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

Commit efeb942

Browse files
committed
improve performance for tabs, include intersectionObserver
fix #10611 fix #10582 fix #10544 fix #10509 fix #10123 fix #9998 fix #9398 fix #8414 fix #7925 fix #7730 fix #7301 fix #6957
1 parent 661ef90 commit efeb942

29 files changed

+907
-711
lines changed

app/common/state/tabContentState.js

-189
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
// Utils
6+
const {isEntryIntersected} = require('../../../../app/renderer/lib/observerUtil')
7+
const {getFrameByKey} = require('../../../../js/state/frameStateUtil')
8+
9+
module.exports.canPlayAudio = (state, frameKey) => {
10+
const frame = getFrameByKey(state, frameKey)
11+
12+
if (frame == null) {
13+
return false
14+
}
15+
16+
return frame.get('audioPlaybackActive') || frame.get('audioMuted')
17+
}
18+
19+
module.exports.isAudioMuted = (state, frameKey) => {
20+
const frame = getFrameByKey(state, frameKey)
21+
22+
if (frame == null) {
23+
return false
24+
}
25+
26+
const tabCanPlayAudio = module.exports.canPlayAudio(state, frameKey)
27+
return tabCanPlayAudio && frame.get('audioMuted')
28+
}
29+
30+
module.exports.showAudioIcon = (state, frameKey) => {
31+
const frame = getFrameByKey(state, frameKey)
32+
33+
if (frame == null) {
34+
return false
35+
}
36+
37+
return (
38+
!isEntryIntersected(state, 'tabs') &&
39+
module.exports.canPlayAudio(state, frameKey)
40+
)
41+
}
42+
43+
module.exports.showAudioTopBorder = (state, frameKey) => {
44+
return (
45+
isEntryIntersected(state, 'tabs') &&
46+
module.exports.canPlayAudio(state, frameKey)
47+
)
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
// Utils
6+
const frameStateUtil = require('../../../../js/state/frameStateUtil')
7+
const {isEntryIntersected} = require('../../../../app/renderer/lib/observerUtil')
8+
const {isSourceAboutUrl} = require('../../../../js/lib/appUrlUtil')
9+
const tabUIState = require('../tabUIState')
10+
const tabState = require('../tabState')
11+
12+
// Styles
13+
const {intersection} = require('../../../renderer/components/styles/global')
14+
15+
module.exports.showFavicon = (state, frameKey) => {
16+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
17+
const isNewTabPage = tabUIState.isNewTab(state, frameKey)
18+
19+
if (frame == null) {
20+
return false
21+
}
22+
23+
if (isEntryIntersected(state, 'tabs', intersection.at35)) {
24+
// when almost all tab content is covered,
25+
// only show favicon for the non-active tab
26+
return !frameStateUtil.isFrameKeyActive(state, frameKey)
27+
}
28+
29+
// new tab page is the only tab we do not show favicon
30+
return !isNewTabPage
31+
}
32+
33+
module.exports.getFavicon = (state, frameKey) => {
34+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
35+
const isLoadingVisible = module.exports.showLoadingIcon(state, frameKey)
36+
37+
if (frame == null) {
38+
return ''
39+
}
40+
return !isLoadingVisible && frame.get('icon')
41+
}
42+
43+
module.exports.showLoadingIcon = (state, frameKey) => {
44+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
45+
46+
if (frame == null) {
47+
return false
48+
}
49+
50+
const tabId = frame.get('tabId', tabState.TAB_ID_NONE)
51+
52+
return (
53+
!isSourceAboutUrl(frame.get('location')) &&
54+
tabState.isLoading(state, tabId)
55+
)
56+
}
57+
58+
module.exports.showIconWithLessMargin = (state) => {
59+
return isEntryIntersected(state, 'tabs', intersection.at20)
60+
}
61+
62+
module.exports.showFaviconAtReducedSize = (state) => {
63+
return isEntryIntersected(state, 'tabs', intersection.at15)
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
// State
6+
const frameStateUtil = require('../../../../js/state/frameStateUtil')
7+
8+
// Constants
9+
const {tabs} = require('../../../../js/constants/config')
10+
11+
module.exports.isPartitionTab = (state, frameKey) => {
12+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
13+
14+
if (frame == null) {
15+
return false
16+
}
17+
18+
return !!frame.get('partitionNumber')
19+
}
20+
21+
module.exports.getPartitionNumber = (state, frameKey) => {
22+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
23+
24+
if (frame == null) {
25+
return 0
26+
}
27+
28+
if (typeof frame.get('partitionNumber') === 'string') {
29+
return frame.get('partitionNumber').replace(/^partition-/i, '')
30+
}
31+
return frame.get('partitionNumber')
32+
}
33+
34+
module.exports.getMaxAllowedPartitionNumber = (state, frameKey) => {
35+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
36+
37+
if (frame == null) {
38+
return 0
39+
}
40+
41+
const partitionNumber = module.exports.getPartitionNumber(state, frameKey)
42+
43+
if (partitionNumber > tabs.maxAllowedNewSessions) {
44+
return tabs.maxAllowedNewSessions
45+
}
46+
return partitionNumber
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
// State
6+
const frameStateUtil = require('../../../../js/state/frameStateUtil')
7+
8+
module.exports.isPrivateTab = (state, frameKey) => {
9+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
10+
11+
if (frame == null) {
12+
return false
13+
}
14+
15+
return !!frame.get('isPrivate')
16+
}

0 commit comments

Comments
 (0)