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

Commit f620cf1

Browse files
authored
Merge pull request #3241 from brave/autofill
Add Autofill support
2 parents 5f49d8e + a116bbb commit f620cf1

35 files changed

+1528
-5
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<!-- This Source Code Form is subject to the terms of the Mozilla Public
3+
- License, v. 2.0. If a copy of the MPL was not distributed with this
4+
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
5+
<html>
6+
<head>
7+
<meta charset="utf-8">
8+
<meta name="availableLanguages" content="">
9+
<meta name="defaultLanguage" content="en-US">
10+
<meta name='theme-color' content='#ff5000'>
11+
<title data-l10n-id="autofillTitle"></title>
12+
<script src='js/about.js'></script>
13+
<script src="ext/l20n.min.js" async></script>
14+
<link rel="localization" href="locales/{locale}/autofill.properties">
15+
</head>
16+
<body>
17+
<div id="appContainer"/>
18+
</body>
19+
</html>

app/extensions/brave/locales/en-US/app.properties

+13
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,16 @@ allSiteCookies=All site cookies
177177
clear=Clear
178178
clearDataWarning=Warning: Selected data, back to the day you installed Brave will be cleared and cannot be undone.
179179
clearBrowsingData=Clear browsing data
180+
name=Name
181+
creditCardNumber=Card Number
182+
expirationDate=Expiration date
183+
organization=Organization
184+
streetAddress=Street Address
185+
city=City
186+
state=State
187+
postalCode=Postal Code
188+
country=Country
189+
phone=Phone
190+
email=Email
191+
editAddress=Edit Address
192+
editCreditCard=Edit Credit Card
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
autofillTitle=Autofill Settings
2+
addresses=Addresses
3+
creditCards=Credit Cards
4+
addAddress=Add Address
5+
addCreditCard=Add Credit Card
6+
name=Name
7+
creditCardNumber=Card Number
8+
expirationDate=Expiration date
9+
noCreditCardsSaved=No saved credit cards
10+
organization=Organization
11+
streetAddress=Street Address
12+
city=City
13+
state=State
14+
postalCode=Postal Code
15+
country=Country
16+
phone=Phone
17+
email=Email
18+
noAddressesSaved=No saved addresses

app/extensions/brave/locales/en-US/preferences.properties

+3
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,6 @@ allSiteCookies=All site cookies
172172
passwordsAndForms=Passwords and Forms
173173
tabSettings=Tab Settings
174174
clearBrowsingDataNow=Clear Browsing Data Now...
175+
autofillSettings=Autofill Settings
176+
manageAutofillData=Manage Autofill Data...
177+
enableAutofill=Enable Autofill

app/filtering.js

+53
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,56 @@ module.exports.setDefaultZoomLevel = (zoom) => {
579579
ses.userPrefs.setDefaultZoomLevel(zoom)
580580
}
581581
}
582+
583+
module.exports.addAutofillAddress = (detail) => {
584+
let guidMap = {}
585+
for (let partition in registeredSessions) {
586+
let ses = registeredSessions[partition]
587+
let guid = ses.autofill.addProfile({
588+
full_name: detail.name,
589+
company_name: detail.organization,
590+
street_address: detail.streetAddress,
591+
city: detail.city,
592+
state: detail.state,
593+
postal_code: detail.postalCode,
594+
country_code: detail.country,
595+
phone: detail.phone,
596+
email: detail.email
597+
})
598+
guidMap[partition] = guid
599+
}
600+
return guidMap
601+
}
602+
603+
module.exports.removeAutofillAddress = (guid) => {
604+
for (let partition in registeredSessions) {
605+
let ses = registeredSessions[partition]
606+
if (guid[partition] !== undefined) {
607+
ses.autofill.removeProfile(guid[partition])
608+
}
609+
}
610+
}
611+
612+
module.exports.addAutofillCreditCard = (detail) => {
613+
let guidMap = {}
614+
for (let partition in registeredSessions) {
615+
let ses = registeredSessions[partition]
616+
let guid = ses.autofill.addCreditCard({
617+
name: detail.name,
618+
card_number: detail.card,
619+
expiration_month: detail.month,
620+
expiration_year: detail.year
621+
})
622+
guidMap[partition] = guid
623+
}
624+
return guidMap
625+
}
626+
627+
module.exports.removeAutofillCreditCard = (guid) => {
628+
for (let partition in registeredSessions) {
629+
let ses = registeredSessions[partition]
630+
if (guid[partition] !== undefined) {
631+
ses.autofill.removeCreditCard(guid[partition])
632+
}
633+
}
634+
}

app/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const spellCheck = require('./spellCheck')
6161
const ledger = require('./ledger')
6262
const flash = require('../js/flash')
6363
const contentSettings = require('../js/state/contentSettings')
64+
const privacy = require('../js/state/privacy')
6465

