Commit 8f9d50e1 authored by dgrogan@chromium.org's avatar dgrogan@chromium.org

Update Durable Storage API method signature

Instead of returning a permission string, requestPersistent() was
recently changed to return a boolean representing the value of the default
box.

This is an experimental API only exposed behind a flag. The spec is at
https://storage.spec.whatwg.org/

BUG=482814

Review URL: https://codereview.chromium.org/1302643002

git-svn-id: svn://svn.chromium.org/blink/trunk@200795 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent e870fcc1
...@@ -12,11 +12,10 @@ promise_test(function() { ...@@ -12,11 +12,10 @@ promise_test(function() {
assert_true(promise instanceof Promise, assert_true(promise instanceof Promise,
"navigator.storage.requestPersistent() returned a Promise.") "navigator.storage.requestPersistent() returned a Promise.")
return promise.then(function (result) { return promise.then(function (result) {
// Layout tests get canned results, not the strings per spec. So testing // Layout tests get canned results, not the value per spec. So testing
// their values here would only be testing our test plumbing. But we can // their values here would only be testing our test plumbing. But we can
// test that a string is being returned instead of something else. // test that the type of the returned value is correct.
assert_equals(typeof result, "string", result + " should be a string"); assert_equals(typeof result, "boolean", result + " should be boolean");
assert_greater_than(result.length, 0, "result should have length >0");
}); });
}, "navigator.storage.requestPersistent returns a promise that resolves."); }, "navigator.storage.requestPersistent returns a promise that resolves.");
......
jsbell@chromium.org
kinuko@chromium.org kinuko@chromium.org
nhiroki@chromium.org nhiroki@chromium.org
tzik@chromium.org tzik@chromium.org
...@@ -18,9 +18,9 @@ namespace blink { ...@@ -18,9 +18,9 @@ namespace blink {
namespace { namespace {
class DurableStoragePermissionCallbacks final : public WebCallbacks<WebPermissionStatus*, void> { class DurableStorageQueryCallbacks final : public WebCallbacks<WebPermissionStatus*, void> {
public: public:
DurableStoragePermissionCallbacks(ScriptPromiseResolver* resolver) DurableStorageQueryCallbacks(ScriptPromiseResolver* resolver)
: m_resolver(resolver) : m_resolver(resolver)
{ {
} }
...@@ -51,6 +51,27 @@ private: ...@@ -51,6 +51,27 @@ private:
Persistent<ScriptPromiseResolver> m_resolver; Persistent<ScriptPromiseResolver> m_resolver;
}; };
class DurableStorageRequestCallbacks final : public WebCallbacks<WebPermissionStatus*, void> {
public:
DurableStorageRequestCallbacks(ScriptPromiseResolver* resolver)
: m_resolver(resolver)
{
}
void onSuccess(WebPermissionStatus* rawStatus) override
{
OwnPtr<WebPermissionStatus> status = adoptPtr(rawStatus);
m_resolver->resolve(*status == WebPermissionStatusGranted);
}
void onError() override
{
ASSERT_NOT_REACHED();
}
private:
Persistent<ScriptPromiseResolver> m_resolver;
};
} // namespace } // namespace
ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState) ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState)
...@@ -77,7 +98,7 @@ ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState) ...@@ -77,7 +98,7 @@ ScriptPromise StorageManager::requestPersistent(ScriptState* scriptState)
resolver->reject(DOMException::create(InvalidStateError, "In its current state, the global scope can't request permissions.")); resolver->reject(DOMException::create(InvalidStateError, "In its current state, the global scope can't request permissions."));
return promise; return promise;
} }
permissionClient->requestPermission(WebPermissionTypeDurableStorage, KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new DurableStoragePermissionCallbacks(resolver)); permissionClient->requestPermission(WebPermissionTypeDurableStorage, KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new DurableStorageRequestCallbacks(resolver));
return promise; return promise;
} }
...@@ -91,7 +112,7 @@ ScriptPromise StorageManager::persistentPermission(ScriptState* scriptState) ...@@ -91,7 +112,7 @@ ScriptPromise StorageManager::persistentPermission(ScriptState* scriptState)
resolver->reject(DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions.")); resolver->reject(DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions."));
return promise; return promise;
} }
permissionClient->queryPermission(WebPermissionTypeDurableStorage, KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new DurableStoragePermissionCallbacks(resolver)); permissionClient->queryPermission(WebPermissionTypeDurableStorage, KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new DurableStorageQueryCallbacks(resolver));
return promise; return promise;
} }
......
...@@ -12,7 +12,7 @@ enum PersistentStoragePermission { "default", "denied", "granted" }; ...@@ -12,7 +12,7 @@ enum PersistentStoragePermission { "default", "denied", "granted" };
GarbageCollected, GarbageCollected,
RuntimeEnabled=DurableStorage, RuntimeEnabled=DurableStorage,
] interface StorageManager { ] interface StorageManager {
[CallWith=ScriptState] Promise<PersistentStoragePermission> requestPersistent(); [CallWith=ScriptState] Promise<boolean> requestPersistent();
[CallWith=ScriptState] Promise<PersistentStoragePermission> persistentPermission(); [CallWith=ScriptState] Promise<PersistentStoragePermission> persistentPermission();
// TODO(dgrogan): Implement estimate() and persistentEstimate(). // TODO(dgrogan): Implement estimate() and persistentEstimate().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment