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

Side by Side Diff: Source/modules/permissions/Permissions.cpp

Issue 1236003004: blink: permissions: add plumbing to request permissions (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@permissions
Patch Set: Rebase Created 5 years, 4 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 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
112 {
113 WebPermissionClient* client = getClient(scriptState->executionContext());
114 if (!client)
115 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't request permissions."));
116
117 TrackExceptionState exceptionState;
118 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState);
119
120 if (exceptionState.hadException())
121 return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8Str ing(scriptState->isolate(), exceptionState.message())));
122
123 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
124 ScriptPromise promise = resolver->promise();
125
126 String name = permission.name();
127 WebPermissionType type = convertPermissionStringToType(name);
128
129 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep tionState))
130 return promise;
131
132 client->requestPermission(type, KURL(KURL(), scriptState->executionContext() ->securityOrigin()->toString()), new PermissionCallback(resolver, type));
133 return promise;
134 }
135
111 ScriptPromise Permissions::revoke(ScriptState* scriptState, const ScriptValue& r awPermission) 136 ScriptPromise Permissions::revoke(ScriptState* scriptState, const ScriptValue& r awPermission)
112 { 137 {
113 WebPermissionClient* client = getClient(scriptState->executionContext()); 138 WebPermissionClient* client = getClient(scriptState->executionContext());
114 if (!client) 139 if (!client)
115 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."));
116 141
117 TrackExceptionState exceptionState; 142 TrackExceptionState exceptionState;
118 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); 143 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState);
119 144
120 if (exceptionState.hadException()) 145 if (exceptionState.hadException())
121 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())));
122 147
123 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 148 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
124 ScriptPromise promise = resolver->promise(); 149 ScriptPromise promise = resolver->promise();
125 150
126 String name = permission.name(); 151 String name = permission.name();
127 WebPermissionType type = convertPermissionStringToType(name); 152 WebPermissionType type = convertPermissionStringToType(name);
128 153
129 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep tionState)) 154 if (handleDefaultBehaviour(scriptState, rawPermission, resolver, type, excep tionState))
130 return promise; 155 return promise;
131 156
132 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));
133 return promise; 158 return promise;
134 } 159 }
135 160
136 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698