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

Delta Between Two Patch Sets: chrome/content/ui/sidebar.js

Issue 29329473: Issue 3222 - Don`t do localization in the contentPolicy module (Closed)
Left Patch Set: Created Oct. 29, 2015, 1:25 p.m.
Right Patch Set: Addressed comments Created Nov. 5, 2015, 3:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « chrome/content/ui/composer.js ('k') | lib/contentPolicy.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 16 matching lines...) Expand all
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 36 // Localized type names
37 var types = new Map(); 37 var localizedTypes = new Map();
tschuster 2015/11/05 15:06:15 localizedTypes maybe?
Wladimir Palant 2015/11/05 15:47:11 Done.
38 38
39 function init() { 39 function init() {
40 docDomainThirdParty = document.documentElement.getAttribute("docDomainThirdPar ty"); 40 docDomainThirdParty = document.documentElement.getAttribute("docDomainThirdPar ty");
41 docDomainFirstParty = document.documentElement.getAttribute("docDomainFirstPar ty"); 41 docDomainFirstParty = document.documentElement.getAttribute("docDomainFirstPar ty");
42 42
43 var list = E("list"); 43 var list = E("list");
44 list.view = treeView; 44 list.view = treeView;
45 45
46 // Restore previous state 46 // Restore previous state
47 var params = Utils.getParams(); 47 var params = Utils.getParams();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 list.addEventListener("select", onSelectionChange, false); 99 list.addEventListener("select", onSelectionChange, false);
100 100
101 // Initialize data 101 // Initialize data
102 handleLocationChange(); 102 handleLocationChange();
103 103
104 // Install a progress listener to catch location changes 104 // Install a progress listener to catch location changes
105 if (addBrowserLocationListener) 105 if (addBrowserLocationListener)
106 addBrowserLocationListener(mainWin, handleLocationChange, true); 106 addBrowserLocationListener(mainWin, handleLocationChange, true);
107 107
108 for (let type of Policy.contentTypes) 108 for (let type of Policy.contentTypes)
109 types.set(type, Utils.getString("type_label_" + type.toLowerCase())); 109 localizedTypes.set(type, Utils.getString("type_label_" + type.toLowerCase()) );
110 } 110 }
111 111
112 // 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
113 function mainUnload() { 113 function mainUnload() {
114 parent.close(); 114 parent.close();
115 } 115 }
116 116
117 // To be called on unload 117 // To be called on unload
118 function cleanUp() { 118 function cleanUp() {
119 flasher.stop(); 119 flasher.stop();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 E("tooltipFilterRow").hidden = !filter; 257 E("tooltipFilterRow").hidden = !filter;
258 E("tooltipFilterSourceRow").hidden = !subscriptions.length; 258 E("tooltipFilterSourceRow").hidden = !subscriptions.length;
259 259
260 if ("tooltip" in item) 260 if ("tooltip" in item)
261 E("tooltipDummy").setAttribute("value", item.tooltip); 261 E("tooltipDummy").setAttribute("value", item.tooltip);
262 else 262 else
263 { 263 {
264 E("tooltipAddress").parentNode.hidden = (item.typeDescr == "ELEMHIDE"); 264 E("tooltipAddress").parentNode.hidden = (item.typeDescr == "ELEMHIDE");
265 setMultilineContent(E("tooltipAddress"), item.location); 265 setMultilineContent(E("tooltipAddress"), item.location);
266 266
267 var type = types.get(item.type); 267 var type = localizedTypes.get(item.type);
268 if (filter && filter instanceof WhitelistFilter) 268 if (filter && filter instanceof WhitelistFilter)
269 type += " " + E("tooltipType").getAttribute("whitelisted"); 269 type += " " + E("tooltipType").getAttribute("whitelisted");
270 else if (filter && item.typeDescr != "ELEMHIDE") 270 else if (filter && item.typeDescr != "ELEMHIDE")
271 type += " " + E("tooltipType").getAttribute("filtered"); 271 type += " " + E("tooltipType").getAttribute("filtered");
272 E("tooltipType").setAttribute("value", type); 272 E("tooltipType").setAttribute("value", type);
273 273
274 if (size) 274 if (size)
275 E("tooltipSize").setAttribute("value", size.join(" x ")); 275 E("tooltipSize").setAttribute("value", size.join(" x "));
276 276
277 E("tooltipDocDomain").setAttribute("value", item.docDomain + " " + (item.thi rdParty ? docDomainThirdParty : docDomainFirstParty)); 277 E("tooltipDocDomain").setAttribute("value", item.docDomain + " " + (item.thi rdParty ? docDomainThirdParty : docDomainFirstParty));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 E("contextBlock").setAttribute("disabled", "filter" in item && item.filter && !item.filter.disabled); 422 E("contextBlock").setAttribute("disabled", "filter" in item && item.filter && !item.filter.disabled);
423 E("contextEditFilter").setAttribute("disabled", !("filter" in item && item.fil ter)); 423 E("contextEditFilter").setAttribute("disabled", !("filter" in item && item.fil ter));
424 E("contextOpen").setAttribute("disabled", "tooltip" in item || item.typeDescr == "ELEMHIDE"); 424 E("contextOpen").setAttribute("disabled", "tooltip" in item || item.typeDescr == "ELEMHIDE");
425 E("contextFlash").setAttribute("disabled", "tooltip" in item || !(item.typeDes cr in visual) || (item.filter && !item.filter.disabled && !(item.filter instance of WhitelistFilter))); 425 E("contextFlash").setAttribute("disabled", "tooltip" in item || !(item.typeDes cr in visual) || (item.filter && !item.filter.disabled && !(item.filter instance of WhitelistFilter)));
426 E("contextCopyFilter").setAttribute("disabled", !allItems.some(function(item) {return "filter" in item && item.filter})); 426 E("contextCopyFilter").setAttribute("disabled", !allItems.some(function(item) {return "filter" in item && item.filter}));
427 427
428 return true; 428 return true;
429 } 429 }
430 430
431 /** 431 /**
432 * Resets context menu data once the context menu is closed.
433 */
434 function clearContextMenu(/**Event*/ event)
435 {
436 if (event.eventPhase != event.AT_TARGET)
437 return;
438
439 {
440 let menuItem = E("contextDisableOnSite");
441 menuItem.item = item;
442 menuItem.filter = filter;
443 menuItem.domain = domain;
444 }
445 }
446
447 /**
448 * Processed mouse clicks on the item list. 432 * Processed mouse clicks on the item list.
449 * @param {Event} event 433 * @param {Event} event
450 */ 434 */
451 function handleClick(event) 435 function handleClick(event)
452 { 436 {
453 let item = treeView.getItemAt(event.clientX, event.clientY); 437 let item = treeView.getItemAt(event.clientX, event.clientY);
454 if (event.button == 0 && treeView.getColumnAt(event.clientX, event.clientY) == "state") 438 if (event.button == 0 && treeView.getColumnAt(event.clientX, event.clientY) == "state")
455 { 439 {
456 if (item.filter) 440 if (item.filter)
457 enableFilter(item.filter, item.filter.disabled); 441 enableFilter(item.filter, item.filter.disabled);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 489 }
506 490
507 function editFilter() 491 function editFilter()
508 { 492 {
509 var item = treeView.getSelectedItem(); 493 var item = treeView.getSelectedItem();
510 if (treeView.data && !treeView.data.length) 494 if (treeView.data && !treeView.data.length)
511 item = treeView.getDummyTooltip(); 495 item = treeView.getDummyTooltip();
512 496
513 if (!("filter" in item) || !item.filter) 497 if (!("filter" in item) || !item.filter)
514 return; 498 return;
515
516 if (!("location") in item)
517 item.location = undefined
518 499
519 UI.openFiltersDialog(item.filter); 500 UI.openFiltersDialog(item.filter);
520 } 501 }
521 502
522 function enableFilter(filter, enable) { 503 function enableFilter(filter, enable) {
523 filter.disabled = !enable; 504 filter.disabled = !enable;
524 505
525 treeView.boxObject.invalidate(); 506 treeView.boxObject.invalidate();
526 } 507 }
527 508
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 return 1; 677 return 1;
697 else 678 else
698 return 0; 679 return 0;
699 } 680 }
700 681
701 function sortByAddressDesc(item1, item2) { 682 function sortByAddressDesc(item1, item2) {
702 return -sortByAddress(item1, item2); 683 return -sortByAddress(item1, item2);
703 } 684 }
704 685
705 function compareType(item1, item2) { 686 function compareType(item1, item2) {
706 let type1 = types.get(item1.type); 687 let type1 = localizedTypes.get(item1.type);
707 let type2 = types.get(item2.type); 688 let type2 = localizedTypes.get(item2.type);
708 if (type1 < type2) 689 if (type1 < type2)
709 return -1; 690 return -1;
710 else if (type1 > type2) 691 else if (type1 > type2)
711 return 1; 692 return 1;
712 else 693 else
713 return 0; 694 return 0;
714 } 695 }
715 696
716 function compareFilter(item1, item2) { 697 function compareFilter(item1, item2) {
717 var hasFilter1 = (item1.filter ? 1 : 0); 698 var hasFilter1 = (item1.filter ? 1 : 0);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 return (this.data && this.data.length ? this.data.length : 1); 847 return (this.data && this.data.length ? this.data.length : 1);
867 }, 848 },
868 getCellText: function(row, col) { 849 getCellText: function(row, col) {
869 col = col.id; 850 col = col.id;
870 if (col != "type" && col != "address" && col != "filter" && col != "size" && col != "docDomain" && col != "filterSource") 851 if (col != "type" && col != "address" && col != "filter" && col != "size" && col != "docDomain" && col != "filterSource")
871 return ""; 852 return "";
872 if (this.data && this.data.length) { 853 if (this.data && this.data.length) {
873 if (row >= this.data.length) 854 if (row >= this.data.length)
874 return ""; 855 return "";
875 if (col == "type") 856 if (col == "type")
876 return types.get(this.data[row].type); 857 return localizedTypes.get(this.data[row].type);
877 else if (col == "filter") 858 else if (col == "filter")
878 return (this.data[row].filter ? this.data[row].filter.text : ""); 859 return (this.data[row].filter ? this.data[row].filter.text : "");
879 else if (col == "size") 860 else if (col == "size")
880 { 861 {
881 let size = getItemSize(this.data[row]); 862 let size = getItemSize(this.data[row]);
882 return (size ? size.join(" x ") : ""); 863 return (size ? size.join(" x ") : "");
883 } 864 }
884 else if (col == "docDomain") 865 else if (col == "docDomain")
885 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc DomainThirdParty : docDomainFirstParty); 866 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc DomainThirdParty : docDomainFirstParty);
886 else if (col == "filterSource") 867 else if (col == "filterSource")
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 * @return {Boolean} true if the item should be shown 1162 * @return {Boolean} true if the item should be shown
1182 */ 1163 */
1183 matchesFilter: function(item) 1164 matchesFilter: function(item)
1184 { 1165 {
1185 if (!this.filter) 1166 if (!this.filter)
1186 return true; 1167 return true;
1187 1168
1188 return (item.location.toLowerCase().indexOf(this.filter) >= 0 || 1169 return (item.location.toLowerCase().indexOf(this.filter) >= 0 ||
1189 (item.filter && item.filter.text.toLowerCase().indexOf(this.filter) >= 0) || 1170 (item.filter && item.filter.text.toLowerCase().indexOf(this.filter) >= 0) ||
1190 item.typeDescr.toLowerCase().indexOf(this.filter.replace(/-/g, "_")) >= 0 || 1171 item.typeDescr.toLowerCase().indexOf(this.filter.replace(/-/g, "_")) >= 0 ||
1191 types.get(item.type).toLowerCase().indexOf(this.filter) >= 0 || 1172 localizedTypes.get(item.type).toLowerCase().indexOf(this.filter) >= 0 ||
1192 (item.docDomain && item.docDomain.toLowerCase().indexOf(this.filter) >= 0) || 1173 (item.docDomain && item.docDomain.toLowerCase().indexOf(this.filter) >= 0) ||
1193 (item.docDomain && item.thirdParty && docDomainThirdParty.toLowerCas e().indexOf(this.filter) >= 0) || 1174 (item.docDomain && item.thirdParty && docDomainThirdParty.toLowerCas e().indexOf(this.filter) >= 0) ||
1194 (item.docDomain && !item.thirdParty && docDomainFirstParty.toLowerCa se().indexOf(this.filter) >= 0)); 1175 (item.docDomain && !item.thirdParty && docDomainFirstParty.toLowerCa se().indexOf(this.filter) >= 0));
1195 }, 1176 },
1196 1177
1197 setFilter: function(filter) { 1178 setFilter: function(filter) {
1198 var oldRows = this.rowCount; 1179 var oldRows = this.rowCount;
1199 1180
1200 this.filter = filter.toLowerCase(); 1181 this.filter = filter.toLowerCase();
1201 this.refilter(); 1182 this.refilter();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 return {tooltip: this.itemsDummyTooltip}; 1251 return {tooltip: this.itemsDummyTooltip};
1271 }, 1252 },
1272 1253
1273 invalidateItem: function(item) 1254 invalidateItem: function(item)
1274 { 1255 {
1275 let row = this.data.indexOf(item); 1256 let row = this.data.indexOf(item);
1276 if (row >= 0) 1257 if (row >= 0)
1277 this.boxObject.invalidateRow(row); 1258 this.boxObject.invalidateRow(row);
1278 } 1259 }
1279 } 1260 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld