OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus 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 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus 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 Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
| 18 let runAsyncQueue = []; |
| 19 |
18 var Utils = exports.Utils = { | 20 var Utils = exports.Utils = { |
19 systemPrincipal: null, | 21 systemPrincipal: null, |
20 getString: function(id) | 22 getString: function(id) |
21 { | 23 { |
22 return id; | 24 return id; |
23 }, | 25 }, |
24 runAsync: function(callback, thisPtr) | 26 runAsync: function(callback, thisPtr) |
25 { | 27 { |
26 var params = Array.prototype.slice.call(arguments, 2); | 28 callback = callback.bind.apply(callback, Array.prototype.slice.call(argument
s, 1)); |
27 window.setTimeout(function() | 29 if (runAsyncQueue) |
28 { | 30 runAsyncQueue.push(callback); |
29 callback.apply(thisPtr, params); | 31 else |
30 }, 0); | 32 window.setTimeout(callback, 0); |
31 }, | 33 }, |
32 get appLocale() | 34 get appLocale() |
33 { | 35 { |
34 var locale = chrome.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); | 36 var locale = chrome.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); |
35 this.__defineGetter__("appLocale", function() {return locale}); | 37 this.__defineGetter__("appLocale", function() {return locale}); |
36 return this.appLocale; | 38 return this.appLocale; |
37 }, | 39 }, |
38 generateChecksum: function(lines) | 40 generateChecksum: function(lines) |
39 { | 41 { |
40 // We cannot calculate MD5 checksums yet :-( | 42 // We cannot calculate MD5 checksums yet :-( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return selectedItem; | 99 return selectedItem; |
98 }, | 100 }, |
99 | 101 |
100 getDocLink: function(linkID) | 102 getDocLink: function(linkID) |
101 { | 103 { |
102 var Prefs = require("prefs").Prefs; | 104 var Prefs = require("prefs").Prefs; |
103 var docLink = Prefs.documentation_link; | 105 var docLink = Prefs.documentation_link; |
104 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale
); | 106 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale
); |
105 } | 107 } |
106 }; | 108 }; |
| 109 |
| 110 Utils.runAsync.enable = function() |
| 111 { |
| 112 // Hack: Opera will happily run asynchronous actions while scripts are |
| 113 // loading, queue them until Utils.runAsync.enable() is called. |
| 114 if (!runAsyncQueue) |
| 115 return; |
| 116 |
| 117 let queue = runAsyncQueue; |
| 118 runAsyncQueue = null; |
| 119 for each (let callback in queue) |
| 120 { |
| 121 try |
| 122 { |
| 123 callback(); |
| 124 } |
| 125 catch(e) |
| 126 { |
| 127 Cu.reportError(e); |
| 128 } |
| 129 } |
| 130 } |
OLD | NEW |