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