Index: lib/child/nodeInfo.js |
=================================================================== |
copy from chrome/content/processScript.js |
copy to lib/child/nodeInfo.js |
--- a/chrome/content/processScript.js |
+++ b/lib/child/nodeInfo.js |
@@ -1,124 +1,63 @@ |
/* |
* This Source Code is subject to the terms of the Mozilla Public License |
* version 2.0 (the "License"). You can obtain a copy of the License at |
* http://mozilla.org/MPL/2.0/. |
*/ |
-const Ci = Components.interfaces; |
-const Cu = Components.utils; |
- |
-let console; |
-try |
-{ |
- // Gecko 44+ |
- ({console} = Cu.import("resource://gre/modules/Console.jsm", {})); |
-} |
-catch (e) |
-{ |
- ({console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {})); |
-} |
- |
-let DebuggerServer; |
-try |
-{ |
- // Firefox 44+ |
- let {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); |
- ({DebuggerServer} = require("devtools/server/main")); |
-} |
-catch (e) |
-{ |
- ({DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {})); |
-} |
+"use strict"; |
let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
+let messageManager = require("messageManager"); |
+ |
let processID = Services.appinfo.processID; |
let maxNodeID = 0; |
let nodes = new Map(); |
-let name = "elemhidehelper"; |
-let actor = { |
- constructorFun: Actor, |
- constructorName: name, |
- name: name |
-}; |
- |
-addMessageListener("ElemHideHelper:Shutdown", onShutdown); |
-addMessageListener("ElemHideHelper:GetNodeInfo", onGetNodeInfo); |
-addMessageListener("ElemHideHelper:Preview", onTogglePreview); |
- |
-DebuggerServer.addTabActor(actor, name); |
- |
-function onShutdown() |
+messageManager.addMessageListener("ElemHideHelper:GetNodeInfo", onGetNodeInfo); |
+onShutdown.add(() => |
{ |
- removeMessageListener("ElemHideHelper:Shutdown", onShutdown); |
- removeMessageListener("ElemHideHelper:GetNodeInfo", onGetNodeInfo); |
- removeMessageListener("ElemHideHelper:Preview", onTogglePreview); |
- |
- try |
- { |
- DebuggerServer.removeTabActor(actor); |
- } |
- catch (e) |
- { |
- // The call above will throw in the content process despite succeeding, |
- // see https://bugzilla.mozilla.org/show_bug.cgi?id=1189780. |
- Cu.reportError(e); |
- } |
-} |
+ messageManager.removeMessageListener("ElemHideHelper:GetNodeInfo", onGetNodeInfo); |
saroyanm
2016/11/24 17:46:11
Nit: Exceeding 80 chars.
Wladimir Palant
2016/12/01 09:40:49
Done.
|
+}); |
function onGetNodeInfo(message) |
{ |
if (Cu.isCrossProcessWrapper(message.objects.element)) |
return; |
let nodeInfo = getNodeInfo(message.objects.element); |
nodeInfo.messageId = message.data; |
- sendAsyncMessage("ElemHideHelper:GetNodeInfo:Response", nodeInfo); |
-} |
- |
-function onTogglePreview(message) |
-{ |
- togglePreview(message.data.nodeID, message.data.stylesheetData); |
- if (message.data.forgetNode) |
- forgetNode(message.data.nodeID); |
+ messageManager.sendAsyncMessage("ElemHideHelper:GetNodeInfo:Response", nodeInfo); |
saroyanm
2016/11/24 17:46:11
Nit: Exceeding 80 chars.
Wladimir Palant
2016/12/01 09:40:49
Done.
|
} |
-function Actor(connection, tabActor) |
-{ |
-} |
- |
-Actor.prototype = { |
- requestTypes: { |
- nodeinfo: function(request, connection) |
- { |
- let nodeActor = connection.getActor(request.nodeActor); |
- return getNodeInfo(nodeActor ? nodeActor.rawNode: null); |
- } |
- } |
-}; |
- |
function getNodeInfo(node) |
{ |
let nodeData = getNodeData(node); |
if (nodeData) |
{ |
let nodeID = processID + "-" + (++maxNodeID); |
nodes.set(nodeID, {document: node.ownerDocument, style: null}); |
return { |
host: node.ownerDocument.defaultView.location.hostname, |
nodeData: nodeData, |
nodeID: nodeID |
}; |
} |
return {}; |
} |
+exports.getNodeInfo = getNodeInfo; |
+ |
+function getNodeById(nodeId) |
+{ |
+ return nodes.get(nodeId); |
+} |
+exports.getNodeById = getNodeById; |
function getNodeData(node, parentNode) |
{ |
if (!node || node.nodeType != Ci.nsIDOMNode.ELEMENT_NODE) |
return null; |
let result = {}; |
result.tagName = {value: node.tagName, checked: false}; |
@@ -160,47 +99,13 @@ function getNodeData(node, parentNode) |
result.attributes[1] = result.attributes[0]; |
result.attributes[0] = tmp; |
} |
result.customCSS = {selected: "", checked: false}; |
return result; |
} |
-function togglePreview(nodeID, stylesheetData) |
-{ |
- let context = nodes.get(nodeID); |
- if (!context) |
- return; |
- |
- if (stylesheetData) |
- { |
- if (!context.style || !context.style.parentNode) |
- { |
- context.style = context.document.createElementNS( |
- "http://www.w3.org/1999/xhtml", "style"); |
- context.style.setAttribute("type", "text/css"); |
- context.document.documentElement.appendChild(context.style); |
- } |
- context.style.textContent = stylesheetData; |
- } |
- else |
- { |
- try |
- { |
- if (context.style && context.style.parentNode) |
- context.style.parentNode.removeChild(context.style); |
- context.style = null; |
- } |
- catch (e) |
- { |
- // If the window was closed (reloaded) we end up with a dead object |
- // reference (https://bugzilla.mozilla.org/show_bug.cgi?id=695480). Just |
- // forget this node then. |
- forgetNode(nodeID); |
- } |
- } |
-} |
- |
function forgetNode(nodeID) |
{ |
nodes.delete(nodeID); |
} |
+exports.forgetNode = forgetNode; |