2014-10-18 08:01:09 +13:00
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
µMatrix - a Chromium browser extension to black/white list requests.
|
|
|
|
Copyright (C) 2014 Raymond Hill
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uMatrix
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* global chrome, µMatrix */
|
2015-04-11 02:45:40 +12:00
|
|
|
/* jshint boss: true */
|
2014-10-18 08:01:09 +13:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// Start isolation from global scope
|
|
|
|
|
|
|
|
µMatrix.webRequest = (function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// Intercept and filter web requests according to white and black lists.
|
|
|
|
|
|
|
|
var onBeforeRootFrameRequestHandler = function(details) {
|
|
|
|
var µm = µMatrix;
|
2015-04-12 09:15:57 +12:00
|
|
|
var requestURL = details.url;
|
2014-10-18 08:01:09 +13:00
|
|
|
var tabId = details.tabId;
|
2015-04-12 09:15:57 +12:00
|
|
|
|
|
|
|
µm.tabContextManager.push(tabId, requestURL);
|
|
|
|
|
2015-04-22 08:22:29 +12:00
|
|
|
var tabContext = µm.tabContextManager.mustLookup(tabId);
|
2015-05-03 05:30:29 +12:00
|
|
|
var pageStore = µm.bindTabToPageStats(tabId);
|
2014-11-19 06:04:40 +13:00
|
|
|
|
|
|
|
// Disallow request as per matrix?
|
2015-04-22 08:22:29 +12:00
|
|
|
var block = µm.mustBlock(tabContext.rootHostname, details.hostname, 'doc');
|
2014-10-18 08:01:09 +13:00
|
|
|
|
2015-04-22 11:47:19 +12:00
|
|
|
pageStore.recordRequest('doc', requestURL, block);
|
2015-04-22 08:22:29 +12:00
|
|
|
|
|
|
|
// Not blocked
|
2014-10-18 08:01:09 +13:00
|
|
|
if ( !block ) {
|
|
|
|
// rhill 2013-11-07: Senseless to do this for behind-the-scene requests.
|
|
|
|
// rhill 2013-12-03: Do this here only for root frames.
|
2015-04-22 08:22:29 +12:00
|
|
|
µm.cookieHunter.recordPageCookies(pageStore);
|
2014-10-18 08:01:09 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-22 08:22:29 +12:00
|
|
|
// Blocked
|
2015-05-03 05:30:29 +12:00
|
|
|
var query = btoa(JSON.stringify({
|
|
|
|
url: requestURL,
|
|
|
|
hn: details.hostname,
|
|
|
|
why: '?'
|
|
|
|
}));
|
2014-10-18 08:01:09 +13:00
|
|
|
|
2015-05-03 05:30:29 +12:00
|
|
|
vAPI.tabs.replace(tabId, vAPI.getURL('main-blocked.html?details=') + query);
|
|
|
|
|
|
|
|
return { cancel: true };
|
2014-10-18 08:01:09 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-11-30 00:50:24 +13:00
|
|
|
// Intercept and filter web requests according to white and black lists.
|
|
|
|
|
|
|
|
var onBeforeRequestHandler = function(details) {
|
|
|
|
var µm = µMatrix;
|
|
|
|
|
|
|
|
// rhill 2014-02-17: Ignore 'filesystem:': this can happen when listening
|
|
|
|
// to 'chrome-extension://'.
|
2015-05-05 02:50:44 +12:00
|
|
|
var requestScheme = µm.URI.schemeFromURI(details.url);
|
2014-11-30 00:50:24 +13:00
|
|
|
if ( requestScheme === 'filesystem' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// console.debug('onBeforeRequestHandler()> "%s": %o', details.url, details);
|
|
|
|
|
2015-04-20 08:19:14 +12:00
|
|
|
var requestType = requestTypeNormalizer[details.type] || 'other';
|
2014-11-30 00:50:24 +13:00
|
|
|
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/303
|
|
|
|
// Wherever the main doc comes from, create a receiver page URL: synthetize
|
|
|
|
// one if needed.
|
|
|
|
if ( requestType === 'doc' && details.parentFrameId < 0 ) {
|
|
|
|
return onBeforeRootFrameRequestHandler(details);
|
|
|
|
}
|
|
|
|
|
|
|
|
var requestURL = details.url;
|
|
|
|
|
|
|
|
// Ignore non-http schemes
|
2015-05-05 02:50:44 +12:00
|
|
|
if ( requestScheme.lastIndexOf('http', 0) !== 0 ) {
|
2014-11-30 00:50:24 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not block myself from updating assets
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/202
|
2015-04-20 08:19:14 +12:00
|
|
|
if ( requestType === 'xhr' && requestURL.lastIndexOf(µm.projectServerRoot, 0) === 0 ) {
|
2014-11-30 00:50:24 +13:00
|
|
|
return;
|
|
|
|
}
|
2014-10-18 08:01:09 +13:00
|
|
|
|
|
|
|
// Re-classify orphan HTTP requests as behind-the-scene requests. There is
|
|
|
|
// not much else which can be done, because there are URLs
|
2014-11-19 06:04:40 +13:00
|
|
|
// which cannot be handled by µMatrix, i.e. `opera://startpage`,
|
2014-10-18 08:01:09 +13:00
|
|
|
// as this would lead to complications with no obvious solution, like how
|
|
|
|
// to scope on unknown scheme? Etc.
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/191
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/91#issuecomment-37180275
|
2015-04-22 11:47:19 +12:00
|
|
|
var tabContext = µm.tabContextManager.mustLookup(details.tabId);
|
|
|
|
var tabId = tabContext.tabId;
|
2015-05-05 02:50:44 +12:00
|
|
|
|
|
|
|
// Enforce strict secure connection?
|
|
|
|
var block = false;
|
|
|
|
if (
|
|
|
|
tabContext.secure &&
|
|
|
|
µm.URI.isSecureScheme(requestScheme) === false &&
|
|
|
|
µm.tMatrix.evaluateSwitchZ('https-strict', tabContext.rootHostname)
|
|
|
|
) {
|
|
|
|
block = true;
|
|
|
|
}
|
2014-10-18 08:01:09 +13:00
|
|
|
|
2014-11-19 06:04:40 +13:00
|
|
|
// Disallow request as per temporary matrix?
|
2015-05-05 02:50:44 +12:00
|
|
|
if ( block === false ) {
|
|
|
|
block = µm.mustBlock(tabContext.rootHostname, details.hostname, requestType);
|
|
|
|
}
|
2014-10-18 08:01:09 +13:00
|
|
|
|
|
|
|
// Record request.
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/342
|
|
|
|
// The way requests are handled now, it may happen at this point some
|
|
|
|
// processing has already been performed, and that a synthetic URL has
|
|
|
|
// been constructed for logging purpose. Use this synthetic URL if
|
|
|
|
// it is available.
|
2015-05-05 02:50:44 +12:00
|
|
|
var pageStore = µm.mustPageStoreFromTabId(tabContext.tabId);
|
2014-11-30 00:50:24 +13:00
|
|
|
pageStore.recordRequest(requestType, requestURL, block);
|
2015-04-11 02:45:40 +12:00
|
|
|
|
2015-05-05 02:50:44 +12:00
|
|
|
// Allowed?
|
2014-10-18 08:01:09 +13:00
|
|
|
if ( !block ) {
|
|
|
|
// console.debug('onBeforeRequestHandler()> ALLOW "%s": %o', details.url, details);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-05 02:50:44 +12:00
|
|
|
// Blocked
|
2014-10-18 08:01:09 +13:00
|
|
|
// console.debug('onBeforeRequestHandler()> BLOCK "%s": %o', details.url, details);
|
|
|
|
|
|
|
|
return { 'cancel': true };
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-04-20 08:19:14 +12:00
|
|
|
// Sanitize outgoing headers as per user settings.
|
2014-10-18 08:01:09 +13:00
|
|
|
|
|
|
|
var onBeforeSendHeadersHandler = function(details) {
|
|
|
|
var µm = µMatrix;
|
|
|
|
|
|
|
|
// console.debug('onBeforeSendHeadersHandler()> "%s": %o', details.url, details);
|
|
|
|
|
|
|
|
// Re-classify orphan HTTP requests as behind-the-scene requests. There is
|
|
|
|
// not much else which can be done, because there are URLs
|
|
|
|
// which cannot be handled by HTTP Switchboard, i.e. `opera://startpage`,
|
|
|
|
// as this would lead to complications with no obvious solution, like how
|
|
|
|
// to scope on unknown scheme? Etc.
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/191
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/91#issuecomment-37180275
|
2015-04-22 08:22:29 +12:00
|
|
|
var pageStore = µm.mustPageStoreFromTabId(details.tabId);
|
|
|
|
var tabId = pageStore.tabId;
|
2014-10-18 08:01:09 +13:00
|
|
|
|
2014-11-30 00:50:24 +13:00
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/342
|
|
|
|
// Is this hyperlink auditing?
|
|
|
|
// If yes, create a synthetic URL for reporting hyperlink auditing
|
|
|
|
// in request log. This way the user is better informed of what went
|
|
|
|
// on.
|
2015-04-20 08:19:14 +12:00
|
|
|
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#hyperlink-auditing
|
|
|
|
//
|
|
|
|
// Target URL = the href of the link
|
|
|
|
// Doc URL = URL of the document containing the target URL
|
|
|
|
// Ping URLs = servers which will be told that user clicked target URL
|
|
|
|
//
|
|
|
|
// `Content-Type` = `text/ping` (always present)
|
|
|
|
// `Ping-To` = target URL (always present)
|
|
|
|
// `Ping-From` = doc URL
|
|
|
|
// `Referer` = doc URL
|
|
|
|
// request URL = URL which will receive the information
|
|
|
|
//
|
|
|
|
// With hyperlink-auditing, removing header(s) is pointless, the whole
|
|
|
|
// request must be cancelled.
|
|
|
|
|
2014-11-30 00:50:24 +13:00
|
|
|
var requestURL = details.url;
|
2015-04-20 08:19:14 +12:00
|
|
|
var requestType = requestTypeNormalizer[details.type] || 'other';
|
2015-04-20 08:30:28 +12:00
|
|
|
if ( requestType === 'ping' ) {
|
2015-04-20 08:19:14 +12:00
|
|
|
var linkAuditor = details.requestHeaders.getHeader('ping-to');
|
|
|
|
if ( linkAuditor !== '' ) {
|
2014-11-30 00:50:24 +13:00
|
|
|
var block = µm.userSettings.processHyperlinkAuditing;
|
|
|
|
pageStore.recordRequest('other', requestURL + '{Ping-To:' + linkAuditor + '}', block);
|
|
|
|
if ( block ) {
|
|
|
|
µm.hyperlinkAuditingFoiledCounter += 1;
|
|
|
|
return { 'cancel': true };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach this point, request is not blocked, so what is left to do
|
|
|
|
// is to sanitize headers.
|
|
|
|
|
2015-05-05 02:50:44 +12:00
|
|
|
if ( µm.mustBlock(pageStore.pageHostname, details.hostname, 'cookie') ) {
|
2015-04-20 08:19:14 +12:00
|
|
|
if ( details.requestHeaders.setHeader('cookie', '') ) {
|
|
|
|
µm.cookieHeaderFoiledCounter++;
|
|
|
|
}
|
2014-10-18 08:01:09 +13:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:17:24 +13:00
|
|
|
if ( µm.tMatrix.evaluateSwitchZ('referrer-spoof', pageStore.pageHostname) ) {
|
2015-05-05 02:50:44 +12:00
|
|
|
foilRefererHeaders(µm, details.hostname, details);
|
2014-10-18 08:01:09 +13:00
|
|
|
}
|
|
|
|
|
2014-11-19 15:18:57 +13:00
|
|
|
if ( µm.tMatrix.evaluateSwitchZ('ua-spoof', pageStore.pageHostname) ) {
|
2015-04-20 08:19:14 +12:00
|
|
|
details.requestHeaders.setHeader('user-agent', µm.userAgentReplaceStr);
|
2014-10-18 08:01:09 +13:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var foilRefererHeaders = function(µm, toHostname, details) {
|
2015-04-20 08:19:14 +12:00
|
|
|
var referer = details.requestHeaders.getHeader('referer');
|
|
|
|
if ( referer === '' ) {
|
|
|
|
return;
|
2014-11-20 14:17:24 +13:00
|
|
|
}
|
|
|
|
var µmuri = µm.URI;
|
2015-04-20 08:19:14 +12:00
|
|
|
if ( µmuri.domainFromHostname(toHostname) === µmuri.domainFromURI(referer) ) {
|
|
|
|
return;
|
2014-11-20 14:17:24 +13:00
|
|
|
}
|
|
|
|
//console.debug('foilRefererHeaders()> foiled referer for "%s"', details.url);
|
|
|
|
//console.debug('\treferrer "%s"', header.value);
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/222#issuecomment-44828402
|
2015-04-20 08:19:14 +12:00
|
|
|
details.requestHeaders.setHeader(
|
|
|
|
'referer',
|
|
|
|
µmuri.schemeFromURI(details.url) + '://' + toHostname + '/'
|
|
|
|
);
|
2014-11-20 14:17:24 +13:00
|
|
|
µm.refererHeaderFoiledCounter++;
|
2014-10-18 08:01:09 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// To prevent inline javascript from being executed.
|
|
|
|
|
|
|
|
// Prevent inline scripting using `Content-Security-Policy`:
|
|
|
|
// https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html
|
|
|
|
|
|
|
|
// This fixes:
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/35
|
|
|
|
|
|
|
|
var onHeadersReceived = function(details) {
|
|
|
|
// console.debug('onHeadersReceived()> "%s": %o', details.url, details);
|
|
|
|
|
|
|
|
// Ignore schemes other than 'http...'
|
2015-04-22 08:22:29 +12:00
|
|
|
if ( details.url.lastIndexOf('http', 0) !== 0 ) {
|
2014-10-18 08:01:09 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-20 08:19:14 +12:00
|
|
|
var requestType = requestTypeNormalizer[details.type] || 'other';
|
2014-10-18 08:01:09 +13:00
|
|
|
if ( requestType === 'frame' ) {
|
|
|
|
return onSubDocHeadersReceived(details);
|
|
|
|
}
|
|
|
|
if ( requestType === 'doc' ) {
|
|
|
|
return onMainDocHeadersReceived(details);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMainDocHeadersReceived = function(details) {
|
2015-04-22 11:47:19 +12:00
|
|
|
var µm = µMatrix;
|
2015-05-05 02:50:44 +12:00
|
|
|
var tabId = details.tabId;
|
|
|
|
var requestURL = details.url;
|
2015-04-22 11:47:19 +12:00
|
|
|
|
2015-04-22 08:22:29 +12:00
|
|
|
// https://github.com/gorhill/uMatrix/issues/145
|
|
|
|
// Check if the main_frame is a download
|
2015-05-05 02:50:44 +12:00
|
|
|
if ( headerValue(details.responseHeaders, 'content-type').lastIndexOf('application/x-', 0) === 0 ) {
|
|
|
|
µm.tabContextManager.unpush(tabId, requestURL);
|
|
|
|
} else {
|
|
|
|
µm.tabContextManager.push(tabId, requestURL);
|
2015-04-22 11:47:19 +12:00
|
|
|
}
|
2015-05-05 02:50:44 +12:00
|
|
|
|
|
|
|
var tabContext = µm.tabContextManager.lookup(tabId);
|
2015-04-22 11:47:19 +12:00
|
|
|
if ( tabContext === null ) {
|
|
|
|
return;
|
2015-04-22 08:22:29 +12:00
|
|
|
}
|
2014-10-18 08:01:09 +13:00
|
|
|
|
2015-05-05 02:50:44 +12:00
|
|
|
// console.debug('onMainDocHeadersReceived()> "%s": %o', requestURL, details);
|
2014-11-19 06:04:40 +13:00
|
|
|
|
2015-05-05 02:50:44 +12:00
|
|
|
var blockScript = µm.mustBlock(tabContext.rootHostname, tabContext.rootHostname, 'script');
|
2014-10-18 08:01:09 +13:00
|
|
|
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/181
|
2015-05-05 02:50:44 +12:00
|
|
|
var pageStore = µm.pageStoreFromTabId(tabId);
|
|
|
|
if ( pageStore ) {
|
|
|
|
pageStore.pageScriptBlocked = blockScript;
|
2014-11-19 06:04:40 +13:00
|
|
|
}
|
2014-10-18 08:01:09 +13:00
|
|
|
|
2015-05-05 02:50:44 +12:00
|
|
|
if ( !blockScript ) {
|
|
|
|
return;
|
2014-11-19 06:04:40 +13:00
|
|
|
}
|
2015-05-05 02:50:44 +12:00
|
|
|
|
|
|
|
µm.logger.writeOne(tabId, 'net', '---', 'inline-script', requestURL);
|
|
|
|
|
|
|
|
// If javascript not allowed, say so through a `Content-Security-Policy` directive.
|
|
|
|
details.responseHeaders.push({
|
|
|
|
'name': 'Content-Security-Policy',
|
|
|
|
'value': "script-src 'none'"
|
|
|
|
});
|
|
|
|
return { responseHeaders: details.responseHeaders };
|
2014-10-18 08:01:09 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onSubDocHeadersReceived = function(details) {
|
2015-05-05 02:50:44 +12:00
|
|
|
var µm = µMatrix;
|
|
|
|
var tabId = details.tabId;
|
2014-10-18 08:01:09 +13:00
|
|
|
|
|
|
|
// console.debug('onSubDocHeadersReceived()> "%s": %o', details.url, details);
|
|
|
|
|
|
|
|
// Do not ignore traffic outside tabs.
|
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/91#issuecomment-37180275
|
2015-04-22 08:22:29 +12:00
|
|
|
var tabContext = µm.tabContextManager.lookup(tabId);
|
|
|
|
if ( tabContext === null ) {
|
|
|
|
return;
|
2014-10-18 08:01:09 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluate
|
2015-05-05 02:50:44 +12:00
|
|
|
if ( µm.mustAllow(tabContext.rootHostname, details.hostname, 'script') ) {
|
2014-10-18 08:01:09 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If javascript not allowed, say so through a `Content-Security-Policy`
|
|
|
|
// directive.
|
|
|
|
|
|
|
|
// For inline javascript within iframes, we need to sandbox.
|
2014-11-01 02:32:24 +13:00
|
|
|
|
2014-10-18 08:01:09 +13:00
|
|
|
// https://github.com/gorhill/httpswitchboard/issues/73
|
|
|
|
// Now because sandbox cancels all permissions, this means
|
|
|
|
// not just javascript is disabled. To avoid negative side
|
|
|
|
// effects, I allow some other permissions, but...
|
2014-11-01 02:32:24 +13:00
|
|
|
|
|
|
|
// https://github.com/gorhill/uMatrix/issues/27
|
|
|
|
// Need to add `allow-popups` to prevent completely breaking links on
|
|
|
|
// some sites old style sites.
|
|
|
|
|
2014-10-18 08:01:09 +13:00
|
|
|
// TODO: Reuse CSP `sandbox` directive if it's already in the
|
|
|
|
// headers (strip out `allow-scripts` if present),
|
|
|
|
// and find out if the `sandbox` in the header interfere with a
|
|
|
|
// `sandbox` attribute which might be present on the iframe.
|
2014-11-01 02:32:24 +13:00
|
|
|
|
2014-10-18 08:01:09 +13:00
|
|
|
// console.debug('onSubDocHeadersReceived()> FRAME CSP "%s": %o, scope="%s"', details.url, details, pageURL);
|
2014-11-01 02:32:24 +13:00
|
|
|
|
2015-05-05 02:50:44 +12:00
|
|
|
µm.logger.writeOne(tabId, 'net', '---', 'inline-script', details.url);
|
|
|
|
|
|
|
|
// If javascript not allowed, say so through a `Content-Security-Policy` directive.
|
2014-10-18 08:01:09 +13:00
|
|
|
details.responseHeaders.push({
|
|
|
|
'name': 'Content-Security-Policy',
|
2015-04-22 08:22:29 +12:00
|
|
|
'value': "script-src 'none'"
|
2014-10-18 08:01:09 +13:00
|
|
|
});
|
|
|
|
|
|
|
|
return { responseHeaders: details.responseHeaders };
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-04-22 08:22:29 +12:00
|
|
|
var headerValue = function(headers, name) {
|
|
|
|
var i = headers.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
if ( headers[i].name.toLowerCase() === name ) {
|
|
|
|
return headers[i].value.trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-10-18 08:01:09 +13:00
|
|
|
// Caller must ensure headerName is normalized to lower case.
|
|
|
|
|
|
|
|
var headerIndexFromName = function(headerName, headers) {
|
|
|
|
var i = headers.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
if ( headers[i].name.toLowerCase() === headerName ) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var requestTypeNormalizer = {
|
2015-04-20 08:30:28 +12:00
|
|
|
'font' : 'css',
|
2014-10-18 08:01:09 +13:00
|
|
|
'image' : 'image',
|
2015-04-20 08:30:28 +12:00
|
|
|
'main_frame' : 'doc',
|
2014-10-18 08:01:09 +13:00
|
|
|
'object' : 'plugin',
|
2015-04-20 08:19:14 +12:00
|
|
|
'other' : 'other',
|
2015-04-20 08:30:28 +12:00
|
|
|
'ping' : 'ping',
|
|
|
|
'script' : 'script',
|
|
|
|
'stylesheet' : 'css',
|
|
|
|
'sub_frame' : 'frame',
|
|
|
|
'xmlhttprequest': 'xhr'
|
2014-10-18 08:01:09 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-04-12 09:15:57 +12:00
|
|
|
vAPI.net.onBeforeRequest = {
|
|
|
|
urls: [
|
|
|
|
"http://*/*",
|
2015-05-03 05:30:29 +12:00
|
|
|
"https://*/*"
|
2015-04-12 09:15:57 +12:00
|
|
|
],
|
|
|
|
extra: [ 'blocking' ],
|
|
|
|
callback: onBeforeRequestHandler
|
|
|
|
};
|
2014-10-26 16:30:43 +13:00
|
|
|
|
2015-04-12 09:15:57 +12:00
|
|
|
vAPI.net.onBeforeSendHeaders = {
|
|
|
|
urls: [
|
|
|
|
"http://*/*",
|
|
|
|
"https://*/*"
|
|
|
|
],
|
|
|
|
extra: [ 'blocking', 'requestHeaders' ],
|
|
|
|
callback: onBeforeSendHeadersHandler
|
|
|
|
};
|
2014-10-26 16:30:43 +13:00
|
|
|
|
2015-04-12 09:15:57 +12:00
|
|
|
vAPI.net.onHeadersReceived = {
|
|
|
|
urls: [
|
|
|
|
"http://*/*",
|
|
|
|
"https://*/*"
|
|
|
|
],
|
|
|
|
types: [
|
|
|
|
"main_frame",
|
|
|
|
"sub_frame"
|
|
|
|
],
|
|
|
|
extra: [ 'blocking', 'responseHeaders' ],
|
|
|
|
callback: onHeadersReceived
|
|
|
|
};
|
2014-10-26 16:30:43 +13:00
|
|
|
|
2015-04-12 09:15:57 +12:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var start = function() {
|
|
|
|
vAPI.net.registerListeners();
|
2014-10-26 16:30:43 +13:00
|
|
|
};
|
2014-10-18 08:01:09 +13:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
return {
|
2014-10-26 16:30:43 +13:00
|
|
|
start: start
|
2014-10-18 08:01:09 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|