forked from mirrors/gecko-dev
MozReview-Commit-ID: GAdlxYUM6rr --HG-- rename : toolkit/components/extensions/ext-c-identity.js => toolkit/components/extensions/ext-identity.js extra : rebase_source : eaec4890e559e0c969b6d7721ee94dcbda85c4f6
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;
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(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;
|
|
},
|
|
},
|
|
};
|
|
}
|
|
};
|