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 if (result) |
| 32 *result = permission.type; |
| 33 return true; |
| 34 } |
| 35 } |
| 36 return false; |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
| 41 HTMLIFrameElementPermissions::HTMLIFrameElementPermissions(HTMLIFrameElement* el
ement) |
| 42 : DOMTokenList(this) |
| 43 , m_element(element) |
| 44 { |
| 45 } |
| 46 |
| 47 HTMLIFrameElementPermissions::~HTMLIFrameElementPermissions() |
| 48 { |
| 49 } |
| 50 |
| 51 DEFINE_TRACE(HTMLIFrameElementPermissions) |
| 52 { |
| 53 visitor->trace(m_element); |
| 54 DOMTokenList::trace(visitor); |
| 55 DOMTokenListObserver::trace(visitor); |
| 56 } |
| 57 |
| 58 Vector<WebPermissionType> HTMLIFrameElementPermissions::parseDelegatedPermission
s(String& invalidTokensErrorMessage) const |
| 59 { |
| 60 Vector<WebPermissionType> permissions; |
| 61 unsigned numTokenErrors = 0; |
| 62 StringBuilder tokenErrors; |
| 63 const SpaceSplitString& tokens = this->tokens(); |
| 64 |
| 65 for (size_t i = 0; i < tokens.size(); ++i) { |
| 66 WebPermissionType type; |
| 67 if (getPermissionType(tokens[i], &type)) { |
| 68 permissions.append(type); |
| 69 } else { |
| 70 if (numTokenErrors) |
| 71 tokenErrors.append(", '"); |
| 72 else |
| 73 tokenErrors.append('\''); |
| 74 tokenErrors.append(tokens[i]); |
| 75 tokenErrors.append('\''); |
| 76 ++numTokenErrors; |
| 77 } |
| 78 } |
| 79 |
| 80 if (numTokenErrors) { |
| 81 if (numTokenErrors > 1) |
| 82 tokenErrors.append(" are invalid permissions flags."); |
| 83 else |
| 84 tokenErrors.append(" is an invalid permissions flag."); |
| 85 invalidTokensErrorMessage = tokenErrors.toString(); |
| 86 } |
| 87 |
| 88 return permissions; |
| 89 } |
| 90 |
| 91 bool HTMLIFrameElementPermissions::validateTokenValue(const AtomicString& tokenV
alue, ExceptionState&) const |
| 92 { |
| 93 WebPermissionType unused; |
| 94 return getPermissionType(tokenValue, &unused); |
| 95 } |
| 96 |
| 97 void HTMLIFrameElementPermissions::valueWasSet() |
| 98 { |
| 99 if (m_element) |
| 100 m_element->permissionsValueWasSet(); |
| 101 } |
| 102 |
| 103 } // namespace blink |
OLD | NEW |