diff --git a/extension/chrome/content/browser.js b/extension/chrome/content/browser.js index c439c57..9cc4fd5 100644 --- a/extension/chrome/content/browser.js +++ b/extension/chrome/content/browser.js @@ -18,6 +18,14 @@ get tabTitle() { return tabbrowser.mCurrentBrowser.contentTitle; }, +get tabGroupTitle() { + try + { + return nightlyApp.getTabGroupTitle(window); + } + catch (e) { } +}, + init: function() { var brandbundle = document.getElementById("bundle_brand"); @@ -33,6 +41,11 @@ init: function() tabbrowser.updateTitlebar = nightly.updateTitlebar; tabbrowser.addEventListener("DOMTitleChanged", nightly.updateTitlebar, false); + + try { // import tabGroupTitle functionality for titlebar customization + Components.utils.import("resource://nightly/tabGroupTitle.jsm", nightlyApp); + } + catch(e) { Components.utils.reportError(e); } }, openURL: function(url) diff --git a/extension/chrome/content/nightly.js b/extension/chrome/content/nightly.js index d9d37d4..8d96c74 100644 --- a/extension/chrome/content/nightly.js +++ b/extension/chrome/content/nightly.js @@ -37,6 +37,7 @@ variables: { get compiler() this.appInfo.XPCOMABI.split("-")[1], get defaulttitle() { return nightlyApp.defaultTitle; }, get tabtitle() { return nightlyApp.tabTitle; }, + get tabgroup() { return nightlyApp.tabGroupTitle; }, profile: null, toolkit: "cairo", flags: "" diff --git a/extension/chrome/content/titlebar/customize.js b/extension/chrome/content/titlebar/customize.js index 7310eb5..b2bd2dc 100644 --- a/extension/chrome/content/titlebar/customize.js +++ b/extension/chrome/content/titlebar/customize.js @@ -85,6 +85,7 @@ init: function(aEvent) paneTitle.addVariable("DefaultTitle"); paneTitle.addVariable("TabTitle"); + paneTitle.addVariable("TabGroup"); paneTitle.addVariable("AppID"); paneTitle.addVariable("Vendor"); paneTitle.addVariable("Name"); diff --git a/extension/chrome/locale/en-US/variables.properties b/extension/chrome/locale/en-US/variables.properties index e5f22b2..9993303 100644 --- a/extension/chrome/locale/en-US/variables.properties +++ b/extension/chrome/locale/en-US/variables.properties @@ -20,5 +20,6 @@ variable.Processor.description=Compilation Processor variable.Compiler.description=Compiler variable.DefaultTitle.description=Default Application Title variable.TabTitle.description=Current Tab's Title +variable.TabGroup.description=Current Tab Group variable.Profile.description=Current Profile variable.Toolkit.description=Graphics Toolkit diff --git a/extension/modules/tabGroupTitle.jsm b/extension/modules/tabGroupTitle.jsm new file mode 100644 index 0000000..c0fbb30 --- /dev/null +++ b/extension/modules/tabGroupTitle.jsm @@ -0,0 +1,75 @@ +var EXPORTED_SYMBOLS = ["getTabGroupTitle"]; + +const Cc = Components.classes; +const Ci = Components.interfaces; + +const GROUP_DATA_IDENTIFIER = "tabview-group"; + +let sstore = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); + + +/** + * Simply retrieves the active tabgroup's title from SessionStore + */ +function getActiveGroupName(win) { + let data = "", groupTitle = ""; + try { + data = sstore.getWindowValue(win, win.TabView.GROUPS_IDENTIFIER); + if (data) { + let parsedData = {}; + parsedData = JSON.parse(data); + let activeGroupId = parsedData.activeGroupId; + data = sstore.getWindowValue(win, GROUP_DATA_IDENTIFIER); + parsedData = JSON.parse(data); + groupTitle = parsedData[activeGroupId].title; + } + } catch (e) { } + + return groupTitle; +} + +/** + * Calculates Tab Group's title for nightlyApp + * @param {nsIDOMWindow} win A window which contains nightly. + * + * In Gecko 1.x title is set to "Undefined" as in other Apps + * Before FF10 title is managed by TabView + * After that we manages the title: using SessionStore and other borrowed code to generate + */ +function getTabGroupTitle(win) { + let nightlyApp = win.nightlyApp; + let TabView = win.TabView; + + // TabView isn't implemented + if (!("TabView" in win)) + return; + + // If we are before Bug 682996, + // use TabView's own implementation except it is null + if (typeof(TabView.getActiveGroupName) === "function") + return TabView.getActiveGroupName() || ""; + + // TabView isn't initialized + if (!TabView._window) { + return getActiveGroupName(win); + } + + // We get the active group this way, instead of querying + // GroupItems.getActiveGroupItem() because the tabSelect event + // will not have happened by the time the browser tries to + // update the title. + let groupItem = null; + let activeTab = win.gBrowser.selectedTab; + let activeTabItem = activeTab._tabViewTabItem; + + if (activeTab.pinned) { + // It's an app tab, so it won't have a .tabItem. However, its .parent + // will already be set as the active group. + groupItem = TabView._window.GroupItems.getActiveGroupItem(); + } else if (activeTabItem) { + groupItem = activeTabItem.parent; + } + + // groupItem may still be null, if the active tab is an orphan. + return groupItem ? groupItem.getTitle() : ""; +}