| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 var cacheStorage = null; | 26 var cacheStorage = null; |
| 27 var noFlash = false; | 27 var noFlash = false; |
| 28 | 28 |
| 29 // Matcher for disabled filters | 29 // Matcher for disabled filters |
| 30 var disabledMatcher = new CombinedMatcher(); | 30 var disabledMatcher = new CombinedMatcher(); |
| 31 | 31 |
| 32 // Cached string values | 32 // Cached string values |
| 33 var docDomainThirdParty = null; | 33 var docDomainThirdParty = null; |
| 34 var docDomainFirstParty = null; | 34 var docDomainFirstParty = null; |
| 35 | 35 |
| 36 // Localized type names | |
| 37 var types = new Map(); | |
|
tschuster
2015/11/05 15:06:15
localizedTypes maybe?
Wladimir Palant
2015/11/05 15:47:11
Done.
| |
| 38 | |
| 36 function init() { | 39 function init() { |
| 37 docDomainThirdParty = document.documentElement.getAttribute("docDomainThirdPar ty"); | 40 docDomainThirdParty = document.documentElement.getAttribute("docDomainThirdPar ty"); |
| 38 docDomainFirstParty = document.documentElement.getAttribute("docDomainFirstPar ty"); | 41 docDomainFirstParty = document.documentElement.getAttribute("docDomainFirstPar ty"); |
| 39 | 42 |
| 40 var list = E("list"); | 43 var list = E("list"); |
| 41 list.view = treeView; | 44 list.view = treeView; |
| 42 | 45 |
| 43 // Restore previous state | 46 // Restore previous state |
| 44 var params = Utils.getParams(); | 47 var params = Utils.getParams(); |
| 45 if (params && params.filter) | 48 if (params && params.filter) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 | 97 |
| 95 // Activate flasher | 98 // Activate flasher |
| 96 list.addEventListener("select", onSelectionChange, false); | 99 list.addEventListener("select", onSelectionChange, false); |
| 97 | 100 |
| 98 // Initialize data | 101 // Initialize data |
| 99 handleLocationChange(); | 102 handleLocationChange(); |
| 100 | 103 |
| 101 // Install a progress listener to catch location changes | 104 // Install a progress listener to catch location changes |
| 102 if (addBrowserLocationListener) | 105 if (addBrowserLocationListener) |
| 103 addBrowserLocationListener(mainWin, handleLocationChange, true); | 106 addBrowserLocationListener(mainWin, handleLocationChange, true); |
| 107 | |
| 108 for (let type of Policy.contentTypes) | |
| 109 types.set(type, Utils.getString("type_label_" + type.toLowerCase())); | |
| 104 } | 110 } |
| 105 | 111 |
| 106 // To be called for a detached window when the main window has been closed | 112 // To be called for a detached window when the main window has been closed |
| 107 function mainUnload() { | 113 function mainUnload() { |
| 108 parent.close(); | 114 parent.close(); |
| 109 } | 115 } |
| 110 | 116 |
| 111 // To be called on unload | 117 // To be called on unload |
| 112 function cleanUp() { | 118 function cleanUp() { |
| 113 flasher.stop(); | 119 flasher.stop(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 E("tooltipFilterRow").hidden = !filter; | 257 E("tooltipFilterRow").hidden = !filter; |
| 252 E("tooltipFilterSourceRow").hidden = !subscriptions.length; | 258 E("tooltipFilterSourceRow").hidden = !subscriptions.length; |
| 253 | 259 |
| 254 if ("tooltip" in item) | 260 if ("tooltip" in item) |
| 255 E("tooltipDummy").setAttribute("value", item.tooltip); | 261 E("tooltipDummy").setAttribute("value", item.tooltip); |
| 256 else | 262 else |
| 257 { | 263 { |
| 258 E("tooltipAddress").parentNode.hidden = (item.typeDescr == "ELEMHIDE"); | 264 E("tooltipAddress").parentNode.hidden = (item.typeDescr == "ELEMHIDE"); |
| 259 setMultilineContent(E("tooltipAddress"), item.location); | 265 setMultilineContent(E("tooltipAddress"), item.location); |
| 260 | 266 |
| 261 var type = item.localizedDescr; | 267 var type = types.get(item.type); |
| 262 if (filter && filter instanceof WhitelistFilter) | 268 if (filter && filter instanceof WhitelistFilter) |
| 263 type += " " + E("tooltipType").getAttribute("whitelisted"); | 269 type += " " + E("tooltipType").getAttribute("whitelisted"); |
| 264 else if (filter && item.typeDescr != "ELEMHIDE") | 270 else if (filter && item.typeDescr != "ELEMHIDE") |
| 265 type += " " + E("tooltipType").getAttribute("filtered"); | 271 type += " " + E("tooltipType").getAttribute("filtered"); |
| 266 E("tooltipType").setAttribute("value", type); | 272 E("tooltipType").setAttribute("value", type); |
| 267 | 273 |
| 268 if (size) | 274 if (size) |
| 269 E("tooltipSize").setAttribute("value", size.join(" x ")); | 275 E("tooltipSize").setAttribute("value", size.join(" x ")); |
| 270 | 276 |
| 271 E("tooltipDocDomain").setAttribute("value", item.docDomain + " " + (item.thi rdParty ? docDomainThirdParty : docDomainFirstParty)); | 277 E("tooltipDocDomain").setAttribute("value", item.docDomain + " " + (item.thi rdParty ? docDomainThirdParty : docDomainFirstParty)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 { | 313 { |
| 308 let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInf o.jsm", null); | 314 let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInf o.jsm", null); |
| 309 let loadContext = content.QueryInterface(Ci.nsIInterfaceRequestor) | 315 let loadContext = content.QueryInterface(Ci.nsIInterfaceRequestor) |
| 310 .getInterface(Ci.nsIWebNavigation) | 316 .getInterface(Ci.nsIWebNavigation) |
| 311 .QueryInterface(Ci.nsILoadContext); | 317 .QueryInterface(Ci.nsILoadContext); |
| 312 cacheStorage = Services.cache2.diskCacheStorage(LoadContextInfo.fromLoad Context(loadContext, false), false); | 318 cacheStorage = Services.cache2.diskCacheStorage(LoadContextInfo.fromLoad Context(loadContext, false), false); |
| 313 } | 319 } |
| 314 else | 320 else |
| 315 cacheStorage = Services.cache.createSession("HTTP", Ci.nsICache.STORE_AN YWHERE, true); | 321 cacheStorage = Services.cache.createSession("HTTP", Ci.nsICache.STORE_AN YWHERE, true); |
| 316 } | 322 } |
| 317 | 323 |
| 318 let showTooltipPreview = function () | 324 let showTooltipPreview = function () |
| 319 { | 325 { |
| 320 E("tooltipPreview").setAttribute("src", item.location); | 326 E("tooltipPreview").setAttribute("src", item.location); |
| 321 E("tooltipPreviewBox").hidden = false; | 327 E("tooltipPreviewBox").hidden = false; |
| 322 }; | 328 }; |
| 323 try | 329 try |
| 324 { | 330 { |
| 325 if (Ci.nsICacheStorage && cacheStorage instanceof Ci.nsICacheStorage) | 331 if (Ci.nsICacheStorage && cacheStorage instanceof Ci.nsICacheStorage) |
| 326 { | 332 { |
| 327 cacheStorage.asyncOpenURI(Utils.makeURI(item.location), "", Ci.nsICacheS torage.OPEN_READONLY, { | 333 cacheStorage.asyncOpenURI(Utils.makeURI(item.location), "", Ci.nsICacheS torage.OPEN_READONLY, { |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 return 1; | 696 return 1; |
| 691 else | 697 else |
| 692 return 0; | 698 return 0; |
| 693 } | 699 } |
| 694 | 700 |
| 695 function sortByAddressDesc(item1, item2) { | 701 function sortByAddressDesc(item1, item2) { |
| 696 return -sortByAddress(item1, item2); | 702 return -sortByAddress(item1, item2); |
| 697 } | 703 } |
| 698 | 704 |
| 699 function compareType(item1, item2) { | 705 function compareType(item1, item2) { |
| 700 if (item1.localizedDescr < item2.localizedDescr) | 706 let type1 = types.get(item1.type); |
| 707 let type2 = types.get(item2.type); | |
| 708 if (type1 < type2) | |
| 701 return -1; | 709 return -1; |
| 702 else if (item1.localizedDescr > item2.localizedDescr) | 710 else if (type1 > type2) |
| 703 return 1; | 711 return 1; |
| 704 else | 712 else |
| 705 return 0; | 713 return 0; |
| 706 } | 714 } |
| 707 | 715 |
| 708 function compareFilter(item1, item2) { | 716 function compareFilter(item1, item2) { |
| 709 var hasFilter1 = (item1.filter ? 1 : 0); | 717 var hasFilter1 = (item1.filter ? 1 : 0); |
| 710 var hasFilter2 = (item2.filter ? 1 : 0); | 718 var hasFilter2 = (item2.filter ? 1 : 0); |
| 711 if (hasFilter1 != hasFilter2) | 719 if (hasFilter1 != hasFilter2) |
| 712 return hasFilter1 - hasFilter2; | 720 return hasFilter1 - hasFilter2; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 return (this.data && this.data.length ? this.data.length : 1); | 866 return (this.data && this.data.length ? this.data.length : 1); |
| 859 }, | 867 }, |
| 860 getCellText: function(row, col) { | 868 getCellText: function(row, col) { |
| 861 col = col.id; | 869 col = col.id; |
| 862 if (col != "type" && col != "address" && col != "filter" && col != "size" && col != "docDomain" && col != "filterSource") | 870 if (col != "type" && col != "address" && col != "filter" && col != "size" && col != "docDomain" && col != "filterSource") |
| 863 return ""; | 871 return ""; |
| 864 if (this.data && this.data.length) { | 872 if (this.data && this.data.length) { |
| 865 if (row >= this.data.length) | 873 if (row >= this.data.length) |
| 866 return ""; | 874 return ""; |
| 867 if (col == "type") | 875 if (col == "type") |
| 868 return this.data[row].localizedDescr; | 876 return types.get(this.data[row].type); |
| 869 else if (col == "filter") | 877 else if (col == "filter") |
| 870 return (this.data[row].filter ? this.data[row].filter.text : ""); | 878 return (this.data[row].filter ? this.data[row].filter.text : ""); |
| 871 else if (col == "size") | 879 else if (col == "size") |
| 872 { | 880 { |
| 873 let size = getItemSize(this.data[row]); | 881 let size = getItemSize(this.data[row]); |
| 874 return (size ? size.join(" x ") : ""); | 882 return (size ? size.join(" x ") : ""); |
| 875 } | 883 } |
| 876 else if (col == "docDomain") | 884 else if (col == "docDomain") |
| 877 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc DomainThirdParty : docDomainFirstParty); | 885 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc DomainThirdParty : docDomainFirstParty); |
| 878 else if (col == "filterSource") | 886 else if (col == "filterSource") |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1173 * @return {Boolean} true if the item should be shown | 1181 * @return {Boolean} true if the item should be shown |
| 1174 */ | 1182 */ |
| 1175 matchesFilter: function(item) | 1183 matchesFilter: function(item) |
| 1176 { | 1184 { |
| 1177 if (!this.filter) | 1185 if (!this.filter) |
| 1178 return true; | 1186 return true; |
| 1179 | 1187 |
| 1180 return (item.location.toLowerCase().indexOf(this.filter) >= 0 || | 1188 return (item.location.toLowerCase().indexOf(this.filter) >= 0 || |
| 1181 (item.filter && item.filter.text.toLowerCase().indexOf(this.filter) >= 0) || | 1189 (item.filter && item.filter.text.toLowerCase().indexOf(this.filter) >= 0) || |
| 1182 item.typeDescr.toLowerCase().indexOf(this.filter.replace(/-/g, "_")) >= 0 || | 1190 item.typeDescr.toLowerCase().indexOf(this.filter.replace(/-/g, "_")) >= 0 || |
| 1183 item.localizedDescr.toLowerCase().indexOf(this.filter) >= 0 || | 1191 types.get(item.type).toLowerCase().indexOf(this.filter) >= 0 || |
| 1184 (item.docDomain && item.docDomain.toLowerCase().indexOf(this.filter) >= 0) || | 1192 (item.docDomain && item.docDomain.toLowerCase().indexOf(this.filter) >= 0) || |
| 1185 (item.docDomain && item.thirdParty && docDomainThirdParty.toLowerCas e().indexOf(this.filter) >= 0) || | 1193 (item.docDomain && item.thirdParty && docDomainThirdParty.toLowerCas e().indexOf(this.filter) >= 0) || |
| 1186 (item.docDomain && !item.thirdParty && docDomainFirstParty.toLowerCa se().indexOf(this.filter) >= 0)); | 1194 (item.docDomain && !item.thirdParty && docDomainFirstParty.toLowerCa se().indexOf(this.filter) >= 0)); |
| 1187 }, | 1195 }, |
| 1188 | 1196 |
| 1189 setFilter: function(filter) { | 1197 setFilter: function(filter) { |
| 1190 var oldRows = this.rowCount; | 1198 var oldRows = this.rowCount; |
| 1191 | 1199 |
| 1192 this.filter = filter.toLowerCase(); | 1200 this.filter = filter.toLowerCase(); |
| 1193 this.refilter(); | 1201 this.refilter(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1262 return {tooltip: this.itemsDummyTooltip}; | 1270 return {tooltip: this.itemsDummyTooltip}; |
| 1263 }, | 1271 }, |
| 1264 | 1272 |
| 1265 invalidateItem: function(item) | 1273 invalidateItem: function(item) |
| 1266 { | 1274 { |
| 1267 let row = this.data.indexOf(item); | 1275 let row = this.data.indexOf(item); |
| 1268 if (row >= 0) | 1276 if (row >= 0) |
| 1269 this.boxObject.invalidateRow(row); | 1277 this.boxObject.invalidateRow(row); |
| 1270 } | 1278 } |
| 1271 } | 1279 } |
| OLD | NEW |