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: Created Jan. 10, 2017, 6:36 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
Index: composer.postload.js
diff --git a/composer.postload.js b/composer.postload.js
index 98fef095aa636d2c8753329fc41d64234e6f839e..97070933d8685b462f037b361db400686e853ad6 100644
--- a/composer.postload.js
+++ b/composer.postload.js
@@ -63,6 +63,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 &&
@@ -121,6 +126,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;
@@ -431,8 +438,11 @@ function elementPicked(event)
highlightElement(currentElement, "#fd1708", "#f6a1b5");
});
- event.preventDefault();
- event.stopPropagation();
+ if (event)
Sebastian Noack 2017/01/11 18:15:11 How is it possible that there is no event here?
kzar 2017/01/12 07:24:04 If the composer.content.contextMenuClicked handler
+ {
+ event.preventDefault();
+ event.stopPropagation();
+ }
}
function stopPickingElement()
@@ -530,10 +540,19 @@ if (document instanceof HTMLDocument)
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 of course only works if the
+ // parent frame is considered to be of the same origin.
+ if (!target && window.frameElement)
+ target = addElementOverlay(window.frameElement);
+
deactivateBlockElement();
- if (event)
+ if (target)
{
- getBlockableElementOrAncestor(event.target, element =>
+ getBlockableElementOrAncestor(target, element =>
{
if (element)
{
« chrome/ext/background.js ('K') | « chrome/ext/background.js ('k') | lib/filterComposer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld