Chromium Code Reviews| 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" | |
|
jsbell
2015/08/03 19:57:41
DOMError is not used?
dgrogan
2015/08/06 23:52:02
Only as a vehicle for ExceptionCode.h. Fixed.
| |
| 10 #include "core/dom/Document.h" | |
| 11 #include "modules/permissions/Permissions.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 class DurableStoragePermissionCallbacks : public WebCallbacks<WebPermissionStatu s*, void> { | |
|
jsbell
2015/08/03 19:57:41
Put this class in anonymous namespace?
jsbell
2015/08/03 19:57:41
final?
dgrogan
2015/08/06 23:52:02
Done.
dgrogan
2015/08/06 23:52:02
Done.
| |
| 20 public: | |
| 21 DurableStoragePermissionCallbacks(PassRefPtr<ScriptPromiseResolver> resolver ) | |
| 22 : m_resolver(resolver) | |
| 23 { | |
| 24 } | |
| 25 | |
| 26 void onSuccess(WebPermissionStatus* rawStatus) override | |
| 27 { | |
| 28 OwnPtr<WebPermissionStatus> status = adoptPtr(rawStatus); | |
| 29 String toReturn; | |
| 30 switch (*status) { | |
| 31 case WebPermissionStatusGranted: | |
| 32 toReturn = "granted"; | |
| 33 break; | |
| 34 case WebPermissionStatusDenied: | |
| 35 toReturn = "denied"; | |
| 36 break; | |
| 37 case WebPermissionStatusPrompt: | |
| 38 toReturn = "default"; | |
| 39 break; | |
| 40 } | |
| 41 m_resolver->resolve(toReturn); | |
|
Lalit Maganti
2015/08/04 13:27:41
Not really any work to be done but very similar co
dgrogan
2015/08/06 23:52:02
It'd be awkward to consolidate while the strings a
| |
| 42 } | |
| 43 void onError() override | |
| 44 { | |
| 45 ASSERT_NOT_REACHED(); | |
|
Lalit Maganti
2015/08/04 13:27:41
I think propogating the error to the resolver may
dgrogan
2015/08/06 23:52:02
I was trying to document that this method can neve
Lalit Maganti
2015/08/07 08:47:28
You're right - currently it cannot be reached. How
dgrogan
2015/08/10 22:26:40
I thought about this and still prefer to leave it
| |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 RefPtr<ScriptPromiseResolver> m_resolver; | |
| 50 }; | |
| 51 | |
| 52 ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState) | |
| 53 { | |
| 54 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
| 55 ScriptPromise promise = resolver->promise(); | |
| 56 ExecutionContext* executionContext = scriptState->executionContext(); | |
| 57 SecurityOrigin* securityOrigin = executionContext->securityOrigin(); | |
| 58 // TODO(dgrogan): Durable is restricted to secure contexts in the browser | |
| 59 // process. Can we do it here too, before jumping the process boundary? | |
|
jsbell
2015/08/03 19:57:41
Yes, use something like:
String errorMessage;
if
dgrogan
2015/08/06 23:52:02
Done, thanks a lot for the pointer.
| |
| 60 if (securityOrigin->isUnique()) { | |
| 61 resolver->reject(DOMException::create(NotSupportedError)); | |
| 62 return promise; | |
| 63 } | |
| 64 if (executionContext->isDocument()) { | |
|
mlamouri (slow - plz ping)
2015/08/04 13:15:19
Why do you want to check if it's in a document? Th
dgrogan
2015/08/06 23:52:02
I should probably rather DCHECK that it's a Docume
| |
| 65 WebPermissionClient* permissionClient = Permissions::getClient(execution Context); | |
| 66 ASSERT(permissionClient); | |
|
Lalit Maganti
2015/08/04 13:27:41
Should this be DASSERT or ASSERT? I think you can
dgrogan
2015/08/06 23:52:02
I don't think DASSERT exists:
https://code.google.
Lalit Maganti
2015/08/07 08:47:28
Apologies - I meant DCHECK
| |
| 67 permissionClient->requestPermission(WebPermissionTypeDurableStorage, KUR L(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new Du rableStoragePermissionCallbacks(resolver)); | |
| 68 } else { | |
| 69 resolver->reject(DOMException::create(NotSupportedError)); | |
| 70 return promise; | |
| 71 } | |
| 72 | |
| 73 return promise; | |
| 74 } | |
| 75 | |
| 76 ScriptPromise StorageManager::persistentPermission(ScriptState* scriptState) | |
| 77 { | |
| 78 // TODO(dgrogan): Add a test for calling this method on a file:/// origin. | |
| 79 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | |
| 80 ScriptPromise promise = resolver->promise(); | |
| 81 WebPermissionClient* permissionClient = Permissions::getClient(scriptState-> executionContext()); | |
| 82 permissionClient->queryPermission(WebPermissionTypeDurableStorage, KURL(KURL (), scriptState->executionContext()->securityOrigin()->toString()), new DurableS toragePermissionCallbacks(resolver)); | |
| 83 return promise; | |
| 84 } | |
| 85 | |
| 86 } // namespace blink | |
| OLD | NEW |