Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/adblockplus_compat.js

Issue 8680033: Made sure to enable acceptable ads and to open the first-run page (Closed)
Patch Set: Created Oct. 25, 2012, 4:24 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/adblockplus_compat.js
===================================================================
--- a/lib/adblockplus_compat.js
+++ b/lib/adblockplus_compat.js
@@ -88,17 +88,17 @@ var XPCOMUtils =
//
require.scopes.info =
{
get addonID()
{
return chrome.i18n.getMessage("@@extension_id");
},
- addonVersion: "2.0.3", // Hardcoded for now
+ addonVersion: "2.1", // Hardcoded for now
addonRoot: "",
get addonName()
{
return chrome.i18n.getMessage("name");
},
application: "chrome"
};
@@ -138,17 +138,17 @@ require.scopes.io =
readFromFile: function(file, decode, listener, callback, timeLineID)
{
if ("spec" in file && /^defaults\b/.test(file.spec))
{
// Code attempts to read the default patterns.ini, we don't have that.
// Make sure to execute first-run actions instead.
callback(null);
- executeFirstRunActions();
+ addSubscription("0.1");
return;
}
this._getFileEntry(file, false, function(fs, fileEntry)
{
fileEntry.file(function(file)
{
var reader = new FileReader();
@@ -356,27 +356,67 @@ require.scopes.utils =
{
// We cannot calculate MD5 checksums yet :-(
return null;
},
makeURI: function(url)
{
return Services.io.newURI(url);
},
+
checkLocalePrefixMatch: function(prefixes)
{
if (!prefixes)
return null;
var list = prefixes.split(",");
for (var i = 0; i < list.length; i++)
if (new RegExp("^" + list[i] + "\\b").test(this.appLocale))
return list[i];
return null;
+ },
+
+ chooseFilterSubscription: function(subscriptions)
+ {
+ var selectedItem = null;
+ var selectedPrefix = null;
+ var matchCount = 0;
+ for (var i = 0; i < subscriptions.length; i++)
+ {
+ var subscription = subscriptions[i];
+ if (!selectedItem)
+ selectedItem = subscription;
+
+ var prefix = require("utils").Utils.checkLocalePrefixMatch(subscription.getAttribute("prefixes"));
+ if (prefix)
+ {
+ if (!selectedPrefix || selectedPrefix.length < prefix.length)
+ {
+ selectedItem = subscription;
+ selectedPrefix = prefix;
+ matchCount = 1;
+ }
+ else if (selectedPrefix && selectedPrefix.length == prefix.length)
+ {
+ matchCount++;
+
+ // If multiple items have a matching prefix of the same length:
+ // Select one of the items randomly, probability should be the same
+ // for all items. So we replace the previous match here with
+ // probability 1/N (N being the number of matches).
+ if (Math.random() * matchCount < 1)
+ {
+ selectedItem = subscription;
+ selectedPrefix = prefix;
+ }
+ }
+ }
+ }
+ return selectedItem;
}
}
};
//
// ElemHideHitRegistration dummy implementation
//
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld