diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/webconsole/enhancers | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/webconsole/enhancers')
5 files changed, 185 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..222de2b083 --- /dev/null +++ b/devtools/client/webconsole/enhancers/actor-releaser.js @@ -0,0 +1,56 @@ +/* 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 { frontInSidebar } = state.ui; + let { frontsToRelease } = state.messages; + // Ignore the front for object still displayed in the sidebar, if there is one. + frontsToRelease = frontInSidebar + ? frontsToRelease.filter( + front => frontInSidebar.actorID !== front.actorID + ) + : state.messages.frontsToRelease; + + webConsoleUI.hud.commands.objectCommand + .releaseObjects(frontsToRelease) + // Emit an event we can listen to to make sure all the fronts were released. + .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", +) |