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

Commit

Permalink
move about page logic to browser process
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Apr 12, 2017
1 parent f5c60e6 commit 74b26a1
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 213 deletions.
23 changes: 23 additions & 0 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const tabState = require('../../common/state/tabState')
const windowConstants = require('../../../js/constants/windowConstants')
const {makeImmutable} = require('../../common/state/immutableUtil')
const {getFlashResourceId} = require('../../../js/flash')
const {l10nErrorText} = require('../../common/lib/httpUtil')

const tabsReducer = (state, action) => {
action = makeImmutable(action)
Expand Down Expand Up @@ -68,6 +69,28 @@ const tabsReducer = (state, action) => {
case appConstants.APP_FRAME_CHANGED:
state = tabState.updateFrame(state, action)
break
case windowConstants.WINDOW_SET_FRAME_ERROR:
{
const tabId = action.getIn(['frameProps', 'tabId'])
const tab = tabs.getWebContents(tabId)
if (tab) {
let currentIndex = tab.getCurrentEntryIndex()
let previousLocation = tab.getURL()
while (previousLocation === action.getIn(['errorDetails', 'url'])) {
previousLocation = tab.getURLAtIndex(--currentIndex)
}
let tabValue = tabState.getByTabId(state, tabId)
if (tabValue) {
tabValue = tabValue.set('aboutDetails', makeImmutable({
title: action.getIn(['errorDetails', 'title']) || l10nErrorText(action.getIn(['errorDetails', 'errorCode'])),
message: action.getIn(['errorDetails', 'message']),
previousLocation
}).merge(action.get('errorDetails')))
state = tabState.updateTabValue(state, tabValue)
}
}
}
break
}
return state
}
Expand Down
164 changes: 162 additions & 2 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ const appActions = require('../../js/actions/appActions')
const config = require('../../js/constants/config')
const Immutable = require('immutable')
const tabState = require('../common/state/tabState')
const {app, BrowserWindow, extensions, session} = require('electron')
const {app, BrowserWindow, extensions, session, ipcMain} = require('electron')
const {makeImmutable} = require('../common/state/immutableUtil')
const {getTargetAboutUrl, isSourceAboutUrl, newFrameUrl} = require('../../js/lib/appUrlUtil')
const {getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl} = require('../../js/lib/appUrlUtil')
const {isURL, getUrlFromInput} = require('../../js/lib/urlutil')
const {isSessionPartition} = require('../../js/state/frameStateUtil')
const {getOrigin} = require('../../js/state/siteUtil')
const {getSetting} = require('../../js/settings')
const settings = require('../../js/constants/settings')
const {getBaseUrl, aboutUrls} = require('../../js/lib/appUrlUtil')
const siteSettings = require('../../js/state/siteSettings')
const messages = require('../../js/constants/messages')
const siteUtil = require('../../js/state/siteUtil')
const aboutHistoryState = require('../common/state/aboutHistoryState')
const appStore = require('../../js/stores/appStore')
const appConfig = require('../../js/constants/appConfig')
const siteTags = require('../../js/constants/siteTags')
const {newTabMode} = require('../common/constants/settingsEnums')

let currentWebContents = {}
let currentPartitionNumber = 0
Expand Down Expand Up @@ -76,6 +85,157 @@ const getPartition = (createProperties) => {
return partition
}

// TODO(bridiver) - refactor this into an action
ipcMain.on(messages.ABOUT_COMPONENT_INITIALIZED, (e) => {
const tab = e.sender
const listener = () => {
if (!tab.isDestroyed()) {
const tabValue = tabState.getByTabId(appStore.getState(), tab.getId())
if (tabValue.get('active') === true) {
updateAboutDetails(tab, tabValue)
}
} else {
appStore.removeChangeListener(listener)
}
}
listener()

appStore.addChangeListener(listener)
tab.on('set-active', () => {
listener()
})
tab.on('did-navigate', () => {
appStore.removeChangeListener(listener)
})
})

