// 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, public CefPrintHandler, public CefJSBindingHandler, public DownloadListener { public: ClientHandler(); virtual ~ClientHandler(); // CefClient methods virtual CefRefPtr GetLifeSpanHandler() OVERRIDE { return this; } virtual CefRefPtr GetLoadHandler() OVERRIDE { return this; } virtual CefRefPtr GetRequestHandler() OVERRIDE { return this; } virtual CefRefPtr GetDisplayHandler() OVERRIDE { return this; } virtual CefRefPtr GetPrintHandler() OVERRIDE { return this; } virtual CefRefPtr GetJSBindingHandler() OVERRIDE { return this; } // CefLifeSpanHandler methods virtual bool OnBeforePopup(CefRefPtr parentBrowser, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, const CefString& url, CefRefPtr& client, CefBrowserSettings& settings) OVERRIDE; virtual void OnAfterCreated(CefRefPtr browser) OVERRIDE; virtual bool DoClose(CefRefPtr browser) OVERRIDE; virtual void OnBeforeClose(CefRefPtr browser) OVERRIDE; // CefLoadHandler methods virtual void OnLoadStart(CefRefPtr browser, CefRefPtr frame) OVERRIDE; virtual void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) OVERRIDE; virtual bool OnLoadError(CefRefPtr browser, CefRefPtr frame, ErrorCode errorCode, const CefString& failedUrl, CefString& errorText) OVERRIDE; // CefRequestHandler methods virtual bool OnBeforeResourceLoad(CefRefPtr browser, CefRefPtr request, CefString& redirectUrl, CefRefPtr& resourceStream, CefRefPtr response, int loadFlags) OVERRIDE; virtual bool GetDownloadHandler(CefRefPtr browser, const CefString& mimeType, const CefString& fileName, int64 contentLength, CefRefPtr& handler) OVERRIDE; // CefDisplayHandler methods virtual void OnNavStateChange(CefRefPtr browser, bool canGoBack, bool canGoForward) OVERRIDE; virtual void OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString& url) OVERRIDE; virtual void OnTitleChange(CefRefPtr browser, const CefString& title) OVERRIDE; virtual bool OnConsoleMessage(CefRefPtr browser, const CefString& message, const CefString& source, int line) OVERRIDE; // CefPrintHandler methods. virtual bool GetPrintHeaderFooter(CefRefPtr browser, CefRefPtr 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; // CefJSBindingHandler methods virtual void OnJSBinding(CefRefPtr browser, CefRefPtr frame, CefRefPtr object) OVERRIDE; // 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 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 visitor); CefRefPtr 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); void CloseMainWindow(); protected: void SetLoading(bool isLoading); void SetNavState(bool canGoBack, bool canGoForward); // The child browser window CefRefPtr 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 > DOMVisitorMap; DOMVisitorMap m_DOMVisitors; // Include the default reference counting implementation. IMPLEMENT_REFCOUNTING(ClientHandler); // Include the default locking implementation. IMPLEMENT_LOCKING(ClientHandler); }; #endif // _CLIENT_HANDLER_H