| 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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 _wrapListener: function(listener) | 28 _wrapListener: function(listener) |
| 29 { | 29 { |
| 30 return function(event) | 30 return function(event) |
| 31 { | 31 { |
| 32 if (event.target instanceof SafariBrowserTab) | 32 if (event.target instanceof SafariBrowserTab) |
| 33 listener(new Tab(event.target)); | 33 listener(new Tab(event.target)); |
| 34 }; | 34 }; |
| 35 } | 35 } |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 var LoadingTabEventTarget = function(target) |
| 39 { |
| 40 WrappedEventTarget.call(this, target, "message", false); |
| 41 }; |
| 42 LoadingTabEventTarget.prototype = { |
| 43 __proto__: WrappedEventTarget.prototype, |
| 44 _wrapListener: function(listener) |
| 45 { |
| 46 return function (event) |
| 47 { |
| 48 if (event.name == "loading" && event.message == event.target.url) |
| 49 listener(new Tab(event.target)); |
| 50 }; |
| 51 } |
| 52 }; |
| 53 |
| 38 Tab = function(tab) | 54 Tab = function(tab) |
| 39 { | 55 { |
| 40 this._tab = tab; | 56 this._tab = tab; |
| 41 | 57 |
| 42 this._eventTarget = tab; | 58 this._eventTarget = tab; |
| 43 this._messageDispatcher = tab.page; | 59 this._messageDispatcher = tab.page; |
| 44 | 60 |
| 45 this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false); | 61 this.onLoading = new LoadingTabEventTarget(tab); |
| 46 this.onCompleted = new TabEventTarget(tab, "navigate", false); | 62 this.onCompleted = new TabEventTarget(tab, "navigate", false); |
| 47 this.onActivated = new TabEventTarget(tab, "activate", false); | 63 this.onActivated = new TabEventTarget(tab, "activate", false); |
| 48 this.onRemoved = new TabEventTarget(tab, "close", false); | 64 this.onRemoved = new TabEventTarget(tab, "close", false); |
| 49 }; | 65 }; |
| 50 Tab.prototype = { | 66 Tab.prototype = { |
| 51 get url() | 67 get url() |
| 52 { | 68 { |
| 53 return this._tab.url; | 69 return this._tab.url; |
| 54 }, | 70 }, |
| 55 close: function() | 71 close: function() |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 return new Window(win); | 499 return new Window(win); |
| 484 })); | 500 })); |
| 485 }, | 501 }, |
| 486 getLastFocused: function(callback) | 502 getLastFocused: function(callback) |
| 487 { | 503 { |
| 488 callback(new Window(safari.application.activeBrowserWindow)); | 504 callback(new Window(safari.application.activeBrowserWindow)); |
| 489 } | 505 } |
| 490 }; | 506 }; |
| 491 | 507 |
| 492 ext.tabs = { | 508 ext.tabs = { |
| 493 onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", t
rue), | 509 onLoading: new LoadingTabEventTarget(safari.application), |
| 494 onCompleted: new TabEventTarget(safari.application, "navigate", true), | 510 onCompleted: new TabEventTarget(safari.application, "navigate", true), |
| 495 onActivated: new TabEventTarget(safari.application, "activate", true), | 511 onActivated: new TabEventTarget(safari.application, "activate", true), |
| 496 onRemoved: new TabEventTarget(safari.application, "close", true) | 512 onRemoved: new TabEventTarget(safari.application, "close", true) |
| 497 }; | 513 }; |
| 498 | 514 |
| 499 ext.backgroundPage = { | 515 ext.backgroundPage = { |
| 500 getWindow: function() | 516 getWindow: function() |
| 501 { | 517 { |
| 502 return safari.extension.globalPage.contentWindow; | 518 return safari.extension.globalPage.contentWindow; |
| 503 } | 519 } |
| 504 }; | 520 }; |
| 505 | 521 |
| 506 ext.onMessage = new MessageEventTarget(safari.application); | 522 ext.onMessage = new MessageEventTarget(safari.application); |
| 507 | 523 |
| 508 | 524 |
| 509 // Safari will load the bubble once, and then show it everytime the icon is | 525 // Safari will load the bubble once, and then show it everytime the icon is |
| 510 // clicked. While Chrome loads it everytime you click the icon. So in order to | 526 // clicked. While Chrome loads it everytime you click the icon. So in order to |
| 511 // force the same behavior in Safari, we are going to reload the page of the | 527 // force the same behavior in Safari, we are going to reload the page of the |
| 512 // bubble everytime it is shown. | 528 // bubble everytime it is shown. |
| 513 if (safari.extension.globalPage.contentWindow != window) | 529 if (safari.extension.globalPage.contentWindow != window) |
| 514 safari.application.addEventListener("popover", function() | 530 safari.application.addEventListener("popover", function() |
| 515 { | 531 { |
| 516 document.documentElement.style.display = "none"; | 532 document.documentElement.style.display = "none"; |
| 517 document.location.reload(); | 533 document.location.reload(); |
| 518 }, true); | 534 }, true); |
| 519 })(); | 535 })(); |
| OLD | NEW |