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

Unified Diff: safari/ext/content.js

Issue 6549206625943552: Issue 1592 - Fixed frame collapsing on Safari (Closed)
Patch Set: Improved comment Created Nov. 25, 2014, 11:43 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: safari/ext/content.js
===================================================================
--- a/safari/ext/content.js
+++ b/safari/ext/content.js
@@ -66,12 +66,15 @@
if (!/^https?:/.test(url))
return;
- var type;
+ var type = "other";
+ var eventName = "error";
+
switch(event.target.localName)
{
case "frame":
case "iframe":
type = "sub_frame";
+ eventName = "load";
break;
case "img":
type = "image";
@@ -85,12 +88,8 @@
break;
case "link":
if (/\bstylesheet\b/i.test(event.target.rel))
- {
type = "stylesheet";
- break;
- }
- default:
- type = "other";
+ break;
}
if (!safari.self.tab.canLoad(
@@ -105,15 +104,18 @@
{
event.preventDefault();
- // Safari doesn't dispatch an "error" event when preventing an element
- // from loading by cancelling the "beforeload" event. So we have to
- // dispatch it manually. Otherwise element collapsing wouldn't work.
- if (type != "sub_frame")
+ // Safari doesn't dispatch all the expected events for elements that
+ // have been prevented from loading by having their "beforeload" event
+ // cancelled. "error" events are never dispatched, and since Safari 8
+ // "load" events are also not dispatched, when blocking frames.
+ // We need to dispatch those events manually here to avoid breaking
+ // element collapsing and pages that rely on those events.
+ if (type != "sub_frame" || parseInt(navigator.userAgent.match(/\bVersion\/(\d+)/)[1], 10) >= 8)
{
setTimeout(function()
{
var evt = document.createEvent("Event");
- evt.initEvent("error");
+ evt.initEvent(eventName);
event.target.dispatchEvent(evt);
}, 0);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld