Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 this.EXPORTED_SYMBOLS = ["Utils"];
9 const Cu = Components.utils;
11 Cu.import("resource://gre/modules/Services.jsm", this);
13 this.Utils = Object.freeze({
14 makeURI: function (url) {
15 return Services.io.newURI(url, null, null);
16 },
18 /**
19 * Returns true if the |url| passed in is part of the given root |domain|.
20 * For example, if |url| is "www.mozilla.org", and we pass in |domain| as
21 * "mozilla.org", this will return true. It would return false the other way
22 * around.
23 */
24 hasRootDomain: function (url, domain) {
25 let host;
27 try {
28 host = this.makeURI(url).host;
29 } catch (e) {
30 // The given URL probably doesn't have a host.
31 return false;
32 }
34 let index = host.indexOf(domain);
35 if (index == -1)
36 return false;
38 if (host == domain)
39 return true;
41 let prevChar = host[index - 1];
42 return (index == (host.length - domain.length)) &&
43 (prevChar == "." || prevChar == "/");
44 },
46 shallowCopy: function (obj) {
47 let retval = {};
49 for (let key of Object.keys(obj)) {
50 retval[key] = obj[key];
51 }
53 return retval;
54 }
55 });