| 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" |
| 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 "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 20 | 20 |
| 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver); | 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver); |
| 22 | 22 |
| 23 namespace favicon { | 23 namespace favicon { |
| 24 namespace { |
| 25 |
| 26 #if defined(OS_ANDROID) |
| 27 const bool kEnableTouchIcon = true; |
| 28 #else |
| 29 const bool kEnableTouchIcon = false; |
| 30 #endif |
| 31 |
| 32 } // namespace |
| 24 | 33 |
| 25 // static | 34 // static |
| 26 void ContentFaviconDriver::CreateForWebContents( | 35 void ContentFaviconDriver::CreateForWebContents( |
| 27 content::WebContents* web_contents, | 36 content::WebContents* web_contents, |
| 28 FaviconService* favicon_service, | 37 FaviconService* favicon_service, |
| 29 history::HistoryService* history_service, | 38 history::HistoryService* history_service, |
| 30 bookmarks::BookmarkModel* bookmark_model) { | 39 bookmarks::BookmarkModel* bookmark_model) { |
| 31 if (FromWebContents(web_contents)) | 40 if (FromWebContents(web_contents)) |
| 32 return; | 41 return; |
| 33 | 42 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 content::NavigationEntry* entry = controller.GetTransientEntry(); | 76 content::NavigationEntry* entry = controller.GetTransientEntry(); |
| 68 if (entry) | 77 if (entry) |
| 69 return entry->GetFavicon().image; | 78 return entry->GetFavicon().image; |
| 70 | 79 |
| 71 entry = controller.GetLastCommittedEntry(); | 80 entry = controller.GetLastCommittedEntry(); |
| 72 if (entry) | 81 if (entry) |
| 73 return entry->GetFavicon().image; | 82 return entry->GetFavicon().image; |
| 74 return gfx::Image(); | 83 return gfx::Image(); |
| 75 } | 84 } |
| 76 | 85 |
| 77 bool ContentFaviconDriver::FaviconIsValid() const { | |
| 78 const content::NavigationController& controller = | |
| 79 web_contents()->GetController(); | |
| 80 content::NavigationEntry* entry = controller.GetTransientEntry(); | |
| 81 if (entry) | |
| 82 return entry->GetFavicon().valid; | |
| 83 | |
| 84 entry = controller.GetLastCommittedEntry(); | |
| 85 if (entry) | |
| 86 return entry->GetFavicon().valid; | |
| 87 | |
| 88 return false; | |
| 89 } | |
| 90 | |
| 91 GURL ContentFaviconDriver::GetActiveURL() { | |
| 92 content::NavigationEntry* entry = | |
| 93 web_contents()->GetController().GetLastCommittedEntry(); | |
| 94 return entry ? entry->GetURL() : GURL(); | |
| 95 } | |
| 96 | |
| 97 ContentFaviconDriver::ContentFaviconDriver( | 86 ContentFaviconDriver::ContentFaviconDriver( |
| 98 content::WebContents* web_contents, | 87 content::WebContents* web_contents, |
| 99 FaviconService* favicon_service, | 88 FaviconService* favicon_service, |
| 100 history::HistoryService* history_service, | 89 history::HistoryService* history_service, |
| 101 bookmarks::BookmarkModel* bookmark_model) | 90 bookmarks::BookmarkModel* bookmark_model) |
| 102 : content::WebContentsObserver(web_contents), | 91 : content::WebContentsObserver(web_contents), |
| 103 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 92 FaviconDriverImpl(kEnableTouchIcon, |
| 104 } | 93 favicon_service, |
| 94 history_service, |
| 95 bookmark_model) {} |
| 105 | 96 |
| 106 ContentFaviconDriver::~ContentFaviconDriver() { | 97 ContentFaviconDriver::~ContentFaviconDriver() { |
| 107 } | 98 } |
| 108 | 99 |
| 109 int ContentFaviconDriver::DownloadImage(const GURL& url, | 100 int ContentFaviconDriver::DownloadImage(const GURL& url, |
| 110 int max_image_size, | 101 int max_image_size, |
| 111 ImageDownloadCallback callback) { | 102 ImageDownloadCallback callback) { |
| 112 if (WasUnableToDownloadFavicon(url)) { | 103 if (WasUnableToDownloadFavicon(url)) { |
| 113 DVLOG(1) << "Skip Failed FavIcon: " << url; | 104 DVLOG(1) << "Skip Failed FavIcon: " << url; |
| 114 return 0; | 105 return 0; |
| 115 } | 106 } |
| 116 | 107 |
| 117 bool bypass_cache = (bypass_cache_page_url_ == GetActiveURL()); | 108 content::NavigationEntry* entry = |
| 109 web_contents()->GetController().GetLastCommittedEntry(); |
| 110 const GURL active_url = entry ? entry->GetURL() : GURL(); |
| 111 |
| 112 bool bypass_cache = (bypass_cache_page_url_ == active_url); |
| 118 bypass_cache_page_url_ = GURL(); | 113 bypass_cache_page_url_ = GURL(); |
| 119 | 114 |
| 120 return web_contents()->DownloadImage(url, true, max_image_size, bypass_cache, | 115 return web_contents()->DownloadImage(url, true, max_image_size, bypass_cache, |
| 121 callback); | 116 callback); |
| 122 } | 117 } |
| 123 | 118 |
| 124 bool ContentFaviconDriver::IsOffTheRecord() { | 119 bool ContentFaviconDriver::IsOffTheRecord() { |
| 125 DCHECK(web_contents()); | 120 DCHECK(web_contents()); |
| 126 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 121 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 127 } | 122 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // redownloaded. | 192 // redownloaded. |
| 198 GURL url = navigation_handle->GetURL(); | 193 GURL url = navigation_handle->GetURL(); |
| 199 if (url != bypass_cache_page_url_) | 194 if (url != bypass_cache_page_url_) |
| 200 bypass_cache_page_url_ = GURL(); | 195 bypass_cache_page_url_ = GURL(); |
| 201 | 196 |
| 202 // Get the favicon, either from history or request it from the net. | 197 // Get the favicon, either from history or request it from the net. |
| 203 FetchFavicon(url); | 198 FetchFavicon(url); |
| 204 } | 199 } |
| 205 | 200 |
| 206 } // namespace favicon | 201 } // namespace favicon |
| OLD | NEW |