| Index: chrome/ext/background.js |
| =================================================================== |
| --- a/chrome/ext/background.js |
| +++ b/chrome/ext/background.js |
| @@ -191,58 +191,62 @@ |
| }; |
| + /* Browser actions */ |
| + |
| + var BrowserAction = function() {}; |
| + BrowserAction.prototype = { |
| + _prepareParams: function(params) {}, |
| + _apply: function(method, params) |
| + { |
| + this._prepareParams(params); |
| + chrome.browserAction[method](params); |
| + }, |
| + setIcon: function(path) |
| + { |
| + this._apply("setIcon", {path: path}); |
| + }, |
| + setTitle: function(title) |
| + { |
| + this._apply("setTitle", {title: title}); |
| + }, |
| + setBadge: function(badge) |
| + { |
| + if (badge) |
| + { |
| + if ("color" in badge) |
| + this._apply("setBadgeBackgroundColor", {color: badge.color}); |
| + |
| + if ("number" in badge) |
| + this._apply("setBadgeText", {text: badge.number.toString()}); |
| + } |
| + else |
| + this._apply("setBadgeText", {text: ""}); |
| + } |
| + }; |
| + |
| + var TabBrowserAction = function(tabId) |
| + { |
| + this._tabId = tabId; |
| + }; |
| + TabBrowserAction.prototype = { |
| + __proto__: BrowserAction.prototype, |
| + _prepareParams: function(params) |
| + { |
| + params.tabId = this._tabId; |
| + } |
| + }; |
| + |
| + |
| /* Tabs */ |
| var sendMessage = chrome.tabs.sendMessage || chrome.tabs.sendRequest; |
| - var BrowserAction = function(tabId) |
| - { |
| - this._tabId = tabId; |
| - }; |
| - BrowserAction.prototype = { |
| - setIcon: function(path) |
| - { |
| - chrome.browserAction.setIcon({tabId: this._tabId, path: path}); |
| - }, |
| - setTitle: function(title) |
| - { |
| - chrome.browserAction.setTitle({tabId: this._tabId, title: title}); |
| - }, |
| - setBadge: function(badge) |
| - { |
| - if (!badge) |
| - { |
| - chrome.browserAction.setBadgeText({ |
| - tabId: this._tabId, |
| - text: "" |
| - }); |
| - return; |
| - } |
| - |
| - if ("color" in badge) |
| - { |
| - chrome.browserAction.setBadgeBackgroundColor({ |
| - tabId: this._tabId, |
| - color: badge.color |
| - }); |
| - } |
| - |
| - if ("number" in badge) |
| - { |
| - chrome.browserAction.setBadgeText({ |
| - tabId: this._tabId, |
| - text: badge.number.toString() |
| - }); |
| - } |
| - } |
| - }; |
| - |
| Tab = function(tab) |
| { |
| this._id = tab.id; |
| this._url = tab.url; |
| - this.browserAction = new BrowserAction(tab.id); |
| + this.browserAction = new TabBrowserAction(tab.id); |
| this.onBeforeNavigate = ext.tabs.onBeforeNavigate._bindToTab(this); |
| this.onLoading = ext.tabs.onLoading._bindToTab(this); |
| @@ -534,4 +538,5 @@ |
| }; |
| ext.onMessage = new BackgroundMessageEventTarget(); |
| + ext.browserAction = new BrowserAction(); |
|
Wladimir Palant
2014/01/16 09:10:05
This is unnecessary IMHO, ext.browserAction can be
Sebastian Noack
2014/01/16 12:45:02
I think it is a pretty bad idea to have different
Wladimir Palant
2014/01/16 12:55:18
It obscures the logic even more than it already is
Sebastian Noack
2014/01/16 14:01:52
I don't agree. It isn't that much code, I have add
Wladimir Palant
2014/01/17 07:54:36
Quite frankly, I disagree. IMHO the abstraction la
Sebastian Noack
2014/01/17 12:56:14
My main concern is having different behavior for S
|
| })(); |