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

Commit

Permalink
Add whether brave is default browser check
Browse files Browse the repository at this point in the history
fix #2105

Auditors: @bridiver, @bbondy
  • Loading branch information
darkdh committed Oct 17, 2016
1 parent cec105e commit c605b3e
Show file tree
Hide file tree
Showing 21 changed files with 288 additions and 5 deletions.
12 changes: 12 additions & 0 deletions app/common/state/defaultBrowserState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* 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 getSetting = require('../../../js/settings').getSetting
const settings = require('../../../js/constants/settings')

module.exports.shouldDisplayDialog = (state) => {
return !getSetting(settings.IS_DEFAULT_BROWSER) &&
!state.get('defaultBrowserCheckComplete') &&
getSetting(settings.CHECK_DEFAULT_ON_STARTUP)
}
4 changes: 4 additions & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,7 @@ cookies=Cookies
licenseTextOk=Ok
closeFirefoxWarningOk=Ok
importSuccessOk=Ok
makeBraveDefault=Ready to make Brave your default Browser?
checkDefaultOnStartup=Always check on startup
useBrave=Use Brave
notNow=Not Now
4 changes: 4 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,7 @@ sendUsageStatistics=Automatically send usage statistics to Brave
bookmarksBarTextOnly=Text only
bookmarksBarTextAndFavicon=Text and Favicons
bookmarksBarFaviconOnly=Favicons only
defaultBrowser=Brave is your default browser.
notDefaultBrowser=Brave is not your default browser.
setAsDefault=Set as default…
checkDefaultOnStartup=Always check on startup
9 changes: 7 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ 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 All @@ -82,6 +81,7 @@ const privacy = require('../js/state/privacy')
const basicAuth = require('./browser/basicAuth')
const async = require('async')
const tabs = require('./browser/tabs')
const settings = require('../js/constants/settings')

// temporary fix for #4517, #4518 and #4472
app.commandLine.appendSwitch('enable-use-zoom-for-dsf', 'false')
Expand All @@ -107,6 +107,8 @@ const prefsRestartLastValue = {}

const unsafeTestMasterKey = 'c66af15fc6555ebecf7cee3a5b82c108fd3cb4b587ab0b299d28e39c79ecc708'

const defaultProtocols = ['http', 'https']

const sessionStoreQueue = async.queue((task, callback) => {
task(callback)
}, 1)
Expand Down Expand Up @@ -421,7 +423,6 @@ app.on('ready', () => {
basicAuth.init()
contentSettings.init()
privacy.init()
Autofill.init()
Extensions.init()
Filtering.init()
SiteHacks.init()
Expand All @@ -442,6 +443,10 @@ app.on('ready', () => {
}
process.emit(messages.APP_INITIALIZED)

// Default browser checking
let isDefaultBrowser = defaultProtocols.every(p => app.isDefaultProtocolClient(p))
appActions.changeSetting(settings.IS_DEFAULT_BROWSER, isDefaultBrowser)

if (CmdLine.newWindowURL) {
appActions.newWindow(Immutable.fromJS({
location: CmdLine.newWindowURL
Expand Down
51 changes: 51 additions & 0 deletions app/renderer/components/checkDefaultBrowserDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* 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 React = require('react')
const ImmutableComponent = require('../../../js/components/immutableComponent')
const Dialog = require('../../../js/components/dialog')
const Button = require('../../../js/components/button')
const SwitchControl = require('../../../js/components/switchControl')
const appActions = require('../../../js/actions/appActions')
const windowActions = require('../../../js/actions/windowActions')
const settings = require('../../../js/constants/settings')

class CheckDefaultBrowserDialog extends ImmutableComponent {
constructor () {
super()
this.onCheckDefaultOnStartup = this.onCheckDefaultOnStartup.bind(this)
this.onNotNow = this.onNotNow.bind(this)
this.onUseBrave = this.onUseBrave.bind(this)
}

onCheckDefaultOnStartup (e) {
windowActions.setModalDialogDetail('checkDefaultBrowserDialog', {checkDefaultOnStartup: e.target.value})
}
onNotNow () {
appActions.defaultBrowserUpdated(false)
appActions.defaultBrowserCheckComplete()
appActions.changeSetting(settings.CHECK_DEFAULT_ON_STARTUP, this.props.checkDefaultOnStartup)
}
onUseBrave () {
appActions.defaultBrowserUpdated(true)
appActions.defaultBrowserCheckComplete()
appActions.changeSetting(settings.CHECK_DEFAULT_ON_STARTUP, this.props.checkDefaultOnStartup)
}
render () {
return <Dialog className='checkDefaultBrowserDialog' >
<div className='checkDefaultBrowser' onClick={(e) => e.stopPropagation()}>
<div className='braveIcon' />
<div className='makeBraveDefault' data-l10n-id='makeBraveDefault' />
<SwitchControl className='checkDefaultOnStartup' rightl10nId='checkDefaultOnStartup'
checkedOn={this.props.checkDefaultOnStartup} onClick={this.onCheckDefaultOnStartup} />
<div className='checkDefaultBrowserButtons'>
<Button l10nId='notNow' className='secondaryAltButton' onClick={this.onNotNow} />
<Button l10nId='useBrave' className='primaryButton' onClick={this.onUseBrave} />
</div>
</div>
</Dialog>
}
}

module.exports = CheckDefaultBrowserDialog
2 changes: 2 additions & 0 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ module.exports.cleanAppData = (data, isShutdown) => {
data.temporarySiteSettings = {}
// Delete Flash state since this is checked on startup
delete data.flashInitialized
// Delete defaultBrowserCheckComplete state since this is checked on startup
delete data.defaultBrowserCheckComplete
// Delete Recovery status on shut down
try {
delete data.ui.about.preferences.recoverySucceeded
Expand Down
16 changes: 16 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,22 @@ Dispatches a message to submit feedback



### defaultBrowserUpdated(useBrave)

Dispatch a message to set default browser

**Parameters**

**useBrave**: `boolean`, whether set Brave as default browser



### defaultBrowserCheckComplete()

Dispatch a message to indicate default browser check is complete




* * *

Expand Down
11 changes: 10 additions & 1 deletion docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ AppStore
'general.downloads.default-save-path': string, // default path for saving files
'general.autohide-menu': boolean, // true if the Windows menu should be autohidden
'general.disable-title-mode': boolean, // true if title mode should always be disabled
'general.check-default-on-startup': boolean, // true to check whether brave is default browser on startup
'general.is-default-browser': boolean, // true if brave is default browser
'search.default-search-engine': string, // name of search engine, from js/data/searchProviders.js
'search.offer-search-suggestions': boolean, // true if suggestions should be offered from the default search engine when available.
'tabs.switch-to-new-tabs': boolean, // true if newly opened tabs should be focused immediately
Expand Down Expand Up @@ -205,7 +207,8 @@ AppStore
},
menu: {
template: object // used on Windows and by our tests: template object with Menubar control
}
},
defaultBrowserCheckComplete: boolean // true to indicate default browser check is complete
}
```

Expand Down Expand Up @@ -526,6 +529,12 @@ WindowStore
favorites: boolean,
mergeFavorites: boolean,
cookies: boolean
},
modalDialogDetail: {
[className]: {
Object // props
},
...
}
}
```
12 changes: 12 additions & 0 deletions docs/windowActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,18 @@ Fired when window receives or loses focus



### setModalDialogDetail(className, props)

Set Modal Dialog detail

**Parameters**

**className**: `string`, name of modal dialog

**props**: `Object`, properties of the modal dialog




* * *

Expand Down
10 changes: 10 additions & 0 deletions js/about/aboutActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ const aboutActions = {
aboutActions.dispatchAction({
actionType: appConstants.APP_SUBMIT_FEEDBACK
})
},

/**
* Dispatch a message to set default browser
*/
setAsDefaultBrowser: function () {
aboutActions.dispatchAction({
actionType: appConstants.APP_DEFAULT_BROWSER_UPDATED,
useBrave: true
})
}
}
module.exports = aboutActions
17 changes: 17 additions & 0 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ class GeneralTab extends ImmutableComponent {
super()
this.importBrowserDataNow = this.importBrowserDataNow.bind(this)
this.onChangeSetting = this.onChangeSetting.bind(this)
this.setAsDefaultBrowser = this.setAsDefaultBrowser.bind(this)
}

importBrowserDataNow () {
Expand All @@ -598,6 +599,10 @@ class GeneralTab extends ImmutableComponent {
this.props.onChangeSetting(key, value)
}

setAsDefaultBrowser () {
aboutActions.setAsDefaultBrowser()
}

enabled (keyArray) {
return keyArray.every((key) => getSetting(key, this.props.settings) === true)
}
Expand All @@ -613,6 +618,13 @@ class GeneralTab extends ImmutableComponent {
const disableShowHomeButton = !homepage || !homepage.length
const disableBookmarksBarSelect = !getSetting(settings.SHOW_BOOKMARKS_TOOLBAR, this.props.settings)
const defaultLanguage = this.props.languageCodes.find((lang) => lang.includes(navigator.language)) || 'en-US'
const defaultBrowser = getSetting(settings.IS_DEFAULT_BROWSER, this.props.settings)
? <div className='sectionTitle' data-l10n-id='defaultBrowser' />
: <div>
<div className='sectionTitle' data-l10n-id='notDefaultBrowser' />
<Button l10nId='setAsDefault' className='primaryButton setAsDefaultButton'
onClick={this.setAsDefaultBrowser} />
</div>

return <SettingsList>
<div className='sectionTitle' data-l10n-id='generalSettings' />
Expand Down Expand Up @@ -661,6 +673,11 @@ class GeneralTab extends ImmutableComponent {
onClick={this.importBrowserDataNow} />
</SettingItem>
</SettingsList>
<SettingsList>
{defaultBrowser}
<SettingCheckbox dataL10nId='checkDefaultOnStartup' prefKey={settings.CHECK_DEFAULT_ON_STARTUP}
settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
</SettingsList>
</SettingsList>
}
}
Expand Down
21 changes: 21 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,27 @@ const appActions = {
AppDispatcher.dispatch({
actionType: AppConstants.APP_SUBMIT_FEEDBACK
})
},

/**
* Dispatch a message to set default browser
*
* @param {boolean} useBrave - whether set Brave as default browser
*/
defaultBrowserUpdated: function (useBrave) {
AppDispatcher.dispatch({
actionType: AppConstants.APP_DEFAULT_BROWSER_UPDATED,
useBrave
})
},

/**
* Dispatch a message to indicate default browser check is complete
*/
defaultBrowserCheckComplete: function () {
AppDispatcher.dispatch({
actionType: AppConstants.APP_DEFAULT_BROWSER_CHECK_COMPLETE
})
}
}

Expand Down
13 changes: 13 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,19 @@ const windowActions = {
actionType: WindowConstants.WINDOW_ON_FOCUS_CHANGED,
hasFocus
})
},

/**
* Set Modal Dialog detail
* @param {string} className - name of modal dialog
* @param {Object} props - properties of the modal dialog
*/
setModalDialogDetail: function (className, props) {
dispatch({
actionType: WindowConstants.WINDOW_SET_MODAL_DIALOG_DETAIL,
className,
props
})
}
}

Expand Down
21 changes: 21 additions & 0 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const NoScriptInfo = require('./noScriptInfo')
const LongPressButton = require('./longPressButton')
const Menubar = require('../../app/renderer/components/menubar')
const WindowCaptionButtons = require('../../app/renderer/components/windowCaptionButtons')
const CheckDefaultBrowserDialog = require('../../app/renderer/components/checkDefaultBrowserDialog')

// Constants
const config = require('../constants/config')
Expand All @@ -60,6 +61,7 @@ const basicAuthState = require('../../app/common/state/basicAuthState')
const extensionState = require('../../app/common/state/extensionState')
const FrameStateUtil = require('../state/frameStateUtil')
const searchProviders = require('../data/searchProviders')
const defaultBrowserState = require('../../app/common/state/defaultBrowserState')

// Util
const cx = require('../lib/classSet')
Expand Down Expand Up @@ -93,6 +95,7 @@ class Main extends ImmutableComponent {
this.onHideAutofillCreditCardPanel = this.onHideAutofillCreditCardPanel.bind(this)
this.onHideNoScript = this.onHideNoScript.bind(this)
this.onHideReleaseNotes = this.onHideReleaseNotes.bind(this)
this.onHideCheckDefaultBrowserDialog = this.onHideCheckDefaultBrowserDialog.bind(this)
this.onBraveMenu = this.onBraveMenu.bind(this)
this.onHamburgerMenu = this.onHamburgerMenu.bind(this)
this.onTabContextMenu = this.onTabContextMenu.bind(this)
Expand Down Expand Up @@ -624,6 +627,10 @@ class Main extends ImmutableComponent {
windowActions.setReleaseNotesVisible(false)
}

onHideCheckDefaultBrowserDialog () {
windowActions.setModalDialogDetail('checkDefaultBrowserDialog')
}

enableNoScript (settings) {
return siteSettings.activeSettings(settings, this.props.appState, appConfig).noScript === true
}
Expand Down Expand Up @@ -826,6 +833,8 @@ class Main extends ImmutableComponent {
const activeRequestedLocation = this.activeRequestedLocation
const noScriptIsVisible = this.props.windowState.getIn(['ui', 'noScriptInfo', 'isVisible'])
const releaseNotesIsVisible = this.props.windowState.getIn(['ui', 'releaseNotes', 'isVisible'])
const checkDefaultBrowserDialogIsVisible =
currentWindow.isFocused() && defaultBrowserState.shouldDisplayDialog(this.props.appState)
const braverySettings = siteSettings.activeSettings(activeSiteSettings, this.props.appState, appConfig)
const loginRequiredDetail = activeFrame ? basicAuthState.getLoginRequiredDetail(this.props.appState, activeFrame.get('tabId')) : null
const customTitlebar = this.customTitlebar
Expand All @@ -838,6 +847,7 @@ class Main extends ImmutableComponent {
!autofillAddressPanelIsVisible &&
!autofillCreditCardPanelIsVisible &&
!releaseNotesIsVisible &&
!checkDefaultBrowserDialogIsVisible &&
!noScriptIsVisible &&
activeFrame && !activeFrame.getIn(['security', 'loginRequiredDetail']) &&
!customTitlebar.menubarSelectedIndex
Expand Down Expand Up @@ -1025,6 +1035,17 @@ class Main extends ImmutableComponent {
onHide={this.onHideReleaseNotes} />
: null
}
{
checkDefaultBrowserDialogIsVisible
? <CheckDefaultBrowserDialog
checkDefaultOnStartup={
this.props.windowState.getIn(['modalDialogDetail', 'checkDefaultBrowserDialog']) === undefined
? getSetting(settings.CHECK_DEFAULT_ON_STARTUP)
: this.props.windowState.getIn(['modalDialogDetail', 'checkDefaultBrowserDialog', 'checkDefaultOnStartup'])
}
onHide={this.onHideCheckDefaultBrowserDialog} />
: null
}

<UpdateBar updates={this.props.appState.get('updates')} />
{
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ module.exports = {
'general.show-home-button': false,
'general.useragent.value': null, // Set at runtime
'general.autohide-menu': true,
'general.check-default-on-startup': true,
'search.default-search-engine': 'Google',
'search.offer-search-suggestions': false, // false by default for privacy reasons
'tabs.switch-to-new-tabs': false,
Expand Down
Loading

0 comments on commit c605b3e

Please sign in to comment.