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

Commit

Permalink
Update guids by personal-data-changed
Browse files Browse the repository at this point in the history
fix #4349
requires brave/muon#70

Auditors: @bridiver

Test Plan:
1. Prepare a fresh install brave (version > 0.12.3)
2. Lauch brave
3. open about:autofill
4. Add an address
5. The address entry should show on the page
6. Add a credit card
7. The credit card entry should show on the page
8. Verify address and credit card on http://www.roboform.com/filling-test-all-fields
  • Loading branch information
darkdh committed Oct 11, 2016
1 parent 7959e5c commit 8facffe
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 49 deletions.
14 changes: 14 additions & 0 deletions app/autofill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* 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/. */

const appActions = require('../js/actions/appActions')

module.exports.init = () => {
process.on('personal-data-changed', (profileGuids, creditCardGuids) => {
setImmediate(() => {
appActions.updateAutofillAddress(profileGuids)
appActions.updateAutofillCreditCard(creditCardGuids)
})
})
}
14 changes: 6 additions & 8 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ module.exports.setDefaultZoomLevel = (zoom) => {
}
}

module.exports.addAutofillAddress = (detail, oldGuid) => {
let guid = session.defaultSession.autofill.addProfile({
module.exports.addAutofillAddress = (detail, guid) => {
session.defaultSession.autofill.addProfile({
full_name: detail.name,
company_name: detail.organization,
street_address: detail.streetAddress,
Expand All @@ -656,24 +656,22 @@ module.exports.addAutofillAddress = (detail, oldGuid) => {
country_code: detail.country,
phone: detail.phone,
email: detail.email,
guid: oldGuid
guid: guid
})
return guid
}

module.exports.removeAutofillAddress = (guid) => {
session.defaultSession.autofill.removeProfile(guid)
}

module.exports.addAutofillCreditCard = (detail, oldGuid) => {
let guid = session.defaultSession.autofill.addCreditCard({
module.exports.addAutofillCreditCard = (detail, guid) => {
session.defaultSession.autofill.addCreditCard({
name: detail.name,
card_number: detail.card,
expiration_month: detail.month,
expiration_year: detail.year,
guid: oldGuid
guid: guid
})
return guid
}

module.exports.removeAutofillCreditCard = (guid) => {
Expand Down
2 changes: 2 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const downloadActions = require('../js/actions/downloadActions')
const SessionStore = require('./sessionStore')
const AppStore = require('../js/stores/appStore')
const PackageLoader = require('./package-loader')
const Autofill = require('./autofill')
const Extensions = require('./extensions')
const Filtering = require('./filtering')
const TrackingProtection = require('./trackingProtection')
Expand Down Expand Up @@ -418,6 +419,7 @@ app.on('ready', () => {
basicAuth.init()
contentSettings.init()
privacy.init()
Autofill.init()
Extensions.init()
Filtering.init()
SiteHacks.init()
Expand Down
20 changes: 20 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ Remove address data



### updateAutofillAddress(guids)

Update guids of address

**Parameters**

**guids**: `Array`, the guid array to access entries in autofill DB



### addAutofillCreditCard(detail, originalDetail)

Add credit card data
Expand All @@ -403,6 +413,16 @@ Remove credit card data



### updateAutofillCreditCard(guids)

Update guids of credit card

**Parameters**

**guids**: `Array`, the guid array to access entries in autofill DB



### windowBlurred(appWindowId)

Dispatches a message when appWindowId loses focus
Expand Down
22 changes: 22 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,17 @@ const appActions = {
})
},

/**
* Update guids of address
* @param {Array} guids - the guid array to access entries in autofill DB
*/
updateAutofillAddress: function (guids) {
AppDispatcher.dispatch({
actionType: AppConstants.APP_UPDATE_AUTOFILL_ADDRESS,
guids
})
},

/**
* Add credit card data
* @param {object} detail - the credit card to add as per doc/state.md's autofillCreditCardDetail
Expand All @@ -465,6 +476,17 @@ const appActions = {
})
},

/**
* Update guids of credit card
* @param {Array} guids - the guid array to access entries in autofill DB
*/
updateAutofillCreditCard: function (guids) {
AppDispatcher.dispatch({
actionType: AppConstants.APP_UPDATE_AUTOFILL_CREDIT_CARD,
guids
})
},

/**
* Dispatches a message when appWindowId loses focus
*
Expand Down
19 changes: 5 additions & 14 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,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 defaultSession = global.require('electron').remote.session.defaultSession
if (this.props.autofillAddresses) {
const guids = this.props.autofillAddresses.get('guid')
let list = []
guids.forEach((entry) => {
const address = currentWindow.webContents.session.autofill.getProfile(entry)
const valid = Object.getOwnPropertyNames(address).length > 0
const address = defaultSession.autofill.getProfile(entry)
let addressDetail = {
name: address.full_name,
organization: address.company_name,
Expand All @@ -135,32 +135,23 @@ class Frame extends ImmutableComponent {
email: address.email,
guid: entry
}
if (valid) {
list.push(addressDetail)
} else {
appActions.removeAutofillAddress(addressDetail)
}
list.push(addressDetail)
})
this.webview.send(messages.AUTOFILL_ADDRESSES_UPDATED, list)
}
if (this.props.autofillCreditCards) {
const guids = this.props.autofillCreditCards.get('guid')
let list = []
guids.forEach((entry) => {
const creditCard = currentWindow.webContents.session.autofill.getCreditCard(entry)
const valid = Object.getOwnPropertyNames(creditCard).length > 0
const creditCard = defaultSession.autofill.getCreditCard(entry)
let creditCardDetail = {
name: creditCard.name,
card: creditCard.card_number,
month: creditCard.expiration_month,
year: creditCard.expiration_year,
guid: entry
}
if (valid) {
list.push(creditCardDetail)
} else {
appActions.removeAutofillCreditCard(creditCardDetail)
}
list.push(creditCardDetail)
})
this.webview.send(messages.AUTOFILL_CREDIT_CARDS_UPDATED, list)
}
Expand Down
2 changes: 2 additions & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ const AppConstants = {
APP_SET_DICTIONARY: _, /** @param {string} locale */
APP_ADD_AUTOFILL_ADDRESS: _,
APP_REMOVE_AUTOFILL_ADDRESS: _,
APP_UPDATE_AUTOFILL_ADDRESS: _,
APP_ADD_AUTOFILL_CREDIT_CARD: _,
APP_REMOVE_AUTOFILL_CREDIT_CARD: _,
APP_UPDATE_AUTOFILL_CREDIT_CARD: _,
APP_SET_LOGIN_REQUIRED_DETAIL: _,
APP_SET_LOGIN_RESPONSE_DETAIL: _,
APP_WINDOW_BLURRED: _,
Expand Down
37 changes: 10 additions & 27 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,55 +633,38 @@ const handleAppAction = (action) => {
case AppConstants.APP_ADD_AUTOFILL_ADDRESS:
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'addresses', 'guid'],
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((guid) => {
return guid === action.originalDetail.get('guid')
}))

let guids = appState.getIn(['autofill', 'addresses', 'guid'])
const guid = Filtering.addAutofillAddress(action.detail.toJS(),
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((guid) => {
return guid === action.detail.get('guid')
}))
Filtering.removeAutofillAddress(action.detail.get('guid'))
appState = appState.setIn(['autofill', 'addresses', 'timestamp'], new Date().getTime())
break
}
case AppConstants.APP_UPDATE_AUTOFILL_ADDRESS:
appState = appState.setIn(['autofill', 'addresses', 'guid'], action.guids)
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((guid) => {
return guid === action.originalDetail.get('guid')
}))

let guids = appState.getIn(['autofill', 'creditCards', 'guid'])
const guid = Filtering.addAutofillCreditCard(action.detail.toJS(),
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((guid) => {
return guid === action.detail.get('guid')
}))
Filtering.removeAutofillCreditCard(action.detail.get('guid'))
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], new Date().getTime())
break
}
case AppConstants.APP_UPDATE_AUTOFILL_CREDIT_CARD:
appState = appState.setIn(['autofill', 'creditCards', 'guid'], action.guids)
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], new Date().getTime())
break
case AppConstants.APP_SET_LOGIN_REQUIRED_DETAIL:
appState = basicAuthState.setLoginRequiredDetail(appState, action.tabId, action.detail)
break
Expand Down

0 comments on commit 8facffe

Please sign in to comment.