OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/favicon/favicon_tab_helper.h" | 5 #include "chrome/browser/favicon/favicon_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/favicon/favicon_download_helper.h" | |
7 #include "chrome/browser/favicon/favicon_handler.h" | 8 #include "chrome/browser/favicon/favicon_handler.h" |
8 #include "chrome/browser/favicon/favicon_service_factory.h" | 9 #include "chrome/browser/favicon/favicon_service_factory.h" |
9 #include "chrome/browser/favicon/favicon_util.h" | 10 #include "chrome/browser/favicon/favicon_util.h" |
10 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
11 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/icon_messages.h" | 16 #include "chrome/common/icon_messages.h" |
16 #include "content/public/browser/favicon_status.h" | 17 #include "content/public/browser/favicon_status.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
47 | 48 |
48 FaviconTabHelper::~FaviconTabHelper() { | 49 FaviconTabHelper::~FaviconTabHelper() { |
49 } | 50 } |
50 | 51 |
51 void FaviconTabHelper::FetchFavicon(const GURL& url) { | 52 void FaviconTabHelper::FetchFavicon(const GURL& url) { |
52 favicon_handler_->FetchFavicon(url); | 53 favicon_handler_->FetchFavicon(url); |
53 if (touch_icon_handler_.get()) | 54 if (touch_icon_handler_.get()) |
54 touch_icon_handler_->FetchFavicon(url); | 55 touch_icon_handler_->FetchFavicon(url); |
55 } | 56 } |
56 | 57 |
57 gfx::Image FaviconTabHelper::GetFavicon() const { | 58 gfx::Image FaviconTabHelper::GetFavicon() const { |
joth
2012/10/18 21:51:13
FWIW, we're going to need a method equivalent to t
| |
58 // Like GetTitle(), we also want to use the favicon for the last committed | 59 // Like GetTitle(), we also want to use the favicon for the last committed |
59 // entry rather than a pending navigation entry. | 60 // entry rather than a pending navigation entry. |
60 const NavigationController& controller = web_contents()->GetController(); | 61 const NavigationController& controller = web_contents()->GetController(); |
61 NavigationEntry* entry = controller.GetTransientEntry(); | 62 NavigationEntry* entry = controller.GetTransientEntry(); |
62 if (entry) | 63 if (entry) |
63 return entry->GetFavicon().image; | 64 return entry->GetFavicon().image; |
64 | 65 |
65 entry = controller.GetLastCommittedEntry(); | 66 entry = controller.GetLastCommittedEntry(); |
66 if (entry) | 67 if (entry) |
67 return entry->GetFavicon().image; | 68 return entry->GetFavicon().image; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 const ImageDownloadCallback& callback) { | 126 const ImageDownloadCallback& callback) { |
126 if (icon_type == history::FAVICON) | 127 if (icon_type == history::FAVICON) |
127 return favicon_handler_->DownloadImage(image_url, image_size, icon_type, | 128 return favicon_handler_->DownloadImage(image_url, image_size, icon_type, |
128 callback); | 129 callback); |
129 else if (touch_icon_handler_.get()) | 130 else if (touch_icon_handler_.get()) |
130 return touch_icon_handler_->DownloadImage(image_url, image_size, icon_type, | 131 return touch_icon_handler_->DownloadImage(image_url, image_size, icon_type, |
131 callback); | 132 callback); |
132 return 0; | 133 return 0; |
133 } | 134 } |
134 | 135 |
135 void FaviconTabHelper::OnUpdateFaviconURL( | 136 void FaviconTabHelper::OnUpdateFaviconURL( |
joth
2012/10/18 21:51:13
hmmm OK I'm just re-reminding myself how the whole
Cait (Slow)
2012/10/23 21:36:43
FaviconDownloadHelper should now handle IconHostMs
| |
136 int32 page_id, | 137 int32 page_id, |
137 const std::vector<FaviconURL>& candidates) { | 138 const std::vector<FaviconURL>& candidates) { |
138 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); | 139 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); |
139 if (touch_icon_handler_.get()) | 140 if (touch_icon_handler_.get()) |
140 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); | 141 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); |
141 } | 142 } |
142 | 143 |
143 NavigationEntry* FaviconTabHelper::GetActiveEntry() { | 144 NavigationEntry* FaviconTabHelper::GetActiveEntry() { |
144 return web_contents()->GetController().GetActiveEntry(); | 145 return web_contents()->GetController().GetActiveEntry(); |
145 } | 146 } |
146 | 147 |
147 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { | 148 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { |
148 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 149 FaviconDownloadHelper::CreateForWebContentsAndDelegate(web_contents(), this); |
149 int id = FaviconUtil::DownloadFavicon(host, url, image_size); | 150 FaviconDownloadHelper* helper = |
151 FaviconDownloadHelper::FromWebContents(web_contents()); | |
152 int id = -1; | |
153 | |
154 if (helper) { | |
155 id = helper->DownloadFavicon(url, image_size); | |
156 } | |
150 return id; | 157 return id; |
151 } | 158 } |
152 | 159 |
153 void FaviconTabHelper::NotifyFaviconUpdated() { | 160 void FaviconTabHelper::NotifyFaviconUpdated() { |
154 content::NotificationService::current()->Notify( | 161 content::NotificationService::current()->Notify( |
155 chrome::NOTIFICATION_FAVICON_UPDATED, | 162 chrome::NOTIFICATION_FAVICON_UPDATED, |
156 content::Source<WebContents>(web_contents()), | 163 content::Source<WebContents>(web_contents()), |
157 content::NotificationService::NoDetails()); | 164 content::NotificationService::NoDetails()); |
158 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 165 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
159 } | 166 } |
(...skipping 13 matching lines...) Expand all Loading... | |
173 void FaviconTabHelper::DidNavigateMainFrame( | 180 void FaviconTabHelper::DidNavigateMainFrame( |
174 const content::LoadCommittedDetails& details, | 181 const content::LoadCommittedDetails& details, |
175 const content::FrameNavigateParams& params) { | 182 const content::FrameNavigateParams& params) { |
176 // Get the favicon, either from history or request it from the net. | 183 // Get the favicon, either from history or request it from the net. |
177 FetchFavicon(details.entry->GetURL()); | 184 FetchFavicon(details.entry->GetURL()); |
178 } | 185 } |
179 | 186 |
180 bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { | 187 bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { |
181 bool message_handled = false; // Allow other handlers to receive these. | 188 bool message_handled = false; // Allow other handlers to receive these. |
182 IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) | 189 IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) |
183 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | |
184 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | 190 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
185 IPC_MESSAGE_UNHANDLED(message_handled = false) | 191 IPC_MESSAGE_UNHANDLED(message_handled = false) |
186 IPC_END_MESSAGE_MAP() | 192 IPC_END_MESSAGE_MAP() |
187 return message_handled; | 193 return message_handled; |
188 } | 194 } |
189 | 195 |
190 void FaviconTabHelper::OnDidDownloadFavicon( | 196 void FaviconTabHelper::OnDidDownloadFavicon( |
191 int id, | 197 int id, |
192 const GURL& image_url, | 198 const GURL& image_url, |
193 bool errored, | 199 bool errored, |
194 int requested_size, | 200 int requested_size, |
195 const std::vector<SkBitmap>& bitmaps) { | 201 const std::vector<SkBitmap>& bitmaps) { |
196 favicon_handler_->OnDidDownloadFavicon( | 202 favicon_handler_->OnDidDownloadFavicon( |
197 id, image_url, errored, requested_size, bitmaps); | 203 id, image_url, errored, requested_size, bitmaps); |
198 if (touch_icon_handler_.get()) { | 204 if (touch_icon_handler_.get()) { |
199 touch_icon_handler_->OnDidDownloadFavicon( | 205 touch_icon_handler_->OnDidDownloadFavicon( |
200 id, image_url, errored, requested_size, bitmaps); | 206 id, image_url, errored, requested_size, bitmaps); |
201 } | 207 } |
202 } | 208 } |
OLD | NEW |