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

Side by Side Diff: lib/utils.js

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Refactor polyfill.js Created Oct. 10, 2017, 10:39 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
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 "use strict"; 18 "use strict";
19 19
20 let Utils = exports.Utils = { 20 let Utils = exports.Utils = {
21 systemPrincipal: null, 21 systemPrincipal: null,
22 getString(id) 22 getString(id)
23 { 23 {
24 return chrome.i18n.getMessage("global_" + id); 24 return browser.i18n.getMessage("global_" + id);
25 }, 25 },
26 runAsync(callback) 26 runAsync(callback)
27 { 27 {
28 if (document.readyState == "loading") 28 if (document.readyState == "loading")
29 { 29 {
30 // Make sure to not run asynchronous actions before all 30 // Make sure to not run asynchronous actions before all
31 // scripts loaded. This caused issues on Opera in the past. 31 // scripts loaded. This caused issues on Opera in the past.
32 let onDOMContentLoaded = () => 32 let onDOMContentLoaded = () =>
33 { 33 {
34 document.removeEventListener("DOMContentLoaded", onDOMContentLoaded); 34 document.removeEventListener("DOMContentLoaded", onDOMContentLoaded);
35 callback(); 35 callback();
36 }; 36 };
37 document.addEventListener("DOMContentLoaded", onDOMContentLoaded); 37 document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
38 } 38 }
39 else 39 else
40 { 40 {
41 setTimeout(callback, 0); 41 setTimeout(callback, 0);
42 } 42 }
43 }, 43 },
44 get appLocale() 44 get appLocale()
45 { 45 {
46 let locale = chrome.i18n.getUILanguage(); 46 let locale = browser.i18n.getUILanguage();
47 Object.defineProperty(this, "appLocale", {value: locale, enumerable: true}); 47 Object.defineProperty(this, "appLocale", {value: locale, enumerable: true});
48 return this.appLocale; 48 return this.appLocale;
49 }, 49 },
50 get readingDirection() 50 get readingDirection()
51 { 51 {
52 let direction = chrome.i18n.getMessage("@@bidi_dir"); 52 let direction = browser.i18n.getMessage("@@bidi_dir");
53 // This fallback is only necessary for Microsoft Edge 53 // This fallback is only necessary for Microsoft Edge
54 if (!direction) 54 if (!direction)
55 direction = /^(?:ar|fa|he|ug|ur)\b/.test(this.appLocale) ? "rtl" : "ltr"; 55 direction = /^(?:ar|fa|he|ug|ur)\b/.test(this.appLocale) ? "rtl" : "ltr";
56 Object.defineProperty( 56 Object.defineProperty(
57 this, 57 this,
58 "readingDirection", 58 "readingDirection",
59 {value: direction, enumerable: true} 59 {value: direction, enumerable: true}
60 ); 60 );
61 return this.readingDirection; 61 return this.readingDirection;
62 }, 62 },
63 generateChecksum(lines) 63 generateChecksum(lines)
64 { 64 {
65 // We cannot calculate MD5 checksums yet :-( 65 // We cannot calculate MD5 checksums yet :-(
66 return null; 66 return null;
67 }, 67 },
68 68
69 getDocLink(linkID) 69 getDocLink(linkID)
70 { 70 {
71 let docLink = require("prefs").Prefs.documentation_link; 71 let docLink = require("prefs").Prefs.documentation_link;
72 return docLink.replace(/%LINK%/g, linkID) 72 return docLink.replace(/%LINK%/g, linkID)
73 .replace(/%LANG%/g, Utils.appLocale); 73 .replace(/%LANG%/g, Utils.appLocale);
74 }, 74 },
75 75
76 yield() 76 yield()
77 { 77 {
78 } 78 }
79 }; 79 };
OLDNEW
« no previous file with comments | « lib/uninstall.js ('k') | lib/whitelisting.js » ('j') | polyfill.js » ('J')

Powered by Google App Engine
This is Rietveld