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/ios/web_favicon_driver.h" | 5 #include "components/favicon/ios/web_favicon_driver.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "components/favicon/core/favicon_url.h" | 8 #include "components/favicon/core/favicon_url.h" |
9 #include "components/favicon/ios/favicon_url_util.h" | 9 #include "components/favicon/ios/favicon_url_util.h" |
10 #include "ios/web/public/browser_state.h" | 10 #include "ios/web/public/browser_state.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 fetch_favicon_url_ = url; | 36 fetch_favicon_url_ = url; |
37 FaviconDriverImpl::FetchFavicon(url); | 37 FaviconDriverImpl::FetchFavicon(url); |
38 } | 38 } |
39 | 39 |
40 gfx::Image WebFaviconDriver::GetFavicon() const { | 40 gfx::Image WebFaviconDriver::GetFavicon() const { |
41 web::NavigationItem* item = | 41 web::NavigationItem* item = |
42 web_state()->GetNavigationManager()->GetLastCommittedItem(); | 42 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
43 return item ? item->GetFavicon().image : gfx::Image(); | 43 return item ? item->GetFavicon().image : gfx::Image(); |
44 } | 44 } |
45 | 45 |
| 46 GURL WebFaviconDriver::GetFaviconURL() const { |
| 47 web::NavigationItem* item = |
| 48 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
| 49 return item ? item->GetFavicon().url : GURL(); |
| 50 } |
| 51 |
46 bool WebFaviconDriver::FaviconIsValid() const { | 52 bool WebFaviconDriver::FaviconIsValid() const { |
47 web::NavigationItem* item = | 53 web::NavigationItem* item = |
48 web_state()->GetNavigationManager()->GetLastCommittedItem(); | 54 web_state()->GetNavigationManager()->GetLastCommittedItem(); |
49 return item ? item->GetFavicon().valid : false; | 55 return item ? item->GetFavicon().valid : false; |
50 } | 56 } |
51 | 57 |
52 int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) { | 58 int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) { |
53 if (WasUnableToDownloadFavicon(url)) { | 59 if (WasUnableToDownloadFavicon(url)) { |
54 DVLOG(1) << "Skip Failed FavIcon: " << url; | 60 DVLOG(1) << "Skip Failed FavIcon: " << url; |
55 return 0; | 61 return 0; |
56 } | 62 } |
57 | 63 |
58 return web_state()->DownloadImage( | 64 return web_state()->DownloadImage( |
59 url, true, max_image_size, false, | 65 url, true, max_image_size, false, |
60 base::Bind(&FaviconDriverImpl::DidDownloadFavicon, | 66 base::Bind(&FaviconDriverImpl::DidDownloadFavicon, |
61 base::Unretained(this))); | 67 base::Unretained(this))); |
62 } | 68 } |
63 | 69 |
64 bool WebFaviconDriver::IsOffTheRecord() { | 70 bool WebFaviconDriver::IsOffTheRecord() { |
65 DCHECK(web_state()); | 71 DCHECK(web_state()); |
66 return web_state()->GetBrowserState()->IsOffTheRecord(); | 72 return web_state()->GetBrowserState()->IsOffTheRecord(); |
67 } | 73 } |
68 | 74 |
69 GURL WebFaviconDriver::GetActiveURL() { | 75 GURL WebFaviconDriver::GetActiveURL() { |
70 web::NavigationItem* item = | 76 web::NavigationItem* item = |
71 web_state()->GetNavigationManager()->GetVisibleItem(); | 77 web_state()->GetNavigationManager()->GetVisibleItem(); |
72 return item ? item->GetURL() : GURL(); | 78 return item ? item->GetURL() : GURL(); |
73 } | 79 } |
74 | 80 |
75 void WebFaviconDriver::SetActiveFaviconValidity(bool validity) { | 81 void WebFaviconDriver::OnFaviconUpdated( |
76 GetFaviconStatus().valid = validity; | 82 const GURL& page_url, |
77 } | 83 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 84 const GURL& icon_url, |
| 85 bool icon_url_changed, |
| 86 const gfx::Image& image) { |
| 87 // Check whether the active URL has changed since FetchFavicon() was called. |
| 88 // On iOS, the active URL can change between calls to FetchFavicon(). For |
| 89 // instance, FetchFavicon() is not synchronously called when the active URL |
| 90 // changes as a result of CRWSessionController::goToEntry(). |
| 91 web::NavigationItem* item = |
| 92 web_state()->GetNavigationManager()->GetVisibleItem(); |
| 93 if (!item || item->GetURL() != page_url) |
| 94 return; |
78 | 95 |
79 GURL WebFaviconDriver::GetActiveFaviconURL() { | 96 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, |
80 return GetFaviconStatus().url; | 97 icon_url_changed, image); |
81 } | |
82 | |
83 void WebFaviconDriver::SetActiveFaviconURL(const GURL& url) { | |
84 GetFaviconStatus().url = url; | |
85 } | |
86 | |
87 void WebFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) { | |
88 GetFaviconStatus().image = image; | |
89 } | |
90 | |
91 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() { | |
92 DCHECK(web_state()->GetNavigationManager()->GetVisibleItem()); | |
93 return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon(); | |
94 } | 98 } |
95 | 99 |
96 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, | 100 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, |
97 FaviconService* favicon_service, | 101 FaviconService* favicon_service, |
98 history::HistoryService* history_service, | 102 history::HistoryService* history_service, |
99 bookmarks::BookmarkModel* bookmark_model) | 103 bookmarks::BookmarkModel* bookmark_model) |
100 : web::WebStateObserver(web_state), | 104 : web::WebStateObserver(web_state), |
101 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 105 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { |
102 } | 106 } |
103 | 107 |
104 WebFaviconDriver::~WebFaviconDriver() { | 108 WebFaviconDriver::~WebFaviconDriver() { |
105 } | 109 } |
106 | 110 |
107 void WebFaviconDriver::FaviconUrlUpdated( | 111 void WebFaviconDriver::FaviconUrlUpdated( |
108 const std::vector<web::FaviconURL>& candidates) { | 112 const std::vector<web::FaviconURL>& candidates) { |
109 DCHECK(!candidates.empty()); | 113 DCHECK(!candidates.empty()); |
110 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); | 114 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); |
111 } | 115 } |
112 | 116 |
113 } // namespace favicon | 117 } // namespace favicon |
OLD | NEW |