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 "wtf/HashMap.h" | |
8 #include "wtf/text/StringBuilder.h" | |
9 | |
10 namespace blink { | |
11 | |
12 namespace { | |
13 | |
14 struct SupportedPermission { | |
15 const char* name; | |
16 WebPermissionType type; | |
17 }; | |
18 | |
19 const SupportedPermission kSupportedPermissions[] = { | |
20 { "geolocation", WebPermissionTypeGeolocation }, | |
21 { "notifications", WebPermissionTypeNotifications }, | |
22 { "midi", WebPermissionTypeMidiSysEx }, | |
23 }; | |
24 | |
25 // Returns true if the name is valid and the type is stored in |result|. | |
26 bool GetPermissionType(const AtomicString& name, WebPermissionType* result) | |
tkent
2016/06/23 04:57:28
With the current Blink coding style, this should b
raymes
2016/06/27 08:09:50
Done.
| |
27 { | |
28 for (const SupportedPermission& permission : kSupportedPermissions) { | |
29 if (name == permission.name) { | |
30 *result = permission.type; | |
31 return true; | |
32 } | |
33 } | |
34 return false; | |
35 } | |
36 | |
37 } // namespace | |
38 | |
39 HTMLIFrameElementPermissions::HTMLIFrameElementPermissions(DOMTokenListObserver* observer) | |
40 : DOMTokenList(observer) | |
41 { | |
42 } | |
43 | |
44 HTMLIFrameElementPermissions::~HTMLIFrameElementPermissions() | |
45 { | |
46 } | |
47 | |
48 Vector<WebPermissionType> HTMLIFrameElementPermissions::parseDelegatedPermission s(String& invalidTokensErrorMessage) const | |
49 { | |
50 Vector<WebPermissionType> permissions; | |
51 unsigned numTokenErrors = 0; | |
52 StringBuilder tokenErrors; | |
53 const SpaceSplitString& tokens = this->tokens(); | |
54 | |
55 for (size_t i = 0; i < tokens.size(); ++i) { | |
56 WebPermissionType type; | |
57 if (GetPermissionType(tokens[i], &type)) { | |
58 permissions.append(type); | |
59 } else { | |
60 if (numTokenErrors) | |
61 tokenErrors.append(", '"); | |
62 else | |
63 tokenErrors.append('\''); | |
64 tokenErrors.append(tokens[i]); | |
65 tokenErrors.append('\''); | |
66 ++numTokenErrors; | |
67 } | |
68 } | |
69 | |
70 if (numTokenErrors) { | |
71 if (numTokenErrors > 1) | |
72 tokenErrors.append(" are invalid permissions flags."); | |
73 else | |
74 tokenErrors.append(" is an invalid permissions flag."); | |
75 invalidTokensErrorMessage = tokenErrors.toString(); | |
76 } | |
77 | |
78 return permissions; | |
79 } | |
80 | |
81 bool HTMLIFrameElementPermissions::validateTokenValue(const AtomicString& tokenV alue, ExceptionState&) const | |
82 { | |
83 WebPermissionType unused; | |
84 return GetPermissionType(tokenValue, &unused); | |
85 } | |
86 | |
87 } // namespace blink | |
OLD | NEW |