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 return GURL(); | |
| 192 | |
| 193 if (scope.GetOrigin() != document_url_.GetOrigin()) { | |
| 194 AddErrorInfo("property 'scope' ignored, should be " | |
| 195 "same origin as document."); | |
| 196 return GURL(); | |
| 197 } | |
| 198 | |
| 199 // According to the spec, if the start URL cannot be parsed, the document URL | |
| 200 // should be used as the start URL. If the start_url could not be parsed, | |
|
Xi Han
2016/06/15 15:20:57
start URL v.s start_url, Please keep these termino
| |
| 201 // check that the document URL is within scope. | |
| 202 GURL check_in_scope = start_url.is_empty() ? document_url_ : start_url; | |
| 203 if (check_in_scope.GetOrigin() != scope.GetOrigin() || | |
| 204 !base::StartsWith(check_in_scope.path(), scope.path(), | |
| 205 base::CompareCase::SENSITIVE)) { | |
| 206 AddErrorInfo( | |
| 207 "property 'scope' ignored. Start url should be within scope " | |
| 208 "of scope URL."); | |
| 209 return GURL(); | |
| 210 } | |
| 211 return scope; | |
| 212 } | |
| 213 | |
| 186 blink::WebDisplayMode ManifestParser::ParseDisplay( | 214 blink::WebDisplayMode ManifestParser::ParseDisplay( |
| 187 const base::DictionaryValue& dictionary) { | 215 const base::DictionaryValue& dictionary) { |
| 188 base::NullableString16 display = ParseString(dictionary, "display", Trim); | 216 base::NullableString16 display = ParseString(dictionary, "display", Trim); |
| 189 if (display.is_null()) | 217 if (display.is_null()) |
| 190 return blink::WebDisplayModeUndefined; | 218 return blink::WebDisplayModeUndefined; |
| 191 | 219 |
| 192 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) | 220 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) |
| 193 return blink::WebDisplayModeFullscreen; | 221 return blink::WebDisplayModeFullscreen; |
| 194 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) | 222 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) |
| 195 return blink::WebDisplayModeStandalone; | 223 return blink::WebDisplayModeStandalone; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 } | 405 } |
| 378 | 406 |
| 379 void ManifestParser::AddErrorInfo(const std::string& error_msg, | 407 void ManifestParser::AddErrorInfo(const std::string& error_msg, |
| 380 bool critical, | 408 bool critical, |
| 381 int error_line, | 409 int error_line, |
| 382 int error_column) { | 410 int error_column) { |
| 383 errors_.push_back({error_msg, critical, error_line, error_column}); | 411 errors_.push_back({error_msg, critical, error_line, error_column}); |
| 384 } | 412 } |
| 385 | 413 |
| 386 } // namespace content | 414 } // namespace content |
| OLD | NEW |