diff options
Diffstat (limited to 'web/js')
-rw-r--r-- | web/js/main.js | 48 |
1 files changed, 12 insertions, 36 deletions
diff --git a/web/js/main.js b/web/js/main.js index 3c1f23a..27d3a1a 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -13,7 +13,7 @@ class Channel { window.addEventListener( 'WebChannelMessageToContent', ev => { - if (ev.detail.message.error) { + if (ev.detail && ev.detail.message.error) { for (const wait in this.waiting) { this.waiting[wait].reject(new Error(ev.detail.message.error)); } @@ -80,6 +80,15 @@ class Channel { }); } + loadOauthCredentials(code, state) { + this._send('account_updates', 'fxaccounts:oauth_login', { + code, + state, + redirect: "urn:ietf:wg:oauth:2.0:oob:oauth-redirect-webchannel", + action: "signin" + }); + } + passwordChanged(email, uid) { this._send('account_updates', 'fxaccounts:change_password', { email, @@ -722,21 +731,6 @@ class FenixSignin extends HTMLElement { const shadow = this.attachShadow({mode: 'open'}); shadow.replaceChildren( $("styles").cloneNode(true), - $("tpl-fenix-signin-warning").content.cloneNode(true)); - shadow.querySelector("#signin").onclick = wrapHandler(async ev => { - ev.preventDefault(); - switchTo(new FenixSigninEnter()); - }); - } -} -customElements.define('do-fenix-signin', FenixSignin); - -class FenixSigninEnter extends HTMLElement { - constructor(session) { - super(); - const shadow = this.attachShadow({mode: 'open'}); - shadow.replaceChildren( - $("styles").cloneNode(true), $("tpl-fenix-signin").content.cloneNode(true)); shadow.querySelector("credentials-form").addEventListener('confirm', wrapHandler(async ev => { ev.preventDefault(); @@ -787,21 +781,7 @@ class FenixSigninEnter extends HTMLElement { code_challenge: param("code_challenge"), }); - console.log(`browser.tabs.executeScript({code: \` - port = browser.runtime.connectNative("mozacWebchannel"); - port.postMessage({ - id: "account_updates", - message: { - command: "fxaccounts:oauth_login", - data: { - "code": "${code.code}", - "state": "${code.state}", - "redirect": "urn:ietf:wg:oauth:2.0:oob:oauth-redirect-webchannel", - "action": "signin" - }, - messageId: 1, - }}); - \`});`); + channel.loadOauthCredentials(code.code, code.state); switchTo(new FenixSignin()); } finally { @@ -809,7 +789,7 @@ class FenixSigninEnter extends HTMLElement { } } } -customElements.define('do-fenix-signin-enter', FenixSigninEnter); +customElements.define('do-fenix-signin', FenixSignin); ////////////////////////////////////////// // initialization @@ -822,10 +802,6 @@ const isAndroid = /Android/.test(navigator.userAgent); document.body.onload = async () => { showMessage("Loading ...", "animate"); - if (isAndroid) { - document.head.appendChild($("tpl-fenix-style").content); - } - try { let resp = await fetch("/.well-known/fxa-client-configuration"); if (!resp.ok) throw new Error(resp.statusText); |