Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1651)

Unified Diff: Source/modules/quota/StorageManager.cpp

Issue 1154573005: Expose Durable Storage API to script (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rename WebSomeCallbacks and SomeCallbacks Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6291a77cd39a58d46ae969ee0612237ec9d75c1b
--- /dev/null
+++ b/Source/modules/quota/StorageManager.cpp
@@ -0,0 +1,70 @@
+// 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);
+ }
+
+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();
+ if (securityOrigin->isUnique()) {
+ resolver->reject(DOMError::create(NotSupportedError));
jsbell 2015/07/01 17:43:29 Reject with DOMException, not DOMError.
dgrogan 2015/07/07 04:03:24 Done.
+ return promise;
+ }
+ if (executionContext->isDocument()) {
+ Document* document = toDocument(executionContext);
+ if (!document->frame()) {
+ // Do something better?
+ return ScriptPromise();
+ }
+ DurableStorageController* controller = DurableStorageController::from(*document->frame());
+ if (!controller) // needed?
jsbell 2015/07/01 17:43:29 Shouldn't be needed. Did you see this test elsewhe
dgrogan 2015/07/07 04:03:24 I thought so but don't see it now. In any case I'm
+ return ScriptPromise();
+ blink::WebDurableStorageDispatcher* client = controller->client();
+ ASSERT(client);
+ client->requestPermission(KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new DurableStoragePermissionCallbacks(resolver));
+ } else {
+ // worker
+ resolver->reject(DOMError::create(NotSupportedError));
jsbell 2015/07/01 17:43:29 Reject with DOMException, not DOMError.
dgrogan 2015/07/07 04:03:24 Done.
+ return promise;
+ }
+
+ return promise;
+}
+
+ScriptPromise StorageManager::persistentPermission()
+{
+ ASSERT_NOT_REACHED();
+ return ScriptPromise();
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698