Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/utils.js

Issue 5173395171835904: Issue 2264 - Remove deprecated logic from Utils.runAsync() on Chrome/Opera/Safari (Closed)
Patch Set: Created April 2, 2015, 10:26 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/storage/io.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
20 var Utils = exports.Utils = { 18 var Utils = exports.Utils = {
21 systemPrincipal: null, 19 systemPrincipal: null,
22 getString: function(id) 20 getString: function(id)
23 { 21 {
24 if (typeof ext !== "undefined" && "i18n" in ext) 22 if (typeof ext !== "undefined" && "i18n" in ext)
25 return ext.i18n.getMessage("global_" + id); 23 return ext.i18n.getMessage("global_" + id);
26 else 24 else
27 return id; 25 return id;
28 }, 26 },
29
30 // This function can take additional parameters. Second paramater will be
31 // passed as this variable to the callback and any additional parameters as
32 // callback parameters.
33 runAsync: function(callback) 27 runAsync: function(callback)
34 { 28 {
35 callback = callback.bind.apply(callback, Array.prototype.slice.call(argument s, 1)); 29 if (document.readyState == "loading")
36
37 if (typeof runAsyncQueue == "undefined")
38 { 30 {
39 runAsyncQueue = (document.readyState == "loading" ? [] : null); 31 // Make sure to not run asynchronous actions before all
40 if (runAsyncQueue) 32 // scripts loaded. This caused issues on Opera in the past.
33 let onDOMContentLoaded = function()
41 { 34 {
42 // Hack: Opera will happily run asynchronous actions while scripts are 35 document.removeEventListener("DOMContentLoaded", onDOMContentLoaded);
43 // loading, queue them until the document is ready. 36 callback();
44 let loadHandler = function() 37 };
45 { 38 document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
46 document.removeEventListener("DOMContentLoaded", loadHandler, false);
47
48 let queue = runAsyncQueue;
49 runAsyncQueue = null;
50 for (let callback of queue)
51 {
52 try
53 {
54 callback();
55 }
56 catch(e)
57 {
58 Cu.reportError(e);
59 }
60 }
61 };
62 document.addEventListener("DOMContentLoaded", loadHandler, false);
63 }
64 } 39 }
65
66 if (runAsyncQueue)
67 runAsyncQueue.push(callback);
68 else 40 else
69 window.setTimeout(callback, 0); 41 {
42 setTimeout(callback, 0);
43 }
70 }, 44 },
71 get appLocale() 45 get appLocale()
72 { 46 {
73 var locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 47 var locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
74 Object.defineProperty(this, "appLocale", {value: locale, enumerable: true}); 48 Object.defineProperty(this, "appLocale", {value: locale, enumerable: true});
75 return this.appLocale; 49 return this.appLocale;
76 }, 50 },
77 generateChecksum: function(lines) 51 generateChecksum: function(lines)
78 { 52 {
79 // We cannot calculate MD5 checksums yet :-( 53 // We cannot calculate MD5 checksums yet :-(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 { 114 {
141 var Prefs = require("prefs").Prefs; 115 var Prefs = require("prefs").Prefs;
142 var docLink = Prefs.documentation_link; 116 var docLink = Prefs.documentation_link;
143 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale ); 117 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale );
144 }, 118 },
145 119
146 yield: function() 120 yield: function()
147 { 121 {
148 } 122 }
149 }; 123 };
OLDNEW
« no previous file with comments | « lib/storage/io.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld