| 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/common/favicon/favicon_url_parser.h" | 5 #include "chrome/common/favicon/favicon_url_parser.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "components/favicon_base/favicon_types.h" | 8 #include "components/favicon_base/favicon_types.h" |
| 9 #include "net/url_request/url_request.h" | 9 #include "net/url_request/url_request.h" |
| 10 #include "ui/base/layout.h" | |
| 11 #include "ui/base/webui/web_ui_util.h" | 10 #include "ui/base/webui/web_ui_util.h" |
| 12 #include "ui/gfx/favicon_size.h" | 11 #include "ui/gfx/favicon_size.h" |
| 13 | 12 |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 // Parameters which can be used in chrome://favicon path. See file | 15 // Parameters which can be used in chrome://favicon path. See file |
| 17 // "chrome/browser/ui/webui/favicon_source.h" for a description of | 16 // "chrome/browser/ui/webui/favicon_source.h" for a description of |
| 18 // what each does. | 17 // what each does. |
| 19 const char kIconURLParameter[] = "iconurl/"; | 18 const char kIconURLParameter[] = "iconurl/"; |
| 20 const char kLargestParameter[] = "largest/"; | 19 const char kLargestParameter[] = "largest/"; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 } // namespace | 31 } // namespace |
| 33 | 32 |
| 34 namespace chrome { | 33 namespace chrome { |
| 35 | 34 |
| 36 bool ParseFaviconPath(const std::string& path, | 35 bool ParseFaviconPath(const std::string& path, |
| 37 int icon_types, | 36 int icon_types, |
| 38 ParsedFaviconPath* parsed) { | 37 ParsedFaviconPath* parsed) { |
| 39 parsed->is_icon_url = false; | 38 parsed->is_icon_url = false; |
| 40 parsed->url = ""; | 39 parsed->url = ""; |
| 41 parsed->size_in_dip = gfx::kFaviconSize; | 40 parsed->size_in_dip = gfx::kFaviconSize; |
| 42 parsed->scale_factor = ui::SCALE_FACTOR_100P; | 41 parsed->scale_factor = 1.0f; |
| 43 parsed->path_index = -1; | 42 parsed->path_index = -1; |
| 44 | 43 |
| 45 if (path.empty()) | 44 if (path.empty()) |
| 46 return false; | 45 return false; |
| 47 | 46 |
| 48 size_t parsed_index = 0; | 47 size_t parsed_index = 0; |
| 49 if (HasSubstringAt(path, parsed_index, kLargestParameter)) { | 48 if (HasSubstringAt(path, parsed_index, kLargestParameter)) { |
| 50 parsed_index += strlen(kLargestParameter); | 49 parsed_index += strlen(kLargestParameter); |
| 51 parsed->size_in_dip = 0; | 50 parsed->size_in_dip = 0; |
| 52 } else if (HasSubstringAt(path, parsed_index, kSizeParameter)) { | 51 } else if (HasSubstringAt(path, parsed_index, kSizeParameter)) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 70 } | 69 } |
| 71 | 70 |
| 72 if (!base::StringToInt(size_str, &parsed->size_in_dip)) | 71 if (!base::StringToInt(size_str, &parsed->size_in_dip)) |
| 73 return false; | 72 return false; |
| 74 | 73 |
| 75 if (parsed->size_in_dip != (gfx::kFaviconSize * 4) && | 74 if (parsed->size_in_dip != (gfx::kFaviconSize * 4) && |
| 76 parsed->size_in_dip != (gfx::kFaviconSize * 2)) { | 75 parsed->size_in_dip != (gfx::kFaviconSize * 2)) { |
| 77 // Only 64x64, 32x32 and 16x16 icons are supported. | 76 // Only 64x64, 32x32 and 16x16 icons are supported. |
| 78 parsed->size_in_dip = gfx::kFaviconSize; | 77 parsed->size_in_dip = gfx::kFaviconSize; |
| 79 } | 78 } |
| 80 | |
| 81 if (!scale_str.empty()) | 79 if (!scale_str.empty()) |
| 82 webui::ParseScaleFactor(scale_str, &parsed->scale_factor); | 80 webui::ParseScaleFactor(scale_str, &parsed->scale_factor); |
| 83 | 81 |
| 84 // Return the default favicon (as opposed to a resized favicon) for | 82 // Return the default favicon (as opposed to a resized favicon) for |
| 85 // favicon sizes which are not cached by the favicon service. | 83 // favicon sizes which are not cached by the favicon service. |
| 86 // Currently the favicon service caches: | 84 // Currently the favicon service caches: |
| 87 // - favicons of sizes "gfx::kFaviconSize * scale factor" px of type FAVICON | 85 // - favicons of sizes "gfx::kFaviconSize * scale factor" px of type FAVICON |
| 88 // where scale factor is one of FaviconUtil::GetFaviconScaleFactors(). | 86 // where scale factor is one of FaviconUtil::GetFaviconScaleFactors(). |
| 89 // - the largest TOUCH_ICON / TOUCH_PRECOMPOSED_ICON | 87 // - the largest TOUCH_ICON / TOUCH_PRECOMPOSED_ICON |
| 90 if (parsed->size_in_dip != gfx::kFaviconSize && | 88 if (parsed->size_in_dip != gfx::kFaviconSize && |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // to translate favicon URLs using advanced parameters. | 120 // to translate favicon URLs using advanced parameters. |
| 123 // Example: | 121 // Example: |
| 124 // "chrome-search://favicon/size/16@2x/<renderer-id>/<most-visited-id>" | 122 // "chrome-search://favicon/size/16@2x/<renderer-id>/<most-visited-id>" |
| 125 // would be translated to: | 123 // would be translated to: |
| 126 // "chrome-search://favicon/size/16@2x/<most-visited-item-with-given-id>". | 124 // "chrome-search://favicon/size/16@2x/<most-visited-item-with-given-id>". |
| 127 parsed->path_index = parsed_index; | 125 parsed->path_index = parsed_index; |
| 128 return true; | 126 return true; |
| 129 } | 127 } |
| 130 | 128 |
| 131 } // namespace chrome | 129 } // namespace chrome |
| OLD | NEW |