Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Add Autofill support #3241

Merged
merged 10 commits into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/extensions/brave/about-autofill.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<html>
<head>
<meta charset="utf-8">
<meta name="availableLanguages" content="">
<meta name="defaultLanguage" content="en-US">
<meta name='theme-color' content='#ff5000'>
<title data-l10n-id="autofillTitle"></title>
<script src='js/about.js'></script>
<script src="ext/l20n.min.js" async></script>
<link rel="localization" href="locales/{locale}/autofill.properties">
</head>
<body>
<div id="appContainer"/>
</body>
</html>
13 changes: 13 additions & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,16 @@ allSiteCookies=All site cookies
clear=Clear
clearDataWarning=Warning: Selected data, back to the day you installed Brave will be cleared and cannot be undone.
clearBrowsingData=Clear browsing data
name=Name
creditCardNumber=Card Number
expirationDate=Expiration date
organization=Organization
streetAddress=Street Address
city=City
state=State
postalCode=Postal Code
country=Country
phone=Phone
email=Email
editAddress=Edit Address
editCreditCard=Edit Credit Card
18 changes: 18 additions & 0 deletions app/extensions/brave/locales/en-US/autofill.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
autofillTitle=Autofill Settings
addresses=Addresses
creditCards=Credit Cards
addAddress=Add Address
addCreditCard=Add Credit Card
name=Name
creditCardNumber=Card Number
expirationDate=Expiration date
noCreditCardsSaved=No saved credit cards
organization=Organization
streetAddress=Street Address
city=City
state=State
postalCode=Postal Code
country=Country
phone=Phone
email=Email
noAddressesSaved=No saved addresses
3 changes: 3 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,6 @@ allSiteCookies=All site cookies
passwordsAndForms=Passwords and Forms
tabSettings=Tab Settings
clearBrowsingDataNow=Clear Browsing Data Now...
autofillSettings=Autofill Settings
manageAutofillData=Manage Autofill Data...
enableAutofill=Enable Autofill
53 changes: 53 additions & 0 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,56 @@ module.exports.setDefaultZoomLevel = (zoom) => {
ses.userPrefs.setDefaultZoomLevel(zoom)
}
}

module.exports.addAutofillAddress = (detail) => {
let guidMap = {}
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
let guid = ses.autofill.addProfile({
full_name: detail.name,
company_name: detail.organization,
street_address: detail.streetAddress,
city: detail.city,
state: detail.state,
postal_code: detail.postalCode,
country_code: detail.country,
phone: detail.phone,
email: detail.email
})
guidMap[partition] = guid
}
return guidMap
}

module.exports.removeAutofillAddress = (guid) => {
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
if (guid[partition] !== undefined) {
ses.autofill.removeProfile(guid[partition])
}
}
}

module.exports.addAutofillCreditCard = (detail) => {
let guidMap = {}
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
let guid = ses.autofill.addCreditCard({
name: detail.name,
card_number: detail.card,
expiration_month: detail.month,
expiration_year: detail.year
})
guidMap[partition] = guid
}
return guidMap
}

module.exports.removeAutofillCreditCard = (guid) => {
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
if (guid[partition] !== undefined) {
ses.autofill.removeCreditCard(guid[partition])
}
}
}
10 changes: 10 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const spellCheck = require('./spellCheck')
const ledger = require('./ledger')
const flash = require('../js/flash')
const contentSettings = require('../js/state/contentSettings')
const privacy = require('../js/state/privacy')

