| 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 "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" | 
| 8 #include "base/strings/nullable_string16.h" | 8 #include "base/strings/nullable_string16.h" | 
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" | 
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" | 
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" | 
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" | 
| 13 #include "base/values.h" | 13 #include "base/values.h" | 
| 14 #include "content/public/common/manifest.h" | 14 #include "content/public/common/manifest.h" | 
|  | 15 #include "content/renderer/manifest/manifest_uma_util.h" | 
| 15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" | 
| 16 | 17 | 
| 17 namespace content { | 18 namespace content { | 
| 18 | 19 | 
| 19 namespace { | 20 namespace { | 
| 20 | 21 | 
| 21 enum TrimType { | 22 enum TrimType { | 
| 22   Trim, | 23   Trim, | 
| 23   NoTrim | 24   NoTrim | 
| 24 }; | 25 }; | 
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 284 | 285 | 
| 285 } // anonymous namespace | 286 } // anonymous namespace | 
| 286 | 287 | 
| 287 Manifest ManifestParser::Parse(const base::StringPiece& json, | 288 Manifest ManifestParser::Parse(const base::StringPiece& json, | 
| 288                                const GURL& manifest_url, | 289                                const GURL& manifest_url, | 
| 289                                const GURL& document_url) { | 290                                const GURL& document_url) { | 
| 290   scoped_ptr<base::Value> value(base::JSONReader::Read(json)); | 291   scoped_ptr<base::Value> value(base::JSONReader::Read(json)); | 
| 291   if (!value) { | 292   if (!value) { | 
| 292     // TODO(mlamouri): get the JSON parsing error and report it to the developer | 293     // TODO(mlamouri): get the JSON parsing error and report it to the developer | 
| 293     // console. | 294     // console. | 
|  | 295     ManifestUmaUtil::ParseFailed(); | 
| 294     return Manifest(); | 296     return Manifest(); | 
| 295   } | 297   } | 
| 296 | 298 | 
| 297   if (value->GetType() != base::Value::TYPE_DICTIONARY) { | 299   if (value->GetType() != base::Value::TYPE_DICTIONARY) { | 
| 298     // TODO(mlamouri): provide a custom message to the developer console. | 300     // TODO(mlamouri): provide a custom message to the developer console. | 
|  | 301     ManifestUmaUtil::ParseFailed(); | 
| 299     return Manifest(); | 302     return Manifest(); | 
| 300   } | 303   } | 
| 301 | 304 | 
| 302   base::DictionaryValue* dictionary = 0; | 305   base::DictionaryValue* dictionary = 0; | 
| 303   value->GetAsDictionary(&dictionary); | 306   value->GetAsDictionary(&dictionary); | 
| 304   if (!dictionary) { | 307   if (!dictionary) { | 
| 305     // TODO(mlamouri): provide a custom message to the developer console. | 308     // TODO(mlamouri): provide a custom message to the developer console. | 
|  | 309     ManifestUmaUtil::ParseFailed(); | 
| 306     return Manifest(); | 310     return Manifest(); | 
| 307   } | 311   } | 
| 308 | 312 | 
| 309   Manifest manifest; | 313   Manifest manifest; | 
| 310 | 314 | 
| 311   manifest.name = ParseName(*dictionary); | 315   manifest.name = ParseName(*dictionary); | 
| 312   manifest.short_name = ParseShortName(*dictionary); | 316   manifest.short_name = ParseShortName(*dictionary); | 
| 313   manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url); | 317   manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url); | 
| 314   manifest.display = ParseDisplay(*dictionary); | 318   manifest.display = ParseDisplay(*dictionary); | 
| 315   manifest.orientation = ParseOrientation(*dictionary); | 319   manifest.orientation = ParseOrientation(*dictionary); | 
| 316   manifest.icons = ParseIcons(*dictionary, manifest_url); | 320   manifest.icons = ParseIcons(*dictionary, manifest_url); | 
| 317   manifest.gcm_sender_id = ParseGCMSenderID(*dictionary); | 321   manifest.gcm_sender_id = ParseGCMSenderID(*dictionary); | 
| 318 | 322 | 
|  | 323   ManifestUmaUtil::ParseSucceeded(manifest); | 
|  | 324 | 
| 319   return manifest; | 325   return manifest; | 
| 320 } | 326 } | 
| 321 | 327 | 
| 322 } // namespace content | 328 } // namespace content | 
| OLD | NEW | 
|---|