aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/config/opts.rs10
-rw-r--r--components/devtools/lib.rs15
-rw-r--r--components/embedder_traits/lib.rs3
-rw-r--r--ports/glutin/browser.rs6
-rw-r--r--ports/libmlservo/src/lib.rs7
-rw-r--r--ports/libsimpleservo/api/src/lib.rs5
-rw-r--r--ports/libsimpleservo/capi/src/lib.rs22
-rw-r--r--ports/libsimpleservo/jniapi/src/lib.rs7
-rw-r--r--support/hololens/ServoApp/ServoControl/Servo.cpp6
-rw-r--r--support/hololens/ServoApp/ServoControl/Servo.h1
10 files changed, 73 insertions, 9 deletions
diff --git a/components/config/opts.rs b/components/config/opts.rs
index 9bdd7bc9061..796bd7d6b96 100644
--- a/components/config/opts.rs
+++ b/components/config/opts.rs
@@ -653,12 +653,7 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
"Start remote debugger server on port",
"2794",
);
- opts.optflagopt(
- "",
- "devtools",
- "Start remote devtools server on port",
- "6000",
- );
+ opts.optflagopt("", "devtools", "Start remote devtools server on port", "0");
opts.optflagopt(
"",
"webdriver",
@@ -886,7 +881,8 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
})
});
- let devtools_port = opt_match.opt_default("devtools", "6000").map(|port| {
+ // Set default port 0 for a random port to be selected.
+ let devtools_port = opt_match.opt_default("devtools", "0").map(|port| {
port.parse()
.unwrap_or_else(|err| args_fail(&format!("Error parsing option: --devtools ({})", err)))
});
diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs
index a33294f078f..661d6ac94e1 100644
--- a/components/devtools/lib.rs
+++ b/components/devtools/lib.rs
@@ -154,7 +154,20 @@ fn run_server(
port: u16,
embedder: EmbedderProxy,
) {
- let listener = TcpListener::bind(&("0.0.0.0", port)).unwrap();
+ let bound = TcpListener::bind(&("0.0.0.0", port)).ok().and_then(|l| {
+ l.local_addr()
+ .map(|addr| addr.port())
+ .ok()
+ .map(|port| (l, port))
+ });
+
+ let port = bound.as_ref().map(|(_, port)| *port).ok_or(());
+ embedder.send((None, EmbedderMsg::OnDevtoolsStarted(port)));
+
+ let listener = match bound {
+ Some((l, _)) => l,
+ None => return,
+ };
let mut registry = ActorRegistry::new();
diff --git a/components/embedder_traits/lib.rs b/components/embedder_traits/lib.rs
index cacaf80ca50..45fa6e1d7b4 100644
--- a/components/embedder_traits/lib.rs
+++ b/components/embedder_traits/lib.rs
@@ -198,6 +198,8 @@ pub enum EmbedderMsg {
/// Notifies the embedder about media session events
/// (i.e. when there is metadata for the active media session, playback state changes...).
MediaSessionEvent(MediaSessionEvent),
+ /// Report the status of Devtools Server
+ OnDevtoolsStarted(Result<u16, ()>),
}
impl Debug for EmbedderMsg {
@@ -232,6 +234,7 @@ impl Debug for EmbedderMsg {
EmbedderMsg::BrowserCreated(..) => write!(f, "BrowserCreated"),
EmbedderMsg::ReportProfile(..) => write!(f, "ReportProfile"),
EmbedderMsg::MediaSessionEvent(..) => write!(f, "MediaSessionEvent"),
+ EmbedderMsg::OnDevtoolsStarted(..) => write!(f, "OnDevtoolsStarted"),
}
}
}
diff --git a/ports/glutin/browser.rs b/ports/glutin/browser.rs
index c46b0bd8337..3aec703c8fc 100644
--- a/ports/glutin/browser.rs
+++ b/ports/glutin/browser.rs
@@ -515,6 +515,12 @@ where
debug!("MediaSessionEvent received");
// TODO(ferjm): MediaSession support for Glutin based browsers.
},
+ EmbedderMsg::OnDevtoolsStarted(port) => {
+ match port {
+ Ok(p) => info!("Devtools Server running on port {}", p),
+ Err(()) => error!("Error running devtools server"),
+ }
+ },
}
}
}
diff --git a/ports/libmlservo/src/lib.rs b/ports/libmlservo/src/lib.rs
index cd7c023e5c6..f2afb24f7ca 100644
--- a/ports/libmlservo/src/lib.rs
+++ b/ports/libmlservo/src/lib.rs
@@ -423,6 +423,13 @@ impl HostTrait for HostCallbacks {
}
fn set_clipboard_contents(&self, _contents: String) {}
+
+ fn on_devtools_started(&self, port: Result<u16, ()>) {
+ match port {
+ Ok(p) => info!("Devtools Server running on port {}", p),
+ Err(()) => error!("Error running Devtools server"),
+ }
+ }
}
pub struct ServoInstance {
diff --git a/ports/libsimpleservo/api/src/lib.rs b/ports/libsimpleservo/api/src/lib.rs
index 64eddcb40e2..98a2029d402 100644
--- a/ports/libsimpleservo/api/src/lib.rs
+++ b/ports/libsimpleservo/api/src/lib.rs
@@ -146,6 +146,8 @@ pub trait HostTrait {
fn on_media_session_playback_state_change(&self, state: MediaSessionPlaybackState);
/// Called when the media session position state is set.
fn on_media_session_set_position_state(&self, duration: f64, position: f64, playback_rate: f64);
+ /// Called when devtools server is started
+ fn on_devtools_started(&self, port: Result<u16, ()>);
}
pub struct ServoGlue {
@@ -670,6 +672,9 @@ impl ServoGlue {
),
};
},
+ EmbedderMsg::OnDevtoolsStarted(port) => {
+ self.callbacks.host_callbacks.on_devtools_started(port);
+ },
EmbedderMsg::Status(..) |
EmbedderMsg::SelectFiles(..) |
EmbedderMsg::MoveTo(..) |
diff --git a/ports/libsimpleservo/capi/src/lib.rs b/ports/libsimpleservo/capi/src/lib.rs
index b7fad2d95c6..2fd0e48fabe 100644
--- a/ports/libsimpleservo/capi/src/lib.rs
+++ b/ports/libsimpleservo/capi/src/lib.rs
@@ -23,7 +23,7 @@ use simpleservo::{
use std::ffi::{CStr, CString};
#[cfg(target_os = "windows")]
use std::mem;
-use std::os::raw::{c_char, c_void};
+use std::os::raw::{c_char, c_uint, c_void};
use std::panic::{self, UnwindSafe};
use std::slice;
use std::str::FromStr;
@@ -229,6 +229,7 @@ pub struct CHostCallbacks {
default: *const c_char,
trusted: bool,
) -> *const c_char,
+ pub on_devtools_started: extern "C" fn(result: CDevtoolsServerState, port: c_uint),
}
/// Servo options
@@ -286,6 +287,12 @@ pub enum CMediaSessionPlaybackState {
Paused,
}
+#[repr(C)]
+pub enum CDevtoolsServerState {
+ Started,
+ Error,
+}
+
impl From<MediaSessionPlaybackState> for CMediaSessionPlaybackState {
fn from(state: MediaSessionPlaybackState) -> Self {
match state {
@@ -854,4 +861,17 @@ impl HostTrait for HostCallbacks {
let contents_str = c_str.to_str().expect("Can't create str");
Some(contents_str.to_owned())
}
+
+ fn on_devtools_started(&self, port: Result<u16, ()>) {
+ match port {
+ Ok(p) => {
+ info!("Devtools Server running on port {}", p);
+ (self.0.on_devtools_started)(CDevtoolsServerState::Started, p.into());
+ },
+ Err(()) => {
+ error!("Error running devtools server");
+ (self.0.on_devtools_started)(CDevtoolsServerState::Error, 0);
+ },
+ }
+ }
}
diff --git a/ports/libsimpleservo/jniapi/src/lib.rs b/ports/libsimpleservo/jniapi/src/lib.rs
index 9a7a6b80dd9..ff328b79d78 100644
--- a/ports/libsimpleservo/jniapi/src/lib.rs
+++ b/ports/libsimpleservo/jniapi/src/lib.rs
@@ -603,6 +603,13 @@ impl HostTrait for HostCallbacks {
)
.unwrap();
}
+
+ fn on_devtools_started(&self, port: Result<u16, ()>) {
+ match port {
+ Ok(p) => info!("Devtools Server running on port {}", p),
+ Err(()) => error!("Error running devtools server"),
+ }
+ }
}
fn initialize_android_glue(env: &JNIEnv, activity: JObject) {
diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp
index 0db1bb93032..d2d04c6fa3e 100644
--- a/support/hololens/ServoApp/ServoControl/Servo.cpp
+++ b/support/hololens/ServoApp/ServoControl/Servo.cpp
@@ -87,6 +87,11 @@ const char *prompt_input(const char *message, const char *default,
}
}
+void on_devtools_started(Servo::DevtoolsServerState result,
+ const unsigned int port) {
+ // FIXME
+}
+
Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
float dpi, ServoDelegate &aDelegate)
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
@@ -147,6 +152,7 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
c.prompt_ok_cancel = &prompt_ok_cancel;
c.prompt_yes_no = &prompt_yes_no;
c.prompt_input = &prompt_input;
+ c.on_devtools_started = &on_devtools_started;
capi::register_panic_handler(&on_panic);
diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h
index f27145ee482..6369a05364c 100644
--- a/support/hololens/ServoApp/ServoControl/Servo.h
+++ b/support/hololens/ServoApp/ServoControl/Servo.h
@@ -31,6 +31,7 @@ public:
typedef capi::CPromptResult PromptResult;
typedef capi::CMediaSessionActionType MediaSessionActionType;
typedef capi::CMediaSessionPlaybackState MediaSessionPlaybackState;
+ typedef capi::CDevtoolsServerState DevtoolsServerState;
void PerformUpdates() { capi::perform_updates(); }
void DeInit() { capi::deinit(); }