2011-05-20 16:42:25 +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 _CLIENT_HANDLER_H
|
|
|
|
#define _CLIENT_HANDLER_H
|
|
|
|
|
|
|
|
#include "include/cef.h"
|
|
|
|
#include "download_handler.h"
|
|
|
|
#include "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,
|
|
|
|
public CefLifeSpanHandler,
|
|
|
|
public CefLoadHandler,
|
|
|
|
public CefRequestHandler,
|
|
|
|
public CefDisplayHandler,
|
2011-10-14 14:40:40 +02:00
|
|
|
public CefFocusHandler,
|
|
|
|
public CefKeyboardHandler,
|
2011-05-20 16:42:25 +02:00
|
|
|
public CefPrintHandler,
|
2011-11-21 22:21:55 +01:00
|
|
|
public CefV8ContextHandler,
|
2011-08-22 03:31:55 +02:00
|
|
|
public CefDragHandler,
|
2011-05-20 16:42:25 +02:00
|
|
|
public DownloadListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ClientHandler();
|
|
|
|
virtual ~ClientHandler();
|
|
|
|
|
|
|
|
// CefClient methods
|
|
|
|
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
|
|
|
|
{ return this; }
|
|
|
|
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
|
|
|
|
{ return this; }
|
|
|
|
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
|
|
|
|
{ return this; }
|
|
|
|
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
|
|
|
|
{ return this; }
|
2011-10-14 14:40:40 +02:00
|
|
|
virtual CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE
|
|
|
|
{ return this; }
|
|
|
|
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE
|
|
|
|
{ return this; }
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual CefRefPtr<CefPrintHandler> GetPrintHandler() OVERRIDE
|
|
|
|
{ return this; }
|
2011-11-21 22:21:55 +01:00
|
|
|
virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE
|
2011-05-20 16:42:25 +02:00
|
|
|
{ return this; }
|
2011-08-22 03:31:55 +02:00
|
|
|
virtual CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE
|
|
|
|
{ return this; }
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
// CefLifeSpanHandler methods
|
|
|
|
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
2011-10-21 21:35:19 +02:00
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
const CefString& url,
|
|
|
|
CefRefPtr<CefClient>& client,
|
|
|
|
CefBrowserSettings& settings) OVERRIDE;
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
2011-08-03 17:35:51 +02:00
|
|
|
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
2011-08-03 17:35:51 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// 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 bool OnLoadError(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
ErrorCode errorCode,
|
|
|
|
const CefString& failedUrl,
|
|
|
|
CefString& errorText) OVERRIDE;
|
|
|
|
|
|
|
|
// CefRequestHandler methods
|
|
|
|
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefString& redirectUrl,
|
|
|
|
CefRefPtr<CefStreamReader>& resourceStream,
|
|
|
|
CefRefPtr<CefResponse> response,
|
|
|
|
int loadFlags) OVERRIDE;
|
|
|
|
virtual bool GetDownloadHandler(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefString& mimeType,
|
|
|
|
const CefString& fileName,
|
|
|
|
int64 contentLength,
|
|
|
|
CefRefPtr<CefDownloadHandler>& handler)
|
|
|
|
OVERRIDE;
|
|
|
|
|
|
|
|
// CefDisplayHandler methods
|
|
|
|
virtual void OnNavStateChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
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;
|
|
|
|
|
2011-10-14 14:40:40 +02:00
|
|
|
// CefFocusHandler methods.
|
|
|
|
virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefDOMNode> node) OVERRIDE;
|
|
|
|
|
|
|
|
// CefKeyboardHandler methods.
|
|
|
|
virtual bool OnKeyEvent(CefRefPtr<CefBrowser> browser,
|
|
|
|
KeyEventType type,
|
|
|
|
int code,
|
|
|
|
int modifiers,
|
2011-11-04 19:19:14 +01:00
|
|
|
bool isSystemKey,
|
|
|
|
bool isAfterJavaScript) OVERRIDE;
|
2011-10-14 14:40:40 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// CefPrintHandler methods.
|
|
|
|
virtual bool GetPrintHeaderFooter(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
const CefPrintInfo& printInfo,
|
|
|
|
const CefString& url,
|
|
|
|
const CefString& title,
|
|
|
|
int currentPage,
|
|
|
|
int maxPages,
|
|
|
|
CefString& topLeft,
|
|
|
|
CefString& topCenter,
|
|
|
|
CefString& topRight,
|
|
|
|
CefString& bottomLeft,
|
|
|
|
CefString& bottomCenter,
|
|
|
|
CefString& bottomRight) OVERRIDE;
|
|
|
|
|
2011-11-21 22:21:55 +01:00
|
|
|
// CefV8ContextHandler methods
|
|
|
|
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
CefRefPtr<CefV8Context> context) OVERRIDE;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
2011-08-22 03:31:55 +02:00
|
|
|
// CefDragHandler methods.
|
|
|
|
virtual bool OnDragStart(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> dragData,
|
|
|
|
DragOperationsMask mask) OVERRIDE;
|
|
|
|
virtual bool OnDragEnter(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> dragData,
|
|
|
|
DragOperationsMask mask) OVERRIDE;
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// DownloadListener methods
|
|
|
|
virtual void NotifyDownloadComplete(const CefString& fileName) OVERRIDE;
|
|
|
|
virtual void NotifyDownloadError(const CefString& fileName) OVERRIDE;
|
|
|
|
|
|
|
|
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; }
|
|
|
|
CefWindowHandle GetBrowserHwnd() { return m_BrowserHwnd; }
|
|
|
|
|
|
|
|
std::string GetLogFile();
|
|
|
|
|
|
|
|
void SetLastDownloadFile(const std::string& fileName);
|
|
|
|
std::string GetLastDownloadFile();
|
|
|
|
|
|
|
|
// DOM visitors will be called after the associated path is loaded.
|
|
|
|
void AddDOMVisitor(const std::string& path, CefRefPtr<CefDOMVisitor> visitor);
|
|
|
|
CefRefPtr<CefDOMVisitor> GetDOMVisitor(const std::string& path);
|
|
|
|
|
|
|
|
// 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);
|
2011-08-03 17:35:51 +02:00
|
|
|
void CloseMainWindow();
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
protected:
|
2011-05-21 01:39:33 +02:00
|
|
|
void SetLoading(bool isLoading);
|
|
|
|
void SetNavState(bool canGoBack, bool canGoForward);
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
// The child browser window
|
|
|
|
CefRefPtr<CefBrowser> m_Browser;
|
|
|
|
|
|
|
|
// The main frame window handle
|
|
|
|
CefWindowHandle m_MainHwnd;
|
|
|
|
|
|
|
|
// The child browser window handle
|
|
|
|
CefWindowHandle m_BrowserHwnd;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// Support for DOM visitors.
|
|
|
|
typedef std::map<std::string, CefRefPtr<CefDOMVisitor> > DOMVisitorMap;
|
|
|
|
DOMVisitorMap m_DOMVisitors;
|
|
|
|
|
2011-10-14 14:40:40 +02:00
|
|
|
// True if a form element currently has focus
|
|
|
|
bool m_bFormElementHasFocus;
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Include the default reference counting implementation.
|
|
|
|
IMPLEMENT_REFCOUNTING(ClientHandler);
|
|
|
|
// Include the default locking implementation.
|
|
|
|
IMPLEMENT_LOCKING(ClientHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _CLIENT_HANDLER_H
|