Skip to content

Commit

Permalink
Update dialog_handler_gtk files with changes from upstream (#403).
Browse files Browse the repository at this point in the history
Generate a patch file with changes.
  • Loading branch information
cztomczak committed Jun 11, 2018
1 parent da2c2ee commit 357a7fb
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 62 deletions.
10 changes: 5 additions & 5 deletions src/cef_v59..v66_changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ internal/cef_types.h
- + Remove: UR_FLAG_ALLOW_CACHED_CREDENTIALS


TODO
MISC
----
1. Compare src/handler/dialog_handler_gtk.cpp (and .h) with upstream
cefclient files
2. In subprocess/print_handler_gtk.cpp use GetWindow implementation
from x11.cpp
+ Compare src/client_handler/dialog_handler_gtk.cpp (and .h) with upstream
cefclient files
- In subprocess/print_handler_gtk.cpp use GetWindow implementation
from x11.cpp

NEW FEATURES
------------
Expand Down
72 changes: 24 additions & 48 deletions src/client_handler/dialog_handler_gtk.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
// Default dialog handler implementation on Linux.
// Copied from upstream cefclient with changes:
// - Rewrote GetWindow() func
// - Removed "client" namespace
// - Changed titles of JS alerts, removed URL and "Javascript" word
// COPIED from upstream "cef/tests/cefclient/browser/" directory
// with minor modifications. See the .patch file in current directory.

// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

#include <libgen.h>
#include <sys/stat.h>
#include <X11/Xlib.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>

#include "include/cef_browser.h"
#include "include/cef_parser.h"
#include "include/wrapper/cef_helpers.h"

#include "include/base/cef_logging.h"

#include "dialog_handler_gtk.h"
#include "x11.h"

Expand All @@ -43,10 +36,10 @@ std::string GetDescriptionFromMimeType(const std::string& mime_type) {
const char* mime_type;
const char* label;
} kWildCardMimeTypes[] = {
{ "audio", "Audio Files" },
{ "image", "Image Files" },
{ "text", "Text Files" },
{ "video", "Video Files" },
{"audio", "Audio Files"},
{"image", "Image Files"},
{"text", "Text Files"},
{"video", "Video Files"},
};

for (size_t i = 0;
Expand Down Expand Up @@ -140,11 +133,7 @@ void AddFilters(GtkFileChooser* chooser,

} // namespace



ClientDialogHandlerGtk::ClientDialogHandlerGtk()
: gtk_dialog_(NULL) {
}
ClientDialogHandlerGtk::ClientDialogHandlerGtk() : gtk_dialog_(NULL) {}

bool ClientDialogHandlerGtk::OnFileDialog(
CefRefPtr<CefBrowser> browser,
Expand All @@ -161,7 +150,7 @@ bool ClientDialogHandlerGtk::OnFileDialog(

// Remove any modifier flags.
FileDialogMode mode_type =
static_cast<FileDialogMode>(mode & FILE_DIALOG_TYPE_MASK);
static_cast<FileDialogMode>(mode & FILE_DIALOG_TYPE_MASK);

if (mode_type == FILE_DIALOG_OPEN || mode_type == FILE_DIALOG_OPEN_MULTIPLE) {
action = GTK_FILE_CHOOSER_ACTION_OPEN;
Expand Down Expand Up @@ -204,20 +193,15 @@ bool ClientDialogHandlerGtk::OnFileDialog(
return false;

GtkWidget* dialog = gtk_file_chooser_dialog_new(
title_str.c_str(),
GTK_WINDOW(window),
action,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
accept_button, GTK_RESPONSE_ACCEPT,
NULL);
title_str.c_str(), GTK_WINDOW(window), action, GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL, accept_button, GTK_RESPONSE_ACCEPT, NULL);

if (mode_type == FILE_DIALOG_OPEN_MULTIPLE)
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);

if (mode_type == FILE_DIALOG_SAVE) {
gtk_file_chooser_set_do_overwrite_confirmation(
GTK_FILE_CHOOSER(dialog),
!!(mode & FILE_DIALOG_OVERWRITEPROMPT_FLAG));
GTK_FILE_CHOOSER(dialog), !!(mode & FILE_DIALOG_OVERWRITEPROMPT_FLAG));
}

gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog),
Expand All @@ -230,8 +214,7 @@ bool ClientDialogHandlerGtk::OnFileDialog(
struct stat sb;
if (stat(file_path.c_str(), &sb) == 0 && S_ISREG(sb.st_mode)) {
// Use the directory and name of the existing file.
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
file_path.data());
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), file_path.data());
exists = true;
}

