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

Delta Between Two Patch Sets: lib/aardvark.js

Issue 29363476: Issue 2879 - Move element selection into the content process (Closed) Base URL: https://hg.adblockplus.org/elemhidehelper
Left Patch Set: Created Nov. 17, 2016, 1:17 p.m.
Right Patch Set: Addressed comments and marked extension as E10S-compatible Created Nov. 24, 2016, 2 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/child/commands.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
saroyanm 2016/11/23 17:44:37 Irrelevant: Why is this file called Aadvark ?
Wladimir Palant 2016/11/24 14:02:00 The origin of this code is the Aardvark extension
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 {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); 7 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
8 8
9 let {Prefs} = require("prefs"); 9 let {Prefs} = require("prefs");
10 10
11 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"] 11 let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
12 .getService(Ci.nsIMessageListenerManager) 12 .getService(Ci.nsIMessageListenerManager)
13 .QueryInterface(Ci.nsIMessageBroadcaster); 13 .QueryInterface(Ci.nsIMessageBroadcaster);
14 14
15 // To be replaced when selection starts 15 // To be replaced when selection starts
16 function E(id) {return null;} 16 function E(id) {return null;}
17 17
18 messageManager.addMessageListener("ElemHideHelper:SelectionStarted", selectionSt arted); 18 messageManager.addMessageListener("ElemHideHelper:SelectionStarted",
saroyanm 2016/11/23 17:44:37 Nit: Exceeding 80 chars
Wladimir Palant 2016/11/24 14:02:01 Done.
19 messageManager.addMessageListener("ElemHideHelper:SelectionSucceeded", selection Succeeded); 19 selectionStarted);
20 messageManager.addMessageListener("ElemHideHelper:SelectionStopped", selectionSt opped); 20 messageManager.addMessageListener("ElemHideHelper:SelectionSucceeded",
21 selectionSucceeded);
22 messageManager.addMessageListener("ElemHideHelper:SelectionStopped",
23 selectionStopped);
21 onShutdown.add(() => 24 onShutdown.add(() =>
22 { 25 {
23 messageManager.removeMessageListener("ElemHideHelper:SelectionStarted", select ionStarted); 26 messageManager.removeMessageListener("ElemHideHelper:SelectionStarted",
24 messageManager.removeMessageListener("ElemHideHelper:SelectionSucceeded", sele ctionSucceeded); 27 selectionStarted);
25 messageManager.removeMessageListener("ElemHideHelper:SelectionStopped", select ionStopped); 28 messageManager.removeMessageListener("ElemHideHelper:SelectionSucceeded",
29 selectionSucceeded);
30 messageManager.removeMessageListener("ElemHideHelper:SelectionStopped",
31 selectionStopped);
26 32
27 selectionStopped(); 33 selectionStopped();
28 }); 34 });
29 35
30 function selectionStarted(message) 36 function selectionStarted(message)
31 { 37 {
32 Aardvark.selectionStarted(); 38 Aardvark.selectionStarted();
33 } 39 }
34 40
35 function selectionSucceeded(message) 41 function selectionSucceeded(message)
36 { 42 {
37 Aardvark.selectionSucceeded(message.data); 43 Aardvark.selectionSucceeded(message.data);
38 } 44 }
39 45
40 function selectionStopped(message) 46 function selectionStopped(message)
41 { 47 {
42 Aardvark.selectionStopped(); 48 Aardvark.selectionStopped();
43 } 49 }
44 50
45 /********************************** 51 /**********************************
46 * General element selection code * 52 * General element selection code *
47 **********************************/ 53 **********************************/
48 54
49 let Aardvark = exports.Aardvark = 55 let Aardvark = exports.Aardvark =
50 { 56 {
51 window: null, 57 window: null,
52 browser: null, 58 browser: null,
53 rememberedWrapper: null, 59 rememberedWrapper: null,
saroyanm 2016/11/23 17:44:37 Curious: Why rememberedWrapper, but not just wrapp
Wladimir Palant 2016/11/24 14:02:00 Its a temporary state, a bit of a hack so that we
54 mouseX: -1, 60 mouseX: -1,
55 mouseY: -1, 61 mouseY: -1,
56 commandLabelTimer: null, 62 commandLabelTimer: null,
57 viewSourceTimer: null, 63 viewSourceTimer: null,
58 64
59 start: function(wrapper) 65 start: function(wrapper)
60 { 66 {
61 this.rememberedWrapper = wrapper; 67 this.rememberedWrapper = wrapper;
62 let browser = wrapper.browser; 68 let browser = wrapper.browser;
63 if ("selectedBrowser" in browser) 69 if ("selectedBrowser" in browser)
saroyanm 2016/11/23 17:44:38 What is "selectedBrowser" property ? Are we assig
Wladimir Palant 2016/11/24 14:02:01 You need to look at https://developer.mozilla.org/
64 browser = browser.selectedBrowser; 70 browser = browser.selectedBrowser;
65 messageManager.broadcastAsyncMessage( 71 messageManager.broadcastAsyncMessage(
66 "ElemHideHelper:StartSelection", 72 "ElemHideHelper:StartSelection",
67 browser.outerWindowID 73 browser.outerWindowID
68 ); 74 );
69 }, 75 },
70 76
71 selectionStarted: function() 77 selectionStarted: function()
72 { 78 {
73 let wrapper = this.rememberedWrapper; 79 let wrapper = this.rememberedWrapper;
74 this.rememberedWrapper = null; 80 this.rememberedWrapper = null;
75 81
76 this.window = wrapper.window; 82 this.window = wrapper.window;
77 this.browser = wrapper.browser; 83 this.browser = wrapper.browser;
saroyanm 2016/11/23 17:44:38 We already assigning this.rememberedWrapper value
Wladimir Palant 2016/11/24 14:02:01 No, we are only assigning it to the local browser
78 E = id => wrapper.E(id); 84 E = id => wrapper.E(id);
79 85
80 this.browser.addEventListener("keypress", this.onKeyPress, true); 86 this.browser.addEventListener("keypress", this.onKeyPress, true);
81 this.browser.addEventListener("mousemove", this.onMouseMove, false); 87 this.browser.addEventListener("mousemove", this.onMouseMove, false);
82 this.browser.addEventListener("select", this.onTabSelect, false); 88 this.browser.addEventListener("select", this.onTabSelect, false);
83 89
84 this.initHelpBox(); 90 this.initHelpBox();
85 91
86 if (Prefs.showhelp) 92 if (Prefs.showhelp)
87 this.showMenu(); 93 this.showMenu();
88 }, 94 },
89 95
90 selectionSucceeded: function(nodeInfo) 96 selectionSucceeded: function(nodeInfo)
91 { 97 {
92 this.window.openDialog("chrome://elemhidehelper/content/composer.xul", 98 this.window.openDialog("chrome://elemhidehelper/content/composer.xul",
saroyanm 2016/11/23 17:44:37 Shouldn't we also remove eventlisteners on selecti
Wladimir Palant 2016/11/24 14:02:01 No, the select command (in lib/child/commands.js)
93 "_blank", "chrome,centerscreen,resizable,dialog=no", nodeInfo); 99 "_blank", "chrome,centerscreen,resizable,dialog=no", nodeInfo);
Wladimir Palant 2016/11/17 13:54:47 This function is pretty much what Aardvark.select(
saroyanm 2016/11/23 17:44:38 Acknowledged.
94 }, 100 },
95 101
96 selectionStopped: function() 102 selectionStopped: function()
97 { 103 {
98 if (!this.browser) 104 if (!this.browser)
99 return; 105 return;
100 106
101 if (this.commandLabelTimer) 107 if (this.commandLabelTimer)
102 this.commandLabelTimer.cancel(); 108 this.commandLabelTimer.cancel();
103 if (this.viewSourceTimer) 109 if (this.viewSourceTimer)
104 this.viewSourceTimer.cancel(); 110 this.viewSourceTimer.cancel();
105 this.commandLabelTimer = null; 111 this.commandLabelTimer = null;
106 this.viewSourceTimer = null; 112 this.viewSourceTimer = null;
107 113
108 this.hideTooltips(); 114 this.hideTooltips();
109 115
110 this.browser.removeEventListener("keypress", this.onKeyPress, true); 116 this.browser.removeEventListener("keypress", this.onKeyPress, true);
111 this.browser.removeEventListener("mousemove", this.onMouseMove, false); 117 this.browser.removeEventListener("mousemove", this.onMouseMove, false);
112 this.browser.removeEventListener("select", this.onTabSelect, false); 118 this.browser.removeEventListener("select", this.onTabSelect, false);
113 119
114 this.window = null; 120 this.window = null;
115 this.browser = null; 121 this.browser = null;
116 E = id => null; 122 E = id => null;
Wladimir Palant 2016/11/17 13:54:47 This function is what Aardvark.quit() used to be.
saroyanm 2016/11/23 17:44:37 Acknowledged.
117 }, 123 },
118 124
119 doCommand: function(command, event) 125 doCommand: function(command, event)
120 { 126 {
121 let showFeedback; 127 let showFeedback;
122 if (this.hasOwnProperty(command)) 128 if (this.hasOwnProperty(command))
123 showFeedback = this[command](); 129 showFeedback = this[command]();
Wladimir Palant 2016/11/17 13:54:47 The command handler no longer gets the selected el
saroyanm 2016/11/23 17:44:38 Acknowledged.
124 else 130 else
125 { 131 {
126 showFeedback = (command != "select" && command != "quit"); 132 showFeedback = (command != "select" && command != "quit");
Wladimir Palant 2016/11/17 13:54:47 This changes behavior slightly - e.g. you will get
saroyanm 2016/11/23 17:44:37 Acknowledged.
127 messageManager.broadcastAsyncMessage("ElemHideHelper:Command", command); 133 messageManager.broadcastAsyncMessage("ElemHideHelper:Command", command);
128 } 134 }
129 135
130 if (showFeedback) 136 if (showFeedback)
131 { 137 {
132 this.showCommandLabel(this.commands[command + "_key"], this.commands[comma nd + "_altkey"], this.commands[command + "_label"]); 138 this.showCommandLabel(this.commands[command + "_key"], this.commands[comma nd + "_altkey"], this.commands[command + "_label"]);
133 if (event) 139 if (event)
134 event.stopPropagation(); 140 event.stopPropagation();
135 } 141 }
136 if (event) 142 if (event)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 tooltip.hidePopup(); 213 tooltip.hidePopup();
208 } 214 }
209 }, 215 },
210 216
211 onKeyPress: function(event) 217 onKeyPress: function(event)
212 { 218 {
213 if (event.altKey || event.ctrlKey || event.metaKey) 219 if (event.altKey || event.ctrlKey || event.metaKey)
214 return; 220 return;
215 221
216 var command = null; 222 var command = null;
217 if (event.keyCode == event.DOM_VK_ESCAPE) 223 if (event.keyCode == event.DOM_VK_ESCAPE)
saroyanm 2016/11/23 17:44:38 Note: keyCode is a deprecated property. You want m
Wladimir Palant 2016/11/24 14:02:01 Yes, definitely.
saroyanm 2016/11/25 16:18:13 Done -> #4666
218 command = "quit"; 224 command = "quit";
219 else if (event.keyCode == event.DOM_VK_RETURN) 225 else if (event.keyCode == event.DOM_VK_RETURN)
220 command = "select"; 226 command = "select";
221 else if (event.charCode) 227 else if (event.charCode)
222 { 228 {
223 var key = String.fromCharCode(event.charCode).toLowerCase(); 229 var key = String.fromCharCode(event.charCode).toLowerCase();
224 var commands = this.commands; 230 var commands = this.commands;
225 for (var i = 0; i < commands.length; i++) 231 for (var i = 0; i < commands.length; i++)
226 if (commands[commands[i] + "_key"] == key || commands[commands[i] + "_al tkey"] == key) 232 if (commands[commands[i] + "_key"] == key || commands[commands[i] + "_al tkey"] == key)
227 command = commands[i]; 233 command = commands[i];
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 "viewSourceWindow", 272 "viewSourceWindow",
267 "showMenu" 273 "showMenu"
268 ], 274 ],
269 275
270 viewSource: function(elem) 276 viewSource: function(elem)
271 { 277 {
272 if (!elem) 278 if (!elem)
273 return false; 279 return false;
274 280
275 var sourceBox = E("ehh-viewsource"); 281 var sourceBox = E("ehh-viewsource");
276 if (sourceBox.state == "open") 282 if (sourceBox.state == "open")
Wladimir Palant 2016/11/17 13:54:47 This is a behavior change, originally we would onl
277 { 283 {
278 sourceBox.hidePopup(); 284 sourceBox.hidePopup();
279 return true; 285 return true;
280 } 286 }
281 sourceBox.hidePopup(); 287 sourceBox.hidePopup();
282 288
283 while (sourceBox.firstElementChild) 289 while (sourceBox.firstElementChild)
284 sourceBox.removeChild(sourceBox.firstElementChild); 290 sourceBox.removeChild(sourceBox.firstElementChild);
285 this.getOuterHtmlFormatted(elem, sourceBox); 291 this.getOuterHtmlFormatted(elem, sourceBox);
286 292
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 // Show help box 428 // Show help box
423 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); 429 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft");
424 return true; 430 return true;
425 } 431 }
426 } 432 }
427 433
428 // Makes sure event handlers like Aardvark.onKeyPress always have the correct 434 // Makes sure event handlers like Aardvark.onKeyPress always have the correct
429 // this pointer set. 435 // this pointer set.
430 for (let method of ["onKeyPress", "onMouseMove", "onTabSelect"]) 436 for (let method of ["onKeyPress", "onMouseMove", "onTabSelect"])
431 Aardvark[method] = Aardvark[method].bind(Aardvark); 437 Aardvark[method] = Aardvark[method].bind(Aardvark);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld