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

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: rename WebSomeCallbacks and SomeCallbacks 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
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/quota/DurableStorageController.h"
12 #include "public/platform/modules/quota/WebDurableStorageDispatcher.h"
13
14 namespace blink {
15
16 class DurableStoragePermissionCallbacks : public WebDurableStoragePermissionCall backs {
17 public:
18 DurableStoragePermissionCallbacks(PassRefPtr<ScriptPromiseResolver> resolver ) : m_resolver(resolver)
19 {
20
21 }
22
23 void didGetPermission(WebDurableStoragePermission result) override
24 {
25 m_resolver->resolve(result);
26 }
27
28 private:
29 RefPtr<ScriptPromiseResolver> m_resolver;
30 };
31
32 ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState)
33 {
34 WTF_LOG_ERROR("Got into StorageManager::requestPersistent");
35 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
36 ScriptPromise promise = resolver->promise();
37 ExecutionContext* executionContext = scriptState->executionContext();
38 SecurityOrigin* securityOrigin = executionContext->securityOrigin();
39 if (securityOrigin->isUnique()) {
40 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.
41 return promise;
42 }
43 if (executionContext->isDocument()) {
44 Document* document = toDocument(executionContext);
45 if (!document->frame()) {
46 // Do something better?
47 return ScriptPromise();
48 }
49 DurableStorageController* controller = DurableStorageController::from(*d ocument->frame());
50 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
51 return ScriptPromise();
52 blink::WebDurableStorageDispatcher* client = controller->client();
53 ASSERT(client);
54 client->requestPermission(KURL(KURL(), scriptState->executionContext()-> securityOrigin()->toString()), new DurableStoragePermissionCallbacks(resolver));
55 } else {
56 // worker
57 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.
58 return promise;
59 }
60
61 return promise;
62 }
63
64 ScriptPromise StorageManager::persistentPermission()
65 {
66 ASSERT_NOT_REACHED();
67 return ScriptPromise();
68 }
69
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698