Browse Source

minor code review

pull/2/head
gorhill 7 years ago
parent
commit
ff5789d4ac
No known key found for this signature in database GPG Key ID: 25E1490B761470C2
  1. 9
      src/js/contentscript.js
  2. 8
      src/js/messaging.js

9
src/js/contentscript.js

@ -67,7 +67,6 @@ vAPI.contentscriptEndInjected = true;
if ( mustRemove ) {
window.localStorage.clear();
window.sessionStorage.clear();
// console.debug('HTTP Switchboard > found and removed non-empty localStorage');
}
};
@ -76,12 +75,14 @@ vAPI.contentscriptEndInjected = true;
// to site data is disabled.
// https://github.com/gorhill/httpswitchboard/issues/215
try {
var hasLocalStorage = window.localStorage && window.localStorage.length;
var hasSessionStorage = window.sessionStorage && window.sessionStorage.length;
var hasLocalStorage =
window.localStorage && window.localStorage.length !== 0;
var hasSessionStorage =
window.sessionStorage && window.sessionStorage.length !== 0;
if ( hasLocalStorage || hasSessionStorage ) {
vAPI.messaging.send('contentscript.js', {
what: 'contentScriptHasLocalStorage',
url: window.location.href
originURL: window.location.origin
}, localStorageHandler);
}

8
src/js/messaging.js

@ -426,19 +426,19 @@ var contentScriptSummaryHandler = function(tabId, details) {
/******************************************************************************/
var contentScriptLocalStorageHandler = function(tabId, pageURL) {
var contentScriptLocalStorageHandler = function(tabId, originURL) {
var tabContext = µm.tabContextManager.lookup(tabId);
if ( tabContext === null ) { return; }
var blocked = µm.mustBlock(
tabContext.rootHostname,
µm.URI.hostnameFromURI(pageURL),
µm.URI.hostnameFromURI(originURL),
'cookie'
);
var pageStore = µm.pageStoreFromTabId(tabId);
if ( pageStore !== null ) {
var requestURL = µm.URI.originFromURI(pageURL) + '/{localStorage}';
var requestURL = originURL + '/{localStorage}';
pageStore.recordRequest('cookie', requestURL, blocked);
µm.logger.writeOne(tabId, 'net', tabContext.rootHostname, requestURL, 'cookie', blocked);
}
@ -520,7 +520,7 @@ var onMessage = function(request, sender, callback) {
switch ( request.what ) {
case 'contentScriptHasLocalStorage':
response = contentScriptLocalStorageHandler(tabId, request.url);
response = contentScriptLocalStorageHandler(tabId, request.originURL);
break;
case 'contentScriptSummary':

Loading…
Cancel
Save