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

Delta Between Two Patch Sets: safari/ext/content.js

Issue 6346177440120832: Added abstraction for frames, to fix domain-based rules, whitelisting and ad counter on Safari (Closed)
Left Patch Set: Created Dec. 21, 2013, 7:48 p.m.
Right Patch Set: Addressed another comment Created Jan. 20, 2014, 8:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « safari/ext/common.js ('k') | webrequest.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 /* Web request blocking */ 280 /* Web request blocking */
281 281
282 document.addEventListener("beforeload", function(event) 282 document.addEventListener("beforeload", function(event)
283 { 283 {
284 var type; 284 var type;
285 285
286 switch(event.target.localName) 286 switch(event.target.localName)
287 { 287 {
288 case "frame": 288 case "frame":
289 case "iframe": 289 case "iframe":
290 type = "sub_rame"; 290 type = "sub_frame";
291 break; 291 break;
292 case "img": 292 case "img":
293 type = "image"; 293 type = "image";
294 break; 294 break;
295 case "object": 295 case "object":
296 case "embed": 296 case "embed":
297 type = "object"; 297 type = "object";
298 break; 298 break;
299 case "script": 299 case "script":
300 type = "script"; 300 type = "script";
301 break; 301 break;
302 case "link": 302 case "link":
303 if (/\bstylesheet\b/i.test(event.target.rel)) 303 if (/\bstylesheet\b/i.test(event.target.rel))
304 { 304 {
305 type = "stylesheet"; 305 type = "stylesheet";
306 break; 306 break;
307 } 307 }
308 default: 308 default:
309 type = "other"; 309 type = "other";
310 } 310 }
311 311
312 if (!safari.self.tab.canLoad(event, { 312 if (!safari.self.tab.canLoad(
Felix Dahlke 2014/01/18 13:39:19 { should go on its own line
Sebastian Noack 2014/01/19 10:19:40 Done.
313 type: "webRequest", 313 event, {
314 payload: { 314 type: "webRequest",
315 url: event.url, 315 payload: {
316 type: type, 316 url: event.url,
317 documentUrl: document.location.href, 317 type: type,
318 isTopLevel: window == window.top 318 documentUrl: document.location.href,
319 } 319 isTopLevel: window == window.top
320 })) 320 }
321 }
322 ))
323 {
321 event.preventDefault(); 324 event.preventDefault();
325
326 // Safari doesn't dispatch an "error" or "load" event when preventing an
327 // element from loading by cancelling the "beforeload" event. So we have
328 // to dispatch it manually. Otherwise element collapsing wouldn't work.
329 var evt = document.createEvent("Event");
330 evt.initEvent(type == "sub_frame" ? "load" : "error");
331 event.target.dispatchEvent(evt);
332 }
322 }, true); 333 }, true);
323 334
324 335
325 /* API */ 336 /* API */
326 337
327 ext.backgroundPage = { 338 ext.backgroundPage = {
328 sendMessage: function(message, responseCallback) { 339 sendMessage: function(message, responseCallback)
Felix Dahlke 2014/01/18 13:39:19 { should go on its own line
Sebastian Noack 2014/01/19 10:19:40 Done.
340 {
329 _sendMessage( 341 _sendMessage(
330 message, responseCallback, 342 message, responseCallback,
331 safari.self.tab, safari.self, 343 safari.self.tab, safari.self,
332 { 344 {
333 documentUrl: document.location.href, 345 documentUrl: document.location.href,
334 isTopLevel: window == window.top 346 isTopLevel: window == window.top
335 } 347 }
336 ); 348 );
337 }, 349 },
338 getWindow: function() 350 getWindow: function()
339 { 351 {
340 return proxy.getObject(0); 352 return proxy.getObject(0);
341 } 353 }
342 }; 354 };
343 355
344 ext.onMessage = new ContentMessageEventTarget(); 356 ext.onMessage = new ContentMessageEventTarget();
357
358
359 // Safari does not pass the element which the context menu is refering to
360 // so we need to add it to the event's user info.
361 document.addEventListener("contextmenu", function(event)
362 {
363 var element = event.srcElement;
364 safari.self.tab.setContextMenuEventUserInfo(event, {
365 srcUrl: ("src" in element) ? element.src : null,
366 tagName: element.localName
367 });
368 }, false);
345 })(); 369 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld