OLD | NEW |
(Empty) | |
| 1 /* |
| 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 |
| 4 * http://mozilla.org/MPL/2.0/. |
| 5 */ |
| 6 |
| 7 let EXPORTED_SYMBOLS = ["shutdown", "getNodeInfo"]; |
| 8 |
| 9 const Ci = Components.interfaces; |
| 10 const Cu = Components.utils; |
| 11 |
| 12 let {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {}); |
| 13 let {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm
", {}); |
| 14 let name = "elemhidehelper"; |
| 15 let actor = { |
| 16 constructorFun: Actor, |
| 17 constructorName: name, |
| 18 name: name |
| 19 }; |
| 20 |
| 21 DebuggerServer.addTabActor(actor, name); |
| 22 |
| 23 let shutdown = (function() |
| 24 { |
| 25 let executed = false; |
| 26 return function() |
| 27 { |
| 28 if (!executed) |
| 29 DebuggerServer.removeTabActor(actor); |
| 30 executed = true; |
| 31 } |
| 32 })(); |
| 33 |
| 34 function Actor(connection, tabActor) |
| 35 { |
| 36 } |
| 37 |
| 38 Actor.prototype = { |
| 39 requestTypes: { |
| 40 nodeinfo: function(request, connection) |
| 41 { |
| 42 let nodeActor = connection.getActor(request.nodeActor); |
| 43 if (!nodeActor || !nodeActor.rawNode || |
| 44 nodeActor.rawNode.nodeType != Ci.nsIDOMNode.ELEMENT_NODE) |
| 45 { |
| 46 return {}; |
| 47 } |
| 48 |
| 49 return getNodeInfo(nodeActor.rawNode); |
| 50 } |
| 51 } |
| 52 }; |
| 53 |
| 54 function getNodeInfo(node) |
| 55 { |
| 56 return { |
| 57 host: node.ownerDocument.defaultView.location.hostname, |
| 58 nodeData: getNodeData(node) |
| 59 }; |
| 60 } |
| 61 |
| 62 function getNodeData(node, parentNode) |
| 63 { |
| 64 if (!node) |
| 65 return null; |
| 66 |
| 67 let result = {}; |
| 68 result.tagName = {value: node.tagName, checked: false}; |
| 69 |
| 70 if (typeof parentNode != "undefined") |
| 71 result.parentNode = parentNode; |
| 72 else |
| 73 result.parentNode = getNodeData(node.parentElement); |
| 74 |
| 75 let prevSibling = node.previousElementSibling; |
| 76 result.prevSibling = getNodeData(prevSibling, result.parentNode); |
| 77 |
| 78 if (result.parentNode && !prevSibling) |
| 79 result.firstChild = {checked: false}; |
| 80 |
| 81 let nextSibling = node.nextElementSibling; |
| 82 if (result.parentNode && !nextSibling) |
| 83 result.lastChild = {checked: false}; |
| 84 |
| 85 result.attributes = []; |
| 86 for (let attribute of node.attributes) |
| 87 { |
| 88 let data = { |
| 89 name: attribute.name, |
| 90 value: attribute.value, |
| 91 selected: attribute.value, |
| 92 checked: false |
| 93 }; |
| 94 if (data.name == "id" || data.name == "class") |
| 95 result.attributes.unshift(data); |
| 96 else |
| 97 result.attributes.push(data); |
| 98 } |
| 99 |
| 100 if (result.attributes.length >= 2 && result.attributes[1].name == "id") |
| 101 { |
| 102 // Make sure ID attribute comes first |
| 103 let tmp = result.attributes[1]; |
| 104 result.attributes[1] = result.attributes[0]; |
| 105 result.attributes[0] = tmp; |
| 106 } |
| 107 |
| 108 result.customCSS = {selected: "", checked: false}; |
| 109 return result; |
| 110 } |
OLD | NEW |