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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 202 } |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 return true; | 206 return true; |
207 } | 207 } |
208 | 208 |
209 bool ParseWebAppFromDefinitionFile(Value* definition_value, | 209 bool ParseWebAppFromDefinitionFile(Value* definition_value, |
210 WebApplicationInfo* web_app, | 210 WebApplicationInfo* web_app, |
211 string16* error) { | 211 string16* error) { |
212 CHECK(web_app->manifest_url.is_valid()); | 212 DCHECK(web_app->manifest_url.is_valid()); |
213 | 213 |
214 int error_code = 0; | 214 int error_code = 0; |
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 DCHECK(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 DCHECK(schema->IsType(Value::TYPE_DICTIONARY)) |
226 << "schema root must be dictionary."; | 226 << "schema root must be dictionary."; |
227 | 227 |
228 JSONSchemaValidator validator(static_cast<DictionaryValue*>(schema.get())); | 228 JSONSchemaValidator validator(static_cast<DictionaryValue*>(schema.get())); |
229 | 229 |
230 // We allow extra properties in the schema for easy compat with other systems, | 230 // We allow extra properties in the schema for easy compat with other systems, |
231 // and for forward compat with ourselves. | 231 // and for forward compat with ourselves. |
232 validator.set_default_allow_additional_properties(true); | 232 validator.set_default_allow_additional_properties(true); |
233 | 233 |
234 if (!validator.Validate(definition_value)) { | 234 if (!validator.Validate(definition_value)) { |
235 *error = UTF8ToUTF16( | 235 *error = UTF8ToUTF16( |
236 validator.errors()[0].path + ": " + validator.errors()[0].message); | 236 validator.errors()[0].path + ": " + validator.errors()[0].message); |
237 return false; | 237 return false; |
238 } | 238 } |
239 | 239 |
240 // This must be true because the schema requires the root value to be a | 240 // This must be true because the schema requires the root value to be a |
241 // dictionary. | 241 // dictionary. |
242 CHECK(definition_value->IsType(Value::TYPE_DICTIONARY)); | 242 DCHECK(definition_value->IsType(Value::TYPE_DICTIONARY)); |
243 DictionaryValue* definition = static_cast<DictionaryValue*>(definition_value); | 243 DictionaryValue* definition = static_cast<DictionaryValue*>(definition_value); |
244 | 244 |
245 // Parse launch URL. It must be a valid URL in the same origin as the | 245 // Parse launch URL. It must be a valid URL in the same origin as the |
246 // manifest. | 246 // manifest. |
247 std::string app_url_string; | 247 std::string app_url_string; |
248 GURL app_url; | 248 GURL app_url; |
249 CHECK(definition->GetString("launch_url", &app_url_string)); | 249 CHECK(definition->GetString("launch_url", &app_url_string)); |
250 if (!(app_url = web_app->manifest_url.Resolve(app_url_string)).is_valid() || | 250 if (!(app_url = web_app->manifest_url.Resolve(app_url_string)).is_valid() || |
251 app_url.GetOrigin() != web_app->manifest_url.GetOrigin()) { | 251 app_url.GetOrigin() != web_app->manifest_url.GetOrigin()) { |
252 *error = UTF8ToUTF16(WebApplicationInfo::kInvalidLaunchURL); | 252 *error = UTF8ToUTF16(WebApplicationInfo::kInvalidLaunchURL); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 web_app->app_url = app_url; | 320 web_app->app_url = app_url; |
321 web_app->urls = urls; | 321 web_app->urls = urls; |
322 web_app->permissions = permissions; | 322 web_app->permissions = permissions; |
323 web_app->icons = icons; | 323 web_app->icons = icons; |
324 | 324 |
325 return true; | 325 return true; |
326 | 326 |
327 } | 327 } |
328 | 328 |
329 } // namespace web_apps | 329 } // namespace web_apps |
OLD | NEW |