Skip to content

Commit 7b3e3de

Browse files
committed
Store very large HTML as a blob #3434
1 parent 47d7cd0 commit 7b3e3de

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

webextensions/common/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,14 @@ export const kWINDOW_STATE_SUBPANEL_HEIGHT = 'subpanel-height';
237237
export const kWINDOW_STATE_SUBPANEL_EFFECTIVE_HEIGHT = 'subpanel-effective-height';
238238
export const kWINDOW_STATE_CACHED_TABS = 'cached-tabs';
239239
export const kWINDOW_STATE_CACHED_SIDEBAR = 'cached-sidebar-contents';
240+
export const kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS = 'cached-sidebar-contents:contents';
240241
export const kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY = 'cached-sidebar-contents:tabs-dirty';
241242
export const kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY = 'cached-sidebar-contents:collapsed-dirty';
242243

243244
export const kCACHE_KEYS = [
244245
kWINDOW_STATE_CACHED_TABS,
245246
kWINDOW_STATE_CACHED_SIDEBAR,
247+
kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS,
246248
kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY,
247249
kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY,
248250
];

webextensions/sidebar/sidebar-cache.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ async function preload(tab) {
8484
mTargetWindow = tab.windowId;
8585
const cache = await MetricsData.addAsync('preload: reading window cache', Promise.all([
8686
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR),
87+
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS),
8788
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY),
8889
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY),
8990
]).catch(ApiTabs.createErrorSuppressor()));
@@ -95,6 +96,7 @@ export async function getEffectiveWindowCache(options = {}) {
9596
log('getEffectiveWindowCache: start');
9697
cancelReservedUpdateCachedTabbar(); // prevent to break cache before loading
9798
let cache;
99+
let cachedContents;
98100
let cachedSignature;
99101
let actualSignature;
100102
await Promise.all([
@@ -107,12 +109,19 @@ export async function getEffectiveWindowCache(options = {}) {
107109
// [cache, const tabsDirty, const collapsedDirty] = await Promise.all([
108110
let tabsDirty, collapsedDirty;
109111
const preloadedCache = mPreloadedCaches.get(`window${mLastWindowCacheOwner.windowId}`);
110-
[cache, tabsDirty, collapsedDirty] = preloadedCache || await MetricsData.addAsync('getEffectiveWindowCache: reading window cache', Promise.all([
112+
[cache, cachedContents, tabsDirty, collapsedDirty] = preloadedCache || await MetricsData.addAsync('getEffectiveWindowCache: reading window cache', Promise.all([
111113
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR),
114+
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS),
112115
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY),
113116
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY)
114117
]));
115118
mPreloadedCaches.clear();
119+
if (cache && cache.tabbar && cachedContents) {
120+
const contents = await cachedContents.text();
121+
const versionPart = contents.match(/^version=(\d+)\n/);
122+
if (versionPart && versionPart[1] == cache.version)
123+
cache.tabbar.contents = contents.replace(/^version=(\d+)\n/, '');
124+
}
116125
cachedSignature = cache && cache.signature;
117126
log(`getEffectiveWindowCache: got from the owner `, mLastWindowCacheOwner, {
118127
cachedSignature, cache, tabsDirty, collapsedDirty
@@ -449,6 +458,7 @@ async function updateWindowCache(key, value) {
449458
function clearWindowCache() {
450459
log('clearWindowCache ', { stack: configs.debug && new Error().stack });
451460
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR);
461+
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS);
452462
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY);
453463
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY);
454464
}
@@ -526,13 +536,16 @@ async function updateCachedTabbar() {
526536
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR, {
527537
version: kCONTENTS_VERSION,
528538
tabbar: {
529-
contents: SidebarTabs.wholeContainer.innerHTML,
530539
style: mTabBar.getAttribute('style'),
531540
pinnedTabsCount: Tab.getPinnedTabs(mTargetWindow).length
532541
},
533542
indent: Indent.getCacheInfo(),
534543
signature
535544
});
545+
updateWindowCache(
546+
Constants.kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS,
547+
new Blob([`version=${kCONTENTS_VERSION}\n${SidebarTabs.wholeContainer.innerHTML}`])
548+
);
536549
}
537550

538551

0 commit comments

Comments
 (0)