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