Skip to content

Commit

Permalink
Fix: update tab icon on forward/backward
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 committed Oct 13, 2018
1 parent f08faea commit 43afa31
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
13 changes: 10 additions & 3 deletions background/background.js
Expand Up @@ -147,11 +147,18 @@ prefs.initializing.then(() => {
refreshAllIcons();
});

navigatorUtil.onUrlChange(({tabId, frameId}, type) => {
navigatorUtil.onUrlChange(({tabId, frameId, transitionQualifiers}, type) => {
if (type === 'committed' && !frameId) {
// it seems that the tab icon would be reset when pressing F5. We
// invalidate the cache here so it would be refreshed.
// it seems that the tab icon would be reset by navigation. We
// invalidate the cache here so it would be refreshed by `apply.js`.
tabIcons.delete(tabId);

// however, if the tab was swapped in by forward/backward buttons,
// `apply.js` doesn't notify the background to update the icon,
// so we have to refresh it manually.
if (transitionQualifiers.includes('forward_back')) {
msg.sendTab(tabId, {method: 'updateCount'}).catch(msg.broadcastError);
}
}
});

Expand Down
3 changes: 3 additions & 0 deletions background/navigator-util.js
Expand Up @@ -23,16 +23,19 @@ const navigatorUtil = (() => {
chrome.webNavigation.onCommitted.addListener(data =>
fixNTPUrl(data)
.then(() => executeCallbacks(handler.urlChange, data, 'committed'))
.catch(console.error)
);

chrome.webNavigation.onHistoryStateUpdated.addListener(data =>
fixNTPUrl(data)
.then(() => executeCallbacks(handler.urlChange, data, 'historyStateUpdated'))
.catch(console.error)
);

chrome.webNavigation.onReferenceFragmentUpdated.addListener(data =>
fixNTPUrl(data)
.then(() => executeCallbacks(handler.urlChange, data, 'referenceFragmentUpdated'))
.catch(console.error)
);
}

Expand Down
9 changes: 4 additions & 5 deletions content/apply.js
Expand Up @@ -219,6 +219,10 @@ const APPLY = (() => {
}
});
break;

case 'updateCount':
updateCount();
break;
}
}

Expand Down Expand Up @@ -336,11 +340,6 @@ const APPLY = (() => {
}
docRootObserver.firstStart();

// FIXME
// if (FF_BUG461 && (gotNewStyles || styles.needTransitionPatch)) {
// setContentsInPageContext();
// }

if (!isOwnPage && !docRewriteObserver && styleElements.size) {
initDocRewriteObserver();
}
Expand Down

0 comments on commit 43afa31

Please sign in to comment.