Allow embedder to bypass devtools prompt

This commit is contained in:
Paul Rouget 2020-06-22 11:06:34 +02:00
parent 3f999ce785
commit 8cf2f14baa
16 changed files with 83 additions and 35 deletions

View file

@ -146,7 +146,7 @@ pub trait HostTrait {
/// 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, ()>);
fn on_devtools_started(&self, port: Result<u16, ()>, token: String);
}
pub struct ServoGlue {
@ -751,8 +751,10 @@ impl ServoGlue {
),
};
},
EmbedderMsg::OnDevtoolsStarted(port) => {
self.callbacks.host_callbacks.on_devtools_started(port);
EmbedderMsg::OnDevtoolsStarted(port, token) => {
self.callbacks
.host_callbacks
.on_devtools_started(port, token);
},
EmbedderMsg::Status(..) |
EmbedderMsg::SelectFiles(..) |

View file

@ -227,7 +227,8 @@ pub struct CHostCallbacks {
default: *const c_char,
trusted: bool,
) -> *const c_char,
pub on_devtools_started: extern "C" fn(result: CDevtoolsServerState, port: c_uint),
pub on_devtools_started:
extern "C" fn(result: CDevtoolsServerState, port: c_uint, token: *const c_char),
pub show_context_menu:
extern "C" fn(title: *const c_char, items_list: *const *const c_char, items_size: u32),
pub on_log_output: extern "C" fn(buffer: *const c_char, buffer_length: u32),
@ -883,15 +884,20 @@ impl HostTrait for HostCallbacks {
Some(contents_str.to_owned())
}
fn on_devtools_started(&self, port: Result<u16, ()>) {
fn on_devtools_started(&self, port: Result<u16, ()>, token: String) {
let token = CString::new(token).expect("Can't create string");
match port {
Ok(p) => {
info!("Devtools Server running on port {}", p);
(self.0.on_devtools_started)(CDevtoolsServerState::Started, p.into());
(self.0.on_devtools_started)(
CDevtoolsServerState::Started,
p.into(),
token.as_ptr(),
);
},
Err(()) => {
error!("Error running devtools server");
(self.0.on_devtools_started)(CDevtoolsServerState::Error, 0);
(self.0.on_devtools_started)(CDevtoolsServerState::Error, 0, token.as_ptr());
},
}
}

View file

@ -515,7 +515,7 @@ where
debug!("MediaSessionEvent received");
// TODO(ferjm): MediaSession support for winit based browsers.
},
EmbedderMsg::OnDevtoolsStarted(port) => {
EmbedderMsg::OnDevtoolsStarted(port, _token) => {
match port {
Ok(p) => info!("Devtools Server running on port {}", p),
Err(()) => error!("Error running devtools server"),