| 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 "content/renderer/manifest/manifest_parser.h" | 5 #include "content/renderer/manifest/manifest_parser.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/nullable_string16.h" | 11 #include "base/strings/nullable_string16.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "content/public/common/manifest.h" | 17 #include "content/public/common/manifest.h" |
| 18 #include "content/public/common/manifest_util.h" |
| 18 #include "content/renderer/manifest/manifest_uma_util.h" | 19 #include "content/renderer/manifest/manifest_uma_util.h" |
| 19 #include "third_party/WebKit/public/platform/WebColor.h" | 20 #include "third_party/WebKit/public/platform/WebColor.h" |
| 20 #include "third_party/WebKit/public/platform/WebIconSizesParser.h" | 21 #include "third_party/WebKit/public/platform/WebIconSizesParser.h" |
| 21 #include "third_party/WebKit/public/platform/WebSize.h" | 22 #include "third_party/WebKit/public/platform/WebSize.h" |
| 22 #include "third_party/WebKit/public/platform/WebString.h" | 23 #include "third_party/WebKit/public/platform/WebString.h" |
| 23 #include "third_party/WebKit/public/web/WebCSSParser.h" | 24 #include "third_party/WebKit/public/web/WebCSSParser.h" |
| 24 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 | 28 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 215 } |
| 215 return scope; | 216 return scope; |
| 216 } | 217 } |
| 217 | 218 |
| 218 blink::WebDisplayMode ManifestParser::ParseDisplay( | 219 blink::WebDisplayMode ManifestParser::ParseDisplay( |
| 219 const base::DictionaryValue& dictionary) { | 220 const base::DictionaryValue& dictionary) { |
| 220 base::NullableString16 display = ParseString(dictionary, "display", Trim); | 221 base::NullableString16 display = ParseString(dictionary, "display", Trim); |
| 221 if (display.is_null()) | 222 if (display.is_null()) |
| 222 return blink::WebDisplayModeUndefined; | 223 return blink::WebDisplayModeUndefined; |
| 223 | 224 |
| 224 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) | 225 blink::WebDisplayMode display_enum = |
| 225 return blink::WebDisplayModeFullscreen; | 226 WebDisplayModeFromString(base::UTF16ToUTF8(display.string())); |
| 226 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) | 227 if (display_enum == blink::WebDisplayModeUndefined) |
| 227 return blink::WebDisplayModeStandalone; | |
| 228 else if (base::LowerCaseEqualsASCII(display.string(), "minimal-ui")) | |
| 229 return blink::WebDisplayModeMinimalUi; | |
| 230 else if (base::LowerCaseEqualsASCII(display.string(), "browser")) | |
| 231 return blink::WebDisplayModeBrowser; | |
| 232 else { | |
| 233 AddErrorInfo("unknown 'display' value ignored."); | 228 AddErrorInfo("unknown 'display' value ignored."); |
| 234 return blink::WebDisplayModeUndefined; | 229 return display_enum; |
| 235 } | |
| 236 } | 230 } |
| 237 | 231 |
| 238 blink::WebScreenOrientationLockType ManifestParser::ParseOrientation( | 232 blink::WebScreenOrientationLockType ManifestParser::ParseOrientation( |
| 239 const base::DictionaryValue& dictionary) { | 233 const base::DictionaryValue& dictionary) { |
| 240 base::NullableString16 orientation = | 234 base::NullableString16 orientation = |
| 241 ParseString(dictionary, "orientation", Trim); | 235 ParseString(dictionary, "orientation", Trim); |
| 242 | 236 |
| 243 if (orientation.is_null()) | 237 if (orientation.is_null()) |
| 244 return blink::WebScreenOrientationLockDefault; | 238 return blink::WebScreenOrientationLockDefault; |
| 245 | 239 |
| 246 if (base::LowerCaseEqualsASCII(orientation.string(), "any")) | 240 blink::WebScreenOrientationLockType orientation_enum = |
| 247 return blink::WebScreenOrientationLockAny; | 241 WebScreenOrientationLockTypeFromString( |
| 248 else if (base::LowerCaseEqualsASCII(orientation.string(), "natural")) | 242 base::UTF16ToUTF8(orientation.string())); |
| 249 return blink::WebScreenOrientationLockNatural; | 243 if (orientation_enum == blink::WebScreenOrientationLockDefault) |
| 250 else if (base::LowerCaseEqualsASCII(orientation.string(), "landscape")) | |
| 251 return blink::WebScreenOrientationLockLandscape; | |
| 252 else if (base::LowerCaseEqualsASCII(orientation.string(), | |
| 253 "landscape-primary")) | |
| 254 return blink::WebScreenOrientationLockLandscapePrimary; | |
| 255 else if (base::LowerCaseEqualsASCII(orientation.string(), | |
| 256 "landscape-secondary")) | |
| 257 return blink::WebScreenOrientationLockLandscapeSecondary; | |
| 258 else if (base::LowerCaseEqualsASCII(orientation.string(), "portrait")) | |
| 259 return blink::WebScreenOrientationLockPortrait; | |
| 260 else if (base::LowerCaseEqualsASCII(orientation.string(), | |
| 261 "portrait-primary")) | |
| 262 return blink::WebScreenOrientationLockPortraitPrimary; | |
| 263 else if (base::LowerCaseEqualsASCII(orientation.string(), | |
| 264 "portrait-secondary")) | |
| 265 return blink::WebScreenOrientationLockPortraitSecondary; | |
| 266 else { | |
| 267 AddErrorInfo("unknown 'orientation' value ignored."); | 244 AddErrorInfo("unknown 'orientation' value ignored."); |
| 268 return blink::WebScreenOrientationLockDefault; | 245 return orientation_enum; |
| 269 } | |
| 270 } | 246 } |
| 271 | 247 |
| 272 GURL ManifestParser::ParseIconSrc(const base::DictionaryValue& icon) { | 248 GURL ManifestParser::ParseIconSrc(const base::DictionaryValue& icon) { |
| 273 return ParseURL(icon, "src", manifest_url_); | 249 return ParseURL(icon, "src", manifest_url_); |
| 274 } | 250 } |
| 275 | 251 |
| 276 base::NullableString16 ManifestParser::ParseIconType( | 252 base::NullableString16 ManifestParser::ParseIconType( |
| 277 const base::DictionaryValue& icon) { | 253 const base::DictionaryValue& icon) { |
| 278 return ParseString(icon, "type", Trim); | 254 return ParseString(icon, "type", Trim); |
| 279 } | 255 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 } | 385 } |
| 410 | 386 |
| 411 void ManifestParser::AddErrorInfo(const std::string& error_msg, | 387 void ManifestParser::AddErrorInfo(const std::string& error_msg, |
| 412 bool critical, | 388 bool critical, |
| 413 int error_line, | 389 int error_line, |
| 414 int error_column) { | 390 int error_column) { |
| 415 errors_.push_back({error_msg, critical, error_line, error_column}); | 391 errors_.push_back({error_msg, critical, error_line, error_column}); |
| 416 } | 392 } |
| 417 | 393 |
| 418 } // namespace content | 394 } // namespace content |
| OLD | NEW |