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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 BackgroundMessageEventTarget.prototype = { | 184 BackgroundMessageEventTarget.prototype = { |
185 __proto__: MessageEventTarget.prototype, | 185 __proto__: MessageEventTarget.prototype, |
186 _wrapSender: function(sender) | 186 _wrapSender: function(sender) |
187 { | 187 { |
188 var tab = new Tab(sender.tab); | 188 var tab = new Tab(sender.tab); |
189 return {tab: tab, frame: new Frame({url: sender.url, tab: tab})}; | 189 return {tab: tab, frame: new Frame({url: sender.url, tab: tab})}; |
190 } | 190 } |
191 }; | 191 }; |
192 | 192 |
193 | 193 |
| 194 /* Browser actions */ |
| 195 |
| 196 var BrowserAction = function() {}; |
| 197 BrowserAction.prototype = { |
| 198 _prepareParams: function(params) {}, |
| 199 _apply: function(method, params) |
| 200 { |
| 201 this._prepareParams(params); |
| 202 chrome.browserAction[method](params); |
| 203 }, |
| 204 setIcon: function(path) |
| 205 { |
| 206 this._apply("setIcon", {path: path}); |
| 207 }, |
| 208 setTitle: function(title) |
| 209 { |
| 210 this._apply("setTitle", {title: title}); |
| 211 }, |
| 212 setBadge: function(badge) |
| 213 { |
| 214 if (badge) |
| 215 { |
| 216 if ("color" in badge) |
| 217 this._apply("setBadgeBackgroundColor", {color: badge.color}); |
| 218 |
| 219 if ("number" in badge) |
| 220 this._apply("setBadgeText", {text: badge.number.toString()}); |
| 221 } |
| 222 else |
| 223 this._apply("setBadgeText", {text: ""}); |
| 224 } |
| 225 }; |
| 226 |
| 227 var TabBrowserAction = function(tabId) |
| 228 { |
| 229 this._tabId = tabId; |
| 230 }; |
| 231 TabBrowserAction.prototype = { |
| 232 __proto__: BrowserAction.prototype, |
| 233 _prepareParams: function(params) |
| 234 { |
| 235 params.tabId = this._tabId; |
| 236 } |
| 237 }; |
| 238 |
| 239 |
194 /* Tabs */ | 240 /* Tabs */ |
195 | 241 |
196 var sendMessage = chrome.tabs.sendMessage || chrome.tabs.sendRequest; | 242 var sendMessage = chrome.tabs.sendMessage || chrome.tabs.sendRequest; |
197 | 243 |
198 var BrowserAction = function(tabId) | |
199 { | |
200 this._tabId = tabId; | |
201 }; | |
202 BrowserAction.prototype = { | |
203 setIcon: function(path) | |
204 { | |
205 chrome.browserAction.setIcon({tabId: this._tabId, path: path}); | |
206 }, | |
207 setTitle: function(title) | |
208 { | |
209 chrome.browserAction.setTitle({tabId: this._tabId, title: title}); | |
210 }, | |
211 setBadge: function(badge) | |
212 { | |
213 if (!badge) | |
214 { | |
215 chrome.browserAction.setBadgeText({ | |
216 tabId: this._tabId, | |
217 text: "" | |
218 }); | |
219 return; | |
220 } | |
221 | |
222 if ("color" in badge) | |
223 { | |
224 chrome.browserAction.setBadgeBackgroundColor({ | |
225 tabId: this._tabId, | |
226 color: badge.color | |
227 }); | |
228 } | |
229 | |
230 if ("number" in badge) | |
231 { | |
232 chrome.browserAction.setBadgeText({ | |
233 tabId: this._tabId, | |
234 text: badge.number.toString() | |
235 }); | |
236 } | |
237 } | |
238 }; | |
239 | |
240 Tab = function(tab) | 244 Tab = function(tab) |
241 { | 245 { |
242 this._id = tab.id; | 246 this._id = tab.id; |
243 this._url = tab.url; | 247 this._url = tab.url; |
244 | 248 |
245 this.browserAction = new BrowserAction(tab.id); | 249 this.browserAction = new TabBrowserAction(tab.id); |
246 | 250 |
247 this.onBeforeNavigate = ext.tabs.onBeforeNavigate._bindToTab(this); | 251 this.onBeforeNavigate = ext.tabs.onBeforeNavigate._bindToTab(this); |
248 this.onLoading = ext.tabs.onLoading._bindToTab(this); | 252 this.onLoading = ext.tabs.onLoading._bindToTab(this); |
249 this.onCompleted = ext.tabs.onCompleted._bindToTab(this); | 253 this.onCompleted = ext.tabs.onCompleted._bindToTab(this); |
250 this.onActivated = ext.tabs.onActivated._bindToTab(this); | 254 this.onActivated = ext.tabs.onActivated._bindToTab(this); |
251 this.onRemoved = ext.tabs.onRemoved._bindToTab(this); | 255 this.onRemoved = ext.tabs.onRemoved._bindToTab(this); |
252 }; | 256 }; |
253 Tab.prototype = { | 257 Tab.prototype = { |
254 get url() | 258 get url() |
255 { | 259 { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 } | 531 } |
528 }); | 532 }); |
529 }, | 533 }, |
530 removeAll: function(callback) | 534 removeAll: function(callback) |
531 { | 535 { |
532 chrome.contextMenus.removeAll(callback); | 536 chrome.contextMenus.removeAll(callback); |
533 } | 537 } |
534 }; | 538 }; |
535 | 539 |
536 ext.onMessage = new BackgroundMessageEventTarget(); | 540 ext.onMessage = new BackgroundMessageEventTarget(); |
| 541 ext.browserAction = new BrowserAction(); |
537 })(); | 542 })(); |
OLD | NEW |