Chromium Code Reviews| 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_helper_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 FaviconDownloadHelper::FaviconDownloadHelper( | |
| 17 WebContents* web_contents, | |
| 18 FaviconDownloadHelperDelegate* delegate) | |
| 19 : content::WebContentsObserver(web_contents), | |
| 20 delegate_(delegate) { | |
| 21 DCHECK(delegate_); | |
| 22 } | |
| 23 | |
| 24 FaviconDownloadHelper::~FaviconDownloadHelper() { | |
| 25 } | |
| 26 | |
| 27 int FaviconDownloadHelper::DownloadFavicon(const GURL& url, int image_size) { | |
| 28 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | |
| 29 int id = FaviconUtil::DownloadFavicon(host, url, image_size); | |
| 30 DownloadIdList::iterator i = | |
| 31 std::find(download_ids_.begin(), download_ids_.end(), id); | |
| 32 DCHECK(i == download_ids_.end()); | |
| 33 download_ids_.insert(id); | |
| 34 return id; | |
| 35 } | |
| 36 | |
| 37 bool FaviconDownloadHelper::OnMessageReceived(const IPC::Message& message) { | |
| 38 bool message_handled = false; // Allow other handlers to receive these. | |
| 39 IPC_BEGIN_MESSAGE_MAP(FaviconDownloadHelper, message) | |
| 40 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | |
| 41 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | |
| 42 IPC_MESSAGE_UNHANDLED(message_handled = false) | |
| 43 IPC_END_MESSAGE_MAP() | |
| 44 return message_handled; | |
| 45 } | |
| 46 | |
| 47 void FaviconDownloadHelper::OnDidDownloadFavicon( | |
| 48 int id, | |
| 49 const GURL& image_url, | |
| 50 bool errored, | |
| 51 int requested_size, | |
| 52 const std::vector<SkBitmap>& bitmaps) { | |
| 53 DownloadIdList::iterator i = | |
| 54 std::find(download_ids_.begin(), download_ids_.end(), id); | |
|
sky
2012/10/30 21:39:09
nit: indent 4.
Cait (Slow)
2012/10/31 19:26:32
Done.
| |
| 55 if (i == download_ids_.end()) { | |
| 56 // Currently WebContents notifies us of ANY downloads so that it is | |
| 57 // possible to get here. | |
| 58 return; | |
| 59 } | |
| 60 delegate_->OnDidDownloadFavicon( | |
| 61 id, image_url, errored, requested_size, bitmaps); | |
| 62 download_ids_.erase(i); | |
| 63 } | |
| 64 | |
| 65 void FaviconDownloadHelper::OnUpdateFaviconURL( | |
| 66 int32 page_id, | |
| 67 const std::vector<FaviconURL>& candidates) { | |
| 68 delegate_->OnUpdateFaviconURL(page_id, candidates); | |
| 69 } | |
| OLD | NEW |