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 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1592 | 1592 |
1593 hideElement(prefix + "contributebutton", Prefs.hideContributeButton); | 1593 hideElement(prefix + "contributebutton", Prefs.hideContributeButton); |
1594 }, | 1594 }, |
1595 | 1595 |
1596 /** | 1596 /** |
1597 * Adds Adblock Plus menu items to the content area context menu when it shows | 1597 * Adds Adblock Plus menu items to the content area context menu when it shows |
1598 * up. | 1598 * up. |
1599 */ | 1599 */ |
1600 fillContentContextMenu: function(/**Element*/ popup) | 1600 fillContentContextMenu: function(/**Element*/ popup) |
1601 { | 1601 { |
1602 let target = popup.triggerNode; | 1602 let window = popup.ownerDocument.defaultView; |
1603 if (target instanceof Ci.nsIDOMHTMLMapElement || target instanceof Ci.nsIDOM HTMLAreaElement) | 1603 if (!window.gContextMenuContentData || |
1604 typeof window.gContextMenuContentData.addonInfo != "object" || | |
1605 typeof window.gContextMenuContentData.addonInfo.adblockplus != "object") | |
1604 { | 1606 { |
1605 // HTML image maps will usually receive events when the mouse pointer is | 1607 return; |
1606 // over a different element, get the real event target. | |
1607 let rect = target.getClientRects()[0]; | |
1608 target = target.ownerDocument.elementFromPoint(Math.max(rect.left, 0), Mat h.max(rect.top, 0)); | |
1609 } | 1608 } |
1610 | 1609 |
1611 if (!target) | 1610 let items = window.gContextMenuContentData.addonInfo.adblockplus; |
1612 return; | 1611 let clicked = null; |
1612 let menuItems = []; | |
1613 | 1613 |
1614 let window = popup.ownerDocument.defaultView; | 1614 function menuItemTriggered(id, nodeData) |
1615 let menuItems = []; | 1615 { |
1616 let addMenuItem = function([node, nodeData]) | 1616 clicked = id; |
1617 this.blockItem(window, id, nodeData); | |
1618 } | |
1619 | |
1620 for (let [id, nodeData] of items) | |
1617 { | 1621 { |
1618 let type = nodeData.type.toLowerCase(); | 1622 let type = nodeData.type.toLowerCase(); |
1619 if (type == "background") | |
1620 { | |
1621 type = "image"; | |
1622 node = null; | |
1623 } | |
1624 | |
1625 let label = this.overlay.attributes[type + "contextlabel"]; | 1623 let label = this.overlay.attributes[type + "contextlabel"]; |
1626 if (!label) | 1624 if (!label) |
1627 return; | 1625 return; |
1628 | 1626 |
1629 let item = popup.ownerDocument.createElement("menuitem"); | 1627 let item = popup.ownerDocument.createElement("menuitem"); |
1630 item.setAttribute("label", label); | 1628 item.setAttribute("label", label); |
1631 item.setAttribute("class", "abp-contextmenuitem"); | 1629 item.setAttribute("class", "abp-contextmenuitem"); |
1632 item.addEventListener("command", this.blockItem.bind(this, window, node, n odeData), false); | 1630 item.addEventListener("command", menuItemTriggered.bind(this, id, nodeData ), false); |
1633 popup.appendChild(item); | 1631 popup.appendChild(item); |
1634 | 1632 |
1635 menuItems.push(item); | 1633 menuItems.push(item); |
1636 }.bind(this); | |
1637 | |
1638 // Look up data that we have for the node | |
1639 let data = RequestNotifier.getDataForNode(target); | |
1640 let hadImage = false; | |
1641 if (data && !data[1].filter) | |
1642 { | |
1643 addMenuItem(data); | |
1644 hadImage = (data[1].type == "IMAGE"); | |
1645 } | |
1646 | |
1647 // Look for frame data | |
1648 let wnd = Utils.getWindow(target); | |
1649 if (wnd.frameElement) | |
1650 { | |
1651 let data = RequestNotifier.getDataForNode(wnd.frameElement, true); | |
1652 if (data && !data[1].filter) | |
1653 addMenuItem(data); | |
1654 } | |
1655 | |
1656 // Look for a background image | |
1657 if (!hadImage) | |
1658 { | |
1659 let extractImageURL = function(computedStyle, property) | |
1660 { | |
1661 let value = computedStyle.getPropertyCSSValue(property); | |
1662 // CSSValueList | |
1663 if ("length" in value && value.length >= 1) | |
1664 value = value[0]; | |
1665 // CSSValuePrimitiveType | |
1666 if ("primitiveType" in value && value.primitiveType == value.CSS_URI) | |
1667 return Utils.unwrapURL(value.getStringValue()).spec; | |
1668 | |
1669 return null; | |
1670 }; | |
1671 | |
1672 let node = target; | |
1673 while (node) | |
1674 { | |
1675 if (node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) | |
1676 { | |
1677 let style = wnd.getComputedStyle(node, ""); | |
1678 let bgImage = extractImageURL(style, "background-image") || extractIma geURL(style, "list-style-image"); | |
1679 if (bgImage) | |
1680 { | |
1681 let data = RequestNotifier.getDataForNode(wnd.document, true, "IMAGE ", bgImage); | |
1682 if (data && !data[1].filter) | |
1683 { | |
1684 addMenuItem(data); | |
1685 break; | |
1686 } | |
1687 } | |
1688 } | |
1689 | |
1690 node = node.parentNode; | |
1691 } | |
1692 } | 1634 } |
1693 | 1635 |
1694 // Add "Remove exception" menu item if necessary | 1636 // Add "Remove exception" menu item if necessary |
1695 let location = this.getCurrentLocation(window); | 1637 let location = this.getCurrentLocation(window); |
1696 let filter = (location ? Policy.isWhitelisted(location.spec) : null); | 1638 let filter = (location ? Policy.isWhitelisted(location.spec) : null); |
1697 if (filter && filter.subscriptions.length && !filter.disabled) | 1639 if (filter && filter.subscriptions.length && !filter.disabled) |
1698 { | 1640 { |
1699 let label = this.overlay.attributes.whitelistcontextlabel; | 1641 let label = this.overlay.attributes.whitelistcontextlabel; |
1700 if (!label) | 1642 if (!label) |
1701 return; | 1643 return; |
1702 | 1644 |
1703 let item = popup.ownerDocument.createElement("menuitem"); | 1645 let item = popup.ownerDocument.createElement("menuitem"); |
1704 item.setAttribute("label", label); | 1646 item.setAttribute("label", label); |
1705 item.setAttribute("class", "abp-contextmenuitem"); | 1647 item.setAttribute("class", "abp-contextmenuitem"); |
1706 item.addEventListener("command", this.toggleFilter.bind(this, filter), fal se); | 1648 item.addEventListener("command", this.toggleFilter.bind(this, filter), fal se); |
1707 popup.appendChild(item); | 1649 popup.appendChild(item); |
1708 | 1650 |
1709 menuItems.push(item); | 1651 menuItems.push(item); |
1710 } | 1652 } |
1711 | 1653 |
1712 // Make sure to clean up everything once the context menu is closed | 1654 // Make sure to clean up everything once the context menu is closed |
1713 if (menuItems.length) | 1655 let cleanUp = function(event) |
1714 { | 1656 { |
1715 let cleanUp = function(event) | 1657 if (event.eventPhase != event.AT_TARGET) |
1716 { | 1658 return; |
1717 if (event.eventPhase != event.AT_TARGET) | |
1718 return; | |
1719 | 1659 |
1720 popup.removeEventListener("popuphidden", cleanUp, false); | 1660 popup.removeEventListener("popuphidden", cleanUp, false); |
1721 for (let i = 0; i < menuItems.length; i++) | 1661 for (let menuItem of menuItems) |
1722 if (menuItems[i].parentNode) | 1662 if (menuItem.parentNode) |
1723 menuItems[i].parentNode.removeChild(menuItems[i]); | 1663 menuItem.parentNode.removeChild(menuItem); |
1724 }.bind(this); | 1664 |
1725 popup.addEventListener("popuphidden", cleanUp, false); | 1665 for (let [id, nodeData] of items) |
1726 } | 1666 if (id && id != clicked) |
1667 Policy.deleteNodes(id); | |
Erik
2015/12/03 23:21:57
I'm not quite sure what this piece is for.
Wladimir Palant
2015/12/04 12:05:10
We are keeping a reference to the nodes in the con
| |
1668 }.bind(this); | |
1669 popup.addEventListener("popuphidden", cleanUp, false); | |
1727 }, | 1670 }, |
1728 | 1671 |
1729 /** | 1672 /** |
1730 * Called when the user presses a key in the application window, reacts to our | 1673 * Called when the user presses a key in the application window, reacts to our |
1731 * shortcut keys. | 1674 * shortcut keys. |
1732 */ | 1675 */ |
1733 onKeyPress: function(/**Event*/ event) | 1676 onKeyPress: function(/**Event*/ event) |
1734 { | 1677 { |
1735 if (!this.hotkeys) | 1678 if (!this.hotkeys) |
1736 this.configureKeys(event.currentTarget); | 1679 this.configureKeys(event.currentTarget); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1944 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)], | 1887 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)], |
1945 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa tegory.bind(Notification, "*", null)] | 1888 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa tegory.bind(Notification, "*", null)] |
1946 ]; | 1889 ]; |
1947 | 1890 |
1948 onShutdown.add(function() | 1891 onShutdown.add(function() |
1949 { | 1892 { |
1950 for (let window of UI.applicationWindows) | 1893 for (let window of UI.applicationWindows) |
1951 if (UI.isBottombarOpen(window)) | 1894 if (UI.isBottombarOpen(window)) |
1952 UI.toggleBottombar(window); | 1895 UI.toggleBottombar(window); |
1953 }); | 1896 }); |
OLD | NEW |