const updateAboutDetails = (tab, tabValue) => {
const appState = appStore.getState()
const url = getSourceAboutUrl(tab.getURL())
let location = getBaseUrl(url)

// TODO(bridiver) - refactor these to use state helpers
const ledgerInfo = appState.get('ledgerInfo')
const publisherInfo = appState.get('publisherInfo')
const preferencesData = appState.getIn(['about', 'preferences'])
const appSettings = appState.get('settings')
let allSiteSettings = appState.get('siteSettings')
if (tabValue.get('incognito') === true) {
allSiteSettings = allSiteSettings.mergeDeep(appState.get('temporarySiteSettings'))
}
const extensions = appState.get('extensions')
const bookmarks = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK)).toList().sort(siteUtil.siteSort)
const bookmarkFolders = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK_FOLDER)).toList().sort(siteUtil.siteSort)
const sync = appState.get('sync')
const braveryDefaults = siteSettings.braveryDefaults(appState, appConfig)
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'])
const newTabDetail = appState.getIn(['about', 'newtab'])
const autofillCreditCards = appState.getIn(['autofill', 'creditCards'])
const autofillAddresses = appState.getIn(['autofill', 'addresses'])
const versionInformation = appState.getIn(['about', 'brave', 'versionInformation'])
const aboutDetails = tabValue.get('aboutDetails')
if (location === 'about:preferences' || location === 'about:contributions' || location === aboutUrls.get('about:contributions')) {
const ledgerData = ledgerInfo.merge(publisherInfo).merge(preferencesData)
tab.send(messages.LEDGER_UPDATED, ledgerData.toJS())
tab.send(messages.SETTINGS_UPDATED, appSettings.toJS())
tab.send(messages.SITE_SETTINGS_UPDATED, allSiteSettings.toJS())
tab.send(messages.SYNC_UPDATED, sync.toJS())
tab.send(messages.BRAVERY_DEFAULTS_UPDATED, braveryDefaults)
tab.send(messages.EXTENSIONS_UPDATED, extensions.toJS())
} else if (location === 'about:bookmarks' && bookmarks) {
tab.send(messages.BOOKMARKS_UPDATED, {
bookmarks: bookmarks.toJS(),
bookmarkFolders: bookmarkFolders.toJS()
})
} else if (location === 'about:history' && history) {
appActions.populateHistory()
tab.send(messages.HISTORY_UPDATED, aboutHistoryState.toJS())
tab.send(messages.SETTINGS_UPDATED, appSettings.toJS())
} else if (location === 'about:extensions' && extensions) {
tab.send(messages.EXTENSIONS_UPDATED, extensions.toJS())
} else if (location === 'about:adblock' && adblock) {
tab.send(messages.ADBLOCK_UPDATED, {
adblock: adblock.toJS(),
settings: appSettings.toJS(),
resources: require('ad-block/lib/regions')
})
} else if (location === 'about:downloads' && downloads) {
tab.send(messages.DOWNLOADS_UPDATED, {
downloads: downloads.toJS()
})
} else if (location === 'about:passwords' && passwords) {
tab.send(messages.PASSWORD_DETAILS_UPDATED, passwords.toJS())
tab.send(messages.PASSWORD_SITE_DETAILS_UPDATED,
allSiteSettings.filter((setting) => setting.get('savePasswords') === false).toJS())
} else if (location === 'about:flash') {
tab.send(messages.BRAVERY_DEFAULTS_UPDATED, braveryDefaults.toJS())
} else if (location === 'about:newtab') {
const showEmptyPage = getSetting(settings.NEWTAB_MODE) === newTabMode.EMPTY_NEW_TAB ||
// TODO: This can be removed once we're on muon 2.57.8 or above
tabValue.get('incognito') === true
const showImages = getSetting(settings.SHOW_DASHBOARD_IMAGES) && !showEmptyPage
tab.send(messages.NEWTAB_DATA_UPDATED, {
showEmptyPage,
showImages,
trackedBlockersCount,
adblockCount,
httpsUpgradedCount,
newTabDetail: newTabDetail.toJS()
})
} else if (location === 'about:autofill') {
const defaultSession = session.defaultSession
{
const guids = autofillAddresses.get('guid')
let list = []
guids.forEach((entry) => {
const address = defaultSession.autofill.getProfile(entry)
let addressDetail = {
name: address.full_name,
organization: address.company_name,
streetAddress: address.street_address,
city: address.city,
state: address.state,
postalCode: address.postal_code,
country: address.country_code,
phone: address.phone,
email: address.email,
guid: entry
}
list.push(addressDetail)
})
tab.send(messages.AUTOFILL_ADDRESSES_UPDATED, list)
}
{
const guids = autofillCreditCards.get('guid')
let list = []
guids.forEach((entry) => {
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
}
list.push(creditCardDetail)
})
tab.send(messages.AUTOFILL_CREDIT_CARDS_UPDATED, list)
}
} else if (location === 'about:brave') {
tab.send(messages.VERSION_INFORMATION_UPDATED, versionInformation.toJS())
}
// send state to about pages
if (aboutUrls.get(location) && aboutDetails) {
tab.send(messages.STATE_UPDATED, aboutDetails.toJS())
}
}

const api = {
init: (state, action) => {
process.on('open-url-from-tab', (e, source, targetUrl, disposition) => {
Expand Down
10 changes: 9 additions & 1 deletion app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ module.exports.cleanPerWindowData = (perWindowData, isShutdown) => {
delete frame.httpsEverywhere
delete frame.adblock
delete frame.noScript
delete frame.trackingProtection

// Guest instance ID's are not valid after restarting.
// Electron won't know about them.
Expand Down Expand Up @@ -632,6 +631,15 @@ module.exports.defaultAppState = () => {
pinnedTopSites: pinnedTopSites
}
},
trackingProtection: {
count: 0
},
adblock: {
count: 0
},
httpsEverywhere: {
count: 0
},
defaultWindowParams: {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/about/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ if (element) {
component.setState(detail)
}
})
ipc.sendToHost(ABOUT_COMPONENT_INITIALIZED)
ipc.send(ABOUT_COMPONENT_INITIALIZED)
}
Loading

0 comments on commit 74b26a1

Please sign in to comment.