| 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 mojom::blink::PermissionName type; | |
| 18 }; | |
| 19 | |
| 20 const SupportedPermission kSupportedPermissions[] = { | |
| 21 {"geolocation", mojom::blink::PermissionName::GEOLOCATION}, | |
| 22 {"notifications", mojom::blink::PermissionName::NOTIFICATIONS}, | |
| 23 {"midi", mojom::blink::PermissionName::MIDI}, | |
| 24 }; | |
| 25 | |
| 26 // Returns true if the name is valid and the type is stored in |result|. | |
| 27 bool getPermissionType(const AtomicString& name, | |
| 28 mojom::blink::PermissionName* result) { | |
| 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( | |
| 42 HTMLIFrameElement* element) | |
| 43 : DOMTokenList(this), m_element(element) {} | |
| 44 | |
| 45 HTMLIFrameElementPermissions::~HTMLIFrameElementPermissions() {} | |
| 46 | |
| 47 DEFINE_TRACE(HTMLIFrameElementPermissions) { | |
| 48 visitor->trace(m_element); | |
| 49 DOMTokenList::trace(visitor); | |
| 50 DOMTokenListObserver::trace(visitor); | |
| 51 } | |
| 52 | |
| 53 Vector<mojom::blink::PermissionName> | |
| 54 HTMLIFrameElementPermissions::parseDelegatedPermissions( | |
| 55 String& invalidTokensErrorMessage) const { | |
| 56 Vector<blink::mojom::blink::PermissionName> permissions; | |
| 57 unsigned numTokenErrors = 0; | |
| 58 StringBuilder tokenErrors; | |
| 59 const SpaceSplitString& tokens = this->tokens(); | |
| 60 | |
| 61 for (size_t i = 0; i < tokens.size(); ++i) { | |
| 62 blink::mojom::blink::PermissionName type; | |
| 63 if (getPermissionType(tokens[i], &type)) { | |
| 64 permissions.push_back(type); | |
| 65 } else { | |
| 66 tokenErrors.append(tokenErrors.isEmpty() ? "'" : ", '"); | |
| 67 tokenErrors.append(tokens[i]); | |
| 68 tokenErrors.append("'"); | |
| 69 ++numTokenErrors; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 if (numTokenErrors) { | |
| 74 tokenErrors.append(numTokenErrors > 1 ? " are invalid permissions flags." | |
| 75 : " is an invalid permissions flag."); | |
| 76 invalidTokensErrorMessage = tokenErrors.toString(); | |
| 77 } | |
| 78 | |
| 79 return permissions; | |
| 80 } | |
| 81 | |
| 82 bool HTMLIFrameElementPermissions::validateTokenValue( | |
| 83 const AtomicString& tokenValue, | |
| 84 ExceptionState&) const { | |
| 85 mojom::blink::PermissionName unused; | |
| 86 return getPermissionType(tokenValue, &unused); | |
| 87 } | |
| 88 | |
| 89 void HTMLIFrameElementPermissions::valueWasSet() { | |
| 90 if (m_element) | |
| 91 m_element->permissionsValueWasSet(); | |
| 92 } | |
| 93 | |
| 94 } // namespace blink | |
| OLD | NEW |