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

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

Issue 2228663002: Mojo C++ bindings: make permissions service use STL string/vector types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 "modules/permissions/Permissions.h" 5 #include "modules/permissions/Permissions.h"
6 6
7 #include "bindings/core/v8/Dictionary.h" 7 #include "bindings/core/v8/Dictionary.h"
8 #include "bindings/core/v8/Nullable.h" 8 #include "bindings/core/v8/Nullable.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 // This must be called after `parsePermission` because the website might 207 // This must be called after `parsePermission` because the website might
208 // be able to run code. 208 // be able to run code.
209 PermissionService* service = getService(scriptState->getExecutionContext()); 209 PermissionService* service = getService(scriptState->getExecutionContext());
210 if (!service) 210 if (!service)
211 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't request permissions.")); 211 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't request permissions."));
212 212
213 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 213 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
214 ScriptPromise promise = resolver->promise(); 214 ScriptPromise promise = resolver->promise();
215 215
216 Vector<PermissionName> internalPermissionsCopy(internalPermissions); 216 service->RequestPermissions(internalPermissions, scriptState->getExecutionCo ntext()->getSecurityOrigin()->toString(), UserGestureIndicator::processingUserGe sture(),
217 service->RequestPermissions(std::move(internalPermissions), scriptState->get ExecutionContext()->getSecurityOrigin()->toString(), UserGestureIndicator::proce ssingUserGesture(), 217 convertToBaseCallback(WTF::bind(&Permissions::batchTaskComplete, wrapPer sistent(this), wrapPersistent(resolver), internalPermissions, callerIndexToInter nalIndex)));
218 convertToBaseCallback(WTF::bind(&Permissions::batchTaskComplete, wrapPer sistent(this), wrapPersistent(resolver), std::move(internalPermissionsCopy), std ::move(callerIndexToInternalIndex))));
219 return promise; 218 return promise;
220 } 219 }
221 220
222 PermissionService* Permissions::getService(ExecutionContext* executionContext) 221 PermissionService* Permissions::getService(ExecutionContext* executionContext)
223 { 222 {
224 if (!m_service && connectToService(executionContext, mojo::GetProxy(&m_servi ce))) 223 if (!m_service && connectToService(executionContext, mojo::GetProxy(&m_servi ce)))
225 m_service.set_connection_error_handler(convertToBaseCallback(WTF::bind(& Permissions::serviceConnectionError, wrapWeakPersistent(this)))); 224 m_service.set_connection_error_handler(convertToBaseCallback(WTF::bind(& Permissions::serviceConnectionError, wrapWeakPersistent(this))));
226 return m_service.get(); 225 return m_service.get();
227 } 226 }
228 227
229 void Permissions::serviceConnectionError() 228 void Permissions::serviceConnectionError()
230 { 229 {
231 m_service.reset(); 230 m_service.reset();
232 } 231 }
233 232
234 void Permissions::taskComplete(ScriptPromiseResolver* resolver, PermissionName n ame, mojom::blink::PermissionStatus result) 233 void Permissions::taskComplete(ScriptPromiseResolver* resolver, PermissionName n ame, mojom::blink::PermissionStatus result)
235 { 234 {
236 if (!resolver->getExecutionContext() || resolver->getExecutionContext()->act iveDOMObjectsAreStopped()) 235 if (!resolver->getExecutionContext() || resolver->getExecutionContext()->act iveDOMObjectsAreStopped())
237 return; 236 return;
238 resolver->resolve(PermissionStatus::take(resolver, result, name)); 237 resolver->resolve(PermissionStatus::take(resolver, result, name));
239 } 238 }
240 239
241 void Permissions::batchTaskComplete(ScriptPromiseResolver* resolver, Vector<Perm issionName> names, Vector<int> callerIndexToInternalIndex, mojo::WTFArray<mojom: :blink::PermissionStatus> results) 240 void Permissions::batchTaskComplete(ScriptPromiseResolver* resolver, Vector<Perm issionName> names, Vector<int> callerIndexToInternalIndex, const Vector<mojom::b link::PermissionStatus>& results)
242 { 241 {
243 if (!resolver->getExecutionContext() || resolver->getExecutionContext()->act iveDOMObjectsAreStopped()) 242 if (!resolver->getExecutionContext() || resolver->getExecutionContext()->act iveDOMObjectsAreStopped())
244 return; 243 return;
245 244
246 // Create the response vector by finding the status for each index by 245 // Create the response vector by finding the status for each index by
247 // using the caller to internal index mapping and looking up the status 246 // using the caller to internal index mapping and looking up the status
248 // using the internal index obtained. 247 // using the internal index obtained.
249 HeapVector<Member<PermissionStatus>> result; 248 HeapVector<Member<PermissionStatus>> result;
250 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); 249 result.reserveInitialCapacity(callerIndexToInternalIndex.size());
251 for (int internalIndex : callerIndexToInternalIndex) 250 for (int internalIndex : callerIndexToInternalIndex)
252 result.append(PermissionStatus::createAndListen(resolver->getExecutionCo ntext(), results[internalIndex], names[internalIndex])); 251 result.append(PermissionStatus::createAndListen(resolver->getExecutionCo ntext(), results[internalIndex], names[internalIndex]));
253 resolver->resolve(result); 252 resolver->resolve(result);
254 } 253 }
255 254
256 } // namespace blink 255 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698