Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/renderer/web_apps.cc

Issue 105493002: Use base namespace for string16 in chrome/renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/web_apps.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 22 matching lines...) Expand all
33 using blink::WebFrame; 33 using blink::WebFrame;
34 using blink::WebNode; 34 using blink::WebNode;
35 using blink::WebNodeList; 35 using blink::WebNodeList;
36 using blink::WebString; 36 using blink::WebString;
37 37
38 namespace web_apps { 38 namespace web_apps {
39 namespace { 39 namespace {
40 40
41 // Sizes a single size (the width or height) from a 'sizes' attribute. A size 41 // Sizes a single size (the width or height) from a 'sizes' attribute. A size
42 // matches must match the following regex: [1-9][0-9]*. 42 // matches must match the following regex: [1-9][0-9]*.
43 int ParseSingleIconSize(const string16& text) { 43 int ParseSingleIconSize(const base::string16& text) {
44 // Size must not start with 0, and be between 0 and 9. 44 // Size must not start with 0, and be between 0 and 9.
45 if (text.empty() || !(text[0] >= L'1' && text[0] <= L'9')) 45 if (text.empty() || !(text[0] >= L'1' && text[0] <= L'9'))
46 return 0; 46 return 0;
47 47
48 // Make sure all chars are from 0-9. 48 // Make sure all chars are from 0-9.
49 for (size_t i = 1; i < text.length(); ++i) { 49 for (size_t i = 1; i < text.length(); ++i) {
50 if (!(text[i] >= L'0' && text[i] <= L'9')) 50 if (!(text[i] >= L'0' && text[i] <= L'9'))
51 return 0; 51 return 0;
52 } 52 }
53 int output; 53 int output;
54 if (!base::StringToInt(text, &output)) 54 if (!base::StringToInt(text, &output))
55 return 0; 55 return 0;
56 return output; 56 return output;
57 } 57 }
58 58
59 // Parses an icon size. An icon size must match the following regex: 59 // Parses an icon size. An icon size must match the following regex:
60 // [1-9][0-9]*x[1-9][0-9]*. 60 // [1-9][0-9]*x[1-9][0-9]*.
61 // If the input couldn't be parsed, a size with a width/height == 0 is returned. 61 // If the input couldn't be parsed, a size with a width/height == 0 is returned.
62 gfx::Size ParseIconSize(const string16& text) { 62 gfx::Size ParseIconSize(const base::string16& text) {
63 std::vector<string16> sizes; 63 std::vector<base::string16> sizes;
64 base::SplitStringDontTrim(text, L'x', &sizes); 64 base::SplitStringDontTrim(text, L'x', &sizes);
65 if (sizes.size() != 2) 65 if (sizes.size() != 2)
66 return gfx::Size(); 66 return gfx::Size();
67 67
68 return gfx::Size(ParseSingleIconSize(sizes[0]), 68 return gfx::Size(ParseSingleIconSize(sizes[0]),
69 ParseSingleIconSize(sizes[1])); 69 ParseSingleIconSize(sizes[1]));
70 } 70 }
71 71
72 void AddInstallIcon(const WebElement& link, 72 void AddInstallIcon(const WebElement& link,
73 std::vector<WebApplicationInfo::IconInfo>* icons) { 73 std::vector<WebApplicationInfo::IconInfo>* icons) {
(...skipping 15 matching lines...) Expand all
89 icon_sizes.size() == 1) { 89 icon_sizes.size() == 1) {
90 icon_info.width = icon_sizes[0].width(); 90 icon_info.width = icon_sizes[0].width();
91 icon_info.height = icon_sizes[0].height(); 91 icon_info.height = icon_sizes[0].height();
92 } 92 }
93 icon_info.url = url; 93 icon_info.url = url;
94 icons->push_back(icon_info); 94 icons->push_back(icon_info);
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 bool ParseIconSizes(const string16& text, 99 bool ParseIconSizes(const base::string16& text,
100 std::vector<gfx::Size>* sizes, 100 std::vector<gfx::Size>* sizes,
101 bool* is_any) { 101 bool* is_any) {
102 *is_any = false; 102 *is_any = false;
103 std::vector<string16> size_strings; 103 std::vector<base::string16> size_strings;
104 base::SplitStringAlongWhitespace(text, &size_strings); 104 base::SplitStringAlongWhitespace(text, &size_strings);
105 for (size_t i = 0; i < size_strings.size(); ++i) { 105 for (size_t i = 0; i < size_strings.size(); ++i) {
106 if (EqualsASCII(size_strings[i], "any")) { 106 if (EqualsASCII(size_strings[i], "any")) {
107 *is_any = true; 107 *is_any = true;
108 } else { 108 } else {
109 gfx::Size size = ParseIconSize(size_strings[i]); 109 gfx::Size size = ParseIconSize(size_strings[i]);
110 if (size.width() <= 0 || size.height() <= 0) 110 if (size.width() <= 0 || size.height() <= 0)
111 return false; // Bogus size. 111 return false; // Bogus size.
112 sizes->push_back(size); 112 sizes->push_back(size);
113 } 113 }
114 } 114 }
115 if (*is_any && !sizes->empty()) { 115 if (*is_any && !sizes->empty()) {
116 // If is_any is true, it must occur by itself. 116 // If is_any is true, it must occur by itself.
117 return false; 117 return false;
118 } 118 }
119 return (*is_any || !sizes->empty()); 119 return (*is_any || !sizes->empty());
120 } 120 }
121 121
122 bool ParseWebAppFromWebDocument(WebFrame* frame, 122 bool ParseWebAppFromWebDocument(WebFrame* frame,
123 WebApplicationInfo* app_info, 123 WebApplicationInfo* app_info,
124 string16* error) { 124 base::string16* error) {
125 WebDocument document = frame->document(); 125 WebDocument document = frame->document();
126 if (document.isNull()) 126 if (document.isNull())
127 return true; 127 return true;
128 128
129 WebElement head = document.head(); 129 WebElement head = document.head();
130 if (head.isNull()) 130 if (head.isNull())
131 return true; 131 return true;
132 132
133 GURL document_url = document.url(); 133 GURL document_url = document.url();
134 WebNodeList children = head.childNodes(); 134 WebNodeList children = head.childNodes();
(...skipping 27 matching lines...) Expand all
162 if (!app_info->app_url.is_valid()) 162 if (!app_info->app_url.is_valid())
163 app_info->app_url = GURL(); 163 app_info->app_url = GURL();
164 } 164 }
165 } 165 }
166 } 166 }
167 167
168 return true; 168 return true;
169 } 169 }
170 170
171 } // namespace web_apps 171 } // namespace web_apps
OLDNEW
« no previous file with comments | « chrome/renderer/web_apps.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698