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

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

Issue 2063003003: Implement "scope" Web Manifest parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'webapk_manifest' into webapk_manifest_scope0 Created 4 years, 6 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 <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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 AddErrorInfo("root element must be a valid JSON object.", true); 57 AddErrorInfo("root element must be a valid JSON object.", true);
58 ManifestUmaUtil::ParseFailed(); 58 ManifestUmaUtil::ParseFailed();
59 failed_ = true; 59 failed_ = true;
60 return; 60 return;
61 } 61 }
62 DCHECK(dictionary); 62 DCHECK(dictionary);
63 63
64 manifest_.name = ParseName(*dictionary); 64 manifest_.name = ParseName(*dictionary);
65 manifest_.short_name = ParseShortName(*dictionary); 65 manifest_.short_name = ParseShortName(*dictionary);
66 manifest_.start_url = ParseStartURL(*dictionary); 66 manifest_.start_url = ParseStartURL(*dictionary);
67 manifest_.scope = ParseScope(*dictionary, manifest_.start_url);
67 manifest_.display = ParseDisplay(*dictionary); 68 manifest_.display = ParseDisplay(*dictionary);
68 manifest_.orientation = ParseOrientation(*dictionary); 69 manifest_.orientation = ParseOrientation(*dictionary);
69 manifest_.icons = ParseIcons(*dictionary); 70 manifest_.icons = ParseIcons(*dictionary);
70 manifest_.related_applications = ParseRelatedApplications(*dictionary); 71 manifest_.related_applications = ParseRelatedApplications(*dictionary);
71 manifest_.prefer_related_applications = 72 manifest_.prefer_related_applications =
72 ParsePreferRelatedApplications(*dictionary); 73 ParsePreferRelatedApplications(*dictionary);
73 manifest_.theme_color = ParseThemeColor(*dictionary); 74 manifest_.theme_color = ParseThemeColor(*dictionary);
74 manifest_.background_color = ParseBackgroundColor(*dictionary); 75 manifest_.background_color = ParseBackgroundColor(*dictionary);
75 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); 76 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary);
76 77
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 177
177 if (start_url.GetOrigin() != document_url_.GetOrigin()) { 178 if (start_url.GetOrigin() != document_url_.GetOrigin()) {
178 AddErrorInfo("property 'start_url' ignored, should be " 179 AddErrorInfo("property 'start_url' ignored, should be "
179 "same origin as document."); 180 "same origin as document.");
180 return GURL(); 181 return GURL();
181 } 182 }
182 183
183 return start_url; 184 return start_url;
184 } 185 }
185 186
187 GURL ManifestParser::ParseScope(const base::DictionaryValue& dictionary,
188 const GURL& start_url) {
189 GURL scope = ParseURL(dictionary, "scope", manifest_url_);
190 if (!scope.is_valid())
hartmanng 2016/06/14 18:29:43 the spec suggests a developer warning here as well
pkotwicz 2016/06/15 01:29:31 You are right. I am following the pattern in Manif
hartmanng 2016/06/15 15:39:30 Fair enough, but maybe add a TODO here?
191 return GURL();
192
193 if (scope.GetOrigin() != document_url_.GetOrigin()) {
hartmanng 2016/06/14 18:29:43 This is most likely correct, but note that the spe
194 AddErrorInfo("property 'scope' ignored, should be "
195 "same origin as document.");
196 return GURL();
197 }
198
199 if (scope.GetOrigin() != start_url.GetOrigin() ||
200 !base::StartsWith(start_url.path(), scope.path(),
hartmanng 2016/06/14 18:29:43 As long as GURL.path() returns a canonicalized pat
pkotwicz 2016/06/15 01:29:31 It looks like GURL::path() returns a canonicalized
hartmanng 2016/06/15 15:39:29 sounds good, thanks for checking.
201 base::CompareCase::SENSITIVE)) {
202 AddErrorInfo("property 'scope' ignored. 'start_url' should be within scope "
203 "of scope URL.");
204 return GURL();
205 }
206
207 return scope;
208 }
209
186 blink::WebDisplayMode ManifestParser::ParseDisplay( 210 blink::WebDisplayMode ManifestParser::ParseDisplay(
187 const base::DictionaryValue& dictionary) { 211 const base::DictionaryValue& dictionary) {
188 base::NullableString16 display = ParseString(dictionary, "display", Trim); 212 base::NullableString16 display = ParseString(dictionary, "display", Trim);
189 if (display.is_null()) 213 if (display.is_null())
190 return blink::WebDisplayModeUndefined; 214 return blink::WebDisplayModeUndefined;
191 215
192 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) 216 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen"))
193 return blink::WebDisplayModeFullscreen; 217 return blink::WebDisplayModeFullscreen;
194 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) 218 else if (base::LowerCaseEqualsASCII(display.string(), "standalone"))
195 return blink::WebDisplayModeStandalone; 219 return blink::WebDisplayModeStandalone;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 401 }
378 402
379 void ManifestParser::AddErrorInfo(const std::string& error_msg, 403 void ManifestParser::AddErrorInfo(const std::string& error_msg,
380 bool critical, 404 bool critical,
381 int error_line, 405 int error_line,
382 int error_column) { 406 int error_column) {
383 errors_.push_back({error_msg, critical, error_line, error_column}); 407 errors_.push_back({error_msg, critical, error_line, error_column});
384 } 408 }
385 409
386 } // namespace content 410 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698