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
|
|
|
|
|
2013-04-03 21:29:47 +02:00
|
|
|
#include <list>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <map>
|
2012-04-12 22:21:50 +02:00
|
|
|
#include <set>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
|
|
|
#include "include/cef_client.h"
|
2014-01-28 00:31:03 +01:00
|
|
|
#include "include/wrapper/cef_message_router.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "cefclient/util.h"
|
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
// The Linux client uses GTK instead of the underlying platform type (X11).
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#define ClientWindowHandle GtkWidget*
|
|
|
|
#else
|
|
|
|
#define ClientWindowHandle CefWindowHandle
|
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Define this value to redirect all popup URLs to the main application browser
|
|
|
|
// window.
|
|
|
|
// #define TEST_REDIRECT_POPUP_URLS
|
|
|
|
|
|
|
|
// ClientHandler implementation.
|
|
|
|
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,
|
2014-07-01 00:30:29 +02:00
|
|
|
public CefRenderHandler,
|
2012-06-11 17:52:49 +02:00
|
|
|
public CefRequestHandler {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2014-07-01 00:30:29 +02:00
|
|
|
// Interface implemented to handle off-screen rendering.
|
|
|
|
class RenderHandler : public CefRenderHandler {
|
|
|
|
public:
|
|
|
|
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) =0;
|
|
|
|
};
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
typedef std::set<CefMessageRouterBrowserSide::Handler*> MessageHandlerSet;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
ClientHandler();
|
|
|
|
virtual ~ClientHandler();
|
|
|
|
|
|
|
|
// CefClient methods
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-06-28 19:21:18 +02:00
|
|
|
virtual CefRefPtr<CefDownloadHandler> GetDownloadHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
2013-06-24 17:45:58 +02:00
|
|
|
virtual CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual CefRefPtr<CefGeolocationHandler> GetGeolocationHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
|
2012-04-03 03:34:16 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
|
2012-04-19 22:31:46 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-06-11 22:03:49 +02:00
|
|
|
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
2012-04-12 22:21:50 +02:00
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message)
|
|
|
|
OVERRIDE;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// CefContextMenuHandler methods
|
|
|
|
virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefContextMenuParams> params,
|
|
|
|
CefRefPtr<CefMenuModel> model) OVERRIDE;
|
|
|
|
virtual 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
|
|
|
|
virtual void OnAddressChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefString& url) OVERRIDE;
|
|
|
|
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& title) OVERRIDE;
|
|
|
|
virtual bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& message,
|
|
|
|
const CefString& source,
|
|
|
|
int line) OVERRIDE;
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
// CefDownloadHandler methods
|
|
|
|
virtual void OnBeforeDownload(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDownloadItem> download_item,
|
|
|
|
const CefString& suggested_name,
|
|
|
|
CefRefPtr<CefBeforeDownloadCallback> callback) OVERRIDE;
|
|
|
|
virtual void OnDownloadUpdated(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDownloadItem> download_item,
|
|
|
|
CefRefPtr<CefDownloadItemCallback> callback) OVERRIDE;
|
|
|
|
|
2013-06-24 17:45:58 +02:00
|
|
|
// CefDragHandler methods
|
|
|
|
virtual bool OnDragEnter(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> dragData,
|
2014-07-01 00:30:29 +02:00
|
|
|
CefDragHandler::DragOperationsMask mask) OVERRIDE;
|
2013-06-24 17:45:58 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// CefGeolocationHandler methods
|
2014-07-02 20:25:22 +02:00
|
|
|
virtual 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
|
|
|
|
virtual bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefKeyEvent& event,
|
|
|
|
CefEventHandle os_event,
|
|
|
|
bool* is_keyboard_shortcut) OVERRIDE;
|
|
|
|
|
|
|
|
// CefLifeSpanHandler methods
|
2014-07-01 00:30:29 +02:00
|
|
|
virtual 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;
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
|
|
|
|
// CefLoadHandler methods
|
2013-09-12 22:34:18 +02:00
|
|
|
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) OVERRIDE;
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) OVERRIDE;
|
|
|
|
|
|
|
|
// CefRequestHandler methods
|
2014-01-28 00:31:03 +01:00
|
|
|
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
bool is_redirect) OVERRIDE;
|
2012-06-11 17:52:49 +02:00
|
|
|
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) OVERRIDE;
|
2012-09-28 00:52:15 +02:00
|
|
|
virtual bool OnQuotaRequest(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& origin_url,
|
|
|
|
int64 new_size,
|
|
|
|
CefRefPtr<CefQuotaCallback> callback) OVERRIDE;
|
2012-06-25 23:21:27 +02:00
|
|
|
virtual void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& url,
|
|
|
|
bool& allow_os_execution) OVERRIDE;
|
2013-09-12 22:34:18 +02:00
|
|
|
virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
|
|
|
|
TerminationStatus status) OVERRIDE;
|
2012-04-19 22:31:46 +02:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
// CefRenderHandler methods
|
|
|
|
virtual bool GetRootScreenRect(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRect& rect) OVERRIDE;
|
|
|
|
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRect& rect) OVERRIDE;
|
|
|
|
virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
|
|
|
|
int viewX,
|
|
|
|
int viewY,
|
|
|
|
int& screenX,
|
|
|
|
int& screenY) OVERRIDE;
|
|
|
|
virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefScreenInfo& screen_info) OVERRIDE;
|
|
|
|
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) OVERRIDE;
|
|
|
|
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRect& rect) OVERRIDE;
|
|
|
|
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
|
|
|
|
PaintElementType type,
|
|
|
|
const RectList& dirtyRects,
|
|
|
|
const void* buffer,
|
|
|
|
int width,
|
|
|
|
int height) OVERRIDE;
|
|
|
|
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefCursorHandle cursor) OVERRIDE;
|
|
|
|
virtual bool StartDragging(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefRenderHandler::DragOperationsMask allowed_ops,
|
|
|
|
int x, int y) OVERRIDE;
|
|
|
|
virtual void UpdateDragCursor(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::DragOperation operation)
|
|
|
|
OVERRIDE;
|
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
void SetMainHwnd(ClientWindowHandle hwnd);
|
|
|
|
ClientWindowHandle GetMainHwnd() { return m_MainHwnd; }
|
|
|
|
void SetEditHwnd(ClientWindowHandle hwnd);
|
2014-07-01 00:30:29 +02:00
|
|
|
void SetOSRHandler(CefRefPtr<RenderHandler> handler) {
|
|
|
|
m_OSRHandler = handler;
|
|
|
|
}
|
|
|
|
CefRefPtr<RenderHandler> GetOSRHandler() { return m_OSRHandler; }
|
2014-05-22 23:01:22 +02:00
|
|
|
void SetButtonHwnds(ClientWindowHandle backHwnd,
|
|
|
|
ClientWindowHandle forwardHwnd,
|
|
|
|
ClientWindowHandle reloadHwnd,
|
|
|
|
ClientWindowHandle stopHwnd);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() { return m_Browser; }
|
|
|
|
int GetBrowserId() { return m_BrowserId; }
|
|
|
|
|
2013-04-03 21:29:47 +02:00
|
|
|
// Request that all existing browser windows close.
|
|
|
|
void CloseAllBrowsers(bool force_close);
|
|
|
|
|
2013-03-19 23:59:33 +01:00
|
|
|
// Returns true if the main browser window is currently closing. Used in
|
|
|
|
// combination with DoClose() and the OS close notification to properly handle
|
|
|
|
// 'onbeforeunload' JavaScript events during window close.
|
|
|
|
bool IsClosing() { return m_bIsClosing; }
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string GetLogFile();
|
|
|
|
|
|
|
|
void SetLastDownloadFile(const std::string& fileName);
|
|
|
|
std::string GetLastDownloadFile();
|
|
|
|
|
|
|
|
// Send a notification to the application. Notifications should not block the
|
|
|
|
// caller.
|
|
|
|
enum NotificationType {
|
|
|
|
NOTIFY_CONSOLE_MESSAGE,
|
|
|
|
NOTIFY_DOWNLOAD_COMPLETE,
|
|
|
|
NOTIFY_DOWNLOAD_ERROR,
|
|
|
|
};
|
|
|
|
void SendNotification(NotificationType type);
|
|
|
|
|
2012-04-27 00:20:18 +02:00
|
|
|
void ShowDevTools(CefRefPtr<CefBrowser> browser);
|
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.
|
|
|
|
std::string GetStartupURL() { return m_StartupURL; }
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
void BeginTracing();
|
|
|
|
void EndTracing();
|
|
|
|
|
|
|
|
bool Save(const std::string& path, const std::string& data);
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
protected:
|
|
|
|
void SetLoading(bool isLoading);
|
|
|
|
void SetNavState(bool canGoBack, bool canGoForward);
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Create all CefMessageRouterBrowserSide::Handler objects. They will be
|
|
|
|
// deleted when the ClientHandler is destroyed.
|
|
|
|
static void CreateMessageHandlers(MessageHandlerSet& handlers);
|
2012-04-12 22:21:50 +02:00
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
// Test context menu creation.
|
|
|
|
void BuildTestMenu(CefRefPtr<CefMenuModel> model);
|
|
|
|
bool ExecuteTestMenu(int command_id);
|
|
|
|
struct TestMenuState {
|
|
|
|
TestMenuState() : check_item(true), radio_item(0) {}
|
|
|
|
bool check_item;
|
|
|
|
int radio_item;
|
|
|
|
} m_TestMenuState;
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
// Returns the full download path for the specified file, or an empty path to
|
|
|
|
// use the default temp directory.
|
|
|
|
std::string GetDownloadPath(const std::string& file_name);
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// The child browser window
|
|
|
|
CefRefPtr<CefBrowser> m_Browser;
|
|
|
|
|
2013-04-03 21:29:47 +02:00
|
|
|
// List of any popup browser windows. Only accessed on the CEF UI thread.
|
|
|
|
typedef std::list<CefRefPtr<CefBrowser> > BrowserList;
|
|
|
|
BrowserList m_PopupBrowsers;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// The main frame window handle
|
2014-05-22 23:01:22 +02:00
|
|
|
ClientWindowHandle m_MainHwnd;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// The child browser id
|
|
|
|
int m_BrowserId;
|
|
|
|
|
2013-03-19 23:59:33 +01:00
|
|
|
// True if the main browser window is currently closing.
|
|
|
|
bool m_bIsClosing;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// The edit window handle
|
2014-05-22 23:01:22 +02:00
|
|
|
ClientWindowHandle m_EditHwnd;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// The button window handles
|
2014-05-22 23:01:22 +02:00
|
|
|
ClientWindowHandle m_BackHwnd;
|
|
|
|
ClientWindowHandle m_ForwardHwnd;
|
|
|
|
ClientWindowHandle m_StopHwnd;
|
|
|
|
ClientWindowHandle m_ReloadHwnd;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<RenderHandler> m_OSRHandler;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Support for logging.
|
|
|
|
std::string m_LogFile;
|
|
|
|
|
|
|
|
// Support for downloading files.
|
|
|
|
std::string m_LastDownloadFile;
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// True if an editable field currently has focus.
|
|
|
|
bool m_bFocusOnEditableField;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-06-26 18:47:05 +02:00
|
|
|
// The startup URL.
|
|
|
|
std::string m_StartupURL;
|
|
|
|
|
2013-04-05 19:05:37 +02:00
|
|
|
// True if mouse cursor change is disabled.
|
|
|
|
bool m_bMouseCursorChangeDisabled;
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
// Handles the browser side of query routing. The renderer side is handled
|
|
|
|
// in client_renderer.cpp.
|
|
|
|
CefRefPtr<CefMessageRouterBrowserSide> message_router_;
|
|
|
|
|
|
|
|
// Set of Handlers registered with the message router.
|
|
|
|
MessageHandlerSet message_handler_set_;
|
|
|
|
|
2013-03-19 23:59:33 +01:00
|
|
|
// Number of currently existing browser windows. The application will exit
|
|
|
|
// when the number of windows reaches 0.
|
|
|
|
static int m_BrowserCount;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Include the default reference counting implementation.
|
|
|
|
IMPLEMENT_REFCOUNTING(ClientHandler);
|
|
|
|
// Include the default locking implementation.
|
|
|
|
IMPLEMENT_LOCKING(ClientHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
|