allow for a service worker network mediator per origin

This commit is contained in:
Gregory Terzian 2020-04-04 13:19:43 +08:00
parent db217d5575
commit 1e017a7082
4 changed files with 12 additions and 24 deletions

View file

@ -16,13 +16,6 @@ mod constellation;
mod event_loop;
mod network_listener;
mod pipeline;
#[cfg(all(
not(target_os = "windows"),
not(target_os = "ios"),
not(target_os = "android"),
not(target_arch = "arm"),
not(target_arch = "aarch64")
))]
mod sandboxing;
mod serviceworker;
mod session_history;
@ -32,11 +25,4 @@ pub use crate::constellation::{
Constellation, FromCompositorLogger, FromScriptLogger, InitialConstellationState,
};
pub use crate::pipeline::UnprivilegedPipelineContent;
#[cfg(all(
not(target_os = "windows"),
not(target_os = "ios"),
not(target_os = "android"),
not(target_arch = "arm"),
not(target_arch = "aarch64")
))]
pub use crate::sandboxing::{content_process_sandbox_profile, UnprivilegedContent};

View file

@ -39,7 +39,7 @@ use profile_traits::mem::{Report, ReportKind, ReportsChan};
use profile_traits::time::ProfilerChan;
use serde::{Deserialize, Serialize};
use servo_arc::Arc as ServoArc;
use servo_url::ServoUrl;
use servo_url::{ImmutableOrigin, ServoUrl};
use std::borrow::{Cow, ToOwned};
use std::collections::HashMap;
use std::fs::{self, File};
@ -299,8 +299,10 @@ impl ResourceChannelManager {
.send(cookie_jar.cookies_for_url(&url, source))
.unwrap();
},
CoreResourceMsg::NetworkMediator(mediator_chan) => {
self.resource_manager.swmanager_chan = Some(mediator_chan)
CoreResourceMsg::NetworkMediator(mediator_chan, origin) => {
self.resource_manager
.sw_managers
.insert(origin, mediator_chan);
},
CoreResourceMsg::GetCookiesDataForUrl(url, consumer, source) => {
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
@ -431,7 +433,7 @@ pub struct AuthCache {
pub struct CoreResourceManager {
user_agent: Cow<'static, str>,
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
swmanager_chan: Option<IpcSender<CustomResponseMediator>>,
sw_managers: HashMap<ImmutableOrigin, IpcSender<CustomResponseMediator>>,
filemanager: FileManager,
thread_pool: Arc<CoreResourceThreadPool>,
certificate_path: Option<String>,
@ -575,7 +577,7 @@ impl CoreResourceManager {
CoreResourceManager {
user_agent: user_agent,
devtools_chan: devtools_channel,
swmanager_chan: None,
sw_managers: Default::default(),
filemanager: FileManager::new(embedder_proxy, Arc::downgrade(&pool_handle)),
thread_pool: pool_handle,
certificate_path,

View file

@ -30,7 +30,7 @@ use ipc_channel::router::ROUTER;
use ipc_channel::Error as IpcError;
use mime::Mime;
use msg::constellation_msg::HistoryStateId;
use servo_url::ServoUrl;
use servo_url::{ImmutableOrigin, ServoUrl};
use time::precise_time_ns;
use webrender_api::ImageKey;
@ -423,8 +423,8 @@ pub enum CoreResourceMsg {
RemoveHistoryStates(Vec<HistoryStateId>),
/// Synchronization message solely for knowing the state of the ResourceChannelManager loop
Synchronize(IpcSender<()>),
/// Send the network sender in constellation to CoreResourceThread
NetworkMediator(IpcSender<CustomResponseMediator>),
/// Send the service worker network mediator for an origin to CoreResourceThread
NetworkMediator(IpcSender<CustomResponseMediator>, ImmutableOrigin),
/// Message forwarded to file manager's handler
ToFileManager(FileManagerThreadMsg),
/// Break the load handler loop, send a reply when done cleaning up local resources

View file

@ -192,7 +192,7 @@ impl ServiceWorkerManager {
}
impl ServiceWorkerManagerFactory for ServiceWorkerManager {
fn create(sw_senders: SWManagerSenders, _origin: ImmutableOrigin) {
fn create(sw_senders: SWManagerSenders, origin: ImmutableOrigin) {
let (resource_chan, resource_port) = ipc::channel().unwrap();
let SWManagerSenders {
@ -204,7 +204,7 @@ impl ServiceWorkerManagerFactory for ServiceWorkerManager {
let from_constellation = ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(receiver);
let resource_port = ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(resource_port);
let _ = resource_sender.send(CoreResourceMsg::NetworkMediator(resource_chan));
let _ = resource_sender.send(CoreResourceMsg::NetworkMediator(resource_chan, origin));
if thread::Builder::new()
.name("ServiceWorkerManager".to_owned())
.spawn(move || {