2011-02-27 17:36:36 -08:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
2010-10-18 02:53:58 -07:00
|
|
|
|
2011-02-17 12:37:32 -08:00
|
|
|
function createEmptyGroupItem(contentWindow, width, height, padding, animate) {
|
2010-10-18 02:53:58 -07:00
|
|
|
let pageBounds = contentWindow.Items.getPageBounds();
|
|
|
|
pageBounds.inset(padding, padding);
|
|
|
|
|
|
|
|
let box = new contentWindow.Rect(pageBounds);
|
|
|
|
box.width = width;
|
|
|
|
box.height = height;
|
2011-02-17 12:37:32 -08:00
|
|
|
|
2011-02-14 09:21:37 -08:00
|
|
|
let emptyGroupItem =
|
2011-02-17 12:37:32 -08:00
|
|
|
new contentWindow.GroupItem([], { bounds: box, immediately: !animate });
|
2010-10-18 02:53:58 -07:00
|
|
|
|
|
|
|
return emptyGroupItem;
|
|
|
|
}
|
2011-01-12 17:08:22 -08:00
|
|
|
|
2011-02-14 09:21:37 -08:00
|
|
|
// ----------
|
|
|
|
function createGroupItemWithTabs(win, width, height, padding, urls, animate) {
|
|
|
|
let contentWindow = win.TabView.getContentWindow();
|
|
|
|
let groupItemCount = contentWindow.GroupItems.groupItems.length;
|
|
|
|
// create empty group item
|
|
|
|
let groupItem = createEmptyGroupItem(contentWindow, width, height, padding, animate);
|
|
|
|
ok(groupItem.isEmpty(), "This group is empty");
|
|
|
|
is(contentWindow.GroupItems.groupItems.length, ++groupItemCount,
|
|
|
|
"The number of groups is increased by 1");
|
|
|
|
// add blank items
|
2011-04-22 13:05:11 -07:00
|
|
|
contentWindow.UI.setActive(groupItem);
|
2011-02-14 09:21:37 -08:00
|
|
|
let t = 0;
|
|
|
|
urls.forEach( function(url) {
|
|
|
|
let newItem = win.gBrowser.loadOneTab(url)._tabViewTabItem;
|
|
|
|
ok(newItem.container, "Created element "+t+":"+newItem.container);
|
|
|
|
++t;
|
|
|
|
});
|
2011-06-22 20:42:50 -07:00
|
|
|
// to set one of tabItem to be active since we load tabs into a group
|
|
|
|
// in a non-standard flow.
|
|
|
|
contentWindow.UI.setActive(groupItem);
|
2011-02-14 09:21:37 -08:00
|
|
|
return groupItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function createGroupItemWithBlankTabs(win, width, height, padding, numNewTabs, animate) {
|
|
|
|
let urls = [];
|
|
|
|
while(numNewTabs--)
|
|
|
|
urls.push("about:blank");
|
|
|
|
return createGroupItemWithTabs(win, width, height, padding, urls, animate);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function closeGroupItem(groupItem, callback) {
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback) {
|
|
|
|
groupItem.addSubscriber("close", function onClose() {
|
|
|
|
groupItem.removeSubscriber("close", onClose);
|
2011-06-17 05:07:59 -07:00
|
|
|
executeSoon(callback);
|
2011-08-09 10:13:54 -07:00
|
|
|
});
|
|
|
|
}
|
2011-06-17 05:07:59 -07:00
|
|
|
|
|
|
|
if (groupItem.getChildren().length) {
|
2011-07-14 10:54:25 -07:00
|
|
|
groupItem.addSubscriber("groupHidden", function onHide() {
|
|
|
|
groupItem.removeSubscriber("groupHidden", onHide);
|
2011-06-17 05:07:59 -07:00
|
|
|
groupItem.closeHidden();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-02-14 09:21:37 -08:00
|
|
|
groupItem.closeAll();
|
|
|
|
}
|
|
|
|
|
2011-01-12 17:08:22 -08:00
|
|
|
// ----------
|
2011-01-13 10:22:47 -08:00
|
|
|
function afterAllTabItemsUpdated(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
let tabItems = win.document.getElementById("tab-view").contentWindow.TabItems;
|
|
|
|
|
|
|
|
for (let a = 0; a < win.gBrowser.tabs.length; a++) {
|
|
|
|
let tabItem = win.gBrowser.tabs[a]._tabViewTabItem;
|
|
|
|
if (tabItem)
|
|
|
|
tabItems._update(win.gBrowser.tabs[a]);
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
2011-03-03 18:51:27 -08:00
|
|
|
function newWindowWithTabView(shownCallback, loadCallback, width, height) {
|
|
|
|
let winWidth = width || 800;
|
|
|
|
let winHeight = height || 800;
|
|
|
|
let win = window.openDialog(getBrowserURL(), "_blank",
|
|
|
|
"chrome,all,dialog=no,height=" + winHeight +
|
|
|
|
",width=" + winWidth);
|
2011-07-04 15:23:35 -07:00
|
|
|
|
|
|
|
whenWindowLoaded(win, function () {
|
2011-07-11 10:45:42 -07:00
|
|
|
if (loadCallback)
|
2011-03-03 18:51:27 -08:00
|
|
|
loadCallback(win);
|
2011-07-11 10:45:42 -07:00
|
|
|
});
|
2011-03-03 18:51:27 -08:00
|
|
|
|
2011-07-11 10:45:42 -07:00
|
|
|
whenDelayedStartupFinished(win, function () {
|
2011-07-04 15:23:35 -07:00
|
|
|
showTabView(function () shownCallback(win), win);
|
|
|
|
});
|
2011-01-13 10:22:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function afterAllTabsLoaded(callback, win) {
|
2011-05-19 15:07:55 -07:00
|
|
|
const TAB_STATE_NEEDS_RESTORE = 1;
|
|
|
|
|
2011-01-13 10:22:47 -08:00
|
|
|
win = win || window;
|
|
|
|
|
2011-01-12 17:08:22 -08:00
|
|
|
let stillToLoad = 0;
|
2011-05-19 15:07:55 -07:00
|
|
|
let restoreHiddenTabs = Services.prefs.getBoolPref(
|
|
|
|
"browser.sessionstore.restore_hidden_tabs");
|
2011-01-12 17:08:22 -08:00
|
|
|
|
|
|
|
function onLoad() {
|
|
|
|
this.removeEventListener("load", onLoad, true);
|
|
|
|
stillToLoad--;
|
|
|
|
if (!stillToLoad)
|
2011-05-27 01:32:04 -07:00
|
|
|
executeSoon(callback);
|
2011-01-12 17:08:22 -08:00
|
|
|
}
|
|
|
|
|
2011-01-13 10:22:47 -08:00
|
|
|
for (let a = 0; a < win.gBrowser.tabs.length; a++) {
|
2011-05-19 15:07:55 -07:00
|
|
|
let tab = win.gBrowser.tabs[a];
|
|
|
|
let browser = tab.linkedBrowser;
|
|
|
|
|
|
|
|
let isRestorable = !(tab.hidden && !restoreHiddenTabs &&
|
|
|
|
browser.__SS_restoreState &&
|
|
|
|
browser.__SS_restoreState == TAB_STATE_NEEDS_RESTORE);
|
|
|
|
|
|
|
|
if (isRestorable && browser.contentDocument.readyState != "complete" ||
|
2011-04-07 12:55:49 -07:00
|
|
|
browser.webProgress.isLoadingDocument) {
|
2011-01-12 17:08:22 -08:00
|
|
|
stillToLoad++;
|
|
|
|
browser.addEventListener("load", onLoad, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stillToLoad)
|
2011-05-19 15:07:55 -07:00
|
|
|
executeSoon(callback);
|
2011-01-12 17:08:22 -08:00
|
|
|
}
|
2011-01-18 04:32:03 -08:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
function showTabView(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
if (win.TabView.isVisible()) {
|
2011-07-19 06:36:55 -07:00
|
|
|
waitForFocus(callback, win);
|
2011-01-18 04:32:03 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-09 10:13:54 -07:00
|
|
|
whenTabViewIsShown(function () {
|
2011-07-19 06:36:55 -07:00
|
|
|
waitForFocus(callback, win);
|
|
|
|
}, win);
|
2011-08-09 10:13:54 -07:00
|
|
|
|
2011-01-18 04:32:03 -08:00
|
|
|
win.TabView.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function hideTabView(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
if (!win.TabView.isVisible()) {
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback)
|
|
|
|
callback();
|
2011-01-18 04:32:03 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback)
|
|
|
|
whenTabViewIsHidden(callback, win);
|
|
|
|
|
2011-01-18 04:32:03 -08:00
|
|
|
win.TabView.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenTabViewIsHidden(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
if (!win.TabView.isVisible()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-23 08:07:39 -07:00
|
|
|
win.addEventListener('tabviewhidden', function onHidden() {
|
|
|
|
win.removeEventListener('tabviewhidden', onHidden, false);
|
2011-01-18 04:32:03 -08:00
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenTabViewIsShown(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
if (win.TabView.isVisible()) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-23 08:07:39 -07:00
|
|
|
win.addEventListener('tabviewshown', function onShown() {
|
|
|
|
win.removeEventListener('tabviewshown', onShown, false);
|
2011-01-18 04:32:03 -08:00
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
}
|
2011-02-22 12:32:16 -08:00
|
|
|
|
2011-03-28 19:51:26 -07:00
|
|
|
// ----------
|
|
|
|
function hideSearch(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
2011-07-04 15:23:35 -07:00
|
|
|
let contentWindow = win.TabView.getContentWindow();
|
2011-09-29 21:17:00 -07:00
|
|
|
if (!contentWindow.Search.isEnabled()) {
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback)
|
|
|
|
callback();
|
2011-03-28 19:51:26 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback)
|
|
|
|
whenSearchIsDisabled(callback, win);
|
|
|
|
|
2011-09-29 21:17:00 -07:00
|
|
|
contentWindow.Search.hide();
|
2011-03-28 19:51:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenSearchIsEnabled(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
2011-07-04 15:23:35 -07:00
|
|
|
let contentWindow = win.TabView.getContentWindow();
|
2011-09-29 21:17:00 -07:00
|
|
|
if (contentWindow.Search.isEnabled()) {
|
2011-03-28 19:51:26 -07:00
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-14 10:54:25 -07:00
|
|
|
contentWindow.addEventListener("tabviewsearchenabled", function onSearchEnabled() {
|
|
|
|
contentWindow.removeEventListener("tabviewsearchenabled", onSearchEnabled, false);
|
2011-03-28 19:51:26 -07:00
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenSearchIsDisabled(callback, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
2011-07-04 15:23:35 -07:00
|
|
|
let contentWindow = win.TabView.getContentWindow();
|
2011-09-29 21:17:00 -07:00
|
|
|
if (!contentWindow.Search.isEnabled()) {
|
2011-03-28 19:51:26 -07:00
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-14 10:54:25 -07:00
|
|
|
contentWindow.addEventListener("tabviewsearchdisabled", function onSearchDisabled() {
|
|
|
|
contentWindow.removeEventListener("tabviewsearchdisabled", onSearchDisabled, false);
|
2011-03-28 19:51:26 -07:00
|
|
|
callback();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-22 12:32:16 -08:00
|
|
|
// ----------
|
|
|
|
function hideGroupItem(groupItem, callback) {
|
|
|
|
if (groupItem.hidden) {
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback)
|
|
|
|
callback();
|
2011-02-22 12:32:16 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback) {
|
|
|
|
groupItem.addSubscriber("groupHidden", function onHide() {
|
|
|
|
groupItem.removeSubscriber("groupHidden", onHide);
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-02-22 12:32:16 -08:00
|
|
|
groupItem.closeAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function unhideGroupItem(groupItem, callback) {
|
|
|
|
if (!groupItem.hidden) {
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback)
|
|
|
|
callback();
|
2011-02-22 12:32:16 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-09 10:13:54 -07:00
|
|
|
if (callback) {
|
|
|
|
groupItem.addSubscriber("groupShown", function onShown() {
|
|
|
|
groupItem.removeSubscriber("groupShown", onShown);
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-02-22 12:32:16 -08:00
|
|
|
groupItem._unhide();
|
|
|
|
}
|
2011-05-17 14:31:41 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenWindowLoaded(win, callback) {
|
|
|
|
win.addEventListener("load", function onLoad() {
|
|
|
|
win.removeEventListener("load", onLoad, false);
|
|
|
|
executeSoon(callback);
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
function whenWindowStateReady(win, callback) {
|
|
|
|
win.addEventListener("SSWindowStateReady", function onReady() {
|
|
|
|
win.removeEventListener("SSWindowStateReady", onReady, false);
|
|
|
|
executeSoon(callback);
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2011-06-22 14:40:19 -07:00
|
|
|
// ----------
|
|
|
|
function whenDelayedStartupFinished(win, callback) {
|
|
|
|
let topic = "browser-delayed-startup-finished";
|
|
|
|
Services.obs.addObserver(function onStartup(aSubject) {
|
|
|
|
if (win != aSubject)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Services.obs.removeObserver(onStartup, topic, false);
|
|
|
|
executeSoon(callback);
|
|
|
|
}, topic, false);
|
|
|
|
}
|
|
|
|
|
2011-05-17 14:31:41 -07:00
|
|
|
// ----------
|
|
|
|
function newWindowWithState(state, callback) {
|
2011-06-14 01:41:18 -07:00
|
|
|
const ss = Cc["@mozilla.org/browser/sessionstore;1"]
|
|
|
|
.getService(Ci.nsISessionStore);
|
|
|
|
|
2011-05-17 14:31:41 -07:00
|
|
|
let opts = "chrome,all,dialog=no,height=800,width=800";
|
|
|
|
let win = window.openDialog(getBrowserURL(), "_blank", opts);
|
|
|
|
|
2011-06-28 06:06:19 -07:00
|
|
|
let numConditions = 2;
|
|
|
|
let check = function () {
|
|
|
|
if (!--numConditions)
|
|
|
|
callback(win);
|
|
|
|
};
|
|
|
|
|
2012-02-08 08:46:51 -08:00
|
|
|
whenDelayedStartupFinished(win, function () {
|
|
|
|
ss.setWindowState(win, JSON.stringify(state), true);
|
|
|
|
win.close();
|
|
|
|
win = ss.undoCloseWindow(0);
|
|
|
|
|
|
|
|
whenWindowLoaded(win, function () {
|
|
|
|
whenWindowStateReady(win, function () {
|
|
|
|
afterAllTabsLoaded(check, win);
|
|
|
|
});
|
2011-06-22 14:40:19 -07:00
|
|
|
});
|
|
|
|
|
2012-02-08 08:46:51 -08:00
|
|
|
whenDelayedStartupFinished(win, check);
|
2011-05-17 14:31:41 -07:00
|
|
|
});
|
|
|
|
}
|
2011-05-27 01:32:04 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
function restoreTab(callback, index, win) {
|
|
|
|
win = win || window;
|
|
|
|
|
|
|
|
let tab = win.undoCloseTab(index || 0);
|
|
|
|
let tabItem = tab._tabViewTabItem;
|
|
|
|
|
2011-06-17 05:07:59 -07:00
|
|
|
let finalize = function () {
|
|
|
|
afterAllTabsLoaded(function () callback(tab), win);
|
|
|
|
};
|
|
|
|
|
2011-05-27 01:32:04 -07:00
|
|
|
if (tabItem._reconnected) {
|
2011-06-17 05:07:59 -07:00
|
|
|
finalize();
|
2011-05-27 01:32:04 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-14 10:54:25 -07:00
|
|
|
tab._tabViewTabItem.addSubscriber("reconnected", function onReconnected() {
|
|
|
|
tab._tabViewTabItem.removeSubscriber("reconnected", onReconnected);
|
2011-06-17 05:07:59 -07:00
|
|
|
finalize();
|
2011-05-27 01:32:04 -07:00
|
|
|
});
|
|
|
|
}
|
2011-08-09 10:13:53 -07:00
|
|
|
|
|
|
|
// ----------
|
|
|
|
function togglePrivateBrowsing(callback) {
|
|
|
|
let topic = "private-browsing-transition-complete";
|
|
|
|
|
|
|
|
Services.obs.addObserver(function observe() {
|
|
|
|
Services.obs.removeObserver(observe, topic);
|
2011-08-16 02:06:14 -07:00
|
|
|
|
|
|
|
// use executeSoon() to let Panorama load its group data from the session
|
|
|
|
// before we call afterAllTabsLoaded()
|
|
|
|
executeSoon(function () afterAllTabsLoaded(callback));
|
2011-08-09 10:13:53 -07:00
|
|
|
}, topic, false);
|
|
|
|
|
|
|
|
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService);
|
|
|
|
|
|
|
|
pb.privateBrowsingEnabled = !pb.privateBrowsingEnabled;
|
|
|
|
}
|