Commit 4d88b936 authored by Yoav Weiss's avatar Yoav Weiss Committed by Commit Bot

[ua-ch] Queue getHighEntropyValues() on a Task

Aligns the implementation with the spec.
https://github.com/WICG/ua-client-hints/issues/77 discusses which Task
type it should be queued on.

Bug: 1070934
Change-Id: I3461f7f1a2e6346717e568008b9879f20d39a82e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2166103Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarAaron Tagliaboschi <aarontag@chromium.org>
Commit-Queue: Yoav Weiss <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763558}
parent a497c856
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/frame/navigator_ua_data.h" #include "third_party/blink/renderer/core/frame/navigator_ua_data.h"
#include "base/single_thread_task_runner.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_ua_data_values.h" #include "third_party/blink/renderer/bindings/core/v8/v8_ua_data_values.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
...@@ -66,6 +67,8 @@ ScriptPromise NavigatorUAData::getHighEntropyValues( ...@@ -66,6 +67,8 @@ ScriptPromise NavigatorUAData::getHighEntropyValues(
Vector<String>& hints) const { Vector<String>& hints) const {
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
auto* executionContext =
ExecutionContext::From(script_state); // GetExecutionContext();
UADataValues* values = MakeGarbageCollected<UADataValues>(); UADataValues* values = MakeGarbageCollected<UADataValues>();
for (const String& hint : hints) { for (const String& hint : hints) {
if (hint == "platform") { if (hint == "platform") {
...@@ -80,7 +83,15 @@ ScriptPromise NavigatorUAData::getHighEntropyValues( ...@@ -80,7 +83,15 @@ ScriptPromise NavigatorUAData::getHighEntropyValues(
values->setUaFullVersion(ua_full_version_); values->setUaFullVersion(ua_full_version_);
} }
} }
resolver->Resolve(values);
DCHECK(executionContext);
executionContext->GetTaskRunner(TaskType::kPermission)
->PostTask(
FROM_HERE,
WTF::Bind([](ScriptPromiseResolver* resolver,
UADataValues* values) { resolver->Resolve(values); },
WrapPersistent(resolver), WrapPersistent(values)));
return promise; return promise;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
}, "navigator.userAgentData is exposed."); }, "navigator.userAgentData is exposed.");
promise_test(async t => { promise_test(async t => {
let didMicrotaskRun = false;
const uaData = navigator.userAgentData; const uaData = navigator.userAgentData;
for (brandVersionPair of uaData.brands) { for (brandVersionPair of uaData.brands) {
assert_equals(typeof brandVersionPair.brand, "string", "brand should be a string"); assert_equals(typeof brandVersionPair.brand, "string", "brand should be a string");
...@@ -25,5 +26,12 @@ ...@@ -25,5 +26,12 @@
assert_equals(highEntropyData2["platformVersion"], "", "Platform version should be an empty string"); assert_equals(highEntropyData2["platformVersion"], "", "Platform version should be an empty string");
assert_equals(highEntropyData2["architecture"], "", "Architecture should be an empty string"); assert_equals(highEntropyData2["architecture"], "", "Architecture should be an empty string");
assert_equals(highEntropyData2["model"], "", "Model should be an empty string"); assert_equals(highEntropyData2["model"], "", "Model should be an empty string");
let finalPromise = uaData.getHighEntropyValues([]).then(() => {
assert_true(didMicrotaskRun, "getHighEntropyValues queued on a task");
});
await Promise.resolve().then(function() {
didMicrotaskRun = true;
});
return finalPromise;
}, "navigator.userAgentData returns a UserAgentMetadata object."); }, "navigator.userAgentData returns a UserAgentMetadata object.");
</script> </script>
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