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: Created Nov. 22, 2014, 1:48 p.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:
Sebastian Noack 2014/11/22 13:53:46 Sorry for this unrelated change. But now, where th
kzar 2014/11/24 16:54:50 Makes sense to me.
- type = "other";
+ break;
}
if (!safari.self.tab.canLoad(
@@ -106,14 +105,16 @@
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")
+ // from loading by cancelling the "beforeload" event. Starting with
kzar 2014/11/24 16:54:50 Nitpick: This comment doesn't read very well start
Sebastian Noack 2014/11/24 17:13:20 Can you explain why it doesn't read well in your o
kzar 2014/11/25 11:27:33 The part "...it not even dispatches..." would be m
Sebastian Noack 2014/11/25 11:48:38 I used a sligthly modified version of your text. I
kzar 2014/11/25 12:06:53 Cool, reads great
+ // Safari 8, it not even dispatches a "load" event for cancelled frames.
+ // So we have to dispatch it manually. Otherwise, element collapsing
+ // wouldn't work, and pages that rely on those events break.
+ if (type != "sub_frame" || parseInt(navigator.userAgent.match(/\bVersion\/(\d+)/)[1], 10) >= 8)
kzar 2014/11/24 16:54:50 What if the user is using a version < 8, shouldn't
Sebastian Noack 2014/11/24 17:13:20 Yes, and it is. However, error events should only
kzar 2014/11/25 11:27:33 Ah I see, sorry.
{
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