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

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: WebContentsObserver and callback 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));
43 favicon_handler_.reset(new FaviconHandler(profile_, this, 41 favicon_handler_.reset(new FaviconHandler(profile_, this,
44 FaviconHandler::FAVICON)); 42 FaviconHandler::FAVICON));
45 if (chrome::kEnableTouchIcon) 43 if (chrome::kEnableTouchIcon)
46 touch_icon_handler_.reset(new FaviconHandler(profile_, this, 44 touch_icon_handler_.reset(new FaviconHandler(profile_, this,
47 FaviconHandler::TOUCH)); 45 FaviconHandler::TOUCH));
48 } 46 }
49 47
50 FaviconTabHelper::~FaviconTabHelper() { 48 FaviconTabHelper::~FaviconTabHelper() {
51 } 49 }
52 50
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 const NavigationController& controller = web_contents()->GetController(); 86 const NavigationController& controller = web_contents()->GetController();
89 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) 87 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry())
90 return true; 88 return true;
91 89
92 content::WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); 90 content::WebUI* web_ui = web_contents()->GetWebUIForCurrentState();
93 if (web_ui) 91 if (web_ui)
94 return !web_ui->ShouldHideFavicon(); 92 return !web_ui->ShouldHideFavicon();
95 return true; 93 return true;
96 } 94 }
97 95
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
106 void FaviconTabHelper::SaveFavicon() { 96 void FaviconTabHelper::SaveFavicon() {
107 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); 97 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry();
108 if (!entry || entry->GetURL().is_empty()) 98 if (!entry || entry->GetURL().is_empty())
109 return; 99 return;
110 100
111 // Make sure the page is in history, otherwise adding the favicon does 101 // Make sure the page is in history, otherwise adding the favicon does
112 // nothing. 102 // nothing.
113 HistoryService* history = HistoryServiceFactory::GetForProfile( 103 HistoryService* history = HistoryServiceFactory::GetForProfile(
114 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); 104 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS);
115 if (!history) 105 if (!history)
(...skipping 11 matching lines...) Expand all
127 } 117 }
128 service->SetFavicons(entry->GetURL(), favicon.url, history::FAVICON, 118 service->SetFavicons(entry->GetURL(), favicon.url, history::FAVICON,
129 favicon.image); 119 favicon.image);
130 } 120 }
131 121
132 NavigationEntry* FaviconTabHelper::GetActiveEntry() { 122 NavigationEntry* FaviconTabHelper::GetActiveEntry() {
133 return web_contents()->GetController().GetActiveEntry(); 123 return web_contents()->GetController().GetActiveEntry();
134 } 124 }
135 125
136 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { 126 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) {
137 return favicon_download_helper_->DownloadFavicon(url, image_size); 127 return web_contents()->DownloadFavicon(url, image_size,
128 base::Bind(&FaviconTabHelper::DidDownloadFavicon,
129 base::Unretained(this)));
138 } 130 }
139 131
140 void FaviconTabHelper::NotifyFaviconUpdated() { 132 void FaviconTabHelper::NotifyFaviconUpdated() {
141 content::NotificationService::current()->Notify( 133 content::NotificationService::current()->Notify(
142 chrome::NOTIFICATION_FAVICON_UPDATED, 134 chrome::NOTIFICATION_FAVICON_UPDATED,
143 content::Source<WebContents>(web_contents()), 135 content::Source<WebContents>(web_contents()),
144 content::NotificationService::NoDetails()); 136 content::NotificationService::NoDetails());
145 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); 137 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
146 } 138 }
147 139
148 void FaviconTabHelper::NavigateToPendingEntry( 140 void FaviconTabHelper::NavigateToPendingEntry(
149 const GURL& url, 141 const GURL& url,
150 NavigationController::ReloadType reload_type) { 142 NavigationController::ReloadType reload_type) {
151 if (reload_type != NavigationController::NO_RELOAD && 143 if (reload_type != NavigationController::NO_RELOAD &&
152 !profile_->IsOffTheRecord()) { 144 !profile_->IsOffTheRecord()) {
153 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 145 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
154 profile_, Profile::IMPLICIT_ACCESS); 146 profile_, Profile::IMPLICIT_ACCESS);
155 if (favicon_service) 147 if (favicon_service)
156 favicon_service->SetFaviconOutOfDateForPage(url); 148 favicon_service->SetFaviconOutOfDateForPage(url);
157 } 149 }
158 } 150 }
159 151
160 void FaviconTabHelper::DidNavigateMainFrame( 152 void FaviconTabHelper::DidNavigateMainFrame(
161 const content::LoadCommittedDetails& details, 153 const content::LoadCommittedDetails& details,
162 const content::FrameNavigateParams& params) { 154 const content::FrameNavigateParams& params) {
163 // Get the favicon, either from history or request it from the net. 155 // Get the favicon, either from history or request it from the net.
164 FetchFavicon(details.entry->GetURL()); 156 FetchFavicon(details.entry->GetURL());
165 } 157 }
166 158
167 void FaviconTabHelper::OnDidDownloadFavicon( 159 void FaviconTabHelper::DidUpdateFaviconURL(
160 int32 page_id,
161 const std::vector<FaviconURL>& candidates) {
162 favicon_handler_->OnUpdateFaviconURL(page_id, candidates);
163 if (touch_icon_handler_.get())
164 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates);
165 }
166
167 void FaviconTabHelper::DidDownloadFavicon(
168 int id, 168 int id,
169 const GURL& image_url, 169 const GURL& image_url,
170 bool errored, 170 bool errored,
171 int requested_size, 171 int requested_size,
172 const std::vector<SkBitmap>& bitmaps) { 172 const std::vector<SkBitmap>& bitmaps) {
173 favicon_handler_->OnDidDownloadFavicon( 173 favicon_handler_->OnDidDownloadFavicon(
174 id, image_url, errored, requested_size, bitmaps); 174 id, image_url, errored, requested_size, bitmaps);
175 if (touch_icon_handler_.get()) { 175 if (touch_icon_handler_.get()) {
176 touch_icon_handler_->OnDidDownloadFavicon( 176 touch_icon_handler_->OnDidDownloadFavicon(
177 id, image_url, errored, requested_size, bitmaps); 177 id, image_url, errored, requested_size, bitmaps);
178 } 178 }
179 } 179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698