OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/permissions/Permissions.h" | 6 #include "modules/permissions/Permissions.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "bindings/modules/v8/V8MidiPermissionDescriptor.h" | 10 #include "bindings/modules/v8/V8MidiPermissionDescriptor.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "public/platform/modules/permissions/WebPermissionClient.h" | 21 #include "public/platform/modules/permissions/WebPermissionClient.h" |
22 | 22 |
23 namespace blink { | 23 namespace blink { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Here we handle some common permission patterns to prevent propogation up to t
he content layer | 27 // Here we handle some common permission patterns to prevent propogation up to t
he content layer |
28 // Examples of behaviours which would go here are rejecting unsupported permissi
ons, accepting | 28 // Examples of behaviours which would go here are rejecting unsupported permissi
ons, accepting |
29 // permissions which are always granted or always denied according to the spec e
tc. | 29 // permissions which are always granted or always denied according to the spec e
tc. |
30 bool handleDefaultBehaviour( | 30 bool handleDefaultBehaviour( |
31 ScriptState* scriptState, const ScriptValue& rawPermission, PassRefPtr<Scrip
tPromiseResolver> resolver, WebPermissionType type, TrackExceptionState& excepti
onState) | 31 ScriptState* scriptState, const ScriptValue& rawPermission, ScriptPromiseRes
olver* resolver, WebPermissionType type, TrackExceptionState& exceptionState) |
32 { | 32 { |
33 if (type == WebPermissionTypePushNotifications) { | 33 if (type == WebPermissionTypePushNotifications) { |
34 PushPermissionDescriptor pushPermission = NativeValueTraits<PushPermissi
onDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exce
ptionState); | 34 PushPermissionDescriptor pushPermission = NativeValueTraits<PushPermissi
onDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exce
ptionState); |
35 // Only "userVisibleOnly" push is supported for now. | 35 // Only "userVisibleOnly" push is supported for now. |
36 if (!pushPermission.userVisibleOnly()) { | 36 if (!pushPermission.userVisibleOnly()) { |
37 resolver->reject(DOMException::create(NotSupportedError, "Push Permi
ssion without userVisibleOnly:true isn't supported yet.")); | 37 resolver->reject(DOMException::create(NotSupportedError, "Push Permi
ssion without userVisibleOnly:true isn't supported yet.")); |
38 return true; | 38 return true; |
39 } | 39 } |
40 } else if (type == WebPermissionTypeMidiSysEx) { | 40 } else if (type == WebPermissionTypeMidiSysEx) { |
41 MidiPermissionDescriptor midiPermission = NativeValueTraits<MidiPermissi
onDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exce
ptionState); | 41 MidiPermissionDescriptor midiPermission = NativeValueTraits<MidiPermissi
onDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exce
ptionState); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 if (!client) | 84 if (!client) |
85 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "In its current state, the global scope can't query pe
rmissions.")); | 85 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "In its current state, the global scope can't query pe
rmissions.")); |
86 | 86 |
87 TrackExceptionState exceptionState; | 87 TrackExceptionState exceptionState; |
88 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n
ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); | 88 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n
ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); |
89 | 89 |
90 | 90 |
91 if (exceptionState.hadException()) | 91 if (exceptionState.hadException()) |
92 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), exceptionState.message()))); | 92 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), exceptionState.message()))); |
93 | 93 |
94 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 94 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
95 ScriptPromise promise = resolver->promise(); | 95 ScriptPromise promise = resolver->promise(); |
96 | 96 |
97 String name = permission.name(); | 97 String name = permission.name(); |
98 WebPermissionType type = convertPermissionStringToType(name); | 98 WebPermissionType type = convertPermissionStringToType(name); |
99 | 99 |
100 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep
tionState)) | 100 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep
tionState)) |
101 return promise; | 101 return promise; |
102 | 102 |
103 // If the current origin is a file scheme, it will unlikely return a | 103 // If the current origin is a file scheme, it will unlikely return a |
104 // meaningful value because most APIs are broken on file scheme and no | 104 // meaningful value because most APIs are broken on file scheme and no |
105 // permission prompt will be shown even if the returned permission will most | 105 // permission prompt will be shown even if the returned permission will most |
106 // likely be "prompt". | 106 // likely be "prompt". |
107 client->queryPermission(type, KURL(KURL(), scriptState->executionContext()->
securityOrigin()->toString()), new PermissionCallback(resolver, type)); | 107 client->queryPermission(type, KURL(KURL(), scriptState->executionContext()->
securityOrigin()->toString()), new PermissionCallback(resolver, type)); |
108 return promise; | 108 return promise; |
109 } | 109 } |
110 | 110 |
111 ScriptPromise Permissions::request(ScriptState* scriptState, const ScriptValue&
rawPermission) | 111 ScriptPromise Permissions::request(ScriptState* scriptState, const ScriptValue&
rawPermission) |
112 { | 112 { |
113 WebPermissionClient* client = getClient(scriptState->executionContext()); | 113 WebPermissionClient* client = getClient(scriptState->executionContext()); |
114 if (!client) | 114 if (!client) |
115 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "In its current state, the global scope can't request
permissions.")); | 115 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "In its current state, the global scope can't request
permissions.")); |
116 | 116 |
117 TrackExceptionState exceptionState; | 117 TrackExceptionState exceptionState; |
118 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n
ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); | 118 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n
ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); |
119 | 119 |
120 if (exceptionState.hadException()) | 120 if (exceptionState.hadException()) |
121 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), exceptionState.message()))); | 121 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), exceptionState.message()))); |
122 | 122 |
123 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 123 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
124 ScriptPromise promise = resolver->promise(); | 124 ScriptPromise promise = resolver->promise(); |
125 | 125 |
126 String name = permission.name(); | 126 String name = permission.name(); |
127 WebPermissionType type = convertPermissionStringToType(name); | 127 WebPermissionType type = convertPermissionStringToType(name); |
128 | 128 |
129 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep
tionState)) | 129 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep
tionState)) |
130 return promise; | 130 return promise; |
131 | 131 |
132 client->requestPermission(type, KURL(KURL(), scriptState->executionContext()
->securityOrigin()->toString()), new PermissionCallback(resolver, type)); | 132 client->requestPermission(type, KURL(KURL(), scriptState->executionContext()
->securityOrigin()->toString()), new PermissionCallback(resolver, type)); |
133 return promise; | 133 return promise; |
134 } | 134 } |
135 | 135 |
136 ScriptPromise Permissions::revoke(ScriptState* scriptState, const ScriptValue& r
awPermission) | 136 ScriptPromise Permissions::revoke(ScriptState* scriptState, const ScriptValue& r
awPermission) |
137 { | 137 { |
138 WebPermissionClient* client = getClient(scriptState->executionContext()); | 138 WebPermissionClient* client = getClient(scriptState->executionContext()); |
139 if (!client) | 139 if (!client) |
140 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "In its current state, the global scope can't revoke p
ermissions.")); | 140 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "In its current state, the global scope can't revoke p
ermissions.")); |
141 | 141 |
142 TrackExceptionState exceptionState; | 142 TrackExceptionState exceptionState; |
143 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n
ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); | 143 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n
ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); |
144 | 144 |
145 if (exceptionState.hadException()) | 145 if (exceptionState.hadException()) |
146 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), exceptionState.message()))); | 146 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), exceptionState.message()))); |
147 | 147 |
148 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 148 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
149 ScriptPromise promise = resolver->promise(); | 149 ScriptPromise promise = resolver->promise(); |
150 | 150 |
151 String name = permission.name(); | 151 String name = permission.name(); |
152 WebPermissionType type = convertPermissionStringToType(name); | 152 WebPermissionType type = convertPermissionStringToType(name); |
153 | 153 |
154 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep
tionState)) | 154 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep
tionState)) |
155 return promise; | 155 return promise; |
156 | 156 |
157 client->revokePermission(type, KURL(KURL(), scriptState->executionContext()-
>securityOrigin()->toString()), new PermissionCallback(resolver, type)); | 157 client->revokePermission(type, KURL(KURL(), scriptState->executionContext()-
>securityOrigin()->toString()), new PermissionCallback(resolver, type)); |
158 return promise; | 158 return promise; |
159 } | 159 } |
160 | 160 |
161 } // namespace blink | 161 } // namespace blink |
OLD | NEW |