Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 let EXPORTED_SYMBOLS = ["shutdown", "getNodeInfo"]; | 7 let EXPORTED_SYMBOLS = ["shutdown", "getNodeInfo", "togglePreview", |
8 "forgetNode"]; | |
8 | 9 |
9 const Ci = Components.interfaces; | 10 const Ci = Components.interfaces; |
10 const Cu = Components.utils; | 11 const Cu = Components.utils; |
11 | 12 |
12 let {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {}); | 13 let {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {}); |
13 let {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm ", {}); | 14 let {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm ", {}); |
15 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | |
16 | |
17 let processID = Services.appinfo.processID; | |
18 let maxNodeID = 0; | |
19 let nodes = new Map(); | |
20 | |
14 let name = "elemhidehelper"; | 21 let name = "elemhidehelper"; |
15 let actor = { | 22 let actor = { |
16 constructorFun: Actor, | 23 constructorFun: Actor, |
17 constructorName: name, | 24 constructorName: name, |
18 name: name | 25 name: name |
19 }; | 26 }; |
20 | 27 |
21 DebuggerServer.addTabActor(actor, name); | 28 DebuggerServer.addTabActor(actor, name); |
22 | 29 |
23 let shutdown = (function() | 30 let shutdown = (function() |
24 { | 31 { |
25 let executed = false; | 32 let executed = false; |
26 return function() | 33 return function() |
27 { | 34 { |
28 if (!executed) | 35 if (!executed) |
29 DebuggerServer.removeTabActor(actor); | 36 { |
30 executed = true; | 37 executed = true; |
38 try | |
39 { | |
40 DebuggerServer.removeTabActor(actor); | |
Wladimir Palant
2015/07/31 14:40:04
This will throw in the content process, I suspect
Wladimir Palant
2015/07/31 15:09:36
My investigation shows that we are doing everythin
| |
41 } | |
42 catch (e) | |
43 { | |
44 Cu.reportError(e); | |
45 } | |
46 } | |
31 } | 47 } |
32 })(); | 48 })(); |
33 | 49 |
34 function Actor(connection, tabActor) | 50 function Actor(connection, tabActor) |
35 { | 51 { |
36 } | 52 } |
37 | 53 |
38 Actor.prototype = { | 54 Actor.prototype = { |
39 requestTypes: { | 55 requestTypes: { |
40 nodeinfo: function(request, connection) | 56 nodeinfo: function(request, connection) |
41 { | 57 { |
42 let nodeActor = connection.getActor(request.nodeActor); | 58 let nodeActor = connection.getActor(request.nodeActor); |
43 if (!nodeActor || !nodeActor.rawNode || | 59 return getNodeInfo(nodeActor ? nodeActor.rawNode: null); |
44 nodeActor.rawNode.nodeType != Ci.nsIDOMNode.ELEMENT_NODE) | |
45 { | |
46 return {}; | |
47 } | |
48 | |
49 return getNodeInfo(nodeActor.rawNode); | |
50 } | 60 } |
51 } | 61 } |
52 }; | 62 }; |
53 | 63 |
54 function getNodeInfo(node) | 64 function getNodeInfo(node) |
55 { | 65 { |
56 return { | 66 let nodeData = getNodeData(node); |
57 host: node.ownerDocument.defaultView.location.hostname, | 67 if (nodeData) |
58 nodeData: getNodeData(node) | 68 { |
59 }; | 69 let nodeID = processID + "-" + (++maxNodeID); |
70 nodes.set(nodeID, {document: node.ownerDocument, style: null}); | |
71 return { | |
72 host: node.ownerDocument.defaultView.location.hostname, | |
73 nodeData: nodeData, | |
74 nodeID: nodeID | |
75 }; | |
76 } | |
77 | |
78 return {}; | |
60 } | 79 } |
61 | 80 |
62 function getNodeData(node, parentNode) | 81 function getNodeData(node, parentNode) |
63 { | 82 { |
64 if (!node) | 83 if (!node || node.nodeType != Ci.nsIDOMNode.ELEMENT_NODE) |
65 return null; | 84 return null; |
66 | 85 |
67 let result = {}; | 86 let result = {}; |
68 result.tagName = {value: node.tagName, checked: false}; | 87 result.tagName = {value: node.tagName, checked: false}; |
69 | 88 |
70 if (typeof parentNode != "undefined") | 89 if (typeof parentNode != "undefined") |
71 result.parentNode = parentNode; | 90 result.parentNode = parentNode; |
72 else | 91 else |
73 result.parentNode = getNodeData(node.parentElement); | 92 result.parentNode = getNodeData(node.parentElement); |
74 | 93 |
(...skipping 26 matching lines...) Expand all Loading... | |
101 { | 120 { |
102 // Make sure ID attribute comes first | 121 // Make sure ID attribute comes first |
103 let tmp = result.attributes[1]; | 122 let tmp = result.attributes[1]; |
104 result.attributes[1] = result.attributes[0]; | 123 result.attributes[1] = result.attributes[0]; |
105 result.attributes[0] = tmp; | 124 result.attributes[0] = tmp; |
106 } | 125 } |
107 | 126 |
108 result.customCSS = {selected: "", checked: false}; | 127 result.customCSS = {selected: "", checked: false}; |
109 return result; | 128 return result; |
110 } | 129 } |
130 | |
131 function togglePreview(nodeID, stylesheetData) | |
132 { | |
133 let context = nodes.get(nodeID); | |
134 if (!context) | |
135 return; | |
136 | |
137 if (stylesheetData) | |
138 { | |
139 if (!context.style || !context.style.parentNode) | |
140 { | |
141 context.style = context.document.createElementNS( | |
142 "http://www.w3.org/1999/xhtml", "style"); | |
143 context.style.setAttribute("type", "text/css"); | |
144 context.document.documentElement.appendChild(context.style); | |
145 } | |
146 context.style.textContent = stylesheetData; | |
147 } | |
148 else | |
149 { | |
150 try | |
151 { | |
152 if (context.style && context.style.parentNode) | |
153 context.style.parentNode.removeChild(context.style); | |
154 context.style = null; | |
155 } | |
156 catch (e) | |
157 { | |
158 // If the window was closed (reloaded) we end up with a dead object | |
159 // reference (https://bugzilla.mozilla.org/show_bug.cgi?id=695480). Just | |
160 // forget this node then. | |
161 forgetNode(nodeID); | |
162 } | |
163 } | |
164 } | |
165 | |
166 function forgetNode(nodeID) | |
167 { | |
168 nodes.delete(nodeID); | |
169 } | |
OLD | NEW |