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

Commit

Permalink
Merge branch 'master' into dev-channel
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Feb 1, 2016
2 parents af10083 + 1cda6ee commit 7da9707
Show file tree
Hide file tree
Showing 28 changed files with 312 additions and 110 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [0.7.12](https://github.com/brave/browser-laptop/releases/v0.7.12dev)
- Various crash fixes and window.opener fixes.
- Fix for state saving when an update is applied.
- Fix for update error handling when on a flaky connection.
- Visual indicator for Session Tabs added.
- Installers and updates reduced by ~40%.
- Windows taskbar grouping fix.
- Initial window size is now bigger.
- Various keyboard shortcuts added.
- HTTPS Everywhere fixes.

## [0.7.11](https://github.com/brave/browser-laptop/releases/v0.7.11dev)

- Security fix (Severity: High): Prevent BrowserWindow from navigating to remote content ([#445](https://github.com/brave/browser-laptop/issues/445)). Impact: if the user is tricked into dragging and dropping a malicious link outside of the tab content area, the linked site is loaded outside the webview sandbox and can compromise the user's system.
Expand Down
57 changes: 57 additions & 0 deletions app/content/webviewPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ function hasSelection (node) {
return false
}

/**
* Whether an element is editable or can be typed into.
* @param {Element} elem
* @return {boolean}
*/
function isEditable (elem) {
// TODO: find other node types that are editable
return (elem.contentEditable === 'true' ||
elem.nodeName === 'INPUT' ||
elem.nodeName === 'TEXTAREA')
}

/**
* Whether we are on OS X
* @return {boolean}
*/
function isPlatformOSX () {
// TODO: navigator.platform is getting deprecated
return window.navigator.platform.includes('Mac')
}

document.addEventListener('contextmenu', (e) => {
var name = e.target.nodeName.toUpperCase()
var nodeProps = {
Expand All @@ -210,12 +231,48 @@ document.addEventListener('contextmenu', (e) => {
e.preventDefault()
}, false)

var shiftDown = false
var cmdDown = false
document.onkeydown = (e) => {
switch (e.keyCode) {
case KeyCodes.ESC:
e.preventDefault()
ipc.send(messages.STOP_LOAD)
break
case KeyCodes.BACKSPACE:
const msg = shiftDown ? messages.GO_FORWARD : messages.GO_BACK
if (!isEditable(document.activeElement)) {
ipc.send(msg)
}
break
case KeyCodes.SHIFT:
shiftDown = true
break
case KeyCodes.CMD1:
case KeyCodes.CMD2:
cmdDown = true
break
case KeyCodes.LEFT:
if (cmdDown && !isEditable(document.activeElement) && isPlatformOSX()) {
ipc.send(messages.GO_BACK)
}
break
case KeyCodes.RIGHT:
if (cmdDown && !isEditable(document.activeElement) && isPlatformOSX()) {
ipc.send(messages.GO_FORWARD)
}
break
}
}
document.onkeyup = (e) => {
switch (e.keyCode) {
case KeyCodes.SHIFT:
shiftDown = false
break
case KeyCodes.CMD1:
case KeyCodes.CMD2:
cmdDown = false
break
}
}

Expand Down
15 changes: 15 additions & 0 deletions app/dates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const moment = require('moment')

exports.todayYMD = () => {
return moment().format('YYYY-MM-DD')
}

exports.todayWOY = () => {
return moment().isoWeek()
}

// Months a returned zero based from moment
// We add 1 to make sure January does not fail a truth test
exports.todayMonth = () => {
return moment().month() + 1
}
5 changes: 3 additions & 2 deletions app/httpsEverywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ function onBeforeHTTPRequest (details, cb) {
return
}

if (canonicalizeUrl(details.url) in redirectBlacklist) {
if (redirectBlacklist.includes(canonicalizeUrl(details.url))) {
// Don't try to rewrite this request, it'll probably just redirect again.
console.log('https everywhere ignoring blacklisted url', details.url)
cb({})
} else {
getRewrittenUrl(details.url, (url) => {
Expand Down Expand Up @@ -232,7 +233,7 @@ function onBeforeRedirect (details) {
*/
function canonicalizeUrl (url) {
var parsed = urlParse(url)
return [parsed.host, parsed.pathname].join('/')
return [parsed.host, parsed.pathname].join('')
}

/**
Expand Down
31 changes: 24 additions & 7 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

'use strict'

// windows installation events etc...
if (process.platform === 'win32') {
// TODO - register browser as HTTP handler in Windows (maybe need to fork)
if (require('electron-squirrel-startup')) {
process.exit(0)
}
require('./windowsInit')
}

const Immutable = require('immutable')
Expand All @@ -31,6 +27,7 @@ const AdBlock = require('./adBlock')
const HttpsEverywhere = require('./httpsEverywhere')
const SiteHacks = require('./siteHacks')
const CmdLine = require('./cmdLine')
const UpdateStatus = require('../js/constants/updateStatus')

let loadAppStatePromise = SessionStore.loadAppState().catch(() => {
return SessionStore.defaultAppState()
Expand All @@ -47,9 +44,23 @@ const saveIfAllCollected = () => {
const ignoreCatch = () => {}

if (process.env.NODE_ENV !== 'test') {
// If the status is still UPDATE_AVAILABLE then the user wants to quit
// and not restart
if (appState.updates.status === UpdateStatus.UPDATE_AVAILABLE ||
appState.updates.status === UpdateStatus.UPDATE_AVAILABLE_DEFERRED) {
appState.updates.status = UpdateStatus.UPDATE_APPLYING_NO_RESTART
}

SessionStore.saveAppState(appState).catch(ignoreCatch).then(() => {
sessionStateStoreAttempted = true
app.quit()
// If there's an update to apply, then do it here.
// Otherwise just quit.
if (appState.updates.status === UpdateStatus.UPDATE_APPLYING_NO_RESTART ||
appState.updates.status === UpdateStatus.UPDATE_APPLYING_RESTART) {
Updater.quitAndInstall()
} else {
app.quit()
}
})
} else {
sessionStateStoreAttempted = true
Expand Down Expand Up @@ -134,6 +145,12 @@ app.on('ready', function () {
ipcMain.on(messages.STOP_LOAD, () => {
BrowserWindow.getFocusedWindow().webContents.send(messages.STOP_LOAD)
})
ipcMain.on(messages.GO_BACK, () => {
BrowserWindow.getFocusedWindow().webContents.send(messages.GO_BACK)
})
ipcMain.on(messages.GO_FORWARD, () => {
BrowserWindow.getFocusedWindow().webContents.send(messages.GO_FORWARD)
})

Menu.init()

Expand All @@ -146,7 +163,7 @@ app.on('ready', function () {
SiteHacks.init()

ipcMain.on(messages.UPDATE_REQUESTED, () => {
Updater.update()
Updater.updateNowRequested()
})

// Setup the crash handling
Expand Down
2 changes: 0 additions & 2 deletions app/localShortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ module.exports.register = (win) => {
const simpleWebContentEvents = [
['CmdOrCtrl+Shift+]', messages.SHORTCUT_NEXT_TAB],
['CmdOrCtrl+Shift+[', messages.SHORTCUT_PREV_TAB],
['CmdOrCtrl+Right', messages.SHORTCUT_ACTIVE_FRAME_FORWARD],
['CmdOrCtrl+Left', messages.SHORTCUT_ACTIVE_FRAME_BACK],
['CmdOrCtrl+9', messages.SHORTCUT_SET_ACTIVE_FRAME_TO_LAST]
]

Expand Down
5 changes: 4 additions & 1 deletion app/locales/en-US/app.l20n
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
<updateViewLog "View log">
<updateHide "Hide">

<sessionInfo "This tab uses partition {{$partitionNumber}}">
<sessionInfoCommon "This tab uses session {{$partitionNumber}}">
<sessionInfo "{{sessionInfoCommon}}">
<sessionInfoTab
title: "{{sessionInfoCommon}}">

<findResults "{{$activeMatchOrdinal}} of {{$numberOfMatches}}">

Expand Down
15 changes: 5 additions & 10 deletions app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const electron = require('electron')
const BrowserWindow = electron.BrowserWindow
const AppConfig = require('../js/constants/appConfig')
const Menu = require('menu')
const messages = require('../js/constants/messages')
Expand Down Expand Up @@ -70,15 +69,6 @@ const init = (args) => {
}

const fileMenu = [
{
label: 'Check for updates ...',
click: function (item, focusedWindow) {
if (BrowserWindow.getAllWindows().length === 0) {
AppActions.newWindow()
}
process.emit(messages.CHECK_FOR_UPDATE)
}
},
// Note: we are keeping this here for testing. Calling process.crash() from the inspector does not create a crash report.
// {
// label: 'Crash!!!!!',
Expand Down Expand Up @@ -201,6 +191,9 @@ const init = (args) => {
if (isWindows) {
fileMenu.push(CommonMenu.separatorMenuItem)
fileMenu.push(CommonMenu.quitMenuItem)
helpMenu.push(CommonMenu.separatorMenuItem)
helpMenu.push(CommonMenu.checkForUpdateMenuItem)
helpMenu.push(CommonMenu.separatorMenuItem)
helpMenu.push(aboutBraveMenuItem)
}

Expand Down Expand Up @@ -515,6 +508,8 @@ const init = (args) => {
submenu: [
aboutBraveMenuItem,
CommonMenu.separatorMenuItem,
CommonMenu.checkForUpdateMenuItem,
CommonMenu.separatorMenuItem,
preferencesMenuItem,
CommonMenu.separatorMenuItem,
{
Expand Down
19 changes: 14 additions & 5 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const fs = require('fs')
const path = require('path')
const app = require('app')
const UpdateStatus = require('../js/constants/updateStatus')
const sessionStorageVersion = 1
const sessionStorageName = `session-store-${sessionStorageVersion}`
const storagePath = path.join(app.getPath('userData'), sessionStorageName)
Expand All @@ -34,11 +35,6 @@ module.exports.saveAppState = (payload) => {
wndPayload.frames = wndPayload.frames.filter(frame => !frame.isPrivate))
}

// Always recalculate the update status
if (payload.updates) {
delete payload.updates.status
}

// payload.frames = payload.frames.filter(frame => !frame.isPrivate)
fs.writeFile(storagePath, JSON.stringify(payload), (err) => {
if (err) {
Expand Down Expand Up @@ -159,6 +155,19 @@ module.exports.loadAppState = () => {
reject(e)
return
}
// Always recalculate the update status
if (data.updates) {
const updateStatus = data.updates.status
delete data.updates.status
// The process always restarts after an update so if the state
// indicates that a restart isn't wanted, close right away.
if (updateStatus === UpdateStatus.UPDATE_APPLYING_NO_RESTART) {
module.exports.saveAppState(data)
// Exit immediately without doing the session store saving stuff
// since we want the same state saved except for the update status
app.exit(0)
}
}
if (data.perWindowState) {
data.perWindowState.forEach(module.exports.cleanSessionData)
}
Expand Down
Loading

0 comments on commit 7da9707

Please sign in to comment.