Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: third_party/WebKit/Source/modules/permissions/Permissions.cpp

Issue 2701993002: DO NOT COMMIT: Results of running new (proposed) clang-format on Blink (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/Nullable.h" 9 #include "bindings/core/v8/Nullable.h"
10 #include "bindings/core/v8/ScriptPromise.h" 10 #include "bindings/core/v8/ScriptPromise.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 PermissionDescriptorPtr descriptor = 138 PermissionDescriptorPtr descriptor =
139 parsePermission(scriptState, rawPermission, exceptionState); 139 parsePermission(scriptState, rawPermission, exceptionState);
140 if (exceptionState.hadException()) 140 if (exceptionState.hadException())
141 return exceptionState.reject(scriptState); 141 return exceptionState.reject(scriptState);
142 142
143 // This must be called after `parsePermission` because the website might 143 // This must be called after `parsePermission` because the website might
144 // be able to run code. 144 // be able to run code.
145 PermissionService* service = getService(scriptState->getExecutionContext()); 145 PermissionService* service = getService(scriptState->getExecutionContext());
146 if (!service) 146 if (!service)
147 return ScriptPromise::rejectWithDOMException( 147 return ScriptPromise::rejectWithDOMException(
148 scriptState, DOMException::create(InvalidStateError, 148 scriptState,
149 "In its current state, the global " 149 DOMException::create(InvalidStateError,
150 "scope can't request permissions.")); 150 "In its current state, the global "
151 "scope can't request permissions."));
151 152
152 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 153 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
153 ScriptPromise promise = resolver->promise(); 154 ScriptPromise promise = resolver->promise();
154 155
155 PermissionDescriptorPtr descriptorCopy = descriptor->Clone(); 156 PermissionDescriptorPtr descriptorCopy = descriptor->Clone();
156 service->RequestPermission( 157 service->RequestPermission(
157 std::move(descriptor), 158 std::move(descriptor),
158 scriptState->getExecutionContext()->getSecurityOrigin(), 159 scriptState->getExecutionContext()->getSecurityOrigin(),
159 UserGestureIndicator::processingUserGestureThreadSafe(), 160 UserGestureIndicator::processingUserGestureThreadSafe(),
160 convertToBaseCallback(WTF::bind( 161 convertToBaseCallback(WTF::bind(
(...skipping 10 matching lines...) Expand all
171 PermissionDescriptorPtr descriptor = 172 PermissionDescriptorPtr descriptor =
172 parsePermission(scriptState, rawPermission, exceptionState); 173 parsePermission(scriptState, rawPermission, exceptionState);
173 if (exceptionState.hadException()) 174 if (exceptionState.hadException())
174 return exceptionState.reject(scriptState); 175 return exceptionState.reject(scriptState);
175 176
176 // This must be called after `parsePermission` because the website might 177 // This must be called after `parsePermission` because the website might
177 // be able to run code. 178 // be able to run code.
178 PermissionService* service = getService(scriptState->getExecutionContext()); 179 PermissionService* service = getService(scriptState->getExecutionContext());
179 if (!service) 180 if (!service)
180 return ScriptPromise::rejectWithDOMException( 181 return ScriptPromise::rejectWithDOMException(
181 scriptState, DOMException::create(InvalidStateError, 182 scriptState,
182 "In its current state, the global " 183 DOMException::create(InvalidStateError,
183 "scope can't revoke permissions.")); 184 "In its current state, the global "
185 "scope can't revoke permissions."));
184 186
185 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 187 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
186 ScriptPromise promise = resolver->promise(); 188 ScriptPromise promise = resolver->promise();
187 189
188 PermissionDescriptorPtr descriptorCopy = descriptor->Clone(); 190 PermissionDescriptorPtr descriptorCopy = descriptor->Clone();
189 service->RevokePermission( 191 service->RevokePermission(
190 std::move(descriptor), 192 std::move(descriptor),
191 scriptState->getExecutionContext()->getSecurityOrigin(), 193 scriptState->getExecutionContext()->getSecurityOrigin(),
192 convertToBaseCallback(WTF::bind( 194 convertToBaseCallback(WTF::bind(
193 &Permissions::taskComplete, wrapPersistent(this), 195 &Permissions::taskComplete, wrapPersistent(this),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 internalPermissions.push_back(std::move(descriptor)); 227 internalPermissions.push_back(std::move(descriptor));
226 } 228 }
227 callerIndexToInternalIndex[i] = internalIndex; 229 callerIndexToInternalIndex[i] = internalIndex;
228 } 230 }
229 231
230 // This must be called after `parsePermission` because the website might 232 // This must be called after `parsePermission` because the website might
231 // be able to run code. 233 // be able to run code.
232 PermissionService* service = getService(scriptState->getExecutionContext()); 234 PermissionService* service = getService(scriptState->getExecutionContext());
233 if (!service) 235 if (!service)
234 return ScriptPromise::rejectWithDOMException( 236 return ScriptPromise::rejectWithDOMException(
235 scriptState, DOMException::create(InvalidStateError, 237 scriptState,
236 "In its current state, the global " 238 DOMException::create(InvalidStateError,
237 "scope can't request permissions.")); 239 "In its current state, the global "
240 "scope can't request permissions."));
238 241
239 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 242 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
240 ScriptPromise promise = resolver->promise(); 243 ScriptPromise promise = resolver->promise();
241 244
242 Vector<PermissionDescriptorPtr> internalPermissionsCopy; 245 Vector<PermissionDescriptorPtr> internalPermissionsCopy;
243 internalPermissionsCopy.reserveCapacity(internalPermissions.size()); 246 internalPermissionsCopy.reserveCapacity(internalPermissions.size());
244 for (const auto& descriptor : internalPermissions) 247 for (const auto& descriptor : internalPermissions)
245 internalPermissionsCopy.push_back(descriptor->Clone()); 248 internalPermissionsCopy.push_back(descriptor->Clone());
246 249
247 service->RequestPermissions( 250 service->RequestPermissions(
248 std::move(internalPermissions), 251 std::move(internalPermissions),
249 scriptState->getExecutionContext()->getSecurityOrigin(), 252 scriptState->getExecutionContext()->getSecurityOrigin(),
250 UserGestureIndicator::processingUserGestureThreadSafe(), 253 UserGestureIndicator::processingUserGestureThreadSafe(),
251 convertToBaseCallback( 254 convertToBaseCallback(
252 WTF::bind(&Permissions::batchTaskComplete, wrapPersistent(this), 255 WTF::bind(&Permissions::batchTaskComplete, wrapPersistent(this),
253 wrapPersistent(resolver), 256 wrapPersistent(resolver),
254 WTF::passed(std::move(internalPermissionsCopy)), 257 WTF::passed(std::move(internalPermissionsCopy)),
255 WTF::passed(std::move(callerIndexToInternalIndex))))); 258 WTF::passed(std::move(callerIndexToInternalIndex)))));
256 return promise; 259 return promise;
257 } 260 }
258 261
259 PermissionService* Permissions::getService(ExecutionContext* executionContext) { 262 PermissionService* Permissions::getService(ExecutionContext* executionContext) {
260 if (!m_service && connectToPermissionService(executionContext, 263 if (!m_service &&
261 mojo::MakeRequest(&m_service))) 264 connectToPermissionService(executionContext,
265 mojo::MakeRequest(&m_service)))
262 m_service.set_connection_error_handler(convertToBaseCallback(WTF::bind( 266 m_service.set_connection_error_handler(convertToBaseCallback(WTF::bind(
263 &Permissions::serviceConnectionError, wrapWeakPersistent(this)))); 267 &Permissions::serviceConnectionError, wrapWeakPersistent(this))));
264 return m_service.get(); 268 return m_service.get();
265 } 269 }
266 270
267 void Permissions::serviceConnectionError() { 271 void Permissions::serviceConnectionError() {
268 m_service.reset(); 272 m_service.reset();
269 } 273 }
270 274
271 void Permissions::taskComplete(ScriptPromiseResolver* resolver, 275 void Permissions::taskComplete(ScriptPromiseResolver* resolver,
(...skipping 22 matching lines...) Expand all
294 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); 298 result.reserveInitialCapacity(callerIndexToInternalIndex.size());
295 for (int internalIndex : callerIndexToInternalIndex) { 299 for (int internalIndex : callerIndexToInternalIndex) {
296 result.push_back(PermissionStatus::createAndListen( 300 result.push_back(PermissionStatus::createAndListen(
297 resolver->getExecutionContext(), results[internalIndex], 301 resolver->getExecutionContext(), results[internalIndex],
298 descriptors[internalIndex]->Clone())); 302 descriptors[internalIndex]->Clone()));
299 } 303 }
300 resolver->resolve(result); 304 resolver->resolve(result);
301 } 305 }
302 306
303 } // namespace blink 307 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698