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

Unified Diff: composer.postload.js

Issue 29370947: Issue 3138 - Improve how context menu "block element" handles iframes (Closed)
Patch Set: Use messaging instead of requiring the info module Created Oct. 19, 2017, 10:52 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ext/background.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: composer.postload.js
diff --git a/composer.postload.js b/composer.postload.js
index b0a6f7f1b8047eba593c9e2b6183d2601111dc9f..8331c53f8a85bfd12280fbe7260862f9dd57ab80 100644
--- a/composer.postload.js
+++ b/composer.postload.js
@@ -40,6 +40,11 @@ let highlightedElementsInterval = null;
let lastRightClickEvent = null;
let lastRightClickEventIsMostRecent = false;
+let perFrameMessagingSupported = false;
+browser.runtime.sendMessage(
+ {type: "app.get", what: "application"},
+ application => { perFrameMessagingSupported = application != "edge"; }
+);
/* Utilities */
@@ -65,6 +70,11 @@ function getFiltersForElement(element, callback)
function getBlockableElementOrAncestor(element, callback)
{
+ // If we're offering to block the iframe element given by window.frameElement
+ // we must use the context of the parent frame.
+ let document = element.ownerDocument;
+ let HTMLElement = document.defaultView.HTMLElement;
+
// We assume that the user doesn't want to block the whole page.
// So we never consider the <html> or <body> element.
while (element && element != document.documentElement &&
@@ -123,6 +133,8 @@ function getBlockableElementOrAncestor(element, callback)
// Adds an overlay to an element in order to highlight it.
function addElementOverlay(element)
{
+ let document = element.ownerDocument;
+
let position = "absolute";
let offsetX = window.scrollX;
let offsetY = window.scrollY;
@@ -422,8 +434,11 @@ function elementPicked(event)
highlightElement(currentElement, "#fd1708", "#f6a1b5");
});
- event.preventDefault();
- event.stopPropagation();
+ if (event)
+ {
+ event.preventDefault();
+ event.stopPropagation();
+ }
}
function stopPickingElement()
@@ -524,10 +539,21 @@ function initializeComposer()
break;
case "composer.content.contextMenuClicked":
let event = lastRightClickEvent;
+ let target = event && event.target;
+
+ // When the user attempts to block an element inside an iframe for which
+ // our right click event listener was trashed the best we can do is to
+ // offer to block the entire iframe. This doesn't work for cross origin
+ // frames, neither on Edge where per-frame messaging isn't supported
+ // yet[1], but it's the best we can do.
+ // [1] - https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/extensions/api-support/supported-apis/
+ if (!target && window.frameElement && perFrameMessagingSupported)
+ target = addElementOverlay(window.frameElement);
+
deactivateBlockElement();
- if (event)
+ if (target)
{
- getBlockableElementOrAncestor(event.target, element =>
+ getBlockableElementOrAncestor(target, element =>
{
if (element)
{
« no previous file with comments | « no previous file | ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld