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

Side by Side Diff: third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp

Issue 2767983003: Initial Implementation of Iframe Attribute for Feature Policy (Part 4) (Closed)
Patch Set: Added container policy tests for vibrate Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/feature_policy/FeaturePolicy.h" 5 #include "platform/feature_policy/FeaturePolicy.h"
6 6
7 #include "platform/RuntimeEnabledFeatures.h" 7 #include "platform/RuntimeEnabledFeatures.h"
8 #include "platform/json/JSONValues.h" 8 #include "platform/json/JSONValues.h"
9 #include "platform/network/HTTPParsers.h" 9 #include "platform/network/HTTPParsers.h"
10 #include "platform/weborigin/SecurityOrigin.h" 10 #include "platform/weborigin/SecurityOrigin.h"
11 #include "platform/wtf/PtrUtil.h" 11 #include "platform/wtf/PtrUtil.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 namespace {
16
17 void AddAllowFeatureToList(
18 WebFeaturePolicyFeature feature,
19 Vector<WebParsedFeaturePolicyDeclaration>& whitelists) {
20 WebParsedFeaturePolicyDeclaration whitelist;
21 whitelist.feature = feature;
22 whitelist.matches_all_origins = true;
23 whitelists.push_back(whitelist);
24 }
25
26 void OverridePolicy(int index,
27 Vector<WebParsedFeaturePolicyDeclaration>& whitelists,
28 RefPtr<SecurityOrigin> origin) {
29 whitelists[index].matches_all_origins = false;
30 whitelists[index].origins = Vector<WebSecurityOrigin>(1UL, {origin});
31 }
32
33 } // namespace
34
15 WebParsedFeaturePolicy ParseFeaturePolicy(const String& policy, 35 WebParsedFeaturePolicy ParseFeaturePolicy(const String& policy,
16 RefPtr<SecurityOrigin> origin, 36 RefPtr<SecurityOrigin> origin,
17 Vector<String>* messages) { 37 Vector<String>* messages) {
18 return ParseFeaturePolicy(policy, origin, messages, 38 return ParseFeaturePolicy(policy, origin, messages,
19 GetDefaultFeatureNameMap()); 39 GetDefaultFeatureNameMap());
20 } 40 }
21 41
22 WebParsedFeaturePolicy ParseFeaturePolicy(const String& policy, 42 WebParsedFeaturePolicy ParseFeaturePolicy(const String& policy,
23 RefPtr<SecurityOrigin> origin, 43 RefPtr<SecurityOrigin> origin,
24 Vector<String>* messages, 44 Vector<String>* messages,
(...skipping 29 matching lines...) Expand all
54 messages->push_back("Whitelist is not an array of strings."); 74 messages->push_back("Whitelist is not an array of strings.");
55 continue; 75 continue;
56 } 76 }
57 77
58 WebParsedFeaturePolicyDeclaration whitelist; 78 WebParsedFeaturePolicyDeclaration whitelist;
59 whitelist.feature = feature; 79 whitelist.feature = feature;
60 Vector<WebSecurityOrigin> origins; 80 Vector<WebSecurityOrigin> origins;
61 String target_string; 81 String target_string;
62 for (size_t j = 0; j < targets->size(); ++j) { 82 for (size_t j = 0; j < targets->size(); ++j) {
63 if (targets->at(j)->AsString(&target_string)) { 83 if (targets->at(j)->AsString(&target_string)) {
64 if (DeprecatedEqualIgnoringCase(target_string, "self")) { 84 if (DeprecatedEqualIgnoringCase(target_string, "self")) {
iclelland 2017/04/25 17:19:54 Is there a simple replacement for the recently-dep
lunalu1 2017/04/25 18:31:42 Replaced by EqualIgnoringASCIICase
65 if (!origin->IsUnique()) 85 if (!origin->IsUnique())
66 origins.push_back(origin); 86 origins.push_back(origin);
67 } else if (target_string == "*") { 87 } else if (target_string == "*") {
68 whitelist.matches_all_origins = true; 88 whitelist.matches_all_origins = true;
69 } else { 89 } else {
70 WebSecurityOrigin target_origin = 90 WebSecurityOrigin target_origin =
71 WebSecurityOrigin::CreateFromString(target_string); 91 WebSecurityOrigin::CreateFromString(target_string);
72 if (!target_origin.IsNull() && !target_origin.IsUnique()) 92 if (!target_origin.IsNull() && !target_origin.IsUnique())
73 origins.push_back(target_origin); 93 origins.push_back(target_origin);
74 } 94 }
75 } else { 95 } else {
76 if (messages) 96 if (messages)
77 messages->push_back("Whitelist is not an array of strings."); 97 messages->push_back("Whitelist is not an array of strings.");
78 } 98 }
79 } 99 }
80 whitelist.origins = origins; 100 whitelist.origins = origins;
81 whitelists.push_back(whitelist); 101 whitelists.push_back(whitelist);
82 } 102 }
83 } 103 }
84 return whitelists; 104 return whitelists;
85 } 105 }
86 106
87 // TODO(lunalu): also take information of allowfullscreen and
88 // allowpaymentrequest into account when constructing the whitelist.
89 WebParsedFeaturePolicy GetContainerPolicyFromAllowedFeatures( 107 WebParsedFeaturePolicy GetContainerPolicyFromAllowedFeatures(
90 const WebVector<WebFeaturePolicyFeature>& features, 108 const WebVector<WebFeaturePolicyFeature>& features,
109 bool allowfullscreen,
110 bool allowpayment,
91 RefPtr<SecurityOrigin> origin) { 111 RefPtr<SecurityOrigin> origin) {
92 Vector<WebParsedFeaturePolicyDeclaration> whitelists; 112 Vector<WebParsedFeaturePolicyDeclaration> whitelists;
113 // If allowfullscreen attribute is present, enable the feature for all
iclelland 2017/04/25 17:19:55 I still think we could make this simpler -- could
114 // origins; similarly for allowpaymentrequest.
115 if (allowpayment)
116 AddAllowFeatureToList(WebFeaturePolicyFeature::kPayment, whitelists);
117 if (allowfullscreen)
118 AddAllowFeatureToList(WebFeaturePolicyFeature::kFullscreen, whitelists);
119 bool should_override_payment_policy = false;
120 bool should_override_fullscreen_policy = false;
93 for (const WebFeaturePolicyFeature feature : features) { 121 for (const WebFeaturePolicyFeature feature : features) {
122 // Container policy should override "allowfullscreen" and
123 // "allowpaymentrequest" policies.
124 if (allowpayment && feature == WebFeaturePolicyFeature::kPayment) {
125 should_override_payment_policy = true;
126 continue;
127 }
128 if (allowfullscreen && feature == WebFeaturePolicyFeature::kFullscreen) {
129 should_override_fullscreen_policy = true;
130 continue;
131 }
94 WebParsedFeaturePolicyDeclaration whitelist; 132 WebParsedFeaturePolicyDeclaration whitelist;
95 whitelist.feature = feature; 133 whitelist.feature = feature;
96 whitelist.origins = Vector<WebSecurityOrigin>(1UL, {origin}); 134 whitelist.origins = Vector<WebSecurityOrigin>(1UL, {origin});
97 whitelists.push_back(whitelist); 135 whitelists.push_back(whitelist);
98 } 136 }
137 if (should_override_payment_policy) {
138 OverridePolicy(0, whitelists, origin);
139 }
140 if (should_override_fullscreen_policy) {
141 // Index for fullscreen policy is 1 if payment policy exists in the
142 // whitelists; 0 otherwise.
143 OverridePolicy(allowpayment ? 1 : 0, whitelists, origin);
144 }
145
99 return whitelists; 146 return whitelists;
100 } 147 }
101 148
102 const FeatureNameMap& GetDefaultFeatureNameMap() { 149 const FeatureNameMap& GetDefaultFeatureNameMap() {
103 DEFINE_STATIC_LOCAL(FeatureNameMap, default_feature_name_map, ()); 150 DEFINE_STATIC_LOCAL(FeatureNameMap, default_feature_name_map, ());
104 if (default_feature_name_map.IsEmpty()) { 151 if (default_feature_name_map.IsEmpty()) {
105 default_feature_name_map.Set("fullscreen", 152 default_feature_name_map.Set("fullscreen",
106 WebFeaturePolicyFeature::kFullscreen); 153 WebFeaturePolicyFeature::kFullscreen);
107 default_feature_name_map.Set("payment", WebFeaturePolicyFeature::kPayment); 154 default_feature_name_map.Set("payment", WebFeaturePolicyFeature::kPayment);
108 if (RuntimeEnabledFeatures::featurePolicyExperimentalFeaturesEnabled()) { 155 if (RuntimeEnabledFeatures::featurePolicyExperimentalFeaturesEnabled()) {
109 default_feature_name_map.Set("vibrate", 156 default_feature_name_map.Set("vibrate",
110 WebFeaturePolicyFeature::kVibrate); 157 WebFeaturePolicyFeature::kVibrate);
111 default_feature_name_map.Set("camera", WebFeaturePolicyFeature::kCamera); 158 default_feature_name_map.Set("camera", WebFeaturePolicyFeature::kCamera);
112 default_feature_name_map.Set("eme", WebFeaturePolicyFeature::kEme); 159 default_feature_name_map.Set("eme", WebFeaturePolicyFeature::kEme);
iclelland 2017/04/25 17:19:55 This one is new with this CL -- ddorwin@ asked for
113 default_feature_name_map.Set("microphone", 160 default_feature_name_map.Set("microphone",
114 WebFeaturePolicyFeature::kMicrophone); 161 WebFeaturePolicyFeature::kMicrophone);
115 default_feature_name_map.Set("speaker", 162 default_feature_name_map.Set("speaker",
116 WebFeaturePolicyFeature::kSpeaker); 163 WebFeaturePolicyFeature::kSpeaker);
117 default_feature_name_map.Set("cookie", 164 default_feature_name_map.Set("cookie",
118 WebFeaturePolicyFeature::kDocumentCookie); 165 WebFeaturePolicyFeature::kDocumentCookie);
119 default_feature_name_map.Set("domain", 166 default_feature_name_map.Set("domain",
120 WebFeaturePolicyFeature::kDocumentDomain); 167 WebFeaturePolicyFeature::kDocumentDomain);
121 default_feature_name_map.Set("docwrit", 168 default_feature_name_map.Set("docwrit",
iclelland 2017/04/25 17:19:55 typo: "docwrite"
122 WebFeaturePolicyFeature::kDocumentWrite); 169 WebFeaturePolicyFeature::kDocumentWrite);
123 default_feature_name_map.Set("geolocation", 170 default_feature_name_map.Set("geolocation",
124 WebFeaturePolicyFeature::kGeolocation); 171 WebFeaturePolicyFeature::kGeolocation);
125 default_feature_name_map.Set("midi", 172 default_feature_name_map.Set("midi",
126 WebFeaturePolicyFeature::kMidiFeature); 173 WebFeaturePolicyFeature::kMidiFeature);
127 default_feature_name_map.Set("notifications", 174 default_feature_name_map.Set("notifications",
128 WebFeaturePolicyFeature::kNotifications); 175 WebFeaturePolicyFeature::kNotifications);
129 default_feature_name_map.Set("push", WebFeaturePolicyFeature::kPush); 176 default_feature_name_map.Set("push", WebFeaturePolicyFeature::kPush);
130 default_feature_name_map.Set("sync-script", 177 default_feature_name_map.Set("sync-script",
131 WebFeaturePolicyFeature::kSyncScript); 178 WebFeaturePolicyFeature::kSyncScript);
132 default_feature_name_map.Set("sync-xhr", 179 default_feature_name_map.Set("sync-xhr",
133 WebFeaturePolicyFeature::kSyncXHR); 180 WebFeaturePolicyFeature::kSyncXHR);
134 default_feature_name_map.Set("webrtc", WebFeaturePolicyFeature::kWebRTC); 181 default_feature_name_map.Set("webrtc", WebFeaturePolicyFeature::kWebRTC);
135 } 182 }
136 } 183 }
137 return default_feature_name_map; 184 return default_feature_name_map;
138 } 185 }
139 186
140 } // namespace blink 187 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698