diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/webconsole/enhancers | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/webconsole/enhancers')
5 files changed, 191 insertions, 0 deletions
diff --git a/devtools/client/webconsole/enhancers/actor-releaser.js b/devtools/client/webconsole/enhancers/actor-releaser.js new file mode 100644 index 0000000000..30232c232a --- /dev/null +++ b/devtools/client/webconsole/enhancers/actor-releaser.js @@ -0,0 +1,62 @@ +/* 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 { + MESSAGES_ADD, + MESSAGES_CLEAR, + PRIVATE_MESSAGES_CLEAR, + FRONTS_TO_RELEASE_CLEAR, +} = require("resource://devtools/client/webconsole/constants.js"); + +/** + * This enhancer is responsible for releasing actors on the backend. + * When messages with arguments are removed from the store we should also + * clean up the backend. + */ +function enableActorReleaser(webConsoleUI) { + return next => (reducer, initialState, enhancer) => { + function releaseActorsEnhancer(state, action) { + state = reducer(state, action); + + const { type } = action; + if ( + webConsoleUI && + [MESSAGES_ADD, MESSAGES_CLEAR, PRIVATE_MESSAGES_CLEAR].includes(type) + ) { + const promises = []; + state.messages.frontsToRelease.forEach(front => { + // We only release the front if it actually has a release method, if it isn't + // already destroyed, and if it's not in the sidebar (where we might still need it). + if ( + front && + typeof front.release === "function" && + !front.isDestroyed() && + (!state.ui.frontInSidebar || + state.ui.frontInSidebar.actorID !== front.actorID) + ) { + promises.push(front.release()); + } + }); + + // Emit an event we can listen to to make sure all the fronts were released. + Promise.all(promises).then(() => + webConsoleUI.emitForTests("fronts-released") + ); + + // Reset `frontsToRelease` in message reducer. + state = reducer(state, { + type: FRONTS_TO_RELEASE_CLEAR, + }); + } + + return state; + } + + return next(releaseActorsEnhancer, initialState, enhancer); + }; +} + +module.exports = enableActorReleaser; diff --git a/devtools/client/webconsole/enhancers/batching.js b/devtools/client/webconsole/enhancers/batching.js new file mode 100644 index 0000000000..7343c11785 --- /dev/null +++ b/devtools/client/webconsole/enhancers/batching.js @@ -0,0 +1,34 @@ +/* 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 { + BATCH_ACTIONS, +} = require("resource://devtools/client/shared/redux/middleware/debounce.js"); + +/** + * A enhancer for the store to handle batched actions. + */ +function enableBatching() { + return next => (reducer, initialState, enhancer) => { + function batchingReducer(state, action) { + switch (action.type) { + case BATCH_ACTIONS: + return action.actions.reduce(batchingReducer, state); + default: + return reducer(state, action); + } + } + + if (typeof initialState === "function" && typeof enhancer === "undefined") { + enhancer = initialState; + initialState = undefined; + } + + return next(batchingReducer, initialState, enhancer); + }; +} + +module.exports = enableBatching; diff --git a/devtools/client/webconsole/enhancers/css-error-reporting.js b/devtools/client/webconsole/enhancers/css-error-reporting.js new file mode 100644 index 0000000000..513552db4d --- /dev/null +++ b/devtools/client/webconsole/enhancers/css-error-reporting.js @@ -0,0 +1,43 @@ +/* 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 { + INITIALIZE, + FILTER_TOGGLE, + FILTERS, +} = require("resource://devtools/client/webconsole/constants.js"); + +/** + * This is responsible for ensuring that error reporting is enabled if the CSS + * filter is toggled on. + */ +function ensureCSSErrorReportingEnabled(webConsoleUI) { + let watchingCSSMessages = false; + return next => (reducer, initialState, enhancer) => { + function ensureErrorReportingEnhancer(state, action) { + state = reducer(state, action); + + // If we're already watching CSS messages, or if the CSS filter is disabled, + // we don't do anything. + if (!webConsoleUI || watchingCSSMessages || !state.filters.css) { + return state; + } + + const cssFilterToggled = + action.type == FILTER_TOGGLE && action.filter == FILTERS.CSS; + + if (cssFilterToggled || action.type == INITIALIZE) { + watchingCSSMessages = true; + webConsoleUI.watchCssMessages(); + } + + return state; + } + return next(ensureErrorReportingEnhancer, initialState, enhancer); + }; +} + +module.exports = ensureCSSErrorReportingEnabled; diff --git a/devtools/client/webconsole/enhancers/message-cache-clearing.js b/devtools/client/webconsole/enhancers/message-cache-clearing.js new file mode 100644 index 0000000000..f2f4b90eab --- /dev/null +++ b/devtools/client/webconsole/enhancers/message-cache-clearing.js @@ -0,0 +1,41 @@ +/* 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 { + MESSAGES_CLEAR, +} = require("resource://devtools/client/webconsole/constants.js"); + +/** + * This enhancer is responsible for clearing the messages caches using the + * webconsoleFront when the user clear the messages (either by direct UI action, or via + * `console.clear()`). + */ +function enableMessagesCacheClearing(webConsoleUI) { + return next => (reducer, initialState, enhancer) => { + function messagesCacheClearingEnhancer(state, action) { + const storeHadMessages = + state?.messages?.mutableMessagesById && + state.messages.mutableMessagesById.size > 0; + state = reducer(state, action); + + if (storeHadMessages && webConsoleUI && action.type === MESSAGES_CLEAR) { + webConsoleUI.clearMessagesCache(); + + // cleans up all the network data provider internal state + webConsoleUI.networkDataProvider?.destroy(); + + if (webConsoleUI.hud?.toolbox) { + webConsoleUI.hud.toolbox.setErrorCount(0); + } + } + return state; + } + + return next(messagesCacheClearingEnhancer, initialState, enhancer); + }; +} + +module.exports = enableMessagesCacheClearing; diff --git a/devtools/client/webconsole/enhancers/moz.build b/devtools/client/webconsole/enhancers/moz.build new file mode 100644 index 0000000000..79bb7dd191 --- /dev/null +++ b/devtools/client/webconsole/enhancers/moz.build @@ -0,0 +1,11 @@ +# vim: set filetype=python: +# 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/. + +DevToolsModules( + "actor-releaser.js", + "batching.js", + "css-error-reporting.js", + "message-cache-clearing.js", +) |