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..1be6eef6a3932ad2c5aa5241e575474ea51f9c41 |
--- /dev/null |
+++ b/Source/modules/quota/StorageManager.cpp |
@@ -0,0 +1,71 @@ |
+// 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/quota/DurableStorageController.h" |
+#include "public/platform/modules/quota/WebDurableStorageDispatcher.h" |
+ |
+namespace blink { |
+ |
+class DurableStoragePermissionCallbacks : public WebDurableStoragePermissionCallbacks { |
+public: |
+ DurableStoragePermissionCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_resolver(resolver) |
+ { |
+ |
+ } |
+ |
+ void didGetPermission(WebDurableStoragePermission result) override |
+ { |
+ m_resolver->resolve(result); |
+// m_resolver->reject(result); |
+ } |
+ |
+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()) { |
+ Document* document = toDocument(executionContext); |
+ if (!document->frame()) { |
+ // Do something better? |
+ return ScriptPromise(); |
+ } |
+ DurableStorageController* controller = DurableStorageController::from(*document->frame()); |
+ blink::WebDurableStorageDispatcher* client = controller->client(); |
+ ASSERT(client); |
+ client->requestPermission(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(); |
+} |
+ |
+} |