From a14ef5f5e4a65180616bbe8913eda8b16c83f45c Mon Sep 17 00:00:00 2001 From: Szabolcs Hubai Date: Fri, 9 Mar 2012 22:10:03 +0100 Subject: [PATCH] Bug 726560 - Add support of Panorama group name (FF10+) for titlebar customization --- extension/chrome/content/browser.js | 60 +++++++++++++++++++ extension/chrome/content/nightly.js | 5 ++ .../chrome/content/titlebar/customize.js | 1 + .../chrome/locale/en-US/variables.properties | 1 + 4 files changed, 67 insertions(+) diff --git a/extension/chrome/content/browser.js b/extension/chrome/content/browser.js index d66440a..7566be3 100644 --- a/extension/chrome/content/browser.js +++ b/extension/chrome/content/browser.js @@ -41,6 +41,9 @@ repository: ['mozilla-central','mozilla-aurora'], storedTitle: document.documentElement.getAttribute("titlemodifier"), +LAST_SESSION_GROUP_NAME_IDENTIFIER: "nightlytt-last-session-group-name", +_lastSessionGroupName: "", + get defaultTitle() { var tabbrowser = document.getElementById("content"); return tabbrowser.getWindowTitleForBrowser(tabbrowser.mCurrentBrowser); @@ -51,6 +54,32 @@ get tabTitle() { return tabbrowser.mCurrentBrowser.contentTitle; }, +get activeTabGroupName() { + // TabView isn't implemented or initialized + if (!TabView || !TabView._window) + return nightlyApp._lastSessionGroupName; + + + // 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 = window.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() : ""; +}, + init: function() { var brandbundle = document.getElementById("bundle_brand"); @@ -66,6 +95,24 @@ init: function() tabbrowser.updateTitlebar = nightly.updateTitlebar; tabbrowser.addEventListener("DOMTitleChanged", nightly.updateTitlebar, false); + + // Listening to Bug 659591 (landed in FF7) - instead "domwindowclosed" (see Bug 655269), + // to store active group's name for showing at next startup + window.addEventListener("SSWindowClosing", function NightlyTT_onWindowClosing() { + window.removeEventListener("SSWindowClosing", NightlyTT_onWindowClosing, false); + nightlyApp.saveActiveGroupName(window); + }, false); + + // grab the last used group title + // use TabView's property if we are before Bug 682996 (landed in FF10) + nightlyApp._lastSessionGroupName = (TabView && TabView._lastSessionGroupName) + ? TabView._lastSessionGroupName + : Cc["@mozilla.org/browser/sessionstore;1"] + .getService(Ci.nsISessionStore) + .getWindowValue( + window, + nightlyApp.LAST_SESSION_GROUP_NAME_IDENTIFIER + ); }, openURL: function(url) @@ -87,6 +134,19 @@ openNotification: function(id, message, label, accessKey, callback) { message, "urlbar", action, null, options); }, +// Function: saveActiveGroupName +// Saves the active group's name for the given window. +saveActiveGroupName: function NightlyTT_saveActiveGroupName(win) { + let groupName = nightlyApp.activeTabGroupName; + Cc["@mozilla.org/browser/sessionstore;1"] + .getService(Ci.nsISessionStore) + .setWindowValue( + win, + nightlyApp.LAST_SESSION_GROUP_NAME_IDENTIFIER, + groupName + ); +}, + setCustomTitle: function(title) { document.getElementById("content").ownerDocument.title = title; diff --git a/extension/chrome/content/nightly.js b/extension/chrome/content/nightly.js index 9bed17e..8e5efe9 100644 --- a/extension/chrome/content/nightly.js +++ b/extension/chrome/content/nightly.js @@ -69,6 +69,7 @@ variables: { get compiler() this.appInfo.XPCOMABI.split("-")[1], get defaulttitle() { return nightlyApp.defaultTitle; }, get tabtitle() { return nightlyApp.tabTitle; }, + get activetabgroupname() { return nightlyApp.activeTabGroupName || null; }, profile: null, toolkit: "cairo", flags: "" @@ -107,6 +108,10 @@ showAlert: function(id, args) { init: function() { window.removeEventListener("load", nightly.init, false); + setTimeout(nightly.initLazy,800); +}, + +initLazy: function() { var prefs = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService); nightly.preferences = prefs.getBranch("nightly.") diff --git a/extension/chrome/content/titlebar/customize.js b/extension/chrome/content/titlebar/customize.js index 9b3d401..995b833 100644 --- a/extension/chrome/content/titlebar/customize.js +++ b/extension/chrome/content/titlebar/customize.js @@ -59,6 +59,7 @@ init: function() paneTitle.addVariable("DefaultTitle"); paneTitle.addVariable("TabTitle"); + paneTitle.addVariable("ActiveTabGroupName"); 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 5e8cf0f..7918490 100644 --- a/extension/chrome/locale/en-US/variables.properties +++ b/extension/chrome/locale/en-US/variables.properties @@ -52,5 +52,6 @@ variable.Processor.description=Compilation Processor variable.Compiler.description=Compiler variable.DefaultTitle.description=Default Application Title variable.TabTitle.description=Current Tab's Title +variable.ActiveTabGroupName.description=Active TabView group name - may be empty in rare cases variable.Profile.description=Current Profile variable.Toolkit.description=Graphics Toolkit