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 2638423008: Convert ContentFaviconDriver to use the new navigation callbacks. (Closed)
Patch Set: fix test by only looking at successful commits as before Created 3 years, 11 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/common/favicon_url.h" 18 #include "content/public/common/favicon_url.h"
18 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
19 20
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver); 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver);
21 22
22 namespace favicon { 23 namespace favicon {
23 24
24 // static 25 // static
25 void ContentFaviconDriver::CreateForWebContents( 26 void ContentFaviconDriver::CreateForWebContents(
26 content::WebContents* web_contents, 27 content::WebContents* web_contents,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 content::NavigationEntry* entry = 156 content::NavigationEntry* entry =
156 web_contents()->GetController().GetLastCommittedEntry(); 157 web_contents()->GetController().GetLastCommittedEntry();
157 if (!entry) 158 if (!entry)
158 return; 159 return;
159 160
160 favicon_urls_ = candidates; 161 favicon_urls_ = candidates;
161 OnUpdateFaviconURL(entry->GetURL(), 162 OnUpdateFaviconURL(entry->GetURL(),
162 FaviconURLsFromContentFaviconURLs(candidates)); 163 FaviconURLsFromContentFaviconURLs(candidates));
163 } 164 }
164 165
165 void ContentFaviconDriver::DidStartNavigationToPendingEntry( 166 void ContentFaviconDriver::DidStartNavigation(
Charlie Reis 2017/01/23 18:30:08 Note: This will get called more often than before,
jam 2017/01/23 19:05:02 This shouldn't make a difference because the funct
Charlie Reis 2017/01/23 19:53:30 Yes, looks like you're right.
166 const GURL& url, 167 content::NavigationHandle* navigation_handle) {
167 content::ReloadType reload_type) { 168 if (!navigation_handle->IsInMainFrame())
169 return;
170
171 content::ReloadType reload_type = navigation_handle->GetReloadType();
168 if (reload_type == content::ReloadType::NONE || IsOffTheRecord()) 172 if (reload_type == content::ReloadType::NONE || IsOffTheRecord())
169 return; 173 return;
170 174
171 bypass_cache_page_url_ = url; 175 bypass_cache_page_url_ = navigation_handle->GetURL();
172 SetFaviconOutOfDateForPage( 176 SetFaviconOutOfDateForPage(
173 url, reload_type == content::ReloadType::BYPASSING_CACHE); 177 navigation_handle->GetURL(),
178 reload_type == content::ReloadType::BYPASSING_CACHE);
174 } 179 }
175 180
176 void ContentFaviconDriver::DidNavigateMainFrame( 181 void ContentFaviconDriver::DidFinishNavigation(
177 const content::LoadCommittedDetails& details, 182 content::NavigationHandle* navigation_handle) {
178 const content::FrameNavigateParams& params) { 183 if (!navigation_handle->IsInMainFrame() ||
184 !navigation_handle->HasCommitted() ||
185 navigation_handle->IsErrorPage()) {
186 return;
187 }
188
179 favicon_urls_.clear(); 189 favicon_urls_.clear();
180 190
181 // Wait till the user navigates to a new URL to start checking the cache 191 // Wait till the user navigates to a new URL to start checking the cache
182 // again. The cache may be ignored for non-reload navigations (e.g. 192 // again. The cache may be ignored for non-reload navigations (e.g.
183 // history.replace() in-page navigation). This is allowed to increase the 193 // history.replace() in-page navigation). This is allowed to increase the
184 // likelihood that "reloading a page ignoring the cache" redownloads the 194 // likelihood that "reloading a page ignoring the cache" redownloads the
185 // favicon. In particular, a page may do an in-page navigation before 195 // favicon. In particular, a page may do an in-page navigation before
186 // FaviconHandler has the time to determine that the favicon needs to be 196 // FaviconHandler has the time to determine that the favicon needs to be
187 // redownloaded. 197 // redownloaded.
188 GURL url = details.entry->GetURL(); 198 GURL url = navigation_handle->GetURL();
189 if (url != bypass_cache_page_url_) 199 if (url != bypass_cache_page_url_)
190 bypass_cache_page_url_ = GURL(); 200 bypass_cache_page_url_ = GURL();
191 201
192 // Get the favicon, either from history or request it from the net. 202 // Get the favicon, either from history or request it from the net.
193 FetchFavicon(url); 203 FetchFavicon(url);
194 } 204 }
195 205
196 } // namespace favicon 206 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698