| 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..6a3933bda4ea7311c8ce23caf16066d859e1924e
|
| --- /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)
|
| +{
|
| + 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.appendLiteral(" are invalid permissions flags.");
|
| + else
|
| + tokenErrors.appendLiteral(" 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
|
|
|