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

Side by Side Diff: chrome/content/processScript.js

Issue 29332902: Issue 3443 - Use process script instead of a frame script in Element Hiding Helper (Closed)
Patch Set: Created Dec. 21, 2015, 12:45 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
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", "togglePreview",
8 "forgetNode"];
9
10 const Ci = Components.interfaces; 7 const Ci = Components.interfaces;
11 const Cu = Components.utils; 8 const Cu = Components.utils;
12 9
13 let {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {}); 10 let {console} = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
14 let {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm ", {}); 11 let {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm ", {});
15 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); 12 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
16 13
17 let processID = Services.appinfo.processID; 14 let processID = Services.appinfo.processID;
18 let maxNodeID = 0; 15 let maxNodeID = 0;
19 let nodes = new Map(); 16 let nodes = new Map();
20 17
21 let name = "elemhidehelper"; 18 let name = "elemhidehelper";
22 let actor = { 19 let actor = {
23 constructorFun: Actor, 20 constructorFun: Actor,
24 constructorName: name, 21 constructorName: name,
25 name: name 22 name: name
26 }; 23 };
27 24
25 addMessageListener("ElemHideHelper:Shutdown", onShutdown);
26 addMessageListener("ElemHideHelper:GetNodeInfo", onGetNodeInfo);
27 addMessageListener("ElemHideHelper:Preview", onTogglePreview);
28
saroyanm 2015/12/21 16:48:55 Nit: No new line should be needed here.
Wladimir Palant 2015/12/21 19:14:15 I disagree - I'd rather separate functional blocks
28 DebuggerServer.addTabActor(actor, name); 29 DebuggerServer.addTabActor(actor, name);
29 30
30 var shutdown = (function() 31 var onShutdown = (function()
saroyanm 2015/12/21 16:48:55 I think it's something that I pointed in another r
Wladimir Palant 2015/12/21 19:14:15 True, this is no longer necessary. In fact, the co
saroyanm 2015/12/23 10:57:05 Looks good.
31 { 32 {
32 let executed = false; 33 let executed = false;
33 return function() 34 return function()
34 { 35 {
35 if (!executed) 36 if (!executed)
36 { 37 {
37 executed = true; 38 executed = true;
39
saroyanm 2015/12/21 16:48:55 Nit: No new line should be needed here.
Wladimir Palant 2015/12/21 19:14:15 Same as above - I'd rather separate functional blo
40 removeMessageListener("ElemHideHelper:Shutdown", onShutdown);
41 removeMessageListener("ElemHideHelper:GetNodeInfo", onGetNodeInfo);
42 removeMessageListener("ElemHideHelper:Preview", onTogglePreview);
43
38 try 44 try
39 { 45 {
40 DebuggerServer.removeTabActor(actor); 46 DebuggerServer.removeTabActor(actor);
41 } 47 }
42 catch (e) 48 catch (e)
43 { 49 {
44 // The call above will throw in the content process despite succeeding, 50 // The call above will throw in the content process despite succeeding,
45 // see https://bugzilla.mozilla.org/show_bug.cgi?id=1189780. 51 // see https://bugzilla.mozilla.org/show_bug.cgi?id=1189780.
46 Cu.reportError(e); 52 Cu.reportError(e);
47 } 53 }
48 } 54 }
49 } 55 }
50 })(); 56 })();
51 57
58 function onGetNodeInfo(message)
59 {
60 if (Cu.isCrossProcessWrapper(message.objects.element))
61 return;
62
63 let nodeInfo = getNodeInfo(message.objects.element);
64 nodeInfo.messageId = message.data;
65 sendAsyncMessage("ElemHideHelper:GetNodeInfo:Response", nodeInfo);
66 }
67
68 function onTogglePreview(message)
69 {
70 togglePreview(message.data.nodeID, message.data.stylesheetData);
71 if (message.data.forgetNode)
72 forgetNode(message.data.nodeID);
73 }
74
52 function Actor(connection, tabActor) 75 function Actor(connection, tabActor)
53 { 76 {
54 } 77 }
55 78
56 Actor.prototype = { 79 Actor.prototype = {
57 requestTypes: { 80 requestTypes: {
58 nodeinfo: function(request, connection) 81 nodeinfo: function(request, connection)
59 { 82 {
60 let nodeActor = connection.getActor(request.nodeActor); 83 let nodeActor = connection.getActor(request.nodeActor);
61 return getNodeInfo(nodeActor ? nodeActor.rawNode: null); 84 return getNodeInfo(nodeActor ? nodeActor.rawNode: null);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // forget this node then. 185 // forget this node then.
163 forgetNode(nodeID); 186 forgetNode(nodeID);
164 } 187 }
165 } 188 }
166 } 189 }
167 190
168 function forgetNode(nodeID) 191 function forgetNode(nodeID)
169 { 192 {
170 nodes.delete(nodeID); 193 nodes.delete(nodeID);
171 } 194 }
OLDNEW
« no previous file with comments | « chrome/content/frameScript.js ('k') | lib/aardvark.js » ('j') | lib/aardvark.js » ('J')

Powered by Google App Engine
This is Rietveld