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

Commit

Permalink
Merge pull request #13783 from brave/single-webview
Browse files Browse the repository at this point in the history
Do not create a new <webview> element or <Frame /> component for each Tab (single-webview)
  • Loading branch information
petemill authored May 11, 2018
2 parents e387dcf + 7288f52 commit 73886ff
Show file tree
Hide file tree
Showing 51 changed files with 2,434 additions and 1,626 deletions.
6 changes: 3 additions & 3 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
runtime = electron
target_arch = x64
brave_electron_version = 5.1.2
chromedriver_version = 2.35
target = v5.1.2
brave_electron_version = 6.0.9
chromedriver_version = 2.36
target = v6.0.9
disturl=https://brave-laptop-binaries.s3.amazonaws.com/atom-shell/dist/
build_from_source = true
10 changes: 10 additions & 0 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ const createDebugSubmenu = (state) => {
click: function (menuItem, browserWindow, e) {
appActions.changeSetting(settings.DEBUG_ALLOW_MANUAL_TAB_DISCARD, menuItem.checked)
}
}, {
label: 'Display tab identifiers',
type: 'checkbox',
checked: !!getSetting(settings.DEBUG_VERBOSE_TAB_INFO),
click: function (menuItem, browserWindow, e) {
appActions.changeSetting(settings.DEBUG_VERBOSE_TAB_INFO, menuItem.checked)
}
}
]
}
Expand Down Expand Up @@ -655,6 +662,9 @@ const doAction = (state, action) => {
if (action.key === settings.DEBUG_ALLOW_MANUAL_TAB_DISCARD) {
setMenuItemAttribute(state, 'Allow manual tab discarding', 'checked', action.value)
}
if (action.key === settings.DEBUG_VERBOSE_TAB_INFO) {
setMenuItemAttribute(state, 'Display tab identifiers', 'checked', action.value)
}
break
case windowConstants.WINDOW_UNDO_CLOSED_FRAME:
{
Expand Down
128 changes: 111 additions & 17 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,51 @@ const getWebRTCPolicy = (state, tabId) => {
}
}

function expireContentSettings (state, tabId, origin) {
// Expired Flash settings should be deleted when the webview is
// navigated or closed. Same for NoScript's allow-once option.
const tabValue = tabState.getByTabId(state, tabId)
const isPrivate = tabValue.get('incognito') === true
const allSiteSettings = siteSettingsState.getAllSiteSettings(state, isPrivate)
const tabSiteSettings =
siteSettings.getSiteSettingsForURL(allSiteSettings, tabValue.get('url'))
if (!tabSiteSettings) {
return
}
const originFlashEnabled = tabSiteSettings.get('flash')
const originWidevineEnabled = tabSiteSettings.get('widevine')
const originNoScriptEnabled = tabSiteSettings.get('noScript')
const originNoScriptExceptions = tabSiteSettings.get('noScriptExceptions')
if (typeof originFlashEnabled === 'number') {
if (originFlashEnabled < Date.now()) {
appActions.removeSiteSetting(origin, 'flash', isPrivate)
}
}
if (originWidevineEnabled === 0) {
appActions.removeSiteSetting(origin, 'widevine', isPrivate)
}
if (originNoScriptEnabled === 0) {
appActions.removeSiteSetting(origin, 'noScript', isPrivate)
}
if (originNoScriptExceptions) {
appActions.noScriptExceptionsAdded(origin, originNoScriptExceptions.map(value => value === 0 ? false : value))
}
}

const tabsReducer = (state, action, immutableAction) => {
action = immutableAction || makeImmutable(action)
switch (action.get('actionType')) {
case tabActionConsts.FINISH_NAVIGATION:
case tabActionConsts.START_NAVIGATION:
{
const tabId = action.get('tabId')
const originalOrigin = tabState.getVisibleOrigin(state, tabId)
state = tabState.setNavigationState(state, tabId, action.get('navigationState'))
const newOrigin = tabState.getVisibleOrigin(state, tabId)
// For cross-origin navigation, clear temp approvals
if (originalOrigin !== newOrigin) {
expireContentSettings(state, tabId, originalOrigin)
}
setImmediate(() => {
tabs.setWebRTCIPHandlingPolicy(tabId, getWebRTCPolicy(state, tabId))
})
Expand All @@ -84,28 +121,62 @@ const tabsReducer = (state, action, immutableAction) => {
})
break
}
case tabActionConsts.FIND_IN_PAGE_REQUEST:
{
const tabId = tabState.resolveTabId(state, action.get('tabId'))
setImmediate(() => {
tabs.findInPage(
tabId,
action.get('searchString'),
action.get('caseSensitivity'),
action.get('forward'),
action.get('findNext')
)
})
break
}
case tabActionConsts.STOP_FIND_IN_PAGE_REQUEST:
{
const tabId = tabState.resolveTabId(state, action.get('tabId'))
setImmediate(() => {
tabs.stopFindInPage(tabId)
})
break
}
case tabActionConsts.ZOOM_CHANGED:
{
const tabId = tabState.resolveTabId(state, action.get('tabId'))
const zoomPercent = action.get('zoomPercent')
state = tabState.setZoomPercent(state, tabId, zoomPercent)
break
}
case appConstants.APP_SET_STATE:
state = tabs.init(state, action)
break
case appConstants.APP_TAB_CREATED:
state = tabState.maybeCreateTab(state, action)
break
case appConstants.APP_TAB_ATTACHED:
case appConstants.APP_TAB_MOVED:
state = tabs.updateTabsStateForAttachedTab(state, action.get('tabId'))
break
case appConstants.APP_TAB_WILL_ATTACH: {
const tabId = action.get('tabId')
const tabValue = tabState.getByTabId(state, tabId)
if (!tabValue) {
case appConstants.APP_TAB_INSERTED_TO_TAB_STRIP: {
const windowId = action.get('windowId')
if (windowId == null) {
break
}
const oldWindowId = tabState.getWindowId(state, tabId)
state = tabs.updateTabsStateForWindow(state, oldWindowId)
const tabId = action.get('tabId')
state = tabState.setTabStripWindowId(state, tabId, windowId)
state = tabs.updateTabIndexesForWindow(state, windowId)
break
}
case appConstants.APP_TAB_MOVED:
state = tabs.updateTabsStateForAttachedTab(state, action.get('tabId'))
case appConstants.APP_TAB_DETACHED_FROM_TAB_STRIP: {
const windowId = action.get('windowId')
if (windowId == null) {
break
}
state = tabs.updateTabIndexesForWindow(state, windowId)
break
}
case appConstants.APP_TAB_DETACH_MENU_ITEM_CLICKED: {
setImmediate(() => {
const tabId = action.get('tabId')
Expand Down Expand Up @@ -256,8 +327,10 @@ const tabsReducer = (state, action, immutableAction) => {
// But still check for no tabId because on tab detach there's a dummy tabId
const tabValue = tabState.getByTabId(state, tabId)
if (tabValue) {
const lastOrigin = tabState.getVisibleOrigin(state, tabId)
expireContentSettings(state, tabId, lastOrigin)
const windowIdOfTabBeingRemoved = tabState.getWindowId(state, tabId)
state = tabs.updateTabsStateForWindow(state, windowIdOfTabBeingRemoved)
state = tabs.updateTabIndexesForWindow(state, windowIdOfTabBeingRemoved)
}
state = tabState.removeTabByTabId(state, tabId)
tabs.forgetTab(tabId)
Expand Down Expand Up @@ -302,6 +375,14 @@ const tabsReducer = (state, action, immutableAction) => {
tabs.setTabIndex(action.get('tabId'), action.get('index'))
})
break
case appConstants.APP_TAB_SET_FULL_SCREEN: {
const isFullscreen = action.get('isFullScreen')
const tabId = action.get('tabId')
if (isFullscreen === true || isFullscreen === false) {
tabs.setFullScreen(tabId, isFullscreen)
}
break
}
case appConstants.APP_TAB_TOGGLE_DEV_TOOLS:
setImmediate(() => {
tabs.toggleDevTools(action.get('tabId'))
Expand Down Expand Up @@ -378,12 +459,19 @@ const tabsReducer = (state, action, immutableAction) => {
}
break
}
case appConstants.APP_FRAME_CHANGED:
state = tabState.updateFrame(state, action, shouldDebugTabEvents)
case appConstants.APP_FRAMES_CHANGED:
for (const frameAction of action.get('frames').valueSeq()) {
state = tabState.updateFrame(state, frameAction, shouldDebugTabEvents)
}
break
// TODO: convert window frame navigation status (load, error, etc)
// to browser actions with data on tab state. This reducer responds to
// actions from both at the moment (browser-side for certificate errors and
// renderer-side for load errors) until all can be refactored.
case windowConstants.WINDOW_SET_FRAME_ERROR:
case tabActionConsts.SET_CONTENTS_ERROR:
{
const tabId = action.getIn(['frameProps', 'tabId'])
const tabId = action.getIn(['frameProps', 'tabId']) || action.get('tabId')
const tab = getWebContents(tabId)
if (tab) {
let currentIndex = tab.getCurrentEntryIndex()
Expand Down Expand Up @@ -448,15 +536,21 @@ const tabsReducer = (state, action, immutableAction) => {
if (dragData && dragData.get('type') === dragTypes.TAB) {
const frame = dragData.get('data')
let frameOpts = frameOptsFromFrame(frame)
const draggingTabId = frameOpts.get('tabId')
const browserOpts = { positionByMouseCursor: true, checkMaximized: true }
const tabIdForIndex = dragData.getIn(['dragOverData', 'draggingOverKey'])
const tabForIndex = tabState.getByTabId(state, tabIdForIndex)
const tabForIndex = tabIdForIndex !== draggingTabId && tabState.getByTabId(state, tabIdForIndex)
const dropWindowId = dragData.get('dropWindowId')
if (dropWindowId != null && dropWindowId !== -1 && tabForIndex) {
let newIndex = -1
// Set new index for new window if last dragged-over tab is in new window.
// Otherwise, could be over another tab's tab strip, but most recently dragged-over a tab in another window.
if (dropWindowId != null && dropWindowId !== -1 && tabForIndex && tabForIndex.get('windowId') === dropWindowId) {
const prependIndexByTabId = dragData.getIn(['dragOverData', 'draggingOverLeftHalf'])
frameOpts = frameOpts.set('index', tabForIndex.get('index') + (prependIndexByTabId ? 0 : 1))
newIndex = tabForIndex.get('index') + (prependIndexByTabId ? 0 : 1)
}
tabs.moveTo(state, frame.get('tabId'), frameOpts, browserOpts, dragData.get('dropWindowId'))
// ensure the tab never moves window with its original index
frameOpts = frameOpts.set('index', newIndex)
tabs.moveTo(state, draggingTabId, frameOpts, browserOpts, dragData.get('dropWindowId'))
}
break
}
Expand Down
Loading

0 comments on commit 73886ff

Please sign in to comment.