Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow suspending web content timers #4907

Closed
jdm opened this issue Feb 12, 2015 · 2 comments
Closed

Allow suspending web content timers #4907

jdm opened this issue Feb 12, 2015 · 2 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Feb 12, 2015

When navigating away from a page, it should be frozen. Part of that is suspending any existing timers (ie. setTimeout and setInterval), so the timer cancellation code in timers.rs should be expanded to include suspending and resuming them.

@pkondzior
Copy link
Contributor

@pkondzior pkondzior commented Feb 17, 2015

I'm willing to take my shot working on this task.

During the IRC conversation with @jdm I've managed to figure out whats could be the best approach for implementing suspend/resume functionality, this comments is brief technical approach for the change.

Changes:

  1. Add enum TimerState { Cancelled, Resumed, Suspended } into timers.rs
  2. Rename TimerHandle script_chan into control_chan and change it's type to Option<Sender<TimerState>>,
  3. TimerHandle cancel function should send TimerState::Cancelled value instead of ()
  4. Change TimerManager set_timeout_or_interval event loop to handle Resume and Suspend states properly: change order of handlers, timeout handle should be invoked only when task is Resumed
  5. Add resume and suspend methods to TimerHandle, send TimerState::Resumed and TimerState::Suspended accordingly through the channels
  6. Add TimerManager suspend and resume methods, each of these methods should iterate over all active_timers and invoke corresponding method on each of the TimerHandle
  7. In windows.rs add thaw and freeze methods to WindowHelpers, methods should map script_timers and invoke resume or suspend methods on each TimeManager accordingly

I'm still not sure how testing for newly introduced code should be done, any ideas ?

@jdm
Copy link
Member Author

@jdm jdm commented Feb 17, 2015

There are two ways to test your code - either integrate it with the session history, or add some temporary methods to Window.webidl that call WindowHelpers::freeze and WindowHelpers::thaw respectively, then write a page that sets some timers and calls window.freeze(). The timers shouldn't execute until window.thaw() is called.

If you want to try the session history integration, the back/forward code in http://mxr.mozilla.org/servo/source/components/compositing/constellation.rs#855 could use the script_chan in the pipeline to send a message to the ScriptTask that causes freeze or thaw to be called on the window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.