// Copyright (c) 2013 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_CEFSIMPLE_SIMPLE_HANDLER_H_ #define CEF_TESTS_CEFSIMPLE_SIMPLE_HANDLER_H_ #include "include/cef_client.h" #include #include #include #include "webview_cookieVisitor.h" #define ColorUNDERLINE \ 0xFF000000 // Black SkColor value for underline, // same as Blink. #define ColorBKCOLOR \ 0x00000000 // White SkColor value for background, // same as Blink. struct browser_info{ CefRefPtr browser; uint32_t width = 1; uint32_t height = 1; float dpi = 1.0; bool is_dragging = false; CefRect prev_ime_position = CefRect(); bool is_ime_commit = false; // Focus the host requested (via setClientFocus) and whether it has been // re-asserted after the first rendered frame. With external_begin_frame the // browser isn't input/focus-ready until frames flow, so a SetFocus issued // right after creation is lost; we re-apply it once the first frame lands. bool wants_focus = false; bool focus_reasserted = false; }; class WebviewHandler : public CefClient, public CefDisplayHandler, public CefLifeSpanHandler, public CefFocusHandler, public CefLoadHandler, public CefRenderHandler{ public: //Paint callback (software off-screen rendering) std::function onPaintCallback; //Accelerated paint callback (GPU shared texture). On Windows |sharedHandle| //is the OnAcceleratedPaint shared-texture HANDLE; |format| is a //cef_color_type_t. Only fired when shared textures are enabled. std::function onAcceleratedPaintCallback; //cef message event std::function onUrlChangedEvent; std::function onTitleChangedEvent; std::functiononCursorChangedEvent; std::function onTooltipEvent; std::functiononConsoleMessageEvent; std::function onFocusedNodeChangeMessage; std::function onImeCompositionRangeChangedMessage; //webpage message std::function onJavaScriptChannelMessage; std::function onLoadStart; std::function onLoadEnd; explicit WebviewHandler(); ~WebviewHandler(); // CefClient methods: virtual CefRefPtr GetDisplayHandler() override { return this; } virtual CefRefPtr GetLifeSpanHandler() override { return this; } virtual CefRefPtr GetFocusHandler() override { return this; } virtual CefRefPtr GetLoadHandler() override { return this; } virtual CefRefPtr GetRenderHandler() override { return this; } bool OnProcessMessageReceived( CefRefPtr browser, CefRefPtr frame, CefProcessId source_process, CefRefPtr message) override; // CefDisplayHandler methods: virtual void OnTitleChange(CefRefPtr browser, const CefString& title) override; virtual void OnAddressChange(CefRefPtr browser, CefRefPtr frame, const CefString& url) override; virtual bool OnCursorChange(CefRefPtr browser, CefCursorHandle cursor, cef_cursor_type_t type, const CefCursorInfo& custom_cursor_info) override; virtual bool OnTooltip(CefRefPtr browser, CefString& text) override; virtual bool OnConsoleMessage(CefRefPtr browser, cef_log_severity_t level, const CefString& message, const CefString& source, int line) override; // CefLifeSpanHandler methods: virtual void OnAfterCreated(CefRefPtr browser) override; virtual bool DoClose(CefRefPtr browser) override; virtual void OnBeforeClose(CefRefPtr browser) override; virtual bool OnBeforePopup(CefRefPtr browser, CefRefPtr frame, int popup_id, const CefString& target_url, const CefString& target_frame_name, WindowOpenDisposition target_disposition, bool user_gesture, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr& client, CefBrowserSettings& settings, CefRefPtr& extra_info, bool* no_javascript_access) override; virtual void OnTakeFocus(CefRefPtr browser, bool next) override; virtual bool OnSetFocus(CefRefPtr browser, FocusSource source) override; virtual void OnGotFocus(CefRefPtr browser) override; // CefLoadHandler methods: virtual void OnLoadError(CefRefPtr browser, CefRefPtr frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) override; virtual void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) override; virtual void OnLoadStart(CefRefPtr browser, CefRefPtr frame, CefLoadHandler::TransitionType transition_type) override; // CefRenderHandler methods: virtual void GetViewRect(CefRefPtr browser, CefRect& rect) override; virtual void OnPaint(CefRefPtr browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height) override; virtual void OnAcceleratedPaint(CefRefPtr browser, PaintElementType type, const RectList& dirtyRects, const CefAcceleratedPaintInfo& info) override; virtual bool GetScreenInfo(CefRefPtr browser, CefScreenInfo& screen_info) override; virtual bool StartDragging(CefRefPtr browser, CefRefPtr drag_data, DragOperationsMask allowed_ops, int x, int y) override; virtual void OnImeCompositionRangeChanged(CefRefPtr browser,const CefRange& selection_range,const CefRenderHandler::RectList& character_bounds) override; // Request that all existing browser windows close. void CloseAllBrowsers(bool force_close); void closeBrowser(int browserId); // javascript: false 면 그 브라우저에서 페이지 스크립트를 실행하지 않는다 (JJ_PATCH.md 5) void createBrowser(std::string url, bool javascript, std::function callback); // Drives one external BeginFrame for every live browser (GPU path only). // Marshals to the CEF UI thread; safe to call from any thread. void sendExternalBeginFrame(); // Diagnostic (GPU path): warn once if no accelerated-paint frame has arrived // shortly after a browser is created — the symptom of an unavailable GPU // shared texture, which would otherwise be a silent black webview. void warnIfNoAcceleratedFrame(); void sendScrollEvent(int browserId, int x, int y, int deltaX, int deltaY); void changeSize(int browserId, float a_dpi, int width, int height); void cursorClick(int browserId, int x, int y, bool up); void cursorMove(int browserId, int x, int y, bool dragging); void sendKeyEvent(CefKeyEvent& ev); void loadUrl(int browserId, std::string url); void goForward(int browserId); void goBack(int browserId); void reload(int browserId); void openDevTools(int browserId); void imeSetComposition(int browserId, std::string text); void imeCommitText(int browserId, std::string text); void setClientFocus(int browserId, bool focus); // Native IME pipeline (Windows WM_IME_*): operate on the currently focused // browser. |text| is UTF-16 read from the IMM composition string. CefRefPtr getFocusedBrowser(); void imeSetCompositionNative(const std::wstring& text, int cursor); void imeCommitTextNative(const std::wstring& text); void imeFinishComposition(); void setCookie(const std::string& domain, const std::string& key, const std::string& value); void deleteCookie(const std::string& domain, const std::string& key); void visitAllCookies(std::function>)> callback); void visitUrlCookies(const std::string& domain, const bool& isHttpOnly, std::function>)> callback); void setJavaScriptChannels(int browserId, const std::vector channels); void sendJavaScriptChannelCallBack(const bool error, const std::string result, const std::string callbackId, const int browserId, const std::string frameId); void executeJavaScript(int browserId, const std::string code, std::function)> callback = nullptr); private: // List of existing browser windows. Only accessed on the CEF UI thread. std::unordered_map browser_map_; std::unordered_map)>> js_callbacks_; #ifdef WEBVIEW_CEF_GPU_TEXTURE // GPU diagnostic state: whether any accelerated-paint frame has arrived, and // whether the "no GPU frame" warning was already logged (log it once). // Only declared on GPU builds so non-GPU builds don't see unused fields. bool received_accelerated_frame_ = false; bool gpu_warning_logged_ = false; #endif // Include the default reference counting implementation. IMPLEMENT_REFCOUNTING(WebviewHandler); }; #endif // CEF_TESTS_CEFSIMPLE_SIMPLE_HANDLER_H_