mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
code review
This commit is contained in:
parent
c32de1dfc4
commit
2705432f43
@ -1923,47 +1923,41 @@ var httpObserver = {
|
||||
// Also:
|
||||
// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Limitations_of_chrome_scripts
|
||||
tabIdFromChannel: function(channel) {
|
||||
var aWindow;
|
||||
if ( channel.notificationCallbacks ) {
|
||||
var ncbs = channel.notificationCallbacks;
|
||||
if ( !ncbs && channel.loadGroup ) {
|
||||
ncbs = channel.loadGroup.notificationCallbacks;
|
||||
}
|
||||
if ( !ncbs ) { return vAPI.noTabId; }
|
||||
var lc;
|
||||
try {
|
||||
var loadContext = channel
|
||||
.notificationCallbacks
|
||||
.getInterface(Ci.nsILoadContext);
|
||||
if ( loadContext.topFrameElement ) {
|
||||
return tabWatcher.tabIdFromTarget(loadContext.topFrameElement);
|
||||
lc = ncbs.getInterface(Ci.nsILoadContext);
|
||||
} catch (ex) { }
|
||||
if ( !lc ) { return vAPI.noTabId; }
|
||||
if ( lc.topFrameElement ) {
|
||||
return tabWatcher.tabIdFromTarget(lc.topFrameElement);
|
||||
}
|
||||
aWindow = loadContext.associatedWindow;
|
||||
} catch (ex) {
|
||||
//console.error(ex.toString());
|
||||
var win = lc.associatedWindow;
|
||||
if ( !win ) { return vAPI.noTabId; }
|
||||
if ( win.top ) {
|
||||
win = win.top;
|
||||
}
|
||||
}
|
||||
var gBrowser;
|
||||
var tabBrowser;
|
||||
try {
|
||||
if ( !aWindow && channel.loadGroup && channel.loadGroup.notificationCallbacks ) {
|
||||
aWindow = channel
|
||||
.loadGroup
|
||||
.notificationCallbacks
|
||||
.getInterface(Ci.nsILoadContext)
|
||||
.associatedWindow;
|
||||
tabBrowser = getTabBrowser(
|
||||
win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell).rootTreeItem
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow)
|
||||
);
|
||||
} catch (ex) { }
|
||||
if ( !tabBrowser ) { return vAPI.noTabId; }
|
||||
if ( tabBrowser.getBrowserForContentWindow ) {
|
||||
return tabWatcher.tabIdFromTarget(tabBrowser.getBrowserForContentWindow(win));
|
||||
}
|
||||
if ( aWindow ) {
|
||||
gBrowser = aWindow
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell)
|
||||
.rootTreeItem
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow)
|
||||
.gBrowser;
|
||||
}
|
||||
} catch (ex) {
|
||||
//console.error(ex.toString());
|
||||
}
|
||||
if ( !gBrowser || !gBrowser._getTabForContentWindow ) {
|
||||
return vAPI.noTabId;
|
||||
}
|
||||
// Using `_getTabForContentWindow` ensure older versions of Firefox
|
||||
// work well.
|
||||
return tabWatcher.tabIdFromTarget(gBrowser._getTabForContentWindow(aWindow));
|
||||
// Falling back onto _getTabForContentWindow to ensure older versions
|
||||
// of Firefox work well.
|
||||
return tabBrowser._getTabForContentWindow ?
|
||||
tabWatcher.tabIdFromTarget(tabBrowser._getTabForContentWindow(win)) :
|
||||
vAPI.noTabId;
|
||||
},
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/959
|
||||
|
@ -276,7 +276,7 @@ var getFirewallRules = function(srcHostname, desHostnames) {
|
||||
/******************************************************************************/
|
||||
|
||||
var popupDataFromTabId = function(tabId, tabTitle) {
|
||||
var tabContext = µb.tabContextManager.lookup(tabId);
|
||||
var tabContext = µb.tabContextManager.mustLookup(tabId);
|
||||
var r = {
|
||||
advancedUserEnabled: µb.userSettings.advancedUserEnabled,
|
||||
appName: vAPI.app.name,
|
||||
|
@ -292,7 +292,7 @@ PageStore.factory = function(tabId) {
|
||||
/******************************************************************************/
|
||||
|
||||
PageStore.prototype.init = function(tabId) {
|
||||
var tabContext = µb.tabContextManager.lookup(tabId);
|
||||
var tabContext = µb.tabContextManager.mustLookup(tabId);
|
||||
this.tabId = tabId;
|
||||
this.tabHostname = tabContext.rootHostname;
|
||||
this.title = tabContext.rawURL;
|
||||
@ -335,7 +335,7 @@ PageStore.prototype.reuse = function(context) {
|
||||
// When force refreshing a page, the page store data needs to be reset.
|
||||
|
||||
// If the hostname changes, we can't merely just update the context.
|
||||
var tabContext = µb.tabContextManager.lookup(this.tabId);
|
||||
var tabContext = µb.tabContextManager.mustLookup(this.tabId);
|
||||
if ( tabContext.rootHostname !== this.tabHostname ) {
|
||||
context = '';
|
||||
}
|
||||
@ -441,7 +441,7 @@ PageStore.prototype.createContextFromFrameHostname = function(frameHostname) {
|
||||
/******************************************************************************/
|
||||
|
||||
PageStore.prototype.getNetFilteringSwitch = function() {
|
||||
return µb.tabContextManager.lookup(this.tabId).getNetFilteringSwitch();
|
||||
return µb.tabContextManager.mustLookup(this.tabId).getNetFilteringSwitch();
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
@ -451,7 +451,7 @@ PageStore.prototype.getSpecificCosmeticFilteringSwitch = function() {
|
||||
return false;
|
||||
}
|
||||
|
||||
var tabContext = µb.tabContextManager.lookup(this.tabId);
|
||||
var tabContext = µb.tabContextManager.mustLookup(this.tabId);
|
||||
|
||||
if ( µb.hnSwitches.evaluateZ('no-cosmetic-filtering', tabContext.rootHostname) ) {
|
||||
return false;
|
||||
|
@ -346,15 +346,15 @@ housekeep itself.
|
||||
return entry;
|
||||
};
|
||||
|
||||
// Find a tab context for a specific tab.
|
||||
var lookup = function(tabId) {
|
||||
return tabContexts[tabId] || null;
|
||||
};
|
||||
|
||||
// Find a tab context for a specific tab. If none is found, attempt to
|
||||
// fix this. When all fail, the behind-the-scene context is returned.
|
||||
var lookup = function(tabId, url) {
|
||||
var entry;
|
||||
if ( url !== undefined ) {
|
||||
entry = push(tabId, url);
|
||||
} else {
|
||||
entry = tabContexts[tabId];
|
||||
}
|
||||
var mustLookup = function(tabId) {
|
||||
var entry = tabContexts[tabId];
|
||||
if ( entry !== undefined ) {
|
||||
return entry;
|
||||
}
|
||||
@ -426,6 +426,7 @@ housekeep itself.
|
||||
push: push,
|
||||
commit: commit,
|
||||
lookup: lookup,
|
||||
mustLookup: mustLookup,
|
||||
exists: exists,
|
||||
createContext: createContext
|
||||
};
|
||||
@ -576,23 +577,15 @@ vAPI.tabs.onPopupUpdated = (function() {
|
||||
return function(targetTabId, openerTabId) {
|
||||
// Opener details.
|
||||
var tabContext = µb.tabContextManager.lookup(openerTabId);
|
||||
var openerURL = '';
|
||||
if ( tabContext.tabId === openerTabId ) {
|
||||
openerURL = tabContext.rawURL;
|
||||
if ( openerURL === '' ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( tabContext === null ) { return; }
|
||||
var openerURL = tabContext.rawURL;
|
||||
if ( openerURL === '' ) { return; }
|
||||
|
||||
// Popup details.
|
||||
tabContext = µb.tabContextManager.lookup(targetTabId);
|
||||
var targetURL = '';
|
||||
if ( tabContext.tabId === targetTabId ) {
|
||||
targetURL = tabContext.rawURL;
|
||||
if ( targetURL === '' ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( tabContext === null ) { return; }
|
||||
var targetURL = tabContext.rawURL;
|
||||
if ( targetURL === '' ) { return; }
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/341
|
||||
// Allow popups if uBlock is turned off in opener's context.
|
||||
|
@ -60,7 +60,7 @@ var onBeforeRequest = function(details) {
|
||||
var µb = µBlock;
|
||||
var pageStore = µb.pageStoreFromTabId(tabId);
|
||||
if ( !pageStore ) {
|
||||
var tabContext = µb.tabContextManager.lookup(tabId);
|
||||
var tabContext = µb.tabContextManager.mustLookup(tabId);
|
||||
if ( vAPI.isBehindTheSceneTabId(tabContext.tabId) ) {
|
||||
return onBeforeBehindTheSceneRequest(details);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user