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/XPCOMUtils.jsm"); | 6 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
7 | 7 |
8 let {Prefs} = require("prefs"); | 8 let {Prefs} = require("prefs"); |
9 let {WindowObserver} = require("windowObserver"); | 9 let {WindowObserver} = require("windowObserver"); |
10 let {getSchemeCorrection, isKnownScheme, getDomainCorrection, getDomainReferral}
= require("rules"); | 10 let {getSchemeCorrection, isKnownScheme, getDomainCorrection, getDomainReferral}
= require("rules"); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 catch (e) | 137 catch (e) |
138 { | 138 { |
139 return (e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS); | 139 return (e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 function correctURL(window, value) | 143 function correctURL(window, value) |
144 { | 144 { |
145 let hasCorrection = false; | 145 let hasCorrection = false; |
146 | 146 |
147 value = value.trim(); | 147 value = value.trim(); |
148 if (value.length == 0) | 148 if (value.length == 0) |
149 return null; | 149 return null; |
150 | 150 |
151 // Replace backslashes | 151 // Replace backslashes |
152 value = value.replace(/\\/g, "/"); | 152 value = value.replace(/\\/g, "/"); |
153 | 153 |
154 // Does the URL scheme need correcting? | 154 // Does the URL scheme need correcting? |
155 if (/^([^\/]+)(\/.*)/.test(value)) | 155 if (/^([^\/]+)(\/.*)/.test(value)) |
156 { | 156 { |
(...skipping 15 matching lines...) Expand all Loading... |
172 if ("getShortcutOrURI" in window && window.getShortcutOrURI(value) != value) | 172 if ("getShortcutOrURI" in window && window.getShortcutOrURI(value) != value) |
173 return null; | 173 return null; |
174 | 174 |
175 // Spaces before the first slash or period is probably a quick search | 175 // Spaces before the first slash or period is probably a quick search |
176 if (/^[^\/\.\s]+\s/.test(value)) | 176 if (/^[^\/\.\s]+\s/.test(value)) |
177 return null; | 177 return null; |
178 | 178 |
179 // Check manually entered corrections | 179 // Check manually entered corrections |
180 if (Prefs.custom_replace.hasOwnProperty(value) && Prefs.custom_replace[value]) | 180 if (Prefs.custom_replace.hasOwnProperty(value) && Prefs.custom_replace[value]) |
181 return Prefs.custom_replace[value]; | 181 return Prefs.custom_replace[value]; |
182 | 182 |
183 let [prefix, domain, suffix] = parseURL(value); | 183 let [prefix, domain, suffix] = parseURL(value); |
184 if (!domain) | 184 if (!domain) |
185 return null; | 185 return null; |
186 | 186 |
187 let oldDomain = domain; | 187 let oldDomain = domain; |
188 if (!isIPAddress(domain)) | 188 if (!isIPAddress(domain)) |
189 { | 189 { |
190 processTypedDomain(domain); | 190 processTypedDomain(domain); |
191 | 191 |
192 let newDomain = getDomainCorrection(domain); | 192 let newDomain = getDomainCorrection(domain); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 { | 240 { |
241 // Yes: Do nothing | 241 // Yes: Do nothing |
242 } | 242 } |
243 }, | 243 }, |
244 { | 244 { |
245 label: no, | 245 label: no, |
246 accessKey: null, | 246 accessKey: null, |
247 callback: function() | 247 callback: function() |
248 { | 248 { |
249 // No: Add to list of corrections (ignore) | 249 // No: Add to list of corrections (ignore) |
250 if (/^www\./.test(value)) | 250 let {onWhitelistEntryAdded} = require("rules"); |
251 { | 251 let entry = oldDomain.replace(/^www\./, ""); |
252 value = value.substr(4); | 252 Prefs.whitelist[entry] = true; |
253 } | 253 onWhitelistEntryAdded(entry); |
254 Prefs.whitelist[value] = value; | |
255 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist)); | 254 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist)); |
256 | 255 |
257 require("appIntegration").loadURI(value); | 256 require("appIntegration").loadURI(window, value); |
258 processFalsePositive(oldDomain, domain); | 257 processFalsePositive(oldDomain, domain); |
259 } | 258 } |
260 } | 259 } |
261 ]; | 260 ]; |
262 require("appIntegration").openInfobar(window, "url-fixer-infobar-askafter", me
ssage, buttons, 1); | 261 require("appIntegration").openInfobar(window, "url-fixer-infobar-askafter", me
ssage, buttons, 1); |
263 | 262 |
264 require("survey").incrementCorrectionsCounter(); | 263 require("survey").incrementCorrectionsCounter(); |
265 | 264 |
266 // Consider the correction a second typed domain | 265 // Consider the correction a second typed domain |
267 if (!isIPAddress(domain)) | 266 if (!isIPAddress(domain)) |
(...skipping 12 matching lines...) Expand all Loading... |
280 let result = [ | 279 let result = [ |
281 stringBundle.GetStringFromName("urlfixer.isItCorrect"), | 280 stringBundle.GetStringFromName("urlfixer.isItCorrect"), |
282 stringBundle.GetStringFromName("urlfixer.yes"), | 281 stringBundle.GetStringFromName("urlfixer.yes"), |
283 stringBundle.GetStringFromName("urlfixer.no"), | 282 stringBundle.GetStringFromName("urlfixer.no"), |
284 stringBundle.GetStringFromName("urlfixer.cancel") | 283 stringBundle.GetStringFromName("urlfixer.cancel") |
285 ]; | 284 ]; |
286 | 285 |
287 getInfobarTexts = function() result; | 286 getInfobarTexts = function() result; |
288 return getInfobarTexts(); | 287 return getInfobarTexts(); |
289 } | 288 } |
OLD | NEW |