Skip to content

Commit

Permalink
Merge pull request #8 from duckduckgo/ema/fix-platforms-breakages
Browse files Browse the repository at this point in the history
Fix breakages introduced on other platforms
  • Loading branch information
GioSensation authored Jul 5, 2021
2 parents 3f8b4d6 + 2849241 commit 2d6e7a3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 41 deletions.
1 change: 1 addition & 0 deletions dist/autofill.css
Original file line number Diff line number Diff line change
Expand Up @@ -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+CiAgICAgICAgPGcgaWQ9IlVuaW9uIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSg0LjAwMDAwMCwgNC4wMDAwMDApIiBmaWxsPSIjMDAwMDAwIj4KICAgICAgICAgICAgPHBhdGggZD0iTTExLjMzMzMsMi42NjY2NyBDMTAuMjI4OCwyLjY2NjY3IDkuMzMzMzMsMy41NjIxIDkuMzMzMzMsNC42NjY2NyBDOS4zMzMzMyw1Ljc3MTI0IDEwLjIyODgsNi42NjY2NyAxMS4zMzMzLDYuNjY2NjcgQzEyLjQzNzksNi42NjY2NyA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IsMTAuNjY2NyAxNiw4LjI3ODg1IDE2LDUuMzMzMzMgQzE2LDIuMzg3ODEgMTMuNjEyMiwwIDEwLjY2NjcsMCBaIE02LjY2NjY3LDUuMzMzMzMgQzYuNjY2NjcsMy4xMjQxOSA4LjQ1NzUzLDEuMzMzMzMgMTAuNjY2NywxLjMzMzMzIEMxMi44NzU4LDEuMzMzMzMgMTQuNjY2NywzLjEyNDE5IDE0LjY2NjcsNS4zMzMzMyBDMTQuNjY2Nyw3LjU0MjQ3IDEyLjg3NTgsOS4zMzMzMyAxMC42NjY3LDkuMzMzMzMgQzEwLjE1NTgsOS4zMzMzMyA5LjY2ODg2LDkuMjM3OSA5LjIyMTUyLDkuMDY0NSBDOC45NzUyOCw4Ljk2OTA1IDguNjk1OTEsOS4wMjc5NSA4LjUwOTE2LDkuMjE0NjkgTDcuNzIzODYsMTAgTDYsMTAgQzUuNjMxODEsMTAgNS4zMzMzMywxMC4yOTg1IDUuMzMzMzMsMTAuNjY2NyBMNS4zMzMzMywxMi42NjY3IEw0LDEyLjY2NjcgQzMuNjMxODEsMTIuNjY2NyAzLjMzMzMzLDEyLjk2NTEgMy4zMzMzMywxMy4zMzMzIEwzLjMzMzMzLDE0LjY2NjcgTDEuMzMzMzMsMTQuNjY2NyBMMS4zMzMzMywxMi42MDk1IEw2LjY5Nzg3LDcuMjQ0OTQgQzYuODc1MDIsNy4wNjc3OSA2LjkzNzksNi44MDYyOSA2Ljg2MDY1LDYuNTY3OTggQzYuNzM0ODksNi4xNzk5NyA2LjY2NjY3LDUuNzY1MjcgNi42NjY2Nyw1LjMzMzMzIFoiIGlkPSJTaGFwZSI+PC9wYXRoPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+');
background-size: cover;
}
Expand Down
51 changes: 28 additions & 23 deletions dist/autofill.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class ExtensionInterface extends InterfacePrototype {
constructor() {
super();

this.isDeviceSignedIn = () => this.hasLocalAddresses;

this.setupAutofill = ({
shouldLog
} = {
Expand Down Expand Up @@ -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 = ({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -763,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;
Expand Down Expand Up @@ -1713,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
Expand Down
29 changes: 15 additions & 14 deletions src/DeviceInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}}) =>
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Form/FormAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/scanForInputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2d6e7a3

Please sign in to comment.