Skip to content

Commit

Permalink
Merge pull request brave#9085 from brave/8906
Browse files Browse the repository at this point in the history
Update passwords and blacklist when deleting
  • Loading branch information
darkdh authored Jun 9, 2017
2 parents 902ee0d + 3fece85 commit 66913ab
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
17 changes: 17 additions & 0 deletions app/autofill.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const electron = require('electron')
const session = electron.session
const appActions = require('../js/actions/appActions')
const messages = require('../js/constants/messages')

module.exports.init = () => {
process.on('personal-data-changed', (profileGuids, creditCardGuids) => {
Expand Down Expand Up @@ -68,3 +69,19 @@ module.exports.removeLogin = (form) => {
module.exports.clearLogins = (form) => {
session.defaultSession.autofill.clearLogins(form)
}

module.exports.getAutofillableLogins = (tab) => {
session.defaultSession.autofill.getAutofillableLogins((result) => {
if (tab && !tab.isDestroyed()) {
tab.send(messages.PASSWORD_DETAILS_UPDATED, result)
}
})
}

module.exports.getBlackedlistLogins = (tab) => {
session.defaultSession.autofill.getBlackedlistLogins((result) => {
if (tab && !tab.isDestroyed()) {
tab.send(messages.PASSWORD_SITE_DETAILS_UPDATED, result)
}
})
}
23 changes: 23 additions & 0 deletions app/browser/reducers/passwordManagerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ const updatePassword = (username, origin, tabId) => {
}
}

const removePassword = (form) => {
autofill.removeLogin(form)
}

const removePasswordSite = (form) => {
let newForm = form
delete newForm['blacklisted_by_user']
autofill.updateLogin(newForm)
}

const clearPasswords = () => {
autofill.clearLogins()
}

const migrate = (state) => {
const passwords = state.get('passwords')
if (passwords.size) {
Expand Down Expand Up @@ -230,6 +244,15 @@ const passwordManagerReducer = (state, action, immutableAction) => {
case appConstants.APP_UPDATE_PASSWORD:
updatePassword(action.get('username'), action.get('origin'), action.get('tabId'))
break
case appConstants.APP_REMOVE_PASSWORD:
removePassword(action.get('passwordDetail').toJS())
break
case appConstants.APP_REMOVE_PASSWORD_SITE:
removePasswordSite(action.get('passwordDetail').toJS())
break
case appConstants.APP_CLEAR_PASSWORDS:
clearPasswords()
break
}
return state
}
Expand Down
13 changes: 4 additions & 9 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {cleanupWebContents, currentWebContents, getWebContents, updateWebContents
const {FilterOptions} = require('ad-block')
const urlParse = require('../common/urlParse')
const {isResourceEnabled} = require('../filtering')
const autofill = require('../autofill')

let currentPartitionNumber = 0
const incrementPartitionNumber = () => ++currentPartitionNumber
Expand Down Expand Up @@ -172,7 +173,6 @@ const updateAboutDetails = (tab, tabValue) => {
const history = aboutHistoryState.getHistory(appState)
const adblock = appState.get('adblock')
const downloads = appState.get('downloads')
const passwords = appState.get('passwords')
const trackedBlockersCount = appState.getIn(['trackingProtection', 'count'])
const adblockCount = appState.getIn(['adblock', 'count'])
const httpsUpgradedCount = appState.getIn(['httpsEverywhere', 'count'])
Expand Down Expand Up @@ -213,14 +213,9 @@ const updateAboutDetails = (tab, tabValue) => {
tab.send(messages.DOWNLOADS_UPDATED, {
downloads: downloads.toJS()
})
} else if (location === 'about:passwords' && passwords) {
const defaultSession = session.defaultSession
defaultSession.autofill.getAutofillableLogins((result) => {
tab.send(messages.PASSWORD_DETAILS_UPDATED, result)
})
defaultSession.autofill.getBlackedlistLogins((result) => {
tab.send(messages.PASSWORD_SITE_DETAILS_UPDATED, result)
})
} else if (location === 'about:passwords') {
autofill.getAutofillableLogins(tab)
autofill.getBlackedlistLogins(tab)
} else if (location === 'about:flash') {
tab.send(messages.BRAVERY_DEFAULTS_UPDATED, braveryDefaults.toJS())
} else if (location === 'about:newtab') {
Expand Down
11 changes: 0 additions & 11 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,6 @@ const handleAppAction = (action) => {
case appConstants.APP_NEW_WINDOW:
createWindow(action)
break
case appConstants.APP_REMOVE_PASSWORD:
autofill.removeLogin(action.passwordDetail.toJS())
break
case appConstants.APP_REMOVE_PASSWORD_SITE:
let newPasswordDetail = action.passwordDetail.toJS()
delete newPasswordDetail['blacklisted_by_user']
autofill.updateLogin(newPasswordDetail)
break
case appConstants.APP_CLEAR_PASSWORDS:
autofill.clearLogins()
break
case appConstants.APP_CHANGE_NEW_TAB_DETAIL:
appState = aboutNewTabState.mergeDetails(appState, action)
if (action.refresh) {
Expand Down

0 comments on commit 66913ab

Please sign in to comment.