From 14f91915279b35e62702b7572f1642c7abb66db7 Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Wed, 22 May 2019 23:35:43 +0200 Subject: [PATCH] Backed out changeset e20df5f95e44 (bug 1552434) for devtools failures in devtools/client/framework/test/browser_toolbox_options.js CLOSED TREE --- devtools/client/webconsole/components/App.js | 32 ------------------- devtools/client/webconsole/constants.js | 4 +-- devtools/client/webconsole/store.js | 1 - devtools/client/webconsole/webconsole-ui.js | 14 ++++++++ .../client/webconsole/webconsole-wrapper.js | 4 +++ 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/devtools/client/webconsole/components/App.js b/devtools/client/webconsole/components/App.js index 17cafee4425d..21c687c6e1b0 100644 --- a/devtools/client/webconsole/components/App.js +++ b/devtools/client/webconsole/components/App.js @@ -33,9 +33,6 @@ const { getAllNotifications } = require("devtools/client/webconsole/selectors/no const { div } = dom; const isMacOS = Services.appinfo.OS === "Darwin"; -// Prefs -const { PREFS } = require("devtools/client/webconsole/constants"); - /** * Console root Application component. */ @@ -66,35 +63,6 @@ class App extends Component { this.onKeyDown = this.onKeyDown.bind(this); } - componentDidMount() { - const { - UI, - } = PREFS; - - // Toggle the timestamp on preference change. We use a weak observer to not have to - // remove the observer (because we don't want to have a componentWillUnmount that - // would do extra work). - this.timeStampObserver = { - QueryInterface: ChromeUtils.generateQI([ - Ci.nsIObserver, - Ci.nsISupportsWeakReference, - ]), - - observe: () => { - const enabled = Services.prefs.getBoolPref(UI.MESSAGE_TIMESTAMP); - this.props.dispatch(actions.timestampsToggle(enabled)); - }, - }; - - Services.prefs.addObserver( - UI.MESSAGE_TIMESTAMP, - this.timeStampObserver, - // This is flag needed to register a weak observer. - // See https://searchfox.org/mozilla-central/rev/f4c39907e0b527dc4b9356a1eeb8c6e6c62d383a/modules/libpref/nsIPrefBranch.idl#430 - true - ); - } - onKeyDown(event) { const { dispatch, diff --git a/devtools/client/webconsole/constants.js b/devtools/client/webconsole/constants.js index 8de5bc751bc9..c7eb1f02d1a0 100644 --- a/devtools/client/webconsole/constants.js +++ b/devtools/client/webconsole/constants.js @@ -69,10 +69,8 @@ const prefs = { INPUT_HISTORY_COUNT: "devtools.webconsole.inputHistoryCount", // Is editor mode enabled. EDITOR: "devtools.webconsole.input.editor", - // Display content messages in the browser console. + // Display content messages in the browser console CONTENT_MESSAGES: "devtools.browserconsole.contentMessages", - // Display timestamp in messages. - MESSAGE_TIMESTAMP: "devtools.webconsole.timestampMessages", }, FEATURES: { // We use the same pref to enable the sidebar on webconsole and browser console. diff --git a/devtools/client/webconsole/store.js b/devtools/client/webconsole/store.js index 21530c9acc44..3841b98924b6 100644 --- a/devtools/client/webconsole/store.js +++ b/devtools/client/webconsole/store.js @@ -81,7 +81,6 @@ function configureStore(webConsoleUI, options = {}) { ? getBoolPref(PREFS.UI.CONTENT_MESSAGES) : true, editor: getBoolPref(PREFS.UI.EDITOR), - timestampsVisible: getBoolPref(PREFS.UI.MESSAGE_TIMESTAMP), }), }; diff --git a/devtools/client/webconsole/webconsole-ui.js b/devtools/client/webconsole/webconsole-ui.js index 386f1604f517..8e0406625c6b 100644 --- a/devtools/client/webconsole/webconsole-ui.js +++ b/devtools/client/webconsole/webconsole-ui.js @@ -19,6 +19,7 @@ loader.lazyRequireGetter(this, "AppConstants", "resource://gre/modules/AppConsta const ZoomKeys = require("devtools/client/shared/zoom-keys"); +const PREF_MESSAGE_TIMESTAMP = "devtools.webconsole.timestampMessages"; const PREF_SIDEBAR_ENABLED = "devtools.webconsole.sidebarToggle"; /** @@ -39,6 +40,7 @@ class WebConsoleUI { this.isBrowserConsole = this.hud._browserConsole; this.window = this.hud.iframeWindow; + this._onToolboxPrefChanged = this._onToolboxPrefChanged.bind(this); this._onPanelSelected = this._onPanelSelected.bind(this); this._onChangeSplitConsoleState = this._onChangeSplitConsoleState.bind(this); @@ -62,6 +64,9 @@ class WebConsoleUI { this._initUI(); await this._initConnection(); await this.wrapper.init(); + // Toggle the timestamp on preference change + Services.prefs.addObserver(PREF_MESSAGE_TIMESTAMP, this._onToolboxPrefChanged); + this._onToolboxPrefChanged(); const id = WebConsoleUtils.supportsString(this.hudId); if (Services.obs) { @@ -74,6 +79,7 @@ class WebConsoleUI { return this._destroyer.promise; } this._destroyer = defer(); + Services.prefs.removeObserver(PREF_MESSAGE_TIMESTAMP, this._onToolboxPrefChanged); this.React = this.ReactDOM = this.FrameView = null; if (this.jsterm) { this.jsterm.destroy(); @@ -312,6 +318,14 @@ class WebConsoleUI { } } + /** + * Called when the message timestamp pref changes. + */ + _onToolboxPrefChanged() { + const newValue = Services.prefs.getBoolPref(PREF_MESSAGE_TIMESTAMP); + this.wrapper.dispatchTimestampsToggle(newValue); + } + /** * Sets the focus to JavaScript input field when the web console tab is * selected or when there is a split console present. diff --git a/devtools/client/webconsole/webconsole-wrapper.js b/devtools/client/webconsole/webconsole-wrapper.js index 1a49d16fbc4f..21943fad3f14 100644 --- a/devtools/client/webconsole/webconsole-wrapper.js +++ b/devtools/client/webconsole/webconsole-wrapper.js @@ -477,6 +477,10 @@ class WebConsoleWrapper { store.dispatch(actions.privateMessagesClear()); } + dispatchTimestampsToggle(enabled) { + store.dispatch(actions.timestampsToggle(enabled)); + } + dispatchPaused(_, packet) { if (packet.executionPoint) { store.dispatch(actions.setPauseExecutionPoint(packet.executionPoint));