OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSDstyle license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/html/HTMLIFrameElementPermissions.h" |
| 6 |
| 7 #include "core/html/HTMLIFrameElement.h" |
| 8 #include "wtf/HashMap.h" |
| 9 #include "wtf/text/StringBuilder.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 namespace { |
| 14 |
| 15 struct SupportedPermission { |
| 16 const char* name; |
| 17 WebPermissionType type; |
| 18 }; |
| 19 |
| 20 const SupportedPermission kSupportedPermissions[] = { |
| 21 { "geolocation", WebPermissionTypeGeolocation }, |
| 22 { "notifications", WebPermissionTypeNotifications }, |
| 23 { "midi", WebPermissionTypeMidiSysEx }, |
| 24 }; |
| 25 |
| 26 // Returns true if the name is valid and the type is stored in |result|. |
| 27 bool getPermissionType(const AtomicString& name, WebPermissionType* result) |
| 28 { |
| 29 for (const SupportedPermission& permission : kSupportedPermissions) { |
| 30 if (name == permission.name) { |
| 31 *result = permission.type; |
| 32 return true; |
| 33 } |
| 34 } |
| 35 return false; |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 HTMLIFrameElementPermissions::HTMLIFrameElementPermissions(HTMLIFrameElement* el
ement) |
| 41 : DOMTokenList(this) |
| 42 , m_element(element) |
| 43 { |
| 44 } |
| 45 |
| 46 HTMLIFrameElementPermissions::~HTMLIFrameElementPermissions() |
| 47 { |
| 48 } |
| 49 |
| 50 DEFINE_TRACE(HTMLIFrameElementPermissions) |
| 51 { |
| 52 visitor->trace(m_element); |
| 53 DOMTokenList::trace(visitor); |
| 54 DOMTokenListObserver::trace(visitor); |
| 55 } |
| 56 |
| 57 Vector<WebPermissionType> HTMLIFrameElementPermissions::parseDelegatedPermission
s(String& invalidTokensErrorMessage) const |
| 58 { |
| 59 Vector<WebPermissionType> permissions; |
| 60 unsigned numTokenErrors = 0; |
| 61 StringBuilder tokenErrors; |
| 62 const SpaceSplitString& tokens = this->tokens(); |
| 63 |
| 64 for (size_t i = 0; i < tokens.size(); ++i) { |
| 65 WebPermissionType type; |
| 66 if (getPermissionType(tokens[i], &type)) { |
| 67 permissions.append(type); |
| 68 } else { |
| 69 if (numTokenErrors) |
| 70 tokenErrors.append(", '"); |
| 71 else |
| 72 tokenErrors.append('\''); |
| 73 tokenErrors.append(tokens[i]); |
| 74 tokenErrors.append('\''); |
| 75 ++numTokenErrors; |
| 76 } |
| 77 } |
| 78 |
| 79 if (numTokenErrors) { |
| 80 if (numTokenErrors > 1) |
| 81 tokenErrors.append(" are invalid permissions flags."); |
| 82 else |
| 83 tokenErrors.append(" is an invalid permissions flag."); |
| 84 invalidTokensErrorMessage = tokenErrors.toString(); |
| 85 } |
| 86 |
| 87 return permissions; |
| 88 } |
| 89 |
| 90 bool HTMLIFrameElementPermissions::validateTokenValue(const AtomicString& tokenV
alue, ExceptionState&) const |
| 91 { |
| 92 WebPermissionType unused; |
| 93 return getPermissionType(tokenValue, &unused); |
| 94 } |
| 95 |
| 96 void HTMLIFrameElementPermissions::valueWasSet() |
| 97 { |
| 98 if (m_element) |
| 99 m_element->permissionsValueWasSet(); |
| 100 } |
| 101 |
| 102 } // namespace blink |
OLD | NEW |