mirror of https://github.com/gorhill/uBlock.git
code review: floating net requests recategorized as behind-the-scene
This commit is contained in:
parent
78a4b59c65
commit
58ebcd21c3
|
@ -134,28 +134,44 @@ vAPI.tabs.registerListeners = function() {
|
|||
}
|
||||
};
|
||||
|
||||
var onCreatedNavigationTarget = function(details) {
|
||||
//console.debug('onCreatedNavigationTarget: popup candidate', details.tabId);
|
||||
popupCandidateCreate(details);
|
||||
popupCandidateTest(details);
|
||||
};
|
||||
// The chrome.webRequest.onBeforeRequest() won't be called for everything
|
||||
// else than `http`/`https`. Thus, in such case, we will bind the tab as
|
||||
// early as possible in order to increase the likelihood of a context
|
||||
// properly setup if network requests are fired from within the tab.
|
||||
// Example: Chromium + case #6 at
|
||||
// http://raymondhill.net/ublock/popup.html
|
||||
var reGoodForWebRequestAPI = /^https?:\/\//;
|
||||
|
||||
var onBeforeNavigate = function(details) {
|
||||
if ( details.frameId === 0 ) {
|
||||
//console.debug('onBeforeNavigate: popup candidate', details.tabId);
|
||||
popupCandidateTest(details);
|
||||
var onCreatedNavigationTarget = function(details) {
|
||||
//console.debug('onCreatedNavigationTarget: popup candidate tab id %d = "%s"', details.tabId, details.url);
|
||||
if ( reGoodForWebRequestAPI.test(details.url) === false ) {
|
||||
details.frameId = 0;
|
||||
onNavigationClient(details);
|
||||
}
|
||||
popupCandidateCreate(details);
|
||||
if ( popupCandidateTest(details) === true ) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
var onBeforeNavigate = function(details) {
|
||||
if ( details.frameId !== 0 ) {
|
||||
return;
|
||||
}
|
||||
//console.debug('onBeforeNavigate: popup candidate tab id %d = "%s"', details.tabId, details.url);
|
||||
popupCandidateTest(details);
|
||||
};
|
||||
|
||||
var onCommitted = function(details) {
|
||||
if ( details.frameId === 0 ) {
|
||||
//console.debug('onCommitted: popup candidate', details.tabId);
|
||||
if ( details.frameId !== 0 ) {
|
||||
return;
|
||||
}
|
||||
onNavigationClient(details);
|
||||
//console.debug('onCommitted: popup candidate tab id %d = "%s"', details.tabId, details.url);
|
||||
if ( popupCandidateTest(details) === true ) {
|
||||
return;
|
||||
}
|
||||
popupCandidateDestroy(details);
|
||||
}
|
||||
onNavigationClient(details);
|
||||
};
|
||||
|
||||
chrome.webNavigation.onCreatedNavigationTarget.addListener(onCreatedNavigationTarget);
|
||||
|
|
|
@ -508,6 +508,12 @@ PageStore.prototype.init = function(tabId, pageURL) {
|
|||
/******************************************************************************/
|
||||
|
||||
PageStore.prototype.reuse = function(pageURL, context) {
|
||||
// This can very well happen under normal circumstances. Leave the context
|
||||
// unchanged when this happens.
|
||||
if ( pageURL === this.pageURL ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// If URL changes without a page reload (more and more common), then we
|
||||
// need to keep all that we collected for reuse. In particular, not
|
||||
// doing so was causing a problem in `videos.foxnews.com`: clicking a
|
||||
|
|
|
@ -65,26 +65,30 @@ var onBeforeRequest = function(details) {
|
|||
var µb = µBlock;
|
||||
var pageStore = µb.pageStoreFromTabId(tabId);
|
||||
if ( !pageStore ) {
|
||||
if ( mostRecentRootDocURL === '' ) {
|
||||
return;
|
||||
}
|
||||
// https://github.com/gorhill/uBlock/issues/1025
|
||||
// Google Hangout popup opens without a root frame. So for now we will
|
||||
// just discard that best-guess root frame if it is too far in the
|
||||
// future, at which point it ceases to be a "best guess".
|
||||
if ( (Date.now() - mostRecentRootDocURLTimestamp) >= 500 ) {
|
||||
mostRecentRootDocURL = '';
|
||||
return;
|
||||
}
|
||||
// https://github.com/gorhill/uBlock/issues/1001
|
||||
// Not a behind-the-scene request, yet no page store found for the
|
||||
// tab id: we will thus bind the last-seen root document to the
|
||||
// unbound tab. It's a guess, but better than ending up filtering
|
||||
// nothing at all.
|
||||
if ( mostRecentRootDocURL !== '' ) {
|
||||
vAPI.tabs.onNavigation({ tabId: tabId, frameId: 0, url: mostRecentRootDocURL });
|
||||
pageStore = µb.pageStoreFromTabId(tabId);
|
||||
}
|
||||
// If all else fail at finding a page store, re-categorize the
|
||||
// request as behind-the-scene. At least this ensures that ultimately
|
||||
// the user can still inspect/filter those net requests which were
|
||||
// about to fall through the cracks.
|
||||
// Example: Chromium + case #12 at
|
||||
// http://raymondhill.net/ublock/popup.html
|
||||
if ( !pageStore ) {
|
||||
return;
|
||||
return onBeforeBehindTheSceneRequest(details);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue