Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: safari/ext/background.js

Issue 5099207639695360: Made browser actions per tab on Safari (Closed)
Patch Set: Created Dec. 27, 2013, 7:22 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: safari/ext/background.js
===================================================================
--- a/safari/ext/background.js
+++ b/safari/ext/background.js
@@ -81,6 +81,8 @@
{
this._tab = tab;
+ this.browserAction = new BrowserAction(this);
+
this.onLoading = new LoadingTabEventTarget(tab);
this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false);
this.onCompleted = new TabEventTarget(tab, "navigate", false);
@@ -106,23 +108,6 @@
message, responseCallback,
this._tab.page, this._tab
);
- },
- browserAction: {
- setIcon: function(path)
- {
- safari.extension.toolbarItems[0].image = safari.extension.baseURI + path;
- },
- setTitle: function(title)
- {
- safari.extension.toolbarItems[0].toolTip = title;
- },
- setBadge: function(badge)
- {
- if (!badge)
- safari.extension.toolbarItems[0].badge = 0;
- else if ("number" in badge)
- safari.extension.toolbarItems[0].badge = badge.number;
- }
}
};
@@ -193,6 +178,86 @@
this._delete(tab._tab);
};
+ ext.tabs = {
+ onLoading: new LoadingTabEventTarget(safari.application),
+ onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", true),
+ onCompleted: new TabEventTarget(safari.application, "navigate", true),
+ onActivated: new TabEventTarget(safari.application, "activate", true),
+ onRemoved: new TabEventTarget(safari.application, "close", true)
+ };
+
+
+ /* Browser actions */
+
+ var globalTooltipItemProperties = {}
+ var tooltipItemPropertiesPerTab = new TabMap();
Wladimir Palant 2014/01/15 15:24:47 You meant toolbarItem, not tooltipItem, right?
Sebastian Noack 2014/01/15 19:25:47 It is gone now.
+
+ var getToolbarItemForWindow = function(win)
+ {
+ for (var i = 0; i < safari.extension.toolbarItems.length; i++)
+ {
+ var toolbarItem = safari.extension.toolbarItems[i];
+
+ if (toolbarItem.browserWindow == win)
+ return toolbarItem;
+ }
Wladimir Palant 2014/01/15 15:24:47 This should return something if no toolbar item is
Sebastian Noack 2014/01/15 19:25:47 Done. Even though I think that it is a bug when th
+ };
+
+ var BrowserAction = function(tab)
+ {
+ this._tab = tab;
+ };
+ BrowserAction.prototype = {
+ _set: function(property, value)
+ {
+ var currentWindow = this._tab._tab.browserWindow;
+ var toolbarItem = getToolbarItemForWindow(currentWindow);
+
+ if (!(property in globalTooltipItemProperties))
+ globalTooltipItemProperties[property] = toolbarItem[property];
+
+ if (this._tab._tab == currentWindow.activeTab)
+ toolbarItem[property] = value;
+
+ var props = tooltipItemPropertiesPerTab.get(this._tab);
+ if (!props)
+ {
+ props = {};
+ tooltipItemPropertiesPerTab.set(this._tab, props);
+ }
+ props[property] = value;
+ },
+ setIcon: function(path)
+ {
+ this._set("image", safari.extension.baseURI + path);
+ },
+ setTitle: function(title)
+ {
+ this._set("toolTip", title);
+ },
+ setBadge: function(badge)
+ {
+ if (!badge)
+ this._set("badge", 0);
+ else if ("number" in badge)
+ this._set("badge", badge.number);
+ }
+ };
+
+ ext.tabs.onActivated.addListener(function(tab)
+ {
+ var props = tooltipItemPropertiesPerTab.get(tab);
+ var toolbarItem = getToolbarItemForWindow(tab._tab.browserWindow);
+
+ for (var property in globalTooltipItemProperties)
+ {
+ if (props && property in props)
+ toolbarItem[property] = props[property];
+ else
+ toolbarItem[property] = globalTooltipItemProperties[property];
+ }
Wladimir Palant 2014/01/15 15:24:47 What's the point of globalTooltipItemProperties? I
Sebastian Noack 2014/01/15 19:25:47 This approach just emulates the behavior we alread
+ });
+
/* Windows */
@@ -538,14 +603,6 @@
}
};
- ext.tabs = {
- onLoading: new LoadingTabEventTarget(safari.application),
- onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", true),
- onCompleted: new TabEventTarget(safari.application, "navigate", true),
- onActivated: new TabEventTarget(safari.application, "activate", true),
- onRemoved: new TabEventTarget(safari.application, "close", true)
- };
-
ext.backgroundPage = {
getWindow: function()
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld