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

Side by Side Diff: lib/aardvark.js

Issue 29352667: Issue 4398 - Fix "view source in a separate window" command (Closed) Base URL: https://hg.adblockplus.org/elemhidehelper
Patch Set: Created Sept. 12, 2016, 12:36 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
« no previous file with comments | « no previous file | no next file » | 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", {});
8
7 let {Prefs} = require("prefs"); 9 let {Prefs} = require("prefs");
8 10
9 // Make sure to stop selection when we are uninstalled 11 // Make sure to stop selection when we are uninstalled
10 onShutdown.add(() => Aardvark.quit()); 12 onShutdown.add(() => Aardvark.quit());
11 13
12 // To be replaced when selection starts 14 // To be replaced when selection starts
13 function E(id) {return null;} 15 function E(id) {return null;}
14 16
15 let messageCounter = 0; 17 let messageCounter = 0;
16 18
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 Aardvark.viewSourceTimer = null; 691 Aardvark.viewSourceTimer = null;
690 }, 500, Ci.nsITimer.TYPE_ONE_SHOT); 692 }, 500, Ci.nsITimer.TYPE_ONE_SHOT);
691 return true; 693 return true;
692 }, 694 },
693 695
694 viewSourceWindow: function(elem) 696 viewSourceWindow: function(elem)
695 { 697 {
696 if (!elem) 698 if (!elem)
697 return false; 699 return false;
698 700
699 var range = elem.ownerDocument.createRange(); 701 if (Services.vc.compare(Services.appinfo.platformVersion, "43.0") >= 0)
700 range.selectNodeContents(elem); 702 {
701 var selection = {rangeCount: 1, getRangeAt: function() {return range}}; 703 // After https://bugzilla.mozilla.org/show_bug.cgi?id=1134585 landed, pass
702 704 // a single object as parameter.
703 this.window.openDialog("chrome://global/content/viewPartialSource.xul", "_bl ank", "scrollbars,resizable,chrome,dialog=no", 705 this.window.openDialog(
704 null, null, selection, "selection"); 706 "chrome://global/content/viewPartialSource.xul",
707 "_blank", "scrollbars,resizable,chrome,dialog=no",
708 {
709 URI: "view-source:data:text/html;charset=utf-8," + encodeURIComponent( elem.outerHTML),
kzar 2016/09/13 09:49:26 How come URI, drawSelection and baseURI are added
Wladimir Palant 2016/09/13 10:32:08 You have to look at the changes introduced in http
kzar 2016/09/13 12:06:50 That makes sense, thanks for explaining. (I tried
710 drawSelection: false,
711 baseURI: elem.ownerDocument.baseURI
712 }
713 );
714 }
715 else
716 {
717 // Before Gecko 43, use positional parameters and a fake selection object.
718 var range = elem.ownerDocument.createRange();
719 range.selectNodeContents(elem);
720 var selection = {rangeCount: 1, getRangeAt: function() {return range}};
721 this.window.openDialog(
722 "chrome://global/content/viewPartialSource.xul",
723 "_blank", "scrollbars,resizable,chrome,dialog=no",
724 null, null, selection, "selection"
725 );
726 }
705 return true; 727 return true;
706 }, 728 },
707 729
708 getOuterHtmlFormatted: function(node, container) 730 getOuterHtmlFormatted: function(node, container)
709 { 731 {
710 var type = null; 732 var type = null;
711 switch (node.nodeType) 733 switch (node.nodeType)
712 { 734 {
713 case node.ELEMENT_NODE: 735 case node.ELEMENT_NODE:
714 var box = this.window.document.createElement("vbox"); 736 var box = this.window.document.createElement("vbox");
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // Show help box 819 // Show help box
798 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); 820 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft");
799 return true; 821 return true;
800 } 822 }
801 } 823 }
802 824
803 // Makes sure event handlers like Aardvark.onKeyPress always have the correct 825 // Makes sure event handlers like Aardvark.onKeyPress always have the correct
804 // this pointer set. 826 // this pointer set.
805 for (let method of ["onMouseClick", "onMouseScroll", "onKeyPress", "onPageHide", "onMouseMove", "onAfterPaint", "quit"]) 827 for (let method of ["onMouseClick", "onMouseScroll", "onKeyPress", "onPageHide", "onMouseMove", "onAfterPaint", "quit"])
806 Aardvark[method] = Aardvark[method].bind(Aardvark); 828 Aardvark[method] = Aardvark[method].bind(Aardvark);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld