OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/favicon_downloader.h" | 5 #include "chrome/browser/extensions/favicon_downloader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "components/favicon/content/content_favicon_driver.h" | 8 #include "components/favicon/content/content_favicon_driver.h" |
9 #include "content/public/browser/navigation_handle.h" | 9 #include "content/public/browser/navigation_handle.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 | 57 |
58 std::vector<content::FaviconURL> | 58 std::vector<content::FaviconURL> |
59 FaviconDownloader::GetFaviconURLsFromWebContents() { | 59 FaviconDownloader::GetFaviconURLsFromWebContents() { |
60 favicon::ContentFaviconDriver* content_favicon_driver = | 60 favicon::ContentFaviconDriver* content_favicon_driver = |
61 web_contents() | 61 web_contents() |
62 ? favicon::ContentFaviconDriver::FromWebContents(web_contents()) | 62 ? favicon::ContentFaviconDriver::FromWebContents(web_contents()) |
63 : nullptr; | 63 : nullptr; |
64 // If favicon_urls() is empty, we are guaranteed that DidUpdateFaviconURLs has | 64 // If favicon_urls() is empty, we are guaranteed that DidUpdateFaviconURLs has |
65 // not yet been called for the current page's navigation. | 65 // not yet been called for the current page's navigation. |
66 return content_favicon_driver ? content_favicon_driver->favicon_urls() | 66 return content_favicon_driver |
67 : std::vector<content::FaviconURL>(); | 67 ? content_favicon_driver->favicon_urls().value_or( |
| 68 std::vector<content::FaviconURL>()) |
| 69 : std::vector<content::FaviconURL>(); |
68 } | 70 } |
69 | 71 |
70 void FaviconDownloader::FetchIcons( | 72 void FaviconDownloader::FetchIcons( |
71 const std::vector<content::FaviconURL>& favicon_urls) { | 73 const std::vector<content::FaviconURL>& favicon_urls) { |
72 std::vector<GURL> urls; | 74 std::vector<GURL> urls; |
73 for (std::vector<content::FaviconURL>::const_iterator it = | 75 for (std::vector<content::FaviconURL>::const_iterator it = |
74 favicon_urls.begin(); | 76 favicon_urls.begin(); |
75 it != favicon_urls.end(); ++it) { | 77 it != favicon_urls.end(); ++it) { |
76 if (it->icon_type != content::FaviconURL::INVALID_ICON) | 78 if (it->icon_type != content::FaviconURL::INVALID_ICON) |
77 urls.push_back(it->icon_url); | 79 urls.push_back(it->icon_url); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 void FaviconDownloader::DidUpdateFaviconURL( | 129 void FaviconDownloader::DidUpdateFaviconURL( |
128 const std::vector<content::FaviconURL>& candidates) { | 130 const std::vector<content::FaviconURL>& candidates) { |
129 // Only consider the first candidates we are given. This prevents pages that | 131 // Only consider the first candidates we are given. This prevents pages that |
130 // change their favicon from spamming us. | 132 // change their favicon from spamming us. |
131 if (!need_favicon_urls_) | 133 if (!need_favicon_urls_) |
132 return; | 134 return; |
133 | 135 |
134 need_favicon_urls_ = false; | 136 need_favicon_urls_ = false; |
135 FetchIcons(candidates); | 137 FetchIcons(candidates); |
136 } | 138 } |
OLD | NEW |