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

Side by Side Diff: lib/child/commands.js

Issue 29366552: Issue 2879 - Make "view source" command work again (Closed) Base URL: https://hg.adblockplus.org/elemhidehelper
Patch Set: Addressed nits Created Dec. 8, 2016, 1:11 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 | « lib/aardvark.js ('k') | no next file » | no next file with comments »
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 "use strict"; 7 "use strict";
8 8
9 let messageManager = require("messageManager"); 9 let messageManager = require("messageManager");
10 let {getNodeInfo} = require("./nodeInfo"); 10 let {getNodeInfo} = require("./nodeInfo");
11 let { 11 let {
12 state, selectElement, setAnchorElement, stopSelection 12 state, selectElement, setAnchorElement, stopSelection
13 } = require("./selection"); 13 } = require("./selection");
14 let {getParentElement} = require("./utils"); 14 let {getParentElement} = require("./utils");
15 15
16 messageManager.addMessageListener("ElemHideHelper:Command", onCommand); 16 messageManager.addMessageListener("ElemHideHelper:Command", onCommand);
17 messageManager.addMessageListener("ElemHideHelper:SerializeSelected",
18 serializeSelected);
17 19
18 onShutdown.add(() => 20 onShutdown.add(() =>
19 { 21 {
20 messageManager.removeMessageListener("ElemHideHelper:Command", onCommand); 22 messageManager.removeMessageListener("ElemHideHelper:Command", onCommand);
23 messageManager.removeMessageListener("ElemHideHelper:SerializeSelected",
24 serializeSelected);
21 }); 25 });
22 26
23 function onCommand(message) 27 function onCommand(message)
24 { 28 {
25 let command = message.data; 29 let command = message.data;
26 if (typeof exports[command] == "function") 30 if (typeof exports[command] == "function")
27 exports[command](); 31 exports[command]();
28 } 32 }
29 33
34 function serializeNode(node)
35 {
36 let result = null;
37 switch (node.nodeType)
38 {
39 case node.ELEMENT_NODE:
40 result = {
41 type: "element",
42 tagName: node.localName,
43 attributes: [],
44 children: []
45 };
46 for (let {name, value} of node.attributes)
47 result.attributes.push({name, value});
48 for (let child = node.firstChild; child; child = child.nextSibling)
49 {
50 let serialized = serializeNode(child);
51 if (serialized)
52 result.children.push(serialized);
53 }
54 break;
55 case node.TEXT_NODE:
56 case node.COMMENT_NODE:
57 result= {
58 type: node.nodeType == node.TEXT_NODE ? "text" : "comment",
59 text: node.textContent
60 };
61 break;
62 }
63 return result;
64 }
65
66 function serializeSelected(message)
67 {
68 messageManager.sendAsyncMessage("ElemHideHelper:Response", {
69 messageId: message.data.messageId,
70 serialized: serializeNode(state.selectedElement)
71 });
72 }
73
30 function quit() 74 function quit()
31 { 75 {
32 stopSelection(); 76 stopSelection();
33 } 77 }
34 exports.quit = quit; 78 exports.quit = quit;
35 79
36 function select() 80 function select()
37 { 81 {
38 if (!state.selectedElement) 82 if (!state.selectedElement)
39 return; 83 return;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 counter: 0, 182 counter: 0,
139 element: state.selectedElement, 183 element: state.selectedElement,
140 origVisibility: state.selectedElement.style.visibility, 184 origVisibility: state.selectedElement.style.visibility,
141 timer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer) 185 timer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer)
142 }; 186 };
143 187
144 blinkState.timer.initWithCallback(doBlink, 250, 188 blinkState.timer.initWithCallback(doBlink, 250,
145 Ci.nsITimer.TYPE_REPEATING_SLACK); 189 Ci.nsITimer.TYPE_REPEATING_SLACK);
146 } 190 }
147 exports.blinkElement = blinkElement; 191 exports.blinkElement = blinkElement;
OLDNEW
« no previous file with comments | « lib/aardvark.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld