Support navigating browsing contexts in the devtools.

Break the association between pipelines and browsing context actors.
Now there is one browsing context actor per actual browsing context,
and individual actors keep track of known pipelines as necessary.
There is also one console/performance/timeline/inspector/etc. actor
per browsing context.

This also centralizes more information in the browsing context actor.
Rather than duplicating state for the active pipeline in actors that
need to use it, each actor now remembers the name of its associated
browsing context actor and obtains that state whenever it's necessary.
This commit is contained in:
Josh Matthews 2020-04-25 12:21:18 -04:00
parent 0540c4a284
commit 7c48644cad
9 changed files with 348 additions and 184 deletions

View file

@ -8,10 +8,22 @@
//! Supports dynamic attaching and detaching which control notifications of navigation, etc.
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::actors::console::ConsoleActor;
use crate::actors::emulation::EmulationActor;
use crate::actors::inspector::InspectorActor;
use crate::actors::performance::PerformanceActor;
use crate::actors::profiler::ProfilerActor;
use crate::actors::root::RootActor;
use crate::actors::stylesheets::StyleSheetsActor;
use crate::actors::thread::ThreadActor;
use crate::actors::timeline::TimelineActor;
use crate::protocol::JsonPacketStream;
use devtools_traits::DevtoolScriptControlMsg::{self, WantsLiveNotifications};
use devtools_traits::DevtoolsPageInfo;
use devtools_traits::NavigationState;
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use serde_json::{Map, Value};
use std::cell::{Cell, RefCell};
use std::net::TcpStream;
#[derive(Serialize)]
@ -118,6 +130,10 @@ pub struct BrowsingContextActor {
pub performance: String,
pub styleSheets: String,
pub thread: String,
pub streams: RefCell<Vec<TcpStream>>,
pub browsing_context_id: BrowsingContextId,
pub active_pipeline: Cell<PipelineId>,
pub script_chan: IpcSender<DevtoolScriptControlMsg>,
}
impl Actor for BrowsingContextActor {
@ -127,7 +143,7 @@ impl Actor for BrowsingContextActor {
fn handle_message(
&self,
registry: &ActorRegistry,
_registry: &ActorRegistry,
msg_type: &str,
msg: &Map<String, Value>,
stream: &mut TcpStream,
@ -137,10 +153,9 @@ impl Actor for BrowsingContextActor {
if let Some(options) = msg.get("options").and_then(|o| o.as_object()) {
if let Some(val) = options.get("performReload") {
if val.as_bool().unwrap_or(false) {
let console_actor = registry.find::<ConsoleActor>(&self.console);
let _ = console_actor
let _ = self
.script_chan
.send(DevtoolScriptControlMsg::Reload(console_actor.pipeline));
.send(DevtoolScriptControlMsg::Reload(self.active_pipeline.get()));
}
}
}
@ -165,32 +180,25 @@ impl Actor for BrowsingContextActor {
watchpoints: false,
},
};
let console_actor = registry.find::<ConsoleActor>(&self.console);
console_actor
.streams
.borrow_mut()
.push(stream.try_clone().unwrap());
self.streams.borrow_mut().push(stream.try_clone().unwrap());
stream.write_json_packet(&msg);
console_actor
.script_chan
.send(WantsLiveNotifications(console_actor.pipeline, true))
self.script_chan
.send(WantsLiveNotifications(self.active_pipeline.get(), true))
.unwrap();
ActorMessageStatus::Processed
},
//FIXME: The current implementation won't work for multiple connections. Need to ensure 105
//FIXME: The current implementation won't work for multiple connections. Need to ensure
// that the correct stream is removed.
"detach" => {
let msg = BrowsingContextDetachedReply {
from: self.name(),
type_: "detached".to_owned(),
};
let console_actor = registry.find::<ConsoleActor>(&self.console);
console_actor.streams.borrow_mut().pop();
self.streams.borrow_mut().pop();
stream.write_json_packet(&msg);
console_actor
.script_chan
.send(WantsLiveNotifications(console_actor.pipeline, false))
self.script_chan
.send(WantsLiveNotifications(self.active_pipeline.get(), false))
.unwrap();
ActorMessageStatus::Processed
},
@ -224,6 +232,70 @@ impl Actor for BrowsingContextActor {
}
impl BrowsingContextActor {
pub(crate) fn new(
console: String,
id: BrowsingContextId,
page_info: DevtoolsPageInfo,
pipeline: PipelineId,
script_sender: IpcSender<DevtoolScriptControlMsg>,
actors: &mut ActorRegistry,
) -> BrowsingContextActor {
let emulation = EmulationActor::new(actors.new_name("emulation"));
let name = actors.new_name("target");
let inspector = InspectorActor {
name: actors.new_name("inspector"),
walker: RefCell::new(None),
pageStyle: RefCell::new(None),
highlighter: RefCell::new(None),
script_chan: script_sender.clone(),
browsing_context: name.clone(),
};
let timeline =
TimelineActor::new(actors.new_name("timeline"), pipeline, script_sender.clone());
let profiler = ProfilerActor::new(actors.new_name("profiler"));
let performance = PerformanceActor::new(actors.new_name("performance"));
// the strange switch between styleSheets and stylesheets is due
// to an inconsistency in devtools. See Bug #1498893 in bugzilla
let styleSheets = StyleSheetsActor::new(actors.new_name("stylesheets"));
let thread = ThreadActor::new(actors.new_name("context"));
let DevtoolsPageInfo { title, url } = page_info;
let target = BrowsingContextActor {
name: name,
script_chan: script_sender,
title: String::from(title),
url: url.into_string(),
console: console,
emulation: emulation.name(),
inspector: inspector.name(),
timeline: timeline.name(),
profiler: profiler.name(),
performance: performance.name(),
styleSheets: styleSheets.name(),
thread: thread.name(),
streams: RefCell::new(Vec::new()),
browsing_context_id: id,
active_pipeline: Cell::new(pipeline),
};
actors.register(Box::new(emulation));
actors.register(Box::new(inspector));
actors.register(Box::new(timeline));
actors.register(Box::new(profiler));
actors.register(Box::new(performance));
actors.register(Box::new(styleSheets));
actors.register(Box::new(thread));
let root = actors.find_mut::<RootActor>("root");
root.tabs.push(target.name.clone());
target
}
pub fn encodable(&self) -> BrowsingContextActorMsg {
BrowsingContextActorMsg {
actor: self.name(),
@ -232,8 +304,10 @@ impl BrowsingContextActor {
},
title: self.title.clone(),
url: self.url.clone(),
browsingContextId: 0, //FIXME should come from constellation
outerWindowID: 0, //FIXME: this should probably be the pipeline id
//FIXME: shouldn't ignore pipeline namespace field
browsingContextId: self.browsing_context_id.index.0.get(),
//FIXME: shouldn't ignore pipeline namespace field
outerWindowID: self.active_pipeline.get().index.0.get(),
consoleActor: self.console.clone(),
emulationActor: self.emulation.clone(),
inspectorActor: self.inspector.clone(),
@ -243,4 +317,40 @@ impl BrowsingContextActor {
styleSheetsActor: self.styleSheets.clone(),
}
}
pub(crate) fn navigate(&self, state: NavigationState) {
let (pipeline, title, url, state) = match state {
NavigationState::Start(url) => (None, None, url, "start"),
NavigationState::Stop(pipeline, info) => {
(Some(pipeline), Some(info.title), info.url, "stop")
},
};
if let Some(p) = pipeline {
self.active_pipeline.set(p);
}
let msg = TabNavigated {
from: self.name(),
type_: "tabNavigated".to_owned(),
url: url.as_str().to_owned(),
title: title,
nativeConsoleAPI: true,
state: state.to_owned(),
isFrameSwitching: false,
};
for stream in &mut *self.streams.borrow_mut() {
stream.write_json_packet(&msg);
}
}
}
#[derive(Serialize)]
struct TabNavigated {
from: String,
#[serde(rename = "type")]
type_: String,
url: String,
title: Option<String>,
nativeConsoleAPI: bool,
state: String,
isFrameSwitching: bool,
}