Skip to content

Commit

Permalink
Suspend/resume media activity based on document activity
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Sep 19, 2019
1 parent 51ed44c commit d7bebce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions components/script/dom/document.rs
Expand Up @@ -145,6 +145,7 @@ use script_traits::{
use servo_arc::Arc;
use servo_atoms::Atom;
use servo_config::pref;
use servo_media::{ClientContextId, ServoMedia};
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use std::borrow::ToOwned;
use std::cell::{Cell, Ref, RefMut};
Expand Down Expand Up @@ -499,12 +500,17 @@ impl Document {
// Set the document's activity level, reflow if necessary, and suspend or resume timers.
if activity != self.activity.get() {
self.activity.set(activity);
let media = ServoMedia::get().unwrap();
let pipeline_id = self.window().pipeline_id().expect("doc with no pipeline");
let client_context_id =
ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
if activity == DocumentActivity::FullyActive {
self.title_changed();
self.dirty_all_nodes();
self.window()
.reflow(ReflowGoal::Full, ReflowReason::CachedPageNeededReflow);
self.window().resume();
media.resume(&client_context_id);
// html.spec.whatwg.org/multipage/#history-traversal
// Step 4.6
if self.ready_state.get() == DocumentReadyState::Complete {
Expand Down Expand Up @@ -544,6 +550,7 @@ impl Document {
}
} else {
self.window().suspend();
media.suspend(&client_context_id);
}
}
}
Expand Down

0 comments on commit d7bebce

Please sign in to comment.