Bug 1639337 - Factor out the macOS status bar WebRTC indicator into a reusable class. r=pbz

Differential Revision: https://phabricator.services.mozilla.com/D76388
This commit is contained in:
Mike Conley
2020-05-26 18:00:36 +00:00
parent ffd45db5d7
commit 3f869ebd2a
2 changed files with 208 additions and 112 deletions

View File

@@ -14,6 +14,18 @@ ChromeUtils.defineModuleGetter(
"resource:///modules/SitePermissions.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"AppConstants",
"resource://gre/modules/AppConstants.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"MacOSWebRTCStatusbarIndicator",
"resource:///modules/webrtcUI.jsm"
);
XPCOMUtils.defineLazyServiceGetter(
this,
"gScreenManager",
@@ -35,6 +47,7 @@ function updateIndicatorState() {
const WebRTCIndicator = {
init(event) {
addEventListener("load", this);
addEventListener("unload", this);
// If the user customizes the position of the indicator, we will
// not try to re-center it on the primary display after indicator
@@ -43,6 +56,10 @@ const WebRTCIndicator = {
this.updatingIndicatorState = false;
this.loaded = false;
if (AppConstants.platform == "macosx") {
this.macOSIndicator = new MacOSWebRTCStatusbarIndicator();
}
},
/**
@@ -50,6 +67,9 @@ const WebRTCIndicator = {
* update itself when sharing states have changed.
*/
updateIndicatorState(initialLayout = false) {
if (this.macOSIndicator) {
this.macOSIndicator.updateIndicatorState();
}
// It's possible that we were called externally before the indicator
// finished loading. If so, then bail out - we're going to call
// updateIndicatorState ourselves automatically once the load
@@ -167,7 +187,11 @@ const WebRTCIndicator = {
handleEvent(event) {
switch (event.type) {
case "load": {
this.onLoad(event);
this.onLoad();
break;
}
case "unload": {
this.onUnload();
break;
}
case "click": {
@@ -202,9 +226,16 @@ const WebRTCIndicator = {
cancelable: true,
});
document.documentElement.dispatchEvent(ev);
this.loaded = true;
},
onUnload() {
if (this.macOSIndicator) {
this.macOSIndicator.close();
}
},
onClick(event) {
switch (event.target.id) {
case "stop-sharing-screen": {