Skip to content

Commit

Permalink
Auto merge of servo#21170 - gterzian:use_remote_event_task_source_for…
Browse files Browse the repository at this point in the history
…_eventsource, r=jdm

Use remote-event task source in EventSource

<!-- Please describe your changes on the following line: -->
Follow up on servo#21126, this again 'changes nothing', but will be useful for servo#21114 in the context of servo#21111.

Trying to break up work into smaller PR's ;)

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix servo#21112 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21170)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Jul 14, 2018
2 parents 3961e8d + baef63b commit 8eb2a53
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 8 deletions.
11 changes: 5 additions & 6 deletions components/script/dom/eventsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl EventSourceContext {
let global = event_source.global();
let event_source = self.event_source.clone();
// FIXME(nox): Why are errors silenced here?
let _ = global.networking_task_source().queue(
let _ = global.remote_event_task_source().queue(
task!(announce_the_event_source_connection: move || {
let event_source = event_source.root();
if event_source.ready_state.get() != ReadyState::Closed {
Expand All @@ -121,7 +121,7 @@ impl EventSourceContext {
let global = event_source.global();
let event_source = self.event_source.clone();
// FIXME(nox): Why are errors silenced here?
let _ = global.networking_task_source().queue(
let _ = global.remote_event_task_source().queue(
task!(fail_the_event_source_connection: move || {
let event_source = event_source.root();
if event_source.ready_state.get() != ReadyState::Closed {
Expand All @@ -145,7 +145,7 @@ impl EventSourceContext {
let action_sender = self.action_sender.clone();
let global = event_source.global();
// FIXME(nox): Why are errors silenced here?
let _ = global.networking_task_source().queue(
let _ = global.remote_event_task_source().queue(
task!(reestablish_the_event_source_onnection: move || {
let event_source = trusted_event_source.root();

Expand Down Expand Up @@ -242,7 +242,7 @@ impl EventSourceContext {
let event_source = self.event_source.clone();
let event = Trusted::new(&*event);
// FIXME(nox): Why are errors silenced here?
let _ = global.networking_task_source().queue(
let _ = global.remote_event_task_source().queue(
task!(dispatch_the_event_source_event: move || {
let event_source = event_source.root();
if event_source.ready_state.get() != ReadyState::Closed {
Expand Down Expand Up @@ -423,6 +423,7 @@ impl EventSource {
self.request.borrow().clone().unwrap()
}

// https://html.spec.whatwg.org/multipage/#dom-eventsource
pub fn Constructor(global: &GlobalScope,
url: DOMString,
event_source_init: &EventSourceInit) -> Fallible<DomRoot<EventSource>> {
Expand Down Expand Up @@ -482,8 +483,6 @@ impl EventSource {
data: String::new(),
last_event_id: String::new(),
};
// TODO: use the "remote event task source", and canceller.
// https://html.spec.whatwg.org/multipage/#remote-event-task-source
let listener = NetworkListener {
context: Arc::new(Mutex::new(context)),
task_source: global.networking_task_source(),
Expand Down
15 changes: 14 additions & 1 deletion components/script/dom/globalscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use task_source::TaskSourceName;
use task_source::file_reading::FileReadingTaskSource;
use task_source::networking::NetworkingTaskSource;
use task_source::performance_timeline::PerformanceTimelineTaskSource;
use task_source::remote_event::RemoteEventTaskSource;
use time::{Timespec, get_time};
use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle};
use timers::{OneshotTimers, TimerCallback};
Expand Down Expand Up @@ -390,7 +391,7 @@ impl GlobalScope {
}

/// `ScriptChan` to send messages to the networking task source of
/// this of this global scope.
/// this global scope.
pub fn networking_task_source(&self) -> NetworkingTaskSource {
if let Some(window) = self.downcast::<Window>() {
return window.networking_task_source();
Expand All @@ -401,6 +402,18 @@ impl GlobalScope {
unreachable!();
}

/// `ScriptChan` to send messages to the remote-event task source of
/// this global scope.
pub fn remote_event_task_source(&self) -> RemoteEventTaskSource {
if let Some(window) = self.downcast::<Window>() {
return window.remote_event_task_source();
}
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
return worker.remote_event_task_source();
}
unreachable!();
}

/// Evaluate JS code on this global scope.
pub fn evaluate_js_on_global_with_result(
&self, code: &str, rval: MutableHandleValue) -> bool {
Expand Down
9 changes: 9 additions & 0 deletions components/script/dom/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ use task_source::file_reading::FileReadingTaskSource;
use task_source::history_traversal::HistoryTraversalTaskSource;
use task_source::networking::NetworkingTaskSource;
use task_source::performance_timeline::PerformanceTimelineTaskSource;
use task_source::remote_event::RemoteEventTaskSource;
use task_source::user_interaction::UserInteractionTaskSource;
use time;
use timers::{IsInterval, TimerCallback};
Expand Down Expand Up @@ -172,6 +173,8 @@ pub struct Window {
file_reading_task_source: FileReadingTaskSource,
#[ignore_malloc_size_of = "task sources are hard"]
performance_timeline_task_source: PerformanceTimelineTaskSource,
#[ignore_malloc_size_of = "task sources are hard"]
remote_event_task_source: RemoteEventTaskSource,
navigator: MutNullableDom<Navigator>,
#[ignore_malloc_size_of = "Arc"]
image_cache: Arc<ImageCache>,
Expand Down Expand Up @@ -358,6 +361,10 @@ impl Window {
self.performance_timeline_task_source.clone()
}

pub fn remote_event_task_source(&self) -> RemoteEventTaskSource {
self.remote_event_task_source.clone()
}

pub fn main_thread_script_chan(&self) -> &Sender<MainThreadScriptMsg> {
&self.script_chan.0
}
Expand Down Expand Up @@ -1798,6 +1805,7 @@ impl Window {
history_traversal_task_source: HistoryTraversalTaskSource,
file_reading_task_source: FileReadingTaskSource,
performance_timeline_task_source: PerformanceTimelineTaskSource,
remote_event_task_source: RemoteEventTaskSource,
image_cache_chan: Sender<ImageCacheMsg>,
image_cache: Arc<ImageCache>,
resource_threads: ResourceThreads,
Expand Down Expand Up @@ -1850,6 +1858,7 @@ impl Window {
history_traversal_task_source,
file_reading_task_source,
performance_timeline_task_source,
remote_event_task_source,
image_cache_chan,
image_cache,
navigator: Default::default(),
Expand Down
5 changes: 5 additions & 0 deletions components/script/dom/workerglobalscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use task::TaskCanceller;
use task_source::file_reading::FileReadingTaskSource;
use task_source::networking::NetworkingTaskSource;
use task_source::performance_timeline::PerformanceTimelineTaskSource;
use task_source::remote_event::RemoteEventTaskSource;
use time::precise_time_ns;
use timers::{IsInterval, TimerCallback};

Expand Down Expand Up @@ -385,6 +386,10 @@ impl WorkerGlobalScope {
PerformanceTimelineTaskSource(self.script_chan(), self.pipeline_id())
}

pub fn remote_event_task_source(&self) -> RemoteEventTaskSource {
RemoteEventTaskSource(self.script_chan(), self.pipeline_id())
}

pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {
let dedicated = self.downcast::<DedicatedWorkerGlobalScope>();
if let Some(dedicated) = dedicated {
Expand Down
9 changes: 9 additions & 0 deletions components/script/script_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ use task_source::file_reading::FileReadingTaskSource;
use task_source::history_traversal::HistoryTraversalTaskSource;
use task_source::networking::NetworkingTaskSource;
use task_source::performance_timeline::PerformanceTimelineTaskSource;
use task_source::remote_event::RemoteEventTaskSource;
use task_source::user_interaction::UserInteractionTaskSource;
use time::{get_time, precise_time_ns, Tm};
use url::Position;
Expand Down Expand Up @@ -436,6 +437,8 @@ pub struct ScriptThread {

performance_timeline_task_sender: Box<ScriptChan>,

remote_event_task_sender: Box<ScriptChan>,

/// A channel to hand out to threads that need to respond to a message from the script thread.
control_chan: IpcSender<ConstellationControlMsg>,

Expand Down Expand Up @@ -850,6 +853,7 @@ impl ScriptThread {
networking_task_sender: boxed_script_sender.clone(),
file_reading_task_sender: boxed_script_sender.clone(),
performance_timeline_task_sender: boxed_script_sender.clone(),
remote_event_task_sender: boxed_script_sender.clone(),

history_traversal_task_source: HistoryTraversalTaskSource(chan),

Expand Down Expand Up @@ -1805,6 +1809,10 @@ impl ScriptThread {
FileReadingTaskSource(self.file_reading_task_sender.clone(), pipeline_id)
}

pub fn remote_event_task_source(&self, pipeline_id: PipelineId) -> RemoteEventTaskSource {
RemoteEventTaskSource(self.remote_event_task_sender.clone(), pipeline_id)
}

/// Handles a request for the window title.
fn handle_get_title_msg(&self, pipeline_id: PipelineId) {
let document = match { self.documents.borrow().find_document(pipeline_id) } {
Expand Down Expand Up @@ -2113,6 +2121,7 @@ impl ScriptThread {
HistoryTraversalTaskSource(history_sender.clone()),
self.file_reading_task_source(incomplete.pipeline_id),
self.performance_timeline_task_source(incomplete.pipeline_id).clone(),
self.remote_event_task_source(incomplete.pipeline_id),
self.image_cache_channel.clone(),
self.image_cache.clone(),
self.resource_threads.clone(),
Expand Down
4 changes: 3 additions & 1 deletion components/script/task_source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod file_reading;
pub mod history_traversal;
pub mod networking;
pub mod performance_timeline;
pub mod remote_event;
pub mod user_interaction;

use dom::globalscope::GlobalScope;
Expand All @@ -26,7 +27,8 @@ pub enum TaskSourceName {
HistoryTraversal,
Networking,
PerformanceTimeline,
UserInteraction
UserInteraction,
RemoteEvent
}

impl TaskSourceName {
Expand Down
36 changes: 36 additions & 0 deletions components/script/task_source/remote_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use msg::constellation_msg::PipelineId;
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory};
use task::{TaskCanceller, TaskOnce};
use task_source::{TaskSource, TaskSourceName};

#[derive(JSTraceable)]
pub struct RemoteEventTaskSource(pub Box<ScriptChan + Send + 'static>, pub PipelineId);

impl Clone for RemoteEventTaskSource {
fn clone(&self) -> RemoteEventTaskSource {
RemoteEventTaskSource(self.0.clone(), self.1.clone())
}
}

impl TaskSource for RemoteEventTaskSource {
const NAME: TaskSourceName = TaskSourceName::RemoteEvent;

fn queue_with_canceller<T>(
&self,
task: T,
canceller: &TaskCanceller,
) -> Result<(), ()>
where
T: TaskOnce + 'static,
{
self.0.send(CommonScriptMsg::Task(
ScriptThreadEventCategory::NetworkEvent,
Box::new(canceller.wrap_task(task)),
Some(self.1),
))
}
}

0 comments on commit 8eb2a53

Please sign in to comment.