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

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

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

Powered by Google App Engine
This is Rietveld 408576698