| 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 "components/favicon/content/favicon_url_util.h" | 9 #include "components/favicon/content/favicon_url_util.h" |
| 9 #include "components/favicon/core/favicon_service.h" | 10 #include "components/favicon/core/favicon_service.h" |
| 10 #include "components/favicon/core/favicon_url.h" | 11 #include "components/favicon/core/favicon_url.h" |
| 11 #include "components/history/core/browser/history_service.h" | 12 #include "components/history/core/browser/history_service.h" |
| 12 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
| 13 #include "content/public/browser/favicon_status.h" | 14 #include "content/public/browser/favicon_status.h" |
| 14 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/navigation_handle.h" | 18 #include "content/public/browser/navigation_handle.h" |
| 18 #include "content/public/common/favicon_url.h" | 19 #include "content/public/common/favicon_url.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 { |
| 24 | 25 |
| 25 // static | 26 // static |
| 26 void ContentFaviconDriver::CreateForWebContents( | 27 void ContentFaviconDriver::CreateForWebContents( |
| 27 content::WebContents* web_contents, | 28 content::WebContents* web_contents, |
| 28 FaviconService* favicon_service, | 29 FaviconService* favicon_service, |
| 29 history::HistoryService* history_service, | 30 history::HistoryService* history_service, |
| 30 bookmarks::BookmarkModel* bookmark_model) { | 31 bookmarks::BookmarkModel* bookmark_model) { |
| 31 if (FromWebContents(web_contents)) | 32 if (FromWebContents(web_contents)) |
| 32 return; | 33 return; |
| 33 | 34 |
| 34 web_contents->SetUserData( | 35 web_contents->SetUserData( |
| 35 UserDataKey(), new ContentFaviconDriver(web_contents, favicon_service, | 36 UserDataKey(), |
| 36 history_service, bookmark_model)); | 37 base::WrapUnique(new ContentFaviconDriver( |
| 38 web_contents, favicon_service, history_service, bookmark_model))); |
| 37 } | 39 } |
| 38 | 40 |
| 39 void ContentFaviconDriver::SaveFavicon() { | 41 void ContentFaviconDriver::SaveFavicon() { |
| 40 content::NavigationEntry* entry = | 42 content::NavigationEntry* entry = |
| 41 web_contents()->GetController().GetLastCommittedEntry(); | 43 web_contents()->GetController().GetLastCommittedEntry(); |
| 42 if (!entry) | 44 if (!entry) |
| 43 return; | 45 return; |
| 44 | 46 |
| 45 // Make sure the page is in history, otherwise adding the favicon does | 47 // Make sure the page is in history, otherwise adding the favicon does |
| 46 // nothing. | 48 // nothing. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // redownloaded. | 194 // redownloaded. |
| 193 GURL url = navigation_handle->GetURL(); | 195 GURL url = navigation_handle->GetURL(); |
| 194 if (url != bypass_cache_page_url_) | 196 if (url != bypass_cache_page_url_) |
| 195 bypass_cache_page_url_ = GURL(); | 197 bypass_cache_page_url_ = GURL(); |
| 196 | 198 |
| 197 // Get the favicon, either from history or request it from the net. | 199 // Get the favicon, either from history or request it from the net. |
| 198 FetchFavicon(url); | 200 FetchFavicon(url); |
| 199 } | 201 } |
| 200 | 202 |
| 201 } // namespace favicon | 203 } // namespace favicon |
| OLD | NEW |