Skip to content

Commit

Permalink
Bug 726560 - Add support of Panorama group name (FF10+) for titlebar …
Browse files Browse the repository at this point in the history
…customization
  • Loading branch information
xabolcs committed Mar 9, 2012
1 parent 1ec0afe commit a14ef5f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
60 changes: 60 additions & 0 deletions extension/chrome/content/browser.js
Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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)
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions extension/chrome/content/nightly.js
Expand Up @@ -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: ""
Expand Down Expand Up @@ -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.")
Expand Down
1 change: 1 addition & 0 deletions extension/chrome/content/titlebar/customize.js
Expand Up @@ -59,6 +59,7 @@ init: function()

paneTitle.addVariable("DefaultTitle");
paneTitle.addVariable("TabTitle");
paneTitle.addVariable("ActiveTabGroupName");
paneTitle.addVariable("AppID");
paneTitle.addVariable("Vendor");
paneTitle.addVariable("Name");
Expand Down
1 change: 1 addition & 0 deletions extension/chrome/locale/en-US/variables.properties
Expand Up @@ -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

0 comments on commit a14ef5f

Please sign in to comment.