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 43c0100 commit 98be423
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 117 deletions.
56 changes: 56 additions & 0 deletions app/autofill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* 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 electron = require('electron')
const session = electron.session
const appActions = require('../js/actions/appActions')

module.exports.init = () => {
process.on('personal-data-changed', (profileGuids, creditCardGuids) => {
setImmediate(() => {
appActions.autofillDataChanged(profileGuids, creditCardGuids)
})
})
}

module.exports.addAutofillAddress = (detail, 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: guid
})
}

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

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: guid
})
}

module.exports.removeAutofillCreditCard = (guid) => {
session.defaultSession.autofill.removeCreditCard(guid)
}

module.exports.clearAutocompleteData = () => {
session.defaultSession.autofill.clearAutocompleteData()
}

module.exports.clearAutofillData = () => {
session.defaultSession.autofill.clearAutofillData()
}
49 changes: 0 additions & 49 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,55 +645,6 @@ module.exports.setDefaultZoomLevel = (zoom) => {
}
}

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) => {
session.defaultSession.autofill.removeProfile(guid)
}

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) => {
session.defaultSession.autofill.removeCreditCard(guid)
}

module.exports.clearAutocompleteData = () => {
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
ses.autofill.clearAutocompleteData()
}
}

module.exports.clearAutofillData = () => {
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
ses.autofill.clearAutofillData()
}
}

module.exports.getMainFrameUrl = (details) => {
if (details.resourceType === 'mainFrame') {
return details.url
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 @@ -420,6 +421,7 @@ app.on('ready', () => {
basicAuth.init()
contentSettings.init()
privacy.init()
Autofill.init()
Extensions.init()
Filtering.init()
SiteHacks.init()
Expand Down
5 changes: 3 additions & 2 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {tabFromFrame} = require('../js/state/frameStateUtil')
const siteUtil = require('../js/state/siteUtil')
const sessionStorageVersion = 1
const filtering = require('./filtering')
const autofill = require('./autofill')
// const tabState = require('./common/state/tabState')

const getSetting = require('../js/settings').getSetting
Expand Down Expand Up @@ -246,11 +247,11 @@ module.exports.cleanAppData = (data, isShutdown) => {
}
const clearAutocompleteData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA) === true
if (clearAutocompleteData) {
filtering.clearAutocompleteData()
autofill.clearAutocompleteData()
}
const clearAutofillData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOFILL_DATA) === true
if (clearAutofillData) {
filtering.clearAutofillData()
autofill.clearAutofillData()
}
const clearSiteSettings = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_SITE_SETTINGS) === true
if (clearSiteSettings) {
Expand Down
12 changes: 12 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,18 @@ Remove credit card data



### autofillDataChanged(addressGuids, creditCardGuids)

Autofill data changed

**Parameters**

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

**creditCardGuids**: `Array`, the guid array to access credit card entries in autofill DB



### windowBlurred(appWindowId)

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

/**
* Autofill data changed
* @param {Array} addressGuids - the guid array to access address entries in autofill DB
* @param {Array} creditCardGuids - the guid array to access credit card entries in autofill DB
*/
autofillDataChanged: function (addressGuids, creditCardGuids) {
AppDispatcher.dispatch({
actionType: AppConstants.APP_AUTOFILL_DATA_CHANGED,
addressGuids,
creditCardGuids
})
},

/**
* 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
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const AppConstants = {
APP_REMOVE_AUTOFILL_ADDRESS: _,
APP_ADD_AUTOFILL_CREDIT_CARD: _,
APP_REMOVE_AUTOFILL_CREDIT_CARD: _,
APP_AUTOFILL_DATA_CHANGED: _,
APP_SET_LOGIN_REQUIRED_DETAIL: _,
APP_SET_LOGIN_RESPONSE_DETAIL: _,
APP_WINDOW_BLURRED: _,
Expand Down
72 changes: 20 additions & 52 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const locale = require('../../app/locale')
const path = require('path')
const {channel} = require('../../app/channel')
const os = require('os')
const autofill = require('../../app/autofill')

// state helpers
const basicAuthState = require('../../app/common/state/basicAuthState')
Expand Down Expand Up @@ -623,12 +624,10 @@ const handleAppAction = (action) => {
Filtering.clearStorageData()
}
if (action.clearDataDetail.get('autocompleteData')) {
const Filtering = require('../../app/filtering')
Filtering.clearAutocompleteData()
autofill.clearAutocompleteData()
}
if (action.clearDataDetail.get('autofillData')) {
const Filtering = require('../../app/filtering')
Filtering.clearAutofillData()
autofill.clearAutofillData()
}
if (action.clearDataDetail.get('savedSiteSettings')) {
appState = appState.set('siteSettings', Immutable.Map())
Expand All @@ -648,57 +647,26 @@ const handleAppAction = (action) => {
break
}
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(),
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
}
autofill.addAutofillAddress(action.detail.toJS(),
action.originalDetail.get('guid') === undefined ? '-1' : action.originalDetail.get('guid'))
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
}
autofill.removeAutofillAddress(action.detail.get('guid'))
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(),
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
}
autofill.addAutofillCreditCard(action.detail.toJS(),
action.originalDetail.get('guid') === undefined ? '-1' : action.originalDetail.get('guid'))
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
}
autofill.removeAutofillCreditCard(action.detail.get('guid'))
break
case AppConstants.APP_AUTOFILL_DATA_CHANGED:
const date = new Date().getTime()
appState = appState.setIn(['autofill', 'addresses', 'guid'], action.addressGuids)
appState = appState.setIn(['autofill', 'addresses', 'timestamp'], date)
appState = appState.setIn(['autofill', 'creditCards', 'guid'], action.creditCardGuids)
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], date)
break
case AppConstants.APP_SET_LOGIN_REQUIRED_DETAIL:
appState = basicAuthState.setLoginRequiredDetail(appState, action.tabId, action.detail)
break
Expand Down

0 comments on commit 98be423

Please sign in to comment.