Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of the URL Fixer, | 2 * This file is part of the URL Fixer, |
3 * Copyright (C) 2006-2012 Eyeo GmbH | 3 * Copyright (C) 2006-2012 Eyeo GmbH |
4 * | 4 * |
5 * URL Fixer is free software: you can redistribute it and/or modify | 5 * URL Fixer is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * URL Fixer is distributed in the hope that it will be useful, | 9 * URL Fixer is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with URL Fixer. If not, see <http://www.gnu.org/licenses/>. | 15 * along with URL Fixer. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 let {Prefs} = require("prefs"); | 18 let {Prefs} = require("prefs"); |
19 let {WindowObserver} = require("windowObserver"); | |
19 let appIntegration = require("typoAppIntegration"); | 20 let appIntegration = require("typoAppIntegration"); |
20 let {onWhitelistEntryRemoved} = require("typoRules"); | 21 let {onWhitelistEntryRemoved} = require("typoRules"); |
21 let {processUserCorrection} = require("typoCollector"); | 22 let {processUserCorrection} = require("typoCollector"); |
22 | 23 |
23 // Load HTML code to add to network error pages | 24 // Load HTML code to add to network error pages |
24 let netErrorOverlay = null; | 25 let netErrorOverlay = null; |
25 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.ns IXMLHttpRequest); | 26 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.ns IXMLHttpRequest); |
26 request.open("GET", "chrome://" + require("info").addonName + "/content/netError .xhtml"); | 27 request.open("GET", "chrome://" + require("info").addonName + "/content/netError .xhtml"); |
27 request.addEventListener("load", function(event) | 28 request.addEventListener("load", function(event) |
28 { | 29 { |
29 netErrorOverlay = event.target.responseXML; | 30 netErrorOverlay = event.target.responseXML; |
31 | |
32 new WindowObserver({ | |
33 applyToWindow: function(window) | |
34 { | |
35 if (!appIntegration.isKnownWindow(window)) | |
36 return; | |
37 | |
38 let browser = appIntegration.getBrowser(window); | |
39 if (browser) | |
40 browser.addEventListener("DOMContentLoaded", handlePageLoad, false); | |
41 }, | |
42 | |
43 removeFromWindow: function(window) | |
44 { | |
45 if (!appIntegration.isKnownWindow(window)) | |
46 return; | |
47 | |
48 let browser = appIntegration.getBrowser(window); | |
49 if (browser) | |
50 { | |
51 browser.removeEventListener("DOMContentLoaded", handlePageLoad, false); | |
52 if (browser.browsers) | |
53 { | |
54 for (let i = 0; i < browser.browsers.length; i++) | |
55 { | |
56 let contentWnd = browser.browsers[i].contentWindow; | |
57 if (contentWnd.document.documentURI.indexOf("about:neterror?") == 0) | |
58 removeFromNetErrorPage(contentWnd); | |
59 } | |
60 } | |
61 } | |
62 } | |
63 }); | |
30 }, false); | 64 }, false); |
31 request.send(null); | 65 request.send(null); |
32 | |
33 exports.applyToWindow = applyToWindow; | |
Wladimir Palant
2012/12/13 16:07:00
How about netError uses its own WindowObserver so
Thomas Greiner
2013/01/14 10:06:41
Done.
| |
34 function applyToWindow(window) | |
35 { | |
36 let browser = appIntegration.getBrowser(window); | |
37 if (browser) | |
38 browser.addEventListener("DOMContentLoaded", handlePageLoad, false); | |
39 } | |
40 | |
41 exports.removeFromWindow = removeFromWindow; | |
42 function removeFromWindow(window) | |
43 { | |
44 let browser = appIntegration.getBrowser(window); | |
45 if (browser) | |
46 { | |
47 browser.removeEventListener("DOMContentLoaded", handlePageLoad, false); | |
48 if (browser.browsers) | |
49 { | |
50 for (let i = 0; i < browser.browsers.length; i++) | |
51 { | |
52 let contentWnd = browser.browsers[i].contentWindow; | |
53 if (contentWnd.document.documentURI.indexOf("about:neterror?") == 0) | |
54 removeFromNetErrorPage(contentWnd); | |
55 } | |
56 } | |
57 } | |
58 } | |
59 | 66 |
60 function handlePageLoad(event) | 67 function handlePageLoad(event) |
61 { | 68 { |
62 let document = event.target; | 69 let document = event.target; |
63 if (document.documentURI.indexOf("about:neterror?") != 0 || | 70 if (document.documentURI.indexOf("about:neterror?") != 0 || |
64 document.documentURI.indexOf("e=netOffline") > 0 || | 71 document.documentURI.indexOf("e=netOffline") > 0 || |
65 document.documentURI.indexOf("e=notCached") > 0) | 72 document.documentURI.indexOf("e=notCached") > 0) |
66 { | 73 { |
67 return; | 74 return; |
68 } | 75 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 overlay.parentNode.removeChild(overlay); | 129 overlay.parentNode.removeChild(overlay); |
123 } | 130 } |
124 | 131 |
125 function parseURL(url) | 132 function parseURL(url) |
126 { | 133 { |
127 if (/^\s*((?:\w+:)?\/*(?:[^\/#]*@)?)([^\/:#]*)/.test(url)) | 134 if (/^\s*((?:\w+:)?\/*(?:[^\/#]*@)?)([^\/:#]*)/.test(url)) |
128 return [RegExp.$1, RegExp.$2.toLowerCase(), RegExp.rightContext]; | 135 return [RegExp.$1, RegExp.$2.toLowerCase(), RegExp.rightContext]; |
129 else | 136 else |
130 return [url, null, null]; | 137 return [url, null, null]; |
131 } | 138 } |
LEFT | RIGHT |