| OLD | NEW |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | 4 |
| 5 Cu.import("resource://gre/modules/Services.jsm"); | 5 Cu.import("resource://gre/modules/Services.jsm"); |
| 6 Cu.import("resource://gre/modules/FileUtils.jsm"); | 6 Cu.import("resource://gre/modules/FileUtils.jsm"); |
| 7 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 7 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
| 8 | 8 |
| 9 // Import prefs from old branch if there are any | 9 // Import prefs from old branch if there are any |
| 10 let {Prefs} = require("prefs"); | 10 let {Prefs} = require("prefs"); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 { | 69 { |
| 70 // window.Browser.addTab(url, true); | 70 // window.Browser.addTab(url, true); |
| 71 // No firstrun on Fennec. | 71 // No firstrun on Fennec. |
| 72 } | 72 } |
| 73 else if ("gBrowser" in window) | 73 else if ("gBrowser" in window) |
| 74 window.gBrowser.loadOneTab(url, {inBackground: false}); | 74 window.gBrowser.loadOneTab(url, {inBackground: false}); |
| 75 } | 75 } |
| 76 | 76 |
| 77 require("typedItCollector").onBrowserInitialized(window); | 77 require("typedItCollector").onBrowserInitialized(window); |
| 78 } | 78 } |
| 79 | |
| 80 var URLFIXER = { | |
| 81 load : function () { | |
| 82 document.addEventListener("URLFixerNetErrorCorrection", URLFIXER.netErrorCor
rection, false, true); | |
| 83 }, | |
| 84 | |
| 85 netErrorCorrection : function (evt) { | |
| 86 var button = evt.target; | |
| 87 var oldUrl = button.getAttribute("old"); | |
| 88 var newUrl = button.getAttribute("new"); | |
| 89 | |
| 90 if (newUrl.indexOf("http://") == -1 && newUrl.indexOf("https://") == -1) { | |
| 91 newUrl = oldUrl.split("//")[0] + "//" + newUrl; | |
| 92 } | |
| 93 | |
| 94 var rv = newUrl; | |
| 95 | |
| 96 var oldParts = oldUrl.split("://"); | |
| 97 var newParts = newUrl.split("://"); | |
| 98 | |
| 99 // Discard the protocol if they're the same. | |
| 100 if (oldParts[0] == newParts[0]) { | |
| 101 oldParts.shift(); | |
| 102 newParts.shift(); | |
| 103 oldUrl = "//" + oldParts.join("//"); | |
| 104 newUrl = "//" + newParts.join("//"); | |
| 105 } | |
| 106 | |
| 107 // Ignore www subdomain if both of them have it. | |
| 108 if (oldUrl.indexOf("//www.") != -1 && (oldUrl.indexOf("//www.") === newUrl.i
ndexOf("//www."))) { | |
| 109 oldUrl = oldUrl.split("//www.")[1]; | |
| 110 newUrl = newUrl.split("//www.")[1]; | |
| 111 } | |
| 112 | |
| 113 // Ignore trailing slashes | |
| 114 if (oldUrl.charAt(oldUrl.length - 1) == "/" && newUrl.charAt(newUrl.length -
1) == "/") { | |
| 115 oldUrl = oldUrl.substr(0, oldUrl.length - 1); | |
| 116 newUrl = newUrl.substr(0, newUrl.length - 1); | |
| 117 } | |
| 118 | |
| 119 var corrections = URLFIXER.getJSONPref("custom_replace", {}); | |
| 120 corrections[oldUrl] = newUrl; | |
| 121 URLFIXER.setJSONPref("custom_replace", corrections); | |
| 122 | |
| 123 content.location.href = rv; | |
| 124 } | |
| 125 }; | |
| 126 | |
| OLD | NEW |