Integrate service worker manager thread

This commit is contained in:
Rahul Sharma 2016-06-09 18:52:52 +05:30
parent e8fa02a07f
commit 1e6293ea1d
39 changed files with 764 additions and 582 deletions

View file

@ -11,6 +11,8 @@ use dom::bindings::str::USVString;
use dom::eventtarget::EventTarget;
use dom::serviceworker::ServiceWorker;
use dom::serviceworkercontainer::Controllable;
use dom::workerglobalscope::prepare_workerscope_init;
use script_traits::{WorkerScriptLoadOrigin, ScopeThings};
use url::Url;
#[dom_struct]
@ -19,7 +21,7 @@ pub struct ServiceWorkerRegistration {
active: Option<JS<ServiceWorker>>,
installing: Option<JS<ServiceWorker>>,
waiting: Option<JS<ServiceWorker>>,
scope: String,
scope: String
}
impl ServiceWorkerRegistration {
@ -29,7 +31,7 @@ impl ServiceWorkerRegistration {
active: Some(JS::from_ref(active_sw)),
installing: None,
waiting: None,
scope: scope
scope: scope,
}
}
#[allow(unrooted_must_root)]
@ -37,11 +39,47 @@ impl ServiceWorkerRegistration {
script_url: Url,
scope: String,
container: &Controllable) -> Root<ServiceWorkerRegistration> {
let active_worker = ServiceWorker::init_service_worker(global, script_url, true);
let active_worker = ServiceWorker::install_serviceworker(global, script_url.clone(), true);
active_worker.set_transition_state(ServiceWorkerState::Installed);
container.set_controller(&*active_worker.clone());
reflect_dom_object(box ServiceWorkerRegistration::new_inherited(&*active_worker, scope), global, Wrap)
}
pub fn get_installed(&self) -> &ServiceWorker {
self.active.as_ref().unwrap()
}
pub fn create_scope_things(global: GlobalRef, script_url: Url) -> ScopeThings {
let worker_load_origin = WorkerScriptLoadOrigin {
referrer_url: None,
referrer_policy: None,
pipeline_id: Some(global.pipeline())
};
let worker_id = global.get_next_worker_id();
let init = prepare_workerscope_init(global, None);
ScopeThings {
script_url: script_url,
pipeline_id: global.pipeline(),
init: init,
worker_load_origin: worker_load_origin,
devtools_chan: global.devtools_chan(),
worker_id: worker_id
}
}
}
pub fn longest_prefix_match(stored_scope: &Url, potential_match: &Url) -> bool {
if stored_scope.origin() != potential_match.origin() {
return false;
}
let scope_chars = stored_scope.path().chars();
let matching_chars = potential_match.path().chars();
if scope_chars.count() > matching_chars.count() {
return false;
}
stored_scope.path().chars().zip(potential_match.path().chars()).all(|(scope, matched)| scope == matched)
}
impl ServiceWorkerRegistrationMethods for ServiceWorkerRegistration {