Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(667)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLIFrameElementPermissions.cpp

Issue 2011763006: Add an iframe permissions= attribute for implementing permission delegation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-delegation-1-flag
Patch Set: Blink-side Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698