Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: chrome/browser/favicon/favicon_tab_helper.cc

Issue 11411180: move favicon download code from chrome/ into content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
8 #include "chrome/browser/favicon/favicon_handler.h" 7 #include "chrome/browser/favicon/favicon_handler.h"
9 #include "chrome/browser/favicon/favicon_service_factory.h" 8 #include "chrome/browser/favicon/favicon_service_factory.h"
10 #include "chrome/browser/favicon/favicon_util.h" 9 #include "chrome/browser/favicon/favicon_util.h"
11 #include "chrome/browser/history/history.h" 10 #include "chrome/browser/history/history.h"
12 #include "chrome/browser/history/history_service_factory.h" 11 #include "chrome/browser/history/history_service_factory.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_constants.h" 13 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/icon_messages.h"
17 #include "content/public/browser/favicon_status.h" 15 #include "content/public/browser/favicon_status.h"
18 #include "content/public/browser/invalidate_type.h" 16 #include "content/public/browser/invalidate_type.h"
19 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/navigation_details.h" 18 #include "content/public/browser/navigation_details.h"
21 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_delegate.h" 23 #include "content/public/browser/web_contents_delegate.h"
26 #include "content/public/browser/web_ui.h" 24 #include "content/public/browser/web_ui.h"
27 #include "ui/gfx/codec/png_codec.h" 25 #include "ui/gfx/codec/png_codec.h"
28 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/image/image_skia.h" 27 #include "ui/gfx/image/image_skia.h"
30 #include "ui/gfx/image/image_skia_rep.h" 28 #include "ui/gfx/image/image_skia_rep.h"
31 29
32 using content::FaviconStatus; 30 using content::FaviconStatus;
31 using content::FaviconURL;
33 using content::NavigationController; 32 using content::NavigationController;
34 using content::NavigationEntry; 33 using content::NavigationEntry;
35 using content::WebContents; 34 using content::WebContents;
36 35
37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper) 36 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper)
38 37
39 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) 38 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents)
40 : content::WebContentsObserver(web_contents), 39 : content::WebContentsObserver(web_contents),
41 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { 40 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
42 favicon_download_helper_.reset(new FaviconDownloadHelper(web_contents, this)); 41 web_contents->RegisterFaviconDelegate(this);
43 favicon_handler_.reset(new FaviconHandler(profile_, this, 42 favicon_handler_.reset(new FaviconHandler(profile_, this,
44 FaviconHandler::FAVICON)); 43 FaviconHandler::FAVICON));
45 if (chrome::kEnableTouchIcon) 44 if (chrome::kEnableTouchIcon)
46 touch_icon_handler_.reset(new FaviconHandler(profile_, this, 45 touch_icon_handler_.reset(new FaviconHandler(profile_, this,
47 FaviconHandler::TOUCH)); 46 FaviconHandler::TOUCH));
48 } 47 }
49 48
50 FaviconTabHelper::~FaviconTabHelper() { 49 FaviconTabHelper::~FaviconTabHelper() {
51 } 50 }
52 51
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 const NavigationController& controller = web_contents()->GetController(); 87 const NavigationController& controller = web_contents()->GetController();
89 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) 88 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry())
90 return true; 89 return true;
91 90
92 content::WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); 91 content::WebUI* web_ui = web_contents()->GetWebUIForCurrentState();
93 if (web_ui) 92 if (web_ui)
94 return !web_ui->ShouldHideFavicon(); 93 return !web_ui->ShouldHideFavicon();
95 return true; 94 return true;
96 } 95 }
97 96
98 void FaviconTabHelper::OnUpdateFaviconURL( 97 void FaviconTabHelper::UpdateFaviconURL(
99 int32 page_id, 98 int32 page_id,
100 const std::vector<FaviconURL>& candidates) { 99 const std::vector<FaviconURL>& candidates) {
101 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); 100 favicon_handler_->OnUpdateFaviconURL(page_id, candidates);
102 if (touch_icon_handler_.get()) 101 if (touch_icon_handler_.get())
103 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); 102 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates);
104 } 103 }
105 104
106 void FaviconTabHelper::SaveFavicon() { 105 void FaviconTabHelper::SaveFavicon() {
107 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); 106 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry();
108 if (!entry || entry->GetURL().is_empty()) 107 if (!entry || entry->GetURL().is_empty())
(...skipping 18 matching lines...) Expand all
127 } 126 }
128 service->SetFavicons(entry->GetURL(), favicon.url, history::FAVICON, 127 service->SetFavicons(entry->GetURL(), favicon.url, history::FAVICON,
129 favicon.image); 128 favicon.image);
130 } 129 }
131 130
132 NavigationEntry* FaviconTabHelper::GetActiveEntry() { 131 NavigationEntry* FaviconTabHelper::GetActiveEntry() {
133 return web_contents()->GetController().GetActiveEntry(); 132 return web_contents()->GetController().GetActiveEntry();
134 } 133 }
135 134
136 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { 135 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) {
137 return favicon_download_helper_->DownloadFavicon(url, image_size); 136 return web_contents()->DownloadFavicon(url, image_size);
138 } 137 }
139 138
140 void FaviconTabHelper::NotifyFaviconUpdated() { 139 void FaviconTabHelper::NotifyFaviconUpdated() {
141 content::NotificationService::current()->Notify( 140 content::NotificationService::current()->Notify(
142 chrome::NOTIFICATION_FAVICON_UPDATED, 141 chrome::NOTIFICATION_FAVICON_UPDATED,
143 content::Source<WebContents>(web_contents()), 142 content::Source<WebContents>(web_contents()),
144 content::NotificationService::NoDetails()); 143 content::NotificationService::NoDetails());
145 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); 144 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
146 } 145 }
147 146
148 void FaviconTabHelper::NavigateToPendingEntry( 147 void FaviconTabHelper::NavigateToPendingEntry(
149 const GURL& url, 148 const GURL& url,
150 NavigationController::ReloadType reload_type) { 149 NavigationController::ReloadType reload_type) {
151 if (reload_type != NavigationController::NO_RELOAD && 150 if (reload_type != NavigationController::NO_RELOAD &&
152 !profile_->IsOffTheRecord()) { 151 !profile_->IsOffTheRecord()) {
153 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 152 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
154 profile_, Profile::IMPLICIT_ACCESS); 153 profile_, Profile::IMPLICIT_ACCESS);
155 if (favicon_service) 154 if (favicon_service)
156 favicon_service->SetFaviconOutOfDateForPage(url); 155 favicon_service->SetFaviconOutOfDateForPage(url);
157 } 156 }
158 } 157 }
159 158
160 void FaviconTabHelper::DidNavigateMainFrame( 159 void FaviconTabHelper::DidNavigateMainFrame(
161 const content::LoadCommittedDetails& details, 160 const content::LoadCommittedDetails& details,
162 const content::FrameNavigateParams& params) { 161 const content::FrameNavigateParams& params) {
163 // Get the favicon, either from history or request it from the net. 162 // Get the favicon, either from history or request it from the net.
164 FetchFavicon(details.entry->GetURL()); 163 FetchFavicon(details.entry->GetURL());
165 } 164 }
166 165
167 void FaviconTabHelper::OnDidDownloadFavicon( 166 void FaviconTabHelper::DidDownloadFavicon(
168 int id, 167 int id,
169 const GURL& image_url, 168 const GURL& image_url,
170 bool errored, 169 bool errored,
171 int requested_size, 170 int requested_size,
172 const std::vector<SkBitmap>& bitmaps) { 171 const std::vector<SkBitmap>& bitmaps) {
173 favicon_handler_->OnDidDownloadFavicon( 172 favicon_handler_->OnDidDownloadFavicon(
174 id, image_url, errored, requested_size, bitmaps); 173 id, image_url, errored, requested_size, bitmaps);
175 if (touch_icon_handler_.get()) { 174 if (touch_icon_handler_.get()) {
176 touch_icon_handler_->OnDidDownloadFavicon( 175 touch_icon_handler_->OnDidDownloadFavicon(
177 id, image_url, errored, requested_size, bitmaps); 176 id, image_url, errored, requested_size, bitmaps);
178 } 177 }
179 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698