summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcaitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-06 06:13:39 +0000
committercaitkp@chromium.org <caitkp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-06 06:13:39 +0000
commit795c28976bcbb5ffabe40ab53f5265a2e1540b3a (patch)
tree42ff43bee81859b7d6c8c0c68588f12f3901d5ba
parent3be2171df16267e9fa5644f1e7ea09edd45e13ca (diff)
downloadchromium_src-795c28976bcbb5ffabe40ab53f5265a2e1540b3a.zip
chromium_src-795c28976bcbb5ffabe40ab53f5265a2e1540b3a.tar.gz
chromium_src-795c28976bcbb5ffabe40ab53f5265a2e1540b3a.tar.bz2
move favicon download code from chrome/ into content/
-chrome/renderer/favicon_helper.(h|cc) ->content/renderer/... -chrome/common/icon_messages.h -> content/common/icon_messages.h -favicon_download_helper.(h|cc) API incorporated into web_contents -chrome/browser/favicon/favicon_download_helper_delegate.h -> content/public/browser/favicon_download_delegate.h Depends on: https://codereview.chromium.org/11416179/ https://codereview.chromium.org/11421051/ BUG=160995 Review URL: https://chromiumcodereview.appspot.com/11411180 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171411 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/favicon/DEPS10
-rw-r--r--chrome/browser/favicon/favicon_download_helper.cc79
-rw-r--r--chrome/browser/favicon/favicon_download_helper.h75
-rw-r--r--chrome/browser/favicon/favicon_download_helper_delegate.h38
-rw-r--r--chrome/browser/favicon/favicon_handler.cc2
-rw-r--r--chrome/browser/favicon/favicon_handler.h12
-rw-r--r--chrome/browser/favicon/favicon_handler_unittest.cc3
-rw-r--r--chrome/browser/favicon/favicon_tab_helper.cc25
-rw-r--r--chrome/browser/favicon/favicon_tab_helper.h21
-rw-r--r--chrome/browser/favicon/favicon_util.cc1
-rw-r--r--chrome/browser/prerender/prerender_contents.cc11
-rw-r--r--chrome/browser/prerender/prerender_contents.h7
-rw-r--r--chrome/browser/prerender/prerender_manager.cc7
-rw-r--r--chrome/browser/prerender/prerender_render_view_host_observer.cc8
-rw-r--r--chrome/browser/prerender/prerender_render_view_host_observer.h5
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc64
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_favicon_loader.h2
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc19
-rw-r--r--chrome/browser/ui/metro_pin_tab_helper_win.cc18
-rw-r--r--chrome/browser/ui/metro_pin_tab_helper_win.h31
-rw-r--r--chrome/browser/ui/views/ash/balloon_view_ash.cc40
-rw-r--r--chrome/browser/ui/views/ash/balloon_view_ash.h21
-rw-r--r--chrome/browser/ui/views/create_application_shortcut_view.cc14
-rw-r--r--chrome/browser/ui/views/create_application_shortcut_view.h14
-rw-r--r--chrome/browser/ui/web_applications/web_app_ui.cc32
-rw-r--r--chrome/browser/ui/webui/ntp/app_launcher_handler.cc2
-rw-r--r--chrome/chrome_browser.gypi3
-rw-r--r--chrome/chrome_common.gypi3
-rw-r--r--chrome/chrome_renderer.gypi2
-rw-r--r--chrome/common/common_message_generator.h1
-rw-r--r--chrome/renderer/chrome_content_renderer_client.cc3
-rw-r--r--chrome/renderer/chrome_render_view_observer.cc1
-rw-r--r--content/browser/web_contents/web_contents_impl.cc47
-rw-r--r--content/browser/web_contents/web_contents_impl.h14
-rw-r--r--content/common/content_message_generator.h1
-rw-r--r--content/common/icon_messages.h (renamed from chrome/common/icon_messages.h)8
-rw-r--r--content/content_common.gypi3
-rw-r--r--content/content_renderer.gypi8
-rw-r--r--content/public/browser/web_contents.h17
-rw-r--r--content/public/browser/web_contents_observer.h5
-rw-r--r--content/public/common/favicon_url.cc (renamed from chrome/common/favicon_url.cc)6
-rw-r--r--content/public/common/favicon_url.h (renamed from chrome/common/favicon_url.h)13
-rw-r--r--content/public/renderer/render_view_observer.h2
-rw-r--r--content/renderer/favicon_helper.cc (renamed from chrome/renderer/favicon_helper.cc)64
-rw-r--r--content/renderer/favicon_helper.h (renamed from chrome/renderer/favicon_helper.h)27
-rw-r--r--content/renderer/render_view_impl.cc6
-rw-r--r--content/renderer/render_view_impl.h4
47 files changed, 336 insertions, 463 deletions
diff --git a/chrome/browser/favicon/DEPS b/chrome/browser/favicon/DEPS
index 3460227..f261846 100644
--- a/chrome/browser/favicon/DEPS
+++ b/chrome/browser/favicon/DEPS
@@ -34,16 +34,6 @@
specific_include_rules = {
# TODO(caitkp): Look into removing history/ dependencies.
- 'favicon_download_helper(_delegate)*\.(h|cc)': [
- "-chrome",
- "-chrome/browser",
- "+chrome/browser/favicon/favicon_download_helper.h",
- "+chrome/browser/favicon/favicon_download_helper_delegate.h",
- "+chrome/browser/favicon/favicon_util.h",
- "+chrome/common/icon_messages.h",
- "+chrome/common/favicon_url.h",
- ],
-
'favicon_util\.(h|cc)': [
"-chrome",
"-chrome/browser",
diff --git a/chrome/browser/favicon/favicon_download_helper.cc b/chrome/browser/favicon/favicon_download_helper.cc
deleted file mode 100644
index 2b364d6..0000000
--- a/chrome/browser/favicon/favicon_download_helper.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/favicon/favicon_download_helper.h"
-
-#include "chrome/browser/favicon/favicon_download_helper_delegate.h"
-#include "chrome/common/icon_messages.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
-
-using content::WebContents;
-
-namespace {
-static int StartDownload(content::RenderViewHost* rvh,
- const GURL& url,
- int image_size) {
- static int id = 0;
- rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url,
- image_size));
- return id;
-}
-} // namespace.
-
-FaviconDownloadHelper::FaviconDownloadHelper(
- WebContents* web_contents,
- FaviconDownloadHelperDelegate* delegate)
- : content::WebContentsObserver(web_contents),
- delegate_(delegate) {
- DCHECK(delegate_);
-}
-
-FaviconDownloadHelper::~FaviconDownloadHelper() {
-}
-
-int FaviconDownloadHelper::DownloadFavicon(const GURL& url, int image_size) {
- content::RenderViewHost* host = web_contents()->GetRenderViewHost();
- int id = StartDownload(host, url, image_size);
- DownloadIdList::iterator i =
- std::find(download_ids_.begin(), download_ids_.end(), id);
- DCHECK(i == download_ids_.end());
- download_ids_.insert(id);
- return id;
-}
-
-bool FaviconDownloadHelper::OnMessageReceived(const IPC::Message& message) {
- bool message_handled = false; // Allow other handlers to receive these.
- IPC_BEGIN_MESSAGE_MAP(FaviconDownloadHelper, message)
- IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
- IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
- IPC_MESSAGE_UNHANDLED(message_handled = false)
- IPC_END_MESSAGE_MAP()
- return message_handled;
-}
-
-void FaviconDownloadHelper::OnDidDownloadFavicon(
- int id,
- const GURL& image_url,
- bool errored,
- int requested_size,
- const std::vector<SkBitmap>& bitmaps) {
- DownloadIdList::iterator i =
- std::find(download_ids_.begin(), download_ids_.end(), id);
- if (i == download_ids_.end()) {
- // Currently WebContents notifies us of ANY downloads so that it is
- // possible to get here.
- return;
- }
- delegate_->OnDidDownloadFavicon(
- id, image_url, errored, requested_size, bitmaps);
- download_ids_.erase(i);
-}
-
-void FaviconDownloadHelper::OnUpdateFaviconURL(
- int32 page_id,
- const std::vector<FaviconURL>& candidates) {
- delegate_->OnUpdateFaviconURL(page_id, candidates);
-}
diff --git a/chrome/browser/favicon/favicon_download_helper.h b/chrome/browser/favicon/favicon_download_helper.h
deleted file mode 100644
index eb5c372..0000000
--- a/chrome/browser/favicon/favicon_download_helper.h
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (c) 2012 The Chromium 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 CHROME_BROWSER_FAVICON_FAVICON_DOWNLOAD_HELPER_H_
-#define CHROME_BROWSER_FAVICON_FAVICON_DOWNLOAD_HELPER_H_
-
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/memory/ref_counted.h"
-#include "chrome/common/favicon_url.h"
-#include "content/public/browser/web_contents_observer.h"
-
-namespace content {
-class WebContents;
-}
-
-namespace gfx {
-class Image;
-}
-
-class GURL;
-class FaviconDownloadHelperDelegate;
-class SkBitmap;
-
-// FaviconDownloadHelper handles requests to download favicons, and listens for
-// the IPC messages from the renderer.
-class FaviconDownloadHelper : public content::WebContentsObserver {
- public:
- FaviconDownloadHelper(content::WebContents* web_contents,
- FaviconDownloadHelperDelegate* delegate);
-
- virtual ~FaviconDownloadHelper();
-
- // Starts the download of the given favicon |url| and returns the unique id of
- // the download request. When the download is finished, an
- // IconHostMsg_DidDownloadFavicon IPC message will be sent and passed on to
- // the delegate via FaviconDownloadHelperDelegate::OnDidDownloadFavicon().
- // Note that |image_size| is a hint for images with multiple sizes. The
- // downloaded image is not resized to the given image_size. If 0 is passed,
- // the first frame of the image is returned.
- int DownloadFavicon(const GURL& url, int image_size);
-
- protected:
- // content::WebContentsObserver overrides.
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
-
- private:
- typedef std::set<int> DownloadIdList;
-
- // Message handler for IconHostMsg_DidDownloadFavicon. Called when the icon
- // at |image_url| has been downloaded.
- // |bitmaps| is a list of all the frames of the icon at |image_url|.
- void OnDidDownloadFavicon(int id,
- const GURL& image_url,
- bool errored,
- int requested_size,
- const std::vector<SkBitmap>& bitmaps);
-
- // Message Handler, called when the FaviconURL associated with the specified
- // page is updated.
- void OnUpdateFaviconURL(int32 page_id,
- const std::vector<FaviconURL>& candidates);
-
- // Delegate to pass Favicon bitmaps back to. Weak.
- FaviconDownloadHelperDelegate* delegate_;
-
- // Ids of pending downloads.
- DownloadIdList download_ids_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(FaviconDownloadHelper);
-};
-
-#endif // CHROME_BROWSER_FAVICON_FAVICON_DOWNLOAD_HELPER_H_
diff --git a/chrome/browser/favicon/favicon_download_helper_delegate.h b/chrome/browser/favicon/favicon_download_helper_delegate.h
deleted file mode 100644
index ebdb5c2..0000000
--- a/chrome/browser/favicon/favicon_download_helper_delegate.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2012 The Chromium 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 CHROME_BROWSER_FAVICON_FAVICON_DOWNLOAD_HELPER_DELEGATE_H_
-#define CHROME_BROWSER_FAVICON_FAVICON_DOWNLOAD_HELPER_DELEGATE_H_
-
-#include <vector>
-
-#include "base/basictypes.h"
-
-class GURL;
-class SkBitmap;
-struct FaviconURL;
-
-// This class provides a delegate interface for a FaviconDownloadHelper. It
-// allows the FaviconDownloadHelper to pass favicon data back to its caller.
-class FaviconDownloadHelperDelegate {
- public:
- // Called when the icon at |image_url| has been downloaded.
- // |bitmaps| is a list of all the frames of the icon at |image_url|.
- virtual void OnDidDownloadFavicon(
- int id,
- const GURL& image_url,
- bool errored,
- int requested_size,
- const std::vector<SkBitmap>& bitmaps) {}
-
- // Message Handler.
- virtual void OnUpdateFaviconURL(
- int32 page_id,
- const std::vector<FaviconURL>& candidates) {}
-
- protected:
- virtual ~FaviconDownloadHelperDelegate() {}
-};
-
-#endif // CHROME_BROWSER_FAVICON_FAVICON_DOWNLOAD_HELPER_DELEGATE_H_
diff --git a/chrome/browser/favicon/favicon_handler.cc b/chrome/browser/favicon/favicon_handler.cc
index dfd7b70..78fd583 100644
--- a/chrome/browser/favicon/favicon_handler.cc
+++ b/chrome/browser/favicon/favicon_handler.cc
@@ -18,7 +18,6 @@
#include "chrome/browser/favicon/favicon_util.h"
#include "chrome/browser/history/select_favicon_frames.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/icon_messages.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_entry.h"
#include "skia/ext/image_operations.h"
@@ -27,6 +26,7 @@
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_util.h"
+using content::FaviconURL;
using content::NavigationEntry;
namespace {
diff --git a/chrome/browser/favicon/favicon_handler.h b/chrome/browser/favicon/favicon_handler.h
index fb19d8f..7f2edee 100644
--- a/chrome/browser/favicon/favicon_handler.h
+++ b/chrome/browser/favicon/favicon_handler.h
@@ -13,8 +13,8 @@
#include "chrome/browser/common/cancelable_request.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/common/favicon_url.h"
#include "chrome/common/ref_counted_util.h"
+#include "content/public/common/favicon_url.h"
#include "googleurl/src/gurl.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image.h"
@@ -94,7 +94,7 @@ class FaviconHandler {
// Message Handler. Must be public, because also called from
// PrerenderContents. Collects the |image_urls| list.
void OnUpdateFaviconURL(int32 page_id,
- const std::vector<FaviconURL>& candidates);
+ const std::vector<content::FaviconURL>& candidates);
// Processes the current image_irls_ entry, requesting the image from the
// history / download service.
@@ -110,7 +110,9 @@ class FaviconHandler {
const std::vector<SkBitmap>& bitmaps);
// For testing.
- const std::deque<FaviconURL>& image_urls() const { return image_urls_; }
+ const std::deque<content::FaviconURL>& image_urls() const {
+ return image_urls_;
+ }
protected:
// These virtual methods make FaviconHandler testable and are overridden by
@@ -237,7 +239,7 @@ class FaviconHandler {
void FetchFaviconInternal();
// Return the current candidate if any.
- FaviconURL* current_candidate() {
+ content::FaviconURL* current_candidate() {
return (image_urls_.size() > 0) ? &image_urls_[0] : NULL;
}
@@ -271,7 +273,7 @@ class FaviconHandler {
const int icon_types_;
// The prioritized favicon candidates from the page back from the renderer.
- std::deque<FaviconURL> image_urls_;
+ std::deque<content::FaviconURL> image_urls_;
// The FaviconBitmapResults from history.
std::vector<history::FaviconBitmapResult> history_results_;
diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc
index 55b9a22..4c29cef 100644
--- a/chrome/browser/favicon/favicon_handler_unittest.cc
+++ b/chrome/browser/favicon/favicon_handler_unittest.cc
@@ -6,9 +6,9 @@
#include "chrome/browser/favicon/favicon_handler.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "content/public/browser/favicon_status.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/favicon_status.h"
#include "content/public/browser/web_contents.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
@@ -17,6 +17,7 @@
class TestFaviconHandler;
+using content::FaviconURL;
using content::NavigationEntry;
using content::WebContents;
diff --git a/chrome/browser/favicon/favicon_tab_helper.cc b/chrome/browser/favicon/favicon_tab_helper.cc
index 912c636..8c9302c 100644
--- a/chrome/browser/favicon/favicon_tab_helper.cc
+++ b/chrome/browser/favicon/favicon_tab_helper.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/browser/favicon/favicon_download_helper.h"
#include "chrome/browser/favicon/favicon_handler.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/favicon/favicon_util.h"
@@ -13,7 +12,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/icon_messages.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_controller.h"
@@ -39,7 +37,6 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper)
FaviconTabHelper::FaviconTabHelper(WebContents* web_contents)
: content::WebContentsObserver(web_contents),
profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
- favicon_download_helper_.reset(new FaviconDownloadHelper(web_contents, this));
favicon_handler_.reset(new FaviconHandler(profile_, this,
FaviconHandler::FAVICON));
if (chrome::kEnableTouchIcon)
@@ -95,14 +92,6 @@ bool FaviconTabHelper::ShouldDisplayFavicon() {
return true;
}
-void FaviconTabHelper::OnUpdateFaviconURL(
- int32 page_id,
- const std::vector<FaviconURL>& candidates) {
- favicon_handler_->OnUpdateFaviconURL(page_id, candidates);
- if (touch_icon_handler_.get())
- touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates);
-}
-
void FaviconTabHelper::SaveFavicon() {
NavigationEntry* entry = web_contents()->GetController().GetActiveEntry();
if (!entry || entry->GetURL().is_empty())
@@ -134,7 +123,9 @@ NavigationEntry* FaviconTabHelper::GetActiveEntry() {
}
int FaviconTabHelper::StartDownload(const GURL& url, int image_size) {
- return favicon_download_helper_->DownloadFavicon(url, image_size);
+ return web_contents()->DownloadFavicon(url, image_size,
+ base::Bind(&FaviconTabHelper::DidDownloadFavicon,
+ base::Unretained(this)));
}
void FaviconTabHelper::NotifyFaviconUpdated() {
@@ -164,7 +155,15 @@ void FaviconTabHelper::DidNavigateMainFrame(
FetchFavicon(details.entry->GetURL());
}
-void FaviconTabHelper::OnDidDownloadFavicon(
+void FaviconTabHelper::DidUpdateFaviconURL(
+ int32 page_id,
+ const std::vector<content::FaviconURL>& candidates) {
+ favicon_handler_->OnUpdateFaviconURL(page_id, candidates);
+ if (touch_icon_handler_.get())
+ touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates);
+}
+
+void FaviconTabHelper::DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
diff --git a/chrome/browser/favicon/favicon_tab_helper.h b/chrome/browser/favicon/favicon_tab_helper.h
index 4dac687..261ab998 100644
--- a/chrome/browser/favicon/favicon_tab_helper.h
+++ b/chrome/browser/favicon/favicon_tab_helper.h
@@ -9,19 +9,17 @@
#include "base/basictypes.h"
#include "base/callback.h"
-#include "chrome/browser/favicon/favicon_download_helper_delegate.h"
#include "chrome/browser/favicon/favicon_handler_delegate.h"
#include "chrome/browser/history/history_types.h"
-#include "chrome/common/favicon_url.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
+#include "content/public/common/favicon_url.h"
namespace gfx {
class Image;
}
class GURL;
-class FaviconDownloadHelper;
class FaviconHandler;
class Profile;
class SkBitmap;
@@ -34,7 +32,6 @@ class SkBitmap;
//
class FaviconTabHelper : public content::WebContentsObserver,
public FaviconHandlerDelegate,
- public FaviconDownloadHelperDelegate,
public content::WebContentsUserData<FaviconTabHelper> {
public:
virtual ~FaviconTabHelper();
@@ -55,11 +52,11 @@ class FaviconTabHelper : public content::WebContentsObserver,
// space is provided for the favicon, and the favicon is never displayed.
virtual bool ShouldDisplayFavicon();
- // Message Handler. Must be public, because also called from
- // PrerenderContents.
- virtual void OnUpdateFaviconURL(
+ // content::WebContentsObserver override. Must be public, because also
+ // called from PrerenderContents.
+ virtual void DidUpdateFaviconURL(
int32 page_id,
- const std::vector<FaviconURL>& candidates) OVERRIDE;
+ const std::vector<content::FaviconURL>& candidates) OVERRIDE;
// Saves the favicon for the current page.
void SaveFavicon();
@@ -81,18 +78,16 @@ class FaviconTabHelper : public content::WebContentsObserver,
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) OVERRIDE;
- // FaviconDownloadHelperDelegate overrides.
- virtual void OnDidDownloadFavicon(
+ // Favicon download callback.
+ void DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
int requested_size,
- const std::vector<SkBitmap>& bitmaps) OVERRIDE;
+ const std::vector<SkBitmap>& bitmaps);
Profile* profile_;
- scoped_ptr<FaviconDownloadHelper> favicon_download_helper_;
-
scoped_ptr<FaviconHandler> favicon_handler_;
// Handles downloading touchicons. It is NULL if
diff --git a/chrome/browser/favicon/favicon_util.cc b/chrome/browser/favicon/favicon_util.cc
index 630f2b3..02c7326 100644
--- a/chrome/browser/favicon/favicon_util.cc
+++ b/chrome/browser/favicon/favicon_util.cc
@@ -6,7 +6,6 @@
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/select_favicon_frames.h"
-#include "chrome/common/icon_messages.h"
#include "content/public/browser/render_view_host.h"
#include "googleurl/src/gurl.h"
#include "ui/gfx/codec/png_codec.h"
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc
index 3b38659..54cfdb1 100644
--- a/chrome/browser/prerender/prerender_contents.cc
+++ b/chrome/browser/prerender/prerender_contents.cc
@@ -20,7 +20,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/icon_messages.h"
#include "chrome/common/prerender_messages.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_child_process_host.h"
@@ -32,6 +31,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view.h"
+#include "content/public/common/favicon_url.h"
#include "ui/gfx/rect.h"
using content::DownloadItem;
@@ -295,7 +295,6 @@ void PrerenderContents::StartPrerendering(
tab_contents_delegate_.reset(new TabContentsDelegateImpl(this));
new_contents->SetDelegate(tab_contents_delegate_.get());
-
// Set the size of the prerender WebContents.
prerender_contents_->web_contents()->GetView()->SizeContents(size_);
@@ -484,13 +483,13 @@ WebContents* PrerenderContents::CreateWebContents(
profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace_map);
}
-void PrerenderContents::OnUpdateFaviconURL(
+void PrerenderContents::DidUpdateFaviconURL(
int32 page_id,
- const std::vector<FaviconURL>& urls) {
+ const std::vector<content::FaviconURL>& urls) {
VLOG(1) << "PrerenderContents::OnUpdateFaviconURL" << icon_url_;
- for (std::vector<FaviconURL>::const_iterator it = urls.begin();
+ for (std::vector<content::FaviconURL>::const_iterator it = urls.begin();
it != urls.end(); ++it) {
- if (it->icon_type == FaviconURL::FAVICON) {
+ if (it->icon_type == content::FaviconURL::FAVICON) {
icon_url_ = it->icon_url;
VLOG(1) << icon_url_;
return;
diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h
index 7461937..8db24c7 100644
--- a/chrome/browser/prerender/prerender_contents.h
+++ b/chrome/browser/prerender/prerender_contents.h
@@ -24,13 +24,13 @@
class Profile;
class TabContents;
-struct FaviconURL;
namespace base {
class ProcessMetrics;
}
namespace content {
+struct FaviconURL;
class RenderViewHost;
class SessionStorageNamespace;
class WebContents;
@@ -202,6 +202,8 @@ class PrerenderContents : public content::NotificationObserver,
const GURL& validated_url,
bool is_main_frame,
content::RenderViewHost* render_view_host) OVERRIDE;
+ virtual void DidUpdateFaviconURL(int32 page_id,
+ const std::vector<content::FaviconURL>& urls) OVERRIDE;
virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
@@ -294,9 +296,6 @@ class PrerenderContents : public content::NotificationObserver,
friend class PrerenderRenderViewHostObserver;
- // Message handlers.
- void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls);
-
// Returns the RenderViewHost Delegate for this prerender.
content::WebContents* GetWebContents();
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index 1cab97e..8dbbf53 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -54,6 +54,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view.h"
+#include "content/public/common/favicon_url.h"
using content::BrowserThread;
using content::RenderViewHost;
@@ -451,10 +452,10 @@ bool PrerenderManager::MaybeUsePrerenderedPage(WebContents* web_contents,
GURL icon_url = prerender_contents->icon_url();
if (!icon_url.is_empty()) {
- std::vector<FaviconURL> urls;
- urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON));
+ std::vector<content::FaviconURL> urls;
+ urls.push_back(content::FaviconURL(icon_url, content::FaviconURL::FAVICON));
FaviconTabHelper::FromWebContents(new_tab_contents->web_contents())->
- OnUpdateFaviconURL(prerender_contents->page_id(), urls);
+ DidUpdateFaviconURL(prerender_contents->page_id(), urls);
}
// Update PPLT metrics:
diff --git a/chrome/browser/prerender/prerender_render_view_host_observer.cc b/chrome/browser/prerender/prerender_render_view_host_observer.cc
index fdc6342..7317b61 100644
--- a/chrome/browser/prerender/prerender_render_view_host_observer.cc
+++ b/chrome/browser/prerender/prerender_render_view_host_observer.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/prerender/prerender_render_view_host_observer.h"
#include "chrome/browser/prerender/prerender_contents.h"
-#include "chrome/common/icon_messages.h"
#include "chrome/common/render_messages.h"
using content::RenderViewHost;
@@ -34,7 +33,6 @@ bool PrerenderRenderViewHostObserver::OnMessageReceived(
bool handled = true;
// The following messages we do want to consume.
IPC_BEGIN_MESSAGE_MAP(PrerenderRenderViewHostObserver, message)
- IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_MaybeCancelPrerenderForHTML5Media,
OnMaybeCancelPrerenderForHTML5Media)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CancelPrerenderForPrinting,
@@ -55,12 +53,6 @@ bool PrerenderRenderViewHostObserver::Send(IPC::Message* message) {
return content::RenderViewHostObserver::Send(message);
}
-void PrerenderRenderViewHostObserver::OnUpdateFaviconURL(
- int32 page_id,
- const std::vector<FaviconURL>& urls) {
- prerender_contents_->OnUpdateFaviconURL(page_id, urls);
-}
-
void PrerenderRenderViewHostObserver::OnMaybeCancelPrerenderForHTML5Media() {
prerender_contents_->Destroy(FINAL_STATUS_HTML5_MEDIA);
}
diff --git a/chrome/browser/prerender/prerender_render_view_host_observer.h b/chrome/browser/prerender/prerender_render_view_host_observer.h
index e6ecf8e..c804b86 100644
--- a/chrome/browser/prerender/prerender_render_view_host_observer.h
+++ b/chrome/browser/prerender/prerender_render_view_host_observer.h
@@ -9,9 +9,8 @@
#include "content/public/browser/render_view_host_observer.h"
-struct FaviconURL;
-
namespace content {
+struct FaviconURL;
class RenderViewHost;
}
@@ -40,7 +39,7 @@ class PrerenderRenderViewHostObserver : public content::RenderViewHostObserver {
private:
// Message handlers.
- void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls);
+
void OnMaybeCancelPrerenderForHTML5Media();
void OnCancelPrerenderForPrinting();
diff --git a/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc b/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
index 468d7da..1969041 100644
--- a/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
@@ -5,14 +5,11 @@
#include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
#include "base/logging.h"
-#include "chrome/browser/favicon/favicon_download_helper.h"
-#include "chrome/browser/favicon/favicon_download_helper_delegate.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
-#include "chrome/common/favicon_url.h"
-#include "chrome/common/icon_messages.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_observer.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -26,12 +23,14 @@ const int kMaxBitmapSize = 256;
// These icon bitmaps are not resized and are not cached beyond the lifetime
// of the class. Bitmaps larger than kMaxBitmapSize are ignored.
-class FaviconBitmapHandler : public FaviconDownloadHelperDelegate {
+class FaviconBitmapHandler : public content::WebContentsObserver {
public:
FaviconBitmapHandler(content::WebContents* web_contents,
LauncherFaviconLoader::Delegate* delegate)
- : delegate_(delegate) {
- download_helper_.reset(new FaviconDownloadHelper(web_contents, this));
+ : content::WebContentsObserver(web_contents),
+ delegate_(delegate),
+ web_contents_(web_contents),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
}
~FaviconBitmapHandler() {}
@@ -40,25 +39,24 @@ class FaviconBitmapHandler : public FaviconDownloadHelperDelegate {
bool HasPendingDownloads() const;
- // FaviconDownloadHelperDelegate methods
- virtual void OnUpdateFaviconURL(
+ // content::WebContentObserver implementation.
+ virtual void DidUpdateFaviconURL(
int32 page_id,
- const std::vector<FaviconURL>& candidates) OVERRIDE;
-
- virtual void OnDidDownloadFavicon(
- int id,
- const GURL& image_url,
- bool errored,
- int requested_size,
- const std::vector<SkBitmap>& bitmaps) OVERRIDE;
+ const std::vector<content::FaviconURL>& candidates) OVERRIDE;
private:
- void DownloadFavicon(const GURL& image_url);
+ void DidDownloadFavicon(
+ int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps);
+
void AddFavicon(const GURL& image_url, const SkBitmap& new_bitmap);
LauncherFaviconLoader::Delegate* delegate_;
- scoped_ptr<FaviconDownloadHelper> download_helper_;
+ content::WebContents* web_contents_;
typedef std::set<GURL> UrlSet;
// Map of pending download urls.
@@ -69,12 +67,14 @@ class FaviconBitmapHandler : public FaviconDownloadHelperDelegate {
SkBitmap bitmap_;
GURL bitmap_url_;
+ base::WeakPtrFactory<FaviconBitmapHandler> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(FaviconBitmapHandler);
};
-void FaviconBitmapHandler::OnUpdateFaviconURL(
+void FaviconBitmapHandler::DidUpdateFaviconURL(
int32 page_id,
- const std::vector<FaviconURL>& candidates) {
+ const std::vector<content::FaviconURL>& candidates) {
// This function receives a complete list of faviocn urls for the page.
// It may get called multiple times with the same list, and will also get
// called any time an item is added or removed. As such, we track processed
@@ -82,9 +82,9 @@ void FaviconBitmapHandler::OnUpdateFaviconURL(
UrlSet new_pending, new_processed;
// Create a map of valid favicon urls.
std::set<GURL> urls;
- for (std::vector<FaviconURL>::const_iterator iter = candidates.begin();
- iter != candidates.end(); ++iter) {
- if (iter->icon_type != FaviconURL::FAVICON)
+ std::vector<content::FaviconURL>::const_iterator iter;
+ for (iter = candidates.begin(); iter != candidates.end(); ++iter) {
+ if (iter->icon_type != content::FaviconURL::FAVICON)
continue;
const GURL& url = iter->icon_url;
if (url.is_valid())
@@ -110,11 +110,17 @@ void FaviconBitmapHandler::OnUpdateFaviconURL(
if (pending_requests_.find(*iter) != pending_requests_.end())
continue; // Skip already pending downloads.
pending_requests_.insert(*iter);
- download_helper_->DownloadFavicon(*iter, 0);
+ web_contents_->DownloadFavicon(*iter, 0,
+ base::Bind(&FaviconBitmapHandler::DidDownloadFavicon,
+ weak_ptr_factory_.GetWeakPtr()));
}
}
-void FaviconBitmapHandler::OnDidDownloadFavicon(
+bool FaviconBitmapHandler::HasPendingDownloads() const {
+ return !pending_requests_.empty();
+}
+
+void FaviconBitmapHandler::DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
@@ -132,10 +138,6 @@ void FaviconBitmapHandler::OnDidDownloadFavicon(
AddFavicon(image_url, bitmaps[0]);
}
-bool FaviconBitmapHandler::HasPendingDownloads() const {
- return !pending_requests_.empty();
-}
-
void FaviconBitmapHandler::AddFavicon(const GURL& image_url,
const SkBitmap& new_bitmap) {
processed_requests_.insert(image_url);
diff --git a/chrome/browser/ui/ash/launcher/launcher_favicon_loader.h b/chrome/browser/ui/ash/launcher/launcher_favicon_loader.h
index 2fd0302..6327c02 100644
--- a/chrome/browser/ui/ash/launcher/launcher_favicon_loader.h
+++ b/chrome/browser/ui/ash/launcher/launcher_favicon_loader.h
@@ -9,7 +9,7 @@
#include "base/basictypes.h"
#include "base/callback.h"
-#include "chrome/common/favicon_url.h"
+#include "content/public/common/favicon_url.h"
class GURL;
class SkBitmap;
diff --git a/chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc b/chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc
index cd1173c..c06e2ab 100644
--- a/chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc
@@ -5,19 +5,19 @@
#include <vector>
#include "base/file_path.h"
+#include "base/stringprintf.h"
#include "base/time.h"
#include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
-#include "chrome/common/favicon_url.h"
-#include "chrome/common/icon_messages.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
+#include "content/public/common/favicon_url.h"
#include "net/test/test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -39,22 +39,13 @@ class ContentsObserver : public content::WebContentsObserver {
}
// content::WebContentsObserver overrides.
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
- bool message_handled = false; // Allow other handlers to receive these.
- IPC_BEGIN_MESSAGE_MAP(ContentsObserver, message)
- IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
- IPC_MESSAGE_UNHANDLED(message_handled = false)
- IPC_END_MESSAGE_MAP()
- return message_handled;
- }
-
- private:
- void OnUpdateFaviconURL(int32 page_id,
- const std::vector<FaviconURL>& candidates) {
+ virtual void DidUpdateFaviconURL(int32 page_id,
+ const std::vector<content::FaviconURL>& candidates) OVERRIDE {
if (!candidates.empty())
got_favicons_ = true;
}
+ private:
bool got_favicons_;
};
diff --git a/chrome/browser/ui/metro_pin_tab_helper_win.cc b/chrome/browser/ui/metro_pin_tab_helper_win.cc
index 195b8cc..5d5c22a 100644
--- a/chrome/browser/ui/metro_pin_tab_helper_win.cc
+++ b/chrome/browser/ui/metro_pin_tab_helper_win.cc
@@ -18,12 +18,10 @@
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/win/metro.h"
-#include "chrome/browser/favicon/favicon_download_helper.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/favicon/favicon_util.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/common/chrome_paths.h"
-#include "chrome/common/icon_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "crypto/sha2.h"
@@ -368,9 +366,7 @@ void MetroPinTabHelper::FaviconChooser::AddPendingRequest(int request_id) {
}
MetroPinTabHelper::MetroPinTabHelper(content::WebContents* web_contents)
- : content::WebContentsObserver(web_contents),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- favicon_download_helper_(web_contents, this)) {
+ : content::WebContentsObserver(web_contents) {
}
MetroPinTabHelper::~MetroPinTabHelper() {}
@@ -425,12 +421,14 @@ void MetroPinTabHelper::TogglePinnedToStartScreen() {
// Request all the candidates.
int image_size = 0; // Request the full sized image.
- for (std::vector<FaviconURL>::const_iterator iter =
+ for (std::vector<content::FaviconURL>::const_iterator iter =
favicon_url_candidates_.begin();
iter != favicon_url_candidates_.end();
++iter) {
favicon_chooser_->AddPendingRequest(
- favicon_download_helper_.DownloadFavicon(iter->icon_url, image_size));
+ web_contents()->DownloadFavicon(iter->icon_url, image_size,
+ base::Bind(&MetroPinTabHelper::DidDownloadFavicon,
+ base::Unretained(this))));
}
}
@@ -446,13 +444,13 @@ void MetroPinTabHelper::DidNavigateMainFrame(
favicon_url_candidates_.clear();
}
-void MetroPinTabHelper::OnUpdateFaviconURL(
+void MetroPinTabHelper::DidUpdateFaviconURL(
int32 page_id,
- const std::vector<FaviconURL>& candidates) {
+ const std::vector<content::FaviconURL>& candidates) {
favicon_url_candidates_ = candidates;
}
-void MetroPinTabHelper::OnDidDownloadFavicon(
+void MetroPinTabHelper::DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
diff --git a/chrome/browser/ui/metro_pin_tab_helper_win.h b/chrome/browser/ui/metro_pin_tab_helper_win.h
index 45b1573..63770ce 100644
--- a/chrome/browser/ui/metro_pin_tab_helper_win.h
+++ b/chrome/browser/ui/metro_pin_tab_helper_win.h
@@ -7,19 +7,16 @@
#include <vector>
-#include "chrome/browser/favicon/favicon_download_helper.h"
-#include "chrome/browser/favicon/favicon_download_helper_delegate.h"
-#include "chrome/common/favicon_url.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
+#include "content/public/common/favicon_url.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image_skia.h"
// Per-tab class to help manage metro pinning.
class MetroPinTabHelper
: public content::WebContentsObserver,
- public content::WebContentsUserData<MetroPinTabHelper>,
- public FaviconDownloadHelperDelegate {
+ public content::WebContentsUserData<MetroPinTabHelper> {
public:
virtual ~MetroPinTabHelper();
@@ -31,6 +28,9 @@ class MetroPinTabHelper
virtual void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) OVERRIDE;
+ virtual void DidUpdateFaviconURL(
+ int32 page_id,
+ const std::vector<content::FaviconURL>& candidates) OVERRIDE;
private:
// The FaviconDownloader class handles downloading the favicons when a page
@@ -41,29 +41,24 @@ class MetroPinTabHelper
explicit MetroPinTabHelper(content::WebContents* tab_contents);
friend class content::WebContentsUserData<MetroPinTabHelper>;
- // FaviconDownloadHelperDelegate overrides.
- void OnUpdateFaviconURL(int32 page_id,
- const std::vector<FaviconURL>& candidates) OVERRIDE;
-
- void OnDidDownloadFavicon(int id,
- const GURL& image_url,
- bool errored,
- int requested_size,
- const std::vector<SkBitmap>& bitmaps) OVERRIDE;
+ // Favicon download callback.
+ void DidDownloadFavicon(int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps);
void UnPinPageFromStartScreen();
- // Called by the |favicon_downloader_| when it has finished.
+ // Called by the |favicon_chooser_| when it has finished.
void FaviconDownloaderFinished();
// Candidate Favicon URLs for the current page.
- std::vector<FaviconURL> favicon_url_candidates_;
+ std::vector<content::FaviconURL> favicon_url_candidates_;
// The currently active FaviconChooser, if there is one.
scoped_ptr<FaviconChooser> favicon_chooser_;
- // FaviconDownloadHelper handles the sending and listening for IPC messages.
- FaviconDownloadHelper favicon_download_helper_;
DISALLOW_COPY_AND_ASSIGN(MetroPinTabHelper);
};
diff --git a/chrome/browser/ui/views/ash/balloon_view_ash.cc b/chrome/browser/ui/views/ash/balloon_view_ash.cc
index 0e3d242..c0ea83f 100644
--- a/chrome/browser/ui/views/ash/balloon_view_ash.cc
+++ b/chrome/browser/ui/views/ash/balloon_view_ash.cc
@@ -9,12 +9,10 @@
#include "base/logging.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/favicon/favicon_download_helper.h"
#include "chrome/browser/favicon/favicon_util.h"
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/icon_messages.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
@@ -39,7 +37,8 @@ message_center::MessageCenter* GetMessageCenter() {
BalloonViewAsh::BalloonViewAsh(BalloonCollection* collection)
: collection_(collection),
- balloon_(NULL) {
+ balloon_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
}
BalloonViewAsh::~BalloonViewAsh() {
@@ -90,6 +89,20 @@ BalloonHost* BalloonViewAsh::GetHost() const {
return NULL;
}
+void BalloonViewAsh::DidDownloadFavicon(
+ int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps) {
+ if (id != current_download_id_ || bitmaps.empty())
+ return;
+ GetMessageCenter()->SetNotificationImage(
+ cached_notification_id_, gfx::ImageSkia(bitmaps[0]));
+ current_download_id_ = -1;
+ cached_notification_id_.clear();
+}
+
void BalloonViewAsh::FetchIcon(const Notification& notification) {
if (!notification.icon().isNull()) {
GetMessageCenter()->SetNotificationImage(
@@ -109,26 +122,13 @@ void BalloonViewAsh::FetchIcon(const Notification& notification) {
LOG(WARNING) << "Notification has icon url but no WebContents";
return;
}
- icon_fetcher_.reset(new FaviconDownloadHelper(web_contents, this));
- current_download_id_ = icon_fetcher_->DownloadFavicon(
- notification.icon_url(), kNotificationIconImageSize);
+ current_download_id_ = web_contents->DownloadFavicon(
+ notification.icon_url(), kNotificationIconImageSize,
+ base::Bind(&BalloonViewAsh::DidDownloadFavicon,
+ weak_ptr_factory_.GetWeakPtr()));
cached_notification_id_ = notification.notification_id();
}
-void BalloonViewAsh::OnDidDownloadFavicon(
- int id,
- const GURL& image_url,
- bool errored,
- int requested_size,
- const std::vector<SkBitmap>& bitmaps) {
- if (id != current_download_id_ || bitmaps.empty())
- return;
- GetMessageCenter()->SetNotificationImage(
- cached_notification_id_, gfx::ImageSkia(bitmaps[0]));
- current_download_id_ = -1;
- cached_notification_id_.clear();
-}
-
std::string BalloonViewAsh::GetExtensionId(Balloon* balloon) {
ExtensionService* extension_service =
balloon_->profile()->GetExtensionService();
diff --git a/chrome/browser/ui/views/ash/balloon_view_ash.h b/chrome/browser/ui/views/ash/balloon_view_ash.h
index ff56d34..097a93c 100644
--- a/chrome/browser/ui/views/ash/balloon_view_ash.h
+++ b/chrome/browser/ui/views/ash/balloon_view_ash.h
@@ -5,16 +5,16 @@
#ifndef CHROME_BROWSER_UI_VIEWS_ASH_BALLOON_VIEW_ASH_H_
#define CHROME_BROWSER_UI_VIEWS_ASH_BALLOON_VIEW_ASH_H_
-#include <map>
+#include <vector>
-#include "chrome/browser/favicon/favicon_download_helper_delegate.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/notifications/balloon.h"
-class FaviconDownloadHelper;
+class GURL;
+class SkBitmap;
// On Ash, a "BalloonView" is just a wrapper for ash notification entries.
-class BalloonViewAsh : public BalloonView,
- public FaviconDownloadHelperDelegate {
+class BalloonViewAsh : public BalloonView {
public:
explicit BalloonViewAsh(BalloonCollection* collection);
virtual ~BalloonViewAsh();
@@ -27,27 +27,26 @@ class BalloonViewAsh : public BalloonView,
virtual gfx::Size GetSize() const OVERRIDE;
virtual BalloonHost* GetHost() const OVERRIDE;
- // FaviconDownloadHelperDelegate interface:
- virtual void OnDidDownloadFavicon(
+ private:
+ // Favicon download callback.
+ void DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
int requested_size,
- const std::vector<SkBitmap>& bitmaps) OVERRIDE;
-
- private:
+ const std::vector<SkBitmap>& bitmaps);
void FetchIcon(const Notification& notification);
std::string GetExtensionId(Balloon* balloon);
BalloonCollection* collection_;
Balloon* balloon_;
- scoped_ptr<FaviconDownloadHelper> icon_fetcher_;
// Track the current notification id and download id so that it can be updated
// properly.
int current_download_id_;
std::string current_notification_id_;
std::string cached_notification_id_;
+ base::WeakPtrFactory<BalloonViewAsh> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BalloonViewAsh);
};
diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc
index 6b63f21..df9eb50 100644
--- a/chrome/browser/ui/views/create_application_shortcut_view.cc
+++ b/chrome/browser/ui/views/create_application_shortcut_view.cc
@@ -11,7 +11,6 @@
#include "base/utf_string_conversions.h"
#include "base/win/windows_version.h"
#include "chrome/browser/extensions/tab_helper.h"
-#include "chrome/browser/favicon/favicon_download_helper.h"
#include "chrome/browser/favicon/favicon_util.h"
#include "chrome/browser/history/select_favicon_frames.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -28,7 +27,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
+#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
@@ -445,18 +444,17 @@ void CreateUrlApplicationShortcutView::FetchIcon() {
if (unprocessed_icons_.empty()) // No icons to fetch.
return;
- if (!download_helper_.get())
- download_helper_.reset(new FaviconDownloadHelper(web_contents_, this));
-
- pending_download_id_ = download_helper_->DownloadFavicon(
+ pending_download_id_ = web_contents_->DownloadFavicon(
unprocessed_icons_.back().url,
std::max(unprocessed_icons_.back().width,
- unprocessed_icons_.back().height));
+ unprocessed_icons_.back().height),
+ base::Bind(&CreateUrlApplicationShortcutView::DidDownloadFavicon,
+ base::Unretained(this)));
unprocessed_icons_.pop_back();
}
-void CreateUrlApplicationShortcutView::OnDidDownloadFavicon(
+void CreateUrlApplicationShortcutView::DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
diff --git a/chrome/browser/ui/views/create_application_shortcut_view.h b/chrome/browser/ui/views/create_application_shortcut_view.h
index db41f63..d2eeddb 100644
--- a/chrome/browser/ui/views/create_application_shortcut_view.h
+++ b/chrome/browser/ui/views/create_application_shortcut_view.h
@@ -11,12 +11,12 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
-#include "chrome/browser/favicon/favicon_download_helper_delegate.h"
#include "chrome/browser/web_applications/web_app.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/window/dialog_delegate.h"
class FaviconDownloadHelper;
+class GURL;
class Profile;
class SkBitmap;
@@ -85,8 +85,7 @@ class CreateApplicationShortcutView : public views::DialogDelegateView,
};
// Create an application shortcut pointing to a URL.
-class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView,
- public FaviconDownloadHelperDelegate {
+class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView {
public:
explicit CreateUrlApplicationShortcutView(content::WebContents* web_contents);
virtual ~CreateUrlApplicationShortcutView();
@@ -98,20 +97,17 @@ class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView,
// The first largest icon downloaded and decoded successfully will be used.
void FetchIcon();
- // FaviconDownloadHelperDelegate overrides.
- virtual void OnDidDownloadFavicon(
+ // Favicon download callback.
+ void DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
int requested_size,
- const std::vector<SkBitmap>& bitmaps) OVERRIDE;
+ const std::vector<SkBitmap>& bitmaps);
// The tab whose URL is being turned into an app.
content::WebContents* web_contents_;
- // Helper class to manage the downloading of favicons.
- scoped_ptr<FaviconDownloadHelper> download_helper_;
-
// Pending app icon download tracked by us.
int pending_download_id_;
diff --git a/chrome/browser/ui/web_applications/web_app_ui.cc b/chrome/browser/ui/web_applications/web_app_ui.cc
index a7f9b98..abfd9b4 100644
--- a/chrome/browser/ui/web_applications/web_app_ui.cc
+++ b/chrome/browser/ui/web_applications/web_app_ui.cc
@@ -11,8 +11,6 @@
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/tab_helper.h"
-#include "chrome/browser/favicon/favicon_download_helper.h"
-#include "chrome/browser/favicon/favicon_download_helper_delegate.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/favicon/favicon_util.h"
#include "chrome/browser/profiles/profile.h"
@@ -24,6 +22,8 @@
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
+#include "googleurl/src/gurl.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#if defined(OS_POSIX) && !defined(OS_MACOSX)
#include "base/environment.h"
@@ -46,8 +46,7 @@ namespace {
// updated. If there are such shortcuts, it schedules icon download and
// update them when icons are downloaded. It observes TAB_CLOSING notification
// and cancels all the work when the underlying tab is closing.
-class UpdateShortcutWorker : public content::NotificationObserver,
- public FaviconDownloadHelperDelegate {
+class UpdateShortcutWorker : public content::NotificationObserver {
public:
explicit UpdateShortcutWorker(WebContents* web_contents);
@@ -62,13 +61,13 @@ class UpdateShortcutWorker : public content::NotificationObserver,
// Downloads icon via the FaviconTabHelper.
void DownloadIcon();
- // FaviconDownloadHelperDelegate override.
- virtual void OnDidDownloadFavicon(
+ // Favicon download callback.
+ void DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
int requested_size,
- const std::vector<SkBitmap>& bitmaps) OVERRIDE;
+ const std::vector<SkBitmap>& bitmaps);
// Checks if shortcuts exists on desktop, start menu and quick launch.
void CheckExistingShortcuts();
@@ -157,26 +156,21 @@ void UpdateShortcutWorker::DownloadIcon() {
return;
}
- scoped_ptr<FaviconDownloadHelper> download_helper(
- new FaviconDownloadHelper(web_contents_, this));
-
- download_helper->DownloadFavicon(unprocessed_icons_.back().url,
- std::max(unprocessed_icons_.back().width,
- unprocessed_icons_.back().height));
+ web_contents_->DownloadFavicon(
+ unprocessed_icons_.back().url,
+ std::max(unprocessed_icons_.back().width,
+ unprocessed_icons_.back().height),
+ base::Bind(&UpdateShortcutWorker::DidDownloadFavicon,
+ base::Unretained(this)));
unprocessed_icons_.pop_back();
}
-void UpdateShortcutWorker::OnDidDownloadFavicon(
+void UpdateShortcutWorker::DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
int requested_size,
const std::vector<SkBitmap>& bitmaps) {
- if (web_contents_ == NULL) {
- DeleteMe(); // We are done if underlying WebContents is gone.
- return;
- }
-
std::vector<ui::ScaleFactor> scale_factors;
scale_factors.push_back(ui::SCALE_FACTOR_100P);
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
index 58575f9..d899c96 100644
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
@@ -39,12 +39,12 @@
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_icon_set.h"
#include "chrome/common/extensions/extension_resource.h"
-#include "chrome/common/favicon_url.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/web_apps.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_ui.h"
+#include "content/public/common/favicon_url.h"
#include "googleurl/src/gurl.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 793e473..8241bc2 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -585,9 +585,6 @@
'browser/external_protocol/external_protocol_observer.cc',
'browser/external_protocol/external_protocol_observer.h',
'browser/external_tab/external_tab_container.h',
- 'browser/favicon/favicon_download_helper.cc',
- 'browser/favicon/favicon_download_helper.h',
- 'browser/favicon/favicon_download_helper_delegate.h',
'browser/favicon/favicon_handler.cc',
'browser/favicon/favicon_handler.h',
'browser/favicon/favicon_handler_delegate.h',
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index 09f5044..1bbf113 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -217,8 +217,6 @@
'common/extensions/api/extension_api_stub.cc',
'common/external_ipc_fuzzer.h',
'common/external_ipc_fuzzer.cc',
- 'common/favicon_url.cc',
- 'common/favicon_url.h',
'common/form_data.cc',
'common/form_data.h',
'common/form_data_predictions.cc',
@@ -227,7 +225,6 @@
'common/form_field_data.h',
'common/form_field_data_predictions.cc',
'common/form_field_data_predictions.h',
- 'common/icon_messages.h',
'common/icon_with_badge_image_source.cc',
'common/icon_with_badge_image_source.h',
'common/instant_types.cc',
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index 102d02b..fb97800 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -129,8 +129,6 @@
'renderer/extensions/web_request_custom_bindings.h',
'renderer/extensions/webstore_bindings.cc',
'renderer/extensions/webstore_bindings.h',
- 'renderer/favicon_helper.cc',
- 'renderer/favicon_helper.h',
'renderer/frame_sniffer.cc',
'renderer/frame_sniffer.h',
'renderer/loadtimes_extension_bindings.h',
diff --git a/chrome/common/common_message_generator.h b/chrome/common/common_message_generator.h
index b6c06e9..9631798 100644
--- a/chrome/common/common_message_generator.h
+++ b/chrome/common/common_message_generator.h
@@ -8,7 +8,6 @@
#include "chrome/common/benchmarking_messages.h"
#include "chrome/common/chrome_utility_messages.h"
#include "chrome/common/extensions/extension_messages.h"
-#include "chrome/common/icon_messages.h"
#include "chrome/common/prerender_messages.h"
#include "chrome/common/print_messages.h"
#include "chrome/common/render_messages.h"
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index c7b30ab2..eb60f95 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -43,7 +43,6 @@
#include "chrome/renderer/extensions/miscellaneous_bindings.h"
#include "chrome/renderer/extensions/resource_request_policy.h"
#include "chrome/renderer/external_extension.h"
-#include "chrome/renderer/favicon_helper.h"
#include "chrome/renderer/loadtimes_extension_bindings.h"
#include "chrome/renderer/net/renderer_net_predictor.h"
#include "chrome/renderer/page_click_tracker.h"
@@ -305,8 +304,6 @@ void ChromeContentRendererClient::RenderViewCreated(
new PepperHelper(render_view);
#endif
- // FaviconHelper will delete itself when render_view is destroyed.
- new FaviconHelper(render_view);
// Used only for testing/automation.
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDomAutomationController)) {
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc
index b0503bb..8c764b5 100644
--- a/chrome/renderer/chrome_render_view_observer.cc
+++ b/chrome/renderer/chrome_render_view_observer.cc
@@ -13,7 +13,6 @@
#include "base/string_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/favicon_url.h"
#include "chrome/common/prerender_messages.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 7cc55b8..e4e4e6d 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"
@@ -148,6 +149,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 +758,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 +1964,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 +2387,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_,
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index 2478406..cb4fdae 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -62,6 +62,7 @@ class WebContentsImpl;
class WebContentsObserver;
class WebContentsView;
class WebContentsViewDelegate;
+struct FaviconURL;
struct LoadNotificationDetails;
// Factory function for the implementations that content knows about. Takes
@@ -277,6 +278,8 @@ class CONTENT_EXPORT WebContentsImpl
virtual void DidChooseColorInColorChooser(int color_chooser_id,
SkColor color) OVERRIDE;
virtual void DidEndColorChooser(int color_chooser_id) OVERRIDE;
+ virtual int DownloadFavicon(const GURL& url, int image_size,
+ const FaviconDownloadCallback& callback) OVERRIDE;
// Implementation of PageNavigator.
virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE;
@@ -571,6 +574,13 @@ class CONTENT_EXPORT WebContentsImpl
void OnBrowserPluginCreateGuest(
int instance_id,
const BrowserPluginHostMsg_CreateGuest_Params& params);
+ void OnDidDownloadFavicon(int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps);
+ void OnUpdateFaviconURL(int32 page_id,
+ const std::vector<FaviconURL>& candidates);
// Changes the IsLoading state and notifies delegate as needed
// |details| is used to provide details on the load that just finished
@@ -858,6 +868,10 @@ class CONTENT_EXPORT WebContentsImpl
// outlive it.
std::set<RenderWidgetHostImpl*> created_widgets_;
+ // Maps the ids of pending favicon downloads to their callbacks
+ typedef std::map<int, FaviconDownloadCallback> FaviconDownloadMap;
+ FaviconDownloadMap favicon_download_map_;
+
DISALLOW_COPY_AND_ASSIGN(WebContentsImpl);
};
diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h
index 805a787..a11172e 100644
--- a/content/common/content_message_generator.h
+++ b/content/common/content_message_generator.h
@@ -26,6 +26,7 @@
#include "content/common/geolocation_messages.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/hyphenator_messages.h"
+#include "content/common/icon_messages.h"
#include "content/common/indexed_db/indexed_db_messages.h"
#include "content/common/intents_messages.h"
#include "content/common/java_bridge_messages.h"
diff --git a/chrome/common/icon_messages.h b/content/common/icon_messages.h
index 26e8f14..2cf1c15 100644
--- a/chrome/common/icon_messages.h
+++ b/content/common/icon_messages.h
@@ -5,7 +5,7 @@
// Multiply-included message file, no traditional include guard.
#include <vector>
-#include "chrome/common/favicon_url.h"
+#include "content/public/common/favicon_url.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_param_traits.h"
@@ -13,9 +13,9 @@
#define IPC_MESSAGE_START IconMsgStart
-IPC_ENUM_TRAITS(FaviconURL::IconType)
+IPC_ENUM_TRAITS(content::FaviconURL::IconType)
-IPC_STRUCT_TRAITS_BEGIN(FaviconURL)
+IPC_STRUCT_TRAITS_BEGIN(content::FaviconURL)
IPC_STRUCT_TRAITS_MEMBER(icon_url)
IPC_STRUCT_TRAITS_MEMBER(icon_type)
IPC_STRUCT_TRAITS_END()
@@ -35,7 +35,7 @@ IPC_MESSAGE_ROUTED3(IconMsg_DownloadFavicon,
// Notification that the urls for the favicon of a site has been determined.
IPC_MESSAGE_ROUTED2(IconHostMsg_UpdateFaviconURL,
int32 /* page_id */,
- std::vector<FaviconURL> /* urls of the favicon */)
+ std::vector<content::FaviconURL> /* urls of the favicon */)
IPC_MESSAGE_ROUTED5(IconHostMsg_DidDownloadFavicon,
int /* Identifier of the request */,
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 8c5c4ca..3a7f550 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -39,6 +39,8 @@
'public/common/console_message_level.h',
'public/common/dx_diag_node.cc',
'public/common/dx_diag_node.h',
+ 'public/common/favicon_url.cc',
+ 'public/common/favicon_url.h',
'public/common/file_chooser_params.cc',
'public/common/file_chooser_params.h',
'public/common/frame_navigate_params.cc',
@@ -253,6 +255,7 @@
'common/gpu/texture_image_transport_surface.cc',
'common/handle_enumerator_win.cc',
'common/handle_enumerator_win.h',
+ 'common/icon_messages.h',
'common/indexed_db/indexed_db_key.cc',
'common/indexed_db/indexed_db_key.h',
'common/indexed_db/indexed_db_key_path.cc',
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 3058717..f296b70 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -81,6 +81,8 @@
'renderer/dom_storage/webstoragenamespace_impl.h',
'renderer/external_popup_menu.cc',
'renderer/external_popup_menu.h',
+ 'renderer/favicon_helper.cc',
+ 'renderer/favicon_helper.h',
'renderer/gamepad_shared_memory_reader.cc',
'renderer/gamepad_shared_memory_reader.h',
'renderer/geolocation_dispatcher.cc',
@@ -139,7 +141,7 @@
'renderer/media/renderer_webaudiodevice_impl.cc',
'renderer/media/renderer_webaudiodevice_impl.h',
'renderer/media/rtc_media_constraints.cc',
- 'renderer/media/rtc_media_constraints.h',
+ 'renderer/media/rtc_media_constraints.h',
'renderer/media/rtc_video_decoder.cc',
'renderer/media/rtc_video_decoder.h',
'renderer/media/rtc_video_renderer.cc',
@@ -334,7 +336,7 @@
'../third_party/libjingle/libjingle.gyp:libjingle_p2p',
'../third_party/libjingle/libjingle.gyp:libjingle_peerconnection',
'../third_party/webrtc/system_wrappers/source/system_wrappers.gyp:system_wrappers',
- '../third_party/webrtc/modules/modules.gyp:audio_device',
+ '../third_party/webrtc/modules/modules.gyp:audio_device',
'../third_party/webrtc/video_engine/video_engine.gyp:video_engine_core',
'../third_party/webrtc/voice_engine/voice_engine.gyp:voice_engine_core',
'<(DEPTH)/crypto/crypto.gyp:crypto',
@@ -353,7 +355,7 @@
'renderer/media/rtc_video_capturer.cc',
'renderer/media/rtc_video_capturer.h',
'renderer/media/webrtc_audio_capturer.cc',
- 'renderer/media/webrtc_audio_capturer.h',
+ 'renderer/media/webrtc_audio_capturer.h',
'renderer/media/webrtc_audio_device_impl.cc',
'renderer/media/webrtc_audio_device_impl.h',
'renderer/media/webrtc_audio_renderer.cc',
diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h
index cab59f0..ebb06df 100644
--- a/content/public/browser/web_contents.h
+++ b/content/public/browser/web_contents.h
@@ -393,6 +393,23 @@ class WebContents : public PageNavigator,
// Does this have an opener associated with it?
virtual bool HasOpener() const = 0;
+
+ typedef base::Callback<void(int, /* id */
+ const GURL&, /* image_url */
+ bool, /* errored */
+ int, /* requested_size */
+ const std::vector<SkBitmap>& /* bitmaps*/)>
+ FaviconDownloadCallback;
+
+ // Sends a request to download the given favicon |url| and returns the unique
+ // id of the download request. When the download is finished, |callback| will
+ // be called with the bitmaps received from the renderer. Note that
+ // |image_size| is a hint for images with multiple sizes. The downloaded image
+ // is not resized to the given image_size. If 0 is passed, the first frame of
+ // the image is returned.
+ virtual int DownloadFavicon(const GURL& url, int image_size,
+ const FaviconDownloadCallback& callback) = 0;
+
};
} // namespace content
diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h
index 87f5f7e..a037efb 100644
--- a/content/public/browser/web_contents_observer.h
+++ b/content/public/browser/web_contents_observer.h
@@ -19,6 +19,7 @@ namespace content {
class RenderViewHost;
class WebContents;
class WebContentsImpl;
+struct FaviconURL;
struct FrameNavigateParams;
struct LoadCommittedDetails;
struct Referrer;
@@ -142,6 +143,10 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener,
virtual void DidBlock3DAPIs(const GURL& url,
ThreeDAPIType requester) {}
+ // Invoked when new FaviconURL candidates are received from the renderer.
+ virtual void DidUpdateFaviconURL(int32 page_id,
+ const std::vector<FaviconURL>& candidates) {}
+
// IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
diff --git a/chrome/common/favicon_url.cc b/content/public/common/favicon_url.cc
index 8b05d0e..44f12bc6 100644
--- a/chrome/common/favicon_url.cc
+++ b/content/public/common/favicon_url.cc
@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/common/favicon_url.h"
+#include "content/public/common/favicon_url.h"
+
+namespace content {
FaviconURL::FaviconURL()
: icon_type(INVALID_ICON) {
@@ -15,3 +17,5 @@ FaviconURL::FaviconURL(const GURL& url, IconType type)
FaviconURL::~FaviconURL() {
}
+
+} // namespace content
diff --git a/chrome/common/favicon_url.h b/content/public/common/favicon_url.h
index 4da256b..b1d13cb 100644
--- a/chrome/common/favicon_url.h
+++ b/content/public/common/favicon_url.h
@@ -2,13 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_COMMON_FAVICON_URL_
-#define CHROME_COMMON_FAVICON_URL_
+#ifndef CONTENT_PUBLIC_COMMON_FAVICON_URL_
+#define CONTENT_PUBLIC_COMMON_FAVICON_URL_
+#include "content/common/content_export.h"
#include "googleurl/src/gurl.h"
+namespace content {
+
// The favicon url from the render.
-struct FaviconURL {
+struct CONTENT_EXPORT FaviconURL {
// The icon type in a page. The definition must be same as history::IconType.
enum IconType {
INVALID_ICON = 0x0,
@@ -28,4 +31,6 @@ struct FaviconURL {
IconType icon_type;
};
-#endif // CHROME_COMMON_FAVICON_URL_
+} // namespace content
+
+#endif // CONTENT_PUBLIC_COMMON_FAVICON_URL_
diff --git a/content/public/renderer/render_view_observer.h b/content/public/renderer/render_view_observer.h
index b3f63b9..b99dc1d 100644
--- a/content/public/renderer/render_view_observer.h
+++ b/content/public/renderer/render_view_observer.h
@@ -49,8 +49,6 @@ class CONTENT_EXPORT RenderViewObserver : public IPC::Listener,
// These match the WebKit API notifications
virtual void DidStartLoading() {}
virtual void DidStopLoading() {}
- virtual void DidChangeIcon(WebKit::WebFrame* frame,
- WebKit::WebIconURL::Type) {}
virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) {}
virtual void DidFailLoad(WebKit::WebFrame* frame,
const WebKit::WebURLError& error) {}
diff --git a/chrome/renderer/favicon_helper.cc b/content/renderer/favicon_helper.cc
index 8df4839..31d97a8 100644
--- a/chrome/renderer/favicon_helper.cc
+++ b/content/renderer/favicon_helper.cc
@@ -2,19 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/favicon_helper.h"
+#include "content/renderer/favicon_helper.h"
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/message_loop.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/common/favicon_url.h"
-#include "chrome/common/icon_messages.h"
+#include "content/common/icon_messages.h"
#include "content/public/renderer/render_view.h"
#include "net/base/data_url.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
+#include "ui/base/ui_base_switches.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/size.h"
#include "ui/gfx/skbitmap_operations.h"
@@ -29,6 +29,21 @@ using WebKit::WebURL;
using WebKit::WebURLRequest;
using webkit_glue::MultiResolutionImageResourceFetcher;
+namespace content {
+
+namespace {
+bool TouchEnabled() {
+// Based on the definition of chrome::kEnableTouchIcon.
+#if defined(OS_ANDROID)
+ return true;
+#else
+ return false;
+#endif
+}
+
+} // namespace
+
+
static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) {
switch (type) {
case WebIconURL::TypeFavicon:
@@ -43,8 +58,25 @@ static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) {
return FaviconURL::INVALID_ICON;
}
-FaviconHelper::FaviconHelper(content::RenderView* render_view)
- : content::RenderViewObserver(render_view) {
+FaviconHelper::FaviconHelper(RenderView* render_view)
+ : RenderViewObserver(render_view) {
+}
+
+void FaviconHelper::DidChangeIcon(WebKit::WebFrame* frame,
+ WebKit::WebIconURL::Type icon_type) {
+ if (frame->parent())
+ return;
+
+ if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
+ return;
+
+ WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
+ std::vector<FaviconURL> urls;
+ for (size_t i = 0; i < icon_urls.size(); i++) {
+ urls.push_back(FaviconURL(icon_urls[i].iconURL(),
+ ToFaviconType(icon_urls[i].iconType())));
+ }
+ SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls);
}
FaviconHelper::~FaviconHelper() {
@@ -139,7 +171,7 @@ bool FaviconHelper::OnMessageReceived(const IPC::Message& message) {
void FaviconHelper::DidStopLoading() {
int icon_types = WebIconURL::TypeFavicon;
- if (chrome::kEnableTouchIcon)
+ if (TouchEnabled())
icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
WebVector<WebIconURL> icon_urls =
@@ -153,20 +185,4 @@ void FaviconHelper::DidStopLoading() {
SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls);
}
-void FaviconHelper::DidChangeIcon(WebKit::WebFrame* frame,
- WebKit::WebIconURL::Type icon_type) {
- if (frame->parent())
- return;
-
- if (!chrome::kEnableTouchIcon &&
- icon_type != WebIconURL::TypeFavicon)
- return;
-
- WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
- std::vector<FaviconURL> urls;
- for (size_t i = 0; i < icon_urls.size(); i++) {
- urls.push_back(FaviconURL(icon_urls[i].iconURL(),
- ToFaviconType(icon_urls[i].iconType())));
- }
- SendUpdateFaviconURL(routing_id(), render_view()->GetPageId(), urls);
-}
+} // namespace content
diff --git a/chrome/renderer/favicon_helper.h b/content/renderer/favicon_helper.h
index aeccd28..acce508 100644
--- a/chrome/renderer/favicon_helper.h
+++ b/content/renderer/favicon_helper.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_RENDERER_FAVICON_HELPER_H_
-#define CHROME_RENDERER_FAVICON_HELPER_H_
+#ifndef CONTENT_RENDERER_FAVICON_HELPER_H_
+#define CONTENT_RENDERER_FAVICON_HELPER_H_
#include <string>
#include <vector>
@@ -13,18 +13,29 @@
#include "content/public/renderer/render_view_observer.h"
#include "googleurl/src/gurl.h"
-struct FaviconURL;
class SkBitmap;
+namespace content {
+struct FaviconURL;
+}
+
namespace webkit_glue {
class MultiResolutionImageResourceFetcher;
}
+namespace content {
+
+struct FaviconURL;
+
// This class deals with favicon downloading.
// There is one FaviconHelper per RenderView, which is owned by the RenderView.
-class FaviconHelper : public content::RenderViewObserver {
+class FaviconHelper : public RenderViewObserver {
public:
- explicit FaviconHelper(content::RenderView* render_view);
+ explicit FaviconHelper(RenderView* render_view);
+
+ // Sund a message that the favicon has changed.
+ void DidChangeIcon(WebKit::WebFrame* frame,
+ WebKit::WebIconURL::Type icon_type);
private:
virtual ~FaviconHelper();
@@ -60,8 +71,6 @@ class FaviconHelper : public content::RenderViewObserver {
// RenderViewObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void DidStopLoading() OVERRIDE;
- virtual void DidChangeIcon(WebKit::WebFrame* frame,
- WebKit::WebIconURL::Type icon_type) OVERRIDE;
typedef ScopedVector<webkit_glue::MultiResolutionImageResourceFetcher>
ImageResourceFetcherList;
@@ -72,4 +81,6 @@ class FaviconHelper : public content::RenderViewObserver {
DISALLOW_COPY_AND_ASSIGN(FaviconHelper);
};
-#endif // CHROME_RENDERER_FAVICON_HELPER_H_
+} // namespace content
+
+#endif // CONTENT_RENDERER_FAVICON_HELPER_H_
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index c98827e..cd37848 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -73,6 +73,7 @@
#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
#include "content/renderer/do_not_track_bindings.h"
#include "content/renderer/external_popup_menu.h"
+#include "content/renderer/favicon_helper.h"
#include "content/renderer/geolocation_dispatcher.h"
#include "content/renderer/gpu/compositor_thread.h"
#include "content/renderer/gpu/compositor_output_surface.h"
@@ -587,6 +588,7 @@ RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
renderer_accessibility_(NULL),
java_bridge_dispatcher_(NULL),
mouse_lock_dispatcher_(NULL),
+ favicon_helper_(NULL),
#if defined(OS_ANDROID)
body_background_color_(SK_ColorWHITE),
update_frame_info_scheduled_(false),
@@ -705,6 +707,7 @@ RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
devtools_agent_ = new DevToolsAgent(this);
mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
intents_host_ = new WebIntentsHost(this);
+ favicon_helper_ = new FaviconHelper(this);
// Create renderer_accessibility_ if needed.
OnSetAccessibilityMode(params->accessibility_mode);
@@ -3513,8 +3516,7 @@ void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
}
void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
- FOR_EACH_OBSERVER(RenderViewObserver, observers_,
- DidChangeIcon(frame, type));
+ favicon_helper_->DidChangeIcon(frame, type);
}
void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
index 2fd89e7..bd61b92 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -143,6 +143,7 @@ class DevToolsAgent;
class DocumentState;
class DomAutomationController;
class ExternalPopupMenu;
+class FaviconHelper;
class GeolocationDispatcher;
class InputTagSpeechDispatcher;
class JavaBridgeDispatcher;
@@ -1404,6 +1405,9 @@ class CONTENT_EXPORT RenderViewImpl
// Mouse Lock dispatcher attached to this view.
MouseLockDispatcher* mouse_lock_dispatcher_;
+ // Helper class to handle favicon changes.
+ FaviconHelper* favicon_helper_;
+
#if defined(OS_ANDROID)
// Android Specific ---------------------------------------------------------