| 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" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (name == "background-sync") | 88 if (name == "background-sync") |
| 89 return createPermissionDescriptor(PermissionName::BACKGROUND_SYNC); | 89 return createPermissionDescriptor(PermissionName::BACKGROUND_SYNC); |
| 90 | 90 |
| 91 return nullptr; | 91 return nullptr; |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // anonymous namespace | 94 } // anonymous namespace |
| 95 | 95 |
| 96 ScriptPromise Permissions::query(ScriptState* scriptState, | 96 ScriptPromise Permissions::query(ScriptState* scriptState, |
| 97 const Dictionary& rawPermission) { | 97 const Dictionary& rawPermission) { |
| 98 ExceptionState exceptionState(ExceptionState::GetterContext, "query", | 98 ExceptionState exceptionState(scriptState->isolate(), |
| 99 "Permissions", scriptState->context()->Global(), | 99 ExceptionState::GetterContext, "Permissions", |
| 100 scriptState->isolate()); | 100 "query"); |
| 101 PermissionDescriptorPtr descriptor = | 101 PermissionDescriptorPtr descriptor = |
| 102 parsePermission(scriptState, rawPermission, exceptionState); | 102 parsePermission(scriptState, rawPermission, exceptionState); |
| 103 if (exceptionState.hadException()) | 103 if (exceptionState.hadException()) |
| 104 return exceptionState.reject(scriptState); | 104 return exceptionState.reject(scriptState); |
| 105 | 105 |
| 106 // This must be called after `parsePermission` because the website might | 106 // This must be called after `parsePermission` because the website might |
| 107 // be able to run code. | 107 // be able to run code. |
| 108 PermissionService* service = getService(scriptState->getExecutionContext()); | 108 PermissionService* service = getService(scriptState->getExecutionContext()); |
| 109 if (!service) | 109 if (!service) |
| 110 return ScriptPromise::rejectWithDOMException( | 110 return ScriptPromise::rejectWithDOMException( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 125 std::move(descriptor), | 125 std::move(descriptor), |
| 126 scriptState->getExecutionContext()->getSecurityOrigin(), | 126 scriptState->getExecutionContext()->getSecurityOrigin(), |
| 127 convertToBaseCallback(WTF::bind( | 127 convertToBaseCallback(WTF::bind( |
| 128 &Permissions::taskComplete, wrapPersistent(this), | 128 &Permissions::taskComplete, wrapPersistent(this), |
| 129 wrapPersistent(resolver), WTF::passed(std::move(descriptorCopy))))); | 129 wrapPersistent(resolver), WTF::passed(std::move(descriptorCopy))))); |
| 130 return promise; | 130 return promise; |
| 131 } | 131 } |
| 132 | 132 |
| 133 ScriptPromise Permissions::request(ScriptState* scriptState, | 133 ScriptPromise Permissions::request(ScriptState* scriptState, |
| 134 const Dictionary& rawPermission) { | 134 const Dictionary& rawPermission) { |
| 135 ExceptionState exceptionState(ExceptionState::GetterContext, "request", | 135 ExceptionState exceptionState(scriptState->isolate(), |
| 136 "Permissions", scriptState->context()->Global(), | 136 ExceptionState::GetterContext, "Permissions", |
| 137 scriptState->isolate()); | 137 "request"); |
| 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( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 158 scriptState->getExecutionContext()->getSecurityOrigin(), | 158 scriptState->getExecutionContext()->getSecurityOrigin(), |
| 159 UserGestureIndicator::processingUserGesture(), | 159 UserGestureIndicator::processingUserGesture(), |
| 160 convertToBaseCallback(WTF::bind( | 160 convertToBaseCallback(WTF::bind( |
| 161 &Permissions::taskComplete, wrapPersistent(this), | 161 &Permissions::taskComplete, wrapPersistent(this), |
| 162 wrapPersistent(resolver), WTF::passed(std::move(descriptorCopy))))); | 162 wrapPersistent(resolver), WTF::passed(std::move(descriptorCopy))))); |
| 163 return promise; | 163 return promise; |
| 164 } | 164 } |
| 165 | 165 |
| 166 ScriptPromise Permissions::revoke(ScriptState* scriptState, | 166 ScriptPromise Permissions::revoke(ScriptState* scriptState, |
| 167 const Dictionary& rawPermission) { | 167 const Dictionary& rawPermission) { |
| 168 ExceptionState exceptionState(ExceptionState::GetterContext, "revoke", | 168 ExceptionState exceptionState(scriptState->isolate(), |
| 169 "Permissions", scriptState->context()->Global(), | 169 ExceptionState::GetterContext, "Permissions", |
| 170 scriptState->isolate()); | 170 "revoke"); |
| 171 PermissionDescriptorPtr descriptor = | 171 PermissionDescriptorPtr descriptor = |
| 172 parsePermission(scriptState, rawPermission, exceptionState); | 172 parsePermission(scriptState, rawPermission, exceptionState); |
| 173 if (exceptionState.hadException()) | 173 if (exceptionState.hadException()) |
| 174 return exceptionState.reject(scriptState); | 174 return exceptionState.reject(scriptState); |
| 175 | 175 |
| 176 // This must be called after `parsePermission` because the website might | 176 // This must be called after `parsePermission` because the website might |
| 177 // be able to run code. | 177 // be able to run code. |
| 178 PermissionService* service = getService(scriptState->getExecutionContext()); | 178 PermissionService* service = getService(scriptState->getExecutionContext()); |
| 179 if (!service) | 179 if (!service) |
| 180 return ScriptPromise::rejectWithDOMException( | 180 return ScriptPromise::rejectWithDOMException( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 191 scriptState->getExecutionContext()->getSecurityOrigin(), | 191 scriptState->getExecutionContext()->getSecurityOrigin(), |
| 192 convertToBaseCallback(WTF::bind( | 192 convertToBaseCallback(WTF::bind( |
| 193 &Permissions::taskComplete, wrapPersistent(this), | 193 &Permissions::taskComplete, wrapPersistent(this), |
| 194 wrapPersistent(resolver), WTF::passed(std::move(descriptorCopy))))); | 194 wrapPersistent(resolver), WTF::passed(std::move(descriptorCopy))))); |
| 195 return promise; | 195 return promise; |
| 196 } | 196 } |
| 197 | 197 |
| 198 ScriptPromise Permissions::requestAll( | 198 ScriptPromise Permissions::requestAll( |
| 199 ScriptState* scriptState, | 199 ScriptState* scriptState, |
| 200 const Vector<Dictionary>& rawPermissions) { | 200 const Vector<Dictionary>& rawPermissions) { |
| 201 ExceptionState exceptionState(ExceptionState::GetterContext, "request", | 201 ExceptionState exceptionState(scriptState->isolate(), |
| 202 "Permissions", scriptState->context()->Global(), | 202 ExceptionState::GetterContext, "Permissions", |
| 203 scriptState->isolate()); | 203 "requestAll"); |
| 204 Vector<PermissionDescriptorPtr> internalPermissions; | 204 Vector<PermissionDescriptorPtr> internalPermissions; |
| 205 Vector<int> callerIndexToInternalIndex; | 205 Vector<int> callerIndexToInternalIndex; |
| 206 callerIndexToInternalIndex.resize(rawPermissions.size()); | 206 callerIndexToInternalIndex.resize(rawPermissions.size()); |
| 207 for (size_t i = 0; i < rawPermissions.size(); ++i) { | 207 for (size_t i = 0; i < rawPermissions.size(); ++i) { |
| 208 const Dictionary& rawPermission = rawPermissions[i]; | 208 const Dictionary& rawPermission = rawPermissions[i]; |
| 209 | 209 |
| 210 auto descriptor = | 210 auto descriptor = |
| 211 parsePermission(scriptState, rawPermission, exceptionState); | 211 parsePermission(scriptState, rawPermission, exceptionState); |
| 212 if (exceptionState.hadException()) | 212 if (exceptionState.hadException()) |
| 213 return exceptionState.reject(scriptState); | 213 return exceptionState.reject(scriptState); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); | 301 result.reserveInitialCapacity(callerIndexToInternalIndex.size()); |
| 302 for (int internalIndex : callerIndexToInternalIndex) { | 302 for (int internalIndex : callerIndexToInternalIndex) { |
| 303 result.append(PermissionStatus::createAndListen( | 303 result.append(PermissionStatus::createAndListen( |
| 304 resolver->getExecutionContext(), results[internalIndex], | 304 resolver->getExecutionContext(), results[internalIndex], |
| 305 descriptors[internalIndex]->Clone())); | 305 descriptors[internalIndex]->Clone())); |
| 306 } | 306 } |
| 307 resolver->resolve(result); | 307 resolver->resolve(result); |
| 308 } | 308 } |
| 309 | 309 |
| 310 } // namespace blink | 310 } // namespace blink |
| OLD | NEW |