Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
changes for v0.8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Feb 10, 2014
1 parent 6d1072f commit 8db73a1
Show file tree
Hide file tree
Showing 16 changed files with 689 additions and 380 deletions.
362 changes: 241 additions & 121 deletions assets/httpsb/preset-recipes-1st.yaml

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion assets/httpsb/preset-recipes-3rd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ Brightcove:
plugin brightcove.com
script brightcove.com
Daily Motion:
facode: f008
keys: www.dailymotion.com
whitelist: |
plugin www.dailymotion.com
script www.dailymotion.com
frame www.dailymotion.com
plugin dmcdn.net
script dmcdn.net
script ajax.googleapis.com
Disqus:
facode: f086
keys: disqus.com
Expand All @@ -60,7 +71,9 @@ Disqus:
Facebook:
facode: f09a
keys: facebook.com
keys: |
facebook.com
connect.facebook.net
whitelist: |
script facebook.com
xhr facebook.com
Expand Down Expand Up @@ -95,6 +108,15 @@ Livefyre:
script fyre.co
xhr fyre.co
Ooyala player:
facode: f008
keys: player.ooyala.com
whitelist: |
plugin player.ooyala.com
script player.ooyala.com
xhr player.ooyala.com
plugin opf.ooyala.com
Pinterest:
facode: f0d2
keys: pinterest.com
Expand Down
10 changes: 5 additions & 5 deletions css/rulemanager.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ h1:first-child {
}
#navi-bar {
border-bottom: 1px solid #ccc;
padding: 1em;
padding: 0.5em;
position: fixed;
background-color: white;
width: 100%;
height: 8em;
height: 7em;
z-index: 100;
}
#navi-bar + div {
padding: 10em 1em 1em 1em;
padding: 8em 0.5em 1em 0.5em;
}
h2 {
margin: 0.5em 0;
Expand Down Expand Up @@ -48,15 +48,15 @@ button {
margin: 0.5em 1em 0 0;
border: 1px solid rgba(0,0,0,0.2);
border-radius: 5px;
padding: 0.5em 1em;
padding: 0.25em 0.75em;
font: inherit;
font-size: 110%;
background-color: #eee;
cursor: pointer;
}
button .fa {
margin-right: 0.5em;
font-size: larger;
font-size: large;
}

#recipeDecode, #recipeImport, #recipeEncode, #recipeExport {
Expand Down
9 changes: 5 additions & 4 deletions js/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ setInterval(asyncJobQueueHandler, asyncJobQueue.resolution);
// A time out is used to coalesce adjacents requests to update badge.

function updateBadgeCallback(pageUrl) {
if ( pageUrl === HTTPSB.behindTheSceneURL ) {
var httpsb = HTTPSB;
if ( pageUrl === httpsb.behindTheSceneURL ) {
return;
}
var tabId = tabIdFromPageUrl(pageUrl);
var tabId = httpsb.tabIdFromPageUrl(pageUrl);
if ( !tabId ) {
return;
}
var pageStats = pageStatsFromTabId(tabId);
var pageStats = httpsb.pageStatsFromTabId(tabId);
if ( pageStats ) {
pageStats.updateBadge(tabId);
} else {
Expand Down Expand Up @@ -228,7 +229,7 @@ function onMessageHandler(request, sender, callback) {
break;

case 'forceReloadTab':
forceReload(request.pageURL);
HTTPSB.forceReload(request.pageURL);
break;

case 'checkScriptBlacklisted':
Expand Down
13 changes: 9 additions & 4 deletions js/contentscripthandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function contentScriptSummaryHandler(details, sender) {
}
var ut = uriTools;
var httpsb = HTTPSB;
var pageURL = pageUrlFromTabId(sender.tab.id);
var pageURL = httpsb.pageUrlFromTabId(sender.tab.id);
var frameURL = ut.normalizeURI(details.locationURL);
var pageHostname = ut.hostname();
var urls, url, hostname, block;
Expand Down Expand Up @@ -58,7 +58,7 @@ function contentScriptSummaryHandler(details, sender) {
hostname = pageHostname;
}
block = httpsb.blacklisted(pageURL, 'script', hostname);
recordFromPageUrl(pageURL, 'script', url, block);
httpsb.recordFromPageUrl(pageURL, 'script', url, block);
}

// plugins
Expand All @@ -74,7 +74,7 @@ function contentScriptSummaryHandler(details, sender) {
hostname = pageHostname;
}
block = httpsb.blacklisted(pageURL, 'object', hostname);
recordFromPageUrl(pageURL, 'object', url, block);
httpsb.recordFromPageUrl(pageURL, 'object', url, block);
}
}

Expand All @@ -83,7 +83,12 @@ function contentScriptSummaryHandler(details, sender) {
function contentScriptLocalStorageHandler(pageURL) {
var httpsb = HTTPSB;
var response = httpsb.blacklisted(pageURL, 'cookie', uriTools.hostnameFromURI(pageURL));
recordFromPageUrl(pageURL, 'cookie', uriTools.rootURLFromURI(pageURL) + '/{localStorage}', response);
httpsb.recordFromPageUrl(
pageURL,
'cookie',
uriTools.rootURLFromURI(pageURL) + '/{localStorage}',
response
);
response = response && httpsb.userSettings.deleteLocalStorage;
if ( response ) {
httpsb.localStorageRemovedCounter++;
Expand Down
2 changes: 1 addition & 1 deletion js/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function contextMenuClickHandler(info, tab) {
switch ( info.menuItemId ) {
case 'gdt-group0':
HTTPSB.whitelistTemporarily(pageURL, '*', pageDomain);
smartReloadTab(tab.id);
HTTPSB.smartReloadTab(tab.id);
break;

case 'revertScopeRules':
Expand Down
4 changes: 2 additions & 2 deletions js/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var cookieHunter = {
if ( !pageStats ) {
return;
}
var pageURL = pageUrlFromPageStats(pageStats);
var pageURL = HTTPSB.pageUrlFromPageStats(pageStats);
this.queuePageRecord[pageURL] = pageStats;
asyncJobQueue.add(
'cookieHunterPageRecord',
Expand Down Expand Up @@ -182,7 +182,7 @@ var cookieHunter = {
if ( !pageStats ) {
return;
}
var pageURL = pageUrlFromPageStats(pageStats);
var pageURL = HTTPSB.pageUrlFromPageStats(pageStats);
this.queuePageRemove[pageURL] = pageStats;
asyncJobQueue.add(
'cookieHunterPageRemove',
Expand Down
94 changes: 81 additions & 13 deletions js/httpsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ HTTPSB.domainScopeKeyFromURL = function(url) {
if ( scheme.indexOf('http') !== 0 ) {
return '';
}
var hostname = ut.hostname();
var domain = ut.domainFromHostname(hostname);
return this.domainScopeKeyFromHostname(ut.hostname());
};

HTTPSB.domainScopeKeyFromHostname = function(hostname) {
var domain = uriTools.domainFromHostname(hostname);
if ( domain === '' ) {
domain = hostname;
}
Expand All @@ -58,6 +61,10 @@ HTTPSB.siteScopeKeyFromURL = function(url) {
return uriTools.hostnameFromURI(url);
};

HTTPSB.siteScopeKeyFromHostname = function(hostname) {
return hostname;
};

/******************************************************************************/

HTTPSB.isGlobalScopeKey = function(scopeKey) {
Expand Down Expand Up @@ -98,6 +105,12 @@ HTTPSB.permanentScopeFromScopeKey = function(scopeKey) {

/******************************************************************************/

HTTPSB.temporaryScopeExists = function(scopeKey) {
return !!this.temporaryScopeFromScopeKey(scopeKey);
};

/******************************************************************************/

// Of course this doesn't make sense as there is always a global scope, but
// what makes sense is that we need to remove site and domain scopes for
// global scope to take effect.
Expand Down Expand Up @@ -136,7 +149,7 @@ HTTPSB.createTemporaryDomainScope = function(url) {
scope = new PermissionScope();
scope.whitelist('main_frame', '*');
this.temporaryScopes.scopes[scopeKey] = scope;
this.copyRulesTemporarily(scopeKey, this.globalScopeKey(), url);
this.copyTemporaryRules(scopeKey, this.globalScopeKey(), url);
} else if ( scope.off ) {
scope.off = false;
}
Expand Down Expand Up @@ -179,8 +192,8 @@ HTTPSB.createTemporarySiteScope = function(url) {
scope = new PermissionScope();
scope.whitelist('main_frame', '*');
this.temporaryScopes.scopes[scopeKey] = scope;
this.copyRulesTemporarily(scopeKey, this.globalScopeKey(), url);
this.copyRulesTemporarily(scopeKey, this.domainScopeKeyFromURL(url), url);
this.copyTemporaryRules(scopeKey, this.globalScopeKey(), url);
this.copyTemporaryRules(scopeKey, this.domainScopeKeyFromURL(url), url);
} else {
scope.off = false;
}
Expand Down Expand Up @@ -247,6 +260,36 @@ HTTPSB.removePermanentScopeFromScopeKey = function(scopeKey, persist) {

/******************************************************************************/

HTTPSB.revealTemporaryDomainScope = function(domainScopeKey) {
if ( !this.isDomainScopeKey(domainScopeKey) ) {
return;
}
// Remove '*' prefix
var keySuffix = domainScopeKey.slice(1);
var keySuffixLen = keySuffix.length;
var scopes = this.temporaryScopes.scopes;
var pos;
for ( var scopeKey in scopes ) {
if ( !scopes.hasOwnProperty(scopeKey) ) {
continue;
}
if ( scopeKey === domainScopeKey ) {
continue;
}
pos = scopeKey.lastIndexOf(keySuffix);
if ( pos < 0 ) {
continue;
}
if ( pos !== scopeKey.length - keySuffixLen ) {
continue;
}
// Turn off scope
scopes[scopeKey].off = true;
}
};

/******************************************************************************/

HTTPSB.temporaryScopeKeyFromPageURL = function(url) {
return this.temporaryScopes.scopeKeyFromPageURL(url);
};
Expand Down Expand Up @@ -342,14 +385,20 @@ HTTPSB.autoCreateTemporarySiteScope = function(pageURL) {
// Copy rules from another scope. If a pageURL is provided,
// it will be used to filter the rules according to the hostname.

HTTPSB.copyRulesTemporarily = function(toScopeKey, fromScopeKey, pageURL) {
var toScope = this.temporaryScopes.scopes[toScopeKey];
var fromScope = this.temporaryScopes.scopes[fromScopeKey];
HTTPSB.copyTemporaryRules = function(toScopeKey, fromScopeKey, pageURL) {
this.copyTemporaryWhiteRules(toScopeKey, fromScopeKey, pageURL);
this.copyTemporaryGrayRules(toScopeKey, fromScopeKey);
this.copyTemporaryBlackRules(toScopeKey, fromScopeKey);
};

HTTPSB.copyTemporaryWhiteRules = function(toScopeKey, fromScopeKey, pageURL) {
var toScope = this.temporaryScopeFromScopeKey(toScopeKey);
var fromScope = this.temporaryScopeFromScopeKey(fromScopeKey);
if ( !toScope || !fromScope ) {
return;
}
var ut = uriTools;
var pageStats = pageStatsFromPageUrl(pageURL);
var pageStats = this.pageStatsFromPageUrl(pageURL);
var hostnames = pageStats ? pageStats.domains : {};
var domains = {};
for ( var hostname in hostnames ) {
Expand All @@ -371,10 +420,26 @@ HTTPSB.copyRulesTemporarily = function(toScopeKey, fromScopeKey, pageURL) {
}
toScope.white.addOne(ruleKey);
}
toScope.black.fromList(fromScope.black);
};

HTTPSB.copyTemporaryGrayRules = function(toScopeKey, fromScopeKey) {
var toScope = this.temporaryScopeFromScopeKey(toScopeKey);
var fromScope = this.temporaryScopeFromScopeKey(fromScopeKey);
if ( !toScope || !fromScope ) {
return;
}
toScope.gray.fromList(fromScope.gray);
};

HTTPSB.copyTemporaryBlackRules = function(toScopeKey, fromScopeKey) {
var toScope = this.temporaryScopeFromScopeKey(toScopeKey);
var fromScope = this.temporaryScopeFromScopeKey(fromScopeKey);
if ( !toScope || !fromScope ) {
return;
}
toScope.black.fromList(fromScope.black);
};

/******************************************************************************/

// Whitelist something
Expand Down Expand Up @@ -556,9 +621,6 @@ HTTPSB.savePermissions = function() {
if ( chrome.runtime.lastError ) {
console.error('HTTP Switchboard > saved permissions: %s', chrome.runtime.lastError.message());
}
chrome.storage.local.getBytesInUse('scopes', function(bytesInUse) {
// console.log('HTTP Switchboard > saved permissions: %d bytes used', bytesInUse);
});
// Remove pre-v0.5.0 obsolete entries
// TODO: Can be removed once everybody is using v0.5.0 or above
chrome.storage.local.remove(['whitelist','blacklist','graylist']);
Expand Down Expand Up @@ -593,3 +655,9 @@ HTTPSB.turnOn = function() {

this.off = false;
};

/******************************************************************************/

HTTPSB.isOpera = function() {
return navigator.userAgent.indexOf(' OPR/') > 0;
};
2 changes: 1 addition & 1 deletion js/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function gethttpsb() {
}

function pageStatsFromPageUrl(pageUrl) {
return chrome.extension.getBackgroundPage().HTTPSB.pageStats[pageUrl];
return gethttpsb().pageStatsFromPageUrl(pageUrl);
}

/******************************************************************************/
Expand Down
15 changes: 6 additions & 9 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getHTTPSB() {
}

function getPageStats() {
return getBackgroundPage().pageStatsFromTabId(HTTPSBPopup.tabId);
return getHTTPSB().pageStatsFromTabId(HTTPSBPopup.tabId);
}

/******************************************************************************/
Expand Down Expand Up @@ -1274,13 +1274,10 @@ function populatePresets() {

function presetEntryHandler() {
var httpsb = getHTTPSB();
var presetId = $(this).prop('presetId');
var preset = httpsb.presetManager.presetFromId(presetId);
if ( !preset ) {
return;
}
var scopeKey = httpsb.temporaryScopeKeyFromPageURL(HTTPSBPopup.pageURL);
preset.applyToScope(scopeKey);
httpsb.presetManager.applyToScope(
httpsb.temporaryScopeKeyFromPageURL(HTTPSBPopup.pageURL),
$(this).prop('presetId')
);
updateScopeCell();
updateMatrixStats();
updateMatrixColors();
Expand Down Expand Up @@ -1339,7 +1336,7 @@ function bindToTabHandler(tabs) {
HTTPSBPopup.tabId = httpsb.behindTheSceneTabId;
} else {
HTTPSBPopup.tabId = tab.id;
HTTPSBPopup.pageURL = background.pageUrlFromTabId(HTTPSBPopup.tabId);
HTTPSBPopup.pageURL = httpsb.pageUrlFromTabId(HTTPSBPopup.tabId);
}
HTTPSBPopup.pageHostname = background.uriTools.hostnameFromURI(HTTPSBPopup.pageURL);
HTTPSBPopup.pageDomain = background.uriTools.domainFromHostname(HTTPSBPopup.pageHostname);
Expand Down
Loading

0 comments on commit 8db73a1

Please sign in to comment.