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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 iconAnimation = { | 18 iconAnimation = { |
19 _icons: new TabMap(), | 19 _icons: new ext.PageMap(), |
20 _animatedTabs: new TabMap(), | 20 _animatedPages: new ext.PageMap(), |
21 _step: 0, | 21 _step: 0, |
22 | 22 |
23 update: function(type) | 23 update: function(type) |
24 { | 24 { |
25 if (type == this._type) | 25 if (type == this._type) |
26 return; | 26 return; |
27 | 27 |
28 if (!this._type) | 28 if (!this._type) |
29 this._start(); | 29 this._start(); |
30 | 30 |
31 this._type = type; | 31 this._type = type; |
32 }, | 32 }, |
33 stop: function() | 33 stop: function() |
34 { | 34 { |
35 clearInterval(this._interval); | 35 clearInterval(this._interval); |
36 | 36 |
37 delete this._interval; | 37 delete this._interval; |
38 delete this._type; | 38 delete this._type; |
39 | 39 |
40 this._animatedTabs.clear(); | 40 this._animatedPages.clear(); |
41 }, | 41 }, |
42 registerTab: function(tab, icon) | 42 registerPage: function(page, icon) |
43 { | 43 { |
44 this._icons.set(tab, icon); | 44 this._icons.set(page, icon); |
45 | 45 |
46 if (this._animatedTabs.has(tab)) | 46 if (this._animatedPages.has(page)) |
47 this._updateIcon(tab); | 47 this._updateIcon(page); |
48 }, | 48 }, |
49 _start: function() | 49 _start: function() |
50 { | 50 { |
51 this._interval = setInterval(function() | 51 this._interval = setInterval(function() |
52 { | 52 { |
53 this._getVisibleTabs(function(tabs) | 53 ext.pages.query({active: true, visibleWindow: true}, function(pages) |
54 { | 54 { |
55 if (tabs.length == 0) | 55 if (pages.length == 0) |
56 return; | 56 return; |
57 | 57 |
58 for (var i = 0; i < tabs.length; i++) | 58 for (var i = 0; i < pages.length; i++) |
59 this._animatedTabs.set(tabs[i], null); | 59 this._animatedPages.set(pages[i], null); |
60 | 60 |
61 var interval = setInterval(function() | 61 var interval = setInterval(function() |
62 { | 62 { |
63 this._step++; | 63 this._step++; |
64 tabs.forEach(this._updateIcon.bind(this)); | 64 pages.forEach(this._updateIcon.bind(this)); |
65 | 65 |
66 if (this._step < 10) | 66 if (this._step < 10) |
67 return; | 67 return; |
68 | 68 |
69 clearInterval(interval); | 69 clearInterval(interval); |
70 setTimeout(function() | 70 setTimeout(function() |
71 { | 71 { |
72 interval = setInterval(function() | 72 interval = setInterval(function() |
73 { | 73 { |
74 this._step--; | 74 this._step--; |
75 tabs.forEach(this._updateIcon.bind(this)); | 75 pages.forEach(this._updateIcon.bind(this)); |
76 | 76 |
77 if (this._step > 0) | 77 if (this._step > 0) |
78 return; | 78 return; |
79 | 79 |
80 clearInterval(interval); | 80 clearInterval(interval); |
81 this._animatedTabs.clear(); | 81 this._animatedPages.clear(); |
82 }.bind(this), 100); | 82 }.bind(this), 100); |
83 }.bind(this), 1000); | 83 }.bind(this), 1000); |
84 }.bind(this), 100); | 84 }.bind(this), 100); |
85 }.bind(this)); | 85 }.bind(this)); |
86 }.bind(this), 15000); | 86 }.bind(this), 15000); |
87 }, | 87 }, |
88 _getVisibleTabs: function(callback) | 88 _updateIcon: function(page) |
89 { | 89 { |
90 ext.windows.getAll(function(windows) | 90 var path = this._icons.get(page); |
91 { | |
92 var tabs = []; | |
93 var visibleWindows = windows.length; | |
94 | |
95 for (var i = 0; i < windows.length; i++) | |
96 { | |
97 if (!windows[i].visible) | |
98 { | |
99 if (--visibleWindows == 0) | |
100 callback(tabs); | |
101 | |
102 continue; | |
103 } | |
104 | |
105 windows[i].getActiveTab(function(tab) | |
106 { | |
107 tabs.push(tab); | |
108 | |
109 if (tabs.length == visibleWindows) | |
110 callback(tabs); | |
111 }); | |
112 } | |
113 }); | |
114 }, | |
115 _updateIcon: function(tab) | |
116 { | |
117 var path = this._icons.get(tab); | |
118 | 91 |
119 if (!path) | 92 if (!path) |
120 return; | 93 return; |
121 | 94 |
122 if (this._step > 0) | 95 if (this._step > 0) |
123 { | 96 { |
124 var suffix = "-notification-" + this._type; | 97 var suffix = "-notification-" + this._type; |
125 | 98 |
126 if (this._step < 10) | 99 if (this._step < 10) |
127 suffix += "-" + this._step; | 100 suffix += "-" + this._step; |
128 | 101 |
129 path = path.replace(/(?=\..+$)/, suffix); | 102 path = path.replace(/(?=\..+$)/, suffix); |
130 } | 103 } |
131 | 104 |
132 tab.browserAction.setIcon(path); | 105 page.browserAction.setIcon(path); |
133 } | 106 } |
134 }; | 107 }; |
OLD | NEW |