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

Side by Side Diff: chrome/content/ui/sidebar.js

Issue 29329479: Issue 3222 - Get rid of RequestEntry.typeDescr property (Closed)
Patch Set: Created Oct. 29, 2015, 1:57 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
« no previous file with comments | « chrome/content/ui/sendReport.js ('k') | lib/requestNotifier.js » ('j') | 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 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 E("tooltipTypeRow").hidden = ("tooltip" in item); 254 E("tooltipTypeRow").hidden = ("tooltip" in item);
255 E("tooltipSizeRow").hidden = !size; 255 E("tooltipSizeRow").hidden = !size;
256 E("tooltipDocDomainRow").hidden = ("tooltip" in item || !item.docDomain); 256 E("tooltipDocDomainRow").hidden = ("tooltip" in item || !item.docDomain);
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.type == "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 = types.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.type != "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));
278 } 278 }
279 279
280 if (filter) 280 if (filter)
(...skipping 12 matching lines...) Expand all
293 { 293 {
294 let sourceElement = E("tooltipFilterSource"); 294 let sourceElement = E("tooltipFilterSource");
295 while (sourceElement.firstChild) 295 while (sourceElement.firstChild)
296 sourceElement.removeChild(sourceElement.firstChild); 296 sourceElement.removeChild(sourceElement.firstChild);
297 for (let i = 0; i < subscriptions.length; i++) 297 for (let i = 0; i < subscriptions.length; i++)
298 setMultilineContent(sourceElement, subscriptions[i].title, true); 298 setMultilineContent(sourceElement, subscriptions[i].title, true);
299 } 299 }
300 } 300 }
301 301
302 var showPreview = Prefs.previewimages && !("tooltip" in item); 302 var showPreview = Prefs.previewimages && !("tooltip" in item);
303 showPreview = showPreview && item.typeDescr == "IMAGE"; 303 showPreview = showPreview && item.type == "IMAGE";
304 showPreview = showPreview && (!item.filter || item.filter.disabled || item.fil ter instanceof WhitelistFilter); 304 showPreview = showPreview && (!item.filter || item.filter.disabled || item.fil ter instanceof WhitelistFilter);
305 E("tooltipPreviewBox").hidden = true; 305 E("tooltipPreviewBox").hidden = true;
306 if (showPreview) 306 if (showPreview)
307 { 307 {
308 if (!cacheStorage) 308 if (!cacheStorage)
309 { 309 {
310 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); 310 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null);
311 // Cache v2 API is enabled by default starting with Gecko 32 311 // Cache v2 API is enabled by default starting with Gecko 32
312 if (Services.vc.compare(Utils.platformVersion, "32.0a1") >= 0) 312 if (Services.vc.compare(Utils.platformVersion, "32.0a1") >= 0)
313 { 313 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 410
411 if (domain && !filter.isActiveOnlyOnDomain(domain)) 411 if (domain && !filter.isActiveOnlyOnDomain(domain))
412 { 412 {
413 menuItem = E("contextDisableOnSite"); 413 menuItem = E("contextDisableOnSite");
414 menuItem.setAttribute("label", menuItem.getAttribute("labeltempl").repla ce(/\?1\?/, domain)); 414 menuItem.setAttribute("label", menuItem.getAttribute("labeltempl").repla ce(/\?1\?/, domain));
415 menuItem.hidden = false; 415 menuItem.hidden = false;
416 } 416 }
417 } 417 }
418 } 418 }
419 419
420 E("contextWhitelist").hidden = ("tooltip" in item || !item.filter || item.filt er.disabled || item.filter instanceof WhitelistFilter || item.typeDescr == "ELEM HIDE"); 420 E("contextWhitelist").hidden = ("tooltip" in item || !item.filter || item.filt er.disabled || item.filter instanceof WhitelistFilter || item.type == "ELEMHIDE" );
421 E("contextBlock").hidden = !E("contextWhitelist").hidden; 421 E("contextBlock").hidden = !E("contextWhitelist").hidden;
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.type == "E LEMHIDE");
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.type in visual) || (item.filter && !item.filter.disabled && !(item.filter instanceof Wh itelistFilter)));
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. 432 * Resets context menu data once the context menu is closed.
433 */ 433 */
434 function clearContextMenu(/**Event*/ event) 434 function clearContextMenu(/**Event*/ event)
435 { 435 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 477 }
478 478
479 /** 479 /**
480 * Opens the item in a new tab. 480 * Opens the item in a new tab.
481 */ 481 */
482 function openInTab(item, /**Event*/ event) 482 function openInTab(item, /**Event*/ event)
483 { 483 {
484 let items = (item ? [item] : treeView.getAllSelectedItems()); 484 let items = (item ? [item] : treeView.getAllSelectedItems());
485 for (let item of items) 485 for (let item of items)
486 { 486 {
487 if (item && item.typeDescr != "ELEMHIDE") 487 if (item && item.type != "ELEMHIDE")
488 UI.loadInBrowser(item.location, mainWin, event); 488 UI.loadInBrowser(item.location, mainWin, event);
489 } 489 }
490 } 490 }
491 491
492 function doBlock() { 492 function doBlock() {
493 var item = treeView.getSelectedItem(); 493 var item = treeView.getSelectedItem();
494 if (!item || item.typeDescr == "ELEMHIDE") 494 if (!item || item.type == "ELEMHIDE")
495 return; 495 return;
496 496
497 var filter = null; 497 var filter = null;
498 if (item.filter && !item.filter.disabled) 498 if (item.filter && !item.filter.disabled)
499 filter = item.filter; 499 filter = item.filter;
500 500
501 if (filter && filter instanceof WhitelistFilter) 501 if (filter && filter instanceof WhitelistFilter)
502 return; 502 return;
503 503
504 openDialog("chrome://adblockplus/content/ui/composer.xul", "_blank", "chrome,c enterscreen,resizable,dialog=no,dependent", item.nodes, item.orig); 504 openDialog("chrome://adblockplus/content/ui/composer.xul", "_blank", "chrome,c enterscreen,resizable,dialog=no,dependent", item.nodes, item.orig);
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 } 1095 }
1096 1096
1097 // Add new item to the list 1097 // Add new item to the list
1098 // Store original item in orig property - reading out prototype is messed up in Gecko 1.9.2 1098 // Store original item in orig property - reading out prototype is messed up in Gecko 1.9.2
1099 item = {__proto__: item, orig: item, nodes: [node]}; 1099 item = {__proto__: item, orig: item, nodes: [node]};
1100 this.allData.push(item); 1100 this.allData.push(item);
1101 this.dataMap[key] = item; 1101 this.dataMap[key] = item;
1102 1102
1103 // Show disabled filters if no other filter applies 1103 // Show disabled filters if no other filter applies
1104 if (!item.filter) 1104 if (!item.filter)
1105 item.filter = disabledMatcher.matchesAny(item.location, RegExpFilter.typeM ap[item.typeDescr], item.docDomain, item.thirdParty); 1105 item.filter = disabledMatcher.matchesAny(item.location, RegExpFilter.typeM ap[item.type], item.docDomain, item.thirdParty);
1106 1106
1107 if (!this.matchesFilter(item)) 1107 if (!this.matchesFilter(item))
1108 return; 1108 return;
1109 1109
1110 let index = -1; 1110 let index = -1;
1111 if (this.sortProc && this.sortColumn && this.sortColumn.id == "size") 1111 if (this.sortProc && this.sortColumn && this.sortColumn.id == "size")
1112 { 1112 {
1113 // Sorting by size requires accessing content document, and that's 1113 // Sorting by size requires accessing content document, and that's
1114 // dangerous from a content policy (and we are likely called directly 1114 // dangerous from a content policy (and we are likely called directly
1115 // from a content policy call). Size data will be inaccurate anyway, 1115 // from a content policy call). Size data will be inaccurate anyway,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 this.boxObject.ensureRowIsVisible(this.selection.currentIndex); 1150 this.boxObject.ensureRowIsVisible(this.selection.currentIndex);
1151 }, 1151 },
1152 1152
1153 updateFilters: function() 1153 updateFilters: function()
1154 { 1154 {
1155 for (let item of this.allData) 1155 for (let item of this.allData)
1156 { 1156 {
1157 if (item.filter instanceof RegExpFilter && item.filter.disabled) 1157 if (item.filter instanceof RegExpFilter && item.filter.disabled)
1158 delete item.filter; 1158 delete item.filter;
1159 if (!item.filter) 1159 if (!item.filter)
1160 item.filter = disabledMatcher.matchesAny(item.location, RegExpFilter.typ eMap[item.typeDescr], item.docDomain, item.thirdParty); 1160 item.filter = disabledMatcher.matchesAny(item.location, RegExpFilter.typ eMap[item.type], item.docDomain, item.thirdParty);
1161 } 1161 }
1162 this.refilter(); 1162 this.refilter();
1163 }, 1163 },
1164 1164
1165 /** 1165 /**
1166 * Updates the list after a filter or sorting change. 1166 * Updates the list after a filter or sorting change.
1167 */ 1167 */
1168 refilter: function() 1168 refilter: function()
1169 { 1169 {
1170 if (this.resortTimeout) 1170 if (this.resortTimeout)
1171 clearTimeout(this.resortTimeout); 1171 clearTimeout(this.resortTimeout);
1172 1172
1173 this.data = this.allData.filter(this.matchesFilter, this); 1173 this.data = this.allData.filter(this.matchesFilter, this);
1174 1174
1175 if (this.sortProc) 1175 if (this.sortProc)
1176 this.data.sort(this.sortProc); 1176 this.data.sort(this.sortProc);
1177 }, 1177 },
1178 1178
1179 /** 1179 /**
1180 * Tests whether an item matches current list filter. 1180 * Tests whether an item matches current list filter.
1181 * @return {Boolean} true if the item should be shown 1181 * @return {Boolean} true if the item should be shown
1182 */ 1182 */
1183 matchesFilter: function(item) 1183 matchesFilter: function(item)
1184 { 1184 {
1185 if (!this.filter) 1185 if (!this.filter)
1186 return true; 1186 return true;
1187 1187
1188 return (item.location.toLowerCase().indexOf(this.filter) >= 0 || 1188 return (item.location.toLowerCase().indexOf(this.filter) >= 0 ||
1189 (item.filter && item.filter.text.toLowerCase().indexOf(this.filter) >= 0) || 1189 (item.filter && item.filter.text.toLowerCase().indexOf(this.filter) >= 0) ||
1190 item.typeDescr.toLowerCase().indexOf(this.filter.replace(/-/g, "_")) >= 0 || 1190 item.type.toLowerCase().indexOf(this.filter.replace(/-/g, "_")) >= 0 ||
1191 types.get(item.type).toLowerCase().indexOf(this.filter) >= 0 || 1191 types.get(item.type).toLowerCase().indexOf(this.filter) >= 0 ||
1192 (item.docDomain && item.docDomain.toLowerCase().indexOf(this.filter) >= 0) || 1192 (item.docDomain && item.docDomain.toLowerCase().indexOf(this.filter) >= 0) ||
1193 (item.docDomain && item.thirdParty && docDomainThirdParty.toLowerCas e().indexOf(this.filter) >= 0) || 1193 (item.docDomain && item.thirdParty && docDomainThirdParty.toLowerCas e().indexOf(this.filter) >= 0) ||
1194 (item.docDomain && !item.thirdParty && docDomainFirstParty.toLowerCa se().indexOf(this.filter) >= 0)); 1194 (item.docDomain && !item.thirdParty && docDomainFirstParty.toLowerCa se().indexOf(this.filter) >= 0));
1195 }, 1195 },
1196 1196
1197 setFilter: function(filter) { 1197 setFilter: function(filter) {
1198 var oldRows = this.rowCount; 1198 var oldRows = this.rowCount;
1199 1199
1200 this.filter = filter.toLowerCase(); 1200 this.filter = filter.toLowerCase();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 return {tooltip: this.itemsDummyTooltip}; 1270 return {tooltip: this.itemsDummyTooltip};
1271 }, 1271 },
1272 1272
1273 invalidateItem: function(item) 1273 invalidateItem: function(item)
1274 { 1274 {
1275 let row = this.data.indexOf(item); 1275 let row = this.data.indexOf(item);
1276 if (row >= 0) 1276 if (row >= 0)
1277 this.boxObject.invalidateRow(row); 1277 this.boxObject.invalidateRow(row);
1278 } 1278 }
1279 } 1279 }
OLDNEW
« no previous file with comments | « chrome/content/ui/sendReport.js ('k') | lib/requestNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld