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 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 } | |
OLD | NEW |