Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLIFrameElementPermissions.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLIFrameElementPermissions.cpp b/third_party/WebKit/Source/core/html/HTMLIFrameElementPermissions.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5f15a93c897dc3cb3fc10148c7929ca4c5a4cb6d |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/html/HTMLIFrameElementPermissions.cpp |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSDstyle license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/html/HTMLIFrameElementPermissions.h" |
| + |
| +#include "wtf/HashMap.h" |
| +#include "wtf/text/StringBuilder.h" |
| + |
| +namespace blink { |
| + |
| +namespace { |
| + |
| +struct SupportedPermission { |
| + const char* name; |
| + WebPermissionType type; |
| +}; |
| + |
| +const SupportedPermission kSupportedPermissions[] = { |
| + { "geolocation", WebPermissionTypeGeolocation }, |
| + { "notifications", WebPermissionTypeNotifications }, |
| + { "midi", WebPermissionTypeMidiSysEx }, |
| +}; |
| + |
| +// Returns true if the name is valid and the type is stored in |result|. |
| +bool GetPermissionType(const AtomicString& name, WebPermissionType* result) |
|
tkent
2016/06/23 04:57:28
With the current Blink coding style, this should b
raymes
2016/06/27 08:09:50
Done.
|
| +{ |
| + for (const SupportedPermission& permission : kSupportedPermissions) { |
| + if (name == permission.name) { |
| + *result = permission.type; |
| + return true; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| +} // namespace |
| + |
| +HTMLIFrameElementPermissions::HTMLIFrameElementPermissions(DOMTokenListObserver* observer) |
| + : DOMTokenList(observer) |
| +{ |
| +} |
| + |
| +HTMLIFrameElementPermissions::~HTMLIFrameElementPermissions() |
| +{ |
| +} |
| + |
| +Vector<WebPermissionType> HTMLIFrameElementPermissions::parseDelegatedPermissions(String& invalidTokensErrorMessage) const |
| +{ |
| + Vector<WebPermissionType> permissions; |
| + unsigned numTokenErrors = 0; |
| + StringBuilder tokenErrors; |
| + const SpaceSplitString& tokens = this->tokens(); |
| + |
| + for (size_t i = 0; i < tokens.size(); ++i) { |
| + WebPermissionType type; |
| + if (GetPermissionType(tokens[i], &type)) { |
| + permissions.append(type); |
| + } else { |
| + if (numTokenErrors) |
| + tokenErrors.append(", '"); |
| + else |
| + tokenErrors.append('\''); |
| + tokenErrors.append(tokens[i]); |
| + tokenErrors.append('\''); |
| + ++numTokenErrors; |
| + } |
| + } |
| + |
| + if (numTokenErrors) { |
| + if (numTokenErrors > 1) |
| + tokenErrors.append(" are invalid permissions flags."); |
| + else |
| + tokenErrors.append(" is an invalid permissions flag."); |
| + invalidTokensErrorMessage = tokenErrors.toString(); |
| + } |
| + |
| + return permissions; |
| +} |
| + |
| +bool HTMLIFrameElementPermissions::validateTokenValue(const AtomicString& tokenValue, ExceptionState&) const |
| +{ |
| + WebPermissionType unused; |
| + return GetPermissionType(tokenValue, &unused); |
| +} |
| + |
| +} // namespace blink |