| LEFT | RIGHT |
| 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 11 matching lines...) Expand all Loading... |
| 22 var TabEventTarget = function() | 22 var TabEventTarget = function() |
| 23 { | 23 { |
| 24 WrappedEventTarget.apply(this, arguments); | 24 WrappedEventTarget.apply(this, arguments); |
| 25 }; | 25 }; |
| 26 TabEventTarget.prototype = { | 26 TabEventTarget.prototype = { |
| 27 __proto__: WrappedEventTarget.prototype, | 27 __proto__: WrappedEventTarget.prototype, |
| 28 _wrapListener: function(listener) | 28 _wrapListener: function(listener) |
| 29 { | 29 { |
| 30 return function(event) | 30 return function(event) |
| 31 { | 31 { |
| 32 listener(new Tab(event.target)); | 32 if (event.target instanceof SafariBrowserTab) |
| 33 listener(new Tab(event.target)); |
| 33 }; | 34 }; |
| 34 } | 35 } |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 Tab = function(tab) | 38 Tab = function(tab) |
| 38 { | 39 { |
| 39 this._tab = tab; | 40 this._tab = tab; |
| 40 | 41 |
| 41 this._eventTarget = tab; | 42 this._eventTarget = tab; |
| 42 this._messageDispatcher = tab.page; | 43 this._messageDispatcher = tab.page; |
| 43 | |
| 44 this.url = tab.url; | |
| 45 | 44 |
| 46 this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false); | 45 this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false); |
| 47 this.onCompleted = new TabEventTarget(tab, "navigate", false); | 46 this.onCompleted = new TabEventTarget(tab, "navigate", false); |
| 48 this.onActivated = new TabEventTarget(tab, "activate", false); | 47 this.onActivated = new TabEventTarget(tab, "activate", false); |
| 49 this.onRemoved = new TabEventTarget(tab, "close", false); | 48 this.onRemoved = new TabEventTarget(tab, "close", false); |
| 50 }; | 49 }; |
| 51 Tab.prototype = { | 50 Tab.prototype = { |
| 51 get url() |
| 52 { |
| 53 return this._tab.url; |
| 54 }, |
| 52 close: function() | 55 close: function() |
| 53 { | 56 { |
| 54 this._tab.close(); | 57 this._tab.close(); |
| 55 }, | 58 }, |
| 56 activate: function() | 59 activate: function() |
| 57 { | 60 { |
| 58 this._tab.activate(); | 61 this._tab.activate(); |
| 59 }, | 62 }, |
| 60 sendMessage: sendMessage, | 63 sendMessage: sendMessage, |
| 61 pageAction: { | 64 pageAction: { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 this._values.splice(idx, 1); | 128 this._values.splice(idx, 1); |
| 126 | 129 |
| 127 tab.removeEventListener("close", this._onClosed, false); | 130 tab.removeEventListener("close", this._onClosed, false); |
| 128 } | 131 } |
| 129 }, | 132 }, |
| 130 _onClosed: function(event) | 133 _onClosed: function(event) |
| 131 { | 134 { |
| 132 this._delete(event.target); | 135 this._delete(event.target); |
| 133 } | 136 } |
| 134 }; | 137 }; |
| 135 TabMap.prototype["delete"] = function(tab) { | 138 TabMap.prototype["delete"] = function(tab) |
| 139 { |
| 136 this._delete(tab._tab); | 140 this._delete(tab._tab); |
| 137 }; | 141 }; |
| 138 | 142 |
| 139 | 143 |
| 140 /* Windows */ | 144 /* Windows */ |
| 141 | 145 |
| 142 Window = function(win) | 146 Window = function(win) |
| 143 { | 147 { |
| 144 this._win = win; | 148 this._win = win; |
| 145 this.visible = win.visible; | |
| 146 } | 149 } |
| 147 Window.prototype = { | 150 Window.prototype = { |
| 151 get visible() |
| 152 { |
| 153 return this._win.visible; |
| 154 }, |
| 148 getAllTabs: function(callback) | 155 getAllTabs: function(callback) |
| 149 { | 156 { |
| 150 callback(this._win.tabs.map(function(tab) { return new Tab(tab); })); | 157 callback(this._win.tabs.map(function(tab) { return new Tab(tab); })); |
| 151 }, | 158 }, |
| 152 getActiveTab: function(callback) | 159 getActiveTab: function(callback) |
| 153 { | 160 { |
| 154 callback(new Tab(this._win.activeTab)); | 161 callback(new Tab(this._win.activeTab)); |
| 155 }, | 162 }, |
| 156 openTab: function(url, callback) | 163 openTab: function(url, callback) |
| 157 { | 164 { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 _urlPatterns: [], | 405 _urlPatterns: [], |
| 399 | 406 |
| 400 _handleMessage: function(message, tab) | 407 _handleMessage: function(message, tab) |
| 401 { | 408 { |
| 402 tab = new Tab(tab); | 409 tab = new Tab(tab); |
| 403 | 410 |
| 404 for (var i = 0; i < this._listeners.length; i++) | 411 for (var i = 0; i < this._listeners.length; i++) |
| 405 { | 412 { |
| 406 var regex = this._urlPatterns[i]; | 413 var regex = this._urlPatterns[i]; |
| 407 | 414 |
| 408 if (!regex || regex.test(message)) | 415 if ((!regex || regex.test(message.url)) && this._listeners[i](messag
e.url, message.type, tab, 0, -1) === false) |
| 409 if (this._listeners[i](message.url, message.type, tab, 0, -1) === fa
lse) | |
| 410 return false; | 416 return false; |
| 411 } | 417 } |
| 412 | 418 |
| 413 return true; | 419 return true; |
| 414 }, | 420 }, |
| 415 addListener: function(listener, urls) | 421 addListener: function(listener, urls) |
| 416 { | 422 { |
| 417 var regex; | 423 var regex; |
| 418 | 424 |
| 419 if (urls) | 425 if (urls) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 }; | 497 }; |
| 492 | 498 |
| 493 ext.backgroundPage = { | 499 ext.backgroundPage = { |
| 494 getWindow: function() | 500 getWindow: function() |
| 495 { | 501 { |
| 496 return safari.extension.globalPage.contentWindow; | 502 return safari.extension.globalPage.contentWindow; |
| 497 } | 503 } |
| 498 }; | 504 }; |
| 499 | 505 |
| 500 ext.onMessage = new MessageEventTarget(safari.application); | 506 ext.onMessage = new MessageEventTarget(safari.application); |
| 507 |
| 508 |
| 509 // 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 |
| 511 // force the same behavior in Safari, we are going to reload the page of the |
| 512 // bubble everytime it is shown. |
| 513 if (safari.extension.globalPage.contentWindow != window) |
| 514 safari.application.addEventListener("popover", function() |
| 515 { |
| 516 document.documentElement.style.display = "none"; |
| 517 document.location.reload(); |
| 518 }, true); |
| 501 })(); | 519 })(); |
| LEFT | RIGHT |