| 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-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 {hook} = require("hooks"); | 18 let {hook} = require("hooks"); | 
|  | 19 let {application, addonName} = require("info"); | 
|  | 20 | 
| 19 let functionHooks = new WeakMap(); | 21 let functionHooks = new WeakMap(); | 
| 20 | 22 | 
| 21 exports.removeFromWindow = function(window) | 23 exports.removeFromWindow = function(window) | 
| 22 { | 24 { | 
| 23   if (functionHooks.has(window)) | 25   if (functionHooks.has(window)) | 
| 24   { | 26   { | 
| 25     let unhook = functionHooks.get(window); | 27     let unhook = functionHooks.get(window); | 
| 26     unhook(); | 28     unhook(); | 
| 27     functionHooks.delete(window); | 29     functionHooks.delete(window); | 
| 28   } | 30   } | 
| 29 }; | 31 }; | 
| 30 | 32 | 
| 31 let {application} = require("info"); | 33 switch (addonName) | 
|  | 34 { | 
|  | 35   case "url-fixer": | 
|  | 36   { | 
|  | 37     // URL Fixer | 
|  | 38     exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix) t
     rue; | 
|  | 39 | 
|  | 40     break; | 
|  | 41   } | 
|  | 42   case "adblockplus": | 
|  | 43   { | 
|  | 44     // Adblock Plus | 
|  | 45     let {Prefs} = require("prefs"); | 
|  | 46 | 
|  | 47     // Do not ask to opt-in if user found setting | 
|  | 48     if (!Prefs.correctTyposAsked) | 
|  | 49     { | 
|  | 50       let onPrefChange = function(name) | 
|  | 51       { | 
|  | 52         if (name == "correctTypos") | 
|  | 53         { | 
|  | 54           Prefs.correctTyposAsked = true; | 
|  | 55           Prefs.removeListener(onPrefChange); | 
|  | 56         } | 
|  | 57       } | 
|  | 58 | 
|  | 59       Prefs.addListener(onPrefChange); | 
|  | 60     } | 
|  | 61 | 
|  | 62     exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix) | 
|  | 63     { | 
|  | 64       if (!Prefs.correctTyposAsked && !Prefs.correctTypos) | 
|  | 65       { | 
|  | 66         let {Utils} = require("utils"); | 
|  | 67         let message = Utils.getString("typo_optin_message").replace(/\?1\?/, dom
     ain); | 
|  | 68         let yes = Utils.getString("typo_optin_yes"); | 
|  | 69         let no = Utils.getString("typo_optin_no"); | 
|  | 70         let buttons = [ | 
|  | 71           { | 
|  | 72             label:      yes, | 
|  | 73             accessKey:  null, | 
|  | 74             callback:   function() | 
|  | 75             { | 
|  | 76               // Yes: Enable typo correction | 
|  | 77               Prefs.correctTypos = true; | 
|  | 78               exports.loadURI(window, prefix + domain + suffix); | 
|  | 79               Prefs.correctTyposAsked = true; | 
|  | 80             } | 
|  | 81           }, | 
|  | 82           { | 
|  | 83             label:      no, | 
|  | 84             accessKey:  null, | 
|  | 85             callback:   function() | 
|  | 86             { | 
|  | 87               // No: Do nothing | 
|  | 88               Prefs.correctTyposAsked = true; | 
|  | 89             } | 
|  | 90           } | 
|  | 91         ]; | 
|  | 92         // We need to have persistence being set to 1 due to redirect which happ
     ens afterwards | 
|  | 93         exports.openInfobar(window, "adblockplus-infobar-correct-typos-ask", mes
     sage, buttons, 1); | 
|  | 94       } | 
|  | 95 | 
|  | 96       return Prefs.correctTypos; | 
|  | 97     }; | 
|  | 98 | 
|  | 99     break; | 
|  | 100   } | 
|  | 101 } | 
|  | 102 | 
| 32 switch (application) | 103 switch (application) | 
| 33 { | 104 { | 
| 34   case "firefox": | 105   case "firefox": | 
| 35   { | 106   { | 
| 36     // Firefox | 107     // Firefox | 
| 37     exports.isKnownWindow = function(window) window.document.documentElement.get
     Attribute("windowtype") == "navigator:browser"; | 108     exports.isKnownWindow = function(window) window.document.documentElement.get
     Attribute("windowtype") == "navigator:browser"; | 
| 38 | 109 | 
| 39     exports.getURLBar = function(window) "gURLBar" in window ? window.gURLBar : 
     null; | 110     exports.getURLBar = function(window) "gURLBar" in window ? window.gURLBar : 
     null; | 
| 40 | 111 | 
| 41     exports.getBrowser = function(window) "gBrowser" in window ? window.gBrowser
      : null; | 112     exports.getBrowser = function(window) "gBrowser" in window ? window.gBrowser
      : null; | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 59     exports.openInfobar = function(window, id, message, buttons, persistence) | 130     exports.openInfobar = function(window, id, message, buttons, persistence) | 
| 60     { | 131     { | 
| 61       let browser = exports.getBrowser(window); | 132       let browser = exports.getBrowser(window); | 
| 62       let infobar = browser.getNotificationBox(); | 133       let infobar = browser.getNotificationBox(); | 
| 63       let notification = infobar.getNotificationWithValue(id); | 134       let notification = infobar.getNotificationWithValue(id); | 
| 64 | 135 | 
| 65       if (notification) | 136       if (notification) | 
| 66       { | 137       { | 
| 67         infobar.removeNotification(notification); | 138         infobar.removeNotification(notification); | 
| 68       } | 139       } | 
| 69 |  | 
| 70       notification = infobar.appendNotification( | 140       notification = infobar.appendNotification( | 
| 71         message, | 141         message, | 
| 72         id, | 142         id, | 
| 73         require("info").addonRoot + "icon64.png", | 143         "chrome://" + addonName + "/skin/icon16.png", | 
| 74         infobar.PRIORITY_INFO_HIGH, | 144         infobar.PRIORITY_INFO_HIGH, | 
| 75         buttons | 145         buttons | 
| 76       ); | 146       ); | 
| 77       notification.persistence = persistence; | 147       notification.persistence = persistence; | 
| 78     }; | 148     }; | 
| 79 | 149 | 
| 80     exports.loadURI = function(window, uri) | 150     exports.loadURI = function(window, uri) | 
| 81     { | 151     { | 
| 82       exports.getBrowser(window).loadURI(uri); | 152       exports.getBrowser(window).loadURI(uri); | 
| 83     }; | 153     }; | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 149       let notification = infobar.getNotificationWithValue(id); | 219       let notification = infobar.getNotificationWithValue(id); | 
| 150 | 220 | 
| 151       if (notification) | 221       if (notification) | 
| 152       { | 222       { | 
| 153         infobar.removeNotification(notification); | 223         infobar.removeNotification(notification); | 
| 154       } | 224       } | 
| 155 | 225 | 
| 156       notification = infobar.appendNotification( | 226       notification = infobar.appendNotification( | 
| 157         message, | 227         message, | 
| 158         id, | 228         id, | 
| 159         require("info").addonRoot + "icon64.png", | 229         "chrome://" + addonName + "/skin/icon16.png", | 
| 160         infobar.PRIORITY_INFO_HIGH, | 230         infobar.PRIORITY_INFO_HIGH, | 
| 161         buttons | 231         buttons | 
| 162       ); | 232       ); | 
| 163       notification.persistence = persistence; | 233       notification.persistence = persistence; | 
| 164     }; | 234     }; | 
| 165 | 235 | 
| 166     exports.loadURI = function(window, uri) | 236     exports.loadURI = function(window, uri) | 
| 167     { | 237     { | 
| 168       exports.getBrowser(window).loadURI(uri); | 238       exports.getBrowser(window).loadURI(uri); | 
| 169     }; | 239     }; | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 206         let notification = infobar.getNotificationWithValue(id); | 276         let notification = infobar.getNotificationWithValue(id); | 
| 207 | 277 | 
| 208         if (notification) | 278         if (notification) | 
| 209         { | 279         { | 
| 210           infobar.removeNotification(notification); | 280           infobar.removeNotification(notification); | 
| 211         } | 281         } | 
| 212 | 282 | 
| 213         notification = infobar.appendNotification( | 283         notification = infobar.appendNotification( | 
| 214           message, | 284           message, | 
| 215           id, | 285           id, | 
| 216           require("info").addonRoot + "icon64.png", | 286           "chrome://" + addonName + "/skin/icon16.png", | 
| 217           infobar.PRIORITY_INFO_HIGH, | 287           infobar.PRIORITY_INFO_HIGH, | 
| 218           buttons | 288           buttons | 
| 219         ); | 289         ); | 
| 220         notification.persistence = persistence; | 290         notification.persistence = persistence; | 
| 221       } | 291       } | 
| 222     }; | 292     }; | 
| 223 | 293 | 
| 224     exports.loadURI = function(window, uri) | 294     exports.loadURI = function(window, uri) | 
| 225     { | 295     { | 
| 226       if ("BrowserUI" in window && "goToURI" in window.BrowserUI) | 296       if ("BrowserUI" in window && "goToURI" in window.BrowserUI) | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 279         functionHooks.set(window, unhook); | 349         functionHooks.set(window, unhook); | 
| 280       } | 350       } | 
| 281     }; | 351     }; | 
| 282 | 352 | 
| 283     exports.openInfobar = function(window, id, message, buttons, persistence) | 353     exports.openInfobar = function(window, id, message, buttons, persistence) | 
| 284     { | 354     { | 
| 285       if ("BrowserApp" in window && "selectedTab" in window.BrowserApp) | 355       if ("BrowserApp" in window && "selectedTab" in window.BrowserApp) | 
| 286       { | 356       { | 
| 287         window.NativeWindow.doorhanger.show(message, id, buttons, window.Browser
     App.selectedTab.id, | 357         window.NativeWindow.doorhanger.show(message, id, buttons, window.Browser
     App.selectedTab.id, | 
| 288           { | 358           { | 
| 289             // No navigation is happening after doorhanger is shown | 359             persistence: persistence | 
| 290             // so persistence needs to be reduced by one |  | 
| 291             persistence: persistence - 1 |  | 
| 292           } | 360           } | 
| 293         ); | 361         ); | 
| 294       } | 362       } | 
| 295     }; | 363     }; | 
| 296 | 364 | 
| 297     exports.loadURI = function(window, uri) | 365     exports.loadURI = function(window, uri) | 
| 298     { | 366     { | 
| 299       if ("BrowserApp" in window && "loadURI" in window.BrowserApp) | 367       if ("BrowserApp" in window && "loadURI" in window.BrowserApp) | 
| 300         window.BrowserApp.loadURI(uri); | 368         window.BrowserApp.loadURI(uri); | 
| 301     }; | 369     }; | 
| 302 | 370 | 
| 303     break; | 371     break; | 
| 304   } | 372   } | 
| 305   default: | 373   default: | 
| 306   { | 374   { | 
| 307     exports.isKnownWindow = function(window) false; | 375     exports.isKnownWindow = function(window) false; | 
| 308     break; | 376     break; | 
| 309   } | 377   } | 
| 310 } | 378 } | 
| OLD | NEW | 
|---|