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.
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#ifndef CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_H_
|
|
|
|
#define CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_H_
|
2012-04-03 03:34:16 +02:00
|
|
|
#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-31 01:55:56 +01:00
|
|
|
#include "cefclient/browser/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-31 01:55:56 +01:00
|
|
|
#include "cefclient/browser/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:
|
2015-01-30 19:55:55 +01:00
|
|
|
// Implement this interface to receive notification of ClientHandler
|
|
|
|
// events. The methods of this class will be called on the main thread.
|
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
// Called when the browser is created.
|
|
|
|
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) = 0;
|
|
|
|
|
|
|
|
// Called when the browser is closing.
|
|
|
|
virtual void OnBrowserClosing(CefRefPtr<CefBrowser> browser) = 0;
|
|
|
|
|
|
|
|
// Called when the browser has been closed.
|
|
|
|
virtual void OnBrowserClosed(CefRefPtr<CefBrowser> browser) = 0;
|
|
|
|
|
|
|
|
// Set the window URL address.
|
|
|
|
virtual void OnSetAddress(const std::string& url) = 0;
|
|
|
|
|
|
|
|
// Set the window title.
|
|
|
|
virtual void OnSetTitle(const std::string& title) = 0;
|
|
|
|
|
|
|
|
// Set the loading state.
|
|
|
|
virtual void OnSetLoadingState(bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) = 0;
|
|
|
|
|
2015-04-24 15:48:32 +02:00
|
|
|
// Set the draggable regions.
|
|
|
|
virtual void OnSetDraggableRegions(
|
|
|
|
const std::vector<CefDraggableRegion>& regions) = 0;
|
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
protected:
|
|
|
|
virtual ~Delegate() {}
|
|
|
|
};
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
typedef std::set<CefMessageRouterBrowserSide::Handler*> MessageHandlerSet;
|
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
// Constructor may be called on any thread.
|
|
|
|
// |delegate| must outlive this object or DetachDelegate() must be called.
|
|
|
|
ClientHandler(Delegate* delegate,
|
|
|
|
bool is_osr,
|
|
|
|
const std::string& startup_url);
|
|
|
|
|
|
|
|
// This object may outlive the Delegate object so it's necessary for the
|
|
|
|
// Delegate to detach itself before destruction.
|
|
|
|
void DetachDelegate();
|
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
|
|
|
|
2015-04-24 15:48:32 +02:00
|
|
|
void OnDraggableRegionsChanged(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const std::vector<CefDraggableRegion>& regions) OVERRIDE;
|
|
|
|
|
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-03-09 21:22:31 +01:00
|
|
|
bool OnBeforePopup(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
const CefString& target_frame_name,
|
|
|
|
CefLifeSpanHandler::WindowOpenDisposition target_disposition,
|
|
|
|
bool user_gesture,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings,
|
|
|
|
bool* no_javascript_access) OVERRIDE;
|
2015-01-23 00:34:29 +01:00
|
|
|
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;
|
2015-03-09 21:22:31 +01:00
|
|
|
bool OnOpenURLFromTab(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& target_url,
|
|
|
|
CefRequestHandler::WindowOpenDisposition target_disposition,
|
|
|
|
bool user_gesture) OVERRIDE;
|
2015-01-23 00:34:29 +01:00
|
|
|
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,
|
2015-04-02 17:21:46 +02:00
|
|
|
CefRefPtr<CefRequestCallback> callback) OVERRIDE;
|
2015-01-23 00:34:29 +01:00
|
|
|
void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& url,
|
|
|
|
bool& allow_os_execution) OVERRIDE;
|
2015-02-11 19:15:04 +01:00
|
|
|
bool OnCertificateError(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
ErrorCode cert_error,
|
|
|
|
const CefString& request_url,
|
|
|
|
CefRefPtr<CefSSLInfo> ssl_info,
|
2015-04-02 17:21:46 +02:00
|
|
|
CefRefPtr<CefRequestCallback> callback) OVERRIDE;
|
2015-01-23 00:34:29 +01:00
|
|
|
void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
|
|
|
|
TerminationStatus status) OVERRIDE;
|
2012-04-19 22:31:46 +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-30 19:55:55 +01:00
|
|
|
private:
|
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.
|
2015-01-30 19:55:55 +01:00
|
|
|
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,
|
2015-01-30 19:55:55 +01:00
|
|
|
CefBrowserSettings& settings);
|
|
|
|
|
|
|
|
// Execute Delegate notifications on the main thread.
|
|
|
|
void NotifyBrowserCreated(CefRefPtr<CefBrowser> browser);
|
|
|
|
void NotifyBrowserClosing(CefRefPtr<CefBrowser> browser);
|
|
|
|
void NotifyBrowserClosed(CefRefPtr<CefBrowser> browser);
|
|
|
|
void NotifyAddress(const CefString& url);
|
|
|
|
void NotifyTitle(const CefString& title);
|
|
|
|
void NotifyLoadingState(bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward);
|
2015-04-24 15:48:32 +02:00
|
|
|
void NotifyDraggableRegions(
|
|
|
|
const std::vector<CefDraggableRegion>& regions);
|
2015-01-26 20:34:26 +01:00
|
|
|
|
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
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// True if this handler uses off-screen rendering.
|
|
|
|
const bool is_osr_;
|
2013-04-03 21:29:47 +02:00
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
// The startup URL.
|
|
|
|
const std::string startup_url_;
|
|
|
|
|
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_;
|
2015-04-24 15:48:32 +02:00
|
|
|
|
2015-01-30 19:55:55 +01:00
|
|
|
// MAIN THREAD MEMBERS
|
|
|
|
// The following members will only be accessed on the main thread. This will
|
|
|
|
// be the same as the CEF UI thread except when using multi-threaded message
|
|
|
|
// loop mode on Windows.
|
|
|
|
|
|
|
|
Delegate* delegate_;
|
|
|
|
|
2015-01-26 20:34:26 +01:00
|
|
|
// 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
|
|
|
|
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
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#endif // CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_H_
|