#ifndef __CEF3WEBVWNDHANDLER_H_ #define __CEF3WEBVWNDHANDLER_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_WND = WM_APP + 2; #define WM_OPENFILEDIALOG WM_USER+1880 #define WM_WEBURLDIALOG WM_USER+1881 class CCef3WebVWndHandler : public CefClient, public CefRenderHandler, public CefContextMenuHandler, public CefDisplayHandler, public CefDownloadHandler, public CefDragHandler, public CefKeyboardHandler, public CefLifeSpanHandler, public CefLoadHandler, public CefDialogHandler, public CefRequestHandler { public: CCef3WebVWndHandler(); ~CCef3WebVWndHandler(); // ------------------------------------------------------------------------------ // // browser methods for user // // ------------------------------------------------------------------------------ IMPLEMENT_REFCOUNTING(CCef3WebVWndHandler); 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,const CefString& url,SOUI::CRect rcView); void Close(); void CloseAllBrowsers(bool force_close); void OpenDevTools(); CefRefPtr GetBrowser(); // ------------------------------------------------------------------------------ // // 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 { 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; /////////////////////////////////////CefDownloadHandler////////////////////////////// virtual void OnBeforeDownload( CefRefPtr browser, CefRefPtr download_item, const CefString& suggested_name, CefRefPtr callback); virtual void OnDownloadUpdated( CefRefPtr browser, CefRefPtr download_item, CefRefPtr callback); virtual CefRefPtr GetDownloadHandler() override; /////////////////////////////////////end CefDownloadHandler////////////////////////////// // // 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; } virtual void OnLoadError(CefRefPtr browser, CefRefPtr frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) { CEF_REQUIRE_UI_THREAD(); // Don't display an error for downloaded files. if (errorCode == ERR_ABORTED) return; // Display a load error message. std::stringstream ss; ss << "" "

Failed to load URL " << std::string(failedUrl) << " with error " << std::string(errorText) << " (" << errorCode << ").

"; frame->LoadString(ss.str(), failedUrl); } protected: /// // Return the handler for dialogs. If no handler is provided the default // implementation will be used. /// /*--cef()--*/ virtual CefRefPtr GetDialogHandler() { return this; } virtual bool OnFileDialog(CefRefPtr browser, FileDialogMode mode, const CefString& title, const CefString& default_file_path, const std::vector& accept_filters, int selected_accept_filter, CefRefPtr callback) { m_pFileDialogCallback = callback; ::SetFocus(m_hOwnerWnd); ::SendMessage(m_hOwnerWnd,WM_OPENFILEDIALOG,NULL,NULL); CefRefPtr host = browser->GetHost(); host->SetFocus(true); return true; } public: CefRefPtr m_pFileDialogCallback; private: mutable base::Lock lock_; HWND m_hOwnerWnd; CefRefPtr m_refBrowser; BOOL m_bPageLoaded; 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_; std::wstring m_PopupUrl; // µ¯³öµØÖ· std::wstring m_strHtml; // ÒªÏÔʾµÄhtmlÄÚÈÝ public: std::wstring GetPopupUrl(); bool IsAllowOsExce(const CefString& url);// Allow OS execution of Spotify URIs. void LoadHtml( std::wstring strValue); }; } //namespace browser #endif // __CEF3WEBVWNDHANDLER_H_