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 "config.h" | 5 #include "config.h" |
6 #include "modules/permissions/PermissionsCallback.h" | 6 #include "modules/permissions/PermissionsCallback.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "modules/permissions/PermissionStatus.h" | 9 #include "modules/permissions/PermissionStatus.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 PermissionsCallback::PermissionsCallback(ScriptPromiseResolver* resolver, PassOw
nPtr<WebVector<WebPermissionType>> permission_types) | 13 PermissionsCallback::PermissionsCallback(ScriptPromiseResolver* resolver, PassOw
nPtr<Vector<WebPermissionType>> internalPermissions, PassOwnPtr<Vector<int>> cal
lerIndexToInternalIndex) |
14 : m_resolver(resolver), | 14 : m_resolver(resolver), |
15 m_permissionTypes(permission_types) | 15 m_internalPermissions(internalPermissions), |
| 16 m_callerIndexToInternalIndex(callerIndexToInternalIndex) |
16 { | 17 { |
17 ASSERT(m_resolver); | 18 ASSERT(m_resolver); |
18 } | 19 } |
19 | 20 |
20 void PermissionsCallback::onSuccess(WebPassOwnPtr<WebVector<WebPermissionStatus>
> permissionStatus) | 21 void PermissionsCallback::onSuccess(WebPassOwnPtr<WebVector<WebPermissionStatus>
> permissionStatus) |
21 { | 22 { |
22 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) | 23 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) |
23 return; | 24 return; |
24 | 25 |
25 OwnPtr<WebVector<WebPermissionStatus>> statusPtr = permissionStatus.release(
); | 26 OwnPtr<WebVector<WebPermissionStatus>> statusPtr = permissionStatus.release(
); |
| 27 Vector<PermissionStatus*> result(m_callerIndexToInternalIndex->size()); |
26 | 28 |
27 Vector<PermissionStatus*> status; | 29 // Create the response vector by finding the status for each index by |
28 status.reserveCapacity(statusPtr->size()); | 30 // using the caller to internal index mapping and looking up the status |
29 for (size_t i = 0; i < statusPtr->size(); ++i) | 31 // using the internal index obtained. |
30 status.append(PermissionStatus::createAndListen(m_resolver->executionCon
text(), (*statusPtr)[i], (*m_permissionTypes)[i])); | 32 for (size_t i = 0; i < m_callerIndexToInternalIndex->size(); ++i) { |
31 | 33 int internalIndex = m_callerIndexToInternalIndex->operator[](i); |
32 m_resolver->resolve(status); | 34 result[i] = PermissionStatus::createAndListen(m_resolver->executionConte
xt(), statusPtr->operator[](internalIndex), m_internalPermissions->operator[](in
ternalIndex)); |
| 35 } |
| 36 m_resolver->resolve(result); |
33 } | 37 } |
34 | 38 |
35 void PermissionsCallback::onError() | 39 void PermissionsCallback::onError() |
36 { | 40 { |
37 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) | 41 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) |
38 return; | 42 return; |
39 m_resolver->reject(); | 43 m_resolver->reject(); |
40 } | 44 } |
41 | 45 |
42 } // namespace blink | 46 } // namespace blink |
OLD | NEW |