OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/web_apps.h" | 5 #include "chrome/common/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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 std::string error_message; | 215 std::string error_message; |
216 scoped_ptr<Value> schema( | 216 scoped_ptr<Value> schema( |
217 base::JSONReader::ReadAndReturnError( | 217 base::JSONReader::ReadAndReturnError( |
218 ResourceBundle::GetSharedInstance().GetRawDataResource( | 218 ResourceBundle::GetSharedInstance().GetRawDataResource( |
219 IDR_WEB_APP_SCHEMA).as_string(), | 219 IDR_WEB_APP_SCHEMA).as_string(), |
220 false, // disallow trailing comma | 220 false, // disallow trailing comma |
221 &error_code, | 221 &error_code, |
222 &error_message)); | 222 &error_message)); |
223 CHECK(schema.get()) | 223 CHECK(schema.get()) |
224 << "Error parsing JSON schema: " << error_code << ": " << error_message; | 224 << "Error parsing JSON schema: " << error_code << ": " << error_message; |
225 CHECK(schema->IsType(Value::TYPE_DICTIONARY)) | 225 CHECK(schema->IsDictionary()) << "schema root must be dictionary."; |
226 << "schema root must be dictionary."; | |
227 | 226 |
228 JSONSchemaValidator validator(static_cast<DictionaryValue*>(schema.get())); | 227 JSONSchemaValidator validator(static_cast<DictionaryValue*>(schema.get())); |
229 | 228 |
230 // We allow extra properties in the schema for easy compat with other systems, | 229 // We allow extra properties in the schema for easy compat with other systems, |
231 // and for forward compat with ourselves. | 230 // and for forward compat with ourselves. |
232 validator.set_default_allow_additional_properties(true); | 231 validator.set_default_allow_additional_properties(true); |
233 | 232 |
234 if (!validator.Validate(definition_value)) { | 233 if (!validator.Validate(definition_value)) { |
235 *error = UTF8ToUTF16( | 234 *error = UTF8ToUTF16( |
236 validator.errors()[0].path + ": " + validator.errors()[0].message); | 235 validator.errors()[0].path + ": " + validator.errors()[0].message); |
237 return false; | 236 return false; |
238 } | 237 } |
239 | 238 |
240 // This must be true because the schema requires the root value to be a | 239 // This must be true because the schema requires the root value to be a |
241 // dictionary. | 240 // dictionary. |
242 CHECK(definition_value->IsType(Value::TYPE_DICTIONARY)); | 241 CHECK(definition_value->IsDictionary()); |
243 DictionaryValue* definition = static_cast<DictionaryValue*>(definition_value); | 242 DictionaryValue* definition = static_cast<DictionaryValue*>(definition_value); |
244 | 243 |
245 // Parse launch URL. It must be a valid URL in the same origin as the | 244 // Parse launch URL. It must be a valid URL in the same origin as the |
246 // manifest. | 245 // manifest. |
247 std::string app_url_string; | 246 std::string app_url_string; |
248 GURL app_url; | 247 GURL app_url; |
249 CHECK(definition->GetString("launch_url", &app_url_string)); | 248 CHECK(definition->GetString("launch_url", &app_url_string)); |
250 if (!(app_url = web_app->manifest_url.Resolve(app_url_string)).is_valid() || | 249 if (!(app_url = web_app->manifest_url.Resolve(app_url_string)).is_valid() || |
251 app_url.GetOrigin() != web_app->manifest_url.GetOrigin()) { | 250 app_url.GetOrigin() != web_app->manifest_url.GetOrigin()) { |
252 *error = UTF8ToUTF16(WebApplicationInfo::kInvalidLaunchURL); | 251 *error = UTF8ToUTF16(WebApplicationInfo::kInvalidLaunchURL); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 web_app->app_url = app_url; | 319 web_app->app_url = app_url; |
321 web_app->urls = urls; | 320 web_app->urls = urls; |
322 web_app->permissions = permissions; | 321 web_app->permissions = permissions; |
323 web_app->icons = icons; | 322 web_app->icons = icons; |
324 | 323 |
325 return true; | 324 return true; |
326 | 325 |
327 } | 326 } |
328 | 327 |
329 } // namespace web_apps | 328 } // namespace web_apps |
OLD | NEW |