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 14 matching lines...) Expand all Loading... |
31 using content::FaviconStatus; | 32 using content::FaviconStatus; |
32 using content::NavigationController; | 33 using content::NavigationController; |
33 using content::NavigationEntry; | 34 using content::NavigationEntry; |
34 using content::WebContents; | 35 using content::WebContents; |
35 | 36 |
36 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper) | 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper) |
37 | 38 |
38 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) | 39 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) |
39 : content::WebContentsObserver(web_contents), | 40 : content::WebContentsObserver(web_contents), |
40 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { | 41 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
| 42 favicon_download_helper_.reset(new FaviconDownloadHelper(web_contents, this)); |
41 favicon_handler_.reset(new FaviconHandler(profile_, this, | 43 favicon_handler_.reset(new FaviconHandler(profile_, this, |
42 FaviconHandler::FAVICON)); | 44 FaviconHandler::FAVICON)); |
43 if (chrome::kEnableTouchIcon) | 45 if (chrome::kEnableTouchIcon) |
44 touch_icon_handler_.reset(new FaviconHandler(profile_, this, | 46 touch_icon_handler_.reset(new FaviconHandler(profile_, this, |
45 FaviconHandler::TOUCH)); | 47 FaviconHandler::TOUCH)); |
46 } | 48 } |
47 | 49 |
48 FaviconTabHelper::~FaviconTabHelper() { | 50 FaviconTabHelper::~FaviconTabHelper() { |
49 } | 51 } |
50 | 52 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 const NavigationController& controller = web_contents()->GetController(); | 88 const NavigationController& controller = web_contents()->GetController(); |
87 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) | 89 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) |
88 return true; | 90 return true; |
89 | 91 |
90 content::WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); | 92 content::WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); |
91 if (web_ui) | 93 if (web_ui) |
92 return !web_ui->ShouldHideFavicon(); | 94 return !web_ui->ShouldHideFavicon(); |
93 return true; | 95 return true; |
94 } | 96 } |
95 | 97 |
| 98 void FaviconTabHelper::OnUpdateFaviconURL( |
| 99 int32 page_id, |
| 100 const std::vector<FaviconURL>& candidates) { |
| 101 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); |
| 102 if (touch_icon_handler_.get()) |
| 103 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); |
| 104 } |
| 105 |
96 void FaviconTabHelper::SaveFavicon() { | 106 void FaviconTabHelper::SaveFavicon() { |
97 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); | 107 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); |
98 if (!entry || entry->GetURL().is_empty()) | 108 if (!entry || entry->GetURL().is_empty()) |
99 return; | 109 return; |
100 | 110 |
101 // Make sure the page is in history, otherwise adding the favicon does | 111 // Make sure the page is in history, otherwise adding the favicon does |
102 // nothing. | 112 // nothing. |
103 HistoryService* history = HistoryServiceFactory::GetForProfile( | 113 HistoryService* history = HistoryServiceFactory::GetForProfile( |
104 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); | 114 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); |
105 if (!history) | 115 if (!history) |
(...skipping 19 matching lines...) Expand all Loading... |
125 const ImageDownloadCallback& callback) { | 135 const ImageDownloadCallback& callback) { |
126 if (icon_type == history::FAVICON) | 136 if (icon_type == history::FAVICON) |
127 return favicon_handler_->DownloadImage(image_url, image_size, icon_type, | 137 return favicon_handler_->DownloadImage(image_url, image_size, icon_type, |
128 callback); | 138 callback); |
129 else if (touch_icon_handler_.get()) | 139 else if (touch_icon_handler_.get()) |
130 return touch_icon_handler_->DownloadImage(image_url, image_size, icon_type, | 140 return touch_icon_handler_->DownloadImage(image_url, image_size, icon_type, |
131 callback); | 141 callback); |
132 return 0; | 142 return 0; |
133 } | 143 } |
134 | 144 |
135 void FaviconTabHelper::OnUpdateFaviconURL( | |
136 int32 page_id, | |
137 const std::vector<FaviconURL>& candidates) { | |
138 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); | |
139 if (touch_icon_handler_.get()) | |
140 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); | |
141 } | |
142 | |
143 NavigationEntry* FaviconTabHelper::GetActiveEntry() { | 145 NavigationEntry* FaviconTabHelper::GetActiveEntry() { |
144 return web_contents()->GetController().GetActiveEntry(); | 146 return web_contents()->GetController().GetActiveEntry(); |
145 } | 147 } |
146 | 148 |
147 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { | 149 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { |
148 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 150 return favicon_download_helper_->DownloadFavicon(url, image_size); |
149 int id = FaviconUtil::DownloadFavicon(host, url, image_size); | |
150 return id; | |
151 } | 151 } |
152 | 152 |
153 void FaviconTabHelper::NotifyFaviconUpdated() { | 153 void FaviconTabHelper::NotifyFaviconUpdated() { |
154 content::NotificationService::current()->Notify( | 154 content::NotificationService::current()->Notify( |
155 chrome::NOTIFICATION_FAVICON_UPDATED, | 155 chrome::NOTIFICATION_FAVICON_UPDATED, |
156 content::Source<WebContents>(web_contents()), | 156 content::Source<WebContents>(web_contents()), |
157 content::NotificationService::NoDetails()); | 157 content::NotificationService::NoDetails()); |
158 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 158 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
159 } | 159 } |
160 | 160 |
161 void FaviconTabHelper::NavigateToPendingEntry( | 161 void FaviconTabHelper::NavigateToPendingEntry( |
162 const GURL& url, | 162 const GURL& url, |
163 NavigationController::ReloadType reload_type) { | 163 NavigationController::ReloadType reload_type) { |
164 if (reload_type != NavigationController::NO_RELOAD && | 164 if (reload_type != NavigationController::NO_RELOAD && |
165 !profile_->IsOffTheRecord()) { | 165 !profile_->IsOffTheRecord()) { |
166 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 166 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
167 profile_, Profile::IMPLICIT_ACCESS); | 167 profile_, Profile::IMPLICIT_ACCESS); |
168 if (favicon_service) | 168 if (favicon_service) |
169 favicon_service->SetFaviconOutOfDateForPage(url); | 169 favicon_service->SetFaviconOutOfDateForPage(url); |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 void FaviconTabHelper::DidNavigateMainFrame( | 173 void FaviconTabHelper::DidNavigateMainFrame( |
174 const content::LoadCommittedDetails& details, | 174 const content::LoadCommittedDetails& details, |
175 const content::FrameNavigateParams& params) { | 175 const content::FrameNavigateParams& params) { |
176 // Get the favicon, either from history or request it from the net. | 176 // Get the favicon, either from history or request it from the net. |
177 FetchFavicon(details.entry->GetURL()); | 177 FetchFavicon(details.entry->GetURL()); |
178 } | 178 } |
179 | 179 |
180 bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { | |
181 bool message_handled = false; // Allow other handlers to receive these. | |
182 IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) | |
183 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | |
184 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | |
185 IPC_MESSAGE_UNHANDLED(message_handled = false) | |
186 IPC_END_MESSAGE_MAP() | |
187 return message_handled; | |
188 } | |
189 | |
190 void FaviconTabHelper::OnDidDownloadFavicon( | 180 void FaviconTabHelper::OnDidDownloadFavicon( |
191 int id, | 181 int id, |
192 const GURL& image_url, | 182 const GURL& image_url, |
193 bool errored, | 183 bool errored, |
194 int requested_size, | 184 int requested_size, |
195 const std::vector<SkBitmap>& bitmaps) { | 185 const std::vector<SkBitmap>& bitmaps) { |
196 favicon_handler_->OnDidDownloadFavicon( | 186 favicon_handler_->OnDidDownloadFavicon( |
197 id, image_url, errored, requested_size, bitmaps); | 187 id, image_url, errored, requested_size, bitmaps); |
198 if (touch_icon_handler_.get()) { | 188 if (touch_icon_handler_.get()) { |
199 touch_icon_handler_->OnDidDownloadFavicon( | 189 touch_icon_handler_->OnDidDownloadFavicon( |
200 id, image_url, errored, requested_size, bitmaps); | 190 id, image_url, errored, requested_size, bitmaps); |
201 } | 191 } |
202 } | 192 } |
OLD | NEW |