| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "core/html/HTMLIFrameElementAllow.h" | 5 #include "core/html/HTMLIFrameElementAllow.h" |
| 6 | 6 |
| 7 #include "core/html/HTMLIFrameElement.h" | 7 #include "core/html/HTMLIFrameElement.h" |
| 8 #include "platform/feature_policy/FeaturePolicy.h" | 8 #include "platform/feature_policy/FeaturePolicy.h" |
| 9 #include "platform/wtf/text/StringBuilder.h" | 9 #include "platform/wtf/text/StringBuilder.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 Vector<WebFeaturePolicyFeature> | 26 Vector<WebFeaturePolicyFeature> |
| 27 HTMLIFrameElementAllow::ParseAllowedFeatureNames( | 27 HTMLIFrameElementAllow::ParseAllowedFeatureNames( |
| 28 String& invalid_tokens_error_message) const { | 28 String& invalid_tokens_error_message) const { |
| 29 Vector<WebFeaturePolicyFeature> feature_names; | 29 Vector<WebFeaturePolicyFeature> feature_names; |
| 30 unsigned num_token_errors = 0; | 30 unsigned num_token_errors = 0; |
| 31 StringBuilder token_errors; | 31 StringBuilder token_errors; |
| 32 const SpaceSplitString& tokens = this->Tokens(); | 32 const SpaceSplitString& tokens = this->Tokens(); |
| 33 | 33 |
| 34 // Collects a list of valid feature names. | 34 // Collects a list of valid feature names. |
| 35 const FeatureNameMap& feature_name_map = GetDefaultFeatureNameMap(); |
| 35 for (size_t i = 0; i < tokens.size(); ++i) { | 36 for (size_t i = 0; i < tokens.size(); ++i) { |
| 36 WebFeaturePolicyFeature feature = GetWebFeaturePolicyFeature(tokens[i]); | 37 if (!feature_name_map.Contains(tokens[i])) { |
| 37 if (feature == WebFeaturePolicyFeature::kNotFound) { | |
| 38 token_errors.Append(token_errors.IsEmpty() ? "'" : ", '"); | 38 token_errors.Append(token_errors.IsEmpty() ? "'" : ", '"); |
| 39 token_errors.Append(tokens[i]); | 39 token_errors.Append(tokens[i]); |
| 40 token_errors.Append("'"); | 40 token_errors.Append("'"); |
| 41 ++num_token_errors; | 41 ++num_token_errors; |
| 42 } else { | 42 } else { |
| 43 feature_names.push_back(feature); | 43 feature_names.push_back(feature_name_map.at(tokens[i])); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 if (num_token_errors) { | 47 if (num_token_errors) { |
| 48 token_errors.Append(num_token_errors > 1 ? " are invalid feature names." | 48 token_errors.Append(num_token_errors > 1 ? " are invalid feature names." |
| 49 : " is an invalid feature name."); | 49 : " is an invalid feature name."); |
| 50 invalid_tokens_error_message = token_errors.ToString(); | 50 invalid_tokens_error_message = token_errors.ToString(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Create a unique set of feature names. | 53 // Create a unique set of feature names. |
| 54 std::sort(feature_names.begin(), feature_names.end()); | 54 std::sort(feature_names.begin(), feature_names.end()); |
| 55 auto it = std::unique(feature_names.begin(), feature_names.end()); | 55 auto it = std::unique(feature_names.begin(), feature_names.end()); |
| 56 feature_names.Shrink(it - feature_names.begin()); | 56 feature_names.Shrink(it - feature_names.begin()); |
| 57 | 57 |
| 58 return feature_names; | 58 return feature_names; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool HTMLIFrameElementAllow::ValidateTokenValue(const AtomicString& token_value, | 61 bool HTMLIFrameElementAllow::ValidateTokenValue(const AtomicString& token_value, |
| 62 ExceptionState&) const { | 62 ExceptionState&) const { |
| 63 return GetWebFeaturePolicyFeature(token_value.GetString()) != | 63 return GetDefaultFeatureNameMap().Contains(token_value.GetString()); |
| 64 WebFeaturePolicyFeature::kNotFound; | |
| 65 } | 64 } |
| 66 | 65 |
| 67 void HTMLIFrameElementAllow::ValueWasSet() { | 66 void HTMLIFrameElementAllow::ValueWasSet() { |
| 68 DCHECK(element_); | 67 DCHECK(element_); |
| 69 element_->AllowValueWasSet(); | 68 element_->AllowValueWasSet(); |
| 70 } | 69 } |
| 71 | 70 |
| 72 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |