diff --git a/browser/actors/DecoderDoctorChild.jsm b/browser/actors/DecoderDoctorChild.jsm new file mode 100644 index 000000000000..c6816bcfd435 --- /dev/null +++ b/browser/actors/DecoderDoctorChild.jsm @@ -0,0 +1,32 @@ +/* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 sw=2 sts=2 et tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +var EXPORTED_SYMBOLS = ["DecoderDoctorChild"]; + +class DecoderDoctorChild extends JSWindowActorChild { + // Observes 'decoder-doctor-notification'. This actor handles most such notifications, but does not deal with notifications with the 'cannot-play' type, which is handled + // @param aSubject the nsPIDOMWindowInner associated with the notification. + // @param aTopic should be "decoder-doctor-notification". + // @param aData json data that contains analysis information from Decoder Doctor: + // - 'type' is the type of issue, it determines which text to show in the + // infobar. + // - 'isSolved' is true when the notification actually indicates the + // resolution of that issue, to be reported as telemetry. + // - 'decoderDoctorReportId' is the Decoder Doctor issue identifier, to be + // used here as key for the telemetry (counting infobar displays, + // "Learn how" buttons clicks, and resolutions) and for the prefs used + // to store at-issue formats. + // - 'formats' contains a comma-separated list of formats (or key systems) + // that suffer the issue. These are kept in a pref, which the backend + // uses to later find when an issue is resolved. + // - 'decodeIssue' is a description of the decode error/warning. + // - 'resourceURL' is the resource with the issue. + observe(aSubject, aTopic, aData) { + this.sendAsyncMessage("DecoderDoctor:Notification", aData); + } +} diff --git a/browser/base/content/browser-media.js b/browser/actors/DecoderDoctorParent.jsm similarity index 70% rename from browser/base/content/browser-media.js rename to browser/actors/DecoderDoctorParent.jsm index fac8e8d4277e..f692522722e4 100644 --- a/browser/base/content/browser-media.js +++ b/browser/actors/DecoderDoctorParent.jsm @@ -1,42 +1,59 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- - * This Source Code Form is subject to the terms of the Mozilla Public +/* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 sw=2 sts=2 et tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; -const TELEMETRY_DDSTAT_SHOWN = 0; -const TELEMETRY_DDSTAT_SHOWN_FIRST = 1; -const TELEMETRY_DDSTAT_CLICKED = 2; -const TELEMETRY_DDSTAT_CLICKED_FIRST = 3; -const TELEMETRY_DDSTAT_SOLVED = 4; +var EXPORTED_SYMBOLS = ["DecoderDoctorParent"]; -let gDecoderDoctorHandler = { +const { AppConstants } = ChromeUtils.import( + "resource://gre/modules/AppConstants.jsm" +); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); + +XPCOMUtils.defineLazyGetter(this, "gNavigatorBundle", function() { + return Services.strings.createBundle( + "chrome://browser/locale/browser.properties" + ); +}); + +class DecoderDoctorParent extends JSWindowActorParent { getLabelForNotificationBox(type) { if (type == "platform-decoder-not-found") { if (AppConstants.platform == "win") { - return gNavigatorBundle.getString("decoder.noHWAcceleration.message"); + return gNavigatorBundle.GetStringFromName( + "decoder.noHWAcceleration.message" + ); } if (AppConstants.platform == "linux") { - return gNavigatorBundle.getString("decoder.noCodecsLinux.message"); + return gNavigatorBundle.GetStringFromName( + "decoder.noCodecsLinux.message" + ); } } if (type == "cannot-initialize-pulseaudio") { - return gNavigatorBundle.getString("decoder.noPulseAudio.message"); + return gNavigatorBundle.GetStringFromName("decoder.noPulseAudio.message"); } if (type == "unsupported-libavcodec" && AppConstants.platform == "linux") { - return gNavigatorBundle.getString( + return gNavigatorBundle.GetStringFromName( "decoder.unsupportedLibavcodec.message" ); } if (type == "decode-error") { - return gNavigatorBundle.getString("decoder.decodeError.message"); + return gNavigatorBundle.GetStringFromName("decoder.decodeError.message"); } if (type == "decode-warning") { - return gNavigatorBundle.getString("decoder.decodeWarning.message"); + return gNavigatorBundle.GetStringFromName( + "decoder.decodeWarning.message" + ); } return ""; - }, + } getSumoForLearnHowButton(type) { if ( @@ -49,7 +66,7 @@ let gDecoderDoctorHandler = { return "fix-common-audio-and-video-issues"; } return ""; - }, + } getEndpointForReportIssueButton(type) { if (type == "decode-error" || type == "decode-warning") { @@ -59,20 +76,33 @@ let gDecoderDoctorHandler = { ); } return ""; - }, + } - receiveMessage({ target: browser, data: data }) { - let box = gBrowser.getNotificationBox(browser); + receiveMessage(aMessage) { + // The top level browsing context's embedding element should be a xul browser element. + let browser = this.browsingContext.top.embedderElement; + // The xul browser is owned by a window. + let window = browser?.ownerGlobal; + + if (!browser || !window) { + // We don't have a browser or window so bail! + return; + } + + let box = browser.getTabBrowser().getNotificationBox(browser); let notificationId = "decoder-doctor-notification"; if (box.getNotificationWithValue(notificationId)) { + // We already have a notification showing, bail. return; } let parsedData; try { - parsedData = JSON.parse(data); + parsedData = JSON.parse(aMessage.data); } catch (ex) { - Cu.reportError("Malformed Decoder Doctor message with data: " + data); + Cu.reportError( + "Malformed Decoder Doctor message with data: " + aMessage.data + ); return; } // parsedData (the result of parsing the incoming 'data' json string) @@ -104,7 +134,7 @@ let gDecoderDoctorHandler = { if (!/^\w+$/im.test(decoderDoctorReportId)) { return; } - let title = gDecoderDoctorHandler.getLabelForNotificationBox(type); + let title = this.getLabelForNotificationBox(type); if (!title) { return; } @@ -146,11 +176,13 @@ let gDecoderDoctorHandler = { } let buttons = []; - let sumo = gDecoderDoctorHandler.getSumoForLearnHowButton(type); + let sumo = this.getSumoForLearnHowButton(type); if (sumo) { buttons.push({ - label: gNavigatorBundle.getString("decoder.noCodecs.button"), - accessKey: gNavigatorBundle.getString("decoder.noCodecs.accesskey"), + label: gNavigatorBundle.GetStringFromName("decoder.noCodecs.button"), + accessKey: gNavigatorBundle.GetStringFromName( + "decoder.noCodecs.accesskey" + ), callback() { let clickedInPref = Services.prefs.getBoolPref( buttonClickedPref, @@ -163,17 +195,17 @@ let gDecoderDoctorHandler = { let baseURL = Services.urlFormatter.formatURLPref( "app.support.baseURL" ); - openTrustedLinkIn(baseURL + sumo, "tab"); + window.openTrustedLinkIn(baseURL + sumo, "tab"); }, }); } - let endpoint = gDecoderDoctorHandler.getEndpointForReportIssueButton( - type - ); + let endpoint = this.getEndpointForReportIssueButton(type); if (endpoint) { buttons.push({ - label: gNavigatorBundle.getString("decoder.decodeError.button"), - accessKey: gNavigatorBundle.getString( + label: gNavigatorBundle.GetStringFromName( + "decoder.decodeError.button" + ), + accessKey: gNavigatorBundle.GetStringFromName( "decoder.decodeError.accesskey" ), callback() { @@ -197,7 +229,7 @@ let gDecoderDoctorHandler = { } params.append("details", JSON.stringify(details)); - openTrustedLinkIn(endpoint + "?" + params.toString(), "tab"); + window.openTrustedLinkIn(endpoint + "?" + params.toString(), "tab"); }, }); } @@ -215,14 +247,5 @@ let gDecoderDoctorHandler = { Services.prefs.clearUserPref(formatsPref); Services.prefs.clearUserPref(buttonClickedPref); } - }, -}; - -window - .getGroupMessageManager("browsers") - .addMessageListener("DecoderDoctor:Notification", gDecoderDoctorHandler); -window.addEventListener("unload", function() { - window - .getGroupMessageManager("browsers") - .removeMessageListener("DecoderDoctor:Notification", gDecoderDoctorHandler); -}); + } +} diff --git a/browser/actors/moz.build b/browser/actors/moz.build index d957a93760df..749ce211d8c0 100644 --- a/browser/actors/moz.build +++ b/browser/actors/moz.build @@ -55,6 +55,8 @@ FINAL_TARGET_FILES.actors += [ 'ContentSearchParent.jsm', 'ContextMenuChild.jsm', 'ContextMenuParent.jsm', + 'DecoderDoctorChild.jsm', + 'DecoderDoctorParent.jsm', 'DOMFullscreenChild.jsm', 'DOMFullscreenParent.jsm', 'EncryptedMediaChild.jsm', diff --git a/browser/base/content/browser.xhtml b/browser/base/content/browser.xhtml index 965fb8b98b81..c208146cffc8 100644 --- a/browser/base/content/browser.xhtml +++ b/browser/base/content/browser.xhtml @@ -96,7 +96,6 @@ if (!AppConstants.MOZILLA_OFFICIAL) { Services.scriptloader.loadSubScript("chrome://browser/content/browser-development-helpers.js", this); } - Services.scriptloader.loadSubScript("chrome://browser/content/browser-media.js", this); Services.scriptloader.loadSubScript("chrome://browser/content/browser-pageActions.js", this); Services.scriptloader.loadSubScript("chrome://browser/content/browser-sidebar.js", this); Services.scriptloader.loadSubScript("chrome://browser/content/browser-tabsintitlebar.js", this); diff --git a/browser/base/content/moz.build b/browser/base/content/moz.build index 5ef1ed0909aa..8efe140ef0f7 100644 --- a/browser/base/content/moz.build +++ b/browser/base/content/moz.build @@ -139,9 +139,6 @@ with Files("browser-fullZoom.js"): with Files("browser-gestureSupport.js"): BUG_COMPONENT = ("Core", "Widget: Cocoa") -with Files("browser-media.js"): - BUG_COMPONENT = ("Core", "Audio/Video: Playback") - with Files("browser-pageActions.js"): BUG_COMPONENT = ("Firefox", "Toolbars and Customization") diff --git a/browser/base/content/test/performance/browser_startup_content.js b/browser/base/content/test/performance/browser_startup_content.js index 2dcceb876eee..df00da7e0dc2 100644 --- a/browser/base/content/test/performance/browser_startup_content.js +++ b/browser/base/content/test/performance/browser_startup_content.js @@ -67,7 +67,6 @@ const known_scripts = { ]), processScripts: new Set([ "chrome://global/content/process-content.js", - "resource:///modules/ContentObservers.js", "resource://gre/modules/extensionProcessScriptLoader.js", ]), }; diff --git a/browser/base/content/test/performance/browser_startup_content_subframe.js b/browser/base/content/test/performance/browser_startup_content_subframe.js index 6c27112f7ab4..f95a7075c8bd 100644 --- a/browser/base/content/test/performance/browser_startup_content_subframe.js +++ b/browser/base/content/test/performance/browser_startup_content_subframe.js @@ -60,7 +60,6 @@ const known_scripts = { ]), processScripts: new Set([ "chrome://global/content/process-content.js", - "resource:///modules/ContentObservers.js", "resource://gre/modules/extensionProcessScriptLoader.js", ]), }; diff --git a/browser/base/jar.mn b/browser/base/jar.mn index 5cf7af4f635d..fd5b25719019 100644 --- a/browser/base/jar.mn +++ b/browser/base/jar.mn @@ -48,7 +48,6 @@ browser.jar: content/browser/browser-fullScreenAndPointerLock.js (content/browser-fullScreenAndPointerLock.js) content/browser/browser-fullZoom.js (content/browser-fullZoom.js) content/browser/browser-gestureSupport.js (content/browser-gestureSupport.js) - content/browser/browser-media.js (content/browser-media.js) content/browser/browser-pageActions.js (content/browser-pageActions.js) content/browser/browser-places.js (content/browser-places.js) content/browser/browser-safebrowsing.js (content/browser-safebrowsing.js) diff --git a/browser/components/BrowserGlue.jsm b/browser/components/BrowserGlue.jsm index 9cc62d03f637..da5fdd7d0b2c 100644 --- a/browser/components/BrowserGlue.jsm +++ b/browser/components/BrowserGlue.jsm @@ -377,6 +377,20 @@ let JSWINDOWACTORS = { allFrames: true, }, + DecoderDoctor: { + parent: { + moduleURI: "resource:///actors/DecoderDoctorParent.jsm", + }, + + child: { + moduleURI: "resource:///actors/DecoderDoctorChild.jsm", + observers: ["decoder-doctor-notification"], + }, + + messageManagerGroups: ["browsers"], + allFrames: true, + }, + DOMFullscreen: { parent: { moduleURI: "resource:///actors/DOMFullscreenParent.jsm", diff --git a/browser/modules/ContentObservers.js b/browser/modules/ContentObservers.js deleted file mode 100644 index ae2718b5aca8..000000000000 --- a/browser/modules/ContentObservers.js +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * This process script is for small observers that we want to register - * once per content process, usually in order to forward content-based - * observer service notifications to the chrome process through - * message passing. Using a process script avoids having them in - * content.js and thereby registering N observers for N open tabs, - * which is bad for perf. - */ - -"use strict"; - -const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); - -var gDecoderDoctorObserver = function(subject, topic, data) { - let win = subject.top; - let mm = getMessageManagerForWindow(win); - if (mm) { - mm.sendAsyncMessage("DecoderDoctor:Notification", data); - } -}; - -function getMessageManagerForWindow(aContentWindow) { - return aContentWindow.docShell.messageManager; -} - -Services.obs.addObserver(gDecoderDoctorObserver, "decoder-doctor-notification"); diff --git a/browser/modules/moz.build b/browser/modules/moz.build index 6a8b14b684a7..e60199812cec 100644 --- a/browser/modules/moz.build +++ b/browser/modules/moz.build @@ -131,7 +131,6 @@ EXTRA_JS_MODULES += [ 'BrowserUsageTelemetry.jsm', 'BrowserWindowTracker.jsm', 'ContentCrashHandlers.jsm', - 'ContentObservers.js', 'Discovery.jsm', 'EveryWindow.jsm', 'ExtensionsUI.jsm', diff --git a/dom/media/doctor/DecoderDoctorDiagnostics.cpp b/dom/media/doctor/DecoderDoctorDiagnostics.cpp index 6fccc73ffd40..d2f20402088f 100644 --- a/dom/media/doctor/DecoderDoctorDiagnostics.cpp +++ b/dom/media/doctor/DecoderDoctorDiagnostics.cpp @@ -236,7 +236,8 @@ enum class ReportParam : uint8_t { }; struct NotificationAndReportStringId { - // Notification type, handled by browser-media.js. + // Notification type, handled by DecoderDoctorChild.jsm and + // DecoderDoctorParent.jsm. dom::DecoderDoctorNotificationType mNotificationType; // Console message id. Key in dom/locales/.../chrome/dom/dom.properties. const char* mReportStringId; diff --git a/toolkit/components/processsingleton/MainProcessSingleton.jsm b/toolkit/components/processsingleton/MainProcessSingleton.jsm index 6acbc10c9995..d1f1022cf866 100644 --- a/toolkit/components/processsingleton/MainProcessSingleton.jsm +++ b/toolkit/components/processsingleton/MainProcessSingleton.jsm @@ -35,10 +35,6 @@ MainProcessSingleton.prototype = { "chrome://global/content/process-content.js", true ); - Services.ppmm.loadProcessScript( - "resource:///modules/ContentObservers.js", - true - ); break; } diff --git a/tools/lint/eslint/modules.json b/tools/lint/eslint/modules.json index 8020c32bf4b4..849783fc4dce 100644 --- a/tools/lint/eslint/modules.json +++ b/tools/lint/eslint/modules.json @@ -38,7 +38,6 @@ "content-process.jsm": ["init"], "content.jsm": ["registerContentFrame"], "ContentCrashHandlers.jsm": ["TabCrashHandler", "SubframeCrashHandler", "UnsubmittedCrashHandler"], - "ContentObservers.js": [], "ContentPrefUtils.jsm": ["ContentPref", "cbHandleResult", "cbHandleError", "cbHandleCompletion", "safeCallback", "_methodsCallableFromChild"], "cookies.js": ["Cookies"], "CoverageUtils.jsm": ["CoverageCollector"],