1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function toNavigator()
{
if (!CycleWindow("navigator:browser"))
OpenBrowserWindow();
}
function ExpirePassword()
{
// Queries the HTTP Auth Manager and clears all sessions
Cc['@mozilla.org/network/http-auth-manager;1']
.getService(Ci.nsIHttpAuthManager)
.clearAll();
// Expires the master password
Cc["@mozilla.org/security/pk11tokendb;1"]
.createInstance(Ci.nsIPK11TokenDB)
.getInternalKeyToken()
.checkPassword("");
}
function toDownloadManager()
{
Cc["@mozilla.org/suite/suiteglue;1"]
.getService(Ci.nsISuiteGlue)
.showDownloadManager();
}
function toDataManager(aView)
{
var useDlg = Services.prefs.getBoolPref("suite.manager.dataman.openAsDialog");
if (useDlg) {
var url = "chrome://communicator/content/dataman/dataman.xul";
var win = toOpenWindowByType("data:manager", url, "", aView);
if (win && aView)
win.gDataman.loadView(aView);
return;
}
switchToTabHavingURI("about:data", true, {
browserCallback: function(browser) {
if (aView) {
browser.contentWindow.wrappedJSObject.gDataman.loadView(aView);
}
}
});
}
function toEM(aView)
{
var useDlg = Services.prefs.getBoolPref("suite.manager.addons.openAsDialog");
if (useDlg) {
var view = aView ? { view: aView } : null;
var url = "chrome://mozapps/content/extensions/extensions.xul";
var win = toOpenWindowByType("Addons:Manager", url, "", view);
if (win && aView)
win.loadView(aView);
return;
}
switchToTabHavingURI("about:addons", true, {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
browserCallback: function(browser) {
if (aView) {
browser.contentWindow.wrappedJSObject.loadView(aView);
}
}
});
}
function toBookmarksManager()
{
toOpenWindowByType("Places:Organizer",
"chrome://communicator/content/places/places.xul");
}
function toJavaScriptConsole()
{
toOpenWindowByType("suite:console", "chrome://communicator/content/console/console.xul");
}
function toOpenWindow( aWindow )
{
try {
// Try to focus the previously focused window e.g. message compose body
aWindow.document.commandDispatcher.focusedWindow.focus();
} catch (e) {
// e.g. non-XUL document; just raise the top window
aWindow.focus();
}
}
function toOpenWindowByType(inType, uri, features, args)
{
// don't do several loads in parallel
if (uri in window)
return;
var topWindow = Services.wm.getMostRecentWindow(inType);
if ( topWindow )
{
toOpenWindow( topWindow );
return topWindow;
}
else
{
// open the requested window, but block it until it's fully loaded
function newWindowLoaded(event)
{
// make sure that this handler is called only once
window.removeEventListener("unload", newWindowLoaded);
window[uri].removeEventListener("load", newWindowLoaded);
delete window[uri];
}
// Remember the newly loading window until it's fully loaded
// or until the current window passes away.
// Only pass args if they exist and have a value (see Bug 1279738).
if (typeof args != "undefined" && args) {
window[uri] = openDialog(uri, "",
features || "non-private,all,dialog=no",
args || null);
}
else {
window[uri] = openDialog(uri, "",
features || "non-private,all,dialog=no");
}
window[uri].addEventListener("load", newWindowLoaded);
window.addEventListener("unload", newWindowLoaded);
}
return;
}
function OpenBrowserWindow()
{
var win = Services.wm.getMostRecentWindow("navigator:browser");
if (document.documentElement.getAttribute("windowtype") ==
"navigator:browser" && window.content && window.content.document)
{
// if and only if the current window is a browser window and
// it has a document with a character set, then extract the
// current charset menu setting from the current document
// and use it to initialize the new browser window
return window.openDialog(getBrowserURL(), "_blank",
"chrome,all,dialog=no,non-private", null,
"charset=" + window.content.document.characterSet);
}
if (win) {
// if a browser window already exists then set startpage to null so
// navigator.js can check pref for how new window should be opened
return win.openDialog(getBrowserURL(), "_blank",
"chrome,all,dialog=no,non-private", null);
}
// open the first browser window as if we were starting up
var cmdLine = {
handleFlagWithParam: function handleFlagWithParam(flag, caseSensitive) {
return flag == "remote" ? "xfeDoCommand(openBrowser)" : null;
},
handleFlag: function handleFlag(flag, caseSensitive) {
return false;
},
preventDefault: true
};
const clh_prefix = "@mozilla.org/commandlinehandler/general-startup;1";
Cc[clh_prefix + "?type=browser"]
.getService(Ci.nsICommandLineHandler)
.handle(cmdLine);
return null;
}
function CycleWindow(aType) {
let topWindowOfType = Services.wm.getMostRecentWindow(aType);
if (topWindowOfType == null)
return null;
let topWindow = Services.wm.getMostRecentWindow(null);
if (topWindowOfType != topWindow) {
toOpenWindow(topWindowOfType);
return topWindowOfType;
}
let topFound = false;
let enumerator = Services.wm.getEnumerator(aType);
let iWindow;
let firstWindow;
while (enumerator.hasMoreElements()) {
iWindow = enumerator.getNext();
if (!iWindow.closed) {
if (!firstWindow) {
firstWindow = iWindow;
}
if (topFound) {
toOpenWindow(iWindow);
return iWindow;
}
if (iWindow == topWindow) {
topFound = true;
}
}
}
if (firstWindow == topWindow) // Only one window
return null;
toOpenWindow(firstWindow);
return firstWindow;
}
function windowMenuDidHide()
{
let sep = document.getElementById("sep-window-list");
// Clear old items
while (sep.nextElementSibling) {
sep.nextElementSibling.remove();
}
}
function checkFocusedWindow()
{
let windows = Services.wm.getEnumerator("");
let frag = document.createDocumentFragment();
while (windows.hasMoreElements()) {
let win = windows.getNext();
if (win.closed || win.document.documentElement.getAttribute("inwindowmenu") == "false") {
continue;
}
let item = document.createElement("menuitem");
item.setAttribute("label", win.document.title);
item.setAttribute("type", "radio");
if (win == window) {
item.setAttribute("checked", "true");
}
item.addEventListener("command", () => {
if (win.windowState == window.STATE_MINIMIZED) {
win.restore();
}
win.focus();
});
frag.appendChild(item);
}
document.getElementById("windowPopup").appendChild(frag);
}
function toProfileManager()
{
var promgrWin = Services.wm.getMostRecentWindow("mozilla:profileSelection");
if (promgrWin) {
promgrWin.focus();
} else {
var params = Cc["@mozilla.org/embedcomp/dialogparam;1"]
.createInstance(Ci.nsIDialogParamBlock);
params.SetNumberStrings(1);
params.SetString(0, "menu");
window.openDialog("chrome://communicator/content/profile/profileSelection.xul",
"",
"centerscreen,chrome,titlebar,resizable",
params);
}
// Here, we don't care about the result code
// that was returned in the param block.
}
// This function is only used by macs.
function ZoomCurrentWindow()
{
if (window.windowState == STATE_NORMAL)
window.maximize();
else
window.restore();
}
|