Chromium Code Reviews| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 content::NavigationEntry* entry = controller.GetTransientEntry(); | 66 content::NavigationEntry* entry = controller.GetTransientEntry(); |
| 67 if (entry) | 67 if (entry) |
| 68 return entry->GetFavicon().image; | 68 return entry->GetFavicon().image; |
| 69 | 69 |
| 70 entry = controller.GetLastCommittedEntry(); | 70 entry = controller.GetLastCommittedEntry(); |
| 71 if (entry) | 71 if (entry) |
| 72 return entry->GetFavicon().image; | 72 return entry->GetFavicon().image; |
| 73 return gfx::Image(); | 73 return gfx::Image(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 GURL ContentFaviconDriver::GetFaviconURL() const { | |
| 77 const content::NavigationController& controller = | |
| 78 web_contents()->GetController(); | |
| 79 content::NavigationEntry* entry = controller.GetTransientEntry(); | |
| 80 if (entry) | |
| 81 return entry->GetFavicon().url; | |
| 82 | |
| 83 entry = controller.GetLastCommittedEntry(); | |
| 84 if (entry) | |
| 85 return entry->GetFavicon().url; | |
| 86 return GURL(); | |
| 87 } | |
| 88 | |
| 76 bool ContentFaviconDriver::FaviconIsValid() const { | 89 bool ContentFaviconDriver::FaviconIsValid() const { |
| 77 const content::NavigationController& controller = | 90 const content::NavigationController& controller = |
| 78 web_contents()->GetController(); | 91 web_contents()->GetController(); |
| 79 content::NavigationEntry* entry = controller.GetTransientEntry(); | 92 content::NavigationEntry* entry = controller.GetTransientEntry(); |
| 80 if (entry) | 93 if (entry) |
| 81 return entry->GetFavicon().valid; | 94 return entry->GetFavicon().valid; |
| 82 | 95 |
| 83 entry = controller.GetLastCommittedEntry(); | 96 entry = controller.GetLastCommittedEntry(); |
| 84 if (entry) | 97 if (entry) |
| 85 return entry->GetFavicon().valid; | 98 return entry->GetFavicon().valid; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 106 DCHECK(web_contents()); | 119 DCHECK(web_contents()); |
| 107 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 120 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 108 } | 121 } |
| 109 | 122 |
| 110 GURL ContentFaviconDriver::GetActiveURL() { | 123 GURL ContentFaviconDriver::GetActiveURL() { |
| 111 content::NavigationEntry* entry = | 124 content::NavigationEntry* entry = |
| 112 web_contents()->GetController().GetLastCommittedEntry(); | 125 web_contents()->GetController().GetLastCommittedEntry(); |
| 113 return entry ? entry->GetURL() : GURL(); | 126 return entry ? entry->GetURL() : GURL(); |
| 114 } | 127 } |
| 115 | 128 |
| 116 void ContentFaviconDriver::SetActiveFaviconValidity(bool valid) { | |
| 117 GetFaviconStatus().valid = valid; | |
| 118 } | |
| 119 | |
| 120 GURL ContentFaviconDriver::GetActiveFaviconURL() { | |
| 121 return GetFaviconStatus().url; | |
| 122 } | |
| 123 | |
| 124 void ContentFaviconDriver::SetActiveFaviconURL(const GURL& url) { | |
| 125 GetFaviconStatus().url = url; | |
| 126 } | |
| 127 | |
| 128 void ContentFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) { | |
| 129 GetFaviconStatus().image = image; | |
| 130 } | |
| 131 | |
| 132 content::FaviconStatus& ContentFaviconDriver::GetFaviconStatus() { | |
| 133 DCHECK(web_contents()->GetController().GetLastCommittedEntry()); | |
| 134 return web_contents()->GetController().GetLastCommittedEntry()->GetFavicon(); | |
| 135 } | |
| 136 | |
| 137 ContentFaviconDriver::ContentFaviconDriver( | 129 ContentFaviconDriver::ContentFaviconDriver( |
| 138 content::WebContents* web_contents, | 130 content::WebContents* web_contents, |
| 139 FaviconService* favicon_service, | 131 FaviconService* favicon_service, |
| 140 history::HistoryService* history_service, | 132 history::HistoryService* history_service, |
| 141 bookmarks::BookmarkModel* bookmark_model) | 133 bookmarks::BookmarkModel* bookmark_model) |
| 142 : content::WebContentsObserver(web_contents), | 134 : content::WebContentsObserver(web_contents), |
| 143 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { | 135 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { |
| 144 } | 136 } |
| 145 | 137 |
| 146 ContentFaviconDriver::~ContentFaviconDriver() { | 138 ContentFaviconDriver::~ContentFaviconDriver() { |
| 147 } | 139 } |
| 148 | 140 |
| 149 void ContentFaviconDriver::NotifyFaviconUpdated(bool icon_url_changed) { | 141 void ContentFaviconDriver::OnFaviconUpdated( |
| 150 FaviconDriverImpl::NotifyFaviconUpdated(icon_url_changed); | 142 const GURL& page_url, |
| 151 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 143 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 144 const GURL& icon_url, | |
| 145 bool icon_url_changed, | |
| 146 const gfx::Image& image) { | |
| 147 // Check whether the active URL has changed since FetchFavicon() was called. | |
| 148 // This should never occur. | |
|
sky
2015/11/20 00:44:26
DCHECK
pkotwicz
2015/11/21 23:04:08
Done.
| |
| 149 content::NavigationEntry* entry = | |
| 150 web_contents()->GetController().GetLastCommittedEntry(); | |
| 151 if (!entry || entry->GetURL() != page_url) | |
| 152 return; | |
| 153 | |
| 154 if (notification_icon_type == FaviconDriverObserver::NON_TOUCH_16_DIP) { | |
| 155 entry->GetFavicon().valid = true; | |
| 156 entry->GetFavicon().url = icon_url; | |
| 157 entry->GetFavicon().image = image; | |
| 158 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | |
| 159 } | |
| 160 | |
| 161 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, | |
| 162 icon_url_changed, image); | |
| 152 } | 163 } |
| 153 | 164 |
| 154 void ContentFaviconDriver::DidUpdateFaviconURL( | 165 void ContentFaviconDriver::DidUpdateFaviconURL( |
| 155 const std::vector<content::FaviconURL>& candidates) { | 166 const std::vector<content::FaviconURL>& candidates) { |
| 156 DCHECK(!candidates.empty()); | 167 DCHECK(!candidates.empty()); |
| 157 | 168 |
| 158 // Ignore the update if there is no last committed navigation entry. This can | 169 // Ignore the update if there is no last committed navigation entry. This can |
| 159 // occur when loading an initially blank page. | 170 // occur when loading an initially blank page. |
| 160 content::NavigationEntry* entry = | 171 content::NavigationEntry* entry = |
| 161 web_contents()->GetController().GetLastCommittedEntry(); | 172 web_contents()->GetController().GetLastCommittedEntry(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 // redownloaded. | 204 // redownloaded. |
| 194 GURL url = details.entry->GetURL(); | 205 GURL url = details.entry->GetURL(); |
| 195 if (url != bypass_cache_page_url_) | 206 if (url != bypass_cache_page_url_) |
| 196 bypass_cache_page_url_ = GURL(); | 207 bypass_cache_page_url_ = GURL(); |
| 197 | 208 |
| 198 // Get the favicon, either from history or request it from the net. | 209 // Get the favicon, either from history or request it from the net. |
| 199 FetchFavicon(url); | 210 FetchFavicon(url); |
| 200 } | 211 } |
| 201 | 212 |
| 202 } // namespace favicon | 213 } // namespace favicon |
| OLD | NEW |