Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | function openViewSourceWindow(aURI, aCallback) { |
michael@0 | 6 | let viewSourceWindow = openDialog("chrome://global/content/viewSource.xul", null, null, aURI); |
michael@0 | 7 | viewSourceWindow.addEventListener("pageshow", function pageShowHandler(event) { |
michael@0 | 8 | // Wait for the inner window to load, not viewSourceWindow. |
michael@0 | 9 | if (event.target.location == "view-source:" + aURI) { |
michael@0 | 10 | info("View source window opened: " + event.target.location); |
michael@0 | 11 | viewSourceWindow.removeEventListener("pageshow", pageShowHandler, false); |
michael@0 | 12 | aCallback(viewSourceWindow); |
michael@0 | 13 | } |
michael@0 | 14 | }, false); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function closeViewSourceWindow(aWindow, aCallback) { |
michael@0 | 18 | Services.wm.addListener({ |
michael@0 | 19 | onCloseWindow: function() { |
michael@0 | 20 | Services.wm.removeListener(this); |
michael@0 | 21 | executeSoon(aCallback); |
michael@0 | 22 | } |
michael@0 | 23 | }); |
michael@0 | 24 | aWindow.close(); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function testViewSourceWindow(aURI, aTestCallback, aCloseCallback) { |
michael@0 | 28 | openViewSourceWindow(aURI, function(aWindow) { |
michael@0 | 29 | aTestCallback(aWindow); |
michael@0 | 30 | closeViewSourceWindow(aWindow, aCloseCallback); |
michael@0 | 31 | }); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function openViewPartialSourceWindow(aReference, aCallback) { |
michael@0 | 35 | let viewSourceWindow = openDialog("chrome://global/content/viewPartialSource.xul", |
michael@0 | 36 | null, null, null, null, aReference, "selection"); |
michael@0 | 37 | viewSourceWindow.addEventListener("pageshow", function pageShowHandler(event) { |
michael@0 | 38 | // Wait for the inner window to load, not viewSourceWindow. |
michael@0 | 39 | if (/^view-source:/.test(event.target.location)) { |
michael@0 | 40 | info("View source window opened: " + event.target.location); |
michael@0 | 41 | viewSourceWindow.removeEventListener("pageshow", pageShowHandler, false); |
michael@0 | 42 | aCallback(viewSourceWindow); |
michael@0 | 43 | } |
michael@0 | 44 | }, false); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | registerCleanupFunction(function() { |
michael@0 | 48 | var windows = Services.wm.getEnumerator("navigator:view-source"); |
michael@0 | 49 | ok(!windows.hasMoreElements(), "No remaining view source windows still open"); |
michael@0 | 50 | while (windows.hasMoreElements()) |
michael@0 | 51 | windows.getNext().close(); |
michael@0 | 52 | }); |
michael@0 | 53 | |
michael@0 | 54 | function openDocument(aURI, aCallback) { |
michael@0 | 55 | let tab = gBrowser.addTab(aURI); |
michael@0 | 56 | let browser = tab.linkedBrowser; |
michael@0 | 57 | browser.addEventListener("DOMContentLoaded", function pageLoadedListener() { |
michael@0 | 58 | browser.removeEventListener("DOMContentLoaded", pageLoadedListener, false); |
michael@0 | 59 | aCallback(tab); |
michael@0 | 60 | }, false); |
michael@0 | 61 | registerCleanupFunction(function() { |
michael@0 | 62 | gBrowser.removeTab(tab); |
michael@0 | 63 | }); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function openDocumentSelect(aURI, aCSSSelector, aCallback) { |
michael@0 | 67 | openDocument(aURI, function(aTab) { |
michael@0 | 68 | let element = aTab.linkedBrowser.contentDocument.querySelector(aCSSSelector); |
michael@0 | 69 | let selection = aTab.linkedBrowser.contentWindow.getSelection(); |
michael@0 | 70 | selection.selectAllChildren(element); |
michael@0 | 71 | |
michael@0 | 72 | openViewPartialSourceWindow(selection, aCallback); |
michael@0 | 73 | }); |
michael@0 | 74 | } |