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" | |
| 9 #include "core/dom/DOMError.h" | |
| 8 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| 9 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 10 #include "modules/permissions/Permissions.h" | 12 #include "modules/permissions/Permissions.h" |
| 13 #include "modules/quota/StorageEstimate.h" | |
| 14 #include "platform/StorageQuotaCallbacks.h" | |
| 11 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 12 #include "public/platform/WebCallbacks.h" | 16 #include "public/platform/WebCallbacks.h" |
| 13 #include "public/platform/modules/permissions/WebPermissionClient.h" | 17 #include "public/platform/modules/permissions/WebPermissionClient.h" |
| 14 #include "public/platform/modules/permissions/WebPermissionStatus.h" | 18 #include "public/platform/modules/permissions/WebPermissionStatus.h" |
| 15 | 19 |
| 16 namespace blink { | 20 namespace blink { |
| 17 | 21 |
| 18 namespace { | 22 namespace { |
| 19 | 23 |
| 20 class DurableStorageQueryCallbacks final : public WebPermissionCallback { | 24 class DurableStorageQueryCallbacks final : public WebPermissionCallback { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 } | 66 } |
| 63 void onError() override | 67 void onError() override |
| 64 { | 68 { |
| 65 ASSERT_NOT_REACHED(); | 69 ASSERT_NOT_REACHED(); |
| 66 } | 70 } |
| 67 | 71 |
| 68 private: | 72 private: |
| 69 Persistent<ScriptPromiseResolver> m_resolver; | 73 Persistent<ScriptPromiseResolver> m_resolver; |
| 70 }; | 74 }; |
| 71 | 75 |
| 76 class EstimateCallbacks final : public StorageQuotaCallbacks { | |
| 77 WTF_MAKE_NONCOPYABLE(EstimateCallbacks); | |
| 78 public: | |
| 79 explicit EstimateCallbacks(ScriptPromiseResolver* resolver) | |
| 80 : m_resolver(resolver) {} | |
| 81 | |
| 82 ~EstimateCallbacks() override {} | |
| 83 | |
| 84 void didQueryStorageUsageAndQuota(unsigned long long usageInBytes, unsigned long long quotaInBytes) override | |
| 85 { | |
| 86 StorageEstimate estimate; | |
| 87 estimate.setUsage(usageInBytes); | |
| 88 estimate.setQuota(quotaInBytes); | |
| 89 m_resolver->resolve(estimate); | |
|
kinuko
2016/04/20 05:56:32
So we're basically just going to expose these raw
jsbell
2016/04/20 19:38:04
Correct.
| |
| 90 } | |
| 91 | |
| 92 void didFail(WebStorageQuotaError error) override | |
| 93 { | |
| 94 // TODO: DOMException! | |
|
kinuko
2016/04/20 05:56:32
TODO(jsbell) ..?
jsbell
2016/04/20 19:38:04
Convered this (and below) to use DOMException. Not
| |
| 95 m_resolver->reject(DOMError::create(static_cast<ExceptionCode>(error))); | |
| 96 } | |
| 97 | |
| 98 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 99 { | |
| 100 visitor->trace(m_resolver); | |
| 101 StorageQuotaCallbacks::trace(visitor); | |
| 102 } | |
| 103 | |
| 104 private: | |
| 105 Member<ScriptPromiseResolver> m_resolver; | |
| 106 }; | |
| 107 | |
| 72 } // namespace | 108 } // namespace |
| 73 | 109 |
| 74 ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState) | 110 ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState) |
| 75 { | 111 { |
| 76 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 112 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
| 77 ScriptPromise promise = resolver->promise(); | 113 ScriptPromise promise = resolver->promise(); |
| 78 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 114 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 79 SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); | 115 SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); |
| 80 // TODO(dgrogan): Is the isUnique() check covered by the later | 116 // TODO(dgrogan): Is the isUnique() check covered by the later |
| 81 // isSecureContext() check? If so, maybe remove it. Write a test if it | 117 // isSecureContext() check? If so, maybe remove it. Write a test if it |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 106 ScriptPromise promise = resolver->promise(); | 142 ScriptPromise promise = resolver->promise(); |
| 107 WebPermissionClient* permissionClient = Permissions::getClient(scriptState-> getExecutionContext()); | 143 WebPermissionClient* permissionClient = Permissions::getClient(scriptState-> getExecutionContext()); |
| 108 if (!permissionClient) { | 144 if (!permissionClient) { |
| 109 resolver->reject(DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions.")); | 145 resolver->reject(DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions.")); |
| 110 return promise; | 146 return promise; |
| 111 } | 147 } |
| 112 permissionClient->queryPermission(WebPermissionTypeDurableStorage, KURL(KURL (), scriptState->getExecutionContext()->getSecurityOrigin()->toString()), new Du rableStorageQueryCallbacks(resolver)); | 148 permissionClient->queryPermission(WebPermissionTypeDurableStorage, KURL(KURL (), scriptState->getExecutionContext()->getSecurityOrigin()->toString()), new Du rableStorageQueryCallbacks(resolver)); |
| 113 return promise; | 149 return promise; |
| 114 } | 150 } |
| 115 | 151 |
| 152 ScriptPromise StorageManager::estimate(ScriptState* scriptState) | |
| 153 { | |
| 154 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 155 ScriptPromise promise = resolver->promise(); | |
| 156 ExecutionContext* executionContext = scriptState->getExecutionContext(); | |
| 157 SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); | |
| 158 if (securityOrigin->isUnique()) { | |
| 159 resolver->reject(DOMError::create(NotSupportedError)); | |
| 160 return promise; | |
| 161 } | |
| 162 // IDL has: [SecureContext] | |
| 163 String errorMessage; | |
| 164 if (!executionContext->isSecureContext(errorMessage)) { | |
| 165 resolver->reject(DOMException::create(SecurityError, errorMessage)); | |
| 166 return promise; | |
| 167 } | |
| 168 | |
| 169 KURL storagePartition = KURL(KURL(), securityOrigin->toString()); | |
| 170 Platform::current()->queryStorageUsageAndQuota(storagePartition, WebStorageQ uotaTypeTemporary, new EstimateCallbacks(resolver)); | |
| 171 return promise; | |
| 172 } | |
| 173 | |
| 116 DEFINE_TRACE(StorageManager) | 174 DEFINE_TRACE(StorageManager) |
| 117 { | 175 { |
| 118 } | 176 } |
| 119 | 177 |
| 120 } // namespace blink | 178 } // namespace blink |
| OLD | NEW |