From cef8f5369bbafa7865b53ac92e879ca798d5f762 Mon Sep 17 00:00:00 2001 From: Emanuele Feliziani Date: Mon, 5 Jul 2021 10:27:44 +0200 Subject: [PATCH 1/2] Make isDeviceSignedIn sync and use it in Form.js Signed-off-by: Emanuele Feliziani --- dist/autofill.css | 1 + dist/autofill.js | 44 +++++++++++++++++++++++------------------- src/DeviceInterface.js | 29 ++++++++++++++-------------- src/Form/Form.js | 2 +- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/dist/autofill.css b/dist/autofill.css index ed8b29222..b38069129 100644 --- a/dist/autofill.css +++ b/dist/autofill.css @@ -109,6 +109,7 @@ width: 36px; height: 36px; margin: auto 6px auto 0; + /* TODO: use dynamically from src/UI/img/ddgPasswordIcon.js */ background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMjRweCIgaGVpZ2h0PSIyNHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8dGl0bGU+ZGRnLXBhc3N3b3JkLWljb24tYmFzZTwvdGl0bGU+CiAgICA8ZyBpZD0iZGRnLXBhc3N3b3JkLWljb24tYmFzZSIgc3Ryb2tlPSJub25lIiBzdHJva2Utd2lkdGg9IjEiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+CiAgICAgICAgPGcgaWQ9IlVuaW9uIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSg0LjAwMDAwMCwgNC4wMDAwMDApIiBmaWxsPSIjMDAwMDAwIj4KICAgICAgICAgICAgPHBhdGggZD0iTTExLjMzMzMsMi42NjY2NyBDMTAuMjI4OCwyLjY2NjY3IDkuMzMzMzMsMy41NjIxIDkuMzMzMzMs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c87..fda927c3c 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -169,6 +169,8 @@ class ExtensionInterface extends InterfacePrototype { constructor() { super(); + this.isDeviceSignedIn = () => this.hasLocalAddresses; + this.setupAutofill = ({ shouldLog } = { @@ -260,28 +262,24 @@ class AndroidInterface extends InterfacePrototype { alias }) => alias); - this.isDeviceSignedIn = () => new Promise(resolve => { - resolve(window.EmailInterface.isSignedIn() === 'true'); - }); + this.isDeviceSignedIn = () => window.EmailInterface.isSignedIn() === 'true'; this.setupAutofill = ({ shouldLog } = { shouldLog: false }) => { - this.isDeviceSignedIn().then(signedIn => { - if (signedIn) { - notifyWebApp({ - deviceSignedIn: { - value: true, - shouldLog - } - }); - scanForInputs(this); - } else { - this.trySigningIn(); - } - }); + if (this.isDeviceSignedIn()) { + notifyWebApp({ + deviceSignedIn: { + value: true, + shouldLog + } + }); + scanForInputs(this); + } else { + this.trySigningIn(); + } }; this.storeUserData = ({ @@ -314,10 +312,13 @@ class AppleDeviceInterface extends InterfacePrototype { await this.getAccounts(); } - const signedIn = await this.isDeviceSignedIn(); + const signedIn = await this._checkDeviceSignedIn(); if (signedIn) { - await this.getAddresses(); + if (isApp) { + await this.getAddresses(); + } + notifyWebApp({ deviceSignedIn: { value: true, @@ -353,10 +354,13 @@ class AppleDeviceInterface extends InterfacePrototype { this.refreshAlias = () => wkSend('emailHandlerRefreshAlias'); - this.isDeviceSignedIn = async () => { + this._checkDeviceSignedIn = async () => { const { isAppSignedIn } = await wkSendAndWait('emailHandlerCheckAppSignedInStatus'); + + this.isDeviceSignedIn = () => !!isAppSignedIn; + return !!isAppSignedIn; }; @@ -662,7 +666,7 @@ class Form { if (this.isLogin) { if (this.Device.hasLocalCredentials) this.decorateInput(input); } else { - if (this.Device.hasLocalAddresses && !input.matches(PASSWORD_SELECTOR)) { + if (this.Device.isDeviceSignedIn() && !input.matches(PASSWORD_SELECTOR)) { this.decorateInput(input); } } diff --git a/src/DeviceInterface.js b/src/DeviceInterface.js index 9115359f8..8b298cc2b 100644 --- a/src/DeviceInterface.js +++ b/src/DeviceInterface.js @@ -110,6 +110,8 @@ class ExtensionInterface extends InterfacePrototype { constructor () { super() + this.isDeviceSignedIn = () => this.hasLocalAddresses + this.setupAutofill = ({shouldLog} = {shouldLog: false}) => { this.getAddresses().then(addresses => { if (this.hasLocalAddresses) { @@ -194,19 +196,15 @@ class AndroidInterface extends InterfacePrototype { window.EmailInterface.showTooltip(), 'getAliasResponse') .then(({alias}) => alias) - this.isDeviceSignedIn = () => new Promise(resolve => { - resolve(window.EmailInterface.isSignedIn() === 'true') - }) + this.isDeviceSignedIn = () => window.EmailInterface.isSignedIn() === 'true' this.setupAutofill = ({shouldLog} = {shouldLog: false}) => { - this.isDeviceSignedIn().then((signedIn) => { - if (signedIn) { - notifyWebApp({ deviceSignedIn: {value: true, shouldLog} }) - scanForInputs(this) - } else { - this.trySigningIn() - } - }) + if (this.isDeviceSignedIn()) { + notifyWebApp({ deviceSignedIn: {value: true, shouldLog} }) + scanForInputs(this) + } else { + this.trySigningIn() + } } this.storeUserData = ({addUserData: {token, userName}}) => @@ -227,9 +225,11 @@ class AppleDeviceInterface extends InterfacePrototype { await this.getAccounts() } - const signedIn = await this.isDeviceSignedIn() + const signedIn = await this._checkDeviceSignedIn() if (signedIn) { - await this.getAddresses() + if (isApp) { + await this.getAddresses() + } notifyWebApp({ deviceSignedIn: {value: true, shouldLog} }) forms.forEach(form => form.redecorateAllInputs()) } else { @@ -260,8 +260,9 @@ class AppleDeviceInterface extends InterfacePrototype { this.refreshAlias = () => wkSend('emailHandlerRefreshAlias') - this.isDeviceSignedIn = async () => { + this._checkDeviceSignedIn = async () => { const {isAppSignedIn} = await wkSendAndWait('emailHandlerCheckAppSignedInStatus') + this.isDeviceSignedIn = () => !!isAppSignedIn return !!isAppSignedIn } diff --git a/src/Form/Form.js b/src/Form/Form.js index e27411cef..368d9505a 100644 --- a/src/Form/Form.js +++ b/src/Form/Form.js @@ -181,7 +181,7 @@ class Form { if (this.isLogin) { if (this.Device.hasLocalCredentials) this.decorateInput(input) } else { - if (this.Device.hasLocalAddresses && !input.matches(PASSWORD_SELECTOR)) { + if (this.Device.isDeviceSignedIn() && !input.matches(PASSWORD_SELECTOR)) { this.decorateInput(input) } } From 28492416dc33ee54a8422bfd9d6b3f75bd133727 Mon Sep 17 00:00:00 2001 From: Emanuele Feliziani Date: Mon, 5 Jul 2021 16:49:37 +0200 Subject: [PATCH 2/2] Avoid autofill on the new quack signup page Signed-off-by: Emanuele Feliziani --- dist/autofill.js | 7 ++++--- src/Form/FormAnalyzer.js | 3 --- src/scanForInputs.js | 3 +++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dist/autofill.js b/dist/autofill.js index fda927c3c..9b8d036ea 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -767,9 +767,7 @@ class FormAnalyzer { constructor(form, input) { this.form = form; this.autofillSignal = 0; - this.signals = []; // Avoid autofill on our signup page - - if (window.location.href.match(/^https:\/\/.+\.duckduckgo\.com\/email\/signup/i)) return this; + this.signals = []; this.evaluateElAttributes(input, 3, true); form ? this.evaluateForm() : this.evaluatePage(); return this; @@ -1717,6 +1715,9 @@ const { const forms = new Map(); // Accepts the DeviceInterface as an explicit dependency const scanForInputs = DeviceInterface => { + // Avoid autofill on our signup page + if (window.location.href.match(/^https:\/\/.+\.duckduckgo\.com\/email\/choose-address/i)) return; + const getParentForm = input => { if (input.form) return input.form; let element = input; // traverse the DOM to search for related inputs diff --git a/src/Form/FormAnalyzer.js b/src/Form/FormAnalyzer.js index 88ef9fb5b..0700195ed 100644 --- a/src/Form/FormAnalyzer.js +++ b/src/Form/FormAnalyzer.js @@ -6,9 +6,6 @@ class FormAnalyzer { this.autofillSignal = 0 this.signals = [] - // Avoid autofill on our signup page - if (window.location.href.match(/^https:\/\/.+\.duckduckgo\.com\/email\/signup/i)) return this - this.evaluateElAttributes(input, 3, true) form ? this.evaluateForm() : this.evaluatePage() return this diff --git a/src/scanForInputs.js b/src/scanForInputs.js index 5f1c142c8..936f9b260 100644 --- a/src/scanForInputs.js +++ b/src/scanForInputs.js @@ -6,6 +6,9 @@ const forms = new Map() // Accepts the DeviceInterface as an explicit dependency const scanForInputs = (DeviceInterface) => { + // Avoid autofill on our signup page + if (window.location.href.match(/^https:\/\/.+\.duckduckgo\.com\/email\/choose-address/i)) return + const getParentForm = (input) => { if (input.form) return input.form