OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/Permissions.h" | 5 #include "modules/permissions/Permissions.h" |
6 | 6 |
7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
8 #include "bindings/core/v8/Nullable.h" | 8 #include "bindings/core/v8/Nullable.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "bindings/modules/v8/V8MidiPermissionDescriptor.h" | 11 #include "bindings/modules/v8/V8MidiPermissionDescriptor.h" |
12 #include "bindings/modules/v8/V8PermissionDescriptor.h" | 12 #include "bindings/modules/v8/V8PermissionDescriptor.h" |
13 #include "bindings/modules/v8/V8PushPermissionDescriptor.h" | 13 #include "bindings/modules/v8/V8PushPermissionDescriptor.h" |
14 #include "core/dom/DOMException.h" | 14 #include "core/dom/DOMException.h" |
15 #include "core/dom/Document.h" | 15 #include "core/dom/Document.h" |
16 #include "core/dom/ExceptionCode.h" | 16 #include "core/dom/ExceptionCode.h" |
17 #include "core/frame/LocalFrame.h" | 17 #include "core/frame/LocalFrame.h" |
18 #include "modules/permissions/PermissionDescriptor.h" | 18 #include "modules/permissions/PermissionDescriptor.h" |
19 #include "modules/permissions/PermissionStatus.h" | 19 #include "modules/permissions/PermissionStatus.h" |
20 #include "modules/permissions/PermissionUtils.h" | |
20 #include "platform/UserGestureIndicator.h" | 21 #include "platform/UserGestureIndicator.h" |
21 #include "public/platform/InterfaceProvider.h" | |
22 #include "public/platform/Platform.h" | 22 #include "public/platform/Platform.h" |
23 #include "wtf/Functional.h" | 23 #include "wtf/Functional.h" |
24 #include "wtf/NotFound.h" | 24 #include "wtf/NotFound.h" |
25 #include "wtf/PtrUtil.h" | 25 #include "wtf/PtrUtil.h" |
26 #include "wtf/Vector.h" | 26 #include "wtf/Vector.h" |
27 #include <memory> | 27 #include <memory> |
28 | 28 |
29 namespace blink { | 29 namespace blink { |
30 | 30 |
31 using mojom::blink::PermissionDescriptorPtr; | |
31 using mojom::blink::PermissionName; | 32 using mojom::blink::PermissionName; |
32 using mojom::blink::PermissionService; | 33 using mojom::blink::PermissionService; |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
37 // Parses the raw permission dictionary and returns the Mojo | |
38 // PermissionDescriptor if parsing was successful. If an exception occurs, it | |
39 // will be stored in |exceptionState| and null will be returned. Therefore, the | |
40 // |exceptionState| should be checked before attempting to use the returned | |
41 // permission as the non-null assert will be fired otherwise. | |
42 // | |
36 // Websites will be able to run code when `name()` is called, changing the | 43 // Websites will be able to run code when `name()` is called, changing the |
37 // current context. The caller should make sure that no assumption is made | 44 // current context. The caller should make sure that no assumption is made |
38 // after this has been called. | 45 // after this has been called. |
39 PermissionName getPermissionName(ScriptState* scriptState, const Dictionary& raw Permission, const PermissionDescriptor& permission, ExceptionState& exceptionSta te) | 46 PermissionDescriptorPtr parsePermission(ScriptState* scriptState, const Dictiona ry rawPermission, ExceptionState& exceptionState) |
40 { | |
41 const String& name = permission.name(); | |
42 if (name == "geolocation") | |
43 return PermissionName::GEOLOCATION; | |
44 if (name == "notifications") | |
45 return PermissionName::NOTIFICATIONS; | |
46 if (name == "push") | |
47 return PermissionName::PUSH_NOTIFICATIONS; | |
48 if (name == "midi") { | |
49 MidiPermissionDescriptor midiPermission = NativeValueTraits<MidiPermissi onDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exce ptionState); | |
50 return midiPermission.sysex() ? PermissionName::MIDI_SYSEX : PermissionN ame::MIDI; | |
51 } | |
52 if (name == "background-sync") | |
53 return PermissionName::BACKGROUND_SYNC; | |
54 | |
55 ASSERT_NOT_REACHED(); | |
56 return PermissionName::GEOLOCATION; | |
57 } | |
58 | |
59 // Parses the raw permission dictionary and returns the PermissionType if | |
60 // parsing was successful. If an exception occurs, it will be stored in | |
61 // |exceptionState| and null will be returned. Therefore, the |exceptionState| | |
62 // should be checked before attempting to use the returned permission as the | |
63 // non-null assert will be fired otherwise. | |
64 Nullable<PermissionName> parsePermission(ScriptState* scriptState, const Diction ary rawPermission, ExceptionState& exceptionState) | |
65 { | 47 { |
66 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); | 48 PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::n ativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState); |
67 | 49 |
68 if (exceptionState.hadException()) { | 50 if (exceptionState.hadException()) { |
69 exceptionState.throwTypeError(exceptionState.message()); | 51 exceptionState.throwTypeError(exceptionState.message()); |
70 return Nullable<PermissionName>(); | 52 return nullptr; |
71 } | 53 } |
72 | 54 |
73 PermissionName name = getPermissionName(scriptState, rawPermission, permissi on, exceptionState); | 55 const String& name = permission.name(); |
74 if (exceptionState.hadException()) { | 56 PermissionName permissionName; |
75 exceptionState.throwTypeError(exceptionState.message()); | 57 if (name == "geolocation") { |
76 return Nullable<PermissionName>(); | 58 permissionName = PermissionName::GEOLOCATION; |
77 } | 59 } else if (name == "notifications") { |
78 | 60 permissionName = PermissionName::NOTIFICATIONS; |
79 // Here we reject any permissions which are not yet supported by Blink. | 61 } else if (name == "push") { |
80 if (name == PermissionName::PUSH_NOTIFICATIONS) { | |
81 PushPermissionDescriptor pushPermission = NativeValueTraits<PushPermissi onDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exce ptionState); | 62 PushPermissionDescriptor pushPermission = NativeValueTraits<PushPermissi onDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exce ptionState); |
82 if (exceptionState.hadException()) { | 63 if (exceptionState.hadException()) { |
83 exceptionState.throwTypeError(exceptionState.message()); | 64 exceptionState.throwTypeError(exceptionState.message()); |
84 return Nullable<PermissionName>(); | 65 return nullptr; |
85 } | 66 } |
86 | 67 |
87 // Only "userVisibleOnly" push is supported for now. | 68 // Only "userVisibleOnly" push is supported for now. |
88 if (!pushPermission.userVisibleOnly()) { | 69 if (!pushPermission.userVisibleOnly()) { |
89 exceptionState.throwDOMException(NotSupportedError, "Push Permission without userVisibleOnly:true isn't supported yet."); | 70 exceptionState.throwDOMException(NotSupportedError, "Push Permission without userVisibleOnly:true isn't supported yet."); |
90 return Nullable<PermissionName>(); | 71 return nullptr; |
91 } | 72 } |
73 | |
74 permissionName = PermissionName::PUSH_NOTIFICATIONS; | |
75 } else if (name == "midi") { | |
76 MidiPermissionDescriptor midiPermission = NativeValueTraits<MidiPermissi onDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exce ptionState); | |
77 return createMidiPermissionDescriptor(midiPermission.sysex()); | |
78 } else if (name == "background-sync") { | |
79 permissionName = PermissionName::BACKGROUND_SYNC; | |
80 } else { | |
81 return nullptr; | |
92 } | 82 } |
93 | 83 |
94 return Nullable<PermissionName>(name); | 84 return createPermissionDescriptor(permissionName); |
mlamouri (slow - plz ping)
2016/09/13 09:57:50
I find it a bit confusing that some if statements
Reilly Grant (use Gerrit)
2016/09/27 10:34:28
Done. You're right, that's cleaner.
| |
95 } | 85 } |
96 | 86 |
97 } // anonymous namespace | 87 } // anonymous namespace |
98 | 88 |
99 // static | |
100 bool Permissions::connectToService(ExecutionContext* executionContext, mojom::bl ink::PermissionServiceRequest request) | |
101 { | |
102 InterfaceProvider* interfaceProvider = nullptr; | |
103 if (executionContext->isDocument()) { | |
104 Document* document = toDocument(executionContext); | |
105 if (document->frame()) | |
106 interfaceProvider = document->frame()->interfaceProvider(); | |
107 } else { | |
108 interfaceProvider = Platform::current()->interfaceProvider(); | |
109 } | |
110 | |
111 if (interfaceProvider) | |
112 interfaceProvider->getInterface(std::move(request)); | |
113 return interfaceProvider; | |
114 } | |
115 | |
116 ScriptPromise Permissions::query(ScriptState* scriptState, const Dictionary& raw Permission) | 89 ScriptPromise Permissions::query(ScriptState* scriptState, const Dictionary& raw Permission) |
117 { | 90 { |
118 ExceptionState exceptionState(ExceptionState::GetterContext, "query", "Perm issions", scriptState->context()->Global(), scriptState->isolate()); | 91 ExceptionState exceptionState(ExceptionState::GetterContext, "query", "Perm issions", scriptState->context()->Global(), scriptState->isolate()); |
119 Nullable<PermissionName> name = parsePermission(scriptState, rawPermission, exceptionState); | 92 auto descriptor = parsePermission(scriptState, rawPermission, exceptionState ); |
mlamouri (slow - plz ping)
2016/09/13 09:57:50
can you explicitly put `PermissionDescriptor` inst
Reilly Grant (use Gerrit)
2016/09/27 10:34:28
Done.
| |
120 if (exceptionState.hadException()) | 93 if (exceptionState.hadException()) |
121 return exceptionState.reject(scriptState); | 94 return exceptionState.reject(scriptState); |
122 | 95 |
123 // This must be called after `parsePermission` because the website might | 96 // This must be called after `parsePermission` because the website might |
124 // be able to run code. | 97 // be able to run code. |
125 PermissionService* service = getService(scriptState->getExecutionContext()); | 98 PermissionService* service = getService(scriptState->getExecutionContext()); |
126 if (!service) | 99 if (!service) |
127 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't query pe rmissions.")); | 100 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't query pe rmissions.")); |
128 | 101 |
129 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 102 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
130 ScriptPromise promise = resolver->promise(); | 103 ScriptPromise promise = resolver->promise(); |
131 | 104 |
132 // If the current origin is a file scheme, it will unlikely return a | 105 // If the current origin is a file scheme, it will unlikely return a |
133 // meaningful value because most APIs are broken on file scheme and no | 106 // meaningful value because most APIs are broken on file scheme and no |
134 // permission prompt will be shown even if the returned permission will most | 107 // permission prompt will be shown even if the returned permission will most |
135 // likely be "prompt". | 108 // likely be "prompt". |
136 service->HasPermission(name.get(), scriptState->getExecutionContext()->getSe curityOrigin(), convertToBaseCallback(WTF::bind(&Permissions::taskComplete, wrap Persistent(this), wrapPersistent(resolver), name.get()))); | 109 auto descriptorCopy = descriptor->Clone(); |
mlamouri (slow - plz ping)
2016/09/13 09:57:50
ditto and all the instances below.
Reilly Grant (use Gerrit)
2016/09/27 10:34:28
Done.
| |
110 service->HasPermission(std::move(descriptor), scriptState->getExecutionConte xt()->getSecurityOrigin(), convertToBaseCallback(WTF::bind(&Permissions::taskCom plete, wrapPersistent(this), wrapPersistent(resolver), passed(std::move(descript orCopy))))); | |
137 return promise; | 111 return promise; |
138 } | 112 } |
139 | 113 |
140 ScriptPromise Permissions::request(ScriptState* scriptState, const Dictionary& r awPermission) | 114 ScriptPromise Permissions::request(ScriptState* scriptState, const Dictionary& r awPermission) |
141 { | 115 { |
142 ExceptionState exceptionState(ExceptionState::GetterContext, "request", "Pe rmissions", scriptState->context()->Global(), scriptState->isolate()); | 116 ExceptionState exceptionState(ExceptionState::GetterContext, "request", "Pe rmissions", scriptState->context()->Global(), scriptState->isolate()); |
143 Nullable<PermissionName> name = parsePermission(scriptState, rawPermission, exceptionState); | 117 auto descriptor = parsePermission(scriptState, rawPermission, exceptionState ); |
144 if (exceptionState.hadException()) | 118 if (exceptionState.hadException()) |
145 return exceptionState.reject(scriptState); | 119 return exceptionState.reject(scriptState); |
146 | 120 |
147 // This must be called after `parsePermission` because the website might | 121 // This must be called after `parsePermission` because the website might |
148 // be able to run code. | 122 // be able to run code. |
149 PermissionService* service = getService(scriptState->getExecutionContext()); | 123 PermissionService* service = getService(scriptState->getExecutionContext()); |
150 if (!service) | 124 if (!service) |
151 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't request permissions.")); | 125 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't request permissions.")); |
152 | 126 |
153 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 127 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
154 ScriptPromise promise = resolver->promise(); | 128 ScriptPromise promise = resolver->promise(); |
155 | 129 |
156 service->RequestPermission(name.get(), scriptState->getExecutionContext()->g etSecurityOrigin(), UserGestureIndicator::processingUserGesture(), convertToBase Callback(WTF::bind(&Permissions::taskComplete, wrapPersistent(this), wrapPersist ent(resolver), name.get()))); | 130 auto descriptorCopy = descriptor->Clone(); |
131 service->RequestPermission(std::move(descriptor), scriptState->getExecutionC ontext()->getSecurityOrigin(), UserGestureIndicator::processingUserGesture(), co nvertToBaseCallback(WTF::bind(&Permissions::taskComplete, wrapPersistent(this), wrapPersistent(resolver), passed(std::move(descriptorCopy))))); | |
157 return promise; | 132 return promise; |
158 } | 133 } |
159 | 134 |
160 ScriptPromise Permissions::revoke(ScriptState* scriptState, const Dictionary& ra wPermission) | 135 ScriptPromise Permissions::revoke(ScriptState* scriptState, const Dictionary& ra wPermission) |
161 { | 136 { |
162 ExceptionState exceptionState(ExceptionState::GetterContext, "revoke", "Per missions", scriptState->context()->Global(), scriptState->isolate()); | 137 ExceptionState exceptionState(ExceptionState::GetterContext, "revoke", "Per missions", scriptState->context()->Global(), scriptState->isolate()); |
163 Nullable<PermissionName> name = parsePermission(scriptState, rawPermission, exceptionState); | 138 auto descriptor = parsePermission(scriptState, rawPermission, exceptionState ); |
164 if (exceptionState.hadException()) | 139 if (exceptionState.hadException()) |
165 return exceptionState.reject(scriptState); | 140 return exceptionState.reject(scriptState); |
166 | 141 |
167 // This must be called after `parsePermission` because the website might | 142 // This must be called after `parsePermission` because the website might |
168 // be able to run code. | 143 // be able to run code. |
169 PermissionService* service = getService(scriptState->getExecutionContext()); | 144 PermissionService* service = getService(scriptState->getExecutionContext()); |
170 if (!service) | 145 if (!service) |
171 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't revoke p ermissions.")); | 146 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't revoke p ermissions.")); |
172 | 147 |
173 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 148 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
174 ScriptPromise promise = resolver->promise(); | 149 ScriptPromise promise = resolver->promise(); |
175 | 150 |
176 service->RevokePermission(name.get(), scriptState->getExecutionContext()->ge tSecurityOrigin(), convertToBaseCallback(WTF::bind(&Permissions::taskComplete, w rapPersistent(this), wrapPersistent(resolver), name.get()))); | 151 auto descriptorCopy = descriptor->Clone(); |
152 service->RevokePermission(std::move(descriptor), scriptState->getExecutionCo ntext()->getSecurityOrigin(), convertToBaseCallback(WTF::bind(&Permissions::task Complete, wrapPersistent(this), wrapPersistent(resolver), passed(std::move(descr iptorCopy))))); | |
177 return promise; | 153 return promise; |
178 } | 154 } |
179 | 155 |
180 ScriptPromise Permissions::requestAll(ScriptState* scriptState, const Vector<Dic tionary>& rawPermissions) | 156 ScriptPromise Permissions::requestAll(ScriptState* scriptState, const Vector<Dic tionary>& rawPermissions) |
181 { | 157 { |
182 ExceptionState exceptionState(ExceptionState::GetterContext, "request", "Pe rmissions", scriptState->context()->Global(), scriptState->isolate()); | 158 ExceptionState exceptionState(ExceptionState::GetterContext, "request", "Pe rmissions", scriptState->context()->Global(), scriptState->isolate()); |
183 Vector<PermissionName> internalPermissions; | 159 Vector<PermissionDescriptorPtr> internalPermissions; |
184 Vector<int> callerIndexToInternalIndex; | 160 Vector<int> callerIndexToInternalIndex; |
185 callerIndexToInternalIndex.resize(rawPermissions.size()); | 161 callerIndexToInternalIndex.resize(rawPermissions.size()); |
186 for (size_t i = 0; i < rawPermissions.size(); ++i) { | 162 for (size_t i = 0; i < rawPermissions.size(); ++i) { |
187 const Dictionary& rawPermission = rawPermissions[i]; | 163 const Dictionary& rawPermission = rawPermissions[i]; |
188 | 164 |
189 Nullable<PermissionName> name = parsePermission(scriptState, rawPermissi on, exceptionState); | 165 auto descriptor = parsePermission(scriptState, rawPermission, exceptionS tate); |
190 if (exceptionState.hadException()) | 166 if (exceptionState.hadException()) |
191 return exceptionState.reject(scriptState); | 167 return exceptionState.reject(scriptState); |
192 | 168 |
193 // Only append permissions to the vector that is passed to the client if it is not already | 169 // Only append permissions types that are not already present in the vec tor. |
194 // in the vector (i.e. do not duplicate permisison types). | 170 int internalIndex = -1; |
mlamouri (slow - plz ping)
2016/09/13 09:57:50
What about using `kNotFound`?
Reilly Grant (use Gerrit)
2016/09/27 10:34:28
I didn't know kNotFound was a common type. Neat.
| |
195 int internalIndex; | 171 for (size_t j = 0; j < internalPermissions.size(); ++j) { |
196 auto it = internalPermissions.find(name.get()); | 172 if (internalPermissions[j]->name == descriptor->name) { |
197 if (it == kNotFound) { | 173 internalIndex = j; |
174 break; | |
175 } | |
176 } | |
177 if (internalIndex == -1) { | |
mlamouri (slow - plz ping)
2016/09/13 09:57:50
... and here you can do `if (internalIndex == kNot
Reilly Grant (use Gerrit)
2016/09/27 10:34:28
Done.
| |
198 internalIndex = internalPermissions.size(); | 178 internalIndex = internalPermissions.size(); |
199 internalPermissions.append(name.get()); | 179 internalPermissions.append(std::move(descriptor)); |
200 } else { | |
201 internalIndex = it; | |
202 } | 180 } |
203 callerIndexToInternalIndex[i] = internalIndex; | 181 callerIndexToInternalIndex[i] = internalIndex; |
204 } | 182 } |
205 | 183 |
206 // This must be called after `parsePermission` because the website might | 184 // This must be called after `parsePermission` because the website might |
207 // be able to run code. | 185 // be able to run code. |
208 PermissionService* service = getService(scriptState->getExecutionContext()); | 186 PermissionService* service = getService(scriptState->getExecutionContext()); |
209 if (!service) | 187 if (!service) |
210 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't request permissions.")); | 188 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't request permissions.")); |
211 | 189 |
212 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 190 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
213 ScriptPromise promise = resolver->promise(); | 191 ScriptPromise promise = resolver->promise(); |
214 | 192 |
215 service->RequestPermissions(internalPermissions, scriptState->getExecutionCo ntext()->getSecurityOrigin(), UserGestureIndicator::processingUserGesture(), | 193 Vector<PermissionDescriptorPtr> internalPermissionsCopy; |
216 convertToBaseCallback(WTF::bind(&Permissions::batchTaskComplete, wrapPer sistent(this), wrapPersistent(resolver), internalPermissions, callerIndexToInter nalIndex))); | 194 internalPermissionsCopy.reserveCapacity(internalPermissions.size()); |
195 for (const auto& descriptor : internalPermissions) | |
196 internalPermissionsCopy.append(descriptor->Clone()); | |
197 | |
198 service->RequestPermissions(std::move(internalPermissions), scriptState->get ExecutionContext()->getSecurityOrigin(), UserGestureIndicator::processingUserGes ture(), | |
199 convertToBaseCallback(WTF::bind(&Permissions::batchTaskComplete, wrapPer sistent(this), wrapPersistent(resolver), passed(std::move(internalPermissionsCop y)), passed(std::move(callerIndexToInternalIndex))))); | |
217 return promise; | 200 return promise; |
218 } | 201 } |
219 | 202 |
220 PermissionService* Permissions::getService(ExecutionContext* executionContext) | 203 PermissionService* Permissions::getService(ExecutionContext* executionContext) |
221 { | 204 { |
222 if (!m_service && connectToService(executionContext, mojo::GetProxy(&m_servi ce))) | 205 if (!m_service && connectToPermissionService(executionContext, mojo::GetProx y(&m_service))) |
223 m_service.set_connection_error_handler(convertToBaseCallback(WTF::bind(& Permissions::serviceConnectionError, wrapWeakPersistent(this)))); | 206 m_service.set_connection_error_handler(convertToBaseCallback(WTF::bind(& Permissions::serviceConnectionError, wrapWeakPersistent(this)))); |
224 return m_service.get(); | 207 return m_service.get(); |
225 } | 208 } |
226 | 209 |
227 void Permissions::serviceConnectionError() | 210 void Permissions::serviceConnectionError() |
228 { | 211 { |
229 m_service.reset(); | 212 m_service.reset(); |
230 } | 213 } |
231 | 214 |
232 void Permissions::taskComplete(ScriptPromiseResolver* resolver, PermissionName n ame, mojom::blink::PermissionStatus result) | 215 void Permissions::taskComplete(ScriptPromiseResolver* resolver, mojom::blink::Pe rmissionDescriptorPtr descriptor, mojom::blink::PermissionStatus result) |
233 { | 216 { |
234 if (!resolver->getExecutionContext() || resolver->getExecutionContext()->act iveDOMObjectsAreStopped()) | 217 if (!resolver->getExecutionContext() || resolver->getExecutionContext()->act iveDOMObjectsAreStopped()) |
235 return; | 218 return; |
236 resolver->resolve(PermissionStatus::take(resolver, result, name)); | 219 resolver->resolve(PermissionStatus::take(resolver, result, std::move(descrip tor))); |
237 } | 220 } |
238 | 221 |
239 void Permissions::batchTaskComplete(ScriptPromiseResolver* resolver, Vector<Perm issionName> names, Vector<int> callerIndexToInternalIndex, const Vector<mojom::b link::PermissionStatus>& results) | 222 void Permissions::batchTaskComplete(ScriptPromiseResolver* resolver, Vector<mojo m::blink::PermissionDescriptorPtr> descriptors, Vector<int> callerIndexToInterna lIndex, const Vector<mojom::blink::PermissionStatus>& results) |
240 { | 223 { |
241 if (!resolver->getExecutionContext() || resolver->getExecutionContext()->act iveDOMObjectsAreStopped()) | 224 if (!resolver->getExecutionContext() || resolver->getExecutionContext()->act iveDOMObjectsAreStopped()) |
242 return; | 225 return; |
243 | 226 |
244 // Create the response vector by finding the status for each index by | 227 // Create the response vector by finding the status for each index by |
245 // using the caller to internal index mapping and looking up the status | 228 // using the caller to internal index mapping and looking up the status |
246 // using the internal index obtained. | 229 // using the internal index obtained. |
247 HeapVector<Member<PermissionStatus>> result; | 230 HeapVector<Member<PermissionStatus>> result; |
248 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); | 231 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); |
249 for (int internalIndex : callerIndexToInternalIndex) | 232 for (int internalIndex : callerIndexToInternalIndex) |
250 result.append(PermissionStatus::createAndListen(resolver->getExecutionCo ntext(), results[internalIndex], names[internalIndex])); | 233 result.append(PermissionStatus::createAndListen(resolver->getExecutionCo ntext(), results[internalIndex], descriptors[internalIndex]->Clone())); |
251 resolver->resolve(result); | 234 resolver->resolve(result); |
252 } | 235 } |
253 | 236 |
254 } // namespace blink | 237 } // namespace blink |
OLD | NEW |