Expand Down Expand Up @@ -298,14 +281,13 @@ bool ClientDialogHandlerGtk::OnFileDialog(
return true;
}

bool ClientDialogHandlerGtk::OnJSDialog(
CefRefPtr<CefBrowser> browser,
const CefString& origin_url,
JSDialogType dialog_type,
const CefString& message_text,
const CefString& default_prompt_text,
CefRefPtr<CefJSDialogCallback> callback,
bool& suppress_message) {
bool ClientDialogHandlerGtk::OnJSDialog(CefRefPtr<CefBrowser> browser,
const CefString& origin_url,
JSDialogType dialog_type,
const CefString& message_text,
const CefString& default_prompt_text,
CefRefPtr<CefJSDialogCallback> callback,
bool& suppress_message) {
CEF_REQUIRE_UI_THREAD();

GtkButtonsType buttons = GTK_BUTTONS_NONE;
Expand Down Expand Up @@ -343,22 +325,16 @@ bool ClientDialogHandlerGtk::OnJSDialog(
if (!window)
return false;

gtk_dialog_ = gtk_message_dialog_new(GTK_WINDOW(window),
GTK_DIALOG_MODAL,
gtk_message_type,
buttons,
"%s",
gtk_dialog_ = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL,
gtk_message_type, buttons, "%s",
message_text.ToString().c_str());
g_signal_connect(gtk_dialog_,
"delete-event",
G_CALLBACK(gtk_widget_hide_on_delete),
NULL);
g_signal_connect(gtk_dialog_, "delete-event",
G_CALLBACK(gtk_widget_hide_on_delete), NULL);

gtk_window_set_title(GTK_WINDOW(gtk_dialog_), title.c_str());

GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_),
GTK_STOCK_OK,
GTK_RESPONSE_OK);
GTK_STOCK_OK, GTK_RESPONSE_OK);

if (dialog_type != JSDIALOGTYPE_PROMPT)
gtk_widget_grab_focus(ok_button);
Expand Down
16 changes: 7 additions & 9 deletions src/client_handler/dialog_handler_gtk.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Default dialog handler implementation on Linux.
// Copied from upstream cefclient with changes:
// - Removed "client" namespace
// COPIED from upstream "cef/tests/cefclient/browser/" directory
// with minor modifications. See the .patch file in current directory.

// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
Expand Down Expand Up @@ -37,15 +36,14 @@ class ClientDialogHandlerGtk : public CefDialogHandler,
const CefString& default_prompt_text,
CefRefPtr<CefJSDialogCallback> callback,
bool& suppress_message) OVERRIDE;
bool OnBeforeUnloadDialog(
CefRefPtr<CefBrowser> browser,
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback) OVERRIDE;
bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser,
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback) OVERRIDE;
void OnResetDialogState(CefRefPtr<CefBrowser> browser) OVERRIDE;

