Skip to content

Commit

Permalink
#68 optimized filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Nov 26, 2015
1 parent e4541ad commit 2bc46c3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Extension/lib/filter/antibanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ AntiBannerService.prototype = {
callback(false);
};

this.serviceClient.loadFilterRules(filter.filterId, successCallback, errorCallback);
this.serviceClient.loadFilterRules(filter.filterId, userSettings.isUseOptimizedFiltersEnabled(), successCallback, errorCallback);
},

/**
Expand Down
4 changes: 4 additions & 0 deletions Extension/lib/pages/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ PageController.prototype = {

changeUseOptimizedFilters: function (e) {
e.preventDefault();

//TODO: Set filter versions to 1.0
//TODO: If ContentBlocker set filters to 1.0 on first start

contentPage.sendMessage({
type: 'changeUserSetting',
key: userSettings.names.USE_OPTIMIZED_FILTERS,
Expand Down
29 changes: 21 additions & 8 deletions Extension/lib/utils/service-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ var ServiceClient = exports.ServiceClient = function () {

// Base url of our backend server
this.backendUrl = "https://chrome.adtidy.org";
this.mobileBackendUrl = "https://mobile.adtidy.org";
this.apiKey = "4DDBE80A3DA94D819A00523252FB6380";

//URL for downloading AG filters
this.getFilterRulesUrl = "/getfilter.html";

// URL for checking filter updates
this.checkFilterVersionsUrl = this.backendUrl + "/checkfilterversions.html";

// URL for downloading AG filters
this.getFilterRulesUrl = this.backendUrl + "/getfilter.html";

// URL for user complaints on missed ads or malware/phishing websites
this.reportUrl = this.backendUrl + "/url-report.html";

Expand Down Expand Up @@ -139,11 +140,12 @@ ServiceClient.prototype = {
/**
* Downloads filter rules by filter ID
*
* @param filterId Filter identifier
* @param successCallback Called on success
* @param errorCallback Called on error
* @param filterId Filter identifier
* @param useOptimizedFilters Download optimized filters flag
* @param successCallback Called on success
* @param errorCallback Called on error
*/
loadFilterRules: function (filterId, successCallback, errorCallback) {
loadFilterRules: function (filterId, useOptimizedFilters, successCallback, errorCallback) {

var AdguardFilterVersion = require('filter/antibanner').AdguardFilterVersion;

Expand Down Expand Up @@ -180,12 +182,23 @@ ServiceClient.prototype = {
var filterVersion = new AdguardFilterVersion(timeUpdated.getTime(), version, filterId);
successCallback(filterVersion, rules);
};
var url = this.getFilterRulesUrl + "?filterid=" + filterId;
var url = this._getFilterRulesUrl(useOptimizedFilters) + "?filterid=" + filterId;
url += this.APP_PARAM;
url = this._addKeyParameter(url);
this._executeRequestAsync(url, "text/plain", success, errorCallback);
},

/**
* URL for downloading AG filters
*
* @param useOptimizedFilters
* @private
*/
_getFilterRulesUrl: function (useOptimizedFilters) {
var host = useOptimizedFilters ? this.mobileBackendUrl : this.backendUrl;
return host + this.getFilterRulesUrl;
},

/**
* Loads filter rules from local file
*
Expand Down
5 changes: 5 additions & 0 deletions Extension/lib/utils/user-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var UserSettings = function () {
this.defaultProperties[this.settings.DISABLE_COLLECT_HITS] = true;
this.defaultProperties[this.settings.DISABLE_SEND_SAFEBROWSING_STATS] = true;
this.defaultProperties[this.settings.DEFAULT_WHITE_LIST_MODE] = true;
this.defaultProperties[this.settings.USE_OPTIMIZED_FILTERS] = Utils.isContentBlockerEnabled();

this.properties = Object.create(null);
};
Expand Down Expand Up @@ -154,6 +155,10 @@ UserSettings.prototype.isDefaultWhiteListMode = function () {
return this.getProperty(this.settings.DEFAULT_WHITE_LIST_MODE);
};

UserSettings.prototype.isUseOptimizedFiltersEnabled = function () {
return this.getProperty(this.settings.USE_OPTIMIZED_FILTERS);
};

UserSettings.prototype.changeDefaultWhiteListMode = function (enabled) {
this.setProperty(this.settings.DEFAULT_WHITE_LIST_MODE, enabled);
};
Expand Down

0 comments on commit 2bc46c3

Please sign in to comment.