// Used to collect the per window state when shutting down the application
let perWindowState = []
Expand Down Expand Up @@ -392,6 +393,7 @@ app.on('ready', () => {
return loadedPerWindowState
}).then((loadedPerWindowState) => {
contentSettings.init()
privacy.init()
Extensions.init()
Filtering.init()
SiteHacks.init()
Expand Down Expand Up @@ -747,6 +749,14 @@ app.on('ready', () => {
}
})

ipcMain.on(messages.REMOVE_AUTOFILL_ADDRESS, (e, address) => {
appActions.removeAutofillAddress(address)
})

ipcMain.on(messages.REMOVE_AUTOFILL_CREDIT_CARD, (e, card) => {
appActions.removeAutofillCreditCard(card)
})

// Setup the crash handling
CrashHerald.init()

Expand Down
44 changes: 44 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,50 @@ Sets whether the bitcoin protocol is handled.



### addAutofillAddress(detail, originalDetail)

Add address data

**Parameters**

**detail**: `object`, the address to add as per doc/state.md's autofillAddressDetail

**originalDetail**: `object`, the original address before editing



### removeAutofillAddress(detail)

Remove address data

**Parameters**

**detail**: `object`, the address to remove as per doc/state.md's autofillAddressDetail



### addAutofillCreditCard(detail, originalDetail)

Add credit card data

**Parameters**

**detail**: `object`, the credit card to add as per doc/state.md's autofillCreditCardDetail

**originalDetail**: `object`, the original credit card before editing



### removeAutofillCreditCard(detail)

Remove credit card data

**Parameters**

**detail**: `object`, the credit card to remove as per doc/state.md's autofillCreditCardDetail




* * *

Expand Down
29 changes: 28 additions & 1 deletion docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ AppStore
locale: string, // en_US, en, or any other locale string
ignoredWords: Array<string>, // List of words to ignore
addedWords: Array<string> // List of words to add to the dictionary
},
autofill: {
addresses: [{
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}],
creditCards: [{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't store plain text CC data in the state. It's already encrypted on the electron side so we should either store the guid and read from there or encrypt (base64 encoded) here. Preferably the former I think because we don't really need two copies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just FYI - this is a blocker for merge because it's a major security issue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 90f62be. Thanks.

Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}]
}
}
```
Expand Down Expand Up @@ -411,6 +419,25 @@ WindowStore
score: ?
}
},
hasBitcoinHandler: boolean // Whether Brave has a bitcoin: protocol handler
hasBitcoinHandler: boolean, // Whether Brave has a bitcoin: protocol handler
autofillAddressDetail: {
name: string,
organization: string,
streetAddress: string,
city: string,
state: string,
postalCode: string,
country: string,
phone: string,
email: string,
guid: Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
},
autofillCreditCardDetail: {
name: string,
card: string,
month: string,
year: string,
guid: Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}
}
```
24 changes: 24 additions & 0 deletions docs/windowActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,30 @@ Sets the clear browsing data popup detail



### setAutofillAddressDetail(currentDetail, originalDetail)

Sets the manage autofill address popup detail

**Parameters**

**currentDetail**: `Object`, Properties of the address to change to

**originalDetail**: `Object`, Properties of the address to edit



### setAutofillCreditCardDetail(currentDetail, originalDetail)

Sets the manage autofill credit card popup detail

**Parameters**

**currentDetail**: `Object`, Properties of the credit card to change to

**originalDetail**: `Object`, Properties of the credit card to edit




* * *

Expand Down
54 changes: 54 additions & 0 deletions js/about/aboutActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,60 @@ const AboutActions = {

createWallet: function () {
ipc.send(messages.LEDGER_CREATE_WALLET)
},

setLedgerEnabled: function (enabled) {
ipc.send(messages.LEDGER_ENABLE, enabled)
},

/**
* Open a adding address dialog
*/
addAutofillAddress: function () {
ipc.sendToHost(messages.ADD_AUTOFILL_ADDRESS)
},

/**
* Remove address
*
* @param {object} address - address to remove as per doc/state.md's autofillAddressDetail
*/
removeAutofillAddress: function (address) {
ipc.send(messages.REMOVE_AUTOFILL_ADDRESS, address)
},

/**
* Open a edit address dialog
*
* @param {object} address - address to edit as per doc/state.md's autofillAddressDetail
*/
editAutofillAddress: function (address) {
ipc.sendToHost(messages.EDIT_AUTOFILL_ADDRESS, address)
},

/**
* Open a adding credit card dialog
*/
addAutofillCreditCard: function () {
ipc.sendToHost(messages.ADD_AUTOFILL_CREDIT_CARD)
},

/**
* Remove credit card
*
* @param {object} card - credit card to remove as per doc/state.md's autofillCreditCardDetail
*/
removeAutofillCreditCard: function (card) {
ipc.send(messages.REMOVE_AUTOFILL_CREDIT_CARD, card)
},

/**
* Open a editing credit card dialog
*
* @param {object} card - credit card to edit as per doc/state.md's autofillCreditCardDetail
*/
editAutofillCreditCard: function (card) {
ipc.sendToHost(messages.EDIT_AUTOFILL_CREDIT_CARD, card)
}
}
module.exports = AboutActions
Loading