| 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..a3422c72d83eacc1fa889ecfaf5fa18a8097b233
|
| --- /dev/null
|
| +++ b/Source/modules/quota/StorageManager.cpp
|
| @@ -0,0 +1,81 @@
|
| +// 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 "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 {
|
| +
|
| +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)
|
| +{
|
| + 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 = WebPermissionClient::get(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();
|
| +}
|
| +
|
| +}
|
|
|