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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 { 59 {
60 var url = resolveURL(event.url); 60 var url = resolveURL(event.url);
61 61
62 // we don't block non-HTTP requests anyway, so we can bail out 62 // we don't block non-HTTP requests anyway, so we can bail out
63 // without asking the background page. This is even necessary 63 // without asking the background page. This is even necessary
64 // because passing large data (like a photo encoded as data: URL) 64 // because passing large data (like a photo encoded as data: URL)
65 // to the background page, freezes Safari. 65 // to the background page, freezes Safari.
66 if (!/^https?:/.test(url)) 66 if (!/^https?:/.test(url))
67 return; 67 return;
68 68
69 var type; 69 var type = "other";
70 var eventName = "error";
71
70 switch(event.target.localName) 72 switch(event.target.localName)
71 { 73 {
72 case "frame": 74 case "frame":
73 case "iframe": 75 case "iframe":
74 type = "sub_frame"; 76 type = "sub_frame";
77 eventName = "load";
75 break; 78 break;
76 case "img": 79 case "img":
77 type = "image"; 80 type = "image";
78 break; 81 break;
79 case "object": 82 case "object":
80 case "embed": 83 case "embed":
81 type = "object"; 84 type = "object";
82 break; 85 break;
83 case "script": 86 case "script":
84 type = "script"; 87 type = "script";
85 break; 88 break;
86 case "link": 89 case "link":
87 if (/\bstylesheet\b/i.test(event.target.rel)) 90 if (/\bstylesheet\b/i.test(event.target.rel))
88 {
89 type = "stylesheet"; 91 type = "stylesheet";
90 break; 92 break;
91 }
92 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.
93 type = "other";
94 } 93 }
95 94
96 if (!safari.self.tab.canLoad( 95 if (!safari.self.tab.canLoad(
97 event, { 96 event, {
98 category: "webRequest", 97 category: "webRequest",
99 url: url, 98 url: url,
100 type: type, 99 type: type,
101 pageId: documentInfo.pageId, 100 pageId: documentInfo.pageId,
102 frameId: documentInfo.frameId 101 frameId: documentInfo.frameId
103 } 102 }
104 )) 103 ))
105 { 104 {
106 event.preventDefault(); 105 event.preventDefault();
107 106
108 // Safari doesn't dispatch an "error" event when preventing an element 107 // Safari doesn't dispatch an "error" event when preventing an element
109 // from loading by cancelling the "beforeload" event. So we have to 108 // 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
110 // dispatch it manually. Otherwise element collapsing wouldn't work. 109 // Safari 8, it not even dispatches a "load" event for cancelled frames.
111 if (type != "sub_frame") 110 // So we have to dispatch it manually. Otherwise, element collapsing
111 // wouldn't work, and pages that rely on those events break.
112 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.
112 { 113 {
113 setTimeout(function() 114 setTimeout(function()
114 { 115 {
115 var evt = document.createEvent("Event"); 116 var evt = document.createEvent("Event");
116 evt.initEvent("error"); 117 evt.initEvent(eventName);
117 event.target.dispatchEvent(evt); 118 event.target.dispatchEvent(evt);
118 }, 0); 119 }, 0);
119 } 120 }
120 } 121 }
121 }, true); 122 }, true);
122 123
123 124
124 /* Context menus */ 125 /* Context menus */
125 126
126 document.addEventListener("contextmenu", function(event) 127 document.addEventListener("contextmenu", function(event)
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 messageProxy.handleResponse(event.message); 425 messageProxy.handleResponse(event.message);
425 break; 426 break;
426 case "proxyCallback": 427 case "proxyCallback":
427 backgroundPageProxy.handleCallback(event.message); 428 backgroundPageProxy.handleCallback(event.message);
428 break; 429 break;
429 } 430 }
430 } 431 }
431 } 432 }
432 }); 433 });
433 })(); 434 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld