Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate ShareMeNot functionality #196

Merged
merged 14 commits into from
Jun 10, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Basic button replacement working.
  • Loading branch information
froeschele committed May 31, 2014
commit 17e7c84475405e601fd88535a3777c91cd57d2b3
13 changes: 11 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,23 @@
{
"js": [
"src/include.preload.js",
"src/clobbercookie.js",
"src/socialwidgets.js"
"src/clobbercookie.js"
],
"matches": [
"<all_urls>"
],
"all_frames": true,
"run_at": "document_start"
},
{
"js": [
"src/socialwidgets.js"
],
"matches": [
"<all_urls>"
],
"all_frames": true,
"run_at": "document_idle"
}
],
"default_locale": "en_US",
Expand Down
3 changes: 1 addition & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ var HeuristicBlocking = require("heuristicblocking");
var SocialWidgetLoader = require("socialwidgetloader");

// Load social widgets
var socialwidgets = SocialWidgetLoader.loadSocialWidgetsFromFile("socialwidgets.json");
console.log(socialwidgets);
var SocialWidgetList = SocialWidgetLoader.loadSocialWidgetsFromFile("src/socialwidgets.json");

// Some types cannot be distinguished
RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
Expand Down
2 changes: 1 addition & 1 deletion src/blockedDomainList.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var BlockedDomainList = exports.BlockedDomainList = {
var updateTime = this._randomFutureTime();
this.domains[domain] = updateTime;
chrome.storage.local.set({blockeddomainlist: this.domains},function(){});
},
},
nextUpdateTime: function(domain){
return this.domains[domain];
},
Expand Down
66 changes: 12 additions & 54 deletions src/socialwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ var browserAbstractionLayer = (function() {
*/
exports.getTrackerData = function(callback) {
chrome.runtime.sendMessage({checkReplaceButton:document.location}, function(response) {
var contentScriptFolderUrl = response.contentScriptFolderUrl;
var trackers = response.trackers;
var trackerButtonsToReplace = response.trackerButtonsToReplace;

callback(contentScriptFolderUrl, trackers, trackerButtonsToReplace);
callback(trackers, trackerButtonsToReplace);
});
}

Expand All @@ -45,66 +43,26 @@ var browserAbstractionLayer = (function() {
return exports;
}());

/*
ShareMeNot is licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php


Copyright (c) 2012 University of Washington

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

"use strict";

/**
* The relative path from the content script folder to the replacement buttons
* folder.
* The absolute path to the replacement buttons folder.
*/
var REPLACEMENT_BUTTONS_FOLDER_PATH = "../skin/socialwidgets/";
var REPLACEMENT_BUTTONS_FOLDER_PATH = chrome.extension.getURL("skin/socialwidgets/");

/**
* The relative path from the content script folder to the stylesheet that is
* injected into every page.
* The absolute path to the stylesheet that is injected into every page.
*/
var CONTENT_SCRIPT_STYLESHEET_PATH = "../skin/socialwidgets.css";

/**
* The absolute URL to the content script folder within the extension.
*/
var contentScriptFolderUrl;
var CONTENT_SCRIPT_STYLESHEET_PATH = chrome.extension.getURL("skin/socialwidgets.css");

/**
* Initializes the content script.
*/
function initialize() {
browserAbstractionLayer.getTrackerData(function (contentScriptFolderUrl2,
trackers, trackerButtonsToReplace) {
contentScriptFolderUrl = contentScriptFolderUrl2;

browserAbstractionLayer.getTrackerData(function (trackers, trackerButtonsToReplace) {
// add the Content.css stylesheet to the page
var head = document.querySelector("head");
var stylesheetLinkElement = getStylesheetLinkElement(contentScriptFolderUrl
+ CONTENT_SCRIPT_STYLESHEET_PATH);
var stylesheetLinkElement = getStylesheetLinkElement(CONTENT_SCRIPT_STYLESHEET_PATH);
head.appendChild(stylesheetLinkElement);

replaceTrackerButtonsHelper(trackers, trackerButtonsToReplace);
});
}
Expand Down Expand Up @@ -182,8 +140,7 @@ function createReplacementButtonImage(tracker) {
* path in the replacement buttons folder
*/
function getReplacementButtonUrl(replacementButtonLocation) {
return contentScriptFolderUrl + REPLACEMENT_BUTTONS_FOLDER_PATH +
replacementButtonLocation;
return REPLACEMENT_BUTTONS_FOLDER_PATH + replacementButtonLocation;
}

/**
Expand Down Expand Up @@ -265,13 +222,14 @@ function replaceTrackerButtonsHelper(trackers, trackerButtonsToReplace) {
trackers.forEach(function(tracker) {
var replaceTrackerButtons = trackerButtonsToReplace[tracker.name];

if (replaceTrackerButtons) {
if (replaceTrackerButtons) {
console.log("replacing tracker button for " + tracker.name);
// makes a comma separated list of CSS selectors that specify
// buttons for the current tracker; used for document.querySelectorAll
var buttonSelectorsString = tracker.buttonSelectors.toString();
var buttonsToReplace =
document.querySelectorAll(buttonSelectorsString);

for (var i = 0; i < buttonsToReplace.length; i++) {
var buttonToReplace = buttonsToReplace[i];

Expand Down
28 changes: 14 additions & 14 deletions socialwidgets.json → src/socialwidgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
},

"Digg": {
"domain": "digg.com",
"domain": "widgets.digg.com",
"matchPatterns": [
"*://*.widgets.digg.com/buttons.js*",
"*://*.widgets.digg.com/*"
"*://*.widgets.digg.com/*"
],

"buttonSelectors": [
Expand All @@ -33,14 +33,14 @@
},

"Facebook": {
"domain": "facebook.com",
"domain": "www.facebook.com",
"matchPatterns": [
"*://*.connect.facebook.net/*",
"*://*.facebook.com/plugins/like.php*",
"*://*.facebook.com/plugins/likebox.php*",
"*://*.facebook.com/plugins/activity.php*",
"*://*.ak.facebook.com/connect*",
"*://*.facebook.com/dialog/oauth*"
"*://*.ak.facebook.com/connect*",
"*://*.facebook.com/dialog/oauth*"
],

"buttonSelectors": [
Expand All @@ -59,8 +59,8 @@
"matchPatterns": [
"*://*.apis.google.com/js/plusone.js*",
"*://*.plusone.google.com/_/+1/fastbutton*",
"*://*.plusone.google.com/_/apps-static*",
"*://*.apis.google.com/_/apps-static*"
"*://*.plusone.google.com/_/apps-static*",
"*://*.apis.google.com/_/apps-static*"
],

"buttonSelectors": [
Expand All @@ -77,7 +77,7 @@
"domain": "linkedin.com",
"matchPatterns": [
"*://*.platform.linkedin.com/*",
"*://*.linkedin.com/analytics/*"
"*://*.linkedin.com/analytics/*"
],

"buttonSelectors": [
Expand All @@ -91,7 +91,7 @@
},

"Pinterest": {
"domain": "pinterest.com",
"domain": "assets.pinterest.com",
"matchPatterns": [
"*://*.assets.pinterest.com/js/pinit.js*",
"*://*.assets.pinterest.com/imagePaths/PinExt.png*",
Expand All @@ -109,11 +109,11 @@
},

"StumbleUpon": {
"domain": "stumbleupon.com",
"domain": "badge.stumbleupon.com",
"matchPatterns": [
"*://*.platform.stumbleupon.com/1/widgets.js*",
"*://*.stumbleupon.com/hostedbadge.php*",
"*://*.badge.stumbleupon.com/*"
"*://*.badge.stumbleupon.com/*"
],

"buttonSelectors": [
Expand All @@ -128,11 +128,11 @@
},

"Twitter": {
"domain": "twitter.com",
"domain": "platform.twitter.com",
"matchPatterns": [
"*://*.platform.twitter.com/widgets.js*",
"*://*.platform.twitter.com/*",
"*://*.p.twitter.com/*"
"*://*.platform.twitter.com/*",
"*://*.p.twitter.com/*"
],

"buttonSelectors": [
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ var Utils = exports.Utils = {
}
},

/**
* check if social widget replacement functionality is enabled
* (TODO: actually make this return something based on a user-facing setting
*/
isSocialWidgetReplacementEnabled: function() {
return true;
},

/**
* add an origin to the disabled sites list
**/
Expand Down
32 changes: 30 additions & 2 deletions src/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,33 @@ function isFrameWhitelisted(tabId, frameId, type) {
return false;
}

// Provides the social widget blocking content script with list of social widgets to block
function getSocialWidgetBlockList(tabId) {

// a mapping of individual SocialWidget objects to boolean values
// saying if the content script should replace that tracker's buttons
var socialWidgetsToReplace = {};

SocialWidgetList.forEach(function(socialwidget) {
var socialWidgetName = socialwidget.name;

// replace them if PrivacyBadger has blocked them
var blockedData = activeMatchers.blockedOriginsByTab[tabId];
if (blockedData && blockedData[socialwidget.domain]) {
socialWidgetsToReplace[socialWidgetName] = (blockedData[socialwidget.domain].latestaction == "block"
|| blockedData[socialwidget.domain].latestaction == "userblock");
}
else {
socialWidgetsToReplace[socialWidgetName] = false;
}
});

return {
"trackers" : SocialWidgetList,
"trackerButtonsToReplace" : socialWidgetsToReplace,
};
}

chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var tabHost = extractHostFromURL(sender.tab.url);
Expand All @@ -425,8 +452,9 @@ chrome.runtime.onMessage.addListener(
var cookieBlock = reqAction == 'cookieblock' || reqAction == 'usercookieblock';
sendResponse(cookieBlock);
}
if(request.checkReplaceButton && Utils.isPrivacyBadgerEnabled(tabHost)){
console.log("checking for replace button");
if(request.checkReplaceButton && Utils.isPrivacyBadgerEnabled(tabHost) && Utils.isSocialWidgetReplacementEnabled()){
var socialWidgetBlockList = getSocialWidgetBlockList(sender.tab.id);
sendResponse(socialWidgetBlockList);
}
}
);