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

Side by Side Diff: content/renderer/manifest/manifest_parser.cc

Issue 919293002: Add related_applications field to manifest parser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do IPC stuff Created 5 years, 10 months 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
OLDNEW
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"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 DCHECK(dictionary); 122 DCHECK(dictionary);
123 123
124 manifest_.name = ParseName(*dictionary); 124 manifest_.name = ParseName(*dictionary);
125 manifest_.short_name = ParseShortName(*dictionary); 125 manifest_.short_name = ParseShortName(*dictionary);
126 manifest_.start_url = ParseStartURL(*dictionary); 126 manifest_.start_url = ParseStartURL(*dictionary);
127 manifest_.display = ParseDisplay(*dictionary); 127 manifest_.display = ParseDisplay(*dictionary);
128 manifest_.orientation = ParseOrientation(*dictionary); 128 manifest_.orientation = ParseOrientation(*dictionary);
129 manifest_.icons = ParseIcons(*dictionary); 129 manifest_.icons = ParseIcons(*dictionary);
130 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); 130 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary);
131 manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary); 131 manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary);
132 manifest_.chrome_related_applications =
133 ParseChromeRelatedApplications(*dictionary);
132 134
133 ManifestUmaUtil::ParseSucceeded(manifest_); 135 ManifestUmaUtil::ParseSucceeded(manifest_);
134 } 136 }
135 137
136 const Manifest& ManifestParser::manifest() const { 138 const Manifest& ManifestParser::manifest() const {
137 return manifest_; 139 return manifest_;
138 } 140 }
139 141
140 const std::vector<std::string>& ManifestParser::errors() const { 142 const std::vector<std::string>& ManifestParser::errors() const {
141 return errors_; 143 return errors_;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 base::NullableString16 ManifestParser::ParseGCMSenderID( 339 base::NullableString16 ManifestParser::ParseGCMSenderID(
338 const base::DictionaryValue& dictionary) { 340 const base::DictionaryValue& dictionary) {
339 return ParseString(dictionary, "gcm_sender_id", Trim); 341 return ParseString(dictionary, "gcm_sender_id", Trim);
340 } 342 }
341 343
342 bool ManifestParser::ParseGCMUserVisibleOnly( 344 bool ManifestParser::ParseGCMUserVisibleOnly(
343 const base::DictionaryValue& dictionary) { 345 const base::DictionaryValue& dictionary) {
344 return ParseBoolean(dictionary, "gcm_user_visible_only", false); 346 return ParseBoolean(dictionary, "gcm_user_visible_only", false);
345 } 347 }
346 348
349 Manifest::ChromeRelatedApplicationPlatform
350 ManifestParser::ParseChromeRelatedApplicationPlatform(
351 const base::DictionaryValue& application) {
352 base::NullableString16 platform = ParseString(application, "platform", Trim);
353 if (platform.is_null()) {
354 errors_.push_back(GetErrorPrefix() + "'platform' is a required field, "
355 "chrome related application ignored.");
356 return Manifest::CHROME_RELATED_APPLICATION_PLATFORM_UNSPECIFIED;
357 }
358
359 if (LowerCaseEqualsASCII(platform.string(), "web"))
360 return Manifest::CHROME_RELATED_APPLICATION_PLATFORM_WEB;
361 else if (LowerCaseEqualsASCII(platform.string(), "android"))
362 return Manifest::CHROME_RELATED_APPLICATION_PLATFORM_ANDROID;
363 else {
364 errors_.push_back(GetErrorPrefix() + "unknown 'platform' value ignored.");
365 return Manifest::CHROME_RELATED_APPLICATION_PLATFORM_UNSPECIFIED;
366 }
367 }
368
369 base::NullableString16 ManifestParser::ParseChromeRelatedApplicationId(
370 const base::DictionaryValue& application) {
371 return ParseString(application, "id", Trim);
372 }
373
374 std::vector<Manifest::ChromeRelatedApplication>
375 ManifestParser::ParseChromeRelatedApplications(
376 const base::DictionaryValue& dictionary) {
377 std::vector<Manifest::ChromeRelatedApplication> applications;
378 if (!dictionary.HasKey("chrome_related_applications"))
379 return applications;
380
381 const base::ListValue* applications_list = nullptr;
382 if (!dictionary.GetList("chrome_related_applications", &applications_list)) {
383 errors_.push_back(
384 GetErrorPrefix() +
385 "property 'chrome_related_applications' ignored, type array expected.");
386 return applications;
387 }
388
389 for (size_t i = 0; i < applications_list->GetSize(); ++i) {
390 const base::DictionaryValue* application_dictionary = nullptr;
391 if (!applications_list->GetDictionary(i, &application_dictionary))
392 continue;
393
394 Manifest::ChromeRelatedApplication application;
395 application.platform =
396 ParseChromeRelatedApplicationPlatform(*application_dictionary);
397 // An application MUST have a valid platform. If it does not, it MUST be
398 // ignored. No error needs to be reported here, as it will have been
399 // reported in ParseChromeRelatedApplicationPlatform.
400 if (application.platform ==
401 Manifest::CHROME_RELATED_APPLICATION_PLATFORM_UNSPECIFIED)
402 continue;
403 application.id = ParseChromeRelatedApplicationId(*application_dictionary);
404
405 applications.push_back(application);
406 }
407
408 return applications;
409 }
410
347 } // namespace content 411 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698