From ad536f769f1a0001bced198ce74271521c676c24 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 12 Jan 2015 19:37:52 +0000 Subject: [PATCH] Add CefDisplayHandler::OnFaviconURLChange callback (issue #964). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1965 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- AUTHORS.txt | 1 + include/capi/cef_display_handler_capi.h | 6 +++++ include/cef_display_handler.h | 7 +++++ libcef/browser/browser_host_impl.cc | 15 +++++++++++ libcef/browser/browser_host_impl.h | 2 ++ libcef_dll/cpptoc/display_handler_cpptoc.cc | 26 ++++++++++++++++++ libcef_dll/ctocpp/display_handler_ctocpp.cc | 30 +++++++++++++++++++++ libcef_dll/ctocpp/display_handler_ctocpp.h | 3 +++ 8 files changed, 90 insertions(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 1b5b1032b..38c5d242c 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -26,3 +26,4 @@ Corey Lucier Mihai Tica Czarek Tomczak Felix Bruns +YuTeh Shen diff --git a/include/capi/cef_display_handler_capi.h b/include/capi/cef_display_handler_capi.h index 0e0b5fec6..87e67c00b 100644 --- a/include/capi/cef_display_handler_capi.h +++ b/include/capi/cef_display_handler_capi.h @@ -70,6 +70,12 @@ typedef struct _cef_display_handler_t { void (CEF_CALLBACK *on_title_change)(struct _cef_display_handler_t* self, struct _cef_browser_t* browser, const cef_string_t* title); + /// + // Called when the page icon changes. + /// + void (CEF_CALLBACK *on_favicon_urlchange)(struct _cef_display_handler_t* self, + struct _cef_browser_t* browser, cef_string_list_t icon_urls); + /// // Called when the browser is about to display a tooltip. |text| contains the // text that will be displayed in the tooltip. To handle the display of the diff --git a/include/cef_display_handler.h b/include/cef_display_handler.h index 681728cd7..69917886f 100644 --- a/include/cef_display_handler.h +++ b/include/cef_display_handler.h @@ -64,6 +64,13 @@ class CefDisplayHandler : public virtual CefBase { virtual void OnTitleChange(CefRefPtr browser, const CefString& title) {} + /// + // Called when the page icon changes. + /// + /*--cef(optional_param=icon_urls)--*/ + virtual void OnFaviconURLChange(CefRefPtr browser, + const std::vector& icon_urls) {} + /// // Called when the browser is about to display a tooltip. |text| contains the // text that will be displayed in the tooltip. To handle the display of the diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 87f4325e8..8c8d46181 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -2490,6 +2490,21 @@ void CefBrowserHostImpl::PluginCrashed(const base::FilePath& plugin_path, } } +void CefBrowserHostImpl::DidUpdateFaviconURL( + const std::vector& candidates) { + if (client_.get()) { + CefRefPtr handler = client_->GetDisplayHandler(); + if (handler.get()) { + std::vector icon_urls; + std::vector::const_iterator it = + candidates.begin(); + for (; it != candidates.end(); ++it) + icon_urls.push_back(it->icon_url.spec()); + handler->OnFaviconURLChange(this, icon_urls); + } + } +} + bool CefBrowserHostImpl::OnMessageReceived(const IPC::Message& message) { // Handle the cursor message here if mouse cursor change is disabled instead // of propegating the message to the normal handler. diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index 05af99558..f7620ed83 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -427,6 +427,8 @@ class CefBrowserHostImpl : public CefBrowserHost, content::RenderFrameHost* render_frame_host) override; void PluginCrashed(const base::FilePath& plugin_path, base::ProcessId plugin_pid) override; + void DidUpdateFaviconURL( + const std::vector& candidates) override; bool OnMessageReceived(const IPC::Message& message) override; // Override to provide a thread safe implementation. bool Send(IPC::Message* message) override; diff --git a/libcef_dll/cpptoc/display_handler_cpptoc.cc b/libcef_dll/cpptoc/display_handler_cpptoc.cc index 3c93a3f49..0a64e2f0a 100644 --- a/libcef_dll/cpptoc/display_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/display_handler_cpptoc.cc @@ -13,6 +13,7 @@ #include "libcef_dll/cpptoc/display_handler_cpptoc.h" #include "libcef_dll/ctocpp/browser_ctocpp.h" #include "libcef_dll/ctocpp/frame_ctocpp.h" +#include "libcef_dll/transfer_util.h" // MEMBER FUNCTIONS - Body may be edited by hand. @@ -65,6 +66,30 @@ void CEF_CALLBACK display_handler_on_title_change( CefString(title)); } +void CEF_CALLBACK display_handler_on_favicon_urlchange( + struct _cef_display_handler_t* self, cef_browser_t* browser, + cef_string_list_t icon_urls) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return; + // Unverified params: icon_urls + + // Translate param: icon_urls; type: string_vec_byref_const + std::vector icon_urlsList; + transfer_string_list_contents(icon_urls, icon_urlsList); + + // Execute + CefDisplayHandlerCppToC::Get(self)->OnFaviconURLChange( + CefBrowserCToCpp::Wrap(browser), + icon_urlsList); +} + int CEF_CALLBACK display_handler_on_tooltip(struct _cef_display_handler_t* self, cef_browser_t* browser, cef_string_t* text) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -143,6 +168,7 @@ CefDisplayHandlerCppToC::CefDisplayHandlerCppToC(CefDisplayHandler* cls) cef_display_handler_t>(cls) { struct_.struct_.on_address_change = display_handler_on_address_change; struct_.struct_.on_title_change = display_handler_on_title_change; + struct_.struct_.on_favicon_urlchange = display_handler_on_favicon_urlchange; struct_.struct_.on_tooltip = display_handler_on_tooltip; struct_.struct_.on_status_message = display_handler_on_status_message; struct_.struct_.on_console_message = display_handler_on_console_message; diff --git a/libcef_dll/ctocpp/display_handler_ctocpp.cc b/libcef_dll/ctocpp/display_handler_ctocpp.cc index 08756bb0d..51797aea2 100644 --- a/libcef_dll/ctocpp/display_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/display_handler_ctocpp.cc @@ -13,6 +13,7 @@ #include "libcef_dll/cpptoc/browser_cpptoc.h" #include "libcef_dll/cpptoc/frame_cpptoc.h" #include "libcef_dll/ctocpp/display_handler_ctocpp.h" +#include "libcef_dll/transfer_util.h" // VIRTUAL METHODS - Body may be edited by hand. @@ -63,6 +64,35 @@ void CefDisplayHandlerCToCpp::OnTitleChange(CefRefPtr browser, title.GetStruct()); } +void CefDisplayHandlerCToCpp::OnFaviconURLChange(CefRefPtr browser, + const std::vector& icon_urls) { + if (CEF_MEMBER_MISSING(struct_, on_favicon_urlchange)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return; + // Unverified params: icon_urls + + // Translate param: icon_urls; type: string_vec_byref_const + cef_string_list_t icon_urlsList = cef_string_list_alloc(); + DCHECK(icon_urlsList); + if (icon_urlsList) + transfer_string_list_contents(icon_urls, icon_urlsList); + + // Execute + struct_->on_favicon_urlchange(struct_, + CefBrowserCppToC::Wrap(browser), + icon_urlsList); + + // Restore param:icon_urls; type: string_vec_byref_const + if (icon_urlsList) + cef_string_list_free(icon_urlsList); +} + bool CefDisplayHandlerCToCpp::OnTooltip(CefRefPtr browser, CefString& text) { if (CEF_MEMBER_MISSING(struct_, on_tooltip)) diff --git a/libcef_dll/ctocpp/display_handler_ctocpp.h b/libcef_dll/ctocpp/display_handler_ctocpp.h index c0e64d46a..f44651f58 100644 --- a/libcef_dll/ctocpp/display_handler_ctocpp.h +++ b/libcef_dll/ctocpp/display_handler_ctocpp.h @@ -18,6 +18,7 @@ #pragma message("Warning: "__FILE__" may be accessed DLL-side only") #else // BUILDING_CEF_SHARED +#include #include "include/cef_display_handler.h" #include "include/capi/cef_display_handler_capi.h" #include "libcef_dll/ctocpp/ctocpp.h" @@ -37,6 +38,8 @@ class CefDisplayHandlerCToCpp const CefString& url) override; void OnTitleChange(CefRefPtr browser, const CefString& title) override; + void OnFaviconURLChange(CefRefPtr browser, + const std::vector& icon_urls) override; bool OnTooltip(CefRefPtr browser, CefString& text) override; void OnStatusMessage(CefRefPtr browser, const CefString& value) override;