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