Skip to content

Commit

Permalink
Update print handler on Linux (#403) and fix print dialog error (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed Jun 11, 2018
1 parent 357a7fb commit d688f42
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/cef_v59..v66_changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ MISC
----
+ Compare src/client_handler/dialog_handler_gtk.cpp (and .h) with upstream
cefclient files
- In subprocess/print_handler_gtk.cpp use GetWindow implementation
+ In subprocess/print_handler_gtk.cpp use GetWindow implementation
from x11.cpp

NEW FEATURES
Expand Down
9 changes: 9 additions & 0 deletions src/client_handler/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// All rights reserved. Licensed under BSD 3-clause license.
// Project website: https://github.com/cztomczak/cefpython

// NOTE: This file is also used by "subprocess" and "libcefpythonapp"
// targets during build.

#include "x11.h"
#include "include/base/cef_logging.h"

Expand All @@ -24,6 +27,7 @@ void InstallX11ErrorHandlers() {
// Copied from upstream cefclient.
// Install xlib error handlers so that the application won't be terminated
// on non-fatal errors. Must be done after initializing GTK.
LOG(INFO) << "[Browser process] Install X11 error handlers";
XSetErrorHandler(XErrorHandlerImpl);
XSetIOErrorHandler(XIOErrorHandlerImpl);
}
Expand All @@ -48,6 +52,7 @@ void SetX11WindowTitle(CefRefPtr<CefBrowser> browser, char* title) {
}

GtkWindow* CefBrowser_GetGtkWindow(CefRefPtr<CefBrowser> browser) {
// TODO: Should return NULL when using the Views framework
// -- REWRITTEN FOR CEF PYTHON USE CASE --
// X11 window handle
::Window xwindow = browser->GetHost()->GetWindowHandle();
Expand All @@ -68,6 +73,10 @@ GtkWindow* CefBrowser_GetGtkWindow(CefRefPtr<CefBrowser> browser) {
// internally, so GTK wasn't yet initialized and must do it
// now, so that display is available. Also must install X11
// error handlers to avoid 'BadWindow' errors.
// --
// A similar code is in cefpython_app.cpp and it might already
// been executed. If making changes here, make changes there
// as well.
LOG(INFO) << "[Browser process] Initialize GTK";
gtk_init(0, NULL);
InstallX11ErrorHandlers();
Expand Down
4 changes: 2 additions & 2 deletions src/subprocess/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ else ifeq ($(UNAME_S), Darwin)
endif

ifeq ($(UNAME_S), Linux)
CPP_FILES = print_handler_gtk.cpp
LIBS = -lcef -lgobject-2.0 -lglib-2.0 -lgtk-x11-2.0
CPP_FILES = print_handler_gtk.cpp ../client_handler/x11.cpp
LIBS = -lcef -lX11 -lgobject-2.0 -lglib-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0
else ifeq ($(UNAME_S), Darwin)
CPP_FILES =
# Include framework before libcef_dll_wrapper
Expand Down
2 changes: 1 addition & 1 deletion src/subprocess/Makefile-libcefpythonapp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ UNAME_S = $(shell uname -s)
CCFLAGS = -fPIC -DBROWSER_PROCESS $(CEF_CCFLAGS)

ifeq ($(UNAME_S), Linux)
SRC_MORE = print_handler_gtk.cpp \
SRC_MORE = print_handler_gtk.cpp ../client_handler/x11.cpp \
main_message_loop/main_message_loop_external_pump_linux.cpp
else ifeq ($(UNAME_S), Darwin)
SRC_MORE = main_message_loop/main_message_loop_external_pump_mac.mm
Expand Down
5 changes: 5 additions & 0 deletions src/subprocess/cefpython_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include "client_handler/x11.h"
#include "print_handler_gtk.h"
#endif // OS_LINUX
#endif // BROWSER_PROCESS
Expand Down Expand Up @@ -221,10 +222,14 @@ CefRefPtr<CefPrintHandler> CefPythonApp::GetPrintHandler() {
#if defined(OS_LINUX)
// For print handler to work GTK must be initialized. This is
// required for some of the examples.
// --
// A similar code is in client_handler/x11.cpp. If making changes here,
// make changes there as well.
GdkDisplay* gdk_display = gdk_display_get_default();
if (!gdk_display) {
LOG(INFO) << "[Browser process] Initialize GTK";
gtk_init(0, NULL);
InstallX11ErrorHandlers();
}
#endif
#endif
Expand Down
16 changes: 3 additions & 13 deletions src/subprocess/print_handler_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "include/wrapper/cef_helpers.h"
#include "include/wrapper/cef_closure_task.h"

#include "client_handler/x11.h"

namespace {

// CUPS Duplex attribute and values.
Expand Down Expand Up @@ -374,7 +376,7 @@ struct ClientPrintHandlerGtk::PrintHandler {
CefRefPtr<CefPrintDialogCallback> callback) {
dialog_callback_ = callback;

GtkWindow* parent = GetWindow();
GtkWindow* parent = CefBrowser_GetGtkWindow(browser_);
// TODO(estade): We need a window title here.
dialog_ = gtk_print_unix_dialog_new(NULL, parent);
g_signal_connect(dialog_, "delete-event",
Expand Down Expand Up @@ -429,18 +431,6 @@ struct ClientPrintHandlerGtk::PrintHandler {
}

private:
// Returns the GtkWindow* for the browser. Will return NULL when using the
// Views framework.
GtkWindow* GetWindow() {
// TODO(cefpython): Test the code that is commented out whether it works
/*
CefWindowHandle hwnd = browser_->GetWindowHandle();
if (hwnd)
return GTK_WINDOW(hwnd);
*/
return NULL;
}

void OnDialogResponse(GtkDialog* dialog, gint response_id) {
int num_matched_handlers = g_signal_handlers_disconnect_by_func(
dialog_, reinterpret_cast<gpointer>(&OnDialogResponseThunk), this);
Expand Down

0 comments on commit d688f42

Please sign in to comment.