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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 // 7 //
8 // Module framework stuff 8 // Module framework stuff
9 // 9 //
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // 86 //
87 // Info pseudo-module 87 // Info pseudo-module
88 // 88 //
89 89
90 require.scopes.info = 90 require.scopes.info =
91 { 91 {
92 get addonID() 92 get addonID()
93 { 93 {
94 return chrome.i18n.getMessage("@@extension_id"); 94 return chrome.i18n.getMessage("@@extension_id");
95 }, 95 },
96 addonVersion: "2.0.3", // Hardcoded for now 96 addonVersion: "2.1", // Hardcoded for now
97 addonRoot: "", 97 addonRoot: "",
98 get addonName() 98 get addonName()
99 { 99 {
100 return chrome.i18n.getMessage("name"); 100 return chrome.i18n.getMessage("name");
101 }, 101 },
102 application: "chrome" 102 application: "chrome"
103 }; 103 };
104 104
105 // 105 //
106 // IO module: no direct file system access, using FileSystem API 106 // IO module: no direct file system access, using FileSystem API
(...skipping 29 matching lines...) Expand all
136 return new FakeFile(path); 136 return new FakeFile(path);
137 }, 137 },
138 138
139 readFromFile: function(file, decode, listener, callback, timeLineID) 139 readFromFile: function(file, decode, listener, callback, timeLineID)
140 { 140 {
141 if ("spec" in file && /^defaults\b/.test(file.spec)) 141 if ("spec" in file && /^defaults\b/.test(file.spec))
142 { 142 {
143 // Code attempts to read the default patterns.ini, we don't have that. 143 // Code attempts to read the default patterns.ini, we don't have that.
144 // Make sure to execute first-run actions instead. 144 // Make sure to execute first-run actions instead.
145 callback(null); 145 callback(null);
146 executeFirstRunActions(); 146 addSubscription("0.1");
147 return; 147 return;
148 } 148 }
149 149
150 this._getFileEntry(file, false, function(fs, fileEntry) 150 this._getFileEntry(file, false, function(fs, fileEntry)
151 { 151 {
152 fileEntry.file(function(file) 152 fileEntry.file(function(file)
153 { 153 {
154 var reader = new FileReader(); 154 var reader = new FileReader();
155 reader.onloadend = function() 155 reader.onloadend = function()
156 { 156 {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 }, 354 },
355 generateChecksum: function(lines) 355 generateChecksum: function(lines)
356 { 356 {
357 // We cannot calculate MD5 checksums yet :-( 357 // We cannot calculate MD5 checksums yet :-(
358 return null; 358 return null;
359 }, 359 },
360 makeURI: function(url) 360 makeURI: function(url)
361 { 361 {
362 return Services.io.newURI(url); 362 return Services.io.newURI(url);
363 }, 363 },
364
364 checkLocalePrefixMatch: function(prefixes) 365 checkLocalePrefixMatch: function(prefixes)
365 { 366 {
366 if (!prefixes) 367 if (!prefixes)
367 return null; 368 return null;
368 369
369 var list = prefixes.split(","); 370 var list = prefixes.split(",");
370 for (var i = 0; i < list.length; i++) 371 for (var i = 0; i < list.length; i++)
371 if (new RegExp("^" + list[i] + "\\b").test(this.appLocale)) 372 if (new RegExp("^" + list[i] + "\\b").test(this.appLocale))
372 return list[i]; 373 return list[i];
373 374
374 return null; 375 return null;
376 },
377
378 chooseFilterSubscription: function(subscriptions)
379 {
380 var selectedItem = null;
381 var selectedPrefix = null;
382 var matchCount = 0;
383 for (var i = 0; i < subscriptions.length; i++)
384 {
385 var subscription = subscriptions[i];
386 if (!selectedItem)
387 selectedItem = subscription;
388
389 var prefix = require("utils").Utils.checkLocalePrefixMatch(subscription. getAttribute("prefixes"));
390 if (prefix)
391 {
392 if (!selectedPrefix || selectedPrefix.length < prefix.length)
393 {
394 selectedItem = subscription;
395 selectedPrefix = prefix;
396 matchCount = 1;
397 }
398 else if (selectedPrefix && selectedPrefix.length == prefix.length)
399 {
400 matchCount++;
401
402 // If multiple items have a matching prefix of the same length:
403 // Select one of the items randomly, probability should be the same
404 // for all items. So we replace the previous match here with
405 // probability 1/N (N being the number of matches).
406 if (Math.random() * matchCount < 1)
407 {
408 selectedItem = subscription;
409 selectedPrefix = prefix;
410 }
411 }
412 }
413 }
414 return selectedItem;
375 } 415 }
376 } 416 }
377 }; 417 };
378 418
379 // 419 //
380 // ElemHideHitRegistration dummy implementation 420 // ElemHideHitRegistration dummy implementation
381 // 421 //
382 422
383 require.scopes.elemHideHitRegistration = 423 require.scopes.elemHideHitRegistration =
384 { 424 {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 status: -1, 579 status: -1,
540 notificationCallbacks: {}, 580 notificationCallbacks: {},
541 loadFlags: 0, 581 loadFlags: 0,
542 INHIBIT_CACHING: 0, 582 INHIBIT_CACHING: 0,
543 VALIDATE_ALWAYS: 0, 583 VALIDATE_ALWAYS: 0,
544 QueryInterface: function() 584 QueryInterface: function()
545 { 585 {
546 return this; 586 return this;
547 } 587 }
548 }; 588 };
OLDNEW
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld