OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the URL Fixer, | 2 * This file is part of the URL Fixer, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 Cu.import("resource://gre/modules/Services.jsm"); | 18 Cu.import("resource://gre/modules/Services.jsm"); |
19 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 19 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
20 | 20 |
21 let {Prefs} = require("prefs"); | 21 let {Prefs} = require("prefs"); |
22 let {WindowObserver} = require("windowObserver"); | 22 let {WindowObserver} = require("windowObserver"); |
23 let {getSchemeCorrection, isKnownScheme, getDomainCorrection, getDomainReferral,
onWhitelistEntryAdded} = require("typoRules"); | 23 let {getSchemeCorrection, isKnownScheme, getDomainCorrection, getDomainReferral,
onWhitelistEntryAdded} = require("typoRules"); |
24 let {processTypedDomain, processDomainCorrection, processFalsePositive} = requir
e("typoCollector"); | |
25 let appIntegration = require("typoAppIntegration"); | 24 let appIntegration = require("typoAppIntegration"); |
26 let netError = require("typoNetError"); | 25 let netError = require("typoNetError"); |
27 | 26 |
28 let typoWindowObserver = null; | 27 let typoWindowObserver = null; |
29 | 28 |
30 exports.attachWindowObserver = attachWindowObserver; | 29 exports.attachWindowObserver = attachWindowObserver; |
31 function attachWindowObserver() | 30 function attachWindowObserver() |
32 { | 31 { |
33 if (typoWindowObserver) | 32 if (typoWindowObserver) |
34 return; | 33 return; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 let [prefix, domain, suffix] = parseURL(value); | 124 let [prefix, domain, suffix] = parseURL(value); |
126 if (!domain) | 125 if (!domain) |
127 return null; | 126 return null; |
128 | 127 |
129 let oldDomain = domain; | 128 let oldDomain = domain; |
130 if (!isIPAddress(domain)) | 129 if (!isIPAddress(domain)) |
131 { | 130 { |
132 // Remove . at end of domain for fully qualified domain names | 131 // Remove . at end of domain for fully qualified domain names |
133 domain = domain.replace(/\.$/, ""); | 132 domain = domain.replace(/\.$/, ""); |
134 | 133 |
135 processTypedDomain(domain); | |
136 | |
137 let newDomain = getDomainCorrection(domain); | 134 let newDomain = getDomainCorrection(domain); |
138 if (newDomain != domain) | 135 if (newDomain != domain) |
139 { | 136 { |
140 processDomainCorrection(domain, newDomain); | |
141 domain = newDomain; | 137 domain = newDomain; |
142 hasCorrection = true; | 138 hasCorrection = true; |
143 | 139 |
144 let referral = getDomainReferral(domain.replace(/^www\./, "")); | 140 let referral = getDomainReferral(domain.replace(/^www\./, "")); |
145 if (referral) | 141 if (referral) |
146 { | 142 { |
147 // We need to add a query string parameter when sending users to this do
main | 143 // We need to add a query string parameter when sending users to this do
main |
148 let anchorIndex = suffix.indexOf("#"); | 144 let anchorIndex = suffix.indexOf("#"); |
149 let anchor = ""; | 145 let anchor = ""; |
150 if (anchorIndex >= 0) | 146 if (anchorIndex >= 0) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 accessKey: "", | 191 accessKey: "", |
196 callback: function() | 192 callback: function() |
197 { | 193 { |
198 // No: Add to list of corrections (ignore) | 194 // No: Add to list of corrections (ignore) |
199 let entry = oldDomain.replace(/^www\./, ""); | 195 let entry = oldDomain.replace(/^www\./, ""); |
200 Prefs.whitelist[entry] = true; | 196 Prefs.whitelist[entry] = true; |
201 onWhitelistEntryAdded(entry); | 197 onWhitelistEntryAdded(entry); |
202 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist)); | 198 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist)); |
203 | 199 |
204 appIntegration.loadURI(window, value); | 200 appIntegration.loadURI(window, value); |
205 processFalsePositive(domain, oldDomain); | |
206 } | 201 } |
207 } | 202 } |
208 ]; | 203 ]; |
209 // We need to have persistence being set to 1 due to redirect which happens af
terwards | 204 // We need to have persistence being set to 1 due to redirect which happens af
terwards |
210 appIntegration.openInfobar(window, require("info").addonName + "-infobar-askaf
ter", message, buttons, 1); | 205 appIntegration.openInfobar(window, require("info").addonName + "-infobar-askaf
ter", message, buttons, 1); |
211 | 206 |
212 require("typoSurvey").incrementCorrectionsCounter(); | 207 require("typoSurvey").incrementCorrectionsCounter(); |
213 | 208 |
214 return prefix + domain + suffix; | 209 return prefix + domain + suffix; |
215 } | 210 } |
216 | 211 |
217 let stringBundle = null; | 212 let stringBundle = null; |
218 | 213 |
219 function getInfobarTexts() | 214 function getInfobarTexts() |
220 { | 215 { |
221 // Randomize URI to work around bug 719376 | 216 // Randomize URI to work around bug 719376 |
222 if (!stringBundle) | 217 if (!stringBundle) |
223 stringBundle = Services.strings.createBundle("chrome://" + require("info").a
ddonName + "/locale/typo.properties?" + Math.random()); | 218 stringBundle = Services.strings.createBundle("chrome://" + require("info").a
ddonName + "/locale/typo.properties?" + Math.random()); |
224 let result = [ | 219 let result = [ |
225 stringBundle.GetStringFromName("urlfixer.isItCorrect"), | 220 stringBundle.GetStringFromName("urlfixer.isItCorrect"), |
226 stringBundle.GetStringFromName("urlfixer.yes"), | 221 stringBundle.GetStringFromName("urlfixer.yes"), |
227 stringBundle.GetStringFromName("urlfixer.no") | 222 stringBundle.GetStringFromName("urlfixer.no") |
228 ]; | 223 ]; |
229 | 224 |
230 getInfobarTexts = () => result; | 225 getInfobarTexts = () => result; |
231 return getInfobarTexts(); | 226 return getInfobarTexts(); |
232 } | 227 } |
OLD | NEW |