private:
static void OnDialogResponse(GtkDialog *dialog,
static void OnDialogResponse(GtkDialog* dialog,
gint response_id,
ClientDialogHandlerGtk* handler);

Expand Down
127 changes: 127 additions & 0 deletions src/client_handler/dialog_handler_gtk.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
diff --git dialog_handler_gtk.cc dialog_handler_gtk.cc
index 042be2ca..ce5a4d4e 100644
--- dialog_handler_gtk.cc
+++ dialog_handler_gtk.cc
@@ -1,18 +1,20 @@
+// COPIED from upstream "cef/tests/cefclient/browser/" directory
+// with minor modifications. See the .patch file in current directory.
+
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

-#include "tests/cefclient/browser/dialog_handler_gtk.h"
-
#include <libgen.h>
#include <sys/stat.h>

#include "include/cef_browser.h"
#include "include/cef_parser.h"
#include "include/wrapper/cef_helpers.h"
-#include "tests/cefclient/browser/root_window.h"

-namespace client {
+#include "include/base/cef_logging.h"
+#include "dialog_handler_gtk.h"
+#include "x11.h"

namespace {

@@ -129,18 +131,6 @@ void AddFilters(GtkFileChooser* chooser,
}
}

-GtkWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
- scoped_refptr<RootWindow> root_window =
- RootWindow::GetForBrowser(browser->GetIdentifier());
- if (root_window) {
- GtkWindow* window = GTK_WINDOW(root_window->GetWindowHandle());
- if (!window)
- LOG(ERROR) << "No GtkWindow for browser";
- return window;
- }
- return NULL;
-}
-
} // namespace

ClientDialogHandlerGtk::ClientDialogHandlerGtk() : gtk_dialog_(NULL) {}
@@ -198,7 +188,7 @@ bool ClientDialogHandlerGtk::OnFileDialog(
}
}

- GtkWindow* window = GetWindow(browser);
+ GtkWindow* window = CefBrowser_GetGtkWindow(browser);
if (!window)
return false;

@@ -308,30 +298,30 @@ bool ClientDialogHandlerGtk::OnJSDialog(CefRefPtr<CefBrowser> browser,
case JSDIALOGTYPE_ALERT:
buttons = GTK_BUTTONS_NONE;
gtk_message_type = GTK_MESSAGE_WARNING;
- title = "JavaScript Alert";
+ title = "Alert";
break;

case JSDIALOGTYPE_CONFIRM:
buttons = GTK_BUTTONS_CANCEL;
gtk_message_type = GTK_MESSAGE_QUESTION;
- title = "JavaScript Confirm";
+ title = "Confirm";
break;

case JSDIALOGTYPE_PROMPT:
buttons = GTK_BUTTONS_CANCEL;
gtk_message_type = GTK_MESSAGE_QUESTION;
- title = "JavaScript Prompt";
+ title = "Prompt";
break;
}

js_dialog_callback_ = callback;

if (!origin_url.empty()) {
- title += " - ";
- title += CefFormatUrlForSecurityDisplay(origin_url).ToString();
+ // title += " - ";
+ // title += CefFormatUrlForSecurityDisplay(origin_url).ToString();
}

- GtkWindow* window = GetWindow(browser);
+ GtkWindow* window = CefBrowser_GetGtkWindow(browser);
if (!window)
return false;

@@ -413,5 +403,3 @@ void ClientDialogHandlerGtk::OnDialogResponse(GtkDialog* dialog,

handler->OnResetDialogState(NULL);
}
-
-} // namespace client
diff --git dialog_handler_gtk.h dialog_handler_gtk.h
index 163d0a35..59f65eda 100644
--- dialog_handler_gtk.h
+++ dialog_handler_gtk.h
@@ -1,3 +1,6 @@
+// COPIED from upstream "cef/tests/cefclient/browser/" directory
+// with minor modifications. See the .patch file in current directory.
+
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
@@ -11,8 +14,6 @@
#include "include/cef_dialog_handler.h"
#include "include/cef_jsdialog_handler.h"

-namespace client {
-
class ClientDialogHandlerGtk : public CefDialogHandler,
public CefJSDialogHandler {
public:
@@ -53,6 +54,4 @@ class ClientDialogHandlerGtk : public CefDialogHandler,
DISALLOW_COPY_AND_ASSIGN(ClientDialogHandlerGtk);
};

-} // namespace client
-
#endif // CEF_TESTS_CEFCLIENT_BROWSER_DIALOG_HANDLER_GTK_H_

0 comments on commit 357a7fb

Please sign in to comment.