2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2011 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.
|
|
|
|
|
|
|
|
#ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
|
|
|
|
#define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
|
|
|
|
#pragma once
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
#include <set>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_client.h"
|
2014-07-11 22:10:05 +02:00
|
|
|
#include "include/wrapper/cef_helpers.h"
|
2014-01-28 00:31:03 +01:00
|
|
|
#include "include/wrapper/cef_message_router.h"
|
2015-01-29 21:53:53 +01:00
|
|
|
#include "cefclient/client_types.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
#if defined(OS_LINUX)
|
2015-01-26 20:34:26 +01:00
|
|
|
#include "cefclient/dialog_handler_gtk.h"
|
2014-05-22 23:01:22 +02:00
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
namespace client {
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Client handler abstract base class. Provides common functionality shared by
|
|
|
|
// all concrete client handler implementations.
|
2012-04-03 03:34:16 +02:00
|
|
|
class ClientHandler : public CefClient,
|
2012-06-11 17:52:49 +02:00
|
|
|
public CefContextMenuHandler,
|
2012-04-03 03:34:16 +02:00
|
|
|
public CefDisplayHandler,
|
2012-06-28 19:21:18 +02:00
|
|
|
public CefDownloadHandler,
|
2013-06-24 17:45:58 +02:00
|
|
|
public CefDragHandler,
|
2012-04-19 22:31:46 +02:00
|
|
|
public CefGeolocationHandler,
|
2012-06-11 17:52:49 +02:00
|
|
|
public CefKeyboardHandler,
|
|
|
|
public CefLifeSpanHandler,
|
|
|
|
public CefLoadHandler,
|
|
|
|
public CefRequestHandler {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2014-01-28 00:31:03 +01:00
|
|
|
typedef std::set<CefMessageRouterBrowserSide::Handler*> MessageHandlerSet;
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
ClientHandler(const std::string& startup_url,
|
|
|
|
bool is_osr);
|
2015-01-23 00:34:29 +01:00
|
|
|
~ClientHandler();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefClient methods
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefDownloadHandler> GetDownloadHandler() OVERRIDE {
|
2012-06-28 19:21:18 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE {
|
2013-06-24 17:45:58 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefGeolocationHandler> GetGeolocationHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
|
2012-06-11 17:52:49 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
|
2012-04-19 22:31:46 +02:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-23 00:34:29 +01:00
|
|
|
bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
2015-01-23 17:20:52 +01:00
|
|
|
CefRefPtr<CefProcessMessage> message) OVERRIDE;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
CefRefPtr<CefDialogHandler> GetDialogHandler() OVERRIDE {
|
|
|
|
return dialog_handler_;
|
|
|
|
}
|
|
|
|
CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() OVERRIDE {
|
|
|
|
return dialog_handler_;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// CefContextMenuHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefContextMenuParams> params,
|
|
|
|
CefRefPtr<CefMenuModel> model) OVERRIDE;
|
|
|
|
bool OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefContextMenuParams> params,
|
|
|
|
int command_id,
|
|
|
|
EventFlags event_flags) OVERRIDE;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefDisplayHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
void OnAddressChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& url) OVERRIDE;
|
|
|
|
void OnTitleChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& title) OVERRIDE;
|
|
|
|
bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& message,
|
|
|
|
const CefString& source,
|
|
|
|
int line) OVERRIDE;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
// CefDownloadHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
void OnBeforeDownload(
|
2012-06-28 19:21:18 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDownloadItem> download_item,
|
|
|
|
const CefString& suggested_name,
|
|
|
|
CefRefPtr<CefBeforeDownloadCallback> callback) OVERRIDE;
|
2015-01-23 00:34:29 +01:00
|
|
|
void OnDownloadUpdated(
|
2012-06-28 19:21:18 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDownloadItem> download_item,
|
|
|
|
CefRefPtr<CefDownloadItemCallback> callback) OVERRIDE;
|
|
|
|
|
2013-06-24 17:45:58 +02:00
|
|
|
// CefDragHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
bool OnDragEnter(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> dragData,
|
|
|
|
CefDragHandler::DragOperationsMask mask) OVERRIDE;
|
2013-06-24 17:45:58 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// CefGeolocationHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
bool OnRequestGeolocationPermission(
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& requesting_url,
|
|
|
|
int request_id,
|
|
|
|
CefRefPtr<CefGeolocationCallback> callback) OVERRIDE;
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// CefKeyboardHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefKeyEvent& event,
|
|
|
|
CefEventHandle os_event,
|
|
|
|
bool* is_keyboard_shortcut) OVERRIDE;
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
// CefLifeSpanHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
bool 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) OVERRIDE;
|
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
// CefLoadHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) OVERRIDE;
|
|
|
|
void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) OVERRIDE;
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
// CefRequestHandler methods
|
2015-01-23 00:34:29 +01:00
|
|
|
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
bool is_redirect) OVERRIDE;
|
|
|
|
CefRefPtr<CefResourceHandler> GetResourceHandler(
|
2012-06-11 17:52:49 +02:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) OVERRIDE;
|
2015-01-23 00:34:29 +01:00
|
|
|
bool OnQuotaRequest(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& origin_url,
|
|
|
|
int64 new_size,
|
|
|
|
CefRefPtr<CefQuotaCallback> callback) OVERRIDE;
|
|
|
|
void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& url,
|
|
|
|
bool& allow_os_execution) OVERRIDE;
|
|
|
|
void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
|
|
|
|
TerminationStatus status) OVERRIDE;
|
2012-04-19 22:31:46 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Set the main frame window handle.
|
2014-07-11 22:28:37 +02:00
|
|
|
void SetMainWindowHandle(ClientWindowHandle handle);
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Get the main frame window handle. Can only be called on the CEF UI thread.
|
|
|
|
ClientWindowHandle GetMainWindowHandle() const;
|
2013-04-03 21:29:47 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Returns the number of browsers currently using this handler. Can only be
|
|
|
|
// called on the CEF UI thread.
|
|
|
|
int GetBrowserCount() const;
|
2013-03-19 23:59:33 +01:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Show a new DevTools popup window.
|
2014-10-11 02:12:01 +02:00
|
|
|
void ShowDevTools(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefPoint& inspect_element_at);
|
2015-01-26 20:34:26 +01:00
|
|
|
|
|
|
|
// Close the existing DevTools popup window, if any.
|
2013-11-08 17:06:06 +01:00
|
|
|
void CloseDevTools(CefRefPtr<CefBrowser> browser);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-26 18:47:05 +02:00
|
|
|
// Returns the startup URL.
|
2015-01-26 20:34:26 +01:00
|
|
|
std::string startup_url() const { return startup_url_; }
|
2012-06-26 18:47:05 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Returns true if this handler uses off-screen rendering.
|
|
|
|
bool is_osr() const { return is_osr_; }
|
2012-10-18 00:45:49 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
protected:
|
|
|
|
// The following virtual methods are called on the CEF UI thread unless
|
|
|
|
// otherwise indicated.
|
|
|
|
|
|
|
|
// A browser has been created.
|
|
|
|
virtual void BrowserCreated(CefRefPtr<CefBrowser> browser) = 0;
|
|
|
|
|
|
|
|
// A browser is closing.
|
|
|
|
virtual void BrowserClosing(CefRefPtr<CefBrowser> browser) = 0;
|
|
|
|
|
|
|
|
// A browser has been closed.
|
|
|
|
virtual void BrowserClosed(CefRefPtr<CefBrowser> browser) = 0;
|
|
|
|
|
|
|
|
// Set the window URL address.
|
|
|
|
virtual void SetAddress(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& url) = 0;
|
|
|
|
|
|
|
|
// Set the window title.
|
|
|
|
virtual void SetTitle(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& title) = 0;
|
|
|
|
|
|
|
|
// Set the loading state.
|
|
|
|
virtual void SetLoadingState(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) = 0;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Create a new popup window using the specified information. |is_devtools|
|
|
|
|
// will be true if the window will be used for DevTools. Return true to
|
|
|
|
// proceed with popup browser creation or false to cancel the popup browser.
|
|
|
|
// May be called on any thead.
|
|
|
|
virtual bool CreatePopupWindow(
|
2015-01-27 01:03:25 +01:00
|
|
|
CefRefPtr<CefBrowser> browser,
|
2015-01-26 20:34:26 +01:00
|
|
|
bool is_devtools,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) = 0;
|
|
|
|
|
|
|
|
private:
|
2012-04-19 22:31:46 +02:00
|
|
|
// Test context menu creation.
|
|
|
|
void BuildTestMenu(CefRefPtr<CefMenuModel> model);
|
|
|
|
bool ExecuteTestMenu(int command_id);
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// THREAD SAFE MEMBERS
|
|
|
|
// The following members may be accessed from any thread.
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
// The startup URL.
|
2015-01-26 20:34:26 +01:00
|
|
|
const std::string startup_url_;
|
|
|
|
|
|
|
|
// True if this handler uses off-screen rendering.
|
|
|
|
const bool is_osr_;
|
2013-04-03 21:29:47 +02:00
|
|
|
|
2014-07-15 00:18:51 +02:00
|
|
|
// True if mouse cursor change is disabled.
|
|
|
|
bool mouse_cursor_change_disabled_;
|
2015-01-23 21:03:47 +01:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
// Custom dialog handler for GTK.
|
|
|
|
CefRefPtr<ClientDialogHandlerGtk> dialog_handler_;
|
|
|
|
#endif
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Handles the browser side of query routing. The renderer side is handled
|
|
|
|
// in client_renderer.cc.
|
|
|
|
CefRefPtr<CefMessageRouterBrowserSide> message_router_;
|
|
|
|
|
|
|
|
// UI THREAD MEMBERS
|
2014-07-15 00:18:51 +02:00
|
|
|
// The following members will only be accessed on the CEF UI thread.
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Track state information for the text context menu.
|
|
|
|
struct TestMenuState {
|
|
|
|
TestMenuState() : check_item(true), radio_item(0) {}
|
|
|
|
bool check_item;
|
|
|
|
int radio_item;
|
|
|
|
} test_menu_state_;
|
|
|
|
|
|
|
|
// The current number of browsers using this handler.
|
|
|
|
int browser_count_;
|
2014-07-15 00:18:51 +02:00
|
|
|
|
|
|
|
// The main frame window handle.
|
|
|
|
ClientWindowHandle main_handle_;
|
2013-03-19 23:59:33 +01:00
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// Console logging state.
|
2015-01-22 22:39:36 +01:00
|
|
|
const std::string console_log_file_;
|
|
|
|
bool first_console_message_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// True if an editable field currently has focus.
|
2014-07-11 22:28:37 +02:00
|
|
|
bool focus_on_editable_field_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Set of Handlers registered with the message router.
|
|
|
|
MessageHandlerSet message_handler_set_;
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ClientHandler);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
} // namespace client
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
|