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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 WebPermissionClient* client = permissionClient(scriptState->executionContext
()); | 43 WebPermissionClient* client = permissionClient(scriptState->executionContext
()); |
44 if (!client) | 44 if (!client) |
45 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "In its current state, the global scope can't query pe
rmissions.")); | 45 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "In its current state, the global scope can't query pe
rmissions.")); |
46 | 46 |
47 TrackExceptionState exceptionState; | 47 TrackExceptionState exceptionState; |
48 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n
ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); | 48 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n
ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); |
49 | 49 |
50 | 50 |
51 if (exceptionState.hadException()) | 51 if (exceptionState.hadException()) |
52 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), exceptionState.message()))); | 52 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), exceptionState.message()))); |
53 if (!permission.hasName()) | |
54 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str
ing(scriptState->isolate(), "'name' is a required property."))); | |
55 | 53 |
56 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 54 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
57 ScriptPromise promise = resolver->promise(); | 55 ScriptPromise promise = resolver->promise(); |
58 | 56 |
59 String name = permission.name(); | 57 String name = permission.name(); |
60 WebPermissionType type; | 58 WebPermissionType type; |
61 if (name == "geolocation") { | 59 if (name == "geolocation") { |
62 type = WebPermissionTypeGeolocation; | 60 type = WebPermissionTypeGeolocation; |
63 } else if (name == "notifications") { | 61 } else if (name == "notifications") { |
64 type = WebPermissionTypeNotifications; | 62 type = WebPermissionTypeNotifications; |
(...skipping 20 matching lines...) Expand all Loading... |
85 | 83 |
86 // If the current origin is a file scheme, it will unlikely return a | 84 // If the current origin is a file scheme, it will unlikely return a |
87 // meaningful value because most APIs are broken on file scheme and no | 85 // meaningful value because most APIs are broken on file scheme and no |
88 // permission prompt will be shown even if the returned permission will most | 86 // permission prompt will be shown even if the returned permission will most |
89 // likely be "prompt". | 87 // likely be "prompt". |
90 client->queryPermission(type, KURL(KURL(), scriptState->executionContext()->
securityOrigin()->toString()), new PermissionQueryCallback(resolver, type)); | 88 client->queryPermission(type, KURL(KURL(), scriptState->executionContext()->
securityOrigin()->toString()), new PermissionQueryCallback(resolver, type)); |
91 return promise; | 89 return promise; |
92 } | 90 } |
93 | 91 |
94 } // namespace blink | 92 } // namespace blink |
OLD | NEW |