fix(script): Set DedicatedWorkerGlobalScope's origin correctly

<https://html.spec.whatwg.org/multipage/workers.html#worker-processing-model>

> 10.2.4 Processing model
>
> When a user agent is to run a worker for a script with `Worker` or
> `SharedWorker` object `worker`, [...] it must run the following steps.
>
> [...]
>
> 8. Set up a worker environment settings object with `realm execution
>    context` and `outside settings`, and let `inside settings` be the
>    result.

<https://html.spec.whatwg.org/multipage/workers.html#script-settings-for-workers>

> To **set up a worker environment settings object**, given a JavaScript
> execution context `execution context` and environment settings object
> `outside settings`:
>
> 1. Let `inherited origin` be `outside settings`'s origin.
>
> 2. Let `realm` be the value of `execution context`'s Realm component.
>
> 3. Let `worker global scope` be `realm`'s global object.
>
> 4. Let `settings object` be a new environment settings object whose
>    algorithms are defined as follows:
>
>    **The origin** Return a unique opaque origin if `worker global
>    scope`'s url's scheme is "data", and `inherited origin` otherwise.
This commit is contained in:
yvt 2021-07-13 09:31:15 +09:00
parent 4181962504
commit e9af95ec0f
5 changed files with 13 additions and 17 deletions

View file

@ -53,7 +53,7 @@ use net_traits::IpcSend;
use parking_lot::Mutex;
use script_traits::{WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
use servo_rand::random;
use servo_url::ServoUrl;
use servo_url::{ImmutableOrigin, ServoUrl};
use std::mem::replace;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
@ -310,7 +310,7 @@ impl DedicatedWorkerGlobalScope {
#[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#run-a-worker
pub fn run_worker_scope(
init: WorkerGlobalScopeInit,
mut init: WorkerGlobalScopeInit,
worker_url: ServoUrl,
from_devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>,
worker: TrustedWorkerAddress,
@ -387,6 +387,17 @@ impl DedicatedWorkerGlobalScope {
devtools_mpsc_chan,
);
// Step 8 "Set up a worker environment settings object [...]"
//
// <https://html.spec.whatwg.org/multipage/workers.html#script-settings-for-workers>
//
// > The origin: Return a unique opaque origin if `worker global
// > scope`'s url's scheme is "data", and `inherited origin`
// > otherwise.
if worker_url.scheme() == "data" {
init.origin = ImmutableOrigin::new_opaque();
}
let global = DedicatedWorkerGlobalScope::new(
init,
DOMString::from_string(worker_name),

View file

@ -1,4 +0,0 @@
[dedicated-worker-in-data-url-context.window.html]
[Create a dedicated worker in a data url dedicated worker]
expected: FAIL

View file

@ -1,4 +0,0 @@
[data-url-worker.html]
[fetching "top.txt" without ACAO should be rejected.]
expected: FAIL

View file

@ -3,9 +3,6 @@
[Same Origin SharedWorker]
expected: FAIL
[Data Url Worker]
expected: FAIL
[Data Url SharedWorker]
expected: FAIL

View file

@ -1,4 +0,0 @@
[dedicated-worker-in-data-url-context.window.html]
[Create a dedicated worker in a data url dedicated worker]
expected: FAIL