fune/toolkit/components/extensions/ext-c-identity.js
Shane Caraveo aac2ef44df Bug 1399070 move launchWebAuthFlow to parent to fix opening auth window when remote, r=zombie
MozReview-Commit-ID: GAdlxYUM6rr

--HG--
rename : toolkit/components/extensions/ext-c-identity.js => toolkit/components/extensions/ext-identity.js
extra : rebase_source : eaec4890e559e0c969b6d7721ee94dcbda85c4f6
2017-09-14 09:18:27 -07:00

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;
},
},
};
}
};