summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/compatibility/actions
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/client/inspector/compatibility/actions
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/inspector/compatibility/actions')
-rw-r--r--devtools/client/inspector/compatibility/actions/compatibility.js333
-rw-r--r--devtools/client/inspector/compatibility/actions/index.js81
-rw-r--r--devtools/client/inspector/compatibility/actions/moz.build10
3 files changed, 424 insertions, 0 deletions
diff --git a/devtools/client/inspector/compatibility/actions/compatibility.js b/devtools/client/inspector/compatibility/actions/compatibility.js
new file mode 100644
index 0000000000..b967319f18
--- /dev/null
+++ b/devtools/client/inspector/compatibility/actions/compatibility.js
@@ -0,0 +1,333 @@
+/* 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 nodeConstants = require("devtools/shared/dom-node-constants");
+
+const UserSettings = require("devtools/client/inspector/shared/compatibility-user-settings");
+
+const {
+ COMPATIBILITY_APPEND_NODE_START,
+ COMPATIBILITY_APPEND_NODE_SUCCESS,
+ COMPATIBILITY_APPEND_NODE_FAILURE,
+ COMPATIBILITY_APPEND_NODE_COMPLETE,
+ COMPATIBILITY_CLEAR_DESTROYED_NODES,
+ COMPATIBILITY_INIT_USER_SETTINGS_START,
+ COMPATIBILITY_INIT_USER_SETTINGS_SUCCESS,
+ COMPATIBILITY_INIT_USER_SETTINGS_FAILURE,
+ COMPATIBILITY_INIT_USER_SETTINGS_COMPLETE,
+ COMPATIBILITY_INTERNAL_APPEND_NODE,
+ COMPATIBILITY_INTERNAL_NODE_UPDATE,
+ COMPATIBILITY_INTERNAL_REMOVE_NODE,
+ COMPATIBILITY_INTERNAL_UPDATE_SELECTED_NODE_ISSUES,
+ COMPATIBILITY_REMOVE_NODE_START,
+ COMPATIBILITY_REMOVE_NODE_SUCCESS,
+ COMPATIBILITY_REMOVE_NODE_FAILURE,
+ COMPATIBILITY_REMOVE_NODE_COMPLETE,
+ COMPATIBILITY_UPDATE_NODE_START,
+ COMPATIBILITY_UPDATE_NODE_SUCCESS,
+ COMPATIBILITY_UPDATE_NODE_FAILURE,
+ COMPATIBILITY_UPDATE_NODE_COMPLETE,
+ COMPATIBILITY_UPDATE_NODES_START,
+ COMPATIBILITY_UPDATE_NODES_SUCCESS,
+ COMPATIBILITY_UPDATE_NODES_FAILURE,
+ COMPATIBILITY_UPDATE_NODES_COMPLETE,
+ COMPATIBILITY_UPDATE_SELECTED_NODE_START,
+ COMPATIBILITY_UPDATE_SELECTED_NODE_SUCCESS,
+ COMPATIBILITY_UPDATE_SELECTED_NODE_FAILURE,
+ COMPATIBILITY_UPDATE_SELECTED_NODE_COMPLETE,
+ COMPATIBILITY_UPDATE_SETTINGS_VISIBILITY,
+ COMPATIBILITY_UPDATE_TARGET_BROWSERS_START,
+ COMPATIBILITY_UPDATE_TARGET_BROWSERS_SUCCESS,
+ COMPATIBILITY_UPDATE_TARGET_BROWSERS_FAILURE,
+ COMPATIBILITY_UPDATE_TARGET_BROWSERS_COMPLETE,
+ COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START,
+ COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_SUCCESS,
+ COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_FAILURE,
+ COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_COMPLETE,
+} = require("devtools/client/inspector/compatibility/actions/index");
+
+function appendNode(node) {
+ return async ({ dispatch, getState }) => {
+ dispatch({ type: COMPATIBILITY_APPEND_NODE_START });
+
+ try {
+ const { targetBrowsers, topLevelTarget } = getState().compatibility;
+ const { walker } = await topLevelTarget.getFront("inspector");
+ await _inspectNode(node, targetBrowsers, walker, dispatch);
+ dispatch({ type: COMPATIBILITY_APPEND_NODE_SUCCESS });
+ } catch (error) {
+ dispatch({
+ type: COMPATIBILITY_APPEND_NODE_FAILURE,
+ error,
+ });
+ }
+
+ dispatch({ type: COMPATIBILITY_APPEND_NODE_COMPLETE });
+ };
+}
+
+function clearDestroyedNodes() {
+ return { type: COMPATIBILITY_CLEAR_DESTROYED_NODES };
+}
+
+function initUserSettings() {
+ return async ({ dispatch, getState }) => {
+ dispatch({ type: COMPATIBILITY_INIT_USER_SETTINGS_START });
+
+ try {
+ const defaultTargetBrowsers = UserSettings.getDefaultTargetBrowsers();
+ const targetBrowsers = UserSettings.getTargetBrowsers();
+
+ dispatch({
+ type: COMPATIBILITY_INIT_USER_SETTINGS_SUCCESS,
+ defaultTargetBrowsers,
+ targetBrowsers,
+ });
+ } catch (error) {
+ dispatch({
+ type: COMPATIBILITY_INIT_USER_SETTINGS_FAILURE,
+ error,
+ });
+ }
+
+ dispatch({ type: COMPATIBILITY_INIT_USER_SETTINGS_COMPLETE });
+ };
+}
+
+function removeNode(node) {
+ return async ({ dispatch, getState }) => {
+ dispatch({ type: COMPATIBILITY_REMOVE_NODE_START });
+
+ try {
+ const { topLevelTarget } = getState().compatibility;
+ const { walker } = await topLevelTarget.getFront("inspector");
+ await _removeNode(node, walker, dispatch);
+ dispatch({ type: COMPATIBILITY_REMOVE_NODE_SUCCESS });
+ } catch (error) {
+ dispatch({
+ type: COMPATIBILITY_REMOVE_NODE_FAILURE,
+ error,
+ });
+ }
+
+ dispatch({ type: COMPATIBILITY_REMOVE_NODE_COMPLETE });
+ };
+}
+
+function updateNodes(selector) {
+ return async ({ dispatch, getState }) => {
+ dispatch({ type: COMPATIBILITY_UPDATE_NODES_START });
+
+ try {
+ const {
+ selectedNode,
+ topLevelTarget,
+ targetBrowsers,
+ } = getState().compatibility;
+ const { walker } = await topLevelTarget.getFront("inspector");
+ const nodeList = await walker.querySelectorAll(walker.rootNode, selector);
+
+ for (const node of await nodeList.items()) {
+ await _updateNode(node, selectedNode, targetBrowsers, dispatch);
+ }
+ dispatch({ type: COMPATIBILITY_UPDATE_NODES_SUCCESS });
+ } catch (error) {
+ dispatch({
+ type: COMPATIBILITY_UPDATE_NODES_FAILURE,
+ error,
+ });
+ }
+
+ dispatch({ type: COMPATIBILITY_UPDATE_NODES_COMPLETE });
+ };
+}
+
+function updateSelectedNode(node) {
+ return async ({ dispatch, getState }) => {
+ dispatch({ type: COMPATIBILITY_UPDATE_SELECTED_NODE_START });
+
+ try {
+ const { targetBrowsers } = getState().compatibility;
+ await _updateSelectedNodeIssues(node, targetBrowsers, dispatch);
+
+ dispatch({
+ type: COMPATIBILITY_UPDATE_SELECTED_NODE_SUCCESS,
+ node,
+ });
+ } catch (error) {
+ dispatch({
+ type: COMPATIBILITY_UPDATE_SELECTED_NODE_FAILURE,
+ error,
+ });
+ }
+
+ dispatch({ type: COMPATIBILITY_UPDATE_SELECTED_NODE_COMPLETE });
+ };
+}
+
+function updateSettingsVisibility(visibility) {
+ return {
+ type: COMPATIBILITY_UPDATE_SETTINGS_VISIBILITY,
+ visibility,
+ };
+}
+
+function updateTargetBrowsers(targetBrowsers) {
+ return async ({ dispatch, getState }) => {
+ dispatch({ type: COMPATIBILITY_UPDATE_TARGET_BROWSERS_START });
+
+ try {
+ UserSettings.setTargetBrowsers(targetBrowsers);
+
+ const { selectedNode, topLevelTarget } = getState().compatibility;
+
+ if (selectedNode) {
+ await _updateSelectedNodeIssues(selectedNode, targetBrowsers, dispatch);
+ }
+
+ if (topLevelTarget) {
+ await _updateTopLevelTargetIssues(
+ topLevelTarget,
+ targetBrowsers,
+ dispatch
+ );
+ }
+
+ dispatch({
+ type: COMPATIBILITY_UPDATE_TARGET_BROWSERS_SUCCESS,
+ targetBrowsers,
+ });
+ } catch (error) {
+ dispatch({ type: COMPATIBILITY_UPDATE_TARGET_BROWSERS_FAILURE, error });
+ }
+
+ dispatch({ type: COMPATIBILITY_UPDATE_TARGET_BROWSERS_COMPLETE });
+ };
+}
+
+function updateTopLevelTarget(target) {
+ return async ({ dispatch, getState }) => {
+ dispatch({ type: COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START });
+
+ try {
+ const { targetBrowsers } = getState().compatibility;
+ await _updateTopLevelTargetIssues(target, targetBrowsers, dispatch);
+
+ dispatch({ type: COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_SUCCESS, target });
+ } catch (error) {
+ dispatch({ type: COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_FAILURE, error });
+ }
+
+ dispatch({ type: COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_COMPLETE });
+ };
+}
+
+function updateNode(node) {
+ return async ({ dispatch, getState }) => {
+ dispatch({ type: COMPATIBILITY_UPDATE_NODE_START });
+
+ try {
+ const { selectedNode, targetBrowsers } = getState().compatibility;
+ await _updateNode(node, selectedNode, targetBrowsers, dispatch);
+ dispatch({ type: COMPATIBILITY_UPDATE_NODE_SUCCESS });
+ } catch (error) {
+ dispatch({
+ type: COMPATIBILITY_UPDATE_NODE_FAILURE,
+ error,
+ });
+ }
+
+ dispatch({ type: COMPATIBILITY_UPDATE_NODE_COMPLETE });
+ };
+}
+
+async function _getNodeIssues(node, targetBrowsers) {
+ const compatibility = await node.inspectorFront.getCompatibilityFront();
+ const declarationBlocksIssues = await compatibility.getNodeCssIssues(
+ node,
+ targetBrowsers
+ );
+
+ return declarationBlocksIssues;
+}
+
+async function _inspectNode(node, targetBrowsers, walker, dispatch) {
+ if (node.nodeType !== nodeConstants.ELEMENT_NODE) {
+ return;
+ }
+
+ const issues = await _getNodeIssues(node, targetBrowsers);
+
+ if (issues.length) {
+ dispatch({
+ type: COMPATIBILITY_INTERNAL_APPEND_NODE,
+ node,
+ issues,
+ });
+ }
+
+ const { nodes: children } = await walker.children(node);
+ for (const child of children) {
+ await _inspectNode(child, targetBrowsers, walker, dispatch);
+ }
+}
+
+async function _removeNode(node, walker, dispatch) {
+ if (node.nodeType !== nodeConstants.ELEMENT_NODE) {
+ return;
+ }
+
+ dispatch({
+ type: COMPATIBILITY_INTERNAL_REMOVE_NODE,
+ node,
+ });
+
+ const { nodes: children } = await walker.children(node);
+ for (const child of children) {
+ await _removeNode(child, walker, dispatch);
+ }
+}
+
+async function _updateNode(node, selectedNode, targetBrowsers, dispatch) {
+ if (selectedNode.actorID === node.actorID) {
+ await _updateSelectedNodeIssues(node, targetBrowsers, dispatch);
+ }
+
+ const issues = await _getNodeIssues(node, targetBrowsers);
+ dispatch({
+ type: COMPATIBILITY_INTERNAL_NODE_UPDATE,
+ node,
+ issues,
+ });
+}
+
+async function _updateSelectedNodeIssues(node, targetBrowsers, dispatch) {
+ const issues = await _getNodeIssues(node, targetBrowsers);
+
+ dispatch({
+ type: COMPATIBILITY_INTERNAL_UPDATE_SELECTED_NODE_ISSUES,
+ issues,
+ });
+}
+
+async function _updateTopLevelTargetIssues(target, targetBrowsers, dispatch) {
+ const { walker } = await target.getFront("inspector");
+ const documentElement = await walker.documentElement();
+ await _inspectNode(documentElement, targetBrowsers, walker, dispatch);
+}
+
+module.exports = {
+ appendNode,
+ clearDestroyedNodes,
+ initUserSettings,
+ removeNode,
+ updateNodes,
+ updateSelectedNode,
+ updateSettingsVisibility,
+ updateTargetBrowsers,
+ updateTopLevelTarget,
+ updateNode,
+};
diff --git a/devtools/client/inspector/compatibility/actions/index.js b/devtools/client/inspector/compatibility/actions/index.js
new file mode 100644
index 0000000000..42413eb2cf
--- /dev/null
+++ b/devtools/client/inspector/compatibility/actions/index.js
@@ -0,0 +1,81 @@
+/* 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 { createEnum } = require("devtools/client/shared/enum");
+
+createEnum(
+ [
+ // Append node and their children on DOM mutation
+ "COMPATIBILITY_APPEND_NODE_START",
+ "COMPATIBILITY_APPEND_NODE_SUCCESS",
+ "COMPATIBILITY_APPEND_NODE_FAILURE",
+ "COMPATIBILITY_APPEND_NODE_COMPLETE",
+
+ // Remove references to node that is removed
+ // programmatically whose fronts are destroyed.
+ "COMPATIBILITY_CLEAR_DESTROYED_NODES",
+
+ // Init user settings.
+ "COMPATIBILITY_INIT_USER_SETTINGS_START",
+ "COMPATIBILITY_INIT_USER_SETTINGS_SUCCESS",
+ "COMPATIBILITY_INIT_USER_SETTINGS_FAILURE",
+ "COMPATIBILITY_INIT_USER_SETTINGS_COMPLETE",
+
+ // Append node using internal helper that caused issues.
+ "COMPATIBILITY_INTERNAL_APPEND_NODE",
+
+ // Updates a node via the internal helper
+ "COMPATIBILITY_INTERNAL_NODE_UPDATE",
+
+ // Remove references to node that is removed
+ // in Markup Inspector but retained by DevTools
+ // using the internal helper.
+ "COMPATIBILITY_INTERNAL_REMOVE_NODE",
+
+ // Updates the selected node issues using internal helper.
+ "COMPATIBILITY_INTERNAL_UPDATE_SELECTED_NODE_ISSUES",
+
+ // Clean up removed node from node list
+ "COMPATIBILITY_REMOVE_NODE_START",
+ "COMPATIBILITY_REMOVE_NODE_SUCCESS",
+ "COMPATIBILITY_REMOVE_NODE_FAILURE",
+ "COMPATIBILITY_REMOVE_NODE_COMPLETE",
+
+ // Update node on attribute mutation
+ "COMPATIBILITY_UPDATE_NODE_START",
+ "COMPATIBILITY_UPDATE_NODE_SUCCESS",
+ "COMPATIBILITY_UPDATE_NODE_FAILURE",
+ "COMPATIBILITY_UPDATE_NODE_COMPLETE",
+
+ // Updates nodes.
+ "COMPATIBILITY_UPDATE_NODES_START",
+ "COMPATIBILITY_UPDATE_NODES_SUCCESS",
+ "COMPATIBILITY_UPDATE_NODES_FAILURE",
+ "COMPATIBILITY_UPDATE_NODES_COMPLETE",
+
+ // Updates the selected node.
+ "COMPATIBILITY_UPDATE_SELECTED_NODE_START",
+ "COMPATIBILITY_UPDATE_SELECTED_NODE_SUCCESS",
+ "COMPATIBILITY_UPDATE_SELECTED_NODE_FAILURE",
+ "COMPATIBILITY_UPDATE_SELECTED_NODE_COMPLETE",
+
+ // Updates the settings panel visibility.
+ "COMPATIBILITY_UPDATE_SETTINGS_VISIBILITY",
+
+ // Updates the target browsers.
+ "COMPATIBILITY_UPDATE_TARGET_BROWSERS_START",
+ "COMPATIBILITY_UPDATE_TARGET_BROWSERS_SUCCESS",
+ "COMPATIBILITY_UPDATE_TARGET_BROWSERS_FAILURE",
+ "COMPATIBILITY_UPDATE_TARGET_BROWSERS_COMPLETE",
+
+ // Updates the top level target.
+ "COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_START",
+ "COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_SUCCESS",
+ "COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_FAILURE",
+ "COMPATIBILITY_UPDATE_TOP_LEVEL_TARGET_COMPLETE",
+ ],
+ module.exports
+);
diff --git a/devtools/client/inspector/compatibility/actions/moz.build b/devtools/client/inspector/compatibility/actions/moz.build
new file mode 100644
index 0000000000..1b2b96950f
--- /dev/null
+++ b/devtools/client/inspector/compatibility/actions/moz.build
@@ -0,0 +1,10 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# 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(
+ "compatibility.js",
+ "index.js",
+)