forked from mirrors/gecko-dev
This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm
MozReview-Commit-ID: 1Nc3XDu0wGl
--HG--
extra : source : 12fc4dee861c812fd2bd032c63ef17af61800c70
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
/* vim: set sts=2 sw=2 et tw=80: */
|
|
"use strict";
|
|
|
|
var {Constructor: CC} = Components;
|
|
|
|
ChromeUtils.defineModuleGetter(this, "CommonUtils",
|
|
"resource://services-common/utils.js");
|
|
XPCOMUtils.defineLazyPreferenceGetter(this, "redirectDomain",
|
|
"extensions.webextensions.identity.redirectDomain");
|
|
|
|
let CryptoHash = CC("@mozilla.org/security/hash;1", "nsICryptoHash", "initWithString");
|
|
|
|
Cu.importGlobalProperties(["URL", "TextEncoder"]);
|
|
|
|
const computeHash = str => {
|
|
let byteArr = new TextEncoder().encode(str);
|
|
let hash = new CryptoHash("sha1");
|
|
hash.update(byteArr, byteArr.length);
|
|
return CommonUtils.bytesAsHex(hash.finish(false));
|
|
};
|
|
|
|
this.identity = class extends ExtensionAPI {
|
|
getAPI(context) {
|
|
let {extension} = context;
|
|
return {
|
|
identity: {
|
|
getRedirectURL: function(path = "") {
|
|
let hash = computeHash(extension.id);
|
|
let url = new URL(`https://${hash}.${redirectDomain}/`);
|
|
url.pathname = path;
|
|
return url.href;
|
|
},
|
|
},
|
|
};
|
|
}
|
|
};
|