Don't double-notify own pages

This commit is contained in:
tophf 2017-04-16 13:20:37 +03:00
parent e8ec224dac
commit 1649a262cd

View File

@ -45,11 +45,14 @@ function notifyAllTabs(msg) {
const affectsTabs = affectsAll || affectsOwnOriginOnly; const affectsTabs = affectsAll || affectsOwnOriginOnly;
const affectsIcon = affectsAll || msg.affects.icon; const affectsIcon = affectsAll || msg.affects.icon;
const affectsPopup = affectsAll || msg.affects.popup; const affectsPopup = affectsAll || msg.affects.popup;
const affectsSelf = affectsPopup || msg.prefs;
if (affectsTabs || affectsIcon) { if (affectsTabs || affectsIcon) {
// list all tabs including chrome-extension:// which can be ours // list all tabs including chrome-extension:// which can be ours
chrome.tabs.query(affectsOwnOriginOnly ? {url: URLS.ownOrigin + '*'} : {}, tabs => { chrome.tabs.query(affectsOwnOriginOnly ? {url: URLS.ownOrigin + '*'} : {}, tabs => {
for (const tab of tabs) { for (const tab of tabs) {
if (affectsTabs || URLS.optionsUI.includes(tab.url)) { // own pages will be notified via runtime.sendMessage later
if ((affectsTabs || URLS.optionsUI.includes(tab.url))
&& !(affectsSelf && tab.url.startsWith(URLS.ownOrigin))) {
chrome.tabs.sendMessage(tab.id, msg); chrome.tabs.sendMessage(tab.id, msg);
} }
if (affectsIcon && BG) { if (affectsIcon && BG) {
@ -67,7 +70,7 @@ function notifyAllTabs(msg) {
applyOnMessage(originalMessage); applyOnMessage(originalMessage);
} }
// notify background page and all open popups // notify background page and all open popups
if (affectsPopup || msg.prefs) { if (affectsSelf) {
chrome.runtime.sendMessage(msg); chrome.runtime.sendMessage(msg);
} }
} }