| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return static_cast<int64_t>(signed_color); | 150 return static_cast<int64_t>(signed_color); |
| 150 } | 151 } |
| 151 | 152 |
| 152 GURL ManifestParser::ParseURL(const base::DictionaryValue& dictionary, | 153 GURL ManifestParser::ParseURL(const base::DictionaryValue& dictionary, |
| 153 const std::string& key, | 154 const std::string& key, |
| 154 const GURL& base_url) { | 155 const GURL& base_url) { |
| 155 base::NullableString16 url_str = ParseString(dictionary, key, NoTrim); | 156 base::NullableString16 url_str = ParseString(dictionary, key, NoTrim); |
| 156 if (url_str.is_null()) | 157 if (url_str.is_null()) |
| 157 return GURL(); | 158 return GURL(); |
| 158 | 159 |
| 159 return base_url.Resolve(url_str.string()); | 160 GURL resolved = base_url.Resolve(url_str.string()); |
| 161 if (!resolved.is_valid()) |
| 162 AddErrorInfo("property '" + key + "' ignored, URL is invalid."); |
| 163 return resolved; |
| 160 } | 164 } |
| 161 | 165 |
| 162 base::NullableString16 ManifestParser::ParseName( | 166 base::NullableString16 ManifestParser::ParseName( |
| 163 const base::DictionaryValue& dictionary) { | 167 const base::DictionaryValue& dictionary) { |
| 164 return ParseString(dictionary, "name", Trim); | 168 return ParseString(dictionary, "name", Trim); |
| 165 } | 169 } |
| 166 | 170 |
| 167 base::NullableString16 ManifestParser::ParseShortName( | 171 base::NullableString16 ManifestParser::ParseShortName( |
| 168 const base::DictionaryValue& dictionary) { | 172 const base::DictionaryValue& dictionary) { |
| 169 return ParseString(dictionary, "short_name", Trim); | 173 return ParseString(dictionary, "short_name", Trim); |
| 170 } | 174 } |
| 171 | 175 |
| 172 GURL ManifestParser::ParseStartURL(const base::DictionaryValue& dictionary) { | 176 GURL ManifestParser::ParseStartURL(const base::DictionaryValue& dictionary) { |
| 173 GURL start_url = ParseURL(dictionary, "start_url", manifest_url_); | 177 GURL start_url = ParseURL(dictionary, "start_url", manifest_url_); |
| 174 if (!start_url.is_valid()) | 178 if (!start_url.is_valid()) |
| 175 return GURL(); | 179 return GURL(); |
| 176 | 180 |
| 177 if (start_url.GetOrigin() != document_url_.GetOrigin()) { | 181 if (start_url.GetOrigin() != document_url_.GetOrigin()) { |
| 178 AddErrorInfo("property 'start_url' ignored, should be " | 182 AddErrorInfo("property 'start_url' ignored, should be " |
| 179 "same origin as document."); | 183 "same origin as document."); |
| 180 return GURL(); | 184 return GURL(); |
| 181 } | 185 } |
| 182 | 186 |
| 183 return start_url; | 187 return start_url; |
| 184 } | 188 } |
| 185 | 189 |
| 190 GURL ManifestParser::ParseScope(const base::DictionaryValue& dictionary, |
| 191 const GURL& start_url) { |
| 192 GURL scope = ParseURL(dictionary, "scope", manifest_url_); |
| 193 if (!scope.is_valid()) { |
| 194 return GURL(); |
| 195 } |
| 196 |
| 197 if (scope.GetOrigin() != document_url_.GetOrigin()) { |
| 198 AddErrorInfo("property 'scope' ignored, should be " |
| 199 "same origin as document."); |
| 200 return GURL(); |
| 201 } |
| 202 |
| 203 // According to the spec, if the start_url cannot be parsed, the document URL |
| 204 // should be used as the start URL. If the start_url could not be parsed, |
| 205 // check that the document URL is within scope. |
| 206 GURL check_in_scope = start_url.is_empty() ? document_url_ : start_url; |
| 207 if (check_in_scope.GetOrigin() != scope.GetOrigin() || |
| 208 !base::StartsWith(check_in_scope.path(), scope.path(), |
| 209 base::CompareCase::SENSITIVE)) { |
| 210 AddErrorInfo( |
| 211 "property 'scope' ignored. Start url should be within scope " |
| 212 "of scope URL."); |
| 213 return GURL(); |
| 214 } |
| 215 return scope; |
| 216 } |
| 217 |
| 186 blink::WebDisplayMode ManifestParser::ParseDisplay( | 218 blink::WebDisplayMode ManifestParser::ParseDisplay( |
| 187 const base::DictionaryValue& dictionary) { | 219 const base::DictionaryValue& dictionary) { |
| 188 base::NullableString16 display = ParseString(dictionary, "display", Trim); | 220 base::NullableString16 display = ParseString(dictionary, "display", Trim); |
| 189 if (display.is_null()) | 221 if (display.is_null()) |
| 190 return blink::WebDisplayModeUndefined; | 222 return blink::WebDisplayModeUndefined; |
| 191 | 223 |
| 192 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) | 224 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) |
| 193 return blink::WebDisplayModeFullscreen; | 225 return blink::WebDisplayModeFullscreen; |
| 194 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) | 226 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) |
| 195 return blink::WebDisplayModeStandalone; | 227 return blink::WebDisplayModeStandalone; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 409 } |
| 378 | 410 |
| 379 void ManifestParser::AddErrorInfo(const std::string& error_msg, | 411 void ManifestParser::AddErrorInfo(const std::string& error_msg, |
| 380 bool critical, | 412 bool critical, |
| 381 int error_line, | 413 int error_line, |
| 382 int error_column) { | 414 int error_column) { |
| 383 errors_.push_back({error_msg, critical, error_line, error_column}); | 415 errors_.push_back({error_msg, critical, error_line, error_column}); |
| 384 } | 416 } |
| 385 | 417 |
| 386 } // namespace content | 418 } // namespace content |
| OLD | NEW |