/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* vim: set sts=2 sw=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 { ExtensionParent } = ChromeUtils.importESModule( "resource://gre/modules/ExtensionParent.sys.mjs" ); ChromeUtils.defineESModuleGetters(this, { BroadcastConduit: "resource://gre/modules/ConduitsParent.sys.mjs", }); var { watchExtensionProxyContextLoad } = ExtensionParent; var { promiseDocumentLoaded } = ExtensionUtils; const WEBEXT_PANELS_URL = "chrome://browser/content/webext-panels.xhtml"; class BaseDevToolsPanel { constructor(context, panelOptions) { const toolbox = context.devToolsToolbox; if (!toolbox) { // This should never happen when this constructor is called with a valid // devtools extension context. throw Error("Missing mandatory toolbox"); } this.context = context; this.extension = context.extension; this.toolbox = toolbox; this.viewType = "devtools_panel"; this.panelOptions = panelOptions; this.id = panelOptions.id; this.unwatchExtensionProxyContextLoad = null; // References to the panel browser XUL element and the toolbox window global which // contains the devtools panel UI. this.browser = null; this.browserContainerWindow = null; } async createBrowserElement(window) { const { toolbox } = this; const { extension } = this.context; const { url } = this.panelOptions || { url: "about:blank" }; this.browser = await window.getBrowser({ extension, extensionUrl: url, browserStyle: false, viewType: "devtools_panel", browserInsertedData: { devtoolsToolboxInfo: { toolboxPanelId: this.id, inspectedWindowTabId: getTargetTabIdForToolbox(toolbox), }, }, }); let hasTopLevelContext = false; // Listening to new proxy contexts. this.unwatchExtensionProxyContextLoad = watchExtensionProxyContextLoad( this, context => { // Keep track of the toolbox and target associated to the context, which is // needed by the API methods implementation. context.devToolsToolbox = toolbox; if (!hasTopLevelContext) { hasTopLevelContext = true; // Resolve the promise when the root devtools_panel context has been created. if (this._resolveTopLevelContext) { this._resolveTopLevelContext(context); } } } ); this.syncToolboxZoom(); this.toolbox.win.browsingContext.embedderElement.addEventListener( "FullZoomChange", this ); this.browser.fixupAndLoadURIString(url, { triggeringPrincipal: this.context.principal, }); } handleEvent(event) { switch (event.type) { case "FullZoomChange": { this.syncToolboxZoom(); break; } } } /** * The remote `` that loads the panel content does not inherit * the zoom level of the `` it's nested inside of. * * about:devtools-toolbox (zoom level applied here) * - ... * - webext-panels.xhtml