OLD | NEW |
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 Loading... |
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 }; |
OLD | NEW |