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 // m_resolver->reject(result); |
| 27 } |
| 28 |
| 29 private: |
| 30 RefPtr<ScriptPromiseResolver> m_resolver; |
| 31 }; |
| 32 |
| 33 ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState) |
| 34 { |
| 35 WTF_LOG_ERROR("Got into StorageManager::requestPersistent"); |
| 36 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
| 37 ScriptPromise promise = resolver->promise(); |
| 38 ExecutionContext* executionContext = scriptState->executionContext(); |
| 39 SecurityOrigin* securityOrigin = executionContext->securityOrigin(); |
| 40 // TODO(dgrogan): Restrict to secure contexts, both here and in the browser |
| 41 // process. https://github.com/whatwg/storage/issues/5 |
| 42 if (securityOrigin->isUnique()) { |
| 43 resolver->reject(DOMException::create(NotSupportedError)); |
| 44 return promise; |
| 45 } |
| 46 if (executionContext->isDocument()) { |
| 47 Document* document = toDocument(executionContext); |
| 48 if (!document->frame()) { |
| 49 // Do something better? |
| 50 return ScriptPromise(); |
| 51 } |
| 52 DurableStorageController* controller = DurableStorageController::from(*d
ocument->frame()); |
| 53 blink::WebDurableStorageDispatcher* client = controller->client(); |
| 54 ASSERT(client); |
| 55 client->requestPermission(KURL(KURL(), scriptState->executionContext()->
securityOrigin()->toString()), new DurableStoragePermissionCallbacks(resolver)); |
| 56 } else { |
| 57 // worker |
| 58 resolver->reject(DOMException::create(NotSupportedError)); |
| 59 return promise; |
| 60 } |
| 61 |
| 62 return promise; |
| 63 } |
| 64 |
| 65 ScriptPromise StorageManager::persistentPermission() |
| 66 { |
| 67 ASSERT_NOT_REACHED(); |
| 68 return ScriptPromise(); |
| 69 } |
| 70 |
| 71 } |
OLD | NEW |