Skip to content

Commit

Permalink
Autofill data add/edit method refactoring
Browse files Browse the repository at this point in the history
1. add/edit data on default session
2. Apply changes to brave/muon#61

requires brave/muon#61

fix brave#4155
fix brave#3725

Auditors: @bridiver, @bbondy

Test Plan:
STR in brave#4155 and brave#3725
  • Loading branch information
darkdh committed Sep 22, 2016
1 parent 2b76366 commit dd3efea
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 86 deletions.
68 changes: 25 additions & 43 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,57 +627,39 @@ module.exports.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.addAutofillAddress = (detail, oldGuid) => {
let guid = session.defaultSession.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,
guid: oldGuid
})
return guid
}

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

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.addAutofillCreditCard = (detail, oldGuid) => {
let guid = session.defaultSession.autofill.addCreditCard({
name: detail.name,
card_number: detail.card,
expiration_month: detail.month,
expiration_year: detail.year,
guid: oldGuid
})
return guid
}

module.exports.removeAutofillCreditCard = (guid) => {
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
if (guid[partition] !== undefined) {
ses.autofill.removeCreditCard(guid[partition])
}
}
session.defaultSession.autofill.removeCreditCard(guid)
}

module.exports.clearAutocompleteData = () => {
Expand Down
12 changes: 4 additions & 8 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,11 @@ AppStore
},
autofill: {
addresses: {
guid: [{
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}],
guid: Array<string>, // List of id used to access the autofill entry in database
timestamp: number
},
creditCards: {
guid: [{
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}],
guid: Array<string>, // List of id used to access the autofill entry in database
timestamp: number
}
},
Expand Down Expand Up @@ -508,14 +504,14 @@ WindowStore
country: string,
phone: string,
email: string,
guid: Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
guid: string // 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
guid: string // id used to access the autofill entry in database
},
importBrowserDataDetail: [
{
Expand Down
20 changes: 9 additions & 11 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ class Frame extends ImmutableComponent {
} else if (location === 'about:flash') {
this.webview.send(messages.BRAVERY_DEFAULTS_UPDATED, this.braveryDefaults)
} else if (location === 'about:autofill') {
const partition = FrameStateUtil.getPartition(this.frame)
if (this.props.autofillAddresses) {
const addresses = this.props.autofillAddresses.get('guid')
const guids = this.props.autofillAddresses.get('guid')
let list = []
addresses.forEach((entry) => {
const guid = entry.get(partition)
const address = currentWindow.webContents.session.autofill.getProfile(guid)
guids.forEach((entry) => {
console.log(entry)
const address = currentWindow.webContents.session.autofill.getProfile(entry)
const valid = Object.getOwnPropertyNames(address).length > 0
let addressDetail = {
name: address.full_name,
Expand All @@ -133,7 +132,7 @@ class Frame extends ImmutableComponent {
country: address.country_code,
phone: address.phone,
email: address.email,
guid: entry.toJS()
guid: entry
}
if (valid) {
list.push(addressDetail)
Expand All @@ -144,18 +143,17 @@ class Frame extends ImmutableComponent {
this.webview.send(messages.AUTOFILL_ADDRESSES_UPDATED, list)
}
if (this.props.autofillCreditCards) {
const creditCards = this.props.autofillCreditCards.get('guid')
const guids = this.props.autofillCreditCards.get('guid')
let list = []
creditCards.forEach((entry) => {
const guid = entry.get(partition)
const creditCard = currentWindow.webContents.session.autofill.getCreditCard(guid)
guids.forEach((entry) => {
const creditCard = currentWindow.webContents.session.autofill.getCreditCard(entry)
const valid = Object.getOwnPropertyNames(creditCard).length > 0
let creditCardDetail = {
name: creditCard.name,
card: creditCard.card_number,
month: creditCard.expiration_month,
year: creditCard.expiration_year,
guid: entry.toJS()
guid: entry
}
if (valid) {
list.push(creditCardDetail)
Expand Down
42 changes: 18 additions & 24 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,57 +613,51 @@ const handleAppAction = (action) => {
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'addresses', 'guid'],
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((address) => {
return Immutable.is(address, action.originalDetail.get('guid'))
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((guid) => {
return guid === action.originalDetail.get('guid')
}))

let addresses = appState.getIn(['autofill', 'addresses', 'guid'])
const guid = Filtering.addAutofillAddress(action.detail.toJS())
if (action.originalDetail.get('guid') !== undefined &&
!Immutable.is(Immutable.fromJS(guid), action.originalDetail.get('guid'))) {
Filtering.removeAutofillAddress(action.originalDetail.get('guid').toJS())
}
appState = appState.setIn(['autofill', 'addresses', 'guid'], addresses.push(Immutable.fromJS(guid)))
let guids = appState.getIn(['autofill', 'addresses', 'guid'])
const guid = Filtering.addAutofillAddress(action.detail.toJS(),
action.originalDetail.get('guid') === undefined ? '-1' : action.originalDetail.get('guid'))
appState = appState.setIn(['autofill', 'addresses', 'guid'], guids.push(guid))
appState = appState.setIn(['autofill', 'addresses', 'timestamp'], new Date().getTime())
break
}
case AppConstants.APP_REMOVE_AUTOFILL_ADDRESS:
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'addresses', 'guid'],
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((address) => {
return Immutable.is(address, action.detail.get('guid'))
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((guid) => {
return guid === action.detail.get('guid')
}))
Filtering.removeAutofillAddress(action.detail.get('guid').toJS())
Filtering.removeAutofillAddress(action.detail.get('guid'))
appState = appState.setIn(['autofill', 'addresses', 'timestamp'], new Date().getTime())
break
}
case AppConstants.APP_ADD_AUTOFILL_CREDIT_CARD:
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'creditCards', 'guid'],
appState.getIn(['autofill', 'creditCards', 'guid']).filterNot((card) => {
return Immutable.is(card, action.originalDetail.get('guid'))
appState.getIn(['autofill', 'creditCards', 'guid']).filterNot((guid) => {
return guid === action.originalDetail.get('guid')
}))

let creditCards = appState.getIn(['autofill', 'creditCards', 'guid'])
const guid = Filtering.addAutofillCreditCard(action.detail.toJS())
if (action.originalDetail.get('guid') !== undefined &&
!Immutable.is(Immutable.fromJS(guid), action.originalDetail.get('guid'))) {
Filtering.removeAutofillCreditCard(action.originalDetail.get('guid').toJS())
}
appState = appState.setIn(['autofill', 'creditCards', 'guid'], creditCards.push(Immutable.fromJS(guid)))
let guids = appState.getIn(['autofill', 'creditCards', 'guid'])
const guid = Filtering.addAutofillCreditCard(action.detail.toJS(),
action.originalDetail.get('guid') === undefined ? '-1' : action.originalDetail.get('guid'))
appState = appState.setIn(['autofill', 'creditCards', 'guid'], guids.push(guid))
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], new Date().getTime())
break
}
case AppConstants.APP_REMOVE_AUTOFILL_CREDIT_CARD:
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'creditCards', 'guid'],
appState.getIn(['autofill', 'creditCards', 'guid']).filterNot((card) => {
return Immutable.is(card, action.detail.get('guid'))
appState.getIn(['autofill', 'creditCards', 'guid']).filterNot((guid) => {
return guid === action.detail.get('guid')
}))
Filtering.removeAutofillCreditCard(action.detail.get('guid').toJS())
Filtering.removeAutofillCreditCard(action.detail.get('guid'))
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], new Date().getTime())
break
}
Expand Down

0 comments on commit dd3efea

Please sign in to comment.