2012-07-03 21:07:22 +00:00
|
|
|
# -*- Mode: javascript; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
# 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/.
|
2002-08-04 02:55:51 +00:00
|
|
|
|
2010-01-28 18:31:45 +00:00
|
|
|
// Services = object with smart getters for common XPCOM services
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2012-01-25 22:43:27 +00:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-10-05 23:25:52 +00:00
|
|
|
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
2013-03-18 15:46:17 +00:00
|
|
|
Components.utils.import("resource:///modules/RecentWindow.jsm");
|
2012-01-25 22:43:27 +00:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "BROWSER_NEW_TAB_URL", function () {
|
2012-03-13 02:03:46 +00:00
|
|
|
const PREF = "browser.newtab.url";
|
|
|
|
|
|
|
|
function getNewTabPageURL() {
|
2012-10-10 00:34:59 +00:00
|
|
|
if (!Services.prefs.prefHasUserValue(PREF)) {
|
|
|
|
if (PrivateBrowsingUtils.isWindowPrivate(window) &&
|
|
|
|
!PrivateBrowsingUtils.permanentPrivateBrowsing)
|
2012-06-25 17:00:32 +00:00
|
|
|
return "about:privatebrowsing";
|
|
|
|
}
|
2013-07-23 14:52:20 +00:00
|
|
|
let url = Services.prefs.getComplexValue(PREF, Ci.nsISupportsString).data;
|
|
|
|
return url || "about:blank";
|
2012-03-13 02:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
BROWSER_NEW_TAB_URL = getNewTabPageURL();
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.prefs.addObserver(PREF, update, false);
|
2012-06-20 21:43:19 +00:00
|
|
|
|
2012-03-13 02:03:46 +00:00
|
|
|
addEventListener("unload", function onUnload() {
|
|
|
|
removeEventListener("unload", onUnload);
|
|
|
|
Services.prefs.removeObserver(PREF, update);
|
|
|
|
});
|
|
|
|
|
|
|
|
return getNewTabPageURL();
|
2012-01-25 22:43:27 +00:00
|
|
|
});
|
2002-08-04 02:55:51 +00:00
|
|
|
|
2011-10-27 00:46:58 +00:00
|
|
|
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
|
|
|
|
|
2005-01-26 01:40:30 +00:00
|
|
|
var gBidiUI = false;
|
2002-08-04 02:55:51 +00:00
|
|
|
|
2012-01-25 22:43:27 +00:00
|
|
|
/**
|
|
|
|
* Determines whether the given url is considered a special URL for new tabs.
|
|
|
|
*/
|
|
|
|
function isBlankPageURL(aURL) {
|
|
|
|
return aURL == "about:blank" || aURL == BROWSER_NEW_TAB_URL;
|
|
|
|
}
|
|
|
|
|
2003-04-30 00:21:48 +00:00
|
|
|
function getBrowserURL()
|
|
|
|
{
|
|
|
|
return "chrome://browser/content/browser.xul";
|
2002-08-04 02:55:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-23 12:01:33 +00:00
|
|
|
function getTopWin(skipPopups) {
|
2011-01-28 19:58:42 +00:00
|
|
|
// If this is called in a browser window, use that window regardless of
|
|
|
|
// whether it's the frontmost window, since commands can be executed in
|
|
|
|
// background windows (bug 626148).
|
|
|
|
if (top.document.documentElement.getAttribute("windowtype") == "navigator:browser" &&
|
2012-01-24 00:37:54 +00:00
|
|
|
(!skipPopups || top.toolbar.visible))
|
2011-01-28 19:58:42 +00:00
|
|
|
return top;
|
|
|
|
|
2013-03-17 15:12:54 +00:00
|
|
|
let isPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
|
|
|
|
return RecentWindow.getMostRecentBrowserWindow({private: isPrivate,
|
|
|
|
allowPopups: !skipPopups});
|
2002-08-04 02:55:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 17:46:26 +00:00
|
|
|
function openTopWin(url) {
|
|
|
|
/* deprecated */
|
|
|
|
openUILinkIn(url, "current");
|
2004-06-23 22:54:12 +00:00
|
|
|
}
|
2002-08-04 02:55:51 +00:00
|
|
|
|
2010-01-28 18:31:45 +00:00
|
|
|
function getBoolPref(prefname, def)
|
2004-06-23 22:54:12 +00:00
|
|
|
{
|
2010-01-28 18:31:45 +00:00
|
|
|
try {
|
|
|
|
return Services.prefs.getBoolPref(prefname);
|
2004-06-23 22:54:12 +00:00
|
|
|
}
|
|
|
|
catch(er) {
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 19:39:08 +00:00
|
|
|
/* openUILink handles clicks on UI elements that cause URLs to load.
|
|
|
|
*
|
|
|
|
* As the third argument, you may pass an object with the same properties as
|
|
|
|
* accepted by openUILinkIn, plus "ignoreButton" and "ignoreAlt".
|
|
|
|
*/
|
|
|
|
function openUILink(url, event, aIgnoreButton, aIgnoreAlt, aAllowThirdPartyFixup,
|
|
|
|
aPostData, aReferrerURI) {
|
|
|
|
let params;
|
|
|
|
|
|
|
|
if (aIgnoreButton && typeof aIgnoreButton == "object") {
|
|
|
|
params = aIgnoreButton;
|
|
|
|
|
|
|
|
// don't forward "ignoreButton" and "ignoreAlt" to openUILinkIn
|
|
|
|
aIgnoreButton = params.ignoreButton;
|
|
|
|
aIgnoreAlt = params.ignoreAlt;
|
|
|
|
delete params.ignoreButton;
|
|
|
|
delete params.ignoreAlt;
|
|
|
|
} else {
|
|
|
|
params = {
|
|
|
|
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
|
|
|
postData: aPostData,
|
2012-10-03 17:10:20 +00:00
|
|
|
referrerURI: aReferrerURI,
|
2012-11-27 16:06:17 +00:00
|
|
|
initiatingDoc: event ? event.target.ownerDocument : null
|
2012-03-17 19:39:08 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let where = whereToOpenLink(event, aIgnoreButton, aIgnoreAlt);
|
|
|
|
openUILinkIn(url, where, params);
|
2004-06-23 22:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* whereToOpenLink() looks at an event to decide where to open a link.
|
|
|
|
*
|
|
|
|
* The event may be a mouse event (click, double-click, middle-click) or keypress event (enter).
|
|
|
|
*
|
|
|
|
* On Windows, the modifiers are:
|
|
|
|
* Ctrl new tab, selected
|
|
|
|
* Shift new window
|
|
|
|
* Ctrl+Shift new tab, in background
|
|
|
|
* Alt save
|
|
|
|
*
|
2011-12-20 00:17:08 +00:00
|
|
|
* Middle-clicking is the same as Ctrl+clicking (it opens a new tab).
|
2004-06-23 22:54:12 +00:00
|
|
|
*
|
|
|
|
* Exceptions:
|
|
|
|
* - Alt is ignored for menu items selected using the keyboard so you don't accidentally save stuff.
|
|
|
|
* (Currently, the Alt isn't sent here at all for menu items, but that will change in bug 126189.)
|
|
|
|
* - Alt is hard to use in context menus, because pressing Alt closes the menu.
|
|
|
|
* - Alt can't be used on the bookmarks toolbar because Alt is used for "treat this as something draggable".
|
|
|
|
* - The button is ignored for the middle-click-paste-URL feature, since it's always a middle-click.
|
|
|
|
*/
|
|
|
|
function whereToOpenLink( e, ignoreButton, ignoreAlt )
|
|
|
|
{
|
2008-09-04 00:18:50 +00:00
|
|
|
// This method must treat a null event like a left click without modifier keys (i.e.
|
|
|
|
// e = { shiftKey:false, ctrlKey:false, metaKey:false, altKey:false, button:0 })
|
|
|
|
// for compatibility purposes.
|
2006-08-18 08:11:46 +00:00
|
|
|
if (!e)
|
2008-09-04 00:18:50 +00:00
|
|
|
return "current";
|
2004-06-23 22:54:12 +00:00
|
|
|
|
|
|
|
var shift = e.shiftKey;
|
|
|
|
var ctrl = e.ctrlKey;
|
|
|
|
var meta = e.metaKey;
|
|
|
|
var alt = e.altKey && !ignoreAlt;
|
|
|
|
|
|
|
|
// ignoreButton allows "middle-click paste" to use function without always opening in a new window.
|
|
|
|
var middle = !ignoreButton && e.button == 1;
|
|
|
|
var middleUsesTabs = getBoolPref("browser.tabs.opentabfor.middleclick", true);
|
|
|
|
|
|
|
|
// Don't do anything special with right-mouse clicks. They're probably clicks on context menu items.
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2010-01-19 19:18:40 +00:00
|
|
|
if (meta || (middle && middleUsesTabs))
|
2004-06-23 22:54:12 +00:00
|
|
|
#else
|
2010-01-19 19:18:40 +00:00
|
|
|
if (ctrl || (middle && middleUsesTabs))
|
2004-06-23 22:54:12 +00:00
|
|
|
#endif
|
2010-01-19 19:18:40 +00:00
|
|
|
return shift ? "tabshifted" : "tab";
|
|
|
|
|
2012-03-01 22:08:03 +00:00
|
|
|
if (alt && getBoolPref("browser.altClickSave", false))
|
2004-06-23 22:54:12 +00:00
|
|
|
return "save";
|
2010-01-19 19:18:40 +00:00
|
|
|
|
|
|
|
if (shift || (middle && !middleUsesTabs))
|
2004-06-23 22:54:12 +00:00
|
|
|
return "window";
|
2010-01-19 19:18:40 +00:00
|
|
|
|
|
|
|
return "current";
|
2004-06-23 22:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* openUILinkIn opens a URL in a place specified by the parameter |where|.
|
|
|
|
*
|
|
|
|
* |where| can be:
|
|
|
|
* "current" current tab (if there aren't any browser windows, then in a new window instead)
|
|
|
|
* "tab" new tab (if there aren't any browser windows, then in a new window instead)
|
|
|
|
* "tabshifted" same as "tab" but in background if default is to select new tabs, and vice versa
|
|
|
|
* "window" new window
|
|
|
|
* "save" save to disk (with no filename hint!)
|
2006-04-03 23:17:51 +00:00
|
|
|
*
|
2010-01-15 08:19:41 +00:00
|
|
|
* aAllowThirdPartyFixup controls whether third party services such as Google's
|
2006-04-03 23:17:51 +00:00
|
|
|
* I Feel Lucky are allowed to interpret this URL. This parameter may be
|
|
|
|
* undefined, which is treated as false.
|
2010-01-15 08:19:41 +00:00
|
|
|
*
|
|
|
|
* Instead of aAllowThirdPartyFixup, you may also pass an object with any of
|
|
|
|
* these properties:
|
|
|
|
* allowThirdPartyFixup (boolean)
|
|
|
|
* postData (nsIInputStream)
|
|
|
|
* referrerURI (nsIURI)
|
|
|
|
* relatedToCurrent (boolean)
|
2004-06-23 22:54:12 +00:00
|
|
|
*/
|
2010-01-15 08:19:41 +00:00
|
|
|
function openUILinkIn(url, where, aAllowThirdPartyFixup, aPostData, aReferrerURI) {
|
2010-10-23 12:01:33 +00:00
|
|
|
var params;
|
|
|
|
|
|
|
|
if (arguments.length == 3 && typeof arguments[2] == "object") {
|
|
|
|
params = aAllowThirdPartyFixup;
|
|
|
|
} else {
|
|
|
|
params = {
|
|
|
|
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
|
|
|
postData: aPostData,
|
|
|
|
referrerURI: aReferrerURI
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-12-24 23:11:45 +00:00
|
|
|
params.fromChrome = true;
|
2010-10-23 12:01:33 +00:00
|
|
|
|
|
|
|
openLinkIn(url, where, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
function openLinkIn(url, where, params) {
|
2006-06-26 17:40:49 +00:00
|
|
|
if (!where || !url)
|
2004-06-23 22:54:12 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-24 23:11:45 +00:00
|
|
|
var aFromChrome = params.fromChrome;
|
2010-10-23 12:01:33 +00:00
|
|
|
var aAllowThirdPartyFixup = params.allowThirdPartyFixup;
|
|
|
|
var aPostData = params.postData;
|
|
|
|
var aCharset = params.charset;
|
|
|
|
var aReferrerURI = params.referrerURI;
|
|
|
|
var aRelatedToCurrent = params.relatedToCurrent;
|
2010-11-07 13:30:26 +00:00
|
|
|
var aInBackground = params.inBackground;
|
2011-07-28 15:37:56 +00:00
|
|
|
var aDisallowInheritPrincipal = params.disallowInheritPrincipal;
|
2011-11-05 15:48:28 +00:00
|
|
|
// Currently, this parameter works only for where=="tab" or "current"
|
|
|
|
var aIsUTF8 = params.isUTF8;
|
2012-10-03 17:10:20 +00:00
|
|
|
var aInitiatingDoc = params.initiatingDoc;
|
2012-11-30 16:32:36 +00:00
|
|
|
var aIsPrivate = params.private;
|
2010-01-15 08:19:41 +00:00
|
|
|
|
2004-06-23 22:54:12 +00:00
|
|
|
if (where == "save") {
|
2012-11-27 16:06:17 +00:00
|
|
|
if (!aInitiatingDoc) {
|
2012-11-28 17:26:02 +00:00
|
|
|
Components.utils.reportError("openUILink/openLinkIn was called with " +
|
|
|
|
"where == 'save' but without initiatingDoc. See bug 814264.");
|
2012-11-27 16:06:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-03 17:10:20 +00:00
|
|
|
saveURL(url, null, null, true, null, aReferrerURI, aInitiatingDoc);
|
2004-06-23 22:54:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-04-23 03:51:11 +00:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2004-06-23 22:54:12 +00:00
|
|
|
|
2006-06-26 17:40:49 +00:00
|
|
|
var w = getTopWin();
|
2010-10-23 12:01:33 +00:00
|
|
|
if ((where == "tab" || where == "tabshifted") &&
|
2012-01-24 00:37:54 +00:00
|
|
|
w && !w.toolbar.visible) {
|
2010-10-23 12:01:33 +00:00
|
|
|
w = getTopWin(true);
|
|
|
|
aRelatedToCurrent = false;
|
|
|
|
}
|
2006-06-26 17:40:49 +00:00
|
|
|
|
|
|
|
if (!w || where == "window") {
|
2008-04-23 03:51:11 +00:00
|
|
|
var sa = Cc["@mozilla.org/supports-array;1"].
|
|
|
|
createInstance(Ci.nsISupportsArray);
|
|
|
|
|
|
|
|
var wuri = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
wuri.data = url;
|
|
|
|
|
2010-10-23 12:01:33 +00:00
|
|
|
let charset = null;
|
|
|
|
if (aCharset) {
|
|
|
|
charset = Cc["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(Ci.nsISupportsString);
|
|
|
|
charset.data = "charset=" + aCharset;
|
|
|
|
}
|
|
|
|
|
2009-11-09 21:14:20 +00:00
|
|
|
var allowThirdPartyFixupSupports = Cc["@mozilla.org/supports-PRBool;1"].
|
|
|
|
createInstance(Ci.nsISupportsPRBool);
|
2010-01-15 08:19:41 +00:00
|
|
|
allowThirdPartyFixupSupports.data = aAllowThirdPartyFixup;
|
2009-11-09 21:14:20 +00:00
|
|
|
|
2008-04-23 03:51:11 +00:00
|
|
|
sa.AppendElement(wuri);
|
2010-10-23 12:01:33 +00:00
|
|
|
sa.AppendElement(charset);
|
2010-01-15 08:19:41 +00:00
|
|
|
sa.AppendElement(aReferrerURI);
|
|
|
|
sa.AppendElement(aPostData);
|
2009-11-09 21:14:20 +00:00
|
|
|
sa.AppendElement(allowThirdPartyFixupSupports);
|
2008-04-23 03:51:11 +00:00
|
|
|
|
2012-11-27 15:09:24 +00:00
|
|
|
let features = "chrome,dialog=no,all";
|
2012-11-30 16:32:36 +00:00
|
|
|
if (aIsPrivate) {
|
2012-11-27 15:09:24 +00:00
|
|
|
features += ",private";
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.ww.openWindow(w || window, getBrowserURL(), null, features, sa);
|
2004-06-23 22:54:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-06-26 17:40:49 +00:00
|
|
|
|
2011-12-20 13:02:48 +00:00
|
|
|
let loadInBackground = where == "current" ? false : aInBackground;
|
2010-11-07 13:30:26 +00:00
|
|
|
if (loadInBackground == null) {
|
|
|
|
loadInBackground = aFromChrome ?
|
2011-12-20 00:17:08 +00:00
|
|
|
false :
|
2010-12-24 23:11:45 +00:00
|
|
|
getBoolPref("browser.tabs.loadInBackground");
|
2010-11-07 13:30:26 +00:00
|
|
|
}
|
2004-06-23 22:54:12 +00:00
|
|
|
|
2010-08-31 19:30:38 +00:00
|
|
|
if (where == "current" && w.gBrowser.selectedTab.pinned) {
|
|
|
|
try {
|
|
|
|
let uriObj = Services.io.newURI(url, null, null);
|
|
|
|
if (!uriObj.schemeIs("javascript") &&
|
|
|
|
w.gBrowser.currentURI.host != uriObj.host) {
|
|
|
|
where = "tab";
|
2010-09-22 12:55:08 +00:00
|
|
|
loadInBackground = false;
|
2010-08-31 19:30:38 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
where = "tab";
|
2010-09-22 12:55:08 +00:00
|
|
|
loadInBackground = false;
|
2010-08-31 19:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 18:11:23 +00:00
|
|
|
// Raise the target window before loading the URI, since loading it may
|
|
|
|
// result in a new frontmost window (e.g. "javascript:window.open('');").
|
|
|
|
w.focus();
|
|
|
|
|
2004-06-23 22:54:12 +00:00
|
|
|
switch (where) {
|
|
|
|
case "current":
|
2011-07-28 15:37:56 +00:00
|
|
|
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
|
|
|
if (aAllowThirdPartyFixup)
|
|
|
|
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
|
|
|
|
if (aDisallowInheritPrincipal)
|
|
|
|
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER;
|
2011-11-05 15:48:28 +00:00
|
|
|
if (aIsUTF8)
|
|
|
|
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_URI_IS_UTF8;
|
2011-07-28 15:37:56 +00:00
|
|
|
w.gBrowser.loadURIWithFlags(url, flags, aReferrerURI, null, aPostData);
|
2004-06-23 22:54:12 +00:00
|
|
|
break;
|
|
|
|
case "tabshifted":
|
2006-05-29 15:59:46 +00:00
|
|
|
loadInBackground = !loadInBackground;
|
|
|
|
// fall through
|
2004-06-23 22:54:12 +00:00
|
|
|
case "tab":
|
2010-01-15 08:19:41 +00:00
|
|
|
let browser = w.gBrowser;
|
2009-09-17 13:03:15 +00:00
|
|
|
browser.loadOneTab(url, {
|
2010-01-15 08:19:41 +00:00
|
|
|
referrerURI: aReferrerURI,
|
2010-10-23 12:01:33 +00:00
|
|
|
charset: aCharset,
|
2010-01-15 08:19:41 +00:00
|
|
|
postData: aPostData,
|
2009-09-17 13:03:15 +00:00
|
|
|
inBackground: loadInBackground,
|
2010-01-15 08:19:41 +00:00
|
|
|
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
2011-11-05 15:48:28 +00:00
|
|
|
relatedToCurrent: aRelatedToCurrent,
|
|
|
|
isUTF8: aIsUTF8});
|
2004-06-23 22:54:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-13 14:49:43 +00:00
|
|
|
|
2012-09-19 10:59:26 +00:00
|
|
|
w.gBrowser.selectedBrowser.focus();
|
2011-12-20 13:02:48 +00:00
|
|
|
|
2013-02-28 18:18:41 +00:00
|
|
|
if (!loadInBackground && w.isBlankPageURL(url))
|
2011-12-20 13:02:48 +00:00
|
|
|
w.focusAndSelectUrlBar();
|
2004-06-23 22:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Used as an onclick handler for UI elements with link-like behavior.
|
|
|
|
// e.g. onclick="checkForMiddleClick(this, event);"
|
2008-08-31 21:00:59 +00:00
|
|
|
function checkForMiddleClick(node, event) {
|
2006-07-13 10:56:54 +00:00
|
|
|
// We should be using the disabled property here instead of the attribute,
|
|
|
|
// but some elements that this function is used with don't support it (e.g.
|
|
|
|
// menuitem).
|
|
|
|
if (node.getAttribute("disabled") == "true")
|
|
|
|
return; // Do nothing
|
|
|
|
|
2004-06-23 22:54:12 +00:00
|
|
|
if (event.button == 1) {
|
2008-08-31 21:00:59 +00:00
|
|
|
/* Execute the node's oncommand or command.
|
2004-06-23 22:54:12 +00:00
|
|
|
*
|
2006-04-24 14:09:00 +00:00
|
|
|
* XXX: we should use node.oncommand(event) once bug 246720 is fixed.
|
2004-06-23 22:54:12 +00:00
|
|
|
*/
|
2008-08-31 21:00:59 +00:00
|
|
|
var target = node.hasAttribute("oncommand") ? node :
|
|
|
|
node.ownerDocument.getElementById(node.getAttribute("command"));
|
|
|
|
var fn = new Function("event", target.getAttribute("oncommand"));
|
|
|
|
fn.call(target, event);
|
2004-06-23 22:54:12 +00:00
|
|
|
|
|
|
|
// If the middle-click was on part of a menu, close the menu.
|
|
|
|
// (Menus close automatically with left-click but not with middle-click.)
|
|
|
|
closeMenus(event.target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Closes all popups that are ancestors of the node.
|
|
|
|
function closeMenus(node)
|
|
|
|
{
|
|
|
|
if ("tagName" in node) {
|
|
|
|
if (node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
&& (node.tagName == "menupopup" || node.tagName == "popup"))
|
|
|
|
node.hidePopup();
|
|
|
|
|
|
|
|
closeMenus(node.parentNode);
|
|
|
|
}
|
2002-08-04 02:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Gather all descendent text under given document node.
|
|
|
|
function gatherTextUnder ( root )
|
|
|
|
{
|
|
|
|
var text = "";
|
|
|
|
var node = root.firstChild;
|
|
|
|
var depth = 1;
|
|
|
|
while ( node && depth > 0 ) {
|
|
|
|
// See if this node is text.
|
2005-06-16 12:58:13 +00:00
|
|
|
if ( node.nodeType == Node.TEXT_NODE ) {
|
2002-08-04 02:55:51 +00:00
|
|
|
// Add this text to our collection.
|
|
|
|
text += " " + node.data;
|
2005-06-30 02:47:04 +00:00
|
|
|
} else if ( node instanceof HTMLImageElement) {
|
2013-08-18 19:40:47 +00:00
|
|
|
// If it has an "alt" attribute, add that.
|
2002-08-04 02:55:51 +00:00
|
|
|
var altText = node.getAttribute( "alt" );
|
|
|
|
if ( altText && altText != "" ) {
|
2013-08-18 19:40:47 +00:00
|
|
|
text += " " + altText;
|
2002-08-04 02:55:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Find next node to test.
|
|
|
|
// First, see if this node has children.
|
|
|
|
if ( node.hasChildNodes() ) {
|
|
|
|
// Go to first child.
|
|
|
|
node = node.firstChild;
|
|
|
|
depth++;
|
|
|
|
} else {
|
2011-12-15 18:42:12 +00:00
|
|
|
// No children, try next sibling (or parent next sibling).
|
|
|
|
while ( depth > 0 && !node.nextSibling ) {
|
|
|
|
node = node.parentNode;
|
|
|
|
depth--;
|
|
|
|
}
|
2002-08-04 02:55:51 +00:00
|
|
|
if ( node.nextSibling ) {
|
|
|
|
node = node.nextSibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-18 19:40:47 +00:00
|
|
|
// Strip leading and tailing whitespace.
|
|
|
|
text = text.trim();
|
2002-08-04 02:55:51 +00:00
|
|
|
// Compress remaining whitespace.
|
|
|
|
text = text.replace( /\s+/g, " " );
|
|
|
|
return text;
|
|
|
|
}
|
2004-07-15 22:51:19 +00:00
|
|
|
|
|
|
|
function getShellService()
|
|
|
|
{
|
|
|
|
var shell = null;
|
|
|
|
try {
|
|
|
|
shell = Components.classes["@mozilla.org/browser/shell-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIShellService);
|
2012-02-22 13:06:55 +00:00
|
|
|
} catch (e) {
|
|
|
|
}
|
2004-07-15 22:51:19 +00:00
|
|
|
return shell;
|
|
|
|
}
|
2005-01-26 01:40:30 +00:00
|
|
|
|
|
|
|
function isBidiEnabled() {
|
2008-12-14 09:05:39 +00:00
|
|
|
// first check the pref.
|
2008-12-18 08:50:59 +00:00
|
|
|
if (getBoolPref("bidi.browser.ui", false))
|
2008-12-14 09:05:39 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// if the pref isn't set, check for an RTL locale and force the pref to true
|
|
|
|
// if we find one.
|
2005-01-26 01:40:30 +00:00
|
|
|
var rv = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
|
|
|
|
.getService(Components.interfaces.nsILocaleService);
|
|
|
|
var systemLocale = localeService.getSystemLocale().getCategory("NSILOCALE_CTYPE").substr(0,3);
|
|
|
|
|
|
|
|
switch (systemLocale) {
|
|
|
|
case "ar-":
|
|
|
|
case "he-":
|
|
|
|
case "fa-":
|
|
|
|
case "ur-":
|
|
|
|
case "syr":
|
|
|
|
rv = true;
|
2010-01-28 18:31:45 +00:00
|
|
|
Services.prefs.setBoolPref("bidi.browser.ui", true);
|
2005-01-26 01:40:30 +00:00
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2005-03-24 16:00:01 +00:00
|
|
|
|
2010-03-04 09:24:31 +00:00
|
|
|
function openAboutDialog() {
|
|
|
|
var enumerator = Services.wm.getEnumerator("Browser:About");
|
|
|
|
while (enumerator.hasMoreElements()) {
|
2010-11-05 21:03:42 +00:00
|
|
|
// Only open one about window (Bug 599573)
|
2010-03-04 09:24:31 +00:00
|
|
|
let win = enumerator.getNext();
|
2013-09-13 21:29:51 +00:00
|
|
|
if (win.closed) {
|
|
|
|
continue;
|
|
|
|
}
|
2005-07-05 21:39:05 +00:00
|
|
|
win.focus();
|
2010-03-04 09:24:31 +00:00
|
|
|
return;
|
2005-07-05 21:39:05 +00:00
|
|
|
}
|
2010-03-04 09:24:31 +00:00
|
|
|
|
2011-05-31 12:20:09 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
var features = "chrome,centerscreen,dependent";
|
|
|
|
#elifdef XP_MACOSX
|
2010-03-04 09:24:31 +00:00
|
|
|
var features = "chrome,resizable=no,minimizable=no";
|
2005-03-24 16:00:01 +00:00
|
|
|
#else
|
2011-05-31 12:20:09 +00:00
|
|
|
var features = "chrome,centerscreen,dependent,dialog=no";
|
2005-03-24 16:00:01 +00:00
|
|
|
#endif
|
2010-03-04 09:24:31 +00:00
|
|
|
window.openDialog("chrome://browser/content/aboutDialog.xul", "", features);
|
2005-03-24 16:00:01 +00:00
|
|
|
}
|
2005-03-25 01:35:01 +00:00
|
|
|
|
2008-04-05 00:18:07 +00:00
|
|
|
function openPreferences(paneID, extraArgs)
|
2005-03-25 01:35:01 +00:00
|
|
|
{
|
2012-07-18 15:18:11 +00:00
|
|
|
if (Services.prefs.getBoolPref("browser.preferences.inContent")) {
|
2012-05-09 02:31:51 +00:00
|
|
|
openUILinkIn("about:preferences", "tab");
|
|
|
|
} else {
|
|
|
|
var instantApply = getBoolPref("browser.preferences.instantApply", false);
|
|
|
|
var features = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal");
|
|
|
|
|
|
|
|
var win = Services.wm.getMostRecentWindow("Browser:Preferences");
|
|
|
|
if (win) {
|
|
|
|
win.focus();
|
|
|
|
if (paneID) {
|
|
|
|
var pane = win.document.getElementById(paneID);
|
|
|
|
win.document.documentElement.showPane(pane);
|
|
|
|
}
|
2005-03-25 01:35:01 +00:00
|
|
|
|
2012-05-09 02:31:51 +00:00
|
|
|
if (extraArgs && extraArgs["advancedTab"]) {
|
|
|
|
var advancedPaneTabs = win.document.getElementById("advancedPrefs");
|
|
|
|
advancedPaneTabs.selectedTab = win.document.getElementById(extraArgs["advancedTab"]);
|
|
|
|
}
|
2008-04-05 00:18:07 +00:00
|
|
|
|
2012-07-18 15:18:11 +00:00
|
|
|
return;
|
2008-04-05 00:18:07 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 15:18:11 +00:00
|
|
|
openDialog("chrome://browser/content/preferences/preferences.xul",
|
|
|
|
"Preferences", features, paneID, extraArgs);
|
2008-02-26 21:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openAdvancedPreferences(tabID)
|
|
|
|
{
|
2012-07-18 15:18:11 +00:00
|
|
|
openPreferences("paneAdvanced", { "advancedTab" : tabID });
|
2005-03-25 01:35:01 +00:00
|
|
|
}
|
2005-03-27 21:06:28 +00:00
|
|
|
|
2009-09-25 16:40:51 +00:00
|
|
|
/**
|
|
|
|
* Opens the troubleshooting information (about:support) page for this version
|
|
|
|
* of the application.
|
|
|
|
*/
|
|
|
|
function openTroubleshootingPage()
|
|
|
|
{
|
|
|
|
openUILinkIn("about:support", "tab");
|
|
|
|
}
|
|
|
|
|
2013-01-15 00:55:43 +00:00
|
|
|
#ifdef MOZ_SERVICES_HEALTHREPORT
|
2013-01-11 23:31:38 +00:00
|
|
|
/**
|
|
|
|
* Opens the troubleshooting information (about:support) page for this version
|
|
|
|
* of the application.
|
|
|
|
*/
|
|
|
|
function openHealthReport()
|
|
|
|
{
|
|
|
|
openUILinkIn("about:healthreport", "tab");
|
|
|
|
}
|
2013-01-15 00:55:43 +00:00
|
|
|
#endif
|
2013-01-11 23:31:38 +00:00
|
|
|
|
2010-08-23 17:34:29 +00:00
|
|
|
/**
|
|
|
|
* Opens the feedback page for this version of the application.
|
|
|
|
*/
|
|
|
|
function openFeedbackPage()
|
|
|
|
{
|
2013-03-06 04:03:25 +00:00
|
|
|
openUILinkIn("https://input.mozilla.org/feedback", "tab");
|
2010-08-23 17:34:29 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 23:17:59 +00:00
|
|
|
function buildHelpMenu()
|
|
|
|
{
|
2012-07-28 06:25:11 +00:00
|
|
|
// Enable/disable the "Report Web Forgery" menu item.
|
|
|
|
if (typeof gSafeBrowsing != "undefined")
|
|
|
|
gSafeBrowsing.setReportPhishingMenu();
|
2005-06-20 21:25:45 +00:00
|
|
|
}
|
2006-09-21 12:57:21 +00:00
|
|
|
|
|
|
|
function isElementVisible(aElement)
|
|
|
|
{
|
2007-10-08 20:17:14 +00:00
|
|
|
if (!aElement)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If aElement or a direct or indirect parent is hidden or collapsed,
|
|
|
|
// height, width or both will be 0.
|
2006-09-21 12:57:21 +00:00
|
|
|
var bo = aElement.boxObject;
|
2007-10-08 20:17:14 +00:00
|
|
|
return (bo.height > 0 && bo.width > 0);
|
2006-09-21 12:57:21 +00:00
|
|
|
}
|
2007-02-08 13:15:50 +00:00
|
|
|
|
2007-12-17 18:27:23 +00:00
|
|
|
function makeURLAbsolute(aBase, aUrl)
|
|
|
|
{
|
2008-02-02 00:39:05 +00:00
|
|
|
// Note: makeURI() will throw if aUri is not a valid URI
|
|
|
|
return makeURI(aUrl, null, makeURI(aBase)).spec;
|
2007-12-17 18:27:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-17 04:12:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* openNewTabWith: opens a new tab with the given URL.
|
|
|
|
*
|
|
|
|
* @param aURL
|
|
|
|
* The URL to open (as a string).
|
|
|
|
* @param aDocument
|
|
|
|
* The document from which the URL came, or null. This is used to set the
|
|
|
|
* referrer header and to do a security check of whether the document is
|
|
|
|
* allowed to reference the URL. If null, there will be no referrer
|
|
|
|
* header and no security check.
|
|
|
|
* @param aPostData
|
|
|
|
* Form POST data, or null.
|
|
|
|
* @param aEvent
|
|
|
|
* The triggering event (for the purpose of determining whether to open
|
|
|
|
* in the background), or null.
|
|
|
|
* @param aAllowThirdPartyFixup
|
|
|
|
* If true, then we allow the URL text to be sent to third party services
|
|
|
|
* (e.g., Google's I Feel Lucky) for interpretation. This parameter may
|
|
|
|
* be undefined in which case it is treated as false.
|
2007-08-26 05:18:47 +00:00
|
|
|
* @param [optional] aReferrer
|
|
|
|
* If aDocument is null, then this will be used as the referrer.
|
|
|
|
* There will be no security check.
|
2007-02-17 04:12:28 +00:00
|
|
|
*/
|
|
|
|
function openNewTabWith(aURL, aDocument, aPostData, aEvent,
|
2010-12-24 23:11:45 +00:00
|
|
|
aAllowThirdPartyFixup, aReferrer) {
|
2007-02-17 04:12:28 +00:00
|
|
|
if (aDocument)
|
|
|
|
urlSecurityCheck(aURL, aDocument.nodePrincipal);
|
|
|
|
|
|
|
|
// As in openNewWindowWith(), we want to pass the charset of the
|
2010-12-24 23:11:45 +00:00
|
|
|
// current document over to a new tab.
|
|
|
|
var originCharset = aDocument && aDocument.characterSet;
|
|
|
|
if (!originCharset &&
|
|
|
|
document.documentElement.getAttribute("windowtype") == "navigator:browser")
|
2007-02-17 04:12:28 +00:00
|
|
|
originCharset = window.content.document.characterSet;
|
|
|
|
|
2010-12-24 23:11:45 +00:00
|
|
|
openLinkIn(aURL, aEvent && aEvent.shiftKey ? "tabshifted" : "tab",
|
|
|
|
{ charset: originCharset,
|
|
|
|
postData: aPostData,
|
|
|
|
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
|
|
|
referrerURI: aDocument ? aDocument.documentURIObject : aReferrer });
|
2007-02-17 04:12:28 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 23:11:45 +00:00
|
|
|
function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup, aReferrer) {
|
2007-02-17 04:12:28 +00:00
|
|
|
if (aDocument)
|
|
|
|
urlSecurityCheck(aURL, aDocument.nodePrincipal);
|
|
|
|
|
|
|
|
// 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...
|
2010-12-24 23:11:45 +00:00
|
|
|
var originCharset = aDocument && aDocument.characterSet;
|
|
|
|
if (!originCharset &&
|
|
|
|
document.documentElement.getAttribute("windowtype") == "navigator:browser")
|
|
|
|
originCharset = window.content.document.characterSet;
|
|
|
|
|
|
|
|
openLinkIn(aURL, "window",
|
|
|
|
{ charset: originCharset,
|
|
|
|
postData: aPostData,
|
|
|
|
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
|
|
|
referrerURI: aDocument ? aDocument.documentURIObject : aReferrer });
|
2007-02-17 04:12:28 +00:00
|
|
|
}
|
2007-06-24 11:26:18 +00:00
|
|
|
|
|
|
|
/**
|
2007-10-02 17:54:35 +00:00
|
|
|
* isValidFeed: checks whether the given data represents a valid feed.
|
2007-06-24 11:26:18 +00:00
|
|
|
*
|
2008-09-07 02:28:36 +00:00
|
|
|
* @param aLink
|
2007-10-02 17:54:35 +00:00
|
|
|
* An object representing a feed with title, href and type.
|
2007-06-24 11:26:18 +00:00
|
|
|
* @param aPrincipal
|
|
|
|
* The principal of the document, used for security check.
|
2007-10-02 17:54:35 +00:00
|
|
|
* @param aIsFeed
|
|
|
|
* Whether this is already a known feed or not, if true only a security
|
|
|
|
* check will be performed.
|
2007-06-24 11:26:18 +00:00
|
|
|
*/
|
2008-09-07 02:28:36 +00:00
|
|
|
function isValidFeed(aLink, aPrincipal, aIsFeed)
|
2007-06-24 11:26:18 +00:00
|
|
|
{
|
2008-09-07 02:28:36 +00:00
|
|
|
if (!aLink || !aPrincipal)
|
2007-10-02 17:54:35 +00:00
|
|
|
return false;
|
|
|
|
|
2008-09-07 02:28:36 +00:00
|
|
|
var type = aLink.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, "");
|
2007-10-02 17:54:35 +00:00
|
|
|
if (!aIsFeed) {
|
|
|
|
aIsFeed = (type == "application/rss+xml" ||
|
|
|
|
type == "application/atom+xml");
|
2007-06-24 11:26:18 +00:00
|
|
|
}
|
|
|
|
|
2007-10-02 17:54:35 +00:00
|
|
|
if (aIsFeed) {
|
|
|
|
try {
|
2008-09-07 02:28:36 +00:00
|
|
|
urlSecurityCheck(aLink.href, aPrincipal,
|
2007-06-24 11:26:18 +00:00
|
|
|
Components.interfaces.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
|
2008-09-07 02:28:36 +00:00
|
|
|
return type || "application/rss+xml";
|
2007-06-24 11:26:18 +00:00
|
|
|
}
|
2007-10-02 17:54:35 +00:00
|
|
|
catch(ex) {
|
2007-06-24 11:26:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-07 02:28:36 +00:00
|
|
|
return null;
|
2007-06-24 11:26:18 +00:00
|
|
|
}
|
2008-02-26 21:13:17 +00:00
|
|
|
|
2008-03-24 17:18:38 +00:00
|
|
|
// aCalledFromModal is optional
|
|
|
|
function openHelpLink(aHelpTopic, aCalledFromModal) {
|
|
|
|
var url = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
|
|
|
|
.getService(Components.interfaces.nsIURLFormatter)
|
|
|
|
.formatURLPref("app.support.baseURL");
|
|
|
|
url += aHelpTopic;
|
|
|
|
|
|
|
|
var where = aCalledFromModal ? "window" : "tab";
|
|
|
|
openUILinkIn(url, where);
|
|
|
|
}
|
|
|
|
|
|
|
|
function openPrefsHelp() {
|
|
|
|
// non-instant apply prefwindows are usually modal, so we can't open in the topmost window,
|
|
|
|
// since its probably behind the window.
|
2010-01-28 18:31:45 +00:00
|
|
|
var instantApply = getBoolPref("browser.preferences.instantApply");
|
2008-03-24 17:18:38 +00:00
|
|
|
|
|
|
|
var helpTopic = document.getElementsByTagName("prefwindow")[0].currentPane.helpTopic;
|
|
|
|
openHelpLink(helpTopic, !instantApply);
|
|
|
|
}
|
2011-06-23 08:13:41 +00:00
|
|
|
|
|
|
|
function trimURL(aURL) {
|
2011-11-10 13:55:07 +00:00
|
|
|
// This function must not modify the given URL such that calling
|
|
|
|
// nsIURIFixup::createFixupURI with the result will produce a different URI.
|
2011-06-23 08:13:41 +00:00
|
|
|
return aURL /* remove single trailing slash for http/https/ftp URLs */
|
|
|
|
.replace(/^((?:http|https|ftp):\/\/[^/]+)\/$/, "$1")
|
2011-11-10 13:55:07 +00:00
|
|
|
/* remove http:// unless the host starts with "ftp\d*\." or contains "@" */
|
|
|
|
.replace(/^http:\/\/((?!ftp\d*\.)[^\/@]+(?:\/|$))/, "$1");
|
2011-06-23 08:13:41 +00:00
|
|
|
}
|