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

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

Issue 2614663008: Migrate WTF::Vector::append() to ::push_back() [part 13 of N] (Closed)
Patch Set: Created 3 years, 11 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // Only append permissions types that are not already present in the vector. 215 // Only append permissions types that are not already present in the vector.
216 size_t internalIndex = kNotFound; 216 size_t internalIndex = kNotFound;
217 for (size_t j = 0; j < internalPermissions.size(); ++j) { 217 for (size_t j = 0; j < internalPermissions.size(); ++j) {
218 if (internalPermissions[j]->name == descriptor->name) { 218 if (internalPermissions[j]->name == descriptor->name) {
219 internalIndex = j; 219 internalIndex = j;
220 break; 220 break;
221 } 221 }
222 } 222 }
223 if (internalIndex == kNotFound) { 223 if (internalIndex == kNotFound) {
224 internalIndex = internalPermissions.size(); 224 internalIndex = internalPermissions.size();
225 internalPermissions.append(std::move(descriptor)); 225 internalPermissions.push_back(std::move(descriptor));
226 } 226 }
227 callerIndexToInternalIndex[i] = internalIndex; 227 callerIndexToInternalIndex[i] = internalIndex;
228 } 228 }
229 229
230 // This must be called after `parsePermission` because the website might 230 // This must be called after `parsePermission` because the website might
231 // be able to run code. 231 // be able to run code.
232 PermissionService* service = getService(scriptState->getExecutionContext()); 232 PermissionService* service = getService(scriptState->getExecutionContext());
233 if (!service) 233 if (!service)
234 return ScriptPromise::rejectWithDOMException( 234 return ScriptPromise::rejectWithDOMException(
235 scriptState, DOMException::create(InvalidStateError, 235 scriptState, DOMException::create(InvalidStateError,
236 "In its current state, the global " 236 "In its current state, the global "
237 "scope can't request permissions.")); 237 "scope can't request permissions."));
238 238
239 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 239 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
240 ScriptPromise promise = resolver->promise(); 240 ScriptPromise promise = resolver->promise();
241 241
242 Vector<PermissionDescriptorPtr> internalPermissionsCopy; 242 Vector<PermissionDescriptorPtr> internalPermissionsCopy;
243 internalPermissionsCopy.reserveCapacity(internalPermissions.size()); 243 internalPermissionsCopy.reserveCapacity(internalPermissions.size());
244 for (const auto& descriptor : internalPermissions) 244 for (const auto& descriptor : internalPermissions)
245 internalPermissionsCopy.append(descriptor->Clone()); 245 internalPermissionsCopy.push_back(descriptor->Clone());
246 246
247 service->RequestPermissions( 247 service->RequestPermissions(
248 std::move(internalPermissions), 248 std::move(internalPermissions),
249 scriptState->getExecutionContext()->getSecurityOrigin(), 249 scriptState->getExecutionContext()->getSecurityOrigin(),
250 UserGestureIndicator::processingUserGestureThreadSafe(), 250 UserGestureIndicator::processingUserGestureThreadSafe(),
251 convertToBaseCallback( 251 convertToBaseCallback(
252 WTF::bind(&Permissions::batchTaskComplete, wrapPersistent(this), 252 WTF::bind(&Permissions::batchTaskComplete, wrapPersistent(this),
253 wrapPersistent(resolver), 253 wrapPersistent(resolver),
254 WTF::passed(std::move(internalPermissionsCopy)), 254 WTF::passed(std::move(internalPermissionsCopy)),
255 WTF::passed(std::move(callerIndexToInternalIndex))))); 255 WTF::passed(std::move(callerIndexToInternalIndex)))));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (!resolver->getExecutionContext() || 293 if (!resolver->getExecutionContext() ||
294 resolver->getExecutionContext()->isContextDestroyed()) 294 resolver->getExecutionContext()->isContextDestroyed())
295 return; 295 return;
296 296
297 // Create the response vector by finding the status for each index by 297 // Create the response vector by finding the status for each index by
298 // using the caller to internal index mapping and looking up the status 298 // using the caller to internal index mapping and looking up the status
299 // using the internal index obtained. 299 // using the internal index obtained.
300 HeapVector<Member<PermissionStatus>> result; 300 HeapVector<Member<PermissionStatus>> result;
301 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); 301 result.reserveInitialCapacity(callerIndexToInternalIndex.size());
302 for (int internalIndex : callerIndexToInternalIndex) { 302 for (int internalIndex : callerIndexToInternalIndex) {
303 result.append(PermissionStatus::createAndListen( 303 result.push_back(PermissionStatus::createAndListen(
304 resolver->getExecutionContext(), results[internalIndex], 304 resolver->getExecutionContext(), results[internalIndex],
305 descriptors[internalIndex]->Clone())); 305 descriptors[internalIndex]->Clone()));
306 } 306 }
307 resolver->resolve(result); 307 resolver->resolve(result);
308 } 308 }
309 309
310 } // namespace blink 310 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698