Skip to content

Commit

Permalink
code review: floating net requests recategorized as behind-the-scene
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Mar 22, 2015
1 parent 78a4b59 commit 58ebcd2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
38 changes: 27 additions & 11 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,44 @@ vAPI.tabs.registerListeners = function() {
}
};

// 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 onCreatedNavigationTarget = function(details) {
//console.debug('onCreatedNavigationTarget: popup candidate', details.tabId);
//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);
popupCandidateTest(details);
if ( popupCandidateTest(details) === true ) {
return;
}
};

var onBeforeNavigate = function(details) {
if ( details.frameId === 0 ) {
//console.debug('onBeforeNavigate: popup candidate', details.tabId);
popupCandidateTest(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 ( popupCandidateTest(details) === true ) {
return;
}
popupCandidateDestroy(details);
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);
};

chrome.webNavigation.onCreatedNavigationTarget.addListener(onCreatedNavigationTarget);
Expand Down
6 changes: 6 additions & 0 deletions src/js/pagestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/js/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
vAPI.tabs.onNavigation({ tabId: tabId, frameId: 0, url: mostRecentRootDocURL });
pageStore = µb.pageStoreFromTabId(tabId);
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);
}
}

Expand Down

0 comments on commit 58ebcd2

Please sign in to comment.