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 "base/supports_user_data.h" | |
| 8 #include "chrome/browser/favicon/favicon_download_helper_delegate.h" | |
| 9 #include "chrome/browser/favicon/favicon_util.h" | |
| 10 #include "chrome/common/icon_messages.h" | |
| 11 #include "content/public/browser/render_view_host.h" | |
| 12 #include "content/public/browser/web_contents.h" | |
| 13 #include "content/public/browser/web_contents_delegate.h" | |
| 14 | |
| 15 using content::WebContents; | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const char* kFaviconDownloadHelperWebContentsUserDataKey = | |
| 20 "web_contents_favicon_download"; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 // static | |
| 25 void FaviconDownloadHelper::CreateForWebContentsAndDelegate( | |
| 26 content::WebContents* contents, | |
| 27 FaviconDownloadHelperDelegate* delegate) { | |
| 28 if (FromWebContents(contents)) | |
| 29 return; | |
| 30 | |
| 31 contents->SetUserData(kFaviconDownloadHelperWebContentsUserDataKey, | |
| 32 new base::UserDataAdapter<FaviconDownloadHelper>( | |
| 33 new FaviconDownloadHelper(contents, delegate))); | |
| 34 } | |
| 35 | |
| 36 // static | |
| 37 FaviconDownloadHelper* FaviconDownloadHelper::FromWebContents( | |
| 38 content::WebContents* contents) { | |
| 39 return base::UserDataAdapter<FaviconDownloadHelper>::Get( | |
| 40 contents, kFaviconDownloadHelperWebContentsUserDataKey); | |
| 41 } | |
| 42 | |
| 43 | |
| 44 FaviconDownloadHelper::FaviconDownloadHelper( | |
| 45 WebContents* web_contents, | |
| 46 FaviconDownloadHelperDelegate* delegate) | |
| 47 : content::WebContentsObserver(web_contents), | |
| 48 delegate_(delegate) { | |
| 49 } | |
| 50 | |
| 51 FaviconDownloadHelper::~FaviconDownloadHelper() { | |
| 52 } | |
| 53 | |
| 54 int FaviconDownloadHelper::DownloadFavicon(const GURL& url, int image_size) { | |
| 55 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | |
| 56 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
| |
| 57 return id; | |
| 58 } | |
| 59 | |
| 60 bool FaviconDownloadHelper::OnMessageReceived(const IPC::Message& message) { | |
| 61 bool message_handled = false; // Allow other handlers to receive these. | |
| 62 IPC_BEGIN_MESSAGE_MAP(FaviconDownloadHelper, message) | |
| 63 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | |
| 64 IPC_MESSAGE_UNHANDLED(message_handled = false) | |
| 65 IPC_END_MESSAGE_MAP() | |
| 66 return message_handled; | |
| 67 } | |
| 68 | |
| 69 void FaviconDownloadHelper::OnDidDownloadFavicon(int id, | |
| 70 const GURL& image_url, | |
| 71 bool errored, | |
| 72 int requested_size, | |
| 73 const std::vector<SkBitmap>& bitmaps) { | |
| 74 if (delegate_) { | |
| 75 delegate_->OnDidDownloadFavicon( | |
| 76 id, image_url, errored, requested_size, bitmaps); | |
| 77 } | |
| 78 } | |
| OLD | NEW |