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

Side by Side Diff: lib/utils.js

Issue 13077005: Fix first-run page in Opera (Closed)
Patch Set: Improved queuing of async actions Created Oct. 16, 2013, 1:13 p.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/localstorage/io.js ('k') | metadata.opera » ('j') | 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 <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 },
26
24 runAsync: function(callback, thisPtr) 27 runAsync: function(callback, thisPtr)
Thomas Greiner 2013/10/16 13:36:46 thisPtr is only implicitly used by callback.bind.a
Wladimir Palant 2013/10/16 13:44:41 That's mainly because this isn't the canonical imp
25 { 28 {
26 var params = Array.prototype.slice.call(arguments, 2); 29 callback = callback.bind.apply(callback, Array.prototype.slice.call(argument s, 1));
27 window.setTimeout(function() 30
31 if (typeof runAsyncQueue == "undefined")
28 { 32 {
29 callback.apply(thisPtr, params); 33 runAsyncQueue = (document.readyState == "loading" ? [] : null)
Thomas Greiner 2013/10/16 13:36:46 Nit: Semicolon at the end is missing.
Wladimir Palant 2013/10/16 13:44:41 Done.
30 }, 0); 34 if (runAsyncQueue)
35 {
36 // Hack: Opera will happily run asynchronous actions while scripts are
37 // loading, queue them until the document is ready.
38 let loadHandler = function()
39 {
40 document.removeEventListener("DOMContentLoaded", loadHandler, false);
41
42 let queue = runAsyncQueue;
43 runAsyncQueue = null;
44 for each (let callback in queue)
45 {
46 try
47 {
48 callback();
49 }
50 catch(e)
51 {
52 Cu.reportError(e);
53 }
54 }
55 };
56 document.addEventListener("DOMContentLoaded", loadHandler, false);
57 }
58 }
59
60 if (runAsyncQueue)
61 runAsyncQueue.push(callback);
62 else
63 window.setTimeout(callback, 0);
31 }, 64 },
32 get appLocale() 65 get appLocale()
33 { 66 {
34 var locale = chrome.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 67 var locale = chrome.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
35 this.__defineGetter__("appLocale", function() {return locale}); 68 this.__defineGetter__("appLocale", function() {return locale});
36 return this.appLocale; 69 return this.appLocale;
37 }, 70 },
38 generateChecksum: function(lines) 71 generateChecksum: function(lines)
39 { 72 {
40 // We cannot calculate MD5 checksums yet :-( 73 // We cannot calculate MD5 checksums yet :-(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return selectedItem; 130 return selectedItem;
98 }, 131 },
99 132
100 getDocLink: function(linkID) 133 getDocLink: function(linkID)
101 { 134 {
102 var Prefs = require("prefs").Prefs; 135 var Prefs = require("prefs").Prefs;
103 var docLink = Prefs.documentation_link; 136 var docLink = Prefs.documentation_link;
104 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale ); 137 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale );
105 } 138 }
106 }; 139 };
OLDNEW
« no previous file with comments | « lib/localstorage/io.js ('k') | metadata.opera » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld