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

Commit 1d8b913

Browse files
authored
Merge pull request #6377 from brave/order-tabs-correctly
Order tabs correctly when they have openers
2 parents 6a1a43b + 4c6a625 commit 1d8b913

File tree

9 files changed

+109
-231
lines changed

9 files changed

+109
-231
lines changed

app/browser/tabs.js

+3
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ const api = {
5151
location = 'about:blank'
5252
}
5353

54+
const openerTabId = !source.isDestroyed() ? source.getId() : -1
55+
5456
// TODO(bridiver) - handle pinned property?? - probably through tabValue
5557
const frameOpts = {
5658
location,
5759
partition: newTab.session.partition,
5860
guestInstanceId: newTab.guestInstanceId,
61+
openerTabId,
5962
disposition
6063
}
6164

docs/state.md

+1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ WindowStore
358358
internalFindStatePresent: boolean // true if a find-first (ie findNext: false) call has been made
359359
}
360360
unloaded: boolean, // true if the tab is unloaded
361+
openerTabId: number, // web contents tabId that opened this tab
361362

362363
navbar: {
363364
focused: boolean, // whether the navbar is focused

docs/windowActions.md

-12
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,6 @@ Dispatches a message to the store to create a new frame
221221

222222

223223

224-
### cloneFrame(frameProps, guestInstanceId)
225-
226-
Dispatches a message to the store to clone an existing frame
227-
228-
**Parameters**
229-
230-
**frameProps**: `Object`, The properties of the frame to clone
231-
232-
**guestInstanceId**: `number`, The guestInstanceId of the cloned webcontents
233-
234-
235-
236224
### closeFrame(frames, frameProps)
237225

238226
Dispatches a message to close a frame

js/actions/windowActions.js

-15
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,6 @@ const windowActions = {
292292
})
293293
},
294294

295-
/**
296-
* Dispatches a message to the store to clone an existing frame
297-
*
298-
* @param {Object} frameProps - The properties of the frame to clone
299-
* @param {number} guestInstanceId - The guestInstanceId of the cloned webcontents
300-
*/
301-
cloneFrame: function (frameProps, guestInstanceId, openInForeground) {
302-
dispatch({
303-
actionType: windowConstants.WINDOW_CLONE_FRAME,
304-
frameOpts: frameProps.toJS ? frameProps.toJS() : frameProps,
305-
guestInstanceId,
306-
openInForeground
307-
})
308-
},
309-
310295
/**
311296
* Dispatches a message to close a frame
312297
*

js/constants/windowConstants.js

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const windowConstants = {
1010
WINDOW_SET_NAVBAR_INPUT: _,
1111
WINDOW_NEW_FRAME: _,
1212
WINDOW_VIEW_KEY: _,
13-
WINDOW_CLONE_FRAME: _,
1413
WINDOW_CLOSE_FRAME: _,
1514
WINDOW_SET_ACTIVE_FRAME: _,
1615
WINDOW_SET_FOCUSED_FRAME: _,

js/state/frameStateUtil.js

+21-34
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ function getFrameByIndex (windowState, i) {
4343
return windowState.getIn(['frames', i])
4444
}
4545

46+
// This will eventually go away fully when we replace frameKey by tabId
47+
function getFrameKeyByTabId (windowState, tabId) {
48+
let parentFrameKey
49+
const openerFrame = getFrameByTabId(windowState, tabId)
50+
if (openerFrame) {
51+
parentFrameKey = openerFrame.get('key')
52+
}
53+
return parentFrameKey
54+
}
55+
4656
function getFrameKeysByDisplayIndex (frames) {
4757
let framesByDisplayIndex = [[], []]
4858
frames.forEach((frame) => {
@@ -232,38 +242,6 @@ function getPartition (frameOpts) {
232242
return partition
233243
}
234244

235-
function cloneFrame (frameOpts, guestInstanceId, key) {
236-
const cloneableAttributes = [
237-
'audioMuted',
238-
'canGoBack',
239-
'canGoForward',
240-
'icon',
241-
'title',
242-
'isPrivate',
243-
'partitionNumber',
244-
'themeColor',
245-
'computedThemeColor'
246-
]
247-
let clone = {}
248-
cloneableAttributes.forEach((attr) => {
249-
clone[attr] = frameOpts[attr]
250-
})
251-
252-
clone.guestInstanceId = guestInstanceId
253-
// copy the history
254-
clone.history = frameOpts.history.slice(0)
255-
// location is loaded by the webcontents
256-
clone.delayedLoadUrl = frameOpts.location
257-
clone.location = 'about:blank'
258-
clone.src = 'about:blank'
259-
clone.parentFrameKey = frameOpts.key
260-
if (frameOpts.aboutDetails !== undefined) {
261-
clone.aboutDetails = frameOpts.aboutDetails
262-
clone.aboutDetails.frameKey = key
263-
}
264-
return clone
265-
}
266-
267245
/**
268246
* Returns an object in the same format that was passed to it (ImmutableJS/POD)
269247
* for the subset of frame data that is used for tabs.
@@ -306,7 +284,8 @@ const tabFromFrame = (frame) => {
306284
* Adds a frame specified by frameOpts and newKey and sets the activeFrameKey
307285
* @return Immutable top level application state ready to merge back in
308286
*/
309-
function addFrame (frames, tabs, frameOpts, newKey, partitionNumber, activeFrameKey, insertionIndex) {
287+
function addFrame (windowState, tabs, frameOpts, newKey, partitionNumber, activeFrameKey, insertionIndex) {
288+
const frames = windowState.get('frames')
310289
const url = frameOpts.location || config.defaultUrl
311290

312291
// delayedLoadUrl is used as a placeholder when the new frame is created
@@ -329,6 +308,13 @@ function addFrame (frames, tabs, frameOpts, newKey, partitionNumber, activeFrame
329308
}
330309
}
331310

311+
// TODO: longer term get rid of parentFrameKey completely instead of
312+
// calculating it here.
313+
let parentFrameKey = frameOpts.parentFrameKey
314+
if (frameOpts.openerTabId) {
315+
parentFrameKey = getFrameKeyByTabId(windowState, frameOpts.openerTabId)
316+
}
317+
332318
const frame = Immutable.fromJS(Object.assign({
333319
zoomLevel: config.zoom.defaultValue,
334320
audioMuted: false, // frame is muted
@@ -371,6 +357,7 @@ function addFrame (frames, tabs, frameOpts, newKey, partitionNumber, activeFrame
371357
certDetails: null
372358
},
373359
unloaded: frameOpts.unloaded,
360+
parentFrameKey,
374361
history: []
375362
}, frameOpts))
376363

@@ -537,11 +524,11 @@ module.exports = {
537524
getFramePropsIndex,
538525
getFrameKeysByDisplayIndex,
539526
getPartition,
540-
cloneFrame,
541527
addFrame,
542528
undoCloseFrame,
543529
removeFrame,
544530
removeOtherFrames,
545531
tabFromFrame,
532+
getFrameKeyByTabId,
546533
getFrameTabPageIndex
547534
}

0 commit comments

Comments
 (0)