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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/aardvark.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/child/commands.js
===================================================================
--- a/lib/child/commands.js
+++ b/lib/child/commands.js
@@ -9,29 +9,73 @@
let messageManager = require("messageManager");
let {getNodeInfo} = require("./nodeInfo");
let {
state, selectElement, setAnchorElement, stopSelection
} = require("./selection");
let {getParentElement} = require("./utils");
messageManager.addMessageListener("ElemHideHelper:Command", onCommand);
+messageManager.addMessageListener("ElemHideHelper:SerializeSelected",
+ serializeSelected);
onShutdown.add(() =>
{
messageManager.removeMessageListener("ElemHideHelper:Command", onCommand);
+ messageManager.removeMessageListener("ElemHideHelper:SerializeSelected",
+ serializeSelected);
});
function onCommand(message)
{
let command = message.data;
if (typeof exports[command] == "function")
exports[command]();
}
+function serializeNode(node)
+{
+ let result = null;
+ switch (node.nodeType)
+ {
+ case node.ELEMENT_NODE:
+ result = {
+ type: "element",
+ tagName: node.localName,
+ attributes: [],
+ children: []
+ };
+ for (let {name, value} of node.attributes)
+ result.attributes.push({name, value});
+ for (let child = node.firstChild; child; child = child.nextSibling)
+ {
+ let serialized = serializeNode(child);
+ if (serialized)
+ result.children.push(serialized);
+ }
+ break;
+ case node.TEXT_NODE:
+ case node.COMMENT_NODE:
+ result= {
+ type: node.nodeType == node.TEXT_NODE ? "text" : "comment",
+ text: node.textContent
+ };
+ break;
+ }
+ return result;
+}
+
+function serializeSelected(message)
+{
+ messageManager.sendAsyncMessage("ElemHideHelper:Response", {
+ messageId: message.data.messageId,
+ serialized: serializeNode(state.selectedElement)
+ });
+}
+
function quit()
{
stopSelection();
}
exports.quit = quit;
function select()
{
« 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