| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/web_apps.h" | 5 #include "chrome/renderer/web_apps.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 using blink::WebFrame; | 32 using blink::WebFrame; |
| 33 using blink::WebNode; | 33 using blink::WebNode; |
| 34 using blink::WebNodeList; | 34 using blink::WebNodeList; |
| 35 using blink::WebString; | 35 using blink::WebString; |
| 36 | 36 |
| 37 namespace web_apps { | 37 namespace web_apps { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Sizes a single size (the width or height) from a 'sizes' attribute. A size | 40 // Sizes a single size (the width or height) from a 'sizes' attribute. A size |
| 41 // matches must match the following regex: [1-9][0-9]*. | 41 // matches must match the following regex: [1-9][0-9]*. |
| 42 int ParseSingleIconSize(const base::string16& text) { | 42 int ParseSingleIconSize(const base::StringPiece16& text) { |
| 43 // Size must not start with 0, and be between 0 and 9. | 43 // Size must not start with 0, and be between 0 and 9. |
| 44 if (text.empty() || !(text[0] >= L'1' && text[0] <= L'9')) | 44 if (text.empty() || !(text[0] >= L'1' && text[0] <= L'9')) |
| 45 return 0; | 45 return 0; |
| 46 | 46 |
| 47 // Make sure all chars are from 0-9. | 47 // Make sure all chars are from 0-9. |
| 48 for (size_t i = 1; i < text.length(); ++i) { | 48 for (size_t i = 1; i < text.length(); ++i) { |
| 49 if (!(text[i] >= L'0' && text[i] <= L'9')) | 49 if (!(text[i] >= L'0' && text[i] <= L'9')) |
| 50 return 0; | 50 return 0; |
| 51 } | 51 } |
| 52 int output; | 52 int output; |
| 53 if (!base::StringToInt(text, &output)) | 53 if (!base::StringToInt(text, &output)) |
| 54 return 0; | 54 return 0; |
| 55 return output; | 55 return output; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Parses an icon size. An icon size must match the following regex: | 58 // Parses an icon size. An icon size must match the following regex: |
| 59 // [1-9][0-9]*x[1-9][0-9]*. | 59 // [1-9][0-9]*x[1-9][0-9]*. |
| 60 // If the input couldn't be parsed, a size with a width/height == 0 is returned. | 60 // If the input couldn't be parsed, a size with a width/height == 0 is returned. |
| 61 gfx::Size ParseIconSize(const base::string16& text) { | 61 gfx::Size ParseIconSize(const base::string16& text) { |
| 62 std::vector<base::string16> sizes; | 62 std::vector<base::StringPiece16> sizes = base::SplitStringPiece( |
| 63 base::SplitStringDontTrim(text, L'x', &sizes); | 63 text, base::string16(1, 'x'), |
| 64 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 64 if (sizes.size() != 2) | 65 if (sizes.size() != 2) |
| 65 return gfx::Size(); | 66 return gfx::Size(); |
| 66 | 67 |
| 67 return gfx::Size(ParseSingleIconSize(sizes[0]), | 68 return gfx::Size(ParseSingleIconSize(sizes[0]), |
| 68 ParseSingleIconSize(sizes[1])); | 69 ParseSingleIconSize(sizes[1])); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void AddInstallIcon(const WebElement& link, | 72 void AddInstallIcon(const WebElement& link, |
| 72 std::vector<WebApplicationInfo::IconInfo>* icons) { | 73 std::vector<WebApplicationInfo::IconInfo>* icons) { |
| 73 WebString href = link.getAttribute("href"); | 74 WebString href = link.getAttribute("href"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 92 icon_info.url = url; | 93 icon_info.url = url; |
| 93 icons->push_back(icon_info); | 94 icons->push_back(icon_info); |
| 94 } | 95 } |
| 95 | 96 |
| 96 } // namespace | 97 } // namespace |
| 97 | 98 |
| 98 bool ParseIconSizes(const base::string16& text, | 99 bool ParseIconSizes(const base::string16& text, |
| 99 std::vector<gfx::Size>* sizes, | 100 std::vector<gfx::Size>* sizes, |
| 100 bool* is_any) { | 101 bool* is_any) { |
| 101 *is_any = false; | 102 *is_any = false; |
| 102 std::vector<base::string16> size_strings; | 103 std::vector<base::string16> size_strings = base::SplitString( |
| 103 base::SplitStringAlongWhitespace(text, &size_strings); | 104 text, base::kWhitespaceASCIIAs16, |
| 105 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 104 for (size_t i = 0; i < size_strings.size(); ++i) { | 106 for (size_t i = 0; i < size_strings.size(); ++i) { |
| 105 if (base::EqualsASCII(size_strings[i], "any")) { | 107 if (base::EqualsASCII(size_strings[i], "any")) { |
| 106 *is_any = true; | 108 *is_any = true; |
| 107 } else { | 109 } else { |
| 108 gfx::Size size = ParseIconSize(size_strings[i]); | 110 gfx::Size size = ParseIconSize(size_strings[i]); |
| 109 if (size.width() <= 0 || size.height() <= 0) | 111 if (size.width() <= 0 || size.height() <= 0) |
| 110 return false; // Bogus size. | 112 return false; // Bogus size. |
| 111 sizes->push_back(size); | 113 sizes->push_back(size); |
| 112 } | 114 } |
| 113 } | 115 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 base::LowerCaseEqualsASCII(content, "yes") && | 181 base::LowerCaseEqualsASCII(content, "yes") && |
| 180 app_info->mobile_capable == | 182 app_info->mobile_capable == |
| 181 WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED) { | 183 WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED) { |
| 182 app_info->mobile_capable = WebApplicationInfo::MOBILE_CAPABLE_APPLE; | 184 app_info->mobile_capable = WebApplicationInfo::MOBILE_CAPABLE_APPLE; |
| 183 } | 185 } |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 } | 188 } |
| 187 | 189 |
| 188 } // namespace web_apps | 190 } // namespace web_apps |
| OLD | NEW |