Chromium Code Reviews| 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 <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 Loading... | |
| 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 Loading... | |
| 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()) { | |
| 191 // TODO(pkotwicz): Emit developer warning when URL is invalid. | |
|
mlamouri (slow - plz ping)
2016/06/21 13:48:54
I would prefer if you could do this in this CL. It
| |
| 192 return GURL(); | |
| 193 } | |
| 194 | |
| 195 if (scope.GetOrigin() != document_url_.GetOrigin()) { | |
| 196 AddErrorInfo("property 'scope' ignored, should be " | |
| 197 "same origin as document."); | |
| 198 return GURL(); | |
| 199 } | |
| 200 | |
| 201 // According to the spec, if the start_url cannot be parsed, the document URL | |
| 202 // should be used as the start URL. If the start_url could not be parsed, | |
| 203 // check that the document URL is within scope. | |
| 204 GURL check_in_scope = start_url.is_empty() ? document_url_ : start_url; | |
| 205 if (check_in_scope.GetOrigin() != scope.GetOrigin() || | |
| 206 !base::StartsWith(check_in_scope.path(), scope.path(), | |
| 207 base::CompareCase::SENSITIVE)) { | |
| 208 AddErrorInfo( | |
| 209 "property 'scope' ignored. Start url should be within scope " | |
| 210 "of scope URL."); | |
| 211 return GURL(); | |
| 212 } | |
| 213 return scope; | |
| 214 } | |
| 215 | |
| 186 blink::WebDisplayMode ManifestParser::ParseDisplay( | 216 blink::WebDisplayMode ManifestParser::ParseDisplay( |
| 187 const base::DictionaryValue& dictionary) { | 217 const base::DictionaryValue& dictionary) { |
| 188 base::NullableString16 display = ParseString(dictionary, "display", Trim); | 218 base::NullableString16 display = ParseString(dictionary, "display", Trim); |
| 189 if (display.is_null()) | 219 if (display.is_null()) |
| 190 return blink::WebDisplayModeUndefined; | 220 return blink::WebDisplayModeUndefined; |
| 191 | 221 |
| 192 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) | 222 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) |
| 193 return blink::WebDisplayModeFullscreen; | 223 return blink::WebDisplayModeFullscreen; |
| 194 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) | 224 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) |
| 195 return blink::WebDisplayModeStandalone; | 225 return blink::WebDisplayModeStandalone; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 } | 407 } |
| 378 | 408 |
| 379 void ManifestParser::AddErrorInfo(const std::string& error_msg, | 409 void ManifestParser::AddErrorInfo(const std::string& error_msg, |
| 380 bool critical, | 410 bool critical, |
| 381 int error_line, | 411 int error_line, |
| 382 int error_column) { | 412 int error_column) { |
| 383 errors_.push_back({error_msg, critical, error_line, error_column}); | 413 errors_.push_back({error_msg, critical, error_line, error_column}); |
| 384 } | 414 } |
| 385 | 415 |
| 386 } // namespace content | 416 } // namespace content |
| OLD | NEW |