| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/permissions/PermissionsCallback.h" | |
| 6 | |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 8 #include "modules/permissions/PermissionStatus.h" | |
| 9 #include "wtf/PtrUtil.h" | |
| 10 #include <memory> | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 PermissionsCallback::PermissionsCallback(ScriptPromiseResolver* resolver, std::u
nique_ptr<Vector<WebPermissionType>> internalPermissions, std::unique_ptr<Vector
<int>> callerIndexToInternalIndex) | |
| 15 : m_resolver(resolver) | |
| 16 , m_internalPermissions(std::move(internalPermissions)) | |
| 17 , m_callerIndexToInternalIndex(std::move(callerIndexToInternalIndex)) | |
| 18 { | |
| 19 ASSERT(m_resolver); | |
| 20 } | |
| 21 | |
| 22 void PermissionsCallback::onSuccess(std::unique_ptr<WebVector<WebPermissionStatu
s>> permissionStatus) | |
| 23 { | |
| 24 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContext()-
>activeDOMObjectsAreStopped()) | |
| 25 return; | |
| 26 | |
| 27 std::unique_ptr<WebVector<WebPermissionStatus>> statusPtr = wrapUnique(permi
ssionStatus.release()); | |
| 28 HeapVector<Member<PermissionStatus>> result(m_callerIndexToInternalIndex->si
ze()); | |
| 29 | |
| 30 // Create the response vector by finding the status for each index by | |
| 31 // using the caller to internal index mapping and looking up the status | |
| 32 // using the internal index obtained. | |
| 33 for (size_t i = 0; i < m_callerIndexToInternalIndex->size(); ++i) { | |
| 34 int internalIndex = m_callerIndexToInternalIndex->operator[](i); | |
| 35 result[i] = PermissionStatus::createAndListen(m_resolver->getExecutionCo
ntext(), statusPtr->operator[](internalIndex), m_internalPermissions->operator[]
(internalIndex)); | |
| 36 } | |
| 37 m_resolver->resolve(result); | |
| 38 } | |
| 39 | |
| 40 void PermissionsCallback::onError() | |
| 41 { | |
| 42 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContext()-
>activeDOMObjectsAreStopped()) | |
| 43 return; | |
| 44 m_resolver->reject(); | |
| 45 } | |
| 46 | |
| 47 } // namespace blink | |
| OLD | NEW |