6566
// Used to collect the per window state when shutting down the application
6667
let perWindowState = []
@@ -392,6 +393,7 @@ app.on('ready', () => {
392393
return loadedPerWindowState
393394
}).then((loadedPerWindowState) => {
394395
contentSettings.init()
396+
privacy.init()
395397
Extensions.init()
396398
Filtering.init()
397399
SiteHacks.init()
@@ -747,6 +749,14 @@ app.on('ready', () => {
747749
}
748750
})
749751

752+
ipcMain.on(messages.REMOVE_AUTOFILL_ADDRESS, (e, address) => {
753+
appActions.removeAutofillAddress(address)
754+
})
755+
756+
ipcMain.on(messages.REMOVE_AUTOFILL_CREDIT_CARD, (e, card) => {
757+
appActions.removeAutofillCreditCard(card)
758+
})
759+
750760
// Setup the crash handling
751761
CrashHerald.init()
752762

docs/appActions.md

+44
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,50 @@ Sets whether the bitcoin protocol is handled.
332332

333333

334334

335+
### addAutofillAddress(detail, originalDetail)
336+
337+
Add address data
338+
339+
**Parameters**
340+
341+
**detail**: `object`, the address to add as per doc/state.md's autofillAddressDetail
342+
343+
**originalDetail**: `object`, the original address before editing
344+
345+
346+
347+
### removeAutofillAddress(detail)
348+
349+
Remove address data
350+
351+
**Parameters**
352+
353+
**detail**: `object`, the address to remove as per doc/state.md's autofillAddressDetail
354+
355+
356+
357+
### addAutofillCreditCard(detail, originalDetail)
358+
359+
Add credit card data
360+
361+
**Parameters**
362+
363+
**detail**: `object`, the credit card to add as per doc/state.md's autofillCreditCardDetail
364+
365+
**originalDetail**: `object`, the original credit card before editing
366+
367+
368+
369+
### removeAutofillCreditCard(detail)
370+
371+
Remove credit card data
372+
373+
**Parameters**
374+
375+
**detail**: `object`, the credit card to remove as per doc/state.md's autofillCreditCardDetail
376+
377+
378+
335379

336380
* * *
337381

docs/state.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ AppStore
170170
locale: string, // en_US, en, or any other locale string
171171
ignoredWords: Array<string>, // List of words to ignore
172172
addedWords: Array<string> // List of words to add to the dictionary
173+
},
174+
autofill: {
175+
addresses: [{
176+
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
177+
}],
178+
creditCards: [{
179+
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
180+
}]
173181
}
174182
}
175183
```
@@ -412,6 +420,25 @@ WindowStore
412420
score: ?
413421
}
414422
},
415-
hasBitcoinHandler: boolean // Whether Brave has a bitcoin: protocol handler
423+
hasBitcoinHandler: boolean, // Whether Brave has a bitcoin: protocol handler
424+
autofillAddressDetail: {
425+
name: string,
426+
organization: string,
427+
streetAddress: string,
428+
city: string,
429+
state: string,
430+
postalCode: string,
431+
country: string,
432+
phone: string,
433+
email: string,
434+
guid: Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
435+
},
436+
autofillCreditCardDetail: {
437+
name: string,
438+
card: string,
439+
month: string,
440+
year: string,
441+
guid: Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
442+
}
416443
}
417444
```

docs/windowActions.md

+24
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,30 @@ Sets the clear browsing data popup detail
741741

742742

743743

744+
### setAutofillAddressDetail(currentDetail, originalDetail)
745+
746+
Sets the manage autofill address popup detail
747+
748+
**Parameters**
749+
750+
**currentDetail**: `Object`, Properties of the address to change to
751+
752+
**originalDetail**: `Object`, Properties of the address to edit
753+
754+
755+
756+
### setAutofillCreditCardDetail(currentDetail, originalDetail)
757+
758+
Sets the manage autofill credit card popup detail
759+
760+
**Parameters**
761+
762+
**currentDetail**: `Object`, Properties of the credit card to change to
763+
764+
**originalDetail**: `Object`, Properties of the credit card to edit
765+
766+
767+
744768

745769
* * *
746770

js/about/aboutActions.js

+54
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,60 @@ const AboutActions = {
129129

130130
createWallet: function () {
131131
ipc.send(messages.LEDGER_CREATE_WALLET)
132+
},
133+
134+
setLedgerEnabled: function (enabled) {
135+
ipc.send(messages.LEDGER_ENABLE, enabled)
136+
},
137+
138+
/**
139+
* Open a adding address dialog
140+
*/
141+
addAutofillAddress: function () {
142+
ipc.sendToHost(messages.ADD_AUTOFILL_ADDRESS)
143+
},
144+
145+
/**
146+
* Remove address
147+
*
148+
* @param {object} address - address to remove as per doc/state.md's autofillAddressDetail
149+
*/
150+
removeAutofillAddress: function (address) {
151+
ipc.send(messages.REMOVE_AUTOFILL_ADDRESS, address)
152+
},
153+
154+
/**
155+
* Open a edit address dialog
156+
*
157+
* @param {object} address - address to edit as per doc/state.md's autofillAddressDetail
158+
*/
159+
editAutofillAddress: function (address) {
160+
ipc.sendToHost(messages.EDIT_AUTOFILL_ADDRESS, address)
161+
},
162+
163+
/**
164+
* Open a adding credit card dialog
165+
*/
166+
addAutofillCreditCard: function () {
167+
ipc.sendToHost(messages.ADD_AUTOFILL_CREDIT_CARD)
168+
},
169+
170+
/**
171+
* Remove credit card
172+
*
173+
* @param {object} card - credit card to remove as per doc/state.md's autofillCreditCardDetail
174+
*/
175+
removeAutofillCreditCard: function (card) {
176+
ipc.send(messages.REMOVE_AUTOFILL_CREDIT_CARD, card)
177+
},
178+
179+
/**
180+
* Open a editing credit card dialog
181+
*
182+
* @param {object} card - credit card to edit as per doc/state.md's autofillCreditCardDetail
183+
*/
184+
editAutofillCreditCard: function (card) {
185+
ipc.sendToHost(messages.EDIT_AUTOFILL_CREDIT_CARD, card)
132186
}
133187
}
134188
module.exports = AboutActions

0 commit comments

Comments
 (0)