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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 { | 139 { |
137 this._delete(tab._tab); | 140 this._delete(tab._tab); |
138 }; | 141 }; |
139 | 142 |
140 | 143 |
141 /* Windows */ | 144 /* Windows */ |
142 | 145 |
143 Window = function(win) | 146 Window = function(win) |
144 { | 147 { |
145 this._win = win; | 148 this._win = win; |
146 this.visible = win.visible; | |
147 } | 149 } |
148 Window.prototype = { | 150 Window.prototype = { |
| 151 get visible() |
| 152 { |
| 153 return this._win.visible; |
| 154 }, |
149 getAllTabs: function(callback) | 155 getAllTabs: function(callback) |
150 { | 156 { |
151 callback(this._win.tabs.map(function(tab) { return new Tab(tab); })); | 157 callback(this._win.tabs.map(function(tab) { return new Tab(tab); })); |
152 }, | 158 }, |
153 getActiveTab: function(callback) | 159 getActiveTab: function(callback) |
154 { | 160 { |
155 callback(new Tab(this._win.activeTab)); | 161 callback(new Tab(this._win.activeTab)); |
156 }, | 162 }, |
157 openTab: function(url, callback) | 163 openTab: function(url, callback) |
158 { | 164 { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 _urlPatterns: [], | 405 _urlPatterns: [], |
400 | 406 |
401 _handleMessage: function(message, tab) | 407 _handleMessage: function(message, tab) |
402 { | 408 { |
403 tab = new Tab(tab); | 409 tab = new Tab(tab); |
404 | 410 |
405 for (var i = 0; i < this._listeners.length; i++) | 411 for (var i = 0; i < this._listeners.length; i++) |
406 { | 412 { |
407 var regex = this._urlPatterns[i]; | 413 var regex = this._urlPatterns[i]; |
408 | 414 |
409 if ((!regex || regex.test(message)) && this._listeners[i](message.ur
l, message.type, tab, 0, -1) === false) | 415 if ((!regex || regex.test(message.url)) && this._listeners[i](messag
e.url, message.type, tab, 0, -1) === false) |
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 |