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 "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_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/public/common/manifest.h" | 12 #include "content/public/common/manifest.h" |
13 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // Parses the 'name' field of the manifest, as defined in: | 17 // Parses the 'name' field of the manifest, as defined in: |
17 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-name-member | 18 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-name-member |
18 // Returns the parsed string if any, a null string if the parsing failed. | 19 // Returns the parsed string if any, a null string if the parsing failed. |
19 base::NullableString16 ParseName(const base::DictionaryValue& dictionary) { | 20 base::NullableString16 ParseName(const base::DictionaryValue& dictionary) { |
20 if (!dictionary.HasKey("name")) | 21 if (!dictionary.HasKey("name")) |
21 return base::NullableString16(); | 22 return base::NullableString16(); |
22 | 23 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 return GURL(); | 69 return GURL(); |
69 | 70 |
70 if (start_url.GetOrigin() != document_url.GetOrigin()) { | 71 if (start_url.GetOrigin() != document_url.GetOrigin()) { |
71 // TODO(mlamouri): provide a custom message to the developer console. | 72 // TODO(mlamouri): provide a custom message to the developer console. |
72 return GURL(); | 73 return GURL(); |
73 } | 74 } |
74 | 75 |
75 return start_url; | 76 return start_url; |
76 } | 77 } |
77 | 78 |
79 // Parses the 'gcm_sender_id' field of the manifest. | |
80 // This is a proprietary extension that we only use when PushMessaging is | |
81 // enabled in Blink. | |
82 // Returns the parsed string if any, a null string if the parsing failed. | |
83 base::NullableString16 ParseGCMSenderID( | |
84 const base::DictionaryValue& dictionary) { | |
Mike West
2014/09/17 04:20:52
Can you add an ASSERT that the runtime flag isn't
mlamouri (slow - plz ping)
2014/09/17 08:35:41
Done.
| |
85 if (!dictionary.HasKey("gcm_sender_id")) | |
86 return base::NullableString16(); | |
87 | |
88 base::string16 gcm_sender_id; | |
89 if (!dictionary.GetString("gcm_sender_id", &gcm_sender_id)) { | |
90 // TODO(mlamouri): provide a custom message to the developer console. | |
91 return base::NullableString16(); | |
92 } | |
93 | |
94 base::TrimWhitespace(gcm_sender_id, base::TRIM_ALL, &gcm_sender_id); | |
95 return base::NullableString16(gcm_sender_id, false); | |
96 } | |
97 | |
78 } // anonymous namespace | 98 } // anonymous namespace |
79 | 99 |
80 namespace content { | 100 namespace content { |
81 | 101 |
82 Manifest ManifestParser::Parse(const base::StringPiece& json, | 102 Manifest ManifestParser::Parse(const base::StringPiece& json, |
83 const GURL& manifest_url, | 103 const GURL& manifest_url, |
84 const GURL& document_url) { | 104 const GURL& document_url) { |
85 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); | 105 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); |
86 if (!value) { | 106 if (!value) { |
87 // TODO(mlamouri): get the JSON parsing error and report it to the developer | 107 // TODO(mlamouri): get the JSON parsing error and report it to the developer |
(...skipping 12 matching lines...) Expand all Loading... | |
100 // TODO(mlamouri): provide a custom message to the developer console. | 120 // TODO(mlamouri): provide a custom message to the developer console. |
101 return Manifest(); | 121 return Manifest(); |
102 } | 122 } |
103 | 123 |
104 Manifest manifest; | 124 Manifest manifest; |
105 | 125 |
106 manifest.name = ParseName(*dictionary); | 126 manifest.name = ParseName(*dictionary); |
107 manifest.short_name = ParseShortName(*dictionary); | 127 manifest.short_name = ParseShortName(*dictionary); |
108 manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url); | 128 manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url); |
109 | 129 |
130 if (blink::WebRuntimeFeatures::isPushMessagingEnabled()) | |
131 manifest.gcm_sender_id = ParseGCMSenderID(*dictionary); | |
132 | |
110 return manifest; | 133 return manifest; |
111 } | 134 } |
112 | 135 |
113 } // namespace content | 136 } // namespace content |
OLD | NEW |