Chromium Code Reviews| Index: chrome/browser/favicon/favicon_download_helper.cc |
| diff --git a/chrome/browser/favicon/favicon_download_helper.cc b/chrome/browser/favicon/favicon_download_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a50989dc8cc6a27ab568b219b9d211126cd1b47d |
| --- /dev/null |
| +++ b/chrome/browser/favicon/favicon_download_helper.cc |
| @@ -0,0 +1,78 @@ |
| +// 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 "base/supports_user_data.h" |
| +#include "chrome/browser/favicon/favicon_download_helper_delegate.h" |
| +#include "chrome/browser/favicon/favicon_util.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 { |
| + |
| +const char* kFaviconDownloadHelperWebContentsUserDataKey = |
| + "web_contents_favicon_download"; |
| + |
| +} // namespace |
| + |
| +// static |
| +void FaviconDownloadHelper::CreateForWebContentsAndDelegate( |
| + content::WebContents* contents, |
| + FaviconDownloadHelperDelegate* delegate) { |
| + if (FromWebContents(contents)) |
| + return; |
| + |
| + contents->SetUserData(kFaviconDownloadHelperWebContentsUserDataKey, |
| + new base::UserDataAdapter<FaviconDownloadHelper>( |
| + new FaviconDownloadHelper(contents, delegate))); |
| +} |
| + |
| +// static |
| +FaviconDownloadHelper* FaviconDownloadHelper::FromWebContents( |
| + content::WebContents* contents) { |
| + return base::UserDataAdapter<FaviconDownloadHelper>::Get( |
| + contents, kFaviconDownloadHelperWebContentsUserDataKey); |
| +} |
| + |
| + |
| +FaviconDownloadHelper::FaviconDownloadHelper( |
| + WebContents* web_contents, |
| + FaviconDownloadHelperDelegate* delegate) |
| + : content::WebContentsObserver(web_contents), |
| + delegate_(delegate) { |
| +} |
| + |
| +FaviconDownloadHelper::~FaviconDownloadHelper() { |
| +} |
| + |
| +int FaviconDownloadHelper::DownloadFavicon(const GURL& url, int image_size) { |
| + content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
| + int id = FaviconUtil::DownloadFavicon(host, url, image_size); |
|
joth
2012/10/18 21:51:13
internally this sends IconMsg_DownloadFavicon ipc
Cait (Slow)
2012/10/23 21:36:43
CL extracting renderer-side code: http://coderevie
|
| + 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_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) { |
| + if (delegate_) { |
| + delegate_->OnDidDownloadFavicon( |
| + id, image_url, errored, requested_size, bitmaps); |
| + } |
| +} |