OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/web/public/favicon_url.h" | 5 #include "ios/web/public/favicon_url.h" |
6 | 6 |
| 7 #include "base/values.h" |
| 8 |
7 namespace web { | 9 namespace web { |
8 | 10 |
9 FaviconURL::FaviconURL() | 11 FaviconURL::FaviconURL() |
10 : icon_type(INVALID_ICON) { | 12 : icon_type(INVALID_ICON) { |
11 } | 13 } |
12 | 14 |
13 FaviconURL::FaviconURL(const GURL& url, | 15 FaviconURL::FaviconURL(const GURL& url, |
14 IconType type, | 16 IconType type, |
15 const std::vector<gfx::Size>& sizes) | 17 const std::vector<gfx::Size>& sizes) |
16 : icon_url(url), icon_type(type), icon_sizes(sizes) {} | 18 : icon_url(url), icon_type(type), icon_sizes(sizes) {} |
17 | 19 |
18 FaviconURL::FaviconURL(const FaviconURL& other) = default; | 20 FaviconURL::FaviconURL(const FaviconURL& other) = default; |
19 | 21 |
20 FaviconURL::~FaviconURL() { | 22 FaviconURL::~FaviconURL() { |
21 } | 23 } |
22 | 24 |
| 25 bool ExtractFaviconURL(base::ListValue* favicons, |
| 26 std::vector<web::FaviconURL>& result_urls) { |
| 27 for (size_t fav_idx = 0; fav_idx != favicons->GetSize(); ++fav_idx) { |
| 28 base::DictionaryValue* favicon = nullptr; |
| 29 if (!favicons->GetDictionary(fav_idx, &favicon)) |
| 30 return false; |
| 31 std::string href; |
| 32 std::string rel; |
| 33 if (!favicon->GetString("href", &href)) { |
| 34 DLOG(WARNING) << "JS message parameter not found: href"; |
| 35 return false; |
| 36 } |
| 37 if (!favicon->GetString("rel", &rel)) { |
| 38 DLOG(WARNING) << "JS message parameter not found: rel"; |
| 39 return false; |
| 40 } |
| 41 web::FaviconURL::IconType icon_type = web::FaviconURL::FAVICON; |
| 42 if (rel == "apple-touch-icon") |
| 43 icon_type = web::FaviconURL::TOUCH_ICON; |
| 44 else if (rel == "apple-touch-icon-precomposed") |
| 45 icon_type = web::FaviconURL::TOUCH_PRECOMPOSED_ICON; |
| 46 result_urls.push_back( |
| 47 web::FaviconURL(GURL(href), icon_type, std::vector<gfx::Size>())); |
| 48 } |
| 49 return true; |
| 50 } |
| 51 |
23 } // namespace web | 52 } // namespace web |
OLD | NEW |