| OLD | NEW |
| 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" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 if (entry) | 81 if (entry) |
| 82 return entry->GetFavicon().valid; | 82 return entry->GetFavicon().valid; |
| 83 | 83 |
| 84 entry = controller.GetLastCommittedEntry(); | 84 entry = controller.GetLastCommittedEntry(); |
| 85 if (entry) | 85 if (entry) |
| 86 return entry->GetFavicon().valid; | 86 return entry->GetFavicon().valid; |
| 87 | 87 |
| 88 return false; | 88 return false; |
| 89 } | 89 } |
| 90 | 90 |
| 91 int ContentFaviconDriver::StartDownload(const GURL& url, int max_image_size) { | |
| 92 if (WasUnableToDownloadFavicon(url)) { | |
| 93 DVLOG(1) << "Skip Failed FavIcon: " << url; | |
| 94 return 0; | |
| 95 } | |
| 96 | |
| 97 bool bypass_cache = (bypass_cache_page_url_ == GetActiveURL()); | |
| 98 bypass_cache_page_url_ = GURL(); | |
| 99 | |
| 100 return web_contents()->DownloadImage( | |
| 101 url, true, max_image_size, bypass_cache, | |
| 102 base::Bind(&FaviconDriverImpl::DidDownloadFavicon, | |
| 103 base::Unretained(this))); | |
| 104 } | |
| 105 | |
| 106 bool ContentFaviconDriver::IsOffTheRecord() { | |
| 107 DCHECK(web_contents()); | |
| 108 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | |
| 109 } | |
| 110 | |
| 111 GURL ContentFaviconDriver::GetActiveURL() { | 91 GURL ContentFaviconDriver::GetActiveURL() { |
| 112 content::NavigationEntry* entry = | 92 content::NavigationEntry* entry = |
| 113 web_contents()->GetController().GetLastCommittedEntry(); | 93 web_contents()->GetController().GetLastCommittedEntry(); |
| 114 return entry ? entry->GetURL() : GURL(); | 94 return entry ? entry->GetURL() : GURL(); |
| 115 } | 95 } |
| 116 | 96 |
| 117 ContentFaviconDriver::ContentFaviconDriver( | 97 ContentFaviconDriver::ContentFaviconDriver( |
| 118 content::WebContents* web_contents, | 98 content::WebContents* web_contents, |
| 119 FaviconService* favicon_service, | 99 FaviconService* favicon_service, |
| 120 history::HistoryService* history_service, | 100 history::HistoryService* history_service, |
| 121 bookmarks::BookmarkModel* bookmark_model) | 101 bookmarks::BookmarkModel* bookmark_model) |
| 122 : content::WebContentsObserver(web_contents), | 102 : content::WebContentsObserver(web_contents), |
| 123 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 103 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { |
| 124 } | 104 } |
| 125 | 105 |
| 126 ContentFaviconDriver::~ContentFaviconDriver() { | 106 ContentFaviconDriver::~ContentFaviconDriver() { |
| 127 } | 107 } |
| 128 | 108 |
| 109 int ContentFaviconDriver::DownloadImage(const GURL& url, |
| 110 int max_image_size, |
| 111 ImageDownloadCallback callback) { |
| 112 if (WasUnableToDownloadFavicon(url)) { |
| 113 DVLOG(1) << "Skip Failed FavIcon: " << url; |
| 114 return 0; |
| 115 } |
| 116 |
| 117 bool bypass_cache = (bypass_cache_page_url_ == GetActiveURL()); |
| 118 bypass_cache_page_url_ = GURL(); |
| 119 |
| 120 return web_contents()->DownloadImage(url, true, max_image_size, bypass_cache, |
| 121 callback); |
| 122 } |
| 123 |
| 124 bool ContentFaviconDriver::IsOffTheRecord() { |
| 125 DCHECK(web_contents()); |
| 126 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 127 } |
| 128 |
| 129 void ContentFaviconDriver::OnFaviconUpdated( | 129 void ContentFaviconDriver::OnFaviconUpdated( |
| 130 const GURL& page_url, | 130 const GURL& page_url, |
| 131 FaviconDriverObserver::NotificationIconType notification_icon_type, | 131 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 132 const GURL& icon_url, | 132 const GURL& icon_url, |
| 133 bool icon_url_changed, | 133 bool icon_url_changed, |
| 134 const gfx::Image& image) { | 134 const gfx::Image& image) { |
| 135 content::NavigationEntry* entry = | 135 content::NavigationEntry* entry = |
| 136 web_contents()->GetController().GetLastCommittedEntry(); | 136 web_contents()->GetController().GetLastCommittedEntry(); |
| 137 DCHECK(entry && entry->GetURL() == page_url); | 137 DCHECK(entry && entry->GetURL() == page_url); |
| 138 | 138 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // redownloaded. | 197 // redownloaded. |
| 198 GURL url = navigation_handle->GetURL(); | 198 GURL url = navigation_handle->GetURL(); |
| 199 if (url != bypass_cache_page_url_) | 199 if (url != bypass_cache_page_url_) |
| 200 bypass_cache_page_url_ = GURL(); | 200 bypass_cache_page_url_ = GURL(); |
| 201 | 201 |
| 202 // 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. |
| 203 FetchFavicon(url); | 203 FetchFavicon(url); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace favicon | 206 } // namespace favicon |
| OLD | NEW |