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

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: hacked up DEPS Created 5 years, 5 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
« no previous file with comments | « Source/modules/quota/StorageManager.h ('k') | Source/modules/quota/StorageManager.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+}
+
+}
« no previous file with comments | « Source/modules/quota/StorageManager.h ('k') | Source/modules/quota/StorageManager.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698