OLD | NEW |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 (function() | 18 (function() |
19 { | 19 { |
20 if (window == window.top) | 20 if (window == window.top) |
21 safari.self.tab.dispatchMessage("loading"); | 21 safari.self.tab.dispatchMessage("loading"); |
22 | 22 |
23 | 23 |
| 24 /* Events */ |
| 25 |
| 26 var ContentMessageEventTarget = function() |
| 27 { |
| 28 MessageEventTarget.call(this, safari.self); |
| 29 }; |
| 30 ContentMessageEventTarget.prototype = { |
| 31 __proto__: MessageEventTarget.prototype, |
| 32 _getResponseDispatcher: function(event) |
| 33 { |
| 34 return event.target.tab; |
| 35 }, |
| 36 _getSenderDetails: function(event) |
| 37 { |
| 38 return {}; |
| 39 } |
| 40 }; |
| 41 |
| 42 |
24 /* Background page proxy */ | 43 /* Background page proxy */ |
25 var proxy = { | 44 var proxy = { |
26 objects: [], | 45 objects: [], |
27 callbacks: [], | 46 callbacks: [], |
28 | 47 |
29 send: function(message) | 48 send: function(message) |
30 { | 49 { |
31 var evt = document.createEvent("Event"); | 50 var evt = document.createEvent("Event"); |
32 evt.initEvent("beforeload"); | 51 evt.initEvent("beforeload"); |
33 return safari.self.tab.canLoad(evt, {type: "proxy", payload: message}); | 52 return safari.self.tab.canLoad(evt, {type: "proxy", payload: message}); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 case "link": | 302 case "link": |
284 if (/\bstylesheet\b/i.test(event.target.rel)) | 303 if (/\bstylesheet\b/i.test(event.target.rel)) |
285 { | 304 { |
286 type = "stylesheet"; | 305 type = "stylesheet"; |
287 break; | 306 break; |
288 } | 307 } |
289 default: | 308 default: |
290 type = "other"; | 309 type = "other"; |
291 } | 310 } |
292 | 311 |
293 if (!safari.self.tab.canLoad(event, {type: "webRequest", payload: {url: even
t.url, type: type}})) | 312 if (!safari.self.tab.canLoad( |
| 313 event, { |
| 314 type: "webRequest", |
| 315 payload: { |
| 316 url: event.url, |
| 317 type: type, |
| 318 documentUrl: document.location.href, |
| 319 isTopLevel: window == window.top |
| 320 } |
| 321 } |
| 322 )) |
294 { | 323 { |
295 event.preventDefault(); | 324 event.preventDefault(); |
296 | 325 |
297 // Safari doesn't dispatch an "error" or "load" event when preventing an | 326 // Safari doesn't dispatch an "error" or "load" event when preventing an |
298 // element from loading by cancelling the "beforeload" event. So we have | 327 // element from loading by cancelling the "beforeload" event. So we have |
299 // to dispatch it manually. Otherwise element collapsing wouldn't work. | 328 // to dispatch it manually. Otherwise element collapsing wouldn't work. |
300 var evt = document.createEvent("Event"); | 329 var evt = document.createEvent("Event"); |
301 evt.initEvent(type == "sub_frame" ? "load" : "error"); | 330 evt.initEvent(type == "sub_frame" ? "load" : "error"); |
302 event.target.dispatchEvent(evt); | 331 event.target.dispatchEvent(evt); |
303 } | 332 } |
304 }, true); | 333 }, true); |
305 | 334 |
306 | 335 |
307 /* API */ | 336 /* API */ |
308 | 337 |
309 ext.backgroundPage = { | 338 ext.backgroundPage = { |
310 _eventTarget: safari.self, | 339 sendMessage: function(message, responseCallback) |
311 _messageDispatcher: safari.self.tab, | 340 { |
312 | 341 _sendMessage( |
313 sendMessage: sendMessage, | 342 message, responseCallback, |
314 getWindow: function() { return proxy.getObject(0); } | 343 safari.self.tab, safari.self, |
| 344 { |
| 345 documentUrl: document.location.href, |
| 346 isTopLevel: window == window.top |
| 347 } |
| 348 ); |
| 349 }, |
| 350 getWindow: function() |
| 351 { |
| 352 return proxy.getObject(0); |
| 353 } |
315 }; | 354 }; |
316 | 355 |
317 ext.onMessage = new MessageEventTarget(safari.self); | 356 ext.onMessage = new ContentMessageEventTarget(); |
| 357 |
318 | 358 |
319 // Safari does not pass the element which the context menu is refering to | 359 // Safari does not pass the element which the context menu is refering to |
320 // so we need to add it to the event's user info. | 360 // so we need to add it to the event's user info. |
321 document.addEventListener("contextmenu", function(event) | 361 document.addEventListener("contextmenu", function(event) |
322 { | 362 { |
323 var element = event.srcElement; | 363 var element = event.srcElement; |
324 safari.self.tab.setContextMenuEventUserInfo(event, { | 364 safari.self.tab.setContextMenuEventUserInfo(event, { |
325 srcUrl: ("src" in element) ? element.src : null, | 365 srcUrl: ("src" in element) ? element.src : null, |
326 tagName: element.localName | 366 tagName: element.localName |
327 }); | 367 }); |
328 }, false); | 368 }, false); |
329 })(); | 369 })(); |
OLD | NEW |