diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-07-18 09:50:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-18 09:50:59 -0700 |
commit | 513811f6b40d522bc425c2588320b889614f2973 (patch) | |
tree | e5903d6006fbc90d9e4093b37cb3b2491e44f830 /components/script/dom/worker.rs | |
parent | b36a3b2fee3e70c11af2bc24832e65510acb71ec (diff) | |
parent | eff3e01df0581e9ee3dc827dd13e86202b66752a (diff) | |
download | servo-513811f6b40d522bc425c2588320b889614f2973.tar.gz servo-513811f6b40d522bc425c2588320b889614f2973.zip |
Auto merge of #11727 - creativcoder:swmanager, r=jdm
Integrate service worker manager thread
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes are part of #11091
<!-- Either: -->
- [X] There are tests for these changes at my [gh-pages](https://github.com/creativcoder/gsoc16/tree/gh-pages) branch to test the instantiation of service workers by their manager, but will need to discuss how that would integrate into master.
Changes:
- Introduces a `ServiceWorkerManager`, which maintains an map of registered service workers as well as a map of active workers keyed by their `scope_url`.
- Adds the initialization of ServiceWorkerManager, at the `script::init()`, which makes it available as a single entity listening for requests from different script threads.
- Adds a timeout thread in `serviceworkerglobalscope`, which terminates the workers, after a timeout of 60 secs, thereby removing it from the active workers list.
- Adds the matching of scope urls, in longest prefix way rather than path structural way, according to [spec](https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#scope-match-algorithm).
- Make ServiceWorkerManager, the holder of network sender, instead of script thread, so it can send `CustomResponse`.
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11727)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/worker.rs')
-rw-r--r-- | components/script/dom/worker.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index 2cf1d1c4e46..c318672fb7a 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -2,9 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - +use devtools_traits::{ScriptToDevtoolsControlMsg, DevtoolsPageInfo}; +use dom::abstractworker::WorkerScriptMsg; use dom::abstractworker::{SimpleWorkerErrorHandler, SharedRt, WorkerErrorHandler}; -use dom::abstractworker::{WorkerScriptLoadOrigin, WorkerScriptMsg}; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::WorkerBinding; use dom::bindings::codegen::Bindings::WorkerBinding::WorkerMethods; @@ -26,6 +26,7 @@ use ipc_channel::ipc; use js::jsapi::{HandleValue, JSContext, JSAutoCompartment}; use js::jsval::UndefinedValue; use script_thread::Runnable; +use script_traits::WorkerScriptLoadOrigin; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{Sender, channel}; use std::sync::{Arc, Mutex}; @@ -81,21 +82,28 @@ impl Worker { let worker_load_origin = WorkerScriptLoadOrigin { referrer_url: None, referrer_policy: None, - request_source: global.request_source(), pipeline_id: Some(global.pipeline()) }; let (devtools_sender, devtools_receiver) = ipc::channel().unwrap(); + let worker_id = global.get_next_worker_id(); + if let Some(ref chan) = global.devtools_chan() { + let pipeline_id = global.pipeline(); + let title = format!("Worker for {}", worker_url); + let page_info = DevtoolsPageInfo { + title: title, + url: worker_url.clone(), + }; + let _ = chan.send(ScriptToDevtoolsControlMsg::NewGlobal((pipeline_id, Some(worker_id)), + devtools_sender.clone(), + page_info)); + } - let init = prepare_workerscope_init(global, - "Worker".to_owned(), - worker_url.clone(), - devtools_sender.clone(), - closing); + let init = prepare_workerscope_init(global, Some(devtools_sender)); DedicatedWorkerGlobalScope::run_worker_scope( init, worker_url, global.pipeline(), devtools_receiver, worker.runtime.clone(), worker_ref, - global.script_chan(), sender, receiver, worker_load_origin); + global.script_chan(), sender, receiver, worker_load_origin, closing); Ok(worker) } |