OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/favicon/favicon_download_helper.h" |
| 6 |
| 7 #include "chrome/browser/favicon/favicon_download_delegate.h" |
| 8 #include "chrome/browser/favicon/favicon_util.h" |
| 9 #include "chrome/common/icon_messages.h" |
| 10 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/browser/web_contents_delegate.h" |
| 13 |
| 14 using content::WebContents; |
| 15 |
| 16 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconDownloadHelper) |
| 17 |
| 18 FaviconDownloadHelper::FaviconDownloadHelper(WebContents* web_contents) |
| 19 : content::WebContentsObserver(web_contents), |
| 20 external_delegate_(NULL) { |
| 21 } |
| 22 |
| 23 FaviconDownloadHelper::~FaviconDownloadHelper() { |
| 24 } |
| 25 |
| 26 int FaviconDownloadHelper::DownloadFavicon(const GURL& url, int image_size) { |
| 27 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); |
| 28 int id = FaviconUtil::DownloadFavicon(host, url, image_size); |
| 29 return id; |
| 30 } |
| 31 |
| 32 bool FaviconDownloadHelper::OnMessageReceived(const IPC::Message& message) { |
| 33 bool message_handled = false; // Allow other handlers to receive these. |
| 34 IPC_BEGIN_MESSAGE_MAP(FaviconDownloadHelper, message) |
| 35 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) |
| 36 IPC_MESSAGE_UNHANDLED(message_handled = false) |
| 37 IPC_END_MESSAGE_MAP() |
| 38 return message_handled; |
| 39 } |
| 40 |
| 41 void FaviconDownloadHelper::OnDidDownloadFavicon(int id, |
| 42 const GURL& image_url, |
| 43 bool errored, |
| 44 int requested_size, |
| 45 const std::vector<SkBitmap>& bitmaps) { |
| 46 if (external_delegate_) { |
| 47 external_delegate_->OnDidDownloadFavicon( |
| 48 id, image_url, errored, requested_size, bitmaps); |
| 49 } |
| 50 } |
OLD | NEW |