Don't wrongly style tabs with identical openerTabId

This commit is contained in:
tophf 2015-07-24 14:42:46 +03:00
parent ff0e07d150
commit 7d25709a7d

View File

@ -1,3 +1,11 @@
var frameIdMessageable;
try {
chrome.tabs.sendMessage(0, {}, {frameId: 0}, function() {
var clearError = chrome.runtime.lastError;
frameIdMessageable = true;
});
} catch(e) {}
// This happens right away, sometimes so fast that the content script isn't even ready. That's // This happens right away, sometimes so fast that the content script isn't even ready. That's
// why the content script also asks for this stuff. // why the content script also asks for this stuff.
chrome.webNavigation.onCommitted.addListener(webNavigationListener.bind(this, "styleApply")); chrome.webNavigation.onCommitted.addListener(webNavigationListener.bind(this, "styleApply"));
@ -7,15 +15,18 @@ function webNavigationListener(method, data) {
// Until Chrome 41, we can't target a frame with a message // Until Chrome 41, we can't target a frame with a message
// (https://developer.chrome.com/extensions/tabs#method-sendMessage) // (https://developer.chrome.com/extensions/tabs#method-sendMessage)
// so a style affecting a page with an iframe will affect the main page as well. // so a style affecting a page with an iframe will affect the main page as well.
// Skip doing this for frames for now, which can result in flicker. // Skip doing this for frames in pre-41 to prevent page flicker.
if (data.frameId != 0) { if (data.frameId != 0 && !frameIdMessageable) {
return; return;
} }
getStyles({matchUrl: data.url, enabled: true, asHash: true}, function(styleHash) { getStyles({matchUrl: data.url, enabled: true, asHash: true}, function(styleHash) {
if (method) { if (method) {
chrome.tabs.sendMessage(data.tabId, {method: method, styles: styleHash}); chrome.tabs.sendMessage(data.tabId, {method: method, styles: styleHash},
frameIdMessageable ? {frameId: data.frameId} : undefined);
}
if (data.frameId == 0) {
updateIcon({id: data.tabId, url: data.url}, styleHash);
} }
updateIcon({id: data.tabId, url: data.url}, styleHash);
}); });
} }