OLD | NEW |
---|---|
(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 SomeCallbacks : public WebSomeCallbacks { | |
17 public: | |
18 SomeCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_resolver(resol ver) | |
19 { | |
20 | |
21 } | |
22 | |
23 void setPromptResult(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()) { | |
jsbell
2015/07/01 17:43:29
Add a TODO to track https://github.com/whatwg/stor
dgrogan
2015/07/07 04:03:24
Done.
| |
40 resolver->reject(DOMError::create(NotSupportedError)); | |
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? | |
51 return ScriptPromise(); | |
52 blink::WebDurableStorageDispatcher* client = controller->client(); | |
53 ASSERT(client); | |
54 client->requestPermission(KURL(KURL(), scriptState->executionContext()-> securityOrigin()->toString()), new SomeCallbacks(resolver)); | |
55 } else { | |
56 // worker | |
57 resolver->reject(DOMError::create(NotSupportedError)); | |
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 } | |
OLD | NEW |