Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 11411180: move favicon download code from chrome/ into content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WebContentsObserver and callback Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_impl.cc
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 9bf52afc22bfe5f8f14028a3661644c8d8c015fb..6775ee3f247fbaacf846f9a748d0ba4eb3141d5c 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -39,6 +39,7 @@
#include "content/browser/web_contents/web_contents_view_guest.h"
#include "content/browser/webui/web_ui_impl.h"
#include "content/common/browser_plugin_messages.h"
+#include "content/common/icon_messages.h"
#include "content/common/intents_messages.h"
#include "content/common/ssl_status_serialization.h"
#include "content/common/view_messages.h"
@@ -68,6 +69,7 @@
#include "content/public/common/content_constants.h"
#include "content/public/common/content_restriction.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/favicon_url.h"
jam 2012/12/03 21:59:39 nit: redundant since by definition icon_messages.h
Cait (Slow) 2012/12/04 20:57:35 Done.
#include "content/public/common/url_constants.h"
#include "net/base/mime_util.h"
#include "net/base/net_util.h"
@@ -148,6 +150,17 @@ const int kSyncWaitDelay = 40;
const char kDotGoogleDotCom[] = ".google.com";
+static int StartDownload(content::RenderViewHost* rvh,
+ const GURL& url,
+ int image_size) {
+ static int g_next_favicon_download_id = 0;
+ rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(),
+ ++g_next_favicon_download_id,
+ url,
+ image_size));
+ return g_next_favicon_download_id;
+}
+
#if defined(OS_WIN)
BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
@@ -746,6 +759,8 @@ bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
OnRequestPpapiBrokerPermission)
IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest,
OnBrowserPluginCreateGuest)
+ IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
+ IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
message_source_ = NULL;
@@ -1950,6 +1965,14 @@ void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
color_chooser_ = NULL;
}
+int WebContentsImpl::DownloadFavicon(const GURL& url, int image_size,
+ const FaviconDownloadCallback& callback) {
+ RenderViewHost* host = GetRenderViewHost();
+ int id = StartDownload(host, url, image_size);
+ favicon_download_map_[id] = callback;
+ return id;
+}
+
bool WebContentsImpl::FocusLocationBarByDefault() {
WebUI* web_ui = GetWebUIForCurrentState();
if (web_ui)
@@ -2365,6 +2388,31 @@ void WebContentsImpl::OnBrowserPluginCreateGuest(
params);
}
+void WebContentsImpl::OnDidDownloadFavicon(
+ int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps) {
+ FaviconDownloadMap::iterator iter = favicon_download_map_.find(id);
+ if (iter == favicon_download_map_.end()) {
+ // Currently WebContents notifies us of ANY downloads so that it is
+ // possible to get here.
+ return;
+ }
+ if (!iter->second.is_null()) {
+ iter->second.Run(id, image_url, errored, requested_size, bitmaps);
+ }
+ favicon_download_map_.erase(id);
+}
+
+void WebContentsImpl::OnUpdateFaviconURL(
+ int32 page_id,
+ const std::vector<FaviconURL>& candidates) {
+ FOR_EACH_OBSERVER(WebContentsObserver, observers_,
+ DidUpdateFaviconURL(page_id, candidates));
+}
+
void WebContentsImpl::DidBlock3DAPIs(const GURL& url,
ThreeDAPIType requester) {
FOR_EACH_OBSERVER(WebContentsObserver, observers_,

Powered by Google App Engine
This is Rietveld 408576698