Chromium Code Reviews| Index: Source/modules/quota/StorageManager.cpp |
| diff --git a/Source/modules/quota/StorageManager.cpp b/Source/modules/quota/StorageManager.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c6a534e20bd9a54d14f303f20c5cd6539248662e |
| --- /dev/null |
| +++ b/Source/modules/quota/StorageManager.cpp |
| @@ -0,0 +1,100 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "modules/quota/StorageManager.h" |
| + |
| +#include "bindings/core/v8/ScriptPromiseResolver.h" |
| +#include "core/dom/DOMError.h" |
| +#include "core/dom/Document.h" |
| +#include "modules/permissions/PermissionController.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebCallbacks.h" |
| +#include "public/platform/modules/permissions/WebPermissionClient.h" |
| +#include "public/platform/modules/permissions/WebPermissionStatus.h" |
| + |
| +namespace blink { |
| + |
| +namespace { |
| + |
| +WebPermissionClient* getPermissionClient(ExecutionContext* executionContext) |
|
dgrogan
2015/07/09 02:56:05
Mounir, you have a TODO about this block of code i
|
| +{ |
| + if (executionContext->isDocument()) { |
| + Document* document = toDocument(executionContext); |
| + if (!document->frame()) |
| + return nullptr; |
| + PermissionController* controller = PermissionController::from(*document->frame()); |
| + return controller ? controller->client() : nullptr; |
| + } |
| + return Platform::current()->permissionClient(); |
| +} |
| + |
| +} // namespace |
| + |
| +class DurableStoragePermissionCallbacks : public WebCallbacks<WebPermissionStatus, void> { |
| +public: |
| + DurableStoragePermissionCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_resolver(resolver) |
| + { |
| + |
| + } |
| + |
| + void onSuccess(WebPermissionStatus* rawStatus) override |
| + { |
| + OwnPtr<WebPermissionStatus> status = adoptPtr(rawStatus); |
| + String toReturn; |
| + switch (*status) { |
| + case WebPermissionStatusGranted: |
| + toReturn = "granted"; |
| + break; |
| + case WebPermissionStatusDenied: |
| + toReturn = "denied"; |
| + break; |
| + case WebPermissionStatusPrompt: |
| + toReturn = "default"; |
| + break; |
| + } |
| + m_resolver->resolve(toReturn); |
| + } |
| + void onError() override |
| + { |
| + ASSERT_NOT_REACHED(); |
| + } |
| + |
| +private: |
| + RefPtr<ScriptPromiseResolver> m_resolver; |
| +}; |
| + |
| +ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState) |
| +{ |
| + WTF_LOG_ERROR("Got into StorageManager::requestPersistent"); |
| + RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + ExecutionContext* executionContext = scriptState->executionContext(); |
| + SecurityOrigin* securityOrigin = executionContext->securityOrigin(); |
| + // TODO(dgrogan): Restrict to secure contexts, both here and in the browser |
| + // process. https://github.com/whatwg/storage/issues/5 |
| + if (securityOrigin->isUnique()) { |
| + resolver->reject(DOMException::create(NotSupportedError)); |
| + return promise; |
| + } |
| + if (executionContext->isDocument()) { |
| + WebPermissionClient* permissionClient = getPermissionClient(executionContext); |
| + ASSERT(permissionClient); |
| + permissionClient->requestDurablePermission(KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new DurableStoragePermissionCallbacks(resolver)); |
| + } else { |
| + // worker |
| + resolver->reject(DOMException::create(NotSupportedError)); |
| + return promise; |
| + } |
| + |
| + return promise; |
| +} |
| + |
| +ScriptPromise StorageManager::persistentPermission() |
| +{ |
| + ASSERT_NOT_REACHED(); |
| + return ScriptPromise(); |
| +} |
| + |
| +} |