Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/actor.jsm

Issue 29323107: Issue 2816 - Restore Preview functionality (Closed)
Patch Set: Created July 30, 2015, 1:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/content/composer.js » ('j') | chrome/content/frameScript.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 DebuggerServer.removeTabActor(actor);
30 executed = true; 37 executed = true;
31 } 38 }
32 })(); 39 })();
33 40
34 function Actor(connection, tabActor) 41 function Actor(connection, tabActor)
35 { 42 {
36 } 43 }
37 44
38 Actor.prototype = { 45 Actor.prototype = {
39 requestTypes: { 46 requestTypes: {
40 nodeinfo: function(request, connection) 47 nodeinfo: function(request, connection)
41 { 48 {
42 let nodeActor = connection.getActor(request.nodeActor); 49 let nodeActor = connection.getActor(request.nodeActor);
43 if (!nodeActor || !nodeActor.rawNode || 50 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 } 51 }
51 } 52 }
52 }; 53 };
53 54
54 function getNodeInfo(node) 55 function getNodeInfo(node)
55 { 56 {
56 return { 57 let nodeData = getNodeData(node);
57 host: node.ownerDocument.defaultView.location.hostname, 58 if (nodeData)
58 nodeData: getNodeData(node) 59 {
59 }; 60 let nodeID = processID + "-" + (++maxNodeID);
61 nodes.set(nodeID, {document: node.ownerDocument, style: null});
62 return {
63 host: node.ownerDocument.defaultView.location.hostname,
64 nodeData: nodeData,
65 nodeID: nodeID
66 };
67 }
68
69 return {};
60 } 70 }
61 71
62 function getNodeData(node, parentNode) 72 function getNodeData(node, parentNode)
63 { 73 {
64 if (!node) 74 if (!node || node.nodeType != Ci.nsIDOMNode.ELEMENT_NODE)
65 return null; 75 return null;
66 76
67 let result = {}; 77 let result = {};
68 result.tagName = {value: node.tagName, checked: false}; 78 result.tagName = {value: node.tagName, checked: false};
69 79
70 if (typeof parentNode != "undefined") 80 if (typeof parentNode != "undefined")
71 result.parentNode = parentNode; 81 result.parentNode = parentNode;
72 else 82 else
73 result.parentNode = getNodeData(node.parentElement); 83 result.parentNode = getNodeData(node.parentElement);
74 84
(...skipping 26 matching lines...) Expand all
101 { 111 {
102 // Make sure ID attribute comes first 112 // Make sure ID attribute comes first
103 let tmp = result.attributes[1]; 113 let tmp = result.attributes[1];
104 result.attributes[1] = result.attributes[0]; 114 result.attributes[1] = result.attributes[0];
105 result.attributes[0] = tmp; 115 result.attributes[0] = tmp;
106 } 116 }
107 117
108 result.customCSS = {selected: "", checked: false}; 118 result.customCSS = {selected: "", checked: false};
109 return result; 119 return result;
110 } 120 }
121
122 function togglePreview(nodeID, stylesheetData)
123 {
124 let context = nodes.get(nodeID);
125 if (!context)
126 return;
127
128 if (stylesheetData)
129 {
130 if (!context.style || !context.style.parentNode)
131 {
132 context.style = context.document.createElementNS(
133 "http://www.w3.org/1999/xhtml", "style");
134 context.style.setAttribute("type", "text/css");
135 context.document.documentElement.appendChild(context.style);
136 }
137 context.style.textContent = stylesheetData;
138 }
139 else
140 {
141 try
142 {
143 if (context.style && context.style.parentNode)
144 context.style.parentNode.removeChild(context.style);
145 }
146 catch (e)
147 {
148 // If the window was closed (reloaded) we end up with dead object
149 // reference (https://bugzilla.mozilla.org/show_bug.cgi?id=695480). Just
150 // ignore this case, we don't need to do anything.
Thomas Greiner 2015/07/31 12:48:03 If the context is no longer valid anyway, what abo
Wladimir Palant 2015/07/31 14:40:04 Done.
151 }
152 context.style = null;
153 }
154 }
155
156 function forgetNode(nodeID)
157 {
158 nodes.delete(nodeID);
159 }
OLDNEW
« no previous file with comments | « no previous file | chrome/content/composer.js » ('j') | chrome/content/frameScript.js » ('J')

Powered by Google App Engine
This is Rietveld