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

Side by Side Diff: lib/aardvark.js

Issue 29366556: Issue 2879 - Make "view source in separate window" command work again (Closed) Base URL: https://hg.adblockplus.org/elemhidehelper
Patch Set: Created Dec. 1, 2016, 11:03 a.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 | « no previous file | lib/child/commands.js » ('j') | 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 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
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 this.viewSourceTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITim er); 322 this.viewSourceTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITim er);
323 this.viewSourceTimer.initWithCallback(function() 323 this.viewSourceTimer.initWithCallback(function()
324 { 324 {
325 sourceBox.showPopup(anchor, x, y, "tooltip", "topleft", "topleft"); 325 sourceBox.showPopup(anchor, x, y, "tooltip", "topleft", "topleft");
326 Aardvark.viewSourceTimer = null; 326 Aardvark.viewSourceTimer = null;
327 }, 500, Ci.nsITimer.TYPE_ONE_SHOT); 327 }, 500, Ci.nsITimer.TYPE_ONE_SHOT);
328 }); 328 });
329 return true; 329 return true;
330 }, 330 },
331 331
332 viewSourceWindow: function(elem) 332 viewSourceWindow: function()
333 { 333 {
334 if (!elem) 334 sendMessageWithResponse("ElemHideHelper:GetHTML", null, data =>
335 return false;
336
337 if (Services.vc.compare(Services.appinfo.platformVersion, "43.0") >= 0)
338 { 335 {
339 // After https://bugzilla.mozilla.org/show_bug.cgi?id=1134585 landed, pass
340 // a single object as parameter.
341 this.window.openDialog( 336 this.window.openDialog(
342 "chrome://global/content/viewPartialSource.xul", 337 "chrome://global/content/viewPartialSource.xul",
343 "_blank", "scrollbars,resizable,chrome,dialog=no", 338 "_blank", "scrollbars,resizable,chrome,dialog=no",
344 { 339 {
345 URI: "view-source:data:text/html;charset=utf-8," + encodeURIComponent( elem.outerHTML), 340 URI: "view-source:data:text/html;charset=utf-8," +
341 encodeURIComponent(data.html),
346 drawSelection: false, 342 drawSelection: false,
saroyanm 2016/12/05 18:02:51 Nit: not aligned with the line above.
Wladimir Palant 2016/12/08 13:04:16 It shouldn't be - the line above is indented to in
saroyanm 2016/12/20 14:32:04 Acknowledged.
347 baseURI: elem.ownerDocument.baseURI 343 baseURI: data.baseURI
348 } 344 }
349 ); 345 );
350 } 346 });
351 else
352 {
353 // Before Gecko 43, use positional parameters and a fake selection object.
354 var range = elem.ownerDocument.createRange();
355 range.selectNodeContents(elem);
356 var selection = {rangeCount: 1, getRangeAt: function() {return range}};
357 this.window.openDialog(
358 "chrome://global/content/viewPartialSource.xul",
359 "_blank", "scrollbars,resizable,chrome,dialog=no",
360 null, null, selection, "selection"
361 );
362 }
363 return true; 347 return true;
364 }, 348 },
365 349
366 getOuterHtmlFormatted: function(node, container) 350 getOuterHtmlFormatted: function(node, container)
367 { 351 {
368 let type = node.type; 352 let type = node.type;
369 if (type == "element") 353 if (type == "element")
370 { 354 {
371 let box = this.window.document.createElement("vbox"); 355 let box = this.window.document.createElement("vbox");
372 box.className = "elementBox"; 356 box.className = "elementBox";
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // Show help box 420 // Show help box
437 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); 421 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft");
438 return true; 422 return true;
439 } 423 }
440 } 424 }
441 425
442 // Makes sure event handlers like Aardvark.onKeyPress always have the correct 426 // Makes sure event handlers like Aardvark.onKeyPress always have the correct
443 // this pointer set. 427 // this pointer set.
444 for (let method of ["onKeyPress", "onMouseMove", "onTabSelect"]) 428 for (let method of ["onKeyPress", "onMouseMove", "onTabSelect"])
445 Aardvark[method] = Aardvark[method].bind(Aardvark); 429 Aardvark[method] = Aardvark[method].bind(Aardvark);
430
431 if (Services.vc.compare(Services.appinfo.platformVersion, "43.0") < 0)
432 {
433 // View source window expected the actual node before
434 // https://bugzil.la/1134585 landed, we don't have it so disable the command.
435 let index = Aardvark.commands.indexOf("viewSourceWindow");
436 Aardvark.commands.splice(index, 1);
437 }
OLDNEW
« no previous file with comments | « no previous file | lib/child/commands.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld