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

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

Issue 29329786: Issue 3258 - Blockable items: fix Size column (Closed)
Left Patch Set: Made getItemSize always call the callback Created Nov. 25, 2015, 10:21 p.m.
Right Patch Set: Cleaner approach: split up getItemSize into sync and async parts Created Nov. 26, 2015, 11:06 a.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 | « no previous file | lib/child/requestNotifier.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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 // Store variables locally, global variables will go away when we are closed 665 // Store variables locally, global variables will go away when we are closed
666 let myPrefs = Prefs; 666 let myPrefs = Prefs;
667 let myMainWin = mainWin; 667 let myMainWin = mainWin;
668 668
669 // Close sidebar and open detached window 669 // Close sidebar and open detached window
670 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); 670 myMainWin.document.getElementById("abp-command-sidebar").doCommand();
671 myPrefs.detachsidebar = doDetach; 671 myPrefs.detachsidebar = doDetach;
672 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); 672 myMainWin.document.getElementById("abp-command-sidebar").doCommand();
673 } 673 }
674 674
675 // Retrieves items size in the document if available 675 // Returns item's size if already known, otherwise undefined
676 function getItemSize(item, callback) 676 function getCachedItemSize(item)
677 { 677 {
678 if ("size" in item) 678 if ("size" in item)
679 return callback(item.size); 679 return item.size;
680 680
681 let filter = getFilter(item); 681 let filter = getFilter(item);
682 if (filter && !filter.disabled && filter instanceof BlockingFilter) 682 if (filter && !filter.disabled && filter instanceof BlockingFilter)
683 return callback(null); 683 return null;
684 684
685 if (requestNotifier) 685 return undefined;
686 { 686 }
687 requestNotifier.retrieveNodeSize(item.ids, function(size) 687
688 { 688 // Retrieves item's size in the document if available
689 function getItemSize(item, callback)
690 {
691 let size = getCachedItemSize(item);
692 if (typeof size != "undefined" || !requestNotifier)
693 {
694 callback(size);
695 return;
696 }
697
698 requestNotifier.retrieveNodeSize(item.ids, function(size)
699 {
700 if (size)
689 item.size = size; 701 item.size = size;
690 callback(size); 702 callback(size);
691 }); 703 });
692 }
693 } 704 }
694 705
695 // Sort functions for the item list 706 // Sort functions for the item list
696 function sortByAddress(item1, item2) { 707 function sortByAddress(item1, item2) {
697 if (item1.location < item2.location) 708 if (item1.location < item2.location)
698 return -1; 709 return -1;
699 else if (item1.location > item2.location) 710 else if (item1.location > item2.location)
700 return 1; 711 return 1;
701 else 712 else
702 return 0; 713 return 0;
(...skipping 29 matching lines...) Expand all
732 743
733 function compareState(item1, item2) 744 function compareState(item1, item2)
734 { 745 {
735 let filter1 = getFilter(item1); 746 let filter1 = getFilter(item1);
736 let filter2 = getFilter(item2); 747 let filter2 = getFilter(item2);
737 let state1 = (!filter1 ? 0 : (filter1.disabled ? 1 : (filter1 instanceof White listFilter ? 2 : 3))); 748 let state1 = (!filter1 ? 0 : (filter1.disabled ? 1 : (filter1 instanceof White listFilter ? 2 : 3)));
738 let state2 = (!filter2 ? 0 : (filter2.disabled ? 1 : (filter2 instanceof White listFilter ? 2 : 3))); 749 let state2 = (!filter2 ? 0 : (filter2.disabled ? 1 : (filter2 instanceof White listFilter ? 2 : 3)));
739 return state1 - state2; 750 return state1 - state2;
740 } 751 }
741 752
742 function compareSize(item1, item2) { 753 function compareSize(item1, item2)
743 let size1; 754 {
744 let size2; 755 let size1 = getCachedItemSize(item1);
745 getItemSize(item1, (size) => size1 = size); 756 let size2 = getCachedItemSize(item2);
746 getItemSize(item2, (size) => size2 = size);
747 757
748 size1 = size1 ? size1[0] * size1[1] : 0; 758 size1 = size1 ? size1[0] * size1[1] : 0;
749 size2 = size2 ? size2[0] * size2[1] : 0; 759 size2 = size2 ? size2[0] * size2[1] : 0;
750 return size1 - size2; 760 return size1 - size2;
751 } 761 }
752 762
753 function compareDocDomain(item1, item2) 763 function compareDocDomain(item1, item2)
754 { 764 {
755 if (item1.docDomain < item2.docDomain) 765 if (item1.docDomain < item2.docDomain)
756 return -1; 766 return -1;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 return ""; 892 return "";
883 if (this.data && this.data.length) { 893 if (this.data && this.data.length) {
884 if (row >= this.data.length) 894 if (row >= this.data.length)
885 return ""; 895 return "";
886 if (col == "type") 896 if (col == "type")
887 return localizedTypes.get(this.data[row].type); 897 return localizedTypes.get(this.data[row].type);
888 else if (col == "filter") 898 else if (col == "filter")
889 return (this.data[row].filter || ""); 899 return (this.data[row].filter || "");
890 else if (col == "size") 900 else if (col == "size")
891 { 901 {
892 let result; 902 let size = getCachedItemSize(this.data[row]);
893 getItemSize(this.data[row], (size) => 903 if (typeof size == "undefined")
894 { 904 {
895 if (typeof result == "undefined") 905 getItemSize(this.data[row], (size) =>
896 result = size; 906 {
897 else 907 if (size)
898 this.boxObject.invalidateRow(row) 908 this.boxObject.invalidateRow(row)
899 }); 909 });
900 result = (result ? result.join(" x ") : ""); 910 }
901 return result; 911 return (size ? size.join(" x ") : "");
902 } 912 }
903 else if (col == "docDomain") 913 else if (col == "docDomain")
904 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc DomainThirdParty : docDomainFirstParty); 914 return this.data[row].docDomain + " " + (this.data[row].thirdParty ? doc DomainThirdParty : docDomainFirstParty);
905 else if (col == "filterSource") 915 else if (col == "filterSource")
906 { 916 {
907 let filter = getFilter(this.data[row]) 917 let filter = getFilter(this.data[row])
908 if (!filter) 918 if (!filter)
909 return ""; 919 return "";
910 920
911 return filter.subscriptions.filter(s => !s.disabled).map(s => s.title).j oin(", "); 921 return filter.subscriptions.filter(s => !s.disabled).map(s => s.title).j oin(", ");
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 return {tooltip: this.itemsDummyTooltip}; 1309 return {tooltip: this.itemsDummyTooltip};
1300 }, 1310 },
1301 1311
1302 invalidateItem: function(item) 1312 invalidateItem: function(item)
1303 { 1313 {
1304 let row = this.data.indexOf(item); 1314 let row = this.data.indexOf(item);
1305 if (row >= 0) 1315 if (row >= 0)
1306 this.boxObject.invalidateRow(row); 1316 this.boxObject.invalidateRow(row);
1307 } 1317 }
1308 } 1318 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld