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 | 79 float scale_factor = 1.0f; |
pkotwicz
2014/05/20 03:31:19
Is this change necessary?
oshima
2014/05/20 18:23:28
Done.
| |
81 if (!scale_str.empty()) | 80 if (!scale_str.empty()) |
82 webui::ParseScaleFactor(scale_str, &parsed->scale_factor); | 81 webui::ParseScaleFactor(scale_str, &scale_factor); |
82 parsed->scale_factor = scale_factor; | |
83 | 83 |
84 // Return the default favicon (as opposed to a resized favicon) for | 84 // Return the default favicon (as opposed to a resized favicon) for |
85 // favicon sizes which are not cached by the favicon service. | 85 // favicon sizes which are not cached by the favicon service. |
86 // Currently the favicon service caches: | 86 // Currently the favicon service caches: |
87 // - favicons of sizes "gfx::kFaviconSize * scale factor" px of type FAVICON | 87 // - favicons of sizes "gfx::kFaviconSize * scale factor" px of type FAVICON |
88 // where scale factor is one of FaviconUtil::GetFaviconScaleFactors(). | 88 // where scale factor is one of FaviconUtil::GetFaviconScaleFactors(). |
89 // - the largest TOUCH_ICON / TOUCH_PRECOMPOSED_ICON | 89 // - the largest TOUCH_ICON / TOUCH_PRECOMPOSED_ICON |
90 if (parsed->size_in_dip != gfx::kFaviconSize && | 90 if (parsed->size_in_dip != gfx::kFaviconSize && |
91 icon_types == favicon_base::FAVICON) | 91 icon_types == favicon_base::FAVICON) |
92 return false; | 92 return false; |
(...skipping 29 matching lines...) Expand all Loading... | |
122 // to translate favicon URLs using advanced parameters. | 122 // to translate favicon URLs using advanced parameters. |
123 // Example: | 123 // Example: |
124 // "chrome-search://favicon/size/16@2x/<renderer-id>/<most-visited-id>" | 124 // "chrome-search://favicon/size/16@2x/<renderer-id>/<most-visited-id>" |
125 // would be translated to: | 125 // would be translated to: |
126 // "chrome-search://favicon/size/16@2x/<most-visited-item-with-given-id>". | 126 // "chrome-search://favicon/size/16@2x/<most-visited-item-with-given-id>". |
127 parsed->path_index = parsed_index; | 127 parsed->path_index = parsed_index; |
128 return true; | 128 return true; |
129 } | 129 } |
130 | 130 |
131 } // namespace chrome | 131 } // namespace chrome |
OLD | NEW |