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
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "cefclient/util.h"
|
|
|
|
|
|
|
|
|
|
|
|
// 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-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:
|
2012-04-12 22:21:50 +02:00
|
|
|
// Interface for process message delegates. Do not perform work in the
|
|
|
|
// RenderDelegate constructor.
|
|
|
|
class ProcessMessageDelegate : public virtual CefBase {
|
|
|
|
public:
|
|
|
|
// Called when a process message is received. Return true if the message was
|
|
|
|
// handled and should not be passed on to other handlers.
|
|
|
|
// ProcessMessageDelegates should check for unique message names to avoid
|
|
|
|
// interfering with each other.
|
|
|
|
virtual bool OnProcessMessageRecieved(
|
|
|
|
CefRefPtr<ClientHandler> handler,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefProcessId source_process,
|
|
|
|
CefRefPtr<CefProcessMessage> message) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::set<CefRefPtr<ProcessMessageDelegate> >
|
|
|
|
ProcessMessageDelegateSet;
|
|
|
|
|
|
|
|
// Interface for request handler delegates. Do not perform work in the
|
|
|
|
// RequestDelegate constructor.
|
|
|
|
class RequestDelegate : public virtual CefBase {
|
|
|
|
public:
|
|
|
|
// Called to retrieve a resource handler.
|
|
|
|
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
|
|
|
|
CefRefPtr<ClientHandler> handler,
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::set<CefRefPtr<RequestDelegate> > RequestDelegateSet;
|
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
|
2012-04-19 22:31:46 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-04-12 22:21:50 +02:00
|
|
|
virtual bool OnProcessMessageRecieved(CefRefPtr<CefBrowser> browser,
|
|
|
|
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 OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) OVERRIDE;
|
|
|
|
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;
|
|
|
|
|
|
|
|
// CefGeolocationHandler methods
|
|
|
|
virtual void OnRequestGeolocationPermission(
|
|
|
|
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
|
|
|
|
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
|
|
|
|
// CefLoadHandler methods
|
|
|
|
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame) OVERRIDE;
|
|
|
|
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int httpStatusCode) OVERRIDE;
|
|
|
|
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& errorText,
|
|
|
|
const CefString& failedUrl) OVERRIDE;
|
|
|
|
|
|
|
|
// CefRequestHandler methods
|
|
|
|
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefRequest> request) OVERRIDE;
|
2012-04-19 22:31:46 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void SetMainHwnd(CefWindowHandle hwnd);
|
|
|
|
CefWindowHandle GetMainHwnd() { return m_MainHwnd; }
|
|
|
|
void SetEditHwnd(CefWindowHandle hwnd);
|
|
|
|
void SetButtonHwnds(CefWindowHandle backHwnd,
|
|
|
|
CefWindowHandle forwardHwnd,
|
|
|
|
CefWindowHandle reloadHwnd,
|
|
|
|
CefWindowHandle stopHwnd);
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() { return m_Browser; }
|
|
|
|
int GetBrowserId() { return m_BrowserId; }
|
|
|
|
|
|
|
|
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);
|
|
|
|
void CloseMainWindow();
|
|
|
|
|
2012-04-27 00:20:18 +02:00
|
|
|
void ShowDevTools(CefRefPtr<CefBrowser> browser);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void SetLoading(bool isLoading);
|
|
|
|
void SetNavState(bool canGoBack, bool canGoForward);
|
|
|
|
|
2012-04-12 22:21:50 +02:00
|
|
|
// Create all of ProcessMessageDelegate objects.
|
|
|
|
static void CreateProcessMessageDelegates(
|
|
|
|
ProcessMessageDelegateSet& delegates);
|
|
|
|
|
|
|
|
// Create all of RequestDelegateSet objects.
|
|
|
|
static void CreateRequestDelegates(RequestDelegateSet& delegates);
|
|
|
|
|
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-04-03 03:34:16 +02:00
|
|
|
// The child browser window
|
|
|
|
CefRefPtr<CefBrowser> m_Browser;
|
|
|
|
|
|
|
|
// The main frame window handle
|
|
|
|
CefWindowHandle m_MainHwnd;
|
|
|
|
|
|
|
|
// The child browser id
|
|
|
|
int m_BrowserId;
|
|
|
|
|
|
|
|
// The edit window handle
|
|
|
|
CefWindowHandle m_EditHwnd;
|
|
|
|
|
|
|
|
// The button window handles
|
|
|
|
CefWindowHandle m_BackHwnd;
|
|
|
|
CefWindowHandle m_ForwardHwnd;
|
|
|
|
CefWindowHandle m_StopHwnd;
|
|
|
|
CefWindowHandle m_ReloadHwnd;
|
|
|
|
|
|
|
|
// 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-04-12 22:21:50 +02:00
|
|
|
// Registered delegates.
|
|
|
|
ProcessMessageDelegateSet process_message_delegates_;
|
|
|
|
RequestDelegateSet request_delegates_;
|
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
std::set<std::string> m_OpenDevToolsURLs;
|
|
|
|
|
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_
|