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

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

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

Powered by Google App Engine
This is Rietveld 408576698