Left: | ||
Right: |
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 |
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 var isPreloadedPage = function(message, tab) | 20 var isTabVisible = function(tab) |
21 { | 21 { |
22 // the message was sent by a preloaded page if document.hidden was set, desp ite the tab is visible | 22 return tab.browserWindow.visible && tab.browserWindow.activeTab == tab; |
23 return message.isDocumentHidden && tab.browserWindow.visible && tab.browserW indow.activeTab == tab | 23 }; |
24 | |
25 var sentByPreloadedPage = function(message, tab) | |
26 { | |
27 // the message was sent by a preloaded page if document.hidden was set, | |
28 // despite the tab is visible | |
29 return message.isDocumentHidden && isTabVisible(tab); | |
24 }; | 30 }; |
25 | 31 |
26 | 32 |
27 /* Events */ | 33 /* Events */ |
28 | 34 |
29 var TabEventTarget = function() | 35 var TabEventTarget = function() |
30 { | 36 { |
31 WrappedEventTarget.apply(this, arguments); | 37 WrappedEventTarget.apply(this, arguments); |
32 }; | 38 }; |
33 TabEventTarget.prototype = { | 39 TabEventTarget.prototype = { |
(...skipping 17 matching lines...) Expand all Loading... | |
51 __proto__: WrappedEventTarget.prototype, | 57 __proto__: WrappedEventTarget.prototype, |
52 _wrapListener: function(listener) | 58 _wrapListener: function(listener) |
53 { | 59 { |
54 return function (event) | 60 return function (event) |
55 { | 61 { |
56 switch (event.name) | 62 switch (event.name) |
57 { | 63 { |
58 case "loading": | 64 case "loading": |
59 var tab = new Tab(event.target); | 65 var tab = new Tab(event.target); |
60 | 66 |
61 // when the "loading" message was sent form a preloaded | 67 // when the "loading" message was sent form a preloaded |
Wladimir Palant
2014/01/24 14:11:34
form => from
| |
62 // page in Safari 7.0, we have to wait until the page is | 68 // page in Safari 7.0, we have to wait until the page is |
63 // shown, before calling the listener. The high-level code | 69 // shown, before calling the listener. The high-level code |
64 // doesn't know anything about preloaded pages and expects | 70 // doesn't know anything about preloaded pages and expects |
65 // all events to be related to the current visible page. | 71 // all events to be related to the current visible page. |
66 if (isPreloadedPage(event.message, event.target)) | 72 if (sentByPreloadedPage(event.message, event.target)) |
67 this._preloadedTabs.set(tab, null); | 73 this._preloadedTabs.set(tab, null); |
68 else | 74 else |
69 { | 75 { |
70 this._preloadedTabs.delete(tab); | 76 this._preloadedTabs.delete(tab); |
71 listener(tab); | 77 listener(tab); |
72 } | 78 } |
73 | 79 |
74 break; | 80 break; |
75 case "show": | 81 case "show": |
76 var tab = new Tab(event.target); | 82 var tab = new Tab(event.target); |
77 | 83 |
78 if (this._preloadedTabs.has(tab)) | 84 if (this._preloadedTabs.has(tab)) |
79 { | 85 { |
80 this._preloadedTabs.delete(tab); | 86 this._preloadedTabs.delete(tab); |
Wladimir Palant
2014/01/24 14:11:34
What if a preloaded page is simply discarded? Won'
Sebastian Noack
2014/01/24 14:17:49
Just temporarily until another page is loaded in t
| |
81 listener(tab); | 87 listener(tab); |
82 } | 88 } |
83 } | 89 } |
84 }.bind(this); | 90 }.bind(this); |
85 } | 91 } |
86 }; | 92 }; |
87 | 93 |
88 var BackgroundMessageEventTarget = function() | 94 var BackgroundMessageEventTarget = function() |
89 { | 95 { |
90 MessageEventTarget.call(this, safari.application); | 96 MessageEventTarget.call(this, safari.application); |
(...skipping 14 matching lines...) Expand all Loading... | |
105 event.target | 111 event.target |
106 ) | 112 ) |
107 }; | 113 }; |
108 }, | 114 }, |
109 _ignoreIf: function(event) | 115 _ignoreIf: function(event) |
110 { | 116 { |
111 // when receiving a message from a preloaded page in Safari 7.0, we | 117 // when receiving a message from a preloaded page in Safari 7.0, we |
112 // have to defer procesing of that message, until the page is shown. | 118 // have to defer procesing of that message, until the page is shown. |
113 // The high-level code doesn't know anything about preloaded pages | 119 // The high-level code doesn't know anything about preloaded pages |
114 // and expects all message to be sent from the current visible page. | 120 // and expects all message to be sent from the current visible page. |
115 if (isPreloadedPage(event.message, event.target)) | 121 if (sentByPreloadedPage(event.message, event.target)) |
116 { | 122 { |
117 event.target.page.dispatchMessage("response", { | 123 event.target.page.dispatchMessage("response", { |
118 requestId: event.message.requestId, | 124 requestId: event.message.requestId, |
119 deferred: true | 125 deferred: true |
120 }); | 126 }); |
121 return true; | 127 return true; |
122 } | 128 } |
123 | 129 |
124 return false; | 130 return false; |
125 } | 131 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 // message payload | 164 // message payload |
159 message, | 165 message, |
160 // response callback | 166 // response callback |
161 responseCallback && function(response) { responseCallback(response.paylo ad); }, | 167 responseCallback && function(response) { responseCallback(response.paylo ad); }, |
162 // message dispatcher | 168 // message dispatcher |
163 this._tab.page, | 169 this._tab.page, |
164 // response event target | 170 // response event target |
165 this._tab, | 171 this._tab, |
166 // extra data | 172 // extra data |
167 { | 173 { |
168 isTabVisible: this._tab.browserWindow.visible && | 174 isTabVisible: isTabVisible(this._tab) |
169 this._tab.browserWindow.activeTab == this._tab | |
170 } | 175 } |
171 ); | 176 ); |
172 } | 177 } |
173 }; | 178 }; |
174 | 179 |
175 TabMap = function(deleteOnPageUnload) | 180 TabMap = function(deleteOnPageUnload) |
176 { | 181 { |
177 this._data = []; | 182 this._data = []; |
178 this._deleteOnPageUnload = deleteOnPageUnload; | 183 this._deleteOnPageUnload = deleteOnPageUnload; |
179 | 184 |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 ext.webRequest = { | 638 ext.webRequest = { |
634 onBeforeRequest: { | 639 onBeforeRequest: { |
635 _listeners: [], | 640 _listeners: [], |
636 | 641 |
637 _handleMessage: function(message, rawTab) | 642 _handleMessage: function(message, rawTab) |
638 { | 643 { |
639 // we have to defer loading of resources on preloaded pages | 644 // we have to defer loading of resources on preloaded pages |
640 // in Safari 7.0, until the page is shown. The high-level code | 645 // in Safari 7.0, until the page is shown. The high-level code |
641 // doesn't know anything about preloaded pages and expects all | 646 // doesn't know anything about preloaded pages and expects all |
642 // web requests to be related to the current visible page. | 647 // web requests to be related to the current visible page. |
643 if (isPreloadedPage(message, rawTab)) | 648 if (sentByPreloadedPage(message, rawTab)) |
644 return "deferred"; | 649 return "deferred"; |
645 | 650 |
646 var tab = new Tab(rawTab); | 651 var tab = new Tab(rawTab); |
647 var frame = new Frame(message.documentUrl, message.isTopLevel, rawTab); | 652 var frame = new Frame(message.documentUrl, message.isTopLevel, rawTab); |
648 | 653 |
649 for (var i = 0; i < this._listeners.length; i++) | 654 for (var i = 0; i < this._listeners.length; i++) |
650 { | 655 { |
651 if (this._listeners[i](message.url, message.type, tab, frame) === fals e) | 656 if (this._listeners[i](message.url, message.type, tab, frame) === fals e) |
652 return "blocked"; | 657 return "blocked"; |
653 } | 658 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 for (var i = 0; i < contextMenuItems.length; i++) | 780 for (var i = 0; i < contextMenuItems.length; i++) |
776 { | 781 { |
777 if (contextMenuItems[i].id == event.command) | 782 if (contextMenuItems[i].id == event.command) |
778 { | 783 { |
779 contextMenuItems[i].onclick(event.userInfo.srcUrl, new Tab(safari.applic ation.activeBrowserWindow.activeTab)); | 784 contextMenuItems[i].onclick(event.userInfo.srcUrl, new Tab(safari.applic ation.activeBrowserWindow.activeTab)); |
780 break; | 785 break; |
781 } | 786 } |
782 } | 787 } |
783 }, false); | 788 }, false); |
784 })(); | 789 })(); |
LEFT | RIGHT |