| 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 "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "components/favicon/content/favicon_url_util.h" | 9 #include "components/favicon/content/favicon_url_util.h" |
| 10 #include "components/favicon/core/favicon_service.h" | 10 #include "components/favicon/core/favicon_service.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 callback.Run(candidates); | 37 callback.Run(candidates); |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 // static | 42 // static |
| 43 void ContentFaviconDriver::CreateForWebContents( | 43 void ContentFaviconDriver::CreateForWebContents( |
| 44 content::WebContents* web_contents, | 44 content::WebContents* web_contents, |
| 45 FaviconService* favicon_service, | 45 FaviconService* favicon_service, |
| 46 history::HistoryService* history_service, | 46 history::HistoryService* history_service) { |
| 47 bookmarks::BookmarkModel* bookmark_model) { | |
| 48 if (FromWebContents(web_contents)) | 47 if (FromWebContents(web_contents)) |
| 49 return; | 48 return; |
| 50 | 49 |
| 51 web_contents->SetUserData( | 50 web_contents->SetUserData( |
| 52 UserDataKey(), | 51 UserDataKey(), base::WrapUnique(new ContentFaviconDriver( |
| 53 base::WrapUnique(new ContentFaviconDriver( | 52 web_contents, favicon_service, history_service))); |
| 54 web_contents, favicon_service, history_service, bookmark_model))); | |
| 55 } | 53 } |
| 56 | 54 |
| 57 void ContentFaviconDriver::SaveFavicon() { | 55 void ContentFaviconDriver::SaveFaviconEvenIfInIncognito() { |
| 58 content::NavigationEntry* entry = | 56 content::NavigationEntry* entry = |
| 59 web_contents()->GetController().GetLastCommittedEntry(); | 57 web_contents()->GetController().GetLastCommittedEntry(); |
| 60 if (!entry) | 58 if (!entry) |
| 61 return; | 59 return; |
| 62 | 60 |
| 63 // Make sure the page is in history, otherwise adding the favicon does | 61 // Make sure the page is in history, otherwise adding the favicon does |
| 64 // nothing. | 62 // nothing. |
| 65 if (!history_service()) | 63 if (!history_service()) |
| 66 return; | 64 return; |
| 67 GURL page_url = entry->GetURL(); | 65 GURL page_url = entry->GetURL(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 106 |
| 109 GURL ContentFaviconDriver::GetActiveURL() { | 107 GURL ContentFaviconDriver::GetActiveURL() { |
| 110 content::NavigationEntry* entry = | 108 content::NavigationEntry* entry = |
| 111 web_contents()->GetController().GetLastCommittedEntry(); | 109 web_contents()->GetController().GetLastCommittedEntry(); |
| 112 return entry ? entry->GetURL() : GURL(); | 110 return entry ? entry->GetURL() : GURL(); |
| 113 } | 111 } |
| 114 | 112 |
| 115 ContentFaviconDriver::ContentFaviconDriver( | 113 ContentFaviconDriver::ContentFaviconDriver( |
| 116 content::WebContents* web_contents, | 114 content::WebContents* web_contents, |
| 117 FaviconService* favicon_service, | 115 FaviconService* favicon_service, |
| 118 history::HistoryService* history_service, | 116 history::HistoryService* history_service) |
| 119 bookmarks::BookmarkModel* bookmark_model) | |
| 120 : content::WebContentsObserver(web_contents), | 117 : content::WebContentsObserver(web_contents), |
| 121 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 118 FaviconDriverImpl(favicon_service, history_service) {} |
| 122 } | |
| 123 | 119 |
| 124 ContentFaviconDriver::~ContentFaviconDriver() { | 120 ContentFaviconDriver::~ContentFaviconDriver() { |
| 125 } | 121 } |
| 126 | 122 |
| 127 int ContentFaviconDriver::DownloadImage(const GURL& url, | 123 int ContentFaviconDriver::DownloadImage(const GURL& url, |
| 128 int max_image_size, | 124 int max_image_size, |
| 129 ImageDownloadCallback callback) { | 125 ImageDownloadCallback callback) { |
| 130 bool bypass_cache = (bypass_cache_page_url_ == GetActiveURL()); | 126 bool bypass_cache = (bypass_cache_page_url_ == GetActiveURL()); |
| 131 bypass_cache_page_url_ = GURL(); | 127 bypass_cache_page_url_ = GURL(); |
| 132 | 128 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // redownloaded. | 237 // redownloaded. |
| 242 GURL url = navigation_handle->GetURL(); | 238 GURL url = navigation_handle->GetURL(); |
| 243 if (url != bypass_cache_page_url_) | 239 if (url != bypass_cache_page_url_) |
| 244 bypass_cache_page_url_ = GURL(); | 240 bypass_cache_page_url_ = GURL(); |
| 245 | 241 |
| 246 // Get the favicon, either from history or request it from the net. | 242 // Get the favicon, either from history or request it from the net. |
| 247 FetchFavicon(url, navigation_handle->IsSameDocument()); | 243 FetchFavicon(url, navigation_handle->IsSameDocument()); |
| 248 } | 244 } |
| 249 | 245 |
| 250 } // namespace favicon | 246 } // namespace favicon |
| OLD | NEW |