Chromium Code Reviews| Index: third_party/WebKit/Source/modules/quota/StorageManager.cpp |
| diff --git a/third_party/WebKit/Source/modules/quota/StorageManager.cpp b/third_party/WebKit/Source/modules/quota/StorageManager.cpp |
| index d35efdf3bc982e8f7af73784e89b0ac2091c5a7b..ccd8eff032333da0b11cca550740bd84a7463947 100644 |
| --- a/third_party/WebKit/Source/modules/quota/StorageManager.cpp |
| +++ b/third_party/WebKit/Source/modules/quota/StorageManager.cpp |
| @@ -5,9 +5,13 @@ |
| #include "modules/quota/StorageManager.h" |
| #include "bindings/core/v8/ScriptPromiseResolver.h" |
| +#include "bindings/modules/v8/V8StorageEstimate.h" |
| +#include "core/dom/DOMError.h" |
| #include "core/dom/Document.h" |
| #include "core/dom/ExceptionCode.h" |
| #include "modules/permissions/Permissions.h" |
| +#include "modules/quota/StorageEstimate.h" |
| +#include "platform/StorageQuotaCallbacks.h" |
| #include "public/platform/Platform.h" |
| #include "public/platform/WebCallbacks.h" |
| #include "public/platform/modules/permissions/WebPermissionClient.h" |
| @@ -69,6 +73,38 @@ private: |
| Persistent<ScriptPromiseResolver> m_resolver; |
| }; |
| +class EstimateCallbacks final : public StorageQuotaCallbacks { |
| + WTF_MAKE_NONCOPYABLE(EstimateCallbacks); |
| +public: |
| + explicit EstimateCallbacks(ScriptPromiseResolver* resolver) |
| + : m_resolver(resolver) {} |
| + |
| + ~EstimateCallbacks() override {} |
| + |
| + void didQueryStorageUsageAndQuota(unsigned long long usageInBytes, unsigned long long quotaInBytes) override |
| + { |
| + StorageEstimate estimate; |
| + estimate.setUsage(usageInBytes); |
| + estimate.setQuota(quotaInBytes); |
| + 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.
|
| + } |
| + |
| + void didFail(WebStorageQuotaError error) override |
| + { |
| + // 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
|
| + m_resolver->reject(DOMError::create(static_cast<ExceptionCode>(error))); |
| + } |
| + |
| + DEFINE_INLINE_VIRTUAL_TRACE() |
| + { |
| + visitor->trace(m_resolver); |
| + StorageQuotaCallbacks::trace(visitor); |
| + } |
| + |
| +private: |
| + Member<ScriptPromiseResolver> m_resolver; |
| +}; |
| + |
| } // namespace |
| ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState) |
| @@ -113,6 +149,28 @@ ScriptPromise StorageManager::persistentPermission(ScriptState* scriptState) |
| return promise; |
| } |
| +ScriptPromise StorageManager::estimate(ScriptState* scriptState) |
| +{ |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| + SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin(); |
| + if (securityOrigin->isUnique()) { |
| + resolver->reject(DOMError::create(NotSupportedError)); |
| + return promise; |
| + } |
| + // IDL has: [SecureContext] |
| + String errorMessage; |
| + if (!executionContext->isSecureContext(errorMessage)) { |
| + resolver->reject(DOMException::create(SecurityError, errorMessage)); |
| + return promise; |
| + } |
| + |
| + KURL storagePartition = KURL(KURL(), securityOrigin->toString()); |
| + Platform::current()->queryStorageUsageAndQuota(storagePartition, WebStorageQuotaTypeTemporary, new EstimateCallbacks(resolver)); |
| + return promise; |
| +} |
| + |
| DEFINE_TRACE(StorageManager) |
| { |
| } |