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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/quota/StorageManager.h ('k') | Source/modules/quota/StorageManager.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "modules/quota/StorageManager.h"
7
8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMError.h"
10 #include "core/dom/Document.h"
11 #include "modules/permissions/PermissionController.h"
12 #include "public/platform/Platform.h"
13 #include "public/platform/WebCallbacks.h"
14 #include "public/platform/modules/permissions/WebPermissionClient.h"
15 #include "public/platform/modules/permissions/WebPermissionStatus.h"
16
17 namespace blink {
18
19 namespace {
20
21 WebPermissionClient* getPermissionClient(ExecutionContext* executionContext)
dgrogan 2015/07/09 02:56:05 Mounir, you have a TODO about this block of code i
22 {
23 if (executionContext->isDocument()) {
24 Document* document = toDocument(executionContext);
25 if (!document->frame())
26 return nullptr;
27 PermissionController* controller = PermissionController::from(*document- >frame());
28 return controller ? controller->client() : nullptr;
29 }
30 return Platform::current()->permissionClient();
31 }
32
33 } // namespace
34
35 class DurableStoragePermissionCallbacks : public WebCallbacks<WebPermissionStatu s, void> {
36 public:
37 DurableStoragePermissionCallbacks(PassRefPtr<ScriptPromiseResolver> resolver ) : m_resolver(resolver)
38 {
39
40 }
41
42 void onSuccess(WebPermissionStatus* rawStatus) override
43 {
44 OwnPtr<WebPermissionStatus> status = adoptPtr(rawStatus);
45 String toReturn;
46 switch (*status) {
47 case WebPermissionStatusGranted:
48 toReturn = "granted";
49 break;
50 case WebPermissionStatusDenied:
51 toReturn = "denied";
52 break;
53 case WebPermissionStatusPrompt:
54 toReturn = "default";
55 break;
56 }
57 m_resolver->resolve(toReturn);
58 }
59 void onError() override
60 {
61 ASSERT_NOT_REACHED();
62 }
63
64 private:
65 RefPtr<ScriptPromiseResolver> m_resolver;
66 };
67
68 ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState)
69 {
70 WTF_LOG_ERROR("Got into StorageManager::requestPersistent");
71 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
72 ScriptPromise promise = resolver->promise();
73 ExecutionContext* executionContext = scriptState->executionContext();
74 SecurityOrigin* securityOrigin = executionContext->securityOrigin();
75 // TODO(dgrogan): Restrict to secure contexts, both here and in the browser
76 // process. https://github.com/whatwg/storage/issues/5
77 if (securityOrigin->isUnique()) {
78 resolver->reject(DOMException::create(NotSupportedError));
79 return promise;
80 }
81 if (executionContext->isDocument()) {
82 WebPermissionClient* permissionClient = getPermissionClient(executionCon text);
83 ASSERT(permissionClient);
84 permissionClient->requestDurablePermission(KURL(KURL(), scriptState->exe cutionContext()->securityOrigin()->toString()), new DurableStoragePermissionCall backs(resolver));
85 } else {
86 // worker
87 resolver->reject(DOMException::create(NotSupportedError));
88 return promise;
89 }
90
91 return promise;
92 }
93
94 ScriptPromise StorageManager::persistentPermission()
95 {
96 ASSERT_NOT_REACHED();
97 return ScriptPromise();
98 }
99
100 }
OLDNEW
« 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