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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 types.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 function getFilter(item) | |
118 { | |
119 if ("filter" in item && item.filter) | |
tschuster
2015/11/12 15:32:05
"filter" in item is not strictly necessary.
Wladimir Palant
2015/11/12 15:46:55
Yes, I know but I didn't feel like changing that.
| |
120 return Filter.fromText(item.filter); | |
121 else | |
122 return null; | |
123 } | |
124 | |
117 // To be called on unload | 125 // To be called on unload |
118 function cleanUp() { | 126 function cleanUp() { |
119 flasher.stop(); | 127 flasher.stop(); |
120 requestNotifier.shutdown(); | 128 requestNotifier.shutdown(); |
121 FilterNotifier.removeListener(reloadDisabledFilters); | 129 FilterNotifier.removeListener(reloadDisabledFilters); |
122 Prefs.removeListener(onPrefChange); | 130 Prefs.removeListener(onPrefChange); |
123 E("list").view = null; | 131 E("list").view = null; |
124 | 132 |
125 let {removeBrowserLocationListener} = require("appSupport"); | 133 let {removeBrowserLocationListener} = require("appSupport"); |
126 if (removeBrowserLocationListener) | 134 if (removeBrowserLocationListener) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 if (!noFlash) | 201 if (!noFlash) |
194 flasher.flash(item ? item.nodes : null); | 202 flasher.flash(item ? item.nodes : null); |
195 } | 203 } |
196 | 204 |
197 function handleLocationChange() | 205 function handleLocationChange() |
198 { | 206 { |
199 if (requestNotifier) | 207 if (requestNotifier) |
200 requestNotifier.shutdown(); | 208 requestNotifier.shutdown(); |
201 | 209 |
202 treeView.clearData(); | 210 treeView.clearData(); |
211 | |
212 let {getBrowser, addBrowserLocationListener} = require("appSupport"); | |
213 let browser = getBrowser(mainWin); | |
214 if ("selectedBrowser" in browser) | |
215 browser = browser.selectedBrowser; | |
216 let outerWindowID = browser.outerWindowID; | |
203 treeView.itemToSelect = RequestNotifier.getSelection(window.content); | 217 treeView.itemToSelect = RequestNotifier.getSelection(window.content); |
204 requestNotifier = new RequestNotifier(window.content, function(wnd, node, item , scanComplete) | 218 requestNotifier = new RequestNotifier(outerWindowID, function(item, scanComple te) |
205 { | 219 { |
206 if (item) | 220 if (item) |
207 treeView.addItem(node, item, scanComplete); | 221 treeView.addItem(item, scanComplete); |
208 }); | 222 }); |
209 cacheStorage = null; | 223 cacheStorage = null; |
210 } | 224 } |
211 | 225 |
212 // Fills a box with text splitting it up into multiple lines if necessary | 226 // Fills a box with text splitting it up into multiple lines if necessary |
213 function setMultilineContent(box, text, noRemove) | 227 function setMultilineContent(box, text, noRemove) |
214 { | 228 { |
215 if (!noRemove) | 229 if (!noRemove) |
216 while (box.firstChild) | 230 while (box.firstChild) |
217 box.removeChild(box.firstChild); | 231 box.removeChild(box.firstChild); |
(...skipping 20 matching lines...) Expand all Loading... | |
238 item = treeView.getDummyTooltip(); | 252 item = treeView.getDummyTooltip(); |
239 else | 253 else |
240 item = treeView.getItemAt(e.clientX, e.clientY); | 254 item = treeView.getItemAt(e.clientX, e.clientY); |
241 | 255 |
242 if (!item) | 256 if (!item) |
243 { | 257 { |
244 e.preventDefault(); | 258 e.preventDefault(); |
245 return; | 259 return; |
246 } | 260 } |
247 | 261 |
248 let filter = ("filter" in item && item.filter ? item.filter : null); | 262 let filter = getFilter(item); |
249 let size = ("tooltip" in item ? null : getItemSize(item)); | 263 let size = ("tooltip" in item ? null : getItemSize(item)); |
250 let subscriptions = (filter ? filter.subscriptions.filter(function(subscriptio n) { return !subscription.disabled; }) : []); | 264 let subscriptions = (filter ? filter.subscriptions.filter(function(subscriptio n) { return !subscription.disabled; }) : []); |
251 | 265 |
252 E("tooltipDummy").hidden = !("tooltip" in item); | 266 E("tooltipDummy").hidden = !("tooltip" in item); |
253 E("tooltipAddressRow").hidden = ("tooltip" in item); | 267 E("tooltipAddressRow").hidden = ("tooltip" in item); |
254 E("tooltipTypeRow").hidden = ("tooltip" in item); | 268 E("tooltipTypeRow").hidden = ("tooltip" in item); |
255 E("tooltipSizeRow").hidden = !size; | 269 E("tooltipSizeRow").hidden = !size; |
256 E("tooltipDocDomainRow").hidden = ("tooltip" in item || !item.docDomain); | 270 E("tooltipDocDomainRow").hidden = ("tooltip" in item || !item.docDomain); |
257 E("tooltipFilterRow").hidden = !filter; | 271 E("tooltipFilterRow").hidden = !filter; |
258 E("tooltipFilterSourceRow").hidden = !subscriptions.length; | 272 E("tooltipFilterSourceRow").hidden = !subscriptions.length; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 let sourceElement = E("tooltipFilterSource"); | 308 let sourceElement = E("tooltipFilterSource"); |
295 while (sourceElement.firstChild) | 309 while (sourceElement.firstChild) |
296 sourceElement.removeChild(sourceElement.firstChild); | 310 sourceElement.removeChild(sourceElement.firstChild); |
297 for (let i = 0; i < subscriptions.length; i++) | 311 for (let i = 0; i < subscriptions.length; i++) |
298 setMultilineContent(sourceElement, subscriptions[i].title, true); | 312 setMultilineContent(sourceElement, subscriptions[i].title, true); |
299 } | 313 } |
300 } | 314 } |
301 | 315 |
302 var showPreview = Prefs.previewimages && !("tooltip" in item); | 316 var showPreview = Prefs.previewimages && !("tooltip" in item); |
303 showPreview = showPreview && item.type == "IMAGE"; | 317 showPreview = showPreview && item.type == "IMAGE"; |
304 showPreview = showPreview && (!item.filter || item.filter.disabled || item.fil ter instanceof WhitelistFilter); | 318 showPreview = showPreview && (!filter || filter.disabled || filter instanceof WhitelistFilter); |
305 E("tooltipPreviewBox").hidden = true; | 319 E("tooltipPreviewBox").hidden = true; |
306 if (showPreview) | 320 if (showPreview) |
307 { | 321 { |
308 if (!cacheStorage) | 322 if (!cacheStorage) |
309 { | 323 { |
310 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); | 324 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); |
311 // Cache v2 API is enabled by default starting with Gecko 32 | 325 // Cache v2 API is enabled by default starting with Gecko 32 |
312 if (Services.vc.compare(Utils.platformVersion, "32.0a1") >= 0) | 326 if (Services.vc.compare(Utils.platformVersion, "32.0a1") >= 0) |
313 { | 327 { |
314 let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInf o.jsm", null); | 328 let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInf o.jsm", null); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 item = treeView.getItemAt(e.clientX, e.clientY); | 401 item = treeView.getItemAt(e.clientX, e.clientY); |
388 allItems = treeView.getAllSelectedItems(); | 402 allItems = treeView.getAllSelectedItems(); |
389 } | 403 } |
390 | 404 |
391 if (!item || ("tooltip" in item && !("filter" in item))) | 405 if (!item || ("tooltip" in item && !("filter" in item))) |
392 return false; | 406 return false; |
393 | 407 |
394 E("contextDisableFilter").hidden = true; | 408 E("contextDisableFilter").hidden = true; |
395 E("contextEnableFilter").hidden = true; | 409 E("contextEnableFilter").hidden = true; |
396 E("contextDisableOnSite").hidden = true; | 410 E("contextDisableOnSite").hidden = true; |
397 if ("filter" in item && item.filter) | 411 let filter = getFilter(item); |
412 if (filter) | |
398 { | 413 { |
399 let filter = item.filter; | |
400 let menuItem = E(filter.disabled ? "contextEnableFilter" : "contextDisableFi lter"); | 414 let menuItem = E(filter.disabled ? "contextEnableFilter" : "contextDisableFi lter"); |
401 menuItem.setAttribute("label", menuItem.getAttribute("labeltempl").replace(/ \?1\?/, filter.text)); | 415 menuItem.setAttribute("label", menuItem.getAttribute("labeltempl").replace(/ \?1\?/, filter.text)); |
402 menuItem.hidden = false; | 416 menuItem.hidden = false; |
403 | 417 |
404 if (filter instanceof ActiveFilter && !filter.disabled && filter.subscriptio ns.length && !filter.subscriptions.some(subscription => !(subscription instanceo f SpecialSubscription))) | 418 if (filter instanceof ActiveFilter && !filter.disabled && filter.subscriptio ns.length && !filter.subscriptions.some(subscription => !(subscription instanceo f SpecialSubscription))) |
405 { | 419 { |
406 let domain = null; | 420 let domain = null; |
407 try { | 421 try { |
408 domain = Utils.effectiveTLD.getBaseDomainFromHost(item.docDomain); | 422 domain = Utils.effectiveTLD.getBaseDomainFromHost(item.docDomain); |
409 } catch (e) {} | 423 } catch (e) {} |
410 | 424 |
411 if (domain && !filter.isActiveOnlyOnDomain(domain)) | 425 if (domain && !filter.isActiveOnlyOnDomain(domain)) |
412 { | 426 { |
413 menuItem = E("contextDisableOnSite"); | 427 menuItem = E("contextDisableOnSite"); |
414 menuItem.setAttribute("label", menuItem.getAttribute("labeltempl").repla ce(/\?1\?/, domain)); | 428 menuItem.setAttribute("label", menuItem.getAttribute("labeltempl").repla ce(/\?1\?/, domain)); |
415 menuItem.hidden = false; | 429 menuItem.hidden = false; |
416 } | 430 } |
417 } | 431 } |
418 } | 432 } |
419 | 433 |
420 E("contextWhitelist").hidden = ("tooltip" in item || !item.filter || item.filt er.disabled || item.filter instanceof WhitelistFilter || item.type == "ELEMHIDE" ); | 434 E("contextWhitelist").hidden = ("tooltip" in item || !filter || filter.disable d || filter instanceof WhitelistFilter || item.type == "ELEMHIDE"); |
421 E("contextBlock").hidden = !E("contextWhitelist").hidden; | 435 E("contextBlock").hidden = !E("contextWhitelist").hidden; |
422 E("contextBlock").setAttribute("disabled", "filter" in item && item.filter && !item.filter.disabled); | 436 E("contextBlock").setAttribute("disabled", filter && !filter.disabled); |
423 E("contextEditFilter").setAttribute("disabled", !("filter" in item && item.fil ter)); | 437 E("contextEditFilter").setAttribute("disabled", !filter); |
424 E("contextOpen").setAttribute("disabled", "tooltip" in item || item.type == "E LEMHIDE"); | 438 E("contextOpen").setAttribute("disabled", "tooltip" in item || item.type == "E LEMHIDE"); |
425 E("contextFlash").setAttribute("disabled", "tooltip" in item || !(item.type in visual) || (item.filter && !item.filter.disabled && !(item.filter instanceof Wh itelistFilter))); | 439 E("contextFlash").setAttribute("disabled", "tooltip" in item || !(item.type in visual) || (filter && !filter.disabled && !(filter instanceof WhitelistFilter)) ); |
426 E("contextCopyFilter").setAttribute("disabled", !allItems.some(function(item) {return "filter" in item && item.filter})); | 440 E("contextCopyFilter").setAttribute("disabled", !allItems.some(getFilter)); |
427 | 441 |
428 return true; | 442 return true; |
429 } | 443 } |
430 | 444 |
431 /** | 445 /** |
432 * Processed mouse clicks on the item list. | 446 * Processed mouse clicks on the item list. |
433 * @param {Event} event | 447 * @param {Event} event |
434 */ | 448 */ |
435 function handleClick(event) | 449 function handleClick(event) |
436 { | 450 { |
437 let item = treeView.getItemAt(event.clientX, event.clientY); | 451 let item = treeView.getItemAt(event.clientX, event.clientY); |
438 if (event.button == 0 && treeView.getColumnAt(event.clientX, event.clientY) == "state") | 452 if (event.button == 0 && treeView.getColumnAt(event.clientX, event.clientY) == "state") |
439 { | 453 { |
440 if (item.filter) | 454 let filter = getFilter(item); |
441 enableFilter(item.filter, item.filter.disabled); | 455 if (filter) |
456 enableFilter(filter, filter.disabled); | |
442 event.preventDefault(); | 457 event.preventDefault(); |
443 } | 458 } |
444 else if (event.button == 1) | 459 else if (event.button == 1) |
445 { | 460 { |
446 openInTab(item, event); | 461 openInTab(item, event); |
447 event.preventDefault(); | 462 event.preventDefault(); |
448 } | 463 } |
449 } | 464 } |
450 | 465 |
451 /** | 466 /** |
(...skipping 19 matching lines...) Expand all Loading... | |
471 if (item && item.type != "ELEMHIDE") | 486 if (item && item.type != "ELEMHIDE") |
472 UI.loadInBrowser(item.location, mainWin, event); | 487 UI.loadInBrowser(item.location, mainWin, event); |
473 } | 488 } |
474 } | 489 } |
475 | 490 |
476 function doBlock() { | 491 function doBlock() { |
477 var item = treeView.getSelectedItem(); | 492 var item = treeView.getSelectedItem(); |
478 if (!item || item.type == "ELEMHIDE") | 493 if (!item || item.type == "ELEMHIDE") |
479 return; | 494 return; |
480 | 495 |
481 var filter = null; | 496 var filter = getFilter(item); |
482 if (item.filter && !item.filter.disabled) | 497 if (filter && !filter.disabled && filter instanceof WhitelistFilter) |
483 filter = item.filter; | |
484 | |
485 if (filter && filter instanceof WhitelistFilter) | |
486 return; | 498 return; |
487 | 499 |
488 openDialog("chrome://adblockplus/content/ui/composer.xul", "_blank", "chrome,c enterscreen,resizable,dialog=no,dependent", item.nodes, item.orig); | 500 openDialog("chrome://adblockplus/content/ui/composer.xul", "_blank", "chrome,c enterscreen,resizable,dialog=no,dependent", item.nodes, item.orig); |
489 } | 501 } |
490 | 502 |
491 function editFilter() | 503 function editFilter() |
492 { | 504 { |
493 var item = treeView.getSelectedItem(); | 505 var item = treeView.getSelectedItem(); |
494 if (treeView.data && !treeView.data.length) | 506 if (treeView.data && !treeView.data.length) |
495 item = treeView.getDummyTooltip(); | 507 item = treeView.getDummyTooltip(); |
496 | 508 |
497 if (!("filter" in item) || !item.filter) | 509 let filter = getFilter(item); |
510 if (!filter) | |
498 return; | 511 return; |
499 | 512 |
500 UI.openFiltersDialog(item.filter); | 513 UI.openFiltersDialog(filter); |
501 } | 514 } |
502 | 515 |
503 function enableFilter(filter, enable) { | 516 function enableFilter(filter, enable) { |
504 filter.disabled = !enable; | 517 filter.disabled = !enable; |
505 | 518 |
506 treeView.boxObject.invalidate(); | 519 treeView.boxObject.invalidate(); |
507 } | 520 } |
508 | 521 |
509 /** | 522 /** |
510 * Edits the filter to disable it on a particular domain. | 523 * Edits the filter to disable it on a particular domain. |
511 */ | 524 */ |
512 function disableOnSite() | 525 function disableOnSite() |
513 { | 526 { |
514 let item = treeView.getSelectedItem(); | 527 let item = treeView.getSelectedItem(); |
515 let filter = item.filter; | 528 let filter = getFilter(item); |
516 if (!(filter instanceof ActiveFilter) || filter.disabled || !filter.subscripti ons.length || filter.subscriptions.some(subscription => !(subscription instanceo f SpecialSubscription))) | 529 if (!(filter instanceof ActiveFilter) || filter.disabled || !filter.subscripti ons.length || filter.subscriptions.some(subscription => !(subscription instanceo f SpecialSubscription))) |
517 return; | 530 return; |
518 | 531 |
519 let domain; | 532 let domain; |
520 try { | 533 try { |
521 domain = Utils.effectiveTLD.getBaseDomainFromHost(item.docDomain).toUpperCas e(); | 534 domain = Utils.effectiveTLD.getBaseDomainFromHost(item.docDomain).toUpperCas e(); |
522 } | 535 } |
523 catch (e) | 536 catch (e) |
524 { | 537 { |
525 return; | 538 return; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 { | 592 { |
580 newFilter.disabled = false; | 593 newFilter.disabled = false; |
581 let subscription = filter.subscriptions.filter(s => s instanceof SpecialSubs cription)[0]; | 594 let subscription = filter.subscriptions.filter(s => s instanceof SpecialSubs cription)[0]; |
582 if (subscription) | 595 if (subscription) |
583 FilterStorage.addFilter(newFilter, subscription, subscription.filters.inde xOf(filter)); | 596 FilterStorage.addFilter(newFilter, subscription, subscription.filters.inde xOf(filter)); |
584 } | 597 } |
585 FilterStorage.removeFilter(filter); | 598 FilterStorage.removeFilter(filter); |
586 | 599 |
587 // Update display | 600 // Update display |
588 for (let i = 0; i < treeView.allData.length; i++) | 601 for (let i = 0; i < treeView.allData.length; i++) |
589 if (treeView.allData[i].filter == filter) | 602 if (getFilter(treeView.allData[i]) == filter) |
590 treeView.allData[i].filter = null; | 603 treeView.allData[i].filter = null; |
591 treeView.boxObject.invalidate(); | 604 treeView.boxObject.invalidate(); |
592 } | 605 } |
593 | 606 |
594 function copyToClipboard() { | 607 function copyToClipboard() { |
595 var items = treeView.getAllSelectedItems(); | 608 var items = treeView.getAllSelectedItems(); |
596 if (!items.length) | 609 if (!items.length) |
597 return; | 610 return; |
598 | 611 |
599 Utils.clipboardHelper.copyString(items.map(function(item) {return item.locatio n}).join(IO.lineBreak)); | 612 Utils.clipboardHelper.copyString(items.map(function(item) {return item.locatio n}).join(IO.lineBreak)); |
600 } | 613 } |
601 | 614 |
602 function copyFilter() { | 615 function copyFilter() { |
603 var items = treeView.getAllSelectedItems().filter(function(item) {return item. filter}); | 616 var items = treeView.getAllSelectedItems().filter(getFilter); |
604 if (treeView.data && !treeView.data.length) | 617 if (treeView.data && !treeView.data.length) |
605 items = [treeView.getDummyTooltip()]; | 618 items = [treeView.getDummyTooltip()]; |
606 | 619 |
607 if (!items.length) | 620 if (!items.length) |
608 return; | 621 return; |
609 | 622 |
610 Utils.clipboardHelper.copyString(items.map(function(item) {return item.filter. text}).join(IO.lineBreak)); | 623 Utils.clipboardHelper.copyString(items.map(function(item) {return item.filter} ).join(IO.lineBreak)); |
611 } | 624 } |
612 | 625 |
613 function selectAll() { | 626 function selectAll() { |
614 treeView.selectAll(); | 627 treeView.selectAll(); |
615 } | 628 } |
616 | 629 |
617 // Saves sidebar's state before detaching/reattaching | 630 // Saves sidebar's state before detaching/reattaching |
618 function saveState() { | 631 function saveState() { |
619 var focused = document.commandDispatcher.focusedElement; | 632 var focused = document.commandDispatcher.focusedElement; |
620 while (focused && (!focused.id || !("focus" in focused))) | 633 while (focused && (!focused.id || !("focus" in focused))) |
(...skipping 28 matching lines...) Expand all Loading... | |
649 | 662 |
650 // Close sidebar and open detached window | 663 // Close sidebar and open detached window |
651 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); | 664 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); |
652 myPrefs.detachsidebar = doDetach; | 665 myPrefs.detachsidebar = doDetach; |
653 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); | 666 myMainWin.document.getElementById("abp-command-sidebar").doCommand(); |
654 } | 667 } |
655 | 668 |
656 // Returns items size in the document if available | 669 // Returns items size in the document if available |
657 function getItemSize(item) | 670 function getItemSize(item) |
658 { | 671 { |
659 if (item.filter && !item.filter.disabled && item.filter instanceof BlockingFil ter) | 672 let filter = getFilter(item); |
673 if (filter && !filter.disabled && filter instanceof BlockingFilter) | |
660 return null; | 674 return null; |
661 | 675 |
662 for (let node of item.nodes) | 676 for (let node of item.nodes) |
663 { | 677 { |
664 if (node instanceof HTMLImageElement && (node.naturalWidth || node.naturalHe ight)) | 678 if (node instanceof HTMLImageElement && (node.naturalWidth || node.naturalHe ight)) |
665 return [node.naturalWidth, node.naturalHeight]; | 679 return [node.naturalWidth, node.naturalHeight]; |
666 else if (node instanceof HTMLElement && (node.offsetWidth || node.offsetHeig ht)) | 680 else if (node instanceof HTMLElement && (node.offsetWidth || node.offsetHeig ht)) |
667 return [node.offsetWidth, node.offsetHeight]; | 681 return [node.offsetWidth, node.offsetHeight]; |
668 } | 682 } |
669 return null; | 683 return null; |
(...skipping 22 matching lines...) Expand all Loading... | |
692 return 1; | 706 return 1; |
693 else | 707 else |
694 return 0; | 708 return 0; |
695 } | 709 } |
696 | 710 |
697 function compareFilter(item1, item2) { | 711 function compareFilter(item1, item2) { |
698 var hasFilter1 = (item1.filter ? 1 : 0); | 712 var hasFilter1 = (item1.filter ? 1 : 0); |
699 var hasFilter2 = (item2.filter ? 1 : 0); | 713 var hasFilter2 = (item2.filter ? 1 : 0); |
700 if (hasFilter1 != hasFilter2) | 714 if (hasFilter1 != hasFilter2) |
701 return hasFilter1 - hasFilter2; | 715 return hasFilter1 - hasFilter2; |
702 else if (hasFilter1 && item1.filter.text < item2.filter.text) | 716 else if (hasFilter1 && item1.filter < item2.filter) |
703 return -1; | 717 return -1; |
704 else if (hasFilter1 && item1.filter.text > item2.filter.text) | 718 else if (hasFilter1 && item1.filter > item2.filter) |
705 return 1; | 719 return 1; |
706 else | 720 else |
707 return 0; | 721 return 0; |
708 } | 722 } |
709 | 723 |
710 function compareState(item1, item2) { | 724 function compareState(item1, item2) |
711 var state1 = (!item1.filter ? 0 : (item1.filter.disabled ? 1 : (item1.filter i nstanceof WhitelistFilter ? 2 : 3))); | 725 { |
712 var state2 = (!item2.filter ? 0 : (item2.filter.disabled ? 1 : (item2.filter i nstanceof WhitelistFilter ? 2 : 3))); | 726 let filter1 = getFilter(item1); |
727 let filter2 = getFilter(item2); | |
728 let state1 = (!filter1 ? 0 : (filter1.disabled ? 1 : (filter1 instanceof White listFilter ? 2 : 3))); | |
729 let state2 = (!filter2 ? 0 : (filter2.disabled ? 1 : (filter2 instanceof White listFilter ? 2 : 3))); | |
713 return state1 - state2; | 730 return state1 - state2; |
714 } | 731 } |
715 | 732 |
716 function compareSize(item1, item2) { | 733 function compareSize(item1, item2) { |
717 var size1 = getItemSize(item1); | 734 var size1 = getItemSize(item1); |
718 size1 = size1 ? size1[0] * size1[1] : 0; | 735 size1 = size1 ? size1[0] * size1[1] : 0; |
719 | 736 |
720 var size2 = getItemSize(item2); | 737 var size2 = getItemSize(item2); |
721 size2 = size2 ? size2[0] * size2[1] : 0; | 738 size2 = size2 ? size2[0] * size2[1] : 0; |
722 return size1 - size2; | 739 return size1 - size2; |
723 } | 740 } |
724 | 741 |
725 function compareDocDomain(item1, item2) | 742 function compareDocDomain(item1, item2) |
726 { | 743 { |
727 if (item1.docDomain < item2.docDomain) | 744 if (item1.docDomain < item2.docDomain) |
728 return -1; | 745 return -1; |
729 else if (item1.docDomain > item2.docDomain) | 746 else if (item1.docDomain > item2.docDomain) |
730 return 1; | 747 return 1; |
731 else if (item1.thirdParty && !item2.thirdParty) | 748 else if (item1.thirdParty && !item2.thirdParty) |
732 return -1; | 749 return -1; |
733 else if (!item1.thirdParty && item2.thirdParty) | 750 else if (!item1.thirdParty && item2.thirdParty) |
734 return 1; | 751 return 1; |
735 else | 752 else |
736 return 0; | 753 return 0; |
737 } | 754 } |
738 | 755 |
739 function compareFilterSource(item1, item2) | 756 function compareFilterSource(item1, item2) |
740 { | 757 { |
741 let subs1 = item1.filter ? item1.filter.subscriptions.map(s => s.title).join(" , ") : ""; | 758 let filter1 = getFilter(item1); |
742 let subs2 = item2.filter ? item2.filter.subscriptions.map(s => s.title).join(" , ") : ""; | 759 let filter2 = getFilter(item2); |
760 let subs1 = filter1 ? filter1.subscriptions.map(s => s.title).join(", ") : ""; | |
761 let subs2 = filter2 ? filter2.subscriptions.map(s => s.title).join(", ") : ""; | |
743 if (subs1 < subs2) | 762 if (subs1 < subs2) |
744 return -1; | 763 return -1; |
745 else if (subs1 > subs2) | 764 else if (subs1 > subs2) |
746 return 1; | 765 return 1; |
747 else | 766 else |
748 return 0; | 767 return 0; |
749 } | 768 } |
750 | 769 |
751 function createSortWithFallback(cmpFunc, fallbackFunc, desc) { | 770 function createSortWithFallback(cmpFunc, fallbackFunc, desc) { |
752 var factor = (desc ? -1 : 1); | 771 var factor = (desc ? -1 : 1); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 getCellText: function(row, col) { | 868 getCellText: function(row, col) { |
850 col = col.id; | 869 col = col.id; |
851 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") |
852 return ""; | 871 return ""; |
853 if (this.data && this.data.length) { | 872 if (this.data && this.data.length) { |
854 if (row >= this.data.length) | 873 if (row >= this.data.length) |
855 return ""; | 874 return ""; |
856 if (col == "type") | 875 if (col == "type") |
857 return types.get(this.data[row].type); | 876 return types.get(this.data[row].type); |
858 else if (col == "filter") | 877 else if (col == "filter") |
859 return (this.data[row].filter ? this.data[row].filter.text : ""); | 878 return (this.data[row].filter || ""); |
860 else if (col == "size") | 879 else if (col == "size") |
861 { | 880 { |
862 let size = getItemSize(this.data[row]); | 881 let size = getItemSize(this.data[row]); |
863 return (size ? size.join(" x ") : ""); | 882 return (size ? size.join(" x ") : ""); |
864 } | 883 } |
865 else if (col == "docDomain") | 884 else if (col == "docDomain") |
866 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); |
867 else if (col == "filterSource") | 886 else if (col == "filterSource") |
868 { | 887 { |
869 if (!this.data[row].filter) | 888 let filter = getFilter(this.data[row]) |
889 if (!filter) | |
870 return ""; | 890 return ""; |
871 | 891 |
872 return this.data[row].filter.subscriptions.filter(s => !s.disabled).map( s => s.title).join(", "); | 892 return filter.subscriptions.filter(s => !s.disabled).map(s => s.title).j oin(", "); |
873 } | 893 } |
874 else | 894 else |
875 return this.data[row].location; | 895 return this.data[row].location; |
876 } | 896 } |
877 else { | 897 else { |
878 // Empty list, show dummy | 898 // Empty list, show dummy |
879 if (row > 0 || (col != "address" && col != "filter")) | 899 if (row > 0 || (col != "address" && col != "filter")) |
880 return ""; | 900 return ""; |
881 if (col == "filter") { | 901 if (col == "filter") { |
882 var filter = Policy.isWindowWhitelisted(window.content); | 902 var filter = Policy.isWindowWhitelisted(window.content); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 if (row >= this.rowCount) | 935 if (row >= this.rowCount) |
916 return ""; | 936 return ""; |
917 | 937 |
918 let list = []; | 938 let list = []; |
919 list.push("selected-" + this.selection.isSelected(row)); | 939 list.push("selected-" + this.selection.isSelected(row)); |
920 | 940 |
921 let state; | 941 let state; |
922 if (this.data && this.data.length) { | 942 if (this.data && this.data.length) { |
923 list.push("dummy-false"); | 943 list.push("dummy-false"); |
924 | 944 |
925 let filter = this.data[row].filter; | 945 let filter = getFilter(this.data[row]); |
926 if (filter) | 946 if (filter) |
927 list.push("filter-disabled-" + filter.disabled); | 947 list.push("filter-disabled-" + filter.disabled); |
928 | 948 |
929 state = "state-regular"; | 949 state = "state-regular"; |
930 if (filter && !filter.disabled) | 950 if (filter && !filter.disabled) |
931 { | 951 { |
932 if (filter instanceof WhitelistFilter) | 952 if (filter instanceof WhitelistFilter) |
933 state = "state-whitelisted"; | 953 state = "state-whitelisted"; |
934 else if (filter instanceof BlockingFilter) | 954 else if (filter instanceof BlockingFilter) |
935 state = "state-filtered"; | 955 state = "state-filtered"; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1052 clearData: function(data) { | 1072 clearData: function(data) { |
1053 var oldRows = this.rowCount; | 1073 var oldRows = this.rowCount; |
1054 this.allData = []; | 1074 this.allData = []; |
1055 this.dataMap = Object.create(null); | 1075 this.dataMap = Object.create(null); |
1056 this.refilter(); | 1076 this.refilter(); |
1057 | 1077 |
1058 this.boxObject.rowCountChanged(0, -oldRows); | 1078 this.boxObject.rowCountChanged(0, -oldRows); |
1059 this.boxObject.rowCountChanged(0, this.rowCount); | 1079 this.boxObject.rowCountChanged(0, this.rowCount); |
1060 }, | 1080 }, |
1061 | 1081 |
1062 addItem: function(/**Node*/ node, /**RequestEntry*/ item, /**Boolean*/ scanCom plete) | 1082 addItem: function(/**RequestEntry*/ item, /**Boolean*/ scanComplete) |
1063 { | 1083 { |
1064 // Merge duplicate entries | 1084 // Merge duplicate entries |
1065 let key = item.location + " " + item.type + " " + item.docDomain; | 1085 let key = item.location + " " + item.type + " " + item.docDomain; |
1066 if (key in this.dataMap) | 1086 if (key in this.dataMap) |
1067 { | 1087 { |
1068 // We know this item already - take over the filter if any and be done wit h it | 1088 // We know this item already - take over the filter if any and be done wit h it |
1069 let existing = this.dataMap[key]; | 1089 let existing = this.dataMap[key]; |
1070 if (item.filter) | 1090 if (item.filter) |
1071 existing.filter = item.filter; | 1091 existing.filter = item.filter; |
1072 | 1092 |
1073 existing.nodes.push(node); | |
1074 this.invalidateItem(existing); | 1093 this.invalidateItem(existing); |
1075 return; | 1094 return; |
1076 } | 1095 } |
1077 | 1096 |
1078 // Add new item to the list | 1097 // Add new item to the list |
1079 // 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 |
1080 item = {__proto__: item, orig: item, nodes: [node]}; | 1099 item = {__proto__: item, orig: item, nodes: []}; |
Wladimir Palant
2015/11/02 20:01:59
Not having nodes has two side-effects: the Size co
| |
1081 this.allData.push(item); | 1100 this.allData.push(item); |
1082 this.dataMap[key] = item; | 1101 this.dataMap[key] = item; |
1083 | 1102 |
1084 // Show disabled filters if no other filter applies | 1103 // Show disabled filters if no other filter applies |
1085 if (!item.filter) | 1104 if (!item.filter) |
1086 item.filter = disabledMatcher.matchesAny(item.location, RegExpFilter.typeM ap[item.type], item.docDomain, item.thirdParty); | 1105 { |
1106 let disabledMatch = disabledMatcher.matchesAny(item.location, RegExpFilter .typeMap[item.type], item.docDomain, item.thirdParty); | |
1107 if (disabledMatch) | |
1108 item.filter = disabledMatch.text; | |
1109 } | |
1087 | 1110 |
1088 if (!this.matchesFilter(item)) | 1111 if (!this.matchesFilter(item)) |
1089 return; | 1112 return; |
1090 | 1113 |
1091 let index = -1; | 1114 let index = -1; |
1092 if (this.sortProc && this.sortColumn && this.sortColumn.id == "size") | 1115 if (this.sortProc && this.sortColumn && this.sortColumn.id == "size") |
1093 { | 1116 { |
1094 // Sorting by size requires accessing content document, and that's | 1117 // Sorting by size requires accessing content document, and that's |
1095 // dangerous from a content policy (and we are likely called directly | 1118 // dangerous from a content policy (and we are likely called directly |
1096 // from a content policy call). Size data will be inaccurate anyway, | 1119 // from a content policy call). Size data will be inaccurate anyway, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1128 this.itemToSelect = null; | 1151 this.itemToSelect = null; |
1129 } | 1152 } |
1130 else if (!scanComplete && this.selection.currentIndex >= 0) // Keep selected row visible while scanning | 1153 else if (!scanComplete && this.selection.currentIndex >= 0) // Keep selected row visible while scanning |
1131 this.boxObject.ensureRowIsVisible(this.selection.currentIndex); | 1154 this.boxObject.ensureRowIsVisible(this.selection.currentIndex); |
1132 }, | 1155 }, |
1133 | 1156 |
1134 updateFilters: function() | 1157 updateFilters: function() |
1135 { | 1158 { |
1136 for (let item of this.allData) | 1159 for (let item of this.allData) |
1137 { | 1160 { |
1138 if (item.filter instanceof RegExpFilter && item.filter.disabled) | 1161 let filter = getFilter(item); |
1162 if (filter instanceof RegExpFilter && filter.disabled) | |
1139 delete item.filter; | 1163 delete item.filter; |
1140 if (!item.filter) | 1164 if (!filter) |
1141 item.filter = disabledMatcher.matchesAny(item.location, RegExpFilter.typ eMap[item.type], item.docDomain, item.thirdParty); | 1165 { |
1166 let disabledMatch = disabledMatcher.matchesAny(item.location, RegExpFilt er.typeMap[item.type], item.docDomain, item.thirdParty); | |
1167 if (disabledMatch) | |
1168 item.filter = disabledMatch.text; | |
1169 } | |
1142 } | 1170 } |
1143 this.refilter(); | 1171 this.refilter(); |
1144 }, | 1172 }, |
1145 | 1173 |
1146 /** | 1174 /** |
1147 * Updates the list after a filter or sorting change. | 1175 * Updates the list after a filter or sorting change. |
1148 */ | 1176 */ |
1149 refilter: function() | 1177 refilter: function() |
1150 { | 1178 { |
1151 if (this.resortTimeout) | 1179 if (this.resortTimeout) |
1152 clearTimeout(this.resortTimeout); | 1180 clearTimeout(this.resortTimeout); |
1153 | 1181 |
1154 this.data = this.allData.filter(this.matchesFilter, this); | 1182 this.data = this.allData.filter(this.matchesFilter, this); |
1155 | 1183 |
1156 if (this.sortProc) | 1184 if (this.sortProc) |
1157 this.data.sort(this.sortProc); | 1185 this.data.sort(this.sortProc); |
1158 }, | 1186 }, |
1159 | 1187 |
1160 /** | 1188 /** |
1161 * Tests whether an item matches current list filter. | 1189 * Tests whether an item matches current list filter. |
1162 * @return {Boolean} true if the item should be shown | 1190 * @return {Boolean} true if the item should be shown |
1163 */ | 1191 */ |
1164 matchesFilter: function(item) | 1192 matchesFilter: function(item) |
1165 { | 1193 { |
1166 if (!this.filter) | 1194 if (!this.filter) |
1167 return true; | 1195 return true; |
1168 | 1196 |
1169 return (item.location.toLowerCase().indexOf(this.filter) >= 0 || | 1197 return (item.location.toLowerCase().indexOf(this.filter) >= 0 || |
1170 (item.filter && item.filter.text.toLowerCase().indexOf(this.filter) >= 0) || | 1198 (item.filter && item.filter.toLowerCase().indexOf(this.filter) >= 0) || |
1171 item.type.toLowerCase().indexOf(this.filter.replace(/-/g, "_")) >= 0 || | 1199 item.type.toLowerCase().indexOf(this.filter.replace(/-/g, "_")) >= 0 || |
1172 types.get(item.type).toLowerCase().indexOf(this.filter) >= 0 || | 1200 types.get(item.type).toLowerCase().indexOf(this.filter) >= 0 || |
1173 (item.docDomain && item.docDomain.toLowerCase().indexOf(this.filter) >= 0) || | 1201 (item.docDomain && item.docDomain.toLowerCase().indexOf(this.filter) >= 0) || |
1174 (item.docDomain && item.thirdParty && docDomainThirdParty.toLowerCas e().indexOf(this.filter) >= 0) || | 1202 (item.docDomain && item.thirdParty && docDomainThirdParty.toLowerCas e().indexOf(this.filter) >= 0) || |
1175 (item.docDomain && !item.thirdParty && docDomainFirstParty.toLowerCa se().indexOf(this.filter) >= 0)); | 1203 (item.docDomain && !item.thirdParty && docDomainFirstParty.toLowerCa se().indexOf(this.filter) >= 0)); |
1176 }, | 1204 }, |
1177 | 1205 |
1178 setFilter: function(filter) { | 1206 setFilter: function(filter) { |
1179 var oldRows = this.rowCount; | 1207 var oldRows = this.rowCount; |
1180 | 1208 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 this.boxObject.getCellAt(x, y, {}, col, {}); | 1267 this.boxObject.getCellAt(x, y, {}, col, {}); |
1240 return (col.value ? col.value.id : null); | 1268 return (col.value ? col.value.id : null); |
1241 }, | 1269 }, |
1242 | 1270 |
1243 getDummyTooltip: function() { | 1271 getDummyTooltip: function() { |
1244 if (!this.data || this.data.length) | 1272 if (!this.data || this.data.length) |
1245 return null; | 1273 return null; |
1246 | 1274 |
1247 var filter = Policy.isWindowWhitelisted(window.content); | 1275 var filter = Policy.isWindowWhitelisted(window.content); |
1248 if (filter) | 1276 if (filter) |
1249 return {tooltip: this.whitelistDummyTooltip, filter: filter}; | 1277 return {tooltip: this.whitelistDummyTooltip, filter: filter.text}; |
1250 else | 1278 else |
1251 return {tooltip: this.itemsDummyTooltip}; | 1279 return {tooltip: this.itemsDummyTooltip}; |
1252 }, | 1280 }, |
1253 | 1281 |
1254 invalidateItem: function(item) | 1282 invalidateItem: function(item) |
1255 { | 1283 { |
1256 let row = this.data.indexOf(item); | 1284 let row = this.data.indexOf(item); |
1257 if (row >= 0) | 1285 if (row >= 0) |
1258 this.boxObject.invalidateRow(row); | 1286 this.boxObject.invalidateRow(row); |
1259 } | 1287 } |
1260 } | 1288 } |
OLD | NEW |