Handle media session callbacks before passing it on to the browser
ClosedPublic

Authored by broulik on Aug 11 2019, 12:41 PM.

Details

Summary

The Media Session API standard evolves quite fast, so there's new actions that we might be able to support that the browser itself doesn't know yet, for instance the "stop" action.
By registering the callback to ourselves before calling into the browser, we're still able to handle it in the extension even if not supported by the browser.

Test Plan

The following now works:

navigator.mediaSession.setActionHandler("stop", () => {
    console.log("stop player");
});

Clicked Stop in context menu of media controller applet, got the callback executed.
Previously an exception would be thrown when calling setActionHandler

Diff Detail

Repository
R856 Plasma Browser Integration
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik created this revision.Aug 11 2019, 12:41 PM
Restricted Application added a project: Plasma. · View Herald TranscriptAug 11 2019, 12:41 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
broulik requested review of this revision.Aug 11 2019, 12:41 PM
fvogt added inline comments.Aug 12 2019, 5:16 PM
extension/content-script.js
687

Why add this check and not just save the exception thrown from oldSetActionHandler for throwing later?

Otherwise the addon controls which browser functionality is accessible.

broulik updated this revision to Diff 63618.Aug 12 2019, 8:04 PM
broulik retitled this revision from Handle media session callbacks even when the requested one isn't supported by the browser to Handle media session callbacks before passing it on to the browser.
broulik edited the summary of this revision. (Show Details)
  • Register ourselves before passing on to the browser which may throw
fvogt accepted this revision.Aug 12 2019, 8:18 PM
This revision is now accepted and ready to land.Aug 12 2019, 8:18 PM
This revision was automatically updated to reflect the committed changes.