| 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 "platform/Logging.h" | 20 #include "platform/Logging.h" |
| 21 #include "platform/UserGestureIndicator.h" | 21 #include "platform/UserGestureIndicator.h" |
| 22 #include "public/platform/InterfaceProvider.h" |
| 22 #include "public/platform/Platform.h" | 23 #include "public/platform/Platform.h" |
| 23 #include "public/platform/ServiceRegistry.h" | |
| 24 #include "wtf/Functional.h" | 24 #include "wtf/Functional.h" |
| 25 #include "wtf/NotFound.h" | 25 #include "wtf/NotFound.h" |
| 26 #include "wtf/PtrUtil.h" | 26 #include "wtf/PtrUtil.h" |
| 27 #include "wtf/Vector.h" | 27 #include "wtf/Vector.h" |
| 28 #include <memory> | 28 #include <memory> |
| 29 | 29 |
| 30 namespace blink { | 30 namespace blink { |
| 31 | 31 |
| 32 using mojom::blink::PermissionName; | 32 using mojom::blink::PermissionName; |
| 33 using mojom::blink::PermissionService; | 33 using mojom::blink::PermissionService; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 return Nullable<PermissionName>(name); | 95 return Nullable<PermissionName>(name); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // anonymous namespace | 98 } // anonymous namespace |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 bool Permissions::connectToService(ExecutionContext* executionContext, mojom::bl
ink::PermissionServiceRequest request) | 101 bool Permissions::connectToService(ExecutionContext* executionContext, mojom::bl
ink::PermissionServiceRequest request) |
| 102 { | 102 { |
| 103 ServiceRegistry* serviceRegistry = nullptr; | 103 InterfaceProvider* interfaceProvider = nullptr; |
| 104 if (executionContext->isDocument()) { | 104 if (executionContext->isDocument()) { |
| 105 Document* document = toDocument(executionContext); | 105 Document* document = toDocument(executionContext); |
| 106 if (document->frame()) | 106 if (document->frame()) |
| 107 serviceRegistry = document->frame()->serviceRegistry(); | 107 interfaceProvider = document->frame()->interfaceProvider(); |
| 108 } else { | 108 } else { |
| 109 serviceRegistry = Platform::current()->serviceRegistry(); | 109 interfaceProvider = Platform::current()->interfaceProvider(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (serviceRegistry) | 112 if (interfaceProvider) |
| 113 serviceRegistry->connectToRemoteService(std::move(request)); | 113 interfaceProvider->getInterface(std::move(request)); |
| 114 return serviceRegistry; | 114 return interfaceProvider; |
| 115 } | 115 } |
| 116 | 116 |
| 117 ScriptPromise Permissions::query(ScriptState* scriptState, const Dictionary& raw
Permission) | 117 ScriptPromise Permissions::query(ScriptState* scriptState, const Dictionary& raw
Permission) |
| 118 { | 118 { |
| 119 ExceptionState exceptionState(ExceptionState::GetterContext, "query", "Perm
issions", scriptState->context()->Global(), scriptState->isolate()); | 119 ExceptionState exceptionState(ExceptionState::GetterContext, "query", "Perm
issions", scriptState->context()->Global(), scriptState->isolate()); |
| 120 Nullable<PermissionName> name = parsePermission(scriptState, rawPermission,
exceptionState); | 120 Nullable<PermissionName> name = parsePermission(scriptState, rawPermission,
exceptionState); |
| 121 if (exceptionState.hadException()) | 121 if (exceptionState.hadException()) |
| 122 return exceptionState.reject(scriptState); | 122 return exceptionState.reject(scriptState); |
| 123 | 123 |
| 124 // This must be called after `parsePermission` because the website might | 124 // This must be called after `parsePermission` because the website might |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // using the caller to internal index mapping and looking up the status | 247 // using the caller to internal index mapping and looking up the status |
| 248 // using the internal index obtained. | 248 // using the internal index obtained. |
| 249 HeapVector<Member<PermissionStatus>> result; | 249 HeapVector<Member<PermissionStatus>> result; |
| 250 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); | 250 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); |
| 251 for (int internalIndex : callerIndexToInternalIndex) | 251 for (int internalIndex : callerIndexToInternalIndex) |
| 252 result.append(PermissionStatus::createAndListen(resolver->getExecutionCo
ntext(), results[internalIndex], names[internalIndex])); | 252 result.append(PermissionStatus::createAndListen(resolver->getExecutionCo
ntext(), results[internalIndex], names[internalIndex])); |
| 253 resolver->resolve(result); | 253 resolver->resolve(result); |
| 254 } | 254 } |
| 255 | 255 |
| 256 } // namespace blink | 256 } // namespace blink |
| OLD | NEW |