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

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

Issue 2923563003: Move container policy logic to frame owner classes. (Closed)
Patch Set: Addressing nits Created 3 years, 6 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 } // namespace
27
28 WebParsedFeaturePolicy ParseFeaturePolicy(const String& policy, 15 WebParsedFeaturePolicy ParseFeaturePolicy(const String& policy,
29 RefPtr<SecurityOrigin> origin, 16 RefPtr<SecurityOrigin> origin,
30 Vector<String>* messages) { 17 Vector<String>* messages) {
31 return ParseFeaturePolicy(policy, origin, messages, 18 return ParseFeaturePolicy(policy, origin, messages,
32 GetDefaultFeatureNameMap()); 19 GetDefaultFeatureNameMap());
33 } 20 }
34 21
35 WebParsedFeaturePolicy ParseFeaturePolicy(const String& policy, 22 WebParsedFeaturePolicy ParseFeaturePolicy(const String& policy,
36 RefPtr<SecurityOrigin> origin, 23 RefPtr<SecurityOrigin> origin,
37 Vector<String>* messages, 24 Vector<String>* messages,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 messages->push_back("Whitelist is not an array of strings."); 77 messages->push_back("Whitelist is not an array of strings.");
91 } 78 }
92 } 79 }
93 whitelist.origins = origins; 80 whitelist.origins = origins;
94 whitelists.push_back(whitelist); 81 whitelists.push_back(whitelist);
95 } 82 }
96 } 83 }
97 return whitelists; 84 return whitelists;
98 } 85 }
99 86
100 WebParsedFeaturePolicy GetContainerPolicyFromAllowedFeatures(
101 const WebVector<WebFeaturePolicyFeature>& features,
102 bool allowfullscreen,
103 bool allowpayment,
104 RefPtr<SecurityOrigin> origin) {
105 Vector<WebParsedFeaturePolicyDeclaration> whitelists;
106 bool override_payment = false;
107 bool override_fullscreen = false;
108 for (const WebFeaturePolicyFeature feature : features) {
109 // Container policy should override "allowfullscreen" and
110 // "allowpaymentrequest" policies.
111 if (feature == WebFeaturePolicyFeature::kPayment)
112 override_payment = true;
113 if (feature == WebFeaturePolicyFeature::kFullscreen)
114 override_fullscreen = true;
115
116 WebParsedFeaturePolicyDeclaration whitelist;
117 whitelist.feature = feature;
118 whitelist.origins = Vector<WebSecurityOrigin>(1UL, {origin});
119 whitelists.push_back(whitelist);
120 }
121 // If allowfullscreen attribute is present and no fullscreen policy is set,
122 // enable the feature for all origins; similarly for allowpaymentrequest.
123 if (allowpayment && !override_payment)
124 AddAllowFeatureToList(WebFeaturePolicyFeature::kPayment, whitelists);
125 if (allowfullscreen && !override_fullscreen)
126 AddAllowFeatureToList(WebFeaturePolicyFeature::kFullscreen, whitelists);
127
128 return whitelists;
129 }
130
131 bool IsSupportedInFeaturePolicy(WebFeaturePolicyFeature feature) { 87 bool IsSupportedInFeaturePolicy(WebFeaturePolicyFeature feature) {
132 switch (feature) { 88 switch (feature) {
133 // TODO(lunalu): Re-enabled fullscreen in feature policy once tests have 89 // TODO(lunalu): Re-enabled fullscreen in feature policy once tests have
134 // been updated. 90 // been updated.
135 // crbug.com/666761 91 // crbug.com/666761
136 case WebFeaturePolicyFeature::kFullscreen: 92 case WebFeaturePolicyFeature::kFullscreen:
137 return false; 93 return false;
138 case WebFeaturePolicyFeature::kPayment: 94 case WebFeaturePolicyFeature::kPayment:
139 return true; 95 return true;
140 case WebFeaturePolicyFeature::kVibrate: 96 case WebFeaturePolicyFeature::kVibrate:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 WebFeaturePolicyFeature::kSyncScript); 134 WebFeaturePolicyFeature::kSyncScript);
179 default_feature_name_map.Set("sync-xhr", 135 default_feature_name_map.Set("sync-xhr",
180 WebFeaturePolicyFeature::kSyncXHR); 136 WebFeaturePolicyFeature::kSyncXHR);
181 default_feature_name_map.Set("webrtc", WebFeaturePolicyFeature::kWebRTC); 137 default_feature_name_map.Set("webrtc", WebFeaturePolicyFeature::kWebRTC);
182 } 138 }
183 } 139 }
184 return default_feature_name_map; 140 return default_feature_name_map;
185 } 141 }
186 142
187 } // namespace blink 143 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698