Skip to content

Commit 619b366

Browse files
committed
Tab Reloading Issue Fix
:Release Notes: Tab Reloading Issue Fix :Detailed Notes: Under critical memory state, all tabs are set to reload. Bug fix - Unloaded tab is not reloaded :Testing Performed: Tested with verification Build :QA Notes: NA :Issues Addressed: [WRO-9714] Unloaded tab is not reloaded Change-Id: I7329fc1ce88e64402eb5380d361d6dcc9feb9e76
1 parent 14db7b1 commit 619b366

5 files changed

Lines changed: 80 additions & 87 deletions

File tree

samples/enact-based/src/NevaLib/MemoryManagerTabPolicy.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
//
77
// https://github.com/webosose/com.webos.app.enactbrowser/blob/master/LICENSE
88

9-
import {RendererPerTabPolicy as SimplePolicy} from './RendererPerTabPolicy.js';
9+
import { RendererPerTabPolicy as SimplePolicy } from './RendererPerTabPolicy.js';
1010

1111
const maxActive = 1;
1212

1313
class MemoryManagerTabPolicy {
14-
constructor (
15-
tabs,
16-
webViews,
17-
maxSuspendedNormal,
18-
maxSuspendedLow,
19-
maxSuspendedCritical
14+
constructor(
15+
tabs,
16+
webViews,
17+
maxSuspendedNormal,
18+
maxSuspendedLow,
19+
maxSuspendedCritical
2020
) {
2121
this.simplePolicy = new SimplePolicy(
2222
tabs,
2323
webViews,
2424
maxActive,
25-
maxSuspendedCritical
25+
maxSuspendedCritical,
2626
);
2727
this.maxSuspendedNormal = maxSuspendedNormal;
2828
this.maxSuspendedLow = maxSuspendedLow;
@@ -33,27 +33,27 @@ class MemoryManagerTabPolicy {
3333
Promise.race([
3434
new Promise((resolve) => {
3535
window.navigator.memorymanager.getMemoryStatus((ev) => {
36-
resolve(ev.system.level);
36+
resolve(ev)
3737
});
3838
}),
3939
new Promise((resolve) => {
4040
window.navigator.memorymanager.onlevelchanged = (ev) => {
41-
resolve(ev.current);
41+
resolve(ev);
4242
};
4343
})
4444
]).then((memoryStatus) => {
4545
console.log('Initializing memory status: ' + memoryStatus); // eslint-disable-line no-console
4646
policy.simplePolicy.maxSuspendedTabFamilies =
47-
policy.statusToMaxSuspended(memoryStatus);
47+
policy.statusToMaxSuspended(memoryStatus);
4848
window.navigator.memorymanager.onlevelchanged =
49-
policy._handleLevelChanged;
49+
policy._handleLevelChanged;
5050
});
5151
} else {
5252
console.error('MemoryManager interface is not implemented! Check your WebOS version!'); // eslint-disable-line no-console
5353
}
5454
}
5555

56-
statusToMaxSuspended (memoryStatus) {
56+
statusToMaxSuspended(memoryStatus) {
5757
switch (memoryStatus) {
5858
case 'normal':
5959
return this.maxSuspendedNormal;
@@ -73,18 +73,18 @@ class MemoryManagerTabPolicy {
7373
current: '[normal|low|critical]'
7474
}
7575
*/
76+
7677
_handleLevelChanged = (ev) => {
77-
console.log('Handle memory level change ' + ev.current); // eslint-disable-line no-console
78+
console.log('Memory level changed to ==>' + ev); // eslint-disable-line no-console
7879
const policy = this.simplePolicy;
79-
policy.maxSuspended = this.statusToMaxSuspended(ev.current);
80-
while (policy.queue.length > policy.maxSuspended + policy.maxActive) {
81-
const id = policy.queue.pop();
82-
policy.webViews[id].deactivate();
80+
if (ev == "critical") {
81+
policy.criticalReached = true
82+
policy._handleCriticalMemory()
83+
} else {
84+
policy.criticalReached = false
8385
}
84-
console.log('_handleLevelChanged'); // eslint-disable-line no-console
85-
console.log(policy); // eslint-disable-line no-console
8686
};
8787
}
8888

8989
export default MemoryManagerTabPolicy;
90-
export {MemoryManagerTabPolicy};
90+
export { MemoryManagerTabPolicy };

samples/enact-based/src/NevaLib/RendererPerTabPolicy.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,44 @@
66
//
77
// https://github.com/webosose/com.webos.app.enactbrowser/blob/master/LICENSE
88

9-
import {TabTypes} from 'js-browser-lib/TabsConsts';
9+
import { TabTypes } from 'js-browser-lib/TabsConsts';
1010

11+
let deactivate_tab_family, maxNotDeactivated;
1112
class RendererPerTabPolicy {
12-
constructor (tabs, webViews, maxActiveTabFamilies, maxSuspendedTabFamilies) {
13-
this.webViews = webViews;
14-
this.queue = [];
15-
this.maxActiveTabFamilies = maxActiveTabFamilies;
16-
this.maxSuspendedTabFamilies = maxSuspendedTabFamilies;
17-
tabs.addEventListener('select', this._handleTabSelect);
18-
tabs.addEventListener('delete', this._handleTabDelete);
19-
}
13+
constructor(tabs, webViews, maxActiveTabFamilies, maxSuspendedTabFamilies) {
14+
this.webViews = webViews;
15+
this.queue = [];
16+
this.maxActiveTabFamilies = maxActiveTabFamilies;
17+
this.maxSuspendedTabFamilies = maxSuspendedTabFamilies;
18+
this.criticalReached = false;
19+
tabs.addEventListener('select', this._handleTabSelect);
20+
tabs.addEventListener('delete', this._handleTabDelete);
21+
}
22+
23+
24+
_handleCriticalMemory = () => {
25+
if (this.criticalReached) {
26+
console.log("reached CRITICAL_HANDLER function")
27+
this.webViews.map((i, index) => {
28+
//Apart from current/active tab, all other tabs are de-activated.
29+
Number(this.queue[0]) !== index && this.webViews[index].deactivate()
30+
});
31+
}
32+
}
2033

21-
_handleTabSelect = (ev) => {
22-
const tab = ev.state;
34+
_handleTabSelect = (ev) => {
35+
const tab = ev.state;
2336

24-
// VKB for current tab should be hidden when the other tab is selected
25-
if (this.queue.length > 0 && this.webViews[this.queue[0]]) {
26-
this.webViews[this.queue[0]].clearTextInputFocus();
27-
}
37+
// VKB for current tab should be hidden when the other tab is selected
38+
if (this.queue.length > 0 && this.webViews[this.queue[0]]) {
39+
this.webViews[this.queue[0]].clearTextInputFocus();
40+
}
2841

29-
if (tab.type !== TabTypes.WEBVIEW) {
30-
return;
31-
}
42+
if (tab.type !== TabTypes.WEBVIEW) {
43+
return;
44+
}
3245

33-
let tab_family_id = this.webViews[tab.id].tabFamilyId;
46+
let tab_family_id = this.webViews[tab.id].tabFamilyId;
3447

3548
this.queue.unshift(tab_family_id);
3649
this.queue = [...new Set(this.queue)]; // remove duplicates
@@ -50,32 +63,41 @@ class RendererPerTabPolicy {
5063
let suspend_tab_family = manage_tab_family(
5164
id => this.webViews[id].suspend()
5265
);
53-
let deactivate_tab_family = manage_tab_family(
66+
deactivate_tab_family = manage_tab_family(
5467
id => this.webViews[id].deactivate()
5568
);
5669

5770
console.log(`tab family id: ${tab_family_id}. this.queue: ${this.queue.toString()}`);
71+
console.log("criticalReached is ==> ", this.criticalReached)
5872

5973
activate_tab_family(tab_family_id);
6074

61-
if (this.queue.length > this.maxActiveTabFamilies) {
62-
suspend_tab_family(this.queue[this.maxActiveTabFamilies]);
75+
if (!this.criticalReached) {
76+
if (this.queue.length > this.maxActiveTabFamilies) {
77+
suspend_tab_family(this.queue[this.maxActiveTabFamilies]);
78+
}
79+
80+
maxNotDeactivated = this.maxActiveTabFamilies + this.maxSuspendedTabFamilies;
6381
}
6482

65-
const maxNotDeactivated = this.maxActiveTabFamilies + this.maxSuspendedTabFamilies;
83+
if (this.criticalReached) {
84+
this.webViews.map((i, index) => {
85+
return Number(this.queue[0]) !== index && this.webViews[index].deactivate()
86+
});
87+
}
6688

6789
if (this.queue.length > maxNotDeactivated) {
68-
deactivate_tab_family(this.queue.pop());
90+
return deactivate_tab_family(this.queue.pop());
6991
}
70-
};
92+
};
7193

72-
_handleTabDelete = (ev) => {
73-
const tab = ev.state;
74-
if (tab.type !== TabTypes.WEBVIEW) {
75-
return;
76-
}
94+
_handleTabDelete = (ev) => {
95+
const tab = ev.state;
96+
if (tab.type !== TabTypes.WEBVIEW) {
97+
return;
98+
}
7799

78-
this.queue = this.queue.filter((tab_family_id) => {
100+
this.queue = this.queue.filter((tab_family_id) => {
79101
// if there are at least one tab family member
80102
let result = this.webViews.find((webView, index, views) => {
81103
if (views[index] === undefined) {
@@ -85,8 +107,8 @@ class RendererPerTabPolicy {
85107
});
86108
return result !== undefined;
87109
});
88-
};
110+
};
89111
}
90112

91113
export default RendererPerTabPolicy;
92-
export {RendererPerTabPolicy};
114+
export { RendererPerTabPolicy };

samples/enact-based/src/components/Popup/Popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// https://github.com/webosose/com.webos.app.enactbrowser/blob/master/LICENSE
88

99
/**
10-
* Contains the declaration for the Menu component.
10+
* Contains the declaration for the Popup component.
1111
*
1212
*/
1313
import $L from '@enact/i18n/$L';

samples/enact-based/src/components/Popup/Popup.module.less

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
1-
/* Menu.module.less */
1+
/* Popup.module.less */
22

33
@import '~@enact/agate/styles/skin.less';
44
@import '~@enact/agate/styles/variables.less';
55
@import '~@enact/agate/styles/mixins.less';
66

7-
.menuContainer {
8-
min-width: 322px;
9-
}
10-
11-
.MenuPopupButton {
12-
width: 20rem !important;
13-
14-
.contextualPopup .container {
15-
width: 20rem;
16-
}
17-
18-
.container {
19-
width: 20rem;
20-
}
21-
}
22-
23-
.applySkins({
24-
.item {
25-
padding: 0;
26-
border-bottom-color: transparent;
27-
line-height: 48px;
28-
29-
.focus({
30-
border-bottom-color: transparent;
31-
});
32-
}
33-
});
34-
357
.NotificationPopup {
368
background-color: white;
379
padding: 0.5%;
@@ -62,7 +34,6 @@
6234
margin-right: 3%;
6335
}
6436

65-
6637
.closeIcon {
6738
color: black;
6839
font-size: 2.2rem !important;

src/WebView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ const WebViewMixinBase = {
9898
deactivate: function WebViewMixin_deactivate() {
9999
console.log('DEACTIVATE ' + this.rootId);
100100
if (this.activeState !== 'deactivated') {
101-
// document.getElementById(this.rootId).removeChild(this); // TODO: change to terminate
102-
// this.activeState = 'deactivated';
101+
document.getElementById(this.rootId).removeChild(this); // TODO: change to terminate
102+
this.activeState = 'deactivated';
103103
}
104104
},
105105

0 commit comments

Comments
 (0)