diff --git a/.npmrc b/.npmrc index 01a91a3a532..4982f59a0e9 100644 --- a/.npmrc +++ b/.npmrc @@ -1,5 +1,5 @@ -runtime = electron -target = 1.4.0 +#runtime = electron +#target = 1.4.0 target_arch = x64 -brave_electron_version = 1.4.31 -disturl = https://atom.io/download/atom-shell +#brave_electron_version = 1.4.23 +#disturl = https://atom.io/download/atom-shell diff --git a/app/browser/lib/patchUserDataDir.js b/app/browser/lib/patchUserDataDir.js deleted file mode 100644 index 310ff3cb572..00000000000 --- a/app/browser/lib/patchUserDataDir.js +++ /dev/null @@ -1,15 +0,0 @@ -/* 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 path = require('path') -const {app} = require('electron') - -if (!process.env.BRAVE_USER_DATA_DIR && ['development', 'test'].includes(process.env.NODE_ENV)) { - process.env.BRAVE_USER_DATA_DIR = path.join(app.getPath('appData'), app.getName() + '-' + process.env.NODE_ENV) -} - -if (process.env.BRAVE_USER_DATA_DIR) { - app.setPath('userData', process.env.BRAVE_USER_DATA_DIR) -} - diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 065cf1abcc6..da4a99effb7 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -25,6 +25,12 @@ const tabs = { activeTab = tab } }) + tab.on('new-window', (e, url, frameName, disposition, options = {}) => { + let userGesture = options.userGesture + if (userGesture === false) { + e.preventDefault() + } + }) currentWebContents[tabId] = tab }) }, diff --git a/app/common/commonMenu.js b/app/common/commonMenu.js index f1886e2dcce..25ffdac99ef 100644 --- a/app/common/commonMenu.js +++ b/app/common/commonMenu.js @@ -12,13 +12,7 @@ const settings = require('../../js/constants/settings') const getSetting = require('../../js/settings').getSetting const communityURL = 'https://community.brave.com/' const isDarwin = process.platform === 'darwin' - -let electron -try { - electron = require('electron') -} catch (e) { - electron = global.require('electron') -} +const electron = require('electron') let app let BrowserWindow diff --git a/app/extensions.js b/app/extensions.js index 5b5dd8f4fbf..140fe4d7853 100644 --- a/app/extensions.js +++ b/app/extensions.js @@ -128,7 +128,9 @@ let generateBraveManifest = () => { web_accessible_resources: [ 'img/favicon.ico', 'about-flash.html', - 'about-blank.html' + 'about-blank.html', + 'about-newtab.html', + 'about-preferences.html' ], incognito: 'spanning', key: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAupOLMy5Fd4dCSOtjcApsAQOnuBdTs+OvBVt/3P93noIrf068x0xXkvxbn+fpigcqfNamiJ5CjGyfx9zAIs7zcHwbxjOw0Uih4SllfgtK+svNTeE0r5atMWE0xR489BvsqNuPSxYJUmW28JqhaSZ4SabYrRx114KcU6ko7hkjyPkjQa3P+chStJjIKYgu5tWBiMJp5QVLelKoM+xkY6S7efvJ8AfajxCViLGyDQPDviGr2D0VvIBob0D1ZmAoTvYOWafcNCaqaejPDybFtuLFX3pZBqfyOCyyzGhucyCmfBXJALKbhjRAqN5glNsUmGhhPK87TuGATQfVuZtenMvXMQIDAQAB' diff --git a/app/extensions/brave/content/scripts/adInsertion.js b/app/extensions/brave/content/scripts/adInsertion.js index 57e2c3760a3..5430444eed8 100644 --- a/app/extensions/brave/content/scripts/adInsertion.js +++ b/app/extensions/brave/content/scripts/adInsertion.js @@ -158,12 +158,12 @@ if (chrome.contentSettings.adInsertion == 'allow') { var host = document.location.hostname if (host) { host = host.replace('www.', '') - chrome.ipc.on('set-ad-div-candidates', (e, divHost, adDivCandidates, placeholderUrl) => { + chrome.ipcRenderer.on('set-ad-div-candidates', (e, divHost, adDivCandidates, placeholderUrl) => { // don't accidentally intercept messages not intended for this host if (host === divHost) { setAdDivCandidates(adDivCandidates, placeholderUrl) } }) - chrome.ipc.send('get-ad-div-candidates', host) + chrome.ipcRenderer.send('get-ad-div-candidates', host) } } diff --git a/app/extensions/brave/content/scripts/blockCanvasFingerprinting.js b/app/extensions/brave/content/scripts/blockCanvasFingerprinting.js index 94340263e2b..f59c4efb477 100644 --- a/app/extensions/brave/content/scripts/blockCanvasFingerprinting.js +++ b/app/extensions/brave/content/scripts/blockCanvasFingerprinting.js @@ -77,7 +77,7 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') { } // Block the read from occuring; send info to background page instead - chrome.ipc.sendToHost('got-canvas-fingerprinting', msg) + chrome.ipcRenderer.sendToHost('got-canvas-fingerprinting', msg) } /** diff --git a/app/extensions/brave/content/scripts/flashListener.js b/app/extensions/brave/content/scripts/flashListener.js index e0acdfc7ce2..bd6c4f0a4b9 100644 --- a/app/extensions/brave/content/scripts/flashListener.js +++ b/app/extensions/brave/content/scripts/flashListener.js @@ -13,7 +13,7 @@ function isAdobeLink (href) { } function showFlashNotification (origin, e) { - chrome.ipc.sendToHost('show-flash-notification', origin) + chrome.ipcRenderer.sendToHost('show-flash-notification', origin) e.preventDefault() e.stopPropagation() } diff --git a/app/extensions/brave/content/scripts/idleHandler.js b/app/extensions/brave/content/scripts/idleHandler.js index 20e08949cbe..4871fa2997f 100644 --- a/app/extensions/brave/content/scripts/idleHandler.js +++ b/app/extensions/brave/content/scripts/idleHandler.js @@ -1,7 +1,7 @@ -chrome.idle.setDetectionInterval(15*60) -chrome.idle.onStateChanged.addListener((idleState) => { - chrome.ipc.send('dispatch-action', JSON.stringify({ - actionType: 'app-idle-state-changed', - idleState - })) -}) +// chrome.idle.setDetectionInterval(15*60) +// chrome.idle.onStateChanged.addListener((idleState) => { +// chrome.ipcRenderer.send('dispatch-action', JSON.stringify({ +// actionType: 'app-idle-state-changed', +// idleState +// })) +// }) diff --git a/app/extensions/brave/content/scripts/inputHandler.js b/app/extensions/brave/content/scripts/inputHandler.js index 461a6def264..86a9ed03497 100644 --- a/app/extensions/brave/content/scripts/inputHandler.js +++ b/app/extensions/brave/content/scripts/inputHandler.js @@ -136,17 +136,17 @@ document.addEventListener('keydown', (e /*: Event*/) => { case KeyEvent.DOM_VK_ESCAPE: if (document.readyState !== 'complete') { e.preventDefault() - chrome.ipc.sendToHost('stop-load') + chrome.ipcRenderer.sendToHost('stop-load') } break case KeyEvent.DOM_VK_LEFT: if (e.metaKey && !isEditable(document.activeElement) && isPlatformOSX()) { - chrome.ipc.sendToHost('go-back') + chrome.ipcRenderer.sendToHost('go-back') } break case KeyEvent.DOM_VK_RIGHT: if (e.metaKey && !isEditable(document.activeElement) && isPlatformOSX()) { - chrome.ipc.sendToHost('go-forward') + chrome.ipcRenderer.sendToHost('go-forward') } break } diff --git a/app/extensions/brave/content/scripts/pageInformation.js b/app/extensions/brave/content/scripts/pageInformation.js index a9bb1f49671..e04e307c1b1 100644 --- a/app/extensions/brave/content/scripts/pageInformation.js +++ b/app/extensions/brave/content/scripts/pageInformation.js @@ -5,7 +5,7 @@ /* jshint asi: true */ /* jshint esversion: 6 */ -(function () { try { +(function () { try { var resolve = (tree, context) => { var node = tree.body ? tree.body[0] : tree @@ -135,7 +135,7 @@ if (!node) node = document.head.querySelector("link[rel='shortcut icon']") if (node) results.faviconURL = node.getAttribute('href') - var pubinfo = chrome.ipc.sendSync('ledger-publisher', document.location.href) + var pubinfo = chrome.ipcRenderer.sendSync('ledger-publisher', document.location.href) if ((!pubinfo) || (!pubinfo.context) || (!pubinfo.rules)) return console.log('no pubinfo available') var context = pubinfo.context @@ -171,7 +171,7 @@ results.faviconURL = resolve(rule.faviconURL.consequent, context) } break - } + } if (results.faviconURL) { var prefix = (results.faviconURL.indexOf('//') === 0) ? document.location.protocol @@ -182,7 +182,7 @@ } results.url = window.location.href - chrome.ipc.send('dispatch-action', JSON.stringify({ + chrome.ipcRenderer.send('dispatch-action', JSON.stringify({ location: window.location.href, actionType: 'event-set-page-info', pageInfo: results diff --git a/app/extensions/brave/content/scripts/passwordManager.js b/app/extensions/brave/content/scripts/passwordManager.js index b4c79d76028..399b5511dcc 100644 --- a/app/extensions/brave/content/scripts/passwordManager.js +++ b/app/extensions/brave/content/scripts/passwordManager.js @@ -5,7 +5,7 @@ if (chrome.contentSettings.passwordManager == 'allow') { let credentials = {} function savePassword (username/*: ?string*/, pw/*: string*/, origin/*: string*/, action/*: string*/) { - chrome.ipc.send('save-password', username, pw, origin, action) + chrome.ipcRenderer.send('save-password', username, pw, origin, action) } let submittedForms = [] @@ -62,7 +62,7 @@ if (chrome.contentSettings.passwordManager == 'allow') { // Fill the password immediately if there's only one or if the username // is already autofilled - chrome.ipc.send('get-passwords', formOrigin, action) + chrome.ipcRenderer.send('get-passwords', formOrigin, action) if (usernameElem) { usernameElem.addEventListener('keyup', (e) => { @@ -73,11 +73,11 @@ if (chrome.contentSettings.passwordManager == 'allow') { case KeyEvent.DOM_VK_ESCAPE: e.preventDefault() e.stopPropagation() - chrome.ipc.send('hide-context-menu') + chrome.ipcRenderer.send('hide-context-menu') break default: let rect = usernameElem.getBoundingClientRect() - chrome.ipc.send('show-username-list', formOrigin, action, { + chrome.ipcRenderer.send('show-username-list', formOrigin, action, { bottom: rect.bottom, left: rect.left, width: rect.width @@ -91,7 +91,7 @@ if (chrome.contentSettings.passwordManager == 'allow') { form.addEventListener('submit', (e) => { if (usernameElem) { usernameElem.blur() - chrome.ipc.send('hide-context-menu') + chrome.ipcRenderer.send('hide-context-menu') } onFormSubmit(form, formOrigin) }) @@ -137,7 +137,7 @@ if (chrome.contentSettings.passwordManager == 'allow') { tryAutofillForm(formOrigin, form) }) - chrome.ipc.on('got-password', (e, username, password, origin, action, isUnique) => { + chrome.ipcRenderer.on('got-password', (e, username, password, origin, action, isUnique) => { var elems = credentials[action] if (formOrigin === origin && elems) { elems.forEach((elem) => { diff --git a/app/extensions/brave/content/scripts/spellCheck.js b/app/extensions/brave/content/scripts/spellCheck.js index 1da52280382..1f9af2edb76 100644 --- a/app/extensions/brave/content/scripts/spellCheck.js +++ b/app/extensions/brave/content/scripts/spellCheck.js @@ -4,5 +4,5 @@ let lang = navigator.language.split('-')[0].split('_')[0] chrome.webFrame.setSpellCheckProvider(lang || '', true, { - spellCheck: (word) => !chrome.ipc.sendSync('is-misspelled', word) + spellCheck: (word) => !chrome.ipcRenderer.sendSync('is-misspelled', word) }) diff --git a/app/extensions/brave/content/scripts/themeColor.js b/app/extensions/brave/content/scripts/themeColor.js index 2d8c5868b20..345b77b1bbe 100644 --- a/app/extensions/brave/content/scripts/themeColor.js +++ b/app/extensions/brave/content/scripts/themeColor.js @@ -3,7 +3,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ (function () { - var ipcRenderer = chrome.ipc; + var ipcRenderer = chrome.ipcRenderer; const rgbaFromStr = function (rgba) { if (!rgba) { @@ -57,6 +57,6 @@ } if(window.top == window.self) { - chrome.ipc.sendToHost('theme-color-computed', computeThemeColor()) + chrome.ipcRenderer.sendToHost('theme-color-computed', computeThemeColor()) } })() diff --git a/app/extensions/brave/index-dev.html b/app/extensions/brave/index-dev.html index 830a89315bc..1cd14395c81 100644 --- a/app/extensions/brave/index-dev.html +++ b/app/extensions/brave/index-dev.html @@ -7,7 +7,7 @@ - + Brave diff --git a/app/extensions/brave/index-load-script.js b/app/extensions/brave/index-load-script.js index 4b0f1639f1d..3ea41c5b38c 100644 --- a/app/extensions/brave/index-load-script.js +++ b/app/extensions/brave/index-load-script.js @@ -1,4 +1,4 @@ -var baseHref = 'http://localhost:' + process.env.npm_package_config_port +var baseHref = 'http://localhost:8080' // + process.env.npm_package_config_port var appEntry = baseHref + '/gen/app.entry.js' var baseNode = document.createElement('base') diff --git a/app/filtering.js b/app/filtering.js index 3665709e0c5..b1b5df43557 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -549,17 +549,20 @@ function initForPartition (partition) { fns.forEach((fn) => { fn(ses, partition) }) } +const filterableProtocols = ['http:', 'https:'] + function shouldIgnoreUrl (url) { // Ensure host is well-formed (RFC 1035) and has a non-empty hostname try { - let host = urlParse(url).hostname - if (host.includes('..') || host.length > 255 || host.length === 0) { - return true + // TODO(bridiver) - handle RFS check and cancel http/https requests with 0 or > 255 length hostames + const parsedUrl = urlParse(url) + if (filterableProtocols.includes(parsedUrl.protocol)) { + return false } } catch (e) { - return true + console.warn('Error parsing ' + url) } - return false + return true } module.exports.init = () => { diff --git a/app/index.js b/app/index.js index 38c7e6adaad..784a62f4794 100644 --- a/app/index.js +++ b/app/index.js @@ -8,7 +8,7 @@ let ready = false // Setup the crash handling -const CrashHerald = require('./crash-herald') +// const CrashHerald = require('./crash-herald') const handleUncaughtError = (error) => { var message, ref, stack @@ -42,14 +42,12 @@ if (process.platform === 'win32') { const electron = require('electron') const app = electron.app -// set userData before loading anything else -require('./browser/lib/patchUserDataDir') const BrowserWindow = electron.BrowserWindow const dialog = electron.dialog const ipcMain = electron.ipcMain const Immutable = require('immutable') const Menu = require('./browser/menu') -const Updater = require('./updater') +// const Updater = require('./updater') const Importer = require('./importer') const messages = require('../js/constants/messages') const appConfig = require('../js/constants/appConfig') @@ -212,7 +210,7 @@ const saveAppState = (appState, cb) => { // Otherwise just quit. if (appState.updates && (appState.updates.status === UpdateStatus.UPDATE_APPLYING_NO_RESTART || appState.updates.status === UpdateStatus.UPDATE_APPLYING_RESTART)) { - Updater.quitAndInstall() + // Updater.quitAndInstall() } else { app.quit() } @@ -254,7 +252,7 @@ loadAppStatePromise.then((initialState) => { } if (initialState.settings[SEND_CRASH_REPORTS] !== false) { console.log('Crash reporting enabled') - CrashHerald.init() + // CrashHerald.init() } else { console.log('Crash reporting disabled') } @@ -435,7 +433,7 @@ app.on('ready', () => { webtorrent.init() if (!loadedPerWindowState || loadedPerWindowState.length === 0) { - if (!CmdLine.newWindowURL()) { + if (!CmdLine.newWindowURL) { appActions.newWindow() } } else { @@ -458,9 +456,9 @@ app.on('ready', () => { appActions.changeSetting(settings.IS_DEFAULT_BROWSER, isDefaultBrowser) } - if (CmdLine.newWindowURL()) { + if (CmdLine.newWindowURL) { appActions.newWindow(Immutable.fromJS({ - location: CmdLine.newWindowURL() + location: CmdLine.newWindowURL })) } @@ -750,11 +748,11 @@ app.on('ready', () => { // Setup the auto updater, check the env variable first because it's // used to check the update channel before releases. - Updater.init(process.platform, process.arch, process.env.BRAVE_UPDATE_VERSION || pack.version) + // Updater.init(process.platform, process.arch, process.env.BRAVE_UPDATE_VERSION || pack.version) // This is fired by a menu entry (for now - will be scheduled) - process.on(messages.CHECK_FOR_UPDATE, () => Updater.checkForUpdate(true)) - ipcMain.on(messages.CHECK_FOR_UPDATE, () => Updater.checkForUpdate(true)) + // process.on(messages.CHECK_FOR_UPDATE, () => Updater.checkForUpdate(true)) + // ipcMain.on(messages.CHECK_FOR_UPDATE, () => Updater.checkForUpdate(true)) // This is fired from a auto-update metadata call process.on(messages.UPDATE_META_DATA_RETRIEVED, (metadata) => { diff --git a/app/renderer/components/browserActionButton.js b/app/renderer/components/browserActionButton.js index 2472773f2cc..911285b3568 100644 --- a/app/renderer/components/browserActionButton.js +++ b/app/renderer/components/browserActionButton.js @@ -4,7 +4,7 @@ const React = require('react') const ImmutableComponent = require('../../../js/components/immutableComponent') -const electron = global.require('electron') +const electron = require('electron') const ipc = electron.ipcRenderer const Button = require('../../../js/components/button') const cx = require('../../../js/lib/classSet') diff --git a/js/about/aboutActions.js b/js/about/aboutActions.js index 3dda621c60c..4a5e6bab9cf 100644 --- a/js/about/aboutActions.js +++ b/js/about/aboutActions.js @@ -6,7 +6,7 @@ const messages = require('../constants/messages') const serializer = require('../dispatcher/serializer') const windowConstants = require('../constants/windowConstants') const appConstants = require('../constants/appConstants') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer const aboutActions = { /** diff --git a/js/about/adblock.js b/js/about/adblock.js index 5e9e9ba9498..5217138528d 100644 --- a/js/about/adblock.js +++ b/js/about/adblock.js @@ -12,7 +12,7 @@ const aboutActions = require('./aboutActions') const ImmutableComponent = require('../components/immutableComponent') const SwitchControl = require('../components/switchControl') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer // Stylesheets require('../../less/switchControls.less') diff --git a/js/about/autofill.js b/js/about/autofill.js index d76192f67b1..78dc2287fd9 100644 --- a/js/about/autofill.js +++ b/js/about/autofill.js @@ -9,7 +9,7 @@ const ImmutableComponent = require('../components/immutableComponent') const aboutActions = require('./aboutActions') const Button = require('../components/button') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer require('../../less/about/autofill.less') require('../../node_modules/font-awesome/css/font-awesome.css') diff --git a/js/about/bookmarks.js b/js/about/bookmarks.js index 1eb0e943a7c..39eb0df97da 100644 --- a/js/about/bookmarks.js +++ b/js/about/bookmarks.js @@ -17,7 +17,7 @@ const siteUtil = require('../state/siteUtil') const formatUtil = require('../../app/common/lib/formatUtil') const iconSize = require('../../app/common/lib/faviconUtil').iconSize -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer // Stylesheets require('../../less/about/bookmarks.less') diff --git a/js/about/certerror.js b/js/about/certerror.js index 638ea24e876..ba7573a5f79 100644 --- a/js/about/certerror.js +++ b/js/about/certerror.js @@ -7,7 +7,7 @@ const Button = require('../components/button') const aboutActions = require('./aboutActions') const WindowConstants = require('../constants/windowConstants') const messages = require('../constants/messages') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer require('../../less/button.less') require('../../less/window.less') diff --git a/js/about/downloads.js b/js/about/downloads.js index 4b1cbf5fef4..5d4b1a3577f 100644 --- a/js/about/downloads.js +++ b/js/about/downloads.js @@ -10,7 +10,7 @@ const messages = require('../constants/messages') const aboutActions = require('./aboutActions') const downloadUtil = require('../state/downloadUtil') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer // Stylesheets require('../../less/about/itemList.less') diff --git a/js/about/entry.js b/js/about/entry.js index 9c2b4afdfee..6ba511c1073 100644 --- a/js/about/entry.js +++ b/js/about/entry.js @@ -32,7 +32,7 @@ if (getFavicon()) { const ReactDOM = require('react-dom') const {getSourceAboutUrl, getBaseUrl} = require('../lib/appUrlUtil') const {ABOUT_COMPONENT_INITIALIZED} = require('../constants/messages') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer let element diff --git a/js/about/extensions.js b/js/about/extensions.js index 97cd964a7a4..f07ad20927a 100644 --- a/js/about/extensions.js +++ b/js/about/extensions.js @@ -9,7 +9,7 @@ const ImmutableComponent = require('../components/immutableComponent') const messages = require('../constants/messages') const aboutActions = require('./aboutActions') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer // Stylesheets require('../../less/about/itemList.less') diff --git a/js/about/flashPlaceholder.js b/js/about/flashPlaceholder.js index 0fd207c5a91..b262862ce32 100644 --- a/js/about/flashPlaceholder.js +++ b/js/about/flashPlaceholder.js @@ -7,7 +7,7 @@ const ImmutableComponent = require('../components/immutableComponent') const messages = require('../constants/messages') const aboutActions = require('./aboutActions') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer require('../../less/about/flash.less') diff --git a/js/about/history.js b/js/about/history.js index d6af81d9586..538b4c049f5 100644 --- a/js/about/history.js +++ b/js/about/history.js @@ -16,7 +16,7 @@ const Button = require('../components/button') const {makeImmutable} = require('../../app/common/state/immutableUtil') const historyUtil = require('../../app/common/lib/historyUtil') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer // Stylesheets require('../../less/about/history.less') diff --git a/js/about/passwords.js b/js/about/passwords.js index 99349905463..8d740ec2145 100644 --- a/js/about/passwords.js +++ b/js/about/passwords.js @@ -7,7 +7,7 @@ const messages = require('../constants/messages') const Immutable = require('immutable') const aboutActions = require('./aboutActions') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer require('../../less/about/passwords.less') require('../../node_modules/font-awesome/css/font-awesome.css') diff --git a/js/about/preferences.js b/js/about/preferences.js index 7db8c173044..19be7a12cda 100644 --- a/js/about/preferences.js +++ b/js/about/preferences.js @@ -50,7 +50,7 @@ const widevine = appConfig.resourceNames.WIDEVINE const isDarwin = navigator.platform === 'MacIntel' const isWindows = navigator.platform && navigator.platform.includes('Win') -const ipc = window.chrome.ipc +const ipc = window.chrome.ipcRenderer // TODO: Determine this from the l20n file automatically const hintCount = 3 diff --git a/js/actions/downloadActions.js b/js/actions/downloadActions.js index 308c3165e15..d22a8bb4bef 100644 --- a/js/actions/downloadActions.js +++ b/js/actions/downloadActions.js @@ -4,12 +4,7 @@ 'use strict' -let electron -try { - electron = require('electron') -} catch (e) { - electron = global.require('electron') -} +const electron = require('electron') let shell, ipc, clipboard, getCurrentWebContents if (process.type === 'browser') { @@ -27,8 +22,8 @@ if (process.type === 'browser') { const appDownloadActions = require('../constants/downloadActions') const appActions = require('../actions/appActions') const messages = require('../constants/messages') -const fs = require('fs') -const path = require('path') +// const fs = require('fs') +// const path = require('path') /** * Creates an action function for the specified app download action @@ -48,22 +43,22 @@ const downloadActions = { // void new window.Notification(locale.translation('urlCopied')) }, openDownloadPath: function (download) { - fs.exists(download.get('savePath'), (exists) => { - if (exists) { - shell.openItem(download.get('savePath')) - } else { - shell.beep() - } - }) + // fs.exists(download.get('savePath'), (exists) => { + // if (exists) { + // shell.openItem(download.get('savePath')) + // } else { + // shell.beep() + // } + // }) }, locateShellPath: function (download) { - fs.exists(download.get('savePath'), (exists) => { - if (exists) { - shell.showItemInFolder(download.get('savePath')) - } else { - shell.openItem(path.dirname(download.get('savePath'))) - } - }) + // fs.exists(download.get('savePath'), (exists) => { + // if (exists) { + // shell.showItemInFolder(download.get('savePath')) + // } else { + // shell.openItem(path.dirname(download.get('savePath'))) + // } + // }) }, hideDownloadsToolbar: function () { if (process.type === 'renderer') { diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index 06a810574ec..bef2f8b0ea8 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -314,7 +314,7 @@ const windowActions = { * @param {Object} frameProps - The properties of the frame to close */ closeFrame: function (frames, frameProps, forceClosePinned) { - const ipc = global.require('electron').ipcRenderer + const ipc = require('electron').ipcRenderer const origin = siteUtil.getOrigin(frameProps.get('location')) if (origin) { appActions.clearMessageBoxes(origin) diff --git a/js/components/clearBrowsingDataPanel.js b/js/components/clearBrowsingDataPanel.js index fc9f68b0808..1d91d113025 100644 --- a/js/components/clearBrowsingDataPanel.js +++ b/js/components/clearBrowsingDataPanel.js @@ -9,7 +9,7 @@ const Button = require('./button') const SwitchControl = require('./switchControl') const windowActions = require('../actions/windowActions') const appActions = require('../actions/appActions') -const ipc = global.require('electron').ipcRenderer +const ipc = require('electron').ipcRenderer const messages = require('../constants/messages') class ClearBrowsingDataPanel extends ImmutableComponent { diff --git a/js/components/frame.js b/js/components/frame.js index c3fb05fcddf..81d83f564b0 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -16,8 +16,8 @@ const UrlUtil = require('../lib/urlutil') const messages = require('../constants/messages') const contextMenus = require('../contextMenus') const {siteHacks} = require('../data/siteHacks') -const ipc = global.require('electron').ipcRenderer -const clipboard = global.require('electron').clipboard +const ipc = require('electron').ipcRenderer +const clipboard = require('electron').clipboard const FullScreenWarning = require('./fullScreenWarning') const debounce = require('../lib/debounce') const getSetting = require('../settings').getSetting @@ -28,7 +28,7 @@ const {isFrameError} = require('../../app/common/lib/httpUtil') const locale = require('../l10n') const appConfig = require('../constants/appConfig') const {getSiteSettingsForHostPattern} = require('../state/siteSettings') -const flash = require('../flash') +// const flash = require('../flash') const currentWindow = require('../../app/renderer/currentWindow') const windowStore = require('../stores/windowStore') const appStoreRenderer = require('../stores/appStoreRenderer') @@ -143,7 +143,7 @@ class Frame extends ImmutableComponent { newTabDetail: this.props.newTabDetail ? this.props.newTabDetail.toJS() : null }) } else if (location === 'about:autofill') { - const defaultSession = global.require('electron').remote.session.defaultSession + const defaultSession = require('electron').remote.session.defaultSession if (this.props.autofillAddresses) { const guids = this.props.autofillAddresses.get('guid') let list = [] @@ -300,17 +300,30 @@ class Frame extends ImmutableComponent { // the webview tag is where the user's page is rendered (runs in its own process) // @see http://electron.atom.io/docs/api/web-view-tag/ this.webview = document.createElement('webview') - + this.addEventListeners() + if (cb) { + this.runOnDomReady = cb + let eventCallback = (e) => { + this.webview.removeEventListener(e.type, eventCallback) + // handle deprectaed zoom level site settings + if (this.zoomLevel) { + this.webview.setZoomLevel(this.zoomLevel) + } + this.runOnDomReady() + delete this.runOnDomReady + } + this.webview.addEventListener('did-attach', eventCallback) + } let partition = FrameStateUtil.getPartition(this.frame) ipc.sendSync(messages.INITIALIZE_PARTITION, partition) this.webview.setAttribute('partition', partition) - if (guestInstanceId) { - this.webview.setAttribute('data-guest-instance-id', guestInstanceId) + if (!this.webview.setGuestInstanceId(guestInstanceId)) { + guestInstanceId = null + } } webviewAdded = true } - this.webview.setAttribute('allowDisplayingInsecureContent', true) this.webview.setAttribute('data-frame-key', this.props.frameKey) const parsedUrl = urlParse(location) @@ -335,20 +348,6 @@ class Frame extends ImmutableComponent { } if (webviewAdded) { - if (cb) { - this.runOnDomReady = cb - let eventCallback = (e) => { - this.webview.removeEventListener(e.type, eventCallback) - // handle deprectaed zoom level site settings - if (this.zoomLevel) { - this.webview.setZoomLevel(this.zoomLevel) - } - this.runOnDomReady() - delete this.runOnDomReady - } - this.webview.addEventListener('did-attach', eventCallback) - } - this.addEventListeners() this.webviewContainer.appendChild(this.webview) } else { cb && cb() @@ -640,26 +639,26 @@ class Frame extends ImmutableComponent { appActions.hideMessageBox(message) } } else { - flash.checkFlashInstalled((installed) => { - if (installed) { - let message = locale.translation('flashInstalled') - appActions.showMessageBox({ - buttons: [ - {text: locale.translation('goToPrefs')}, - {text: locale.translation('goToAdobe')} - ], - message: message, - options: {nonce} - }) - this.notificationCallbacks[message] = (buttonIndex) => { - appActions.hideMessageBox(message) - const location = buttonIndex === 0 ? 'about:preferences#security' : appConfig.flash.installUrl - windowActions.newFrame({ location }, true) - } - } else if (noFlashCallback) { - noFlashCallback() - } - }) + // flash.checkFlashInstalled((installed) => { + // if (installed) { + // let message = locale.translation('flashInstalled') + // appActions.showMessageBox({ + // buttons: [ + // {text: locale.translation('goToPrefs')}, + // {text: locale.translation('goToAdobe')} + // ], + // message: message, + // options: {nonce} + // }) + // this.notificationCallbacks[message] = (buttonIndex) => { + // appActions.hideMessageBox(message) + // const location = buttonIndex === 0 ? 'about:preferences#security' : appConfig.flash.installUrl + // windowActions.newFrame({ location }, true) + // } + // } else if (noFlashCallback) { + // noFlashCallback() + // } + // }) } ipc.once(messages.NOTIFICATION_RESPONSE + nonce, (e, msg, buttonIndex, persist) => { @@ -780,9 +779,7 @@ class Frame extends ImmutableComponent { }) // @see new-window event this.webview.addEventListener('new-window', (e) => { - e.preventDefault() - - let guestInstanceId = e.options && e.options.webPreferences && e.options.webPreferences.guestInstanceId + let guestInstanceId = e.options && e.options.guestInstanceId let windowOpts = e.options && e.options.windowOptions || {} windowOpts.parentWindowKey = currentWindow.id windowOpts.disposition = e.disposition @@ -1163,7 +1160,7 @@ class Frame extends ImmutableComponent { } }) // Handle zoom using Ctrl/Cmd and the mouse wheel. - this.webview.addEventListener('mousewheel', this.onMouseWheel.bind(this)) + // this.webview.addEventListener('mousewheel', this.onMouseWheel.bind(this)) } goBack () { diff --git a/js/components/main.js b/js/components/main.js index 65b97c5e637..bc3c81da036 100644 --- a/js/components/main.js +++ b/js/components/main.js @@ -5,9 +5,9 @@ const React = require('react') const ImmutableComponent = require('./immutableComponent') const Immutable = require('immutable') -const electron = global.require('electron') +const electron = require('electron') const ipc = electron.ipcRenderer -const systemPreferences = electron.remote.systemPreferences +// const systemPreferences = electron.remote.systemPreferences // Actions const appActions = require('../actions/appActions') @@ -206,7 +206,7 @@ class Main extends ImmutableComponent { registerSwipeListener () { // Navigates back/forward on macOS two-finger swipe var trackingFingers = false - var swipeGesture = false + // var swipeGesture = false var isSwipeOnEdge = false var deltaX = 0 var deltaY = 0 @@ -219,7 +219,7 @@ class Main extends ImmutableComponent { deltaY = deltaY + e.deltaY time = (new Date()).getTime() - startTime } - }) + }, { passive: true }) ipc.on(messages.DEBUG_REACT_PROFILE, (e, args) => { window.perf = require('react-addons-perf') if (!window.perf.isRunning()) { @@ -247,18 +247,18 @@ class Main extends ImmutableComponent { } }) ipc.on(messages.ENABLE_SWIPE_GESTURE, (e) => { - swipeGesture = true + // swipeGesture = true }) ipc.on(messages.DISABLE_SWIPE_GESTURE, (e) => { - swipeGesture = false + // swipeGesture = false }) ipc.on('scroll-touch-begin', function () { - if (swipeGesture && - systemPreferences.isSwipeTrackingFromScrollEventsEnabled()) { - trackingFingers = true - isSwipeOnEdge = false - startTime = (new Date()).getTime() - } + // if (swipeGesture && + // systemPreferences.isSwipeTrackingFromScrollEventsEnabled()) { + // trackingFingers = true + // isSwipeOnEdge = false + // startTime = (new Date()).getTime() + // } }) ipc.on('scroll-touch-end', function () { if (time > 50 && trackingFingers && Math.abs(deltaY) < 50 && isSwipeOnEdge) { @@ -499,7 +499,7 @@ class Main extends ImmutableComponent { }, true) const activeFrame = FrameStateUtil.getActiveFrame(self.props.windowState) - if (activeFrame) { + if (activeFrame && activeFrame.get('title')) { currentWindow.setTitle(activeFrame.get('title')) } diff --git a/js/components/navigationBar.js b/js/components/navigationBar.js index 67546336ae1..c0ee31b1cbb 100644 --- a/js/components/navigationBar.js +++ b/js/components/navigationBar.js @@ -13,7 +13,7 @@ const windowActions = require('../actions/windowActions') const siteTags = require('../constants/siteTags') const messages = require('../constants/messages') const settings = require('../constants/settings') -const ipc = global.require('electron').ipcRenderer +const ipc = require('electron').ipcRenderer const {isSourceAboutUrl} = require('../lib/appUrlUtil') const AddEditBookmarkHanger = require('../../app/renderer/components/addEditBookmarkHanger') const siteUtil = require('../state/siteUtil') diff --git a/js/components/updateBar.js b/js/components/updateBar.js index 7896b1388d5..fa24170daa7 100644 --- a/js/components/updateBar.js +++ b/js/components/updateBar.js @@ -9,7 +9,7 @@ const Button = require('./button') const appActions = require('../actions/appActions') const windowActions = require('../actions/windowActions') const UpdateStatus = require('../constants/updateStatus') -const remote = global.require('electron').remote +const remote = require('electron').remote const path = require('path') const cx = require('../lib/classSet') diff --git a/js/components/urlBar.js b/js/components/urlBar.js index c102dbbecb2..f309be1e656 100644 --- a/js/components/urlBar.js +++ b/js/components/urlBar.js @@ -11,7 +11,7 @@ const appActions = require('../actions/appActions') const KeyCodes = require('../../app/common/constants/keyCodes') const cx = require('../lib/classSet') const debounce = require('../lib/debounce') -const ipc = global.require('electron').ipcRenderer +const ipc = require('electron').ipcRenderer const UrlBarSuggestions = require('./urlBarSuggestions') const UrlBarIcon = require('../../app/renderer/components/urlBarIcon') diff --git a/js/contextMenus.js b/js/contextMenus.js index 4251cbbfbee..50f517c21a7 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -2,7 +2,7 @@ * 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 = global.require('electron') +const electron = require('electron') const remote = electron.remote const Menu = remote.Menu const Immutable = require('immutable') @@ -24,7 +24,7 @@ const CommonMenu = require('../app/common/commonMenu') const dnd = require('./dnd') const dndData = require('./dndData') const appStoreRenderer = require('./stores/appStoreRenderer') -const ipc = global.require('electron').ipcRenderer +const ipc = require('electron').ipcRenderer const locale = require('../js/l10n') const {getSetting} = require('./settings') const settings = require('./constants/settings') diff --git a/js/dispatcher/appDispatcher.js b/js/dispatcher/appDispatcher.js index c11dfc63692..bc6c5238b2c 100644 --- a/js/dispatcher/appDispatcher.js +++ b/js/dispatcher/appDispatcher.js @@ -4,7 +4,7 @@ const Serializer = require('./serializer') const messages = require('../constants/messages') -const electron = process.type === 'renderer' ? global.require('electron') : require('electron') +const electron = require('electron') 'use strict' class AppDispatcher { diff --git a/js/entry.js b/js/entry.js index ff741d545c1..91472ae3f29 100644 --- a/js/entry.js +++ b/js/entry.js @@ -22,27 +22,27 @@ require('../less/addEditBookmark.less') require('../node_modules/font-awesome/css/font-awesome.css') // Enable or disable crash reporting based on platform -const setupCrashReporting = () => { - if (process.platform === 'darwin') { - // Setup the crash handling for mac renderer processes - // https://github.com/electron/electron/blob/master/docs/api/crash-reporter.md#crashreporterstartoptions - console.log('macOS renderer crash reporting initialized') - require('../app/crash-herald').init() - } -} +// const setupCrashReporting = () => { +// // if (process.platform === 'darwin') { +// // // Setup the crash handling for mac renderer processes +// // // https://github.com/electron/electron/blob/master/docs/api/crash-reporter.md#crashreporterstartoptions +// // console.log('macOS renderer crash reporting initialized') +// // require('../app/crash-herald').init() +// // } +// } -// Notify that renderer crash reporting is disabled -const disableCrashReporting = () => { - console.log('Disabling renderer crash reporting') -} +// // Notify that renderer crash reporting is disabled +// const disableCrashReporting = () => { +// console.log('Disabling renderer crash reporting') +// } const React = require('react') const ReactDOM = require('react-dom') const Window = require('./components/window') -const electron = global.require('electron') -const currentWindow = require('../app/renderer/currentWindow') +const electron = require('electron') +// const currentWindow = require('../app/renderer/currentWindow') const ipc = electron.ipcRenderer -const webFrame = electron.webFrame +// // const webFrame = electron.webFrame const windowStore = require('./stores/windowStore') const appStoreRenderer = require('./stores/appStoreRenderer') const windowActions = require('./actions/windowActions') @@ -51,11 +51,11 @@ const Immutable = require('immutable') const patch = require('immutablepatch') const l10n = require('./l10n') -// don't allow scaling or zooming of the ui -webFrame.setPageScaleLimits(1, 1) -webFrame.setZoomLevelLimits(0, 0) -// override any default zoom level changes -currentWindow.webContents.setZoomLevel(0.0) +// // // don't allow scaling or zooming of the ui +// // webFrame.setPageScaleLimits(1, 1) +// // webFrame.setZoomLevelLimits(0, 0) +// // // override any default zoom level changes +// // currentWindow.webContents.setZoomLevel(0.0) l10n.init() @@ -63,11 +63,11 @@ ipc.on(messages.REQUEST_WINDOW_STATE, () => { ipc.send(messages.RESPONSE_WINDOW_STATE, windowStore.getState().toJS()) }) -if (process.env.NODE_ENV === 'test') { - window.appStoreRenderer = appStoreRenderer - window.windowActions = windowActions - window.windowStore = windowStore -} +// // if (process.env.NODE_ENV === 'test') { +// // window.appStoreRenderer = appStoreRenderer +// // window.windowActions = windowActions +// // window.windowStore = windowStore +// // } ipc.on(messages.APP_STATE_CHANGE, (e, action) => { appStoreRenderer.state = action.stateDiff @@ -83,15 +83,15 @@ window.addEventListener('beforeunload', function () { ipc.send(messages.LAST_WINDOW_STATE, windowStore.getState().toJS()) }) -// get appStore from url ipc.on(messages.INITIALIZE_WINDOW, (e, disposition, appState, frames, initWindowState) => { // Configure renderer crash reporting - if (appState.settings[require('./constants/settings').SEND_CRASH_REPORTS] !== false) { - setupCrashReporting() - } else { - disableCrashReporting() - } + // if (appState.settings[require('./constants/settings').SEND_CRASH_REPORTS] !== false) { + // setupCrashReporting() + // } else { + // disableCrashReporting() + // } appStoreRenderer.state = Immutable.fromJS(appState) + // ReactDOM.render(
test
, document.getElementById('windowContainer')) ReactDOM.render( , document.getElementById('windowContainer')) diff --git a/js/flash.js b/js/flash.js index eb0d1352bb4..04c5d13b912 100644 --- a/js/flash.js +++ b/js/flash.js @@ -5,13 +5,8 @@ const fs = require('fs') const path = require('path') -let electron +const electron = require('electron') let app -try { - electron = require('electron') -} catch (e) { - electron = global.require('electron') -} if (process.type === 'browser') { app = electron.app } else { diff --git a/js/lib/appUrlUtil.js b/js/lib/appUrlUtil.js index 05a14d6b9ec..eb5a2a32d20 100644 --- a/js/lib/appUrlUtil.js +++ b/js/lib/appUrlUtil.js @@ -71,8 +71,8 @@ module.exports.getBraveIndexPath = function (relateivePath = '') { module.exports.getBraveExtIndexHTML = function () { return process.env.NODE_ENV === 'development' - ? module.exports.getBraveIndexPath('index-dev.html') - : module.exports.getBraveIndexPath('index.html') + ? module.exports.getBraveIndexPath('index-dev.html').replace('file://', 'chrome://brave') + : module.exports.getBraveIndexPath('index.html').replace('file://', 'chrome://brave') } /** diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 0fd2cf0f98a..05726fc1dc0 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -233,8 +233,6 @@ const createWindow = (browserOpts, defaults, frameOpts, windowState) => { }) LocalShortcuts.register(mainWindow) - - mainWindow.loadURL(appUrlUtil.getBraveExtIndexHTML()) return mainWindow } @@ -287,6 +285,7 @@ function windowDefaults () { windowOffset: 20, webPreferences: { sharedWorker: true, + nodeIntegration: false, partition: 'default', allowFileAccessFromFileUrls: true, allowUniversalAccessFromFileUrls: true diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index 2064bf08236..4e214b50449 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -9,7 +9,7 @@ const config = require('../constants/config') const settings = require('../constants/settings') const Immutable = require('immutable') const FrameStateUtil = require('../state/frameStateUtil') -const ipc = global.require('electron').ipcRenderer +const ipc = require('electron').ipcRenderer const messages = require('../constants/messages') const debounce = require('../lib/debounce') const getSetting = require('../settings').getSetting diff --git a/package.json b/package.json index 22cf0862343..38b7fb3c3f2 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "lint": "standard", "postinstall": "webpack", "preload-httpse": "node ./preload-httpse.js", - "start": "node ./tools/start.js --debug=5858 --enable-logging --v=0 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck", + "start": "node ./tools/start.js --user-data-dir=brave-development --debug=5858 --enable-logging --v=0 --enable-extension-activity-logging --enable-sandbox-logging --enable-dcheck", "start-brk": "node ./tools/start.js --debug-brk=5858 -enable-logging --v=0 --enable-dcheck", "test": "NODE_ENV=test mocha --require babel-register --require babel-polyfill 'test/**/*Test.js'", "unittest": "NODE_ENV=test mocha --require babel-register --require babel-polyfill 'test/unit/**/*Test.js'", @@ -137,7 +137,6 @@ "css-loader": "^0.23.0", "electron-builder": "^2.3.1", "electron-packager": "brave/electron-packager", - "electron-rebuild": "^1.1.1", "electron-winstaller": "2.5.1", "empty-port": "0.0.2", "flow-bin": "^0.22.1", diff --git a/webpack.config.js b/webpack.config.js index b3f9099a2f8..f7ec3da168e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -50,6 +50,9 @@ function config () { resolve: { extensions: ['', '.js', '.jsx'] }, + externals: { + 'electron': 'chrome' + }, plugins: [ new WebpackNotifierPlugin({title: 'Brave-' + env}), new webpack.IgnorePlugin(/^\.\/stores\/appStore$/), @@ -64,6 +67,7 @@ function config () { }) ], node: { + process: false, __filename: true, __dirname: true, fs: 'empty' @@ -74,7 +78,8 @@ function config () { function development () { var dev = config() dev.devServer = { - publicPath: 'http://localhost:' + port + '/gen/' + publicPath: 'http://localhost:' + port + '/gen/', + headers: { 'Access-Control-Allow-Origin': '*' } } return dev } @@ -102,7 +107,7 @@ function merge (config, env) { var app = { name: 'app', - target: 'electron', + target: 'web', entry: ['./js/entry.js'], output: { path: path.resolve(__dirname, 'app', 'extensions', 'brave', 'gen'),