#ifndef _BROWSER_BROWSERHANDLER_H #define _BROWSER_BROWSERHANDLER_H #include "include/cef_client.h" #include "include/cef_app.h" #include "include/cef_browser.h" #include "include/cef_frame.h" #include "Cef3ClientApp.h" #include "include/cef_drag_handler.h" #include "include/wrapper/cef_resource_manager.h" #include #include "souistd.h" namespace browser { const int POPUP_DEVTOOLS = WM_APP + 1; class CCef3WebviewHandler : public CefClient, public CefRenderHandler, public CefContextMenuHandler, public CefDisplayHandler, public CefDragHandler, public CefKeyboardHandler, public CefLifeSpanHandler, public CefLoadHandler, public CefRequestHandler { public: // Implement this interface to receive notification of ClientHandlerOsr // events. The methods of this class will be called on the CEF UI thread. class OsrDelegate { public: // These methods match the CefLifeSpanHandler interface. virtual void OnAfterCreated(CefRefPtr browser) = 0; virtual void OnBeforeClose(CefRefPtr browser) = 0; // These methods match the CefRenderHandler interface. virtual bool GetRootScreenRect(CefRefPtr browser, CefRect& rect) = 0; virtual bool GetViewRect(CefRefPtr browser, CefRect& rect) = 0; virtual bool GetScreenPoint(CefRefPtr browser, int viewX, int viewY, int& screenX, int& screenY) = 0; virtual bool GetScreenInfo(CefRefPtr browser, CefScreenInfo& screen_info) = 0; virtual void OnPopupShow(CefRefPtr browser, bool show) = 0; virtual void OnPopupSize(CefRefPtr browser, const CefRect& rect) = 0; virtual void OnPaint(CefRefPtr browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height) = 0; virtual void OnCursorChange( CefRefPtr browser, CefCursorHandle cursor, CefRenderHandler::CursorType type, const CefCursorInfo& custom_cursor_info) = 0; virtual void UpdateDragCursor( CefRefPtr browser, CefRenderHandler::DragOperation operation) = 0; virtual void OnImeCompositionRangeChanged( CefRefPtr browser, const CefRange& selection_range, const CefRenderHandler::RectList& character_bounds) = 0; virtual void OnBeforePopup(CefRefPtr browser, CefRefPtr frame, const CefString& target_url, const CefString& target_frame_name, CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr& client, CefBrowserSettings& settings, bool* no_javascript_access) = 0; virtual void OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString &url) = 0; virtual void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) = 0; protected: virtual ~OsrDelegate() {} }; class MessageHandler { public: virtual bool OnBrowserMessage(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) = 0; }; CCef3WebviewHandler(); ~CCef3WebviewHandler(); // ------------------------------------------------------------------------------ // // browser methods for user // // ------------------------------------------------------------------------------ IMPLEMENT_REFCOUNTING(CCef3WebviewHandler); public: void CloseDevTools(CefRefPtr browser); bool CreatePopupWindow( CefRefPtr browser, bool is_devtools, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr& client, CefBrowserSettings& settings); BOOL Open(HWND hParent, SOUI::CRect rcView); void Close(); void CloseAllBrowsers(bool force_close); void OpenDevTools(); void SetRender(OsrDelegate * pHost); CefRefPtr GetBrowser(); void RegisterMessageHandler(MessageHandler * handler); void UnRegisterMessgeHandler(MessageHandler * handler); bool IsAllowOsExce(const CefString& url);// Allow OS execution of Spotify URIs. // ------------------------------------------------------------------------------ // // impl cef handler callbacks // // ------------------------------------------------------------------------------ protected: // // CefClient methods. Important to return |this| for the handler callbacks. // virtual CefRefPtr GetContextMenuHandler() OVERRIDE { return this; } virtual CefRefPtr GetRenderHandler() OVERRIDE { return this; } virtual CefRefPtr GetDisplayHandler() OVERRIDE { return this; } virtual CefRefPtr GetKeyboardHandler() OVERRIDE { return this; } virtual CefRefPtr GetLifeSpanHandler() OVERRIDE { return this; } virtual CefRefPtr GetLoadHandler() OVERRIDE { return this; } virtual CefRefPtr GetDragHandler() OVERRIDE { return this; } virtual CefRefPtr GetRequestHandler() OVERRIDE { return this; } virtual bool OnProcessMessageReceived(CefRefPtr browser, CefProcessId source_process, CefRefPtr message) OVERRIDE { if (m_pMsgHandler) { return m_pMsgHandler->OnBrowserMessage(browser, source_process, message); } return true; } // CefRequestHandler methods bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, bool is_redirect) OVERRIDE; bool OnOpenURLFromTab( CefRefPtr browser, CefRefPtr frame, const CefString& target_url, CefRequestHandler::WindowOpenDisposition target_disposition, bool user_gesture) OVERRIDE; cef_return_value_t OnBeforeResourceLoad( CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr callback) OVERRIDE; CefRefPtr GetResourceHandler( CefRefPtr browser, CefRefPtr frame, CefRefPtr request) OVERRIDE; CefRefPtr GetResourceResponseFilter( CefRefPtr browser, CefRefPtr frame, CefRefPtr request, CefRefPtr response) OVERRIDE; bool OnQuotaRequest(CefRefPtr browser, const CefString& origin_url, int64 new_size, CefRefPtr callback) OVERRIDE; void OnProtocolExecution(CefRefPtr browser, const CefString& url, bool& allow_os_execution) OVERRIDE; bool OnCertificateError( CefRefPtr browser, ErrorCode cert_error, const CefString& request_url, CefRefPtr ssl_info, CefRefPtr callback) OVERRIDE; void OnRenderProcessTerminated(CefRefPtr browser, TerminationStatus status) OVERRIDE; // CefRenderHandler interfaces virtual bool GetRootScreenRect(CefRefPtr browser, CefRect& rect) OVERRIDE; virtual bool GetViewRect(CefRefPtr browser, CefRect& rect) OVERRIDE; virtual bool GetScreenPoint(CefRefPtr browser, int viewX, int viewY, int& screenX, int& screenY) OVERRIDE; virtual bool GetScreenInfo(CefRefPtr browser, CefScreenInfo& screen_info) OVERRIDE; virtual void OnPopupShow(CefRefPtr browser, bool show) OVERRIDE; virtual void OnPopupSize(CefRefPtr browser, const CefRect& rect) OVERRIDE; virtual void OnPaint( CefRefPtr browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height) OVERRIDE; virtual void OnCursorChange(CefRefPtr browser, CefCursorHandle cursor, CursorType type, const CefCursorInfo& custom_cursor_info) OVERRIDE; virtual bool StartDragging( CefRefPtr browser, CefRefPtr drag_data, CefRenderHandler::DragOperationsMask allowed_ops, int x, int y) OVERRIDE; virtual void UpdateDragCursor( CefRefPtr browser, CefRenderHandler::DragOperation operation) OVERRIDE; void OnImeCompositionRangeChanged( CefRefPtr browser, const CefRange& selection_range, const CefRenderHandler::RectList& character_bounds) OVERRIDE; // // CefContextMenuHandler methods // virtual void OnBeforeContextMenu(CefRefPtr browser, CefRefPtr frame, CefRefPtr params, CefRefPtr model) OVERRIDE; // CefDisplayHandler methods void OnTitleChange(CefRefPtr browser, const CefString& title) OVERRIDE; bool OnConsoleMessage(CefRefPtr browser, const CefString& message, const CefString& source, int line) OVERRIDE; void OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString& url) OVERRIDE; // // CefKeyboardHandler methods // virtual bool OnPreKeyEvent(CefRefPtr browser, const CefKeyEvent& event, CefEventHandle os_event, bool* is_keyboard_shortcut) OVERRIDE; // // CefLifeSpanHandler methods // virtual bool OnBeforePopup(CefRefPtr browser, CefRefPtr frame, const CefString& target_url, const CefString& target_frame_name, CefLifeSpanHandler::WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr& client, CefBrowserSettings& settings, bool* no_javascript_access)OVERRIDE; virtual bool DoClose(CefRefPtr browser) OVERRIDE ; virtual void OnAfterCreated(CefRefPtr browser) OVERRIDE; virtual void OnBeforeClose(CefRefPtr browser)OVERRIDE; // // CefLoadHandler methods // virtual void OnLoadStart(CefRefPtr browser, CefRefPtr frame, TransitionType transition_typ) OVERRIDE { } virtual void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) OVERRIDE { m_bPageLoaded = TRUE; if (m_posr) { m_posr->OnLoadEnd(browser, frame, httpStatusCode); } } virtual void OnLoadError(CefRefPtr browser, CefRefPtr frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) { } private: CefRefPtr m_refBrowser; BOOL m_bPageLoaded; OsrDelegate * m_posr; MessageHandler * m_pMsgHandler; CefRefPtr m_refDevToolsClient; // Manages the registration and delivery of resources. CefRefPtr resource_manager_; // Console logging state. const std::string console_log_file_; bool first_console_message_; }; } //namespace browser #endif