| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 109 } |
| 110 | 110 |
| 111 var activeNotification = null; | 111 var activeNotification = null; |
| 112 | 112 |
| 113 // Adds or removes page action icon according to options. | 113 // Adds or removes page action icon according to options. |
| 114 function refreshIconAndContextMenu(tab) | 114 function refreshIconAndContextMenu(tab) |
| 115 { | 115 { |
| 116 if(!/^https?:/.test(tab.url)) | 116 if(!/^https?:/.test(tab.url)) |
| 117 return; | 117 return; |
| 118 | 118 |
| 119 var excluded = isWhitelisted(tab.url); | |
| 120 var iconFilename; | 119 var iconFilename; |
| 121 | 120 if (require("info").platform == "safari") |
| 122 // If the page is whitelisted use the grayscale version of the icon | 121 // There is no grayscale version of the icon for whitelisted tabs |
| 123 // for that tab, except for Safari where all icons are grayscale | 122 // when using Safari, because icons are grayscale already and icons |
| 124 // already and where icons aren't per tab. | 123 // aren't per tab in Safari. |
| 125 if ("safari" in window || !excluded) | 124 iconFilename = "icons/abp-16.png" |
| 126 iconFilename = "icons/abp-18.png"; | |
| 127 else | 125 else |
| 128 iconFilename = "icons/abp-18-whitelisted.png"; | 126 { |
| 127 var excluded = isWhitelisted(tab.url); |
| 128 iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.png
"; |
| 129 } |
| 129 | 130 |
| 130 tab.pageAction.setIcon(iconFilename); | 131 tab.pageAction.setIcon(iconFilename); |
| 131 tab.pageAction.setTitle("Adblock Plus"); | 132 tab.pageAction.setTitle(ext.i18n.getMessage("name")); |
| 132 | 133 |
| 133 iconAnimation.registerTab(tab, iconFilename); | 134 iconAnimation.registerTab(tab, iconFilename); |
| 134 | 135 |
| 135 if (localStorage.shouldShowIcon == "false") | 136 if (localStorage.shouldShowIcon == "false") |
| 136 tab.pageAction.hide(); | 137 tab.pageAction.hide(); |
| 137 else | 138 else |
| 138 tab.pageAction.show(); | 139 tab.pageAction.show(); |
| 139 | 140 |
| 140 if ("chrome" in window) // TODO: Implement context menus for Safari | 141 if (require("info").platform == "chromium") // TODO: Implement context menus f
or Safari |
| 141 // Set context menu status according to whether current tab has whitelisted
domain | 142 // Set context menu status according to whether current tab has whitelisted
domain |
| 142 if (excluded) | 143 if (excluded) |
| 143 chrome.contextMenus.removeAll(); | 144 chrome.contextMenus.removeAll(); |
| 144 else | 145 else |
| 145 showContextMenu(); | 146 showContextMenu(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 /** | 149 /** |
| 149 * Old versions stored filter data in the localStorage object, this will import | 150 * Old versions stored filter data in the localStorage object, this will import |
| 150 * it into FilterStorage properly. | 151 * it into FilterStorage properly. |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 364 } |
| 364 else | 365 else |
| 365 addAcceptable = false; | 366 addAcceptable = false; |
| 366 } | 367 } |
| 367 | 368 |
| 368 if (!addSubscription && !addAcceptable) | 369 if (!addSubscription && !addAcceptable) |
| 369 return; | 370 return; |
| 370 | 371 |
| 371 function notifyUser() | 372 function notifyUser() |
| 372 { | 373 { |
| 373 ext.windows.getLastFocused(function(win) { | 374 ext.windows.getLastFocused(function(win) |
| 375 { |
| 374 win.openTab(ext.getURL("firstRun.html")); | 376 win.openTab(ext.getURL("firstRun.html")); |
| 375 }); | 377 }); |
| 376 } | 378 } |
| 377 | 379 |
| 378 if (addSubscription) | 380 if (addSubscription) |
| 379 { | 381 { |
| 380 // Load subscriptions data | 382 // Load subscriptions data |
| 381 var request = new XMLHttpRequest(); | 383 var request = new XMLHttpRequest(); |
| 382 request.open("GET", "subscriptions.xml"); | 384 request.open("GET", "subscriptions.xml"); |
| 383 request.addEventListener("load", function() | 385 request.addEventListener("load", function() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 411 { | 413 { |
| 412 chrome.contextMenus.create({"title": chrome.i18n.getMessage("block_element
"), "contexts": ["image", "video", "audio"], "onclick": function(info, tab) | 414 chrome.contextMenus.create({"title": chrome.i18n.getMessage("block_element
"), "contexts": ["image", "video", "audio"], "onclick": function(info, tab) |
| 413 { | 415 { |
| 414 if(info.srcUrl) | 416 if(info.srcUrl) |
| 415 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-new-filter", fi
lter: info.srcUrl}); | 417 chrome.tabs.sendRequest(tab.id, {reqtype: "clickhide-new-filter", fi
lter: info.srcUrl}); |
| 416 }}); | 418 }}); |
| 417 } | 419 } |
| 418 }); | 420 }); |
| 419 } | 421 } |
| 420 | 422 |
| 423 /** |
| 424 * Opens options tab or focuses an existing one, within the last focused window
. |
| 425 * @param {Function} callback function to be called with the |
| 426 Tab object of the options tab |
| 427 */ |
| 421 function openOptions(callback) | 428 function openOptions(callback) |
| 422 { | 429 { |
| 423 ext.windows.getLastFocused(function(win) | 430 ext.windows.getLastFocused(function(win) |
| 424 { | 431 { |
| 425 win.getAllTabs(function(tabs) | 432 win.getAllTabs(function(tabs) |
| 426 { | 433 { |
| 427 var optionsUrl = ext.getURL("options.html"); | 434 var optionsUrl = ext.getURL("options.html"); |
| 428 | 435 |
| 429 for (var i = 0; i < tabs.length; i++) | 436 for (var i = 0; i < tabs.length; i++) |
| 437 { |
| 430 if (tabs[i].url == optionsUrl) | 438 if (tabs[i].url == optionsUrl) |
| 431 { | 439 { |
| 432 tabs[i].activate(); | 440 tabs[i].activate(); |
| 433 if (callback) | 441 if (callback) |
| 434 callback(tabs[i]); | 442 callback(tabs[i]); |
| 435 return; | 443 return; |
| 436 } | 444 } |
| 437 | 445 } |
| 438 win.openTab(optionsUrl, callback && function(tab) { | 446 |
| 447 win.openTab(optionsUrl, callback && function(tab) |
| 448 { |
| 439 tab.onCompleted.addListener(callback); | 449 tab.onCompleted.addListener(callback); |
| 440 }); | 450 }); |
| 441 }); | 451 }); |
| 442 }); | 452 }); |
| 443 } | 453 } |
| 444 | 454 |
| 445 function prepareNotificationIconAndPopup() | 455 function prepareNotificationIconAndPopup() |
| 446 { | 456 { |
| 447 activeNotification.onClicked = function() | 457 activeNotification.onClicked = function() |
| 448 { | 458 { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 478 for (var frameId in frames.get(tab)) | 488 for (var frameId in frames.get(tab)) |
| 479 if (getFrameUrl(tab, frameId) == url) | 489 if (getFrameUrl(tab, frameId) == url) |
| 480 return frameId; | 490 return frameId; |
| 481 return -1; | 491 return -1; |
| 482 } | 492 } |
| 483 | 493 |
| 484 ext.onMessage.addListener(function (msg, sender, sendResponse) | 494 ext.onMessage.addListener(function (msg, sender, sendResponse) |
| 485 { | 495 { |
| 486 switch (msg.type) | 496 switch (msg.type) |
| 487 { | 497 { |
| 488 case "get-settings": | 498 case "get-selectors": |
| 489 var hostDomain = null; | |
| 490 var selectors = null; | 499 var selectors = null; |
| 491 | |
| 492 var frameId = sender.tab ? getFrameId(sender.tab, msg.frameUrl) : -1; | 500 var frameId = sender.tab ? getFrameId(sender.tab, msg.frameUrl) : -1; |
| 493 var enabled = false; | 501 |
| 494 | 502 if (!isFrameWhitelisted(sender.tab, frameId, "DOCUMENT") && |
| 495 if (!isFrameWhitelisted(sender.tab, frameId, "DOCUMENT")) | 503 !isFrameWhitelisted(sender.tab, frameId, "ELEMHIDE")) |
| 496 if (!isFrameWhitelisted(sender.tab, frameId, "ELEMHIDE")) { | 504 { |
| 497 var enabled = true; | 505 var noStyleRules = false; |
| 498 | 506 var host = extractHostFromURL(msg.frameUrl); |
| 499 if (msg.selectors) | 507 for (var i = 0; i < noStyleRulesHosts.length; i++) |
| 500 { | 508 { |
| 501 var noStyleRules = false; | 509 var noStyleHost = noStyleRulesHosts[i]; |
| 502 var host = extractHostFromURL(msg.frameUrl); | 510 if (host == noStyleHost || (host.length > noStyleHost.length && |
| 503 hostDomain = getBaseDomain(host); | 511 host.substr(host.length - noStyleHost.leng
th - 1) == "." + noStyleHost)) |
| 504 for (var i = 0; i < noStyleRulesHosts.length; i++) | |
| 505 { | 512 { |
| 506 var noStyleHost = noStyleRulesHosts[i]; | 513 noStyleRules = true; |
| 507 if (host == noStyleHost || (host.length > noStyleHost.length && | |
| 508 host.substr(host.length - noStyleHost.le
ngth - 1) == "." + noStyleHost)) | |
| 509 { | |
| 510 noStyleRules = true; | |
| 511 } | |
| 512 } | |
| 513 selectors = ElemHide.getSelectorsForDomain(host, false); | |
| 514 if (noStyleRules) | |
| 515 { | |
| 516 selectors = selectors.filter(function(s) | |
| 517 { | |
| 518 return !/\[style[\^\$]?=/.test(s); | |
| 519 }); | |
| 520 } | 514 } |
| 521 } | 515 } |
| 522 } | 516 selectors = ElemHide.getSelectorsForDomain(host, false); |
| 523 | 517 if (noStyleRules) |
| 524 sendResponse({enabled: enabled, hostDomain: hostDomain, selectors: selecto
rs}); | 518 { |
| 519 selectors = selectors.filter(function(s) |
| 520 { |
| 521 return !/\[style[\^\$]?=/.test(s); |
| 522 }); |
| 523 } |
| 524 } |
| 525 |
| 526 sendResponse(selectors); |
| 525 break; | 527 break; |
| 526 case "should-collapse": | 528 case "should-collapse": |
| 527 var frameId = sender.tab ? getFrameId(sender.tab, msg.documentUrl) : -1; | 529 var frameId = sender.tab ? getFrameId(sender.tab, msg.documentUrl) : -1; |
| 528 | 530 |
| 529 if (isFrameWhitelisted(sender.tab, frameId, "DOCUMENT")) | 531 if (isFrameWhitelisted(sender.tab, frameId, "DOCUMENT")) |
| 530 { | 532 { |
| 531 sendResponse(false); | 533 sendResponse(false); |
| 532 break; | 534 break; |
| 533 } | 535 } |
| 534 | 536 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 556 } | 558 } |
| 557 break; | 559 break; |
| 558 case "add-filters": | 560 case "add-filters": |
| 559 if (msg.filters && msg.filters.length) | 561 if (msg.filters && msg.filters.length) |
| 560 { | 562 { |
| 561 for (var i = 0; i < msg.filters.length; i++) | 563 for (var i = 0; i < msg.filters.length; i++) |
| 562 FilterStorage.addFilter(Filter.fromText(msg.filters[i])); | 564 FilterStorage.addFilter(Filter.fromText(msg.filters[i])); |
| 563 } | 565 } |
| 564 break; | 566 break; |
| 565 case "add-subscription": | 567 case "add-subscription": |
| 566 openOptions(function(tab) { tab.sendMessage(msg); }); | 568 openOptions(function(tab) |
| 569 { |
| 570 tab.sendMessage(msg); |
| 571 }); |
| 567 break; | 572 break; |
| 568 case "forward": | 573 case "forward": |
| 569 tab.sendMessage(msg.payload, sendResponse); | 574 tab.sendMessage(msg.payload, sendResponse); |
| 570 break; | 575 break; |
| 571 default: | 576 default: |
| 572 sendResponse({}); | 577 sendResponse({}); |
| 573 break; | 578 break; |
| 574 } | 579 } |
| 575 }); | 580 }); |
| 576 | 581 |
| 577 // Show icon as page action for all tabs that already exist | 582 // Show icon as page action for all tabs that already exist |
| 578 ext.windows.getAll(function(windows) | 583 ext.windows.getAll(function(windows) |
| 579 { | 584 { |
| 580 for (var i = 0; i < windows.length; i++) | 585 for (var i = 0; i < windows.length; i++) |
| 586 { |
| 581 windows[i].getAllTabs(function(tabs) | 587 windows[i].getAllTabs(function(tabs) |
| 582 { | 588 { |
| 583 tabs.forEach(refreshIconAndContextMenu); | 589 tabs.forEach(refreshIconAndContextMenu); |
| 584 }); | 590 }); |
| 591 } |
| 585 }); | 592 }); |
| 586 | 593 |
| 587 // Update icon if a tab changes location | 594 // Update icon if a tab changes location |
| 588 ext.tabs.onBeforeNavigate.addListener(function(tab) | 595 ext.tabs.onBeforeNavigate.addListener(function(tab) |
| 589 { | 596 { |
| 590 tab.sendMessage({type: "clickhide-deactivate"}); | 597 tab.sendMessage({type: "clickhide-deactivate"}); |
| 591 refreshIconAndContextMenu(tab); | 598 refreshIconAndContextMenu(tab); |
| 592 }); | 599 }); |
| 593 | 600 |
| 594 setTimeout(function() | 601 setTimeout(function() |
| 595 { | 602 { |
| 596 var notificationToShow = Notification.getNextToShow(); | 603 var notificationToShow = Notification.getNextToShow(); |
| 597 if (notificationToShow) | 604 if (notificationToShow) |
| 598 showNotification(notificationToShow); | 605 showNotification(notificationToShow); |
| 599 }, 3 * 60 * 1000); | 606 }, 3 * 60 * 1000); |
| LEFT | RIGHT |