Changeset View
Changeset View
Standalone View
Standalone View
extension/content-script.js
Show First 20 Lines • Show All 677 Lines • ▼ Show 20 Line(s) | 658 | function() { | |||
---|---|---|---|---|---|
678 | if (!navigator.mediaSession) { | 678 | if (!navigator.mediaSession) { | ||
679 | navigator.mediaSession = {}; | 679 | navigator.mediaSession = {}; | ||
680 | } | 680 | } | ||
681 | 681 | | |||
682 | var noop = function() { }; | 682 | var noop = function() { }; | ||
683 | 683 | | |||
684 | var oldSetActionHandler = navigator.mediaSession.setActionHandler || noop; | 684 | var oldSetActionHandler = navigator.mediaSession.setActionHandler || noop; | ||
685 | navigator.mediaSession.setActionHandler = function (name, cb) { | 685 | navigator.mediaSession.setActionHandler = function (name, cb) { | ||
686 | // Call the original native implementation | | |||
687 | // "call()" is needed as the real setActionHandler is a class member | | |||
688 | // and calling it directly is illegal as it lacks the context | | |||
689 | // We'll register the callback for ourself after this since it may | | |||
690 | // throw for unsupported callback names. | | |||
691 | var ret = oldSetActionHandler.call(navigator.mediaSession, name, cb); | | |||
692 | | ||||
693 | if (cb) { | 686 | if (cb) { | ||
694 | ${mediaSessionsClassName}.callbacks[name] = cb; | 687 | ${mediaSessionsClassName}.callbacks[name] = cb; | ||
fvogt: Why add this check and not just save the exception thrown from `oldSetActionHandler` for… | |||||
695 | } else { | 688 | } else { | ||
696 | delete ${mediaSessionsClassName}.callbacks[name]; | 689 | delete ${mediaSessionsClassName}.callbacks[name]; | ||
697 | } | 690 | } | ||
698 | ${mediaSessionsClassName}.sendMessage("callbacks", Object.keys(${mediaSessionsClassName}.callbacks)); | 691 | ${mediaSessionsClassName}.sendMessage("callbacks", Object.keys(${mediaSessionsClassName}.callbacks)); | ||
699 | 692 | | |||
700 | return ret; | 693 | // Call the original native implementation | ||
694 | // "call()" is needed as the real setActionHandler is a class member | ||||
695 | // and calling it directly is illegal as it lacks the context | ||||
696 | // This may throw for unsupported actions but we registered the callback | ||||
697 | // ourselves before | ||||
698 | return oldSetActionHandler.call(navigator.mediaSession, name, cb); | ||||
701 | }; | 699 | }; | ||
702 | 700 | | |||
703 | Object.defineProperty(navigator.mediaSession, "metadata", { | 701 | Object.defineProperty(navigator.mediaSession, "metadata", { | ||
704 | get: function() { return ${mediaSessionsClassName}.metadata; }, | 702 | get: function() { return ${mediaSessionsClassName}.metadata; }, | ||
705 | set: function(newValue) { | 703 | set: function(newValue) { | ||
706 | ${mediaSessionsClassName}.metadata = newValue; | 704 | ${mediaSessionsClassName}.metadata = newValue; | ||
707 | 705 | | |||
708 | // MediaMetadata is not a regular Object so we cannot just JSON.stringify it | 706 | // MediaMetadata is not a regular Object so we cannot just JSON.stringify it | ||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |
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.