Chromium Code Reviews| 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 "modules/quota/StorageManager.h" | 5 #include "modules/quota/StorageManager.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "bindings/modules/v8/V8StorageEstimate.h" | 8 #include "bindings/modules/v8/V8StorageEstimate.h" |
| 9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 private: | 53 private: |
| 54 Member<ScriptPromiseResolver> m_resolver; | 54 Member<ScriptPromiseResolver> m_resolver; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 ScriptPromise StorageManager::persist(ScriptState* scriptState) { | 59 ScriptPromise StorageManager::persist(ScriptState* scriptState) { |
| 60 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 60 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 61 ScriptPromise promise = resolver->promise(); | 61 ScriptPromise promise = resolver->promise(); |
| 62 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 62 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 63 DCHECK(executionContext->isSecureContext()); // [SecureContext] in IDL | |
| 63 SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); | 64 SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); |
| 64 // TODO(dgrogan): Is the isUnique() check covered by the later | 65 // TODO(jsbell): Is the isUnique() check covered by [SecureContext]? If so, |
|
jsbell
2017/02/11 01:01:43
I'm keeping this TODO but maybe mkwst@ has an answ
| |
| 65 // isSecureContext() check? If so, maybe remove it. Write a test if it | 66 // maybe remove it. Write a test if it stays. |
| 66 // stays. | |
| 67 if (securityOrigin->isUnique()) { | 67 if (securityOrigin->isUnique()) { |
| 68 resolver->reject(DOMException::create(NotSupportedError)); | 68 resolver->reject(DOMException::create(NotSupportedError)); |
| 69 return promise; | 69 return promise; |
| 70 } | 70 } |
| 71 String errorMessage; | 71 |
| 72 if (!executionContext->isSecureContext(errorMessage)) { | |
| 73 resolver->reject(DOMException::create(SecurityError, errorMessage)); | |
| 74 return promise; | |
| 75 } | |
| 76 ASSERT(executionContext->isDocument()); | 72 ASSERT(executionContext->isDocument()); |
| 77 PermissionService* permissionService = | 73 PermissionService* permissionService = |
| 78 getPermissionService(scriptState->getExecutionContext()); | 74 getPermissionService(scriptState->getExecutionContext()); |
| 79 if (!permissionService) { | 75 if (!permissionService) { |
| 80 resolver->reject(DOMException::create( | 76 resolver->reject(DOMException::create( |
| 81 InvalidStateError, | 77 InvalidStateError, |
| 82 "In its current state, the global scope can't request permissions.")); | 78 "In its current state, the global scope can't request permissions.")); |
| 83 return promise; | 79 return promise; |
| 84 } | 80 } |
| 85 permissionService->RequestPermission( | 81 permissionService->RequestPermission( |
| 86 createPermissionDescriptor(PermissionName::DURABLE_STORAGE), | 82 createPermissionDescriptor(PermissionName::DURABLE_STORAGE), |
| 87 scriptState->getExecutionContext()->getSecurityOrigin(), | 83 scriptState->getExecutionContext()->getSecurityOrigin(), |
| 88 UserGestureIndicator::processingUserGesture(), | 84 UserGestureIndicator::processingUserGesture(), |
| 89 convertToBaseCallback( | 85 convertToBaseCallback( |
| 90 WTF::bind(&StorageManager::permissionRequestComplete, | 86 WTF::bind(&StorageManager::permissionRequestComplete, |
| 91 wrapPersistent(this), wrapPersistent(resolver)))); | 87 wrapPersistent(this), wrapPersistent(resolver)))); |
| 92 | 88 |
| 93 return promise; | 89 return promise; |
| 94 } | 90 } |
| 95 | 91 |
| 96 ScriptPromise StorageManager::persisted(ScriptState* scriptState) { | 92 ScriptPromise StorageManager::persisted(ScriptState* scriptState) { |
| 97 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 93 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 98 ScriptPromise promise = resolver->promise(); | 94 ScriptPromise promise = resolver->promise(); |
| 95 ExecutionContext* executionContext = scriptState->getExecutionContext(); | |
| 96 DCHECK(executionContext->isSecureContext()); // [SecureContext] in IDL | |
| 97 SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); | |
| 98 // TODO(jsbell): Is the isUnique() check covered by [SecureContext]? If so, | |
| 99 // maybe remove it. Write a test if it stays. | |
| 100 if (securityOrigin->isUnique()) { | |
| 101 resolver->reject(DOMException::create(NotSupportedError)); | |
| 102 return promise; | |
| 103 } | |
| 104 | |
| 99 PermissionService* permissionService = | 105 PermissionService* permissionService = |
| 100 getPermissionService(scriptState->getExecutionContext()); | 106 getPermissionService(scriptState->getExecutionContext()); |
| 101 if (!permissionService) { | 107 if (!permissionService) { |
| 102 resolver->reject(DOMException::create( | 108 resolver->reject(DOMException::create( |
| 103 InvalidStateError, | 109 InvalidStateError, |
| 104 "In its current state, the global scope can't query permissions.")); | 110 "In its current state, the global scope can't query permissions.")); |
| 105 return promise; | 111 return promise; |
| 106 } | 112 } |
| 107 permissionService->HasPermission( | 113 permissionService->HasPermission( |
| 108 createPermissionDescriptor(PermissionName::DURABLE_STORAGE), | 114 createPermissionDescriptor(PermissionName::DURABLE_STORAGE), |
| 109 scriptState->getExecutionContext()->getSecurityOrigin(), | 115 scriptState->getExecutionContext()->getSecurityOrigin(), |
| 110 convertToBaseCallback( | 116 convertToBaseCallback( |
| 111 WTF::bind(&StorageManager::permissionRequestComplete, | 117 WTF::bind(&StorageManager::permissionRequestComplete, |
| 112 wrapPersistent(this), wrapPersistent(resolver)))); | 118 wrapPersistent(this), wrapPersistent(resolver)))); |
| 113 return promise; | 119 return promise; |
| 114 } | 120 } |
| 115 | 121 |
| 116 ScriptPromise StorageManager::estimate(ScriptState* scriptState) { | 122 ScriptPromise StorageManager::estimate(ScriptState* scriptState) { |
| 117 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 123 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 118 ScriptPromise promise = resolver->promise(); | 124 ScriptPromise promise = resolver->promise(); |
| 119 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 125 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 126 DCHECK(executionContext->isSecureContext()); // [SecureContext] in IDL | |
| 120 SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); | 127 SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); |
| 128 // TODO(jsbell): Is the isUnique() check covered by [SecureContext]? If so, | |
| 129 // maybe remove it. Write a test if it stays. | |
| 121 if (securityOrigin->isUnique()) { | 130 if (securityOrigin->isUnique()) { |
| 122 resolver->reject(DOMException::create(NotSupportedError)); | 131 resolver->reject(DOMException::create(NotSupportedError)); |
| 123 return promise; | 132 return promise; |
| 124 } | 133 } |
| 125 // IDL has: [SecureContext] | |
| 126 String errorMessage; | |
| 127 if (!executionContext->isSecureContext(errorMessage)) { | |
| 128 resolver->reject(DOMException::create(SecurityError, errorMessage)); | |
| 129 return promise; | |
| 130 } | |
| 131 | 134 |
| 132 KURL storagePartition = KURL(KURL(), securityOrigin->toString()); | 135 KURL storagePartition = KURL(KURL(), securityOrigin->toString()); |
| 133 Platform::current()->queryStorageUsageAndQuota( | 136 Platform::current()->queryStorageUsageAndQuota( |
| 134 storagePartition, WebStorageQuotaTypeTemporary, | 137 storagePartition, WebStorageQuotaTypeTemporary, |
| 135 new EstimateCallbacks(resolver)); | 138 new EstimateCallbacks(resolver)); |
| 136 return promise; | 139 return promise; |
| 137 } | 140 } |
| 138 | 141 |
| 139 DEFINE_TRACE(StorageManager) {} | 142 DEFINE_TRACE(StorageManager) {} |
| 140 | 143 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 155 | 158 |
| 156 void StorageManager::permissionRequestComplete(ScriptPromiseResolver* resolver, | 159 void StorageManager::permissionRequestComplete(ScriptPromiseResolver* resolver, |
| 157 PermissionStatus status) { | 160 PermissionStatus status) { |
| 158 if (!resolver->getExecutionContext() || | 161 if (!resolver->getExecutionContext() || |
| 159 resolver->getExecutionContext()->isContextDestroyed()) | 162 resolver->getExecutionContext()->isContextDestroyed()) |
| 160 return; | 163 return; |
| 161 resolver->resolve(status == PermissionStatus::GRANTED); | 164 resolver->resolve(status == PermissionStatus::GRANTED); |
| 162 } | 165 } |
| 163 | 166 |
| 164 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |