2013-04-03 20:20:59 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-04-03 03:34:16 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "cefclient/client_handler.h"
|
|
|
|
#include <stdio.h>
|
2013-04-16 21:23:00 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <set>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2013-04-16 21:23:00 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
#include "include/base/cef_bind.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_browser.h"
|
|
|
|
#include "include/cef_frame.h"
|
2012-06-26 18:47:05 +02:00
|
|
|
#include "include/cef_path_util.h"
|
|
|
|
#include "include/cef_process_util.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
#include "include/cef_trace.h"
|
2013-04-03 20:20:59 +02:00
|
|
|
#include "include/cef_url.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2012-04-12 22:21:50 +02:00
|
|
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "cefclient/cefclient.h"
|
2012-06-11 17:52:49 +02:00
|
|
|
#include "cefclient/client_renderer.h"
|
2012-06-26 18:47:05 +02:00
|
|
|
#include "cefclient/client_switches.h"
|
2012-04-12 22:21:50 +02:00
|
|
|
#include "cefclient/resource_util.h"
|
2015-01-22 21:21:21 +01:00
|
|
|
#include "cefclient/test_runner.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-04-03 20:20:59 +02:00
|
|
|
namespace {
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
// Custom menu command Ids.
|
|
|
|
enum client_menu_ids {
|
|
|
|
CLIENT_ID_SHOW_DEVTOOLS = MENU_ID_USER_FIRST,
|
2013-11-08 17:06:06 +01:00
|
|
|
CLIENT_ID_CLOSE_DEVTOOLS,
|
2014-10-11 02:12:01 +02:00
|
|
|
CLIENT_ID_INSPECT_ELEMENT,
|
2012-04-19 22:31:46 +02:00
|
|
|
CLIENT_ID_TESTMENU_SUBMENU,
|
|
|
|
CLIENT_ID_TESTMENU_CHECKITEM,
|
|
|
|
CLIENT_ID_TESTMENU_RADIOITEM1,
|
|
|
|
CLIENT_ID_TESTMENU_RADIOITEM2,
|
|
|
|
CLIENT_ID_TESTMENU_RADIOITEM3,
|
|
|
|
};
|
|
|
|
|
2013-04-03 20:20:59 +02:00
|
|
|
} // namespace
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
int ClientHandler::browser_count_ = 0;
|
2013-03-19 23:59:33 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
ClientHandler::ClientHandler()
|
2014-07-15 00:18:51 +02:00
|
|
|
: browser_id_(0),
|
2014-07-11 22:28:37 +02:00
|
|
|
is_closing_(false),
|
2014-07-15 00:18:51 +02:00
|
|
|
main_handle_(NULL),
|
2014-07-11 22:28:37 +02:00
|
|
|
edit_handle_(NULL),
|
|
|
|
back_handle_(NULL),
|
|
|
|
forward_handle_(NULL),
|
|
|
|
stop_handle_(NULL),
|
|
|
|
reload_handle_(NULL),
|
|
|
|
focus_on_editable_field_(false) {
|
2014-07-09 19:13:06 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
gtk_dialog_ = NULL;
|
|
|
|
#endif
|
|
|
|
|
2012-06-26 18:47:05 +02:00
|
|
|
// Read command line settings.
|
|
|
|
CefRefPtr<CefCommandLine> command_line =
|
|
|
|
CefCommandLine::GetGlobalCommandLine();
|
|
|
|
|
|
|
|
if (command_line->HasSwitch(cefclient::kUrl))
|
2014-07-11 22:28:37 +02:00
|
|
|
startup_url_ = command_line->GetSwitchValue(cefclient::kUrl);
|
|
|
|
if (startup_url_.empty())
|
|
|
|
startup_url_ = "http://www.google.com/";
|
2012-06-26 18:47:05 +02:00
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
mouse_cursor_change_disabled_ =
|
2013-04-05 19:05:37 +02:00
|
|
|
command_line->HasSwitch(cefclient::kMouseCursorChangeDisabled);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ClientHandler::~ClientHandler() {
|
|
|
|
}
|
|
|
|
|
2012-06-11 22:03:49 +02:00
|
|
|
bool ClientHandler::OnProcessMessageReceived(
|
2012-04-12 22:21:50 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
if (message_router_->OnProcessMessageReceived(browser, source_process,
|
|
|
|
message)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Check for messages from the client renderer.
|
|
|
|
std::string message_name = message->GetName();
|
|
|
|
if (message_name == client_renderer::kFocusedNodeChangedMessage) {
|
|
|
|
// A message is sent from ClientRenderDelegate to tell us whether the
|
2014-07-11 22:28:37 +02:00
|
|
|
// currently focused DOM node is editable. Use of |focus_on_editable_field_|
|
2012-06-11 17:52:49 +02:00
|
|
|
// is redundant with CefKeyEvent.focus_on_editable_field in OnPreKeyEvent
|
|
|
|
// but is useful for demonstration purposes.
|
2014-07-11 22:28:37 +02:00
|
|
|
focus_on_editable_field_ = message->GetArgumentList()->GetBool(0);
|
2012-06-11 17:52:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
return false;
|
2012-04-12 22:21:50 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
void ClientHandler::OnBeforeContextMenu(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefContextMenuParams> params,
|
|
|
|
CefRefPtr<CefMenuModel> model) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
if ((params->GetTypeFlags() & (CM_TYPEFLAG_PAGE | CM_TYPEFLAG_FRAME)) != 0) {
|
|
|
|
// Add a separator if the menu already has items.
|
|
|
|
if (model->GetCount() > 0)
|
2012-08-29 18:58:40 +02:00
|
|
|
model->AddSeparator();
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
// Add DevTools items to all context menus.
|
2012-06-11 17:52:49 +02:00
|
|
|
model->AddItem(CLIENT_ID_SHOW_DEVTOOLS, "&Show DevTools");
|
2013-11-08 17:06:06 +01:00
|
|
|
model->AddItem(CLIENT_ID_CLOSE_DEVTOOLS, "Close DevTools");
|
2014-10-11 02:12:01 +02:00
|
|
|
model->AddSeparator();
|
|
|
|
model->AddItem(CLIENT_ID_INSPECT_ELEMENT, "Inspect Element");
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
// Test context menu features.
|
|
|
|
BuildTestMenu(model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::OnContextMenuCommand(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefContextMenuParams> params,
|
|
|
|
int command_id,
|
|
|
|
EventFlags event_flags) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
switch (command_id) {
|
|
|
|
case CLIENT_ID_SHOW_DEVTOOLS:
|
2014-10-11 02:12:01 +02:00
|
|
|
ShowDevTools(browser, CefPoint());
|
2012-06-11 17:52:49 +02:00
|
|
|
return true;
|
2013-11-08 17:06:06 +01:00
|
|
|
case CLIENT_ID_CLOSE_DEVTOOLS:
|
|
|
|
CloseDevTools(browser);
|
|
|
|
return true;
|
2014-10-11 02:12:01 +02:00
|
|
|
case CLIENT_ID_INSPECT_ELEMENT:
|
|
|
|
ShowDevTools(browser, CefPoint(params->GetXCoord(), params->GetYCoord()));
|
|
|
|
return true;
|
2012-06-11 17:52:49 +02:00
|
|
|
default: // Allow default handling, if any.
|
|
|
|
return ExecuteTestMenu(command_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-09 20:03:43 +02:00
|
|
|
#if !defined(OS_LINUX)
|
|
|
|
|
|
|
|
bool ClientHandler::OnFileDialog(CefRefPtr<CefBrowser> browser,
|
|
|
|
FileDialogMode mode,
|
|
|
|
const CefString& title,
|
2015-01-20 19:24:54 +01:00
|
|
|
const CefString& default_file_path,
|
|
|
|
const std::vector<CefString>& accept_filters,
|
|
|
|
int selected_accept_filter,
|
2014-07-09 20:03:43 +02:00
|
|
|
CefRefPtr<CefFileDialogCallback> callback) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2014-07-09 20:03:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(OS_LINUX)
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& message,
|
|
|
|
const CefString& source,
|
|
|
|
int line) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
bool first_message;
|
|
|
|
std::string logFile;
|
|
|
|
|
|
|
|
{
|
2014-07-11 22:28:37 +02:00
|
|
|
first_message = log_file_.empty();
|
2012-06-11 17:52:49 +02:00
|
|
|
if (first_message) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << AppGetWorkingDirectory();
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
ss << "\\";
|
|
|
|
#else
|
|
|
|
ss << "/";
|
|
|
|
#endif
|
|
|
|
ss << "console.log";
|
2014-07-11 22:28:37 +02:00
|
|
|
log_file_ = ss.str();
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
2014-07-11 22:28:37 +02:00
|
|
|
logFile = log_file_;
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE* file = fopen(logFile.c_str(), "a");
|
|
|
|
if (file) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Message: " << std::string(message) << "\r\nSource: " <<
|
|
|
|
std::string(source) << "\r\nLine: " << line <<
|
|
|
|
"\r\n-----------------------\r\n";
|
|
|
|
fputs(ss.str().c_str(), file);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
if (first_message)
|
|
|
|
SendNotification(NOTIFY_CONSOLE_MESSAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
void ClientHandler::OnBeforeDownload(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDownloadItem> download_item,
|
|
|
|
const CefString& suggested_name,
|
|
|
|
CefRefPtr<CefBeforeDownloadCallback> callback) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
// Continue the download and show the "Save As" dialog.
|
2015-01-22 21:21:21 +01:00
|
|
|
callback->Continue(AppGetDownloadPath(suggested_name), true);
|
2012-06-28 19:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnDownloadUpdated(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDownloadItem> download_item,
|
|
|
|
CefRefPtr<CefDownloadItemCallback> callback) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
if (download_item->IsComplete()) {
|
|
|
|
SetLastDownloadFile(download_item->GetFullPath());
|
|
|
|
SendNotification(NOTIFY_DOWNLOAD_COMPLETE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 17:45:58 +02:00
|
|
|
bool ClientHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> dragData,
|
2014-07-01 00:30:29 +02:00
|
|
|
CefDragHandler::DragOperationsMask mask) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2013-06-24 17:45:58 +02:00
|
|
|
|
|
|
|
// Forbid dragging of link URLs.
|
2013-07-24 22:15:18 +02:00
|
|
|
if (mask & DRAG_OPERATION_LINK)
|
2013-06-24 17:45:58 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-02 20:25:22 +02:00
|
|
|
bool ClientHandler::OnRequestGeolocationPermission(
|
2012-06-11 17:52:49 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& requesting_url,
|
|
|
|
int request_id,
|
|
|
|
CefRefPtr<CefGeolocationCallback> callback) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Allow geolocation access from all websites.
|
|
|
|
callback->Continue(true);
|
2014-07-02 20:25:22 +02:00
|
|
|
return true;
|
2012-06-11 17:52:49 +02:00
|
|
|
}
|
|
|
|
|
2014-07-09 19:13:06 +02:00
|
|
|
#if !defined(OS_LINUX)
|
|
|
|
|
|
|
|
bool ClientHandler::OnJSDialog(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& origin_url,
|
|
|
|
const CefString& accept_lang,
|
|
|
|
JSDialogType dialog_type,
|
|
|
|
const CefString& message_text,
|
|
|
|
const CefString& default_prompt_text,
|
|
|
|
CefRefPtr<CefJSDialogCallback> callback,
|
|
|
|
bool& suppress_message) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-09 19:13:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::OnBeforeUnloadDialog(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& message_text,
|
|
|
|
bool is_reload,
|
|
|
|
CefRefPtr<CefJSDialogCallback> callback) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-09 19:13:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnResetDialogState(CefRefPtr<CefBrowser> browser) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-09 19:13:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(OS_LINUX)
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
bool ClientHandler::OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefKeyEvent& event,
|
|
|
|
CefEventHandle os_event,
|
|
|
|
bool* is_keyboard_shortcut) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
if (!event.focus_on_editable_field && event.windows_key_code == 0x20) {
|
|
|
|
// Special handling for the space character when an input element does not
|
|
|
|
// have focus. Handling the event in OnPreKeyEvent() keeps the event from
|
|
|
|
// being processed in the renderer. If we instead handled the event in the
|
|
|
|
// OnKeyEvent() method the space key would cause the window to scroll in
|
|
|
|
// addition to showing the alert box.
|
|
|
|
if (event.type == KEYEVENT_RAWKEYDOWN) {
|
|
|
|
browser->GetMainFrame()->ExecuteJavaScript(
|
|
|
|
"alert('You pressed the space bar!');", "", 0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
const CefString& target_frame_name,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings,
|
|
|
|
bool* no_javascript_access) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
if (browser->GetHost()->IsWindowRenderingDisabled()) {
|
|
|
|
// Cancel popups in off-screen rendering mode.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-02-10 19:53:56 +01:00
|
|
|
if (!message_router_) {
|
|
|
|
// Create the browser-side router for query handling.
|
|
|
|
CefMessageRouterConfig config;
|
|
|
|
message_router_ = CefMessageRouterBrowserSide::Create(config);
|
|
|
|
|
|
|
|
// Register handlers with the router.
|
2015-01-22 21:21:21 +01:00
|
|
|
client::test_runner::CreateMessageHandlers(message_handler_set_);
|
2014-02-10 19:53:56 +01:00
|
|
|
MessageHandlerSet::const_iterator it = message_handler_set_.begin();
|
|
|
|
for (; it != message_handler_set_.end(); ++it)
|
|
|
|
message_router_->AddHandler(*(it), false);
|
|
|
|
}
|
|
|
|
|
2013-04-05 19:05:37 +02:00
|
|
|
// Disable mouse cursor change if requested via the command-line flag.
|
2014-07-11 22:28:37 +02:00
|
|
|
if (mouse_cursor_change_disabled_)
|
2013-04-05 19:05:37 +02:00
|
|
|
browser->GetHost()->SetMouseCursorChangeDisabled(true);
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
if (!GetBrowser()) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2012-04-03 03:34:16 +02:00
|
|
|
// We need to keep the main child window, but not popup windows
|
2014-07-11 22:28:37 +02:00
|
|
|
browser_ = browser;
|
|
|
|
browser_id_ = browser->GetIdentifier();
|
2013-04-03 21:29:47 +02:00
|
|
|
} else if (browser->IsPopup()) {
|
|
|
|
// Add to the list of popup browsers.
|
2014-07-11 22:28:37 +02:00
|
|
|
popup_browsers_.push_back(browser);
|
2014-06-06 21:04:21 +02:00
|
|
|
|
|
|
|
// Give focus to the popup browser. Perform asynchronously because the
|
|
|
|
// parent window may attempt to keep focus after launching the popup.
|
|
|
|
CefPostTask(TID_UI,
|
2014-07-15 00:18:51 +02:00
|
|
|
base::Bind(&CefBrowserHost::SetFocus, browser->GetHost().get(), true));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2013-03-19 23:59:33 +01:00
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
browser_count_++;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-03-19 23:59:33 +01:00
|
|
|
// Closing the main window requires special handling. See the DoClose()
|
|
|
|
// documentation in the CEF header for a detailed destription of this
|
|
|
|
// process.
|
2014-07-15 00:18:51 +02:00
|
|
|
if (GetBrowserId() == browser->GetIdentifier()) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2013-03-19 23:59:33 +01:00
|
|
|
// Set a flag to indicate that the window close should be allowed.
|
2014-07-11 22:28:37 +02:00
|
|
|
is_closing_ = true;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-03-19 23:59:33 +01:00
|
|
|
// Allow the close. For windowed browsers this will result in the OS close
|
|
|
|
// event being sent.
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
message_router_->OnBeforeClose(browser);
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
if (GetBrowserId() == browser->GetIdentifier()) {
|
|
|
|
{
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
// Free the browser pointer so that the browser can be destroyed
|
|
|
|
browser_ = NULL;
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
if (osr_handler_.get()) {
|
|
|
|
osr_handler_->OnBeforeClose(browser);
|
|
|
|
osr_handler_ = NULL;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
2012-05-18 17:04:56 +02:00
|
|
|
} else if (browser->IsPopup()) {
|
2013-04-03 21:29:47 +02:00
|
|
|
// Remove from the browser popup list.
|
2014-07-11 22:28:37 +02:00
|
|
|
BrowserList::iterator bit = popup_browsers_.begin();
|
|
|
|
for (; bit != popup_browsers_.end(); ++bit) {
|
2013-04-03 21:29:47 +02:00
|
|
|
if ((*bit)->IsSame(browser)) {
|
2014-07-11 22:28:37 +02:00
|
|
|
popup_browsers_.erase(bit);
|
2013-04-03 21:29:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2013-03-19 23:59:33 +01:00
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
if (--browser_count_ == 0) {
|
2014-01-28 00:31:03 +01:00
|
|
|
// All browser windows have closed.
|
|
|
|
// Remove and delete message router handlers.
|
|
|
|
MessageHandlerSet::const_iterator it = message_handler_set_.begin();
|
|
|
|
for (; it != message_handler_set_.end(); ++it) {
|
|
|
|
message_router_->RemoveHandler(*(it));
|
|
|
|
delete *(it);
|
|
|
|
}
|
|
|
|
message_handler_set_.clear();
|
|
|
|
message_router_ = NULL;
|
|
|
|
|
|
|
|
// Quit the application message loop.
|
2013-03-19 23:59:33 +01:00
|
|
|
AppQuitMessageLoop();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-09-12 22:34:18 +02:00
|
|
|
void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-09-12 22:34:18 +02:00
|
|
|
SetLoading(isLoading);
|
|
|
|
SetNavState(canGoBack, canGoForward);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) {
|
2014-07-11 22:10:05 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2012-04-11 20:00:55 +02:00
|
|
|
|
2012-06-11 19:35:23 +02:00
|
|
|
// Don't display an error for downloaded files.
|
|
|
|
if (errorCode == ERR_ABORTED)
|
|
|
|
return;
|
|
|
|
|
2012-06-25 23:21:27 +02:00
|
|
|
// Don't display an error for external protocols that we allow the OS to
|
|
|
|
// handle. See OnProtocolExecution().
|
|
|
|
if (errorCode == ERR_UNKNOWN_URL_SCHEME) {
|
|
|
|
std::string urlStr = frame->GetURL();
|
|
|
|
if (urlStr.find("spotify:") == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
// Display a load error message.
|
|
|
|
std::stringstream ss;
|
2013-09-03 23:58:02 +02:00
|
|
|
ss << "<html><body bgcolor=\"white\">"
|
|
|
|
"<h2>Failed to load URL " << std::string(failedUrl) <<
|
2012-04-11 20:00:55 +02:00
|
|
|
" with error " << std::string(errorText) << " (" << errorCode <<
|
|
|
|
").</h2></body></html>";
|
|
|
|
frame->LoadString(ss.str(), failedUrl);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
bool ClientHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
bool is_redirect) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
message_router_->OnBeforeBrowse(browser, frame);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
|
2014-01-28 00:31:03 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_IO_THREAD();
|
2015-01-22 21:21:21 +01:00
|
|
|
return client::test_runner::GetResourceHandler(browser, frame, request);
|
2012-04-12 22:21:50 +02:00
|
|
|
}
|
|
|
|
|
2012-09-28 00:52:15 +02:00
|
|
|
bool ClientHandler::OnQuotaRequest(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& origin_url,
|
|
|
|
int64 new_size,
|
|
|
|
CefRefPtr<CefQuotaCallback> callback) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_IO_THREAD();
|
|
|
|
|
2012-09-28 00:52:15 +02:00
|
|
|
static const int64 max_size = 1024 * 1024 * 20; // 20mb.
|
|
|
|
|
|
|
|
// Grant the quota request if the size is reasonable.
|
|
|
|
callback->Continue(new_size <= max_size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-25 23:21:27 +02:00
|
|
|
void ClientHandler::OnProtocolExecution(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& url,
|
|
|
|
bool& allow_os_execution) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2012-06-25 23:21:27 +02:00
|
|
|
std::string urlStr = url;
|
|
|
|
|
|
|
|
// Allow OS execution of Spotify URIs.
|
|
|
|
if (urlStr.find("spotify:") == 0)
|
|
|
|
allow_os_execution = true;
|
|
|
|
}
|
|
|
|
|
2013-09-12 22:34:18 +02:00
|
|
|
void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
|
|
|
|
TerminationStatus status) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
message_router_->OnRenderProcessTerminated(browser);
|
|
|
|
|
2013-09-12 22:34:18 +02:00
|
|
|
// Load the startup URL if that's not the website that we terminated on.
|
|
|
|
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
|
|
|
|
std::string url = frame->GetURL();
|
|
|
|
std::transform(url.begin(), url.end(), url.begin(), tolower);
|
|
|
|
|
|
|
|
std::string startupURL = GetStartupURL();
|
2013-12-17 23:04:35 +01:00
|
|
|
if (startupURL != "chrome://crash" && !url.empty() &&
|
|
|
|
url.find(startupURL) != 0) {
|
2013-09-12 22:34:18 +02:00
|
|
|
frame->LoadURL(startupURL);
|
2013-12-17 23:04:35 +01:00
|
|
|
}
|
2013-09-12 22:34:18 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
bool ClientHandler::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
|
2014-07-15 00:18:51 +02:00
|
|
|
CefRect& rect) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return false;
|
2014-07-11 22:28:37 +02:00
|
|
|
return osr_handler_->GetRootScreenRect(browser, rect);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return false;
|
2014-07-11 22:28:37 +02:00
|
|
|
return osr_handler_->GetViewRect(browser, rect);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::GetScreenPoint(CefRefPtr<CefBrowser> browser,
|
|
|
|
int viewX,
|
|
|
|
int viewY,
|
|
|
|
int& screenX,
|
|
|
|
int& screenY) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return false;
|
2014-07-11 22:28:37 +02:00
|
|
|
return osr_handler_->GetScreenPoint(browser, viewX, viewY, screenX, screenY);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::GetScreenInfo(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefScreenInfo& screen_info) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return false;
|
2014-07-11 22:28:37 +02:00
|
|
|
return osr_handler_->GetScreenInfo(browser, screen_info);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnPopupShow(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool show) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2014-07-11 22:28:37 +02:00
|
|
|
return osr_handler_->OnPopupShow(browser, show);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnPopupSize(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRect& rect) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2014-07-11 22:28:37 +02:00
|
|
|
return osr_handler_->OnPopupSize(browser, rect);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnPaint(CefRefPtr<CefBrowser> browser,
|
|
|
|
PaintElementType type,
|
|
|
|
const RectList& dirtyRects,
|
|
|
|
const void* buffer,
|
|
|
|
int width,
|
|
|
|
int height) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2014-07-11 22:28:37 +02:00
|
|
|
osr_handler_->OnPaint(browser, type, dirtyRects, buffer, width, height);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnCursorChange(CefRefPtr<CefBrowser> browser,
|
2014-11-24 22:56:12 +01:00
|
|
|
CefCursorHandle cursor,
|
|
|
|
CursorType type,
|
|
|
|
const CefCursorInfo& custom_cursor_info) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2014-11-24 22:56:12 +01:00
|
|
|
osr_handler_->OnCursorChange(browser, cursor, type, custom_cursor_info);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::StartDragging(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefRenderHandler::DragOperationsMask allowed_ops,
|
|
|
|
int x, int y) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return false;
|
2014-07-11 22:28:37 +02:00
|
|
|
return osr_handler_->StartDragging(browser, drag_data, allowed_ops, x, y);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::UpdateDragCursor(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::DragOperation operation) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!osr_handler_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
2014-07-11 22:28:37 +02:00
|
|
|
osr_handler_->UpdateDragCursor(browser, operation);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
void ClientHandler::SetMainWindowHandle(ClientWindowHandle handle) {
|
2014-07-15 00:18:51 +02:00
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::Bind(&ClientHandler::SetMainWindowHandle, this, handle));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
main_handle_ = handle;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
ClientWindowHandle ClientHandler::GetMainWindowHandle() const {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return main_handle_;
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
void ClientHandler::SetEditWindowHandle(ClientWindowHandle handle) {
|
2014-07-15 00:18:51 +02:00
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::Bind(&ClientHandler::SetEditWindowHandle, this, handle));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
edit_handle_ = handle;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
void ClientHandler::SetButtonWindowHandles(ClientWindowHandle backHandle,
|
2014-07-15 00:18:51 +02:00
|
|
|
ClientWindowHandle forwardHandle,
|
|
|
|
ClientWindowHandle reloadHandle,
|
|
|
|
ClientWindowHandle stopHandle) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::Bind(&ClientHandler::SetButtonWindowHandles, this,
|
|
|
|
backHandle, forwardHandle, reloadHandle, stopHandle));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
back_handle_ = backHandle;
|
|
|
|
forward_handle_ = forwardHandle;
|
|
|
|
reload_handle_ = reloadHandle;
|
|
|
|
stop_handle_ = stopHandle;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
void ClientHandler::SetOSRHandler(CefRefPtr<RenderHandler> handler) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::Bind(&ClientHandler::SetOSRHandler, this, handler));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
osr_handler_ = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<ClientHandler::RenderHandler> ClientHandler::GetOSRHandler() const {
|
|
|
|
return osr_handler_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> ClientHandler::GetBrowser() const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return browser_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ClientHandler::GetBrowserId() const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return browser_id_;
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:29:47 +02:00
|
|
|
void ClientHandler::CloseAllBrowsers(bool force_close) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute on the UI thread.
|
|
|
|
CefPostTask(TID_UI,
|
2014-07-15 00:18:51 +02:00
|
|
|
base::Bind(&ClientHandler::CloseAllBrowsers, this, force_close));
|
2013-04-03 21:29:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
if (!popup_browsers_.empty()) {
|
2013-04-03 21:29:47 +02:00
|
|
|
// Request that any popup browsers close.
|
2014-07-11 22:28:37 +02:00
|
|
|
BrowserList::const_iterator it = popup_browsers_.begin();
|
|
|
|
for (; it != popup_browsers_.end(); ++it)
|
2013-04-03 21:29:47 +02:00
|
|
|
(*it)->GetHost()->CloseBrowser(force_close);
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:28:37 +02:00
|
|
|
if (browser_.get()) {
|
2013-04-03 21:29:47 +02:00
|
|
|
// Request that the main browser close.
|
2014-07-11 22:28:37 +02:00
|
|
|
browser_->GetHost()->CloseBrowser(force_close);
|
2013-04-03 21:29:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
bool ClientHandler::IsClosing() const {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return is_closing_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ClientHandler::GetLogFile() const {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
return log_file_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::SetLastDownloadFile(const std::string& fileName) {
|
2014-07-15 00:18:51 +02:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
last_download_file_ = fileName;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
std::string ClientHandler::GetLastDownloadFile() const {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2014-07-11 22:28:37 +02:00
|
|
|
return last_download_file_;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-10-11 02:12:01 +02:00
|
|
|
void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefPoint& inspect_element_at) {
|
2013-11-08 17:06:06 +01:00
|
|
|
CefWindowInfo windowInfo;
|
|
|
|
CefBrowserSettings settings;
|
2012-06-26 18:47:05 +02:00
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
windowInfo.SetAsPopup(browser->GetHost()->GetWindowHandle(), "DevTools");
|
|
|
|
#endif
|
2012-06-26 18:47:05 +02:00
|
|
|
|
2014-10-11 02:12:01 +02:00
|
|
|
browser->GetHost()->ShowDevTools(windowInfo, this, settings,
|
|
|
|
inspect_element_at);
|
2013-11-08 17:06:06 +01:00
|
|
|
}
|
2012-06-26 18:47:05 +02:00
|
|
|
|
2013-11-08 17:06:06 +01:00
|
|
|
void ClientHandler::CloseDevTools(CefRefPtr<CefBrowser> browser) {
|
|
|
|
browser->GetHost()->CloseDevTools();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2012-04-12 22:21:50 +02:00
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
std::string ClientHandler::GetStartupURL() const {
|
|
|
|
return startup_url_;
|
|
|
|
}
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
bool ClientHandler::Save(const std::string& path, const std::string& data) {
|
|
|
|
FILE* f = fopen(path.c_str(), "w");
|
|
|
|
if (!f)
|
|
|
|
return false;
|
2013-01-17 23:25:57 +01:00
|
|
|
size_t total = 0;
|
|
|
|
do {
|
|
|
|
size_t write = fwrite(data.c_str() + total, 1, data.size() - total, f);
|
|
|
|
if (write == 0)
|
|
|
|
break;
|
|
|
|
total += write;
|
|
|
|
} while (total < data.size());
|
2012-10-18 00:45:49 +02:00
|
|
|
fclose(f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
void ClientHandler::BuildTestMenu(CefRefPtr<CefMenuModel> model) {
|
|
|
|
if (model->GetCount() > 0)
|
2012-08-29 18:58:40 +02:00
|
|
|
model->AddSeparator();
|
2012-04-19 22:31:46 +02:00
|
|
|
|
|
|
|
// Build the sub menu.
|
|
|
|
CefRefPtr<CefMenuModel> submenu =
|
|
|
|
model->AddSubMenu(CLIENT_ID_TESTMENU_SUBMENU, "Context Menu Test");
|
|
|
|
submenu->AddCheckItem(CLIENT_ID_TESTMENU_CHECKITEM, "Check Item");
|
|
|
|
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM1, "Radio Item 1", 0);
|
|
|
|
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM2, "Radio Item 2", 0);
|
|
|
|
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM3, "Radio Item 3", 0);
|
|
|
|
|
|
|
|
// Check the check item.
|
2014-07-11 22:28:37 +02:00
|
|
|
if (test_menu_state_.check_item)
|
2012-04-19 22:31:46 +02:00
|
|
|
submenu->SetChecked(CLIENT_ID_TESTMENU_CHECKITEM, true);
|
|
|
|
|
|
|
|
// Check the selected radio item.
|
|
|
|
submenu->SetChecked(
|
2014-07-11 22:28:37 +02:00
|
|
|
CLIENT_ID_TESTMENU_RADIOITEM1 + test_menu_state_.radio_item, true);
|
2012-04-19 22:31:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::ExecuteTestMenu(int command_id) {
|
|
|
|
if (command_id == CLIENT_ID_TESTMENU_CHECKITEM) {
|
|
|
|
// Toggle the check item.
|
2014-07-11 22:28:37 +02:00
|
|
|
test_menu_state_.check_item ^= 1;
|
2012-04-19 22:31:46 +02:00
|
|
|
return true;
|
|
|
|
} else if (command_id >= CLIENT_ID_TESTMENU_RADIOITEM1 &&
|
|
|
|
command_id <= CLIENT_ID_TESTMENU_RADIOITEM3) {
|
|
|
|
// Store the selected radio item.
|
2014-07-11 22:28:37 +02:00
|
|
|
test_menu_state_.radio_item = (command_id - CLIENT_ID_TESTMENU_RADIOITEM1);
|
2012-04-19 22:31:46 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow default handling to proceed.
|
|
|
|
return false;
|
|
|
|
}
|