diff --git a/platform/firefox/bootstrap.js b/platform/firefox/bootstrap.js index 3e74b5a..6704d54 100644 --- a/platform/firefox/bootstrap.js +++ b/platform/firefox/bootstrap.js @@ -19,7 +19,7 @@ Home: https://github.com/gorhill/uMatrix */ -/* global APP_SHUTDOWN, APP_STARTUP */ +/* global ADDON_UNINSTALL, APP_SHUTDOWN, APP_STARTUP */ /* exported startup, shutdown, install, uninstall */ 'use strict'; @@ -141,6 +141,16 @@ function install() { /******************************************************************************/ -function uninstall() {} +function uninstall(data, aReason) { + if ( aReason !== ADDON_UNINSTALL ) { + return; + } + // To cleanup vAPI.localStorage in vapi-common.js, aka + // "extensions.umatrix.*" in `about:config`. + Components.utils.import('resource://gre/modules/Services.jsm', null) + .Services.prefs + .getBranch('extensions.' + hostName + '.') + .deleteBranch(''); +} /******************************************************************************/ diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index a8dfcd8..4c2a88b 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -110,6 +110,8 @@ window.addEventListener('unload', function() { /******************************************************************************/ var SQLite = { + db: null, + open: function() { var path = Services.dirsvc.get('ProfD', Ci.nsIFile); path.append('extension-data'); diff --git a/src/js/background.js b/src/js/background.js index 7ffdc87..13ec531 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -35,16 +35,18 @@ var oneDay = 24 * oneHour; /******************************************************************************/ var defaultUserAgentStrings = [ - '# http://www.useragentstring.com/pages/Chrome/', '# http://techblog.willshouse.com/2012/01/03/most-common-user-agents/', - 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25', - 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36', - 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36' -].join('\n'); + '# using ua string which are same browser as real one may work better overall', + 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36', + 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/600.5.17 (KHTML, like Gecko) Version/8.0.5 Safari/600.5.17', + 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36', + 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36', + 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36', + 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0', + '' +].join('\n').trim(); /******************************************************************************/ @@ -63,17 +65,13 @@ return { externalHostsFiles: '', iconBadgeEnabled: false, maxLoggedRequests: 1000, - popupCollapseDomains: false, - popupCollapseSpecificDomains: {}, - popupHideBlacklisted: false, popupScopeLevel: 'domain', processBehindTheSceneRequests: false, processHyperlinkAuditing: true, processReferer: false, spoofUserAgent: false, spoofUserAgentEvery: 5, - spoofUserAgentWith: defaultUserAgentStrings, - statsFilters: {} + spoofUserAgentWith: defaultUserAgentStrings }, clearBrowserCacheCycle: 0, @@ -114,14 +112,9 @@ return { userAgentReplaceStr: '', userAgentReplaceStrBirth: 0, - // record what chromium is doing behind the scene - behindTheSceneURL: 'http://behind-the-scene/', - behindTheSceneMaxReq: 250, + // record what the browser is doing behind the scene behindTheSceneScope: 'behind-the-scene', - // Commonly encountered strings - fontCSSURL: vAPI.getURL('css/fonts/Roboto_Condensed/RobotoCondensed-Regular.ttf'), - noopFunc: function(){}, // so that I don't have to care for last comma diff --git a/src/js/cookies.js b/src/js/cookies.js index 2367d4b..0fc595a 100644 --- a/src/js/cookies.js +++ b/src/js/cookies.js @@ -292,21 +292,18 @@ var chromeCookieRemove = function(url, name) { var persistCookieKey = cookieKeyFromCookieURL(url, 'persistent', name); var callback = function(details) { var success = !!details; + var template = success ? i18nCookieDeleteSuccess : i18nCookieDeleteFailure; if ( removeCookieFromDict(sessionCookieKey) ) { if ( success ) { - µm.logger.writeOne('', 'info', i18nCookieDeleteSuccess.replace('{{value}}', sessionCookieKey)); µm.cookieRemovedCounter += 1; - } else { - µm.logger.writeOne('', 'error', i18nCookieDeleteFailure.replace('{{value}}', sessionCookieKey)); } + µm.logger.writeOne('', 'info', 'cookie', template.replace('{{value}}', sessionCookieKey)); } if ( removeCookieFromDict(persistCookieKey) ) { if ( success ) { - µm.logger.writeOne('', 'info', i18nCookieDeleteSuccess.replace('{{value}}', persistCookieKey)); µm.cookieRemovedCounter += 1; - } else { - µm.logger.writeOne('', 'error', i18nCookieDeleteFailure.replace('{{value}}', persistCookieKey)); } + µm.logger.writeOne('', 'info', 'cookie', template.replace('{{value}}', persistCookieKey)); } }; diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js index e4385b0..584655d 100644 --- a/src/js/logger-ui.js +++ b/src/js/logger-ui.js @@ -71,9 +71,37 @@ var reEscapeRightBracket = />/g; /******************************************************************************/ -// Emphasize hostname in URL, as this is what matters in uMatrix's rules. +// Emphasize hostname and cookie name. -var nodeFromURL = function(url) { +var emphasizeCookie = function(s) { + var pnode = emphasizeHostname(s); + if ( pnode.childNodes.length !== 3 ) { + return pnode; + } + var prefix = '-cookie:'; + var text = pnode.childNodes[2].textContent; + var beg = text.indexOf(prefix); + if ( beg === -1 ) { + return pnode; + } + beg += prefix.length; + var end = text.indexOf('}', beg); + if ( end === -1 ) { + return pnode; + } + var cnode = emphasizeTemplate.cloneNode(true); + cnode.childNodes[0].textContent = text.slice(0, beg); + cnode.childNodes[1].textContent = text.slice(beg, end); + cnode.childNodes[2].textContent = text.slice(end); + pnode.replaceChild(cnode, pnode.childNodes[2]); + return pnode; +}; + +/******************************************************************************/ + +// Emphasize hostname in URL. + +var emphasizeHostname = function(url) { var hnbeg = url.indexOf('://'); if ( hnbeg === -1 ) { return document.createTextNode(url); @@ -90,14 +118,14 @@ var nodeFromURL = function(url) { } } - var node = renderedURLTemplate.cloneNode(true); + var node = emphasizeTemplate.cloneNode(true); node.childNodes[0].textContent = url.slice(0, hnbeg); node.childNodes[1].textContent = url.slice(hnbeg, hnend); node.childNodes[2].textContent = url.slice(hnend); return node; }; -var renderedURLTemplate = document.querySelector('#renderedURLTemplate > span'); +var emphasizeTemplate = document.querySelector('#emphasizeTemplate > span'); /******************************************************************************/ @@ -180,7 +208,11 @@ var renderLogEntry = function(entry) { case 'error': case 'info': tr = createRow('1'); - tr.cells[fvdc].textContent = entry.d0; + if ( entry.d0 === 'cookie' ) { + tr.cells[fvdc].appendChild(emphasizeCookie(entry.d1)); + } else { + tr.cells[fvdc].textContent = entry.d0; + } break; case 'net': @@ -198,7 +230,7 @@ var renderLogEntry = function(entry) { tr.cells[fvdc].textContent = ''; } tr.cells[fvdc+1].textContent = (prettyRequestTypes[entry.d2] || entry.d2); - tr.cells[fvdc+2].appendChild(nodeFromURL(entry.d1)); + tr.cells[fvdc+2].appendChild(emphasizeHostname(entry.d1)); break; default: diff --git a/src/js/messaging.js b/src/js/messaging.js index ceb67bc..1ea5d51 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -164,9 +164,6 @@ var matrixSnapshot = function(pageStore, details) { userSettings: { colorBlindFriendly: µmuser.colorBlindFriendly, displayTextSize: µmuser.displayTextSize, - popupCollapseDomains: µmuser.popupCollapseDomains, - popupCollapseSpecificDomains: µmuser.popupCollapseSpecificDomains, - popupHideBlacklisted: µmuser.popupHideBlacklisted, popupScopeLevel: µmuser.popupScopeLevel } }; diff --git a/src/js/popup.js b/src/js/popup.js index db3eb24..5293f5e 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -87,6 +87,23 @@ function setUserSetting(setting, value) { /******************************************************************************/ +function getUISetting(setting) { + var r = vAPI.localStorage.getItem(setting); + if ( typeof r !== 'string' ) { + return undefined; + } + return JSON.parse(r); +} + +function setUISetting(setting, value) { + vAPI.localStorage.setItem( + setting, + JSON.stringify(value) + ); +} + +/******************************************************************************/ + function updateMatrixSnapshot() { matrixSnapshotPoller.pollNow(); } @@ -258,11 +275,11 @@ function getCellClass(hostname, type) { // want to lose all his hardwork. function getCollapseState(domain) { - var states = getUserSetting('popupCollapseSpecificDomains'); - if ( states !== undefined && states[domain] !== undefined ) { + var states = getUISetting('popupCollapseSpecificDomains'); + if ( typeof states === 'object' && states[domain] !== undefined ) { return states[domain]; } - return getUserSetting('popupCollapseDomains'); + return getUISetting('popupCollapseDomains'); } function toggleCollapseState(elem) { @@ -277,9 +294,9 @@ function toggleMainCollapseState(uelem) { var matHead = uelem.ancestors('#matHead.collapsible').toggleClass('collapsed'); var collapsed = matHead.hasClass('collapsed'); uDom('#matList .matSection.collapsible').toggleClass('collapsed', collapsed); - setUserSetting('popupCollapseDomains', collapsed); + setUISetting('popupCollapseDomains', collapsed); - var specificCollapseStates = getUserSetting('popupCollapseSpecificDomains') || {}; + var specificCollapseStates = getUISetting('popupCollapseSpecificDomains') || {}; var domains = Object.keys(specificCollapseStates); var i = domains.length; var domain; @@ -289,7 +306,7 @@ function toggleMainCollapseState(uelem) { delete specificCollapseStates[domain]; } } - setUserSetting('popupCollapseSpecificDomains', specificCollapseStates); + setUISetting('popupCollapseSpecificDomains', specificCollapseStates); } function toggleSpecificCollapseState(uelem) { @@ -298,14 +315,14 @@ function toggleSpecificCollapseState(uelem) { var section = uelem.ancestors('.matSection.collapsible').toggleClass('collapsed'); var domain = section.prop('domain'); var collapsed = section.hasClass('collapsed'); - var mainCollapseState = getUserSetting('popupCollapseDomains'); - var specificCollapseStates = getUserSetting('popupCollapseSpecificDomains') || {}; + var mainCollapseState = getUISetting('popupCollapseDomains'); + var specificCollapseStates = getUISetting('popupCollapseSpecificDomains') || {}; if ( collapsed !== mainCollapseState ) { specificCollapseStates[domain] = collapsed; - setUserSetting('popupCollapseSpecificDomains', specificCollapseStates); + setUISetting('popupCollapseSpecificDomains', specificCollapseStates); } else if ( specificCollapseStates[domain] !== undefined ) { delete specificCollapseStates[domain]; - setUserSetting('popupCollapseSpecificDomains', specificCollapseStates); + setUISetting('popupCollapseSpecificDomains', specificCollapseStates); } } @@ -495,7 +512,7 @@ var createMatrixRow = function() { function renderMatrixHeaderRow() { var matHead = uDom('#matHead.collapsible'); - matHead.toggleClass('collapsed', getUserSetting('popupCollapseDomains')); + matHead.toggleClass('collapsed', getUISetting('popupCollapseDomains')); var cells = matHead.descendants('.matCell'); cells.at(0) .prop('reqType', '*') @@ -902,7 +919,7 @@ function makeMatrixGroup4(group) { var groupDiv = createMatrixGroup().addClass('g4'); createMatrixSection() .addClass('g4Meta') - .toggleClass('g4Collapsed', !!getUserSetting('popupHideBlacklisted')) + .toggleClass('g4Collapsed', !!getUISetting('popupHideBlacklisted')) .appendTo(groupDiv); makeMatrixMetaRow(computeMatrixGroupMetaStats(group), 'g4') .appendTo(groupDiv); @@ -1332,7 +1349,7 @@ uDom('#matList').on('click', '.g4Meta', function() { var collapsed = uDom(this) .toggleClass('g4Collapsed') .hasClass('g4Collapsed'); - setUserSetting('popupHideBlacklisted', collapsed); + setUISetting('popupHideBlacklisted', collapsed); }); /******************************************************************************/ diff --git a/src/js/start.js b/src/js/start.js index da9f610..16d3468 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -131,6 +131,15 @@ var onHostsFilesLoaded = function() { }; var onUserSettingsLoaded = function() { + // Version 0.9.0.0 + // Remove obsolete user settings which may have been loaded. + // These are now stored as local settings: + delete µm.userSettings.popupCollapseDomains; + delete µm.userSettings.popupCollapseSpecificDomains; + delete µm.userSettings.popupHideBlacklisted; + // These do not exist anymore: + delete µm.userSettings.statsFilters; + µm.loadHostsFiles(onHostsFilesLoaded); }; diff --git a/src/js/tab.js b/src/js/tab.js index 59481f2..1e80d85 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -47,7 +47,7 @@ var µm = µMatrix; µm.normalizePageURL = function(tabId, pageURL) { if ( vAPI.isBehindTheSceneTabId(tabId) ) { - return 'http://behind-the-scene/'; + return 'http://' + this.behindTheSceneScope + '/'; } // If the URL is that of our "blocked page" document, return the URL of diff --git a/src/js/user-rules.js b/src/js/user-rules.js index 1f700f2..53ea13a 100644 --- a/src/js/user-rules.js +++ b/src/js/user-rules.js @@ -236,7 +236,6 @@ uDom.onLoad(function() { uDom('#importButton').on('click', startImportFilePicker); uDom('#importFilePicker').on('change', handleImportFilePicker); uDom('#exportButton').on('click', exportUserRulesToFile); - uDom('#revertButton').on('click', revertHandler); uDom('#commitButton').on('click', commitHandler); uDom('#editEnterButton').on('click', editStartHandler); diff --git a/src/logger-ui.html b/src/logger-ui.html index 0c18bde..87241dd 100644 --- a/src/logger-ui.html +++ b/src/logger-ui.html @@ -29,7 +29,7 @@
-
+