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

Side by Side Diff: components/favicon/content/content_favicon_driver.cc

Issue 2799273002: Add support to process favicons from Web Manifests (Closed)
Patch Set: Created 3 years, 8 months 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/favicon/content/content_favicon_driver.h" 5 #include "components/favicon/content/content_favicon_driver.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "components/favicon/content/favicon_url_util.h" 8 #include "components/favicon/content/favicon_url_util.h"
9 #include "components/favicon/core/favicon_service.h" 9 #include "components/favicon/core/favicon_service.h"
10 #include "components/favicon/core/favicon_url.h" 10 #include "components/favicon/core/favicon_url.h"
11 #include "components/history/core/browser/history_service.h" 11 #include "components/history/core/browser/history_service.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/favicon_status.h" 13 #include "content/public/browser/favicon_status.h"
14 #include "content/public/browser/navigation_controller.h" 14 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/navigation_details.h" 15 #include "content/public/browser/navigation_details.h"
16 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/browser/navigation_handle.h" 17 #include "content/public/browser/navigation_handle.h"
18 #include "content/public/common/favicon_url.h" 18 #include "content/public/common/favicon_url.h"
19 #include "content/public/common/manifest.h"
19 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
20 21
21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver); 22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver);
22 23
23 namespace favicon { 24 namespace favicon {
25 namespace {
26
27 void ExtractManifestIcons(
28 ContentFaviconDriver::ManifestDownloadCallback callback,
29 const GURL& manifest_url,
30 const content::Manifest& manifest) {
31 std::vector<FaviconURL> candidates;
32 for (const content::Manifest::Icon& icon : manifest.icons) {
33 candidates.emplace_back(icon.src, favicon_base::FAVICON, icon.sizes);
34 }
35 callback.Run(candidates);
36 }
37
38 } // namespace
24 39
25 // static 40 // static
26 void ContentFaviconDriver::CreateForWebContents( 41 void ContentFaviconDriver::CreateForWebContents(
27 content::WebContents* web_contents, 42 content::WebContents* web_contents,
28 FaviconService* favicon_service, 43 FaviconService* favicon_service,
29 history::HistoryService* history_service, 44 history::HistoryService* history_service,
30 bookmarks::BookmarkModel* bookmark_model) { 45 bookmarks::BookmarkModel* bookmark_model) {
31 if (FromWebContents(web_contents)) 46 if (FromWebContents(web_contents))
32 return; 47 return;
33 48
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 int ContentFaviconDriver::DownloadImage(const GURL& url, 124 int ContentFaviconDriver::DownloadImage(const GURL& url,
110 int max_image_size, 125 int max_image_size,
111 ImageDownloadCallback callback) { 126 ImageDownloadCallback callback) {
112 bool bypass_cache = (bypass_cache_page_url_ == GetActiveURL()); 127 bool bypass_cache = (bypass_cache_page_url_ == GetActiveURL());
113 bypass_cache_page_url_ = GURL(); 128 bypass_cache_page_url_ = GURL();
114 129
115 return web_contents()->DownloadImage(url, true, max_image_size, bypass_cache, 130 return web_contents()->DownloadImage(url, true, max_image_size, bypass_cache,
116 callback); 131 callback);
117 } 132 }
118 133
134 void ContentFaviconDriver::DownloadManifest(const GURL& url,
135 ManifestDownloadCallback callback) {
136 web_contents()->GetManifest(base::Bind(&ExtractManifestIcons, callback));
137 }
138
119 bool ContentFaviconDriver::IsOffTheRecord() { 139 bool ContentFaviconDriver::IsOffTheRecord() {
120 DCHECK(web_contents()); 140 DCHECK(web_contents());
121 return web_contents()->GetBrowserContext()->IsOffTheRecord(); 141 return web_contents()->GetBrowserContext()->IsOffTheRecord();
122 } 142 }
123 143
124 void ContentFaviconDriver::OnFaviconUpdated( 144 void ContentFaviconDriver::OnFaviconUpdated(
125 const GURL& page_url, 145 const GURL& page_url,
126 FaviconDriverObserver::NotificationIconType notification_icon_type, 146 FaviconDriverObserver::NotificationIconType notification_icon_type,
127 const GURL& icon_url, 147 const GURL& icon_url,
128 bool icon_url_changed, 148 bool icon_url_changed,
(...skipping 18 matching lines...) Expand all
147 DCHECK(!candidates.empty()); 167 DCHECK(!candidates.empty());
148 168
149 // Ignore the update if there is no last committed navigation entry. This can 169 // Ignore the update if there is no last committed navigation entry. This can
150 // occur when loading an initially blank page. 170 // occur when loading an initially blank page.
151 content::NavigationEntry* entry = 171 content::NavigationEntry* entry =
152 web_contents()->GetController().GetLastCommittedEntry(); 172 web_contents()->GetController().GetLastCommittedEntry();
153 if (!entry) 173 if (!entry)
154 return; 174 return;
155 175
156 favicon_urls_ = candidates; 176 favicon_urls_ = candidates;
157 OnUpdateFaviconURL(entry->GetURL(), 177 }
158 FaviconURLsFromContentFaviconURLs(candidates)); 178
179 void ContentFaviconDriver::DidUpdateManifestURL(
180 const base::Optional<GURL>& manifest_url) {
181 // Ignore the update if there is no last committed navigation entry. This can
182 // occur when loading an initially blank page.
183 content::NavigationEntry* entry =
184 web_contents()->GetController().GetLastCommittedEntry();
185 if (!entry)
186 return;
187
188 OnUpdateCandidates(entry->GetURL(),
189 FaviconURLsFromContentFaviconURLs(favicon_urls_),
190 manifest_url);
159 } 191 }
160 192
161 void ContentFaviconDriver::DidStartNavigation( 193 void ContentFaviconDriver::DidStartNavigation(
162 content::NavigationHandle* navigation_handle) { 194 content::NavigationHandle* navigation_handle) {
163 if (!navigation_handle->IsInMainFrame()) 195 if (!navigation_handle->IsInMainFrame())
164 return; 196 return;
165 197
198 favicon_urls_.clear();
199
166 content::ReloadType reload_type = navigation_handle->GetReloadType(); 200 content::ReloadType reload_type = navigation_handle->GetReloadType();
167 if (reload_type == content::ReloadType::NONE || IsOffTheRecord()) 201 if (reload_type == content::ReloadType::NONE || IsOffTheRecord())
168 return; 202 return;
169 203
170 bypass_cache_page_url_ = navigation_handle->GetURL(); 204 bypass_cache_page_url_ = navigation_handle->GetURL();
171 SetFaviconOutOfDateForPage( 205 SetFaviconOutOfDateForPage(
172 navigation_handle->GetURL(), 206 navigation_handle->GetURL(),
173 reload_type == content::ReloadType::BYPASSING_CACHE); 207 reload_type == content::ReloadType::BYPASSING_CACHE);
174 } 208 }
175 209
176 void ContentFaviconDriver::DidFinishNavigation( 210 void ContentFaviconDriver::DidFinishNavigation(
177 content::NavigationHandle* navigation_handle) { 211 content::NavigationHandle* navigation_handle) {
178 if (!navigation_handle->IsInMainFrame() || 212 if (!navigation_handle->IsInMainFrame() ||
179 !navigation_handle->HasCommitted() || 213 !navigation_handle->HasCommitted() ||
180 navigation_handle->IsErrorPage()) { 214 navigation_handle->IsErrorPage()) {
181 return; 215 return;
182 } 216 }
183 217
184 favicon_urls_.clear();
185
186 // Wait till the user navigates to a new URL to start checking the cache 218 // Wait till the user navigates to a new URL to start checking the cache
187 // again. The cache may be ignored for non-reload navigations (e.g. 219 // again. The cache may be ignored for non-reload navigations (e.g.
188 // history.replace() in-page navigation). This is allowed to increase the 220 // history.replace() in-page navigation). This is allowed to increase the
189 // likelihood that "reloading a page ignoring the cache" redownloads the 221 // likelihood that "reloading a page ignoring the cache" redownloads the
190 // favicon. In particular, a page may do an in-page navigation before 222 // favicon. In particular, a page may do an in-page navigation before
191 // FaviconHandler has the time to determine that the favicon needs to be 223 // FaviconHandler has the time to determine that the favicon needs to be
192 // redownloaded. 224 // redownloaded.
193 GURL url = navigation_handle->GetURL(); 225 GURL url = navigation_handle->GetURL();
194 if (url != bypass_cache_page_url_) 226 if (url != bypass_cache_page_url_)
195 bypass_cache_page_url_ = GURL(); 227 bypass_cache_page_url_ = GURL();
196 228
197 // Get the favicon, either from history or request it from the net. 229 // Get the favicon, either from history or request it from the net.
198 FetchFavicon(url); 230 FetchFavicon(url);
199 } 231 }
200 232
201 } // namespace favicon 233 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698