2007-03-22 10:30:00 -07:00
|
|
|
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
|
|
|
# The Original Code is mozilla.org code.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is
|
|
|
|
# Netscape Communications Corporation.
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Alec Flett <alecf@netscape.com>
|
2007-06-24 04:26:18 -07:00
|
|
|
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2010-01-28 10:31:45 -08:00
|
|
|
# Gavin Sharp <gavin@gavinsharp.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
|
2010-01-28 10:31:45 -08:00
|
|
|
// Services = object with smart getters for common XPCOM services
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-19 04:00:05 -08:00
|
|
|
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var gBidiUI = false;
|
|
|
|
|
|
|
|
function getBrowserURL()
|
|
|
|
{
|
|
|
|
return "chrome://browser/content/browser.xul";
|
|
|
|
}
|
|
|
|
|
|
|
|
function goToggleToolbar( id, elementID )
|
|
|
|
{
|
|
|
|
var toolbar = document.getElementById(id);
|
|
|
|
var element = document.getElementById(elementID);
|
|
|
|
if (toolbar)
|
|
|
|
{
|
|
|
|
var isHidden = toolbar.hidden;
|
|
|
|
toolbar.hidden = !isHidden;
|
|
|
|
document.persist(id, 'hidden');
|
|
|
|
if (element) {
|
|
|
|
element.setAttribute("checked", isHidden ? "true" : "false");
|
|
|
|
document.persist(elementID, 'checked');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTopWin()
|
|
|
|
{
|
2010-01-28 10:31:45 -08:00
|
|
|
return Services.wm.getMostRecentWindow("navigator:browser");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function openTopWin( url )
|
|
|
|
{
|
|
|
|
openUILink(url, {})
|
|
|
|
}
|
|
|
|
|
2010-01-28 10:31:45 -08:00
|
|
|
function getBoolPref(prefname, def)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-28 10:31:45 -08:00
|
|
|
try {
|
|
|
|
return Services.prefs.getBoolPref(prefname);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch(er) {
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// openUILink handles clicks on UI elements that cause URLs to load.
|
|
|
|
function openUILink( url, e, ignoreButton, ignoreAlt, allowKeywordFixup, postData, referrerUrl )
|
|
|
|
{
|
|
|
|
var where = whereToOpenLink(e, ignoreButton, ignoreAlt);
|
|
|
|
openUILinkIn(url, where, allowKeywordFixup, postData, referrerUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*
|
|
|
|
* You can swap Ctrl and Ctrl+shift by toggling the hidden pref
|
|
|
|
* browser.tabs.loadBookmarksInBackground (not browser.tabs.loadInBackground, which
|
|
|
|
* is for content area links).
|
|
|
|
*
|
|
|
|
* Middle-clicking is the same as Ctrl+clicking (it opens a new tab) and it is
|
|
|
|
* subject to the shift modifier and pref in the same way.
|
|
|
|
*
|
|
|
|
* 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-03 17:18:50 -07: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!e)
|
2008-09-03 17:18:50 -07:00
|
|
|
return "current";
|
2007-03-22 10:30:00 -07: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 11:18:40 -08:00
|
|
|
if (meta || (middle && middleUsesTabs))
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2010-01-19 11:18:40 -08:00
|
|
|
if (ctrl || (middle && middleUsesTabs))
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2010-01-19 11:18:40 -08:00
|
|
|
return shift ? "tabshifted" : "tab";
|
|
|
|
|
|
|
|
if (alt)
|
2007-03-22 10:30:00 -07:00
|
|
|
return "save";
|
2010-01-19 11:18:40 -08:00
|
|
|
|
|
|
|
if (shift || (middle && !middleUsesTabs))
|
2007-03-22 10:30:00 -07:00
|
|
|
return "window";
|
2010-01-19 11:18:40 -08:00
|
|
|
|
|
|
|
return "current";
|
2007-03-22 10:30:00 -07: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!)
|
|
|
|
*
|
2010-01-15 00:19:41 -08:00
|
|
|
* aAllowThirdPartyFixup controls whether third party services such as Google's
|
2007-03-22 10:30:00 -07:00
|
|
|
* I Feel Lucky are allowed to interpret this URL. This parameter may be
|
|
|
|
* undefined, which is treated as false.
|
2010-01-15 00:19:41 -08:00
|
|
|
*
|
|
|
|
* Instead of aAllowThirdPartyFixup, you may also pass an object with any of
|
|
|
|
* these properties:
|
|
|
|
* allowThirdPartyFixup (boolean)
|
|
|
|
* postData (nsIInputStream)
|
|
|
|
* referrerURI (nsIURI)
|
|
|
|
* relatedToCurrent (boolean)
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-01-15 00:19:41 -08:00
|
|
|
function openUILinkIn(url, where, aAllowThirdPartyFixup, aPostData, aReferrerURI) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!where || !url)
|
|
|
|
return;
|
|
|
|
|
2010-01-15 00:19:41 -08:00
|
|
|
var aRelatedToCurrent;
|
|
|
|
if (arguments.length == 3 &&
|
|
|
|
typeof arguments[2] == "object") {
|
|
|
|
let params = arguments[2];
|
|
|
|
aAllowThirdPartyFixup = params.allowThirdPartyFixup;
|
|
|
|
aPostData = params.postData;
|
|
|
|
aReferrerURI = params.referrerURI;
|
|
|
|
aRelatedToCurrent = params.relatedToCurrent;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (where == "save") {
|
2010-01-15 00:19:41 -08:00
|
|
|
saveURL(url, null, null, true, null, aReferrerURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-04-22 20:51:11 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var w = getTopWin();
|
|
|
|
|
|
|
|
if (!w || where == "window") {
|
2008-04-22 20:51:11 -07: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;
|
|
|
|
|
2009-11-09 13:14:20 -08:00
|
|
|
var allowThirdPartyFixupSupports = Cc["@mozilla.org/supports-PRBool;1"].
|
|
|
|
createInstance(Ci.nsISupportsPRBool);
|
2010-01-15 00:19:41 -08:00
|
|
|
allowThirdPartyFixupSupports.data = aAllowThirdPartyFixup;
|
2009-11-09 13:14:20 -08:00
|
|
|
|
2008-04-22 20:51:11 -07:00
|
|
|
sa.AppendElement(wuri);
|
|
|
|
sa.AppendElement(null);
|
2010-01-15 00:19:41 -08:00
|
|
|
sa.AppendElement(aReferrerURI);
|
|
|
|
sa.AppendElement(aPostData);
|
2009-11-09 13:14:20 -08:00
|
|
|
sa.AppendElement(allowThirdPartyFixupSupports);
|
2008-04-22 20:51:11 -07:00
|
|
|
|
|
|
|
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
|
|
|
getService(Ci.nsIWindowWatcher);
|
|
|
|
|
|
|
|
ww.openWindow(w || window,
|
|
|
|
getBrowserURL(),
|
|
|
|
null,
|
|
|
|
"chrome,dialog=no,all",
|
|
|
|
sa);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-28 10:31:45 -08:00
|
|
|
var loadInBackground = getBoolPref("browser.tabs.loadBookmarksInBackground");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-31 12:30:38 -07: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";
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
where = "tab";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (where) {
|
|
|
|
case "current":
|
2010-01-15 00:19:41 -08:00
|
|
|
w.loadURI(url, aReferrerURI, aPostData, aAllowThirdPartyFixup);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case "tabshifted":
|
|
|
|
loadInBackground = !loadInBackground;
|
|
|
|
// fall through
|
|
|
|
case "tab":
|
2010-01-15 00:19:41 -08:00
|
|
|
let browser = w.gBrowser;
|
2009-09-17 06:03:15 -07:00
|
|
|
browser.loadOneTab(url, {
|
2010-01-15 00:19:41 -08:00
|
|
|
referrerURI: aReferrerURI,
|
|
|
|
postData: aPostData,
|
2009-09-17 06:03:15 -07:00
|
|
|
inBackground: loadInBackground,
|
2010-01-15 00:19:41 -08:00
|
|
|
allowThirdPartyFixup: aAllowThirdPartyFixup,
|
|
|
|
relatedToCurrent: aRelatedToCurrent});
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-24 10:12:31 -07:00
|
|
|
// If this window is active, focus the target window. Otherwise, focus the
|
|
|
|
// content but don't raise the window, since the URI we just loaded may have
|
|
|
|
// resulted in a new frontmost window (e.g. "javascript:window.open('');").
|
|
|
|
var fm = Components.classes["@mozilla.org/focus-manager;1"].
|
|
|
|
getService(Components.interfaces.nsIFocusManager);
|
2009-08-10 09:27:10 -07:00
|
|
|
if (window == fm.activeWindow)
|
2009-06-24 10:12:31 -07:00
|
|
|
w.content.focus();
|
2009-08-10 09:27:10 -07:00
|
|
|
else
|
|
|
|
w.gBrowser.selectedBrowser.focus();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Used as an onclick handler for UI elements with link-like behavior.
|
|
|
|
// e.g. onclick="checkForMiddleClick(this, event);"
|
2008-08-31 14:00:59 -07:00
|
|
|
function checkForMiddleClick(node, event) {
|
2007-03-22 10:30:00 -07: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
|
|
|
|
|
|
|
|
if (event.button == 1) {
|
2008-08-31 14:00:59 -07:00
|
|
|
/* Execute the node's oncommand or command.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* XXX: we should use node.oncommand(event) once bug 246720 is fixed.
|
|
|
|
*/
|
2008-08-31 14:00:59 -07: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);
|
2007-03-22 10:30:00 -07: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if ( node.nodeType == Node.TEXT_NODE ) {
|
|
|
|
// Add this text to our collection.
|
|
|
|
text += " " + node.data;
|
|
|
|
} else if ( node instanceof HTMLImageElement) {
|
|
|
|
// If it has an alt= attribute, use that.
|
|
|
|
var altText = node.getAttribute( "alt" );
|
|
|
|
if ( altText && altText != "" ) {
|
|
|
|
text = altText;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Find next node to test.
|
|
|
|
// First, see if this node has children.
|
|
|
|
if ( node.hasChildNodes() ) {
|
|
|
|
// Go to first child.
|
|
|
|
node = node.firstChild;
|
|
|
|
depth++;
|
|
|
|
} else {
|
|
|
|
// No children, try next sibling.
|
|
|
|
if ( node.nextSibling ) {
|
|
|
|
node = node.nextSibling;
|
|
|
|
} else {
|
|
|
|
// Last resort is our next oldest uncle/aunt.
|
|
|
|
node = node.parentNode.nextSibling;
|
|
|
|
depth--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Strip leading whitespace.
|
|
|
|
text = text.replace( /^\s+/, "" );
|
|
|
|
// Strip trailing whitespace.
|
|
|
|
text = text.replace( /\s+$/, "" );
|
|
|
|
// Compress remaining whitespace.
|
|
|
|
text = text.replace( /\s+/g, " " );
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getShellService()
|
|
|
|
{
|
|
|
|
var shell = null;
|
|
|
|
try {
|
|
|
|
shell = Components.classes["@mozilla.org/browser/shell-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIShellService);
|
|
|
|
} catch (e) {dump("*** e = " + e + "\n");}
|
|
|
|
return shell;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isBidiEnabled() {
|
2008-12-14 01:05:39 -08:00
|
|
|
// first check the pref.
|
2008-12-18 00:50:59 -08:00
|
|
|
if (getBoolPref("bidi.browser.ui", false))
|
2008-12-14 01:05:39 -08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// if the pref isn't set, check for an RTL locale and force the pref to true
|
|
|
|
// if we find one.
|
2007-03-22 10:30:00 -07: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 10:31:45 -08:00
|
|
|
Services.prefs.setBoolPref("bidi.browser.ui", true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-03-04 01:24:31 -08:00
|
|
|
function openAboutDialog() {
|
|
|
|
var enumerator = Services.wm.getEnumerator("Browser:About");
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
let win = enumerator.getNext();
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (win.opener != window)
|
|
|
|
continue;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
win.focus();
|
2010-03-04 01:24:31 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-04 01:24:31 -08:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
var features = "chrome,resizable=no,minimizable=no";
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2010-03-04 01:24:31 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
var features = "chrome,centerscreen,dependent";
|
|
|
|
#else
|
|
|
|
var features = "chrome,centerscreen";
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2010-03-04 01:24:31 -08:00
|
|
|
window.openDialog("chrome://browser/content/aboutDialog.xul", "", features);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-04-04 17:18:07 -07:00
|
|
|
function openPreferences(paneID, extraArgs)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
var instantApply = getBoolPref("browser.preferences.instantApply", false);
|
|
|
|
var features = "chrome,titlebar,toolbar,centerscreen" + (instantApply ? ",dialog=no" : ",modal");
|
|
|
|
|
2010-01-28 10:31:45 -08:00
|
|
|
var win = Services.wm.getMostRecentWindow("Browser:Preferences");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (win) {
|
|
|
|
win.focus();
|
|
|
|
if (paneID) {
|
|
|
|
var pane = win.document.getElementById(paneID);
|
|
|
|
win.document.documentElement.showPane(pane);
|
|
|
|
}
|
2008-04-04 17:18:07 -07:00
|
|
|
|
|
|
|
if (extraArgs && extraArgs["advancedTab"]) {
|
|
|
|
var advancedPaneTabs = win.document.getElementById("advancedPrefs");
|
|
|
|
advancedPaneTabs.selectedTab = win.document.getElementById(extraArgs["advancedTab"]);
|
|
|
|
}
|
|
|
|
|
2008-02-26 13:13:17 -08:00
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
|
|
|
return openDialog("chrome://browser/content/preferences/preferences.xul",
|
2008-04-04 17:18:07 -07:00
|
|
|
"Preferences", features, paneID, extraArgs);
|
2008-02-26 13:13:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function openAdvancedPreferences(tabID)
|
|
|
|
{
|
2008-04-04 17:18:07 -07:00
|
|
|
return openPreferences("paneAdvanced", { "advancedTab" : tabID });
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the release notes page for this version of the application.
|
|
|
|
*/
|
2009-04-02 07:56:25 -07:00
|
|
|
function openReleaseNotes()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
|
|
|
|
.getService(Components.interfaces.nsIURLFormatter);
|
|
|
|
var relnotesURL = formatter.formatURLPref("app.releaseNotesURL");
|
|
|
|
|
2009-04-02 07:56:25 -07:00
|
|
|
openUILinkIn(relnotesURL, "tab");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-11-26 00:45:24 -08:00
|
|
|
|
2009-09-25 09:40:51 -07:00
|
|
|
/**
|
|
|
|
* Opens the troubleshooting information (about:support) page for this version
|
|
|
|
* of the application.
|
|
|
|
*/
|
|
|
|
function openTroubleshootingPage()
|
|
|
|
{
|
|
|
|
openUILinkIn("about:support", "tab");
|
|
|
|
}
|
|
|
|
|
2010-08-23 10:34:29 -07:00
|
|
|
/**
|
|
|
|
* Opens the feedback page for this version of the application.
|
|
|
|
*/
|
|
|
|
function openFeedbackPage()
|
|
|
|
{
|
|
|
|
openUILinkIn("http://input.mozilla.com/sad", "tab");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 00:45:24 -08:00
|
|
|
#ifdef MOZ_UPDATER
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Opens the update manager and checks for updates to the application.
|
|
|
|
*/
|
|
|
|
function checkForUpdates()
|
|
|
|
{
|
|
|
|
var um =
|
|
|
|
Components.classes["@mozilla.org/updates/update-manager;1"].
|
|
|
|
getService(Components.interfaces.nsIUpdateManager);
|
|
|
|
var prompter =
|
|
|
|
Components.classes["@mozilla.org/updates/update-prompt;1"].
|
|
|
|
createInstance(Components.interfaces.nsIUpdatePrompt);
|
|
|
|
|
|
|
|
// If there's an update ready to be applied, show the "Update Downloaded"
|
|
|
|
// UI instead and let the user know they have to restart the browser for
|
|
|
|
// the changes to be applied.
|
|
|
|
if (um.activeUpdate && um.activeUpdate.state == "pending")
|
2008-01-08 23:37:06 -08:00
|
|
|
prompter.showUpdateDownloaded(um.activeUpdate);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
prompter.checkForUpdates();
|
|
|
|
}
|
2008-11-26 00:45:24 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
function buildHelpMenu()
|
|
|
|
{
|
|
|
|
// Enable/disable the "Report Web Forgery" menu item. safebrowsing object
|
|
|
|
// may not exist in OSX
|
|
|
|
if (typeof safebrowsing != "undefined")
|
|
|
|
safebrowsing.setReportPhishingMenu();
|
|
|
|
|
2008-11-26 00:45:24 -08:00
|
|
|
#ifdef MOZ_UPDATER
|
2007-03-22 10:30:00 -07:00
|
|
|
var updates =
|
|
|
|
Components.classes["@mozilla.org/updates/update-service;1"].
|
2009-12-18 14:02:08 -08:00
|
|
|
getService(Components.interfaces.nsIApplicationUpdateService);
|
2007-03-22 10:30:00 -07:00
|
|
|
var um =
|
|
|
|
Components.classes["@mozilla.org/updates/update-manager;1"].
|
|
|
|
getService(Components.interfaces.nsIUpdateManager);
|
|
|
|
|
|
|
|
// Disable the UI if the update enabled pref has been locked by the
|
|
|
|
// administrator or if we cannot update for some other reason
|
|
|
|
var checkForUpdates = document.getElementById("checkForUpdates");
|
2009-11-18 21:50:05 -08:00
|
|
|
var canCheckForUpdates = updates.canCheckForUpdates;
|
|
|
|
checkForUpdates.setAttribute("disabled", !canCheckForUpdates);
|
|
|
|
if (!canCheckForUpdates)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
var strings = document.getElementById("bundle_browser");
|
|
|
|
var activeUpdate = um.activeUpdate;
|
|
|
|
|
|
|
|
// If there's an active update, substitute its name into the label
|
|
|
|
// we show for this item, otherwise display a generic label.
|
|
|
|
function getStringWithUpdateName(key) {
|
|
|
|
if (activeUpdate && activeUpdate.name)
|
|
|
|
return strings.getFormattedString(key, [activeUpdate.name]);
|
|
|
|
return strings.getString(key + "Fallback");
|
|
|
|
}
|
|
|
|
|
|
|
|
// By default, show "Check for Updates..."
|
|
|
|
var key = "default";
|
|
|
|
if (activeUpdate) {
|
|
|
|
switch (activeUpdate.state) {
|
|
|
|
case "downloading":
|
|
|
|
// If we're downloading an update at present, show the text:
|
|
|
|
// "Downloading Firefox x.x..." otherwise we're paused, and show
|
|
|
|
// "Resume Downloading Firefox x.x..."
|
|
|
|
key = updates.isDownloading ? "downloading" : "resume";
|
|
|
|
break;
|
|
|
|
case "pending":
|
|
|
|
// If we're waiting for the user to restart, show: "Apply Downloaded
|
|
|
|
// Updates Now..."
|
|
|
|
key = "pending";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkForUpdates.label = getStringWithUpdateName("updatesItem_" + key);
|
2009-04-11 01:46:01 -07:00
|
|
|
checkForUpdates.accessKey = strings.getString("updatesItem_" + key + ".accesskey");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (um.activeUpdate && updates.isDownloading)
|
|
|
|
checkForUpdates.setAttribute("loading", "true");
|
|
|
|
else
|
|
|
|
checkForUpdates.removeAttribute("loading");
|
2008-11-26 00:45:24 -08:00
|
|
|
#else
|
|
|
|
// Needed by safebrowsing for inserting its menuitem so just hide it
|
|
|
|
document.getElementById("updateSeparator").hidden = true;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function isElementVisible(aElement)
|
|
|
|
{
|
2007-10-08 13:17:14 -07:00
|
|
|
if (!aElement)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If aElement or a direct or indirect parent is hidden or collapsed,
|
|
|
|
// height, width or both will be 0.
|
2007-03-22 10:30:00 -07:00
|
|
|
var bo = aElement.boxObject;
|
2007-10-08 13:17:14 -07:00
|
|
|
return (bo.height > 0 && bo.width > 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-17 10:27:23 -08:00
|
|
|
function makeURLAbsolute(aBase, aUrl)
|
|
|
|
{
|
2008-02-01 16:39:05 -08:00
|
|
|
// Note: makeURI() will throw if aUri is not a valid URI
|
|
|
|
return makeURI(aUrl, null, makeURI(aBase)).spec;
|
2007-12-17 10:27:23 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07: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-25 22:18:47 -07:00
|
|
|
* @param [optional] aReferrer
|
|
|
|
* If aDocument is null, then this will be used as the referrer.
|
|
|
|
* There will be no security check.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
function openNewTabWith(aURL, aDocument, aPostData, aEvent,
|
2007-08-25 22:18:47 -07:00
|
|
|
aAllowThirdPartyFixup, aReferrer)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aDocument)
|
|
|
|
urlSecurityCheck(aURL, aDocument.nodePrincipal);
|
|
|
|
|
2010-01-28 10:31:45 -08:00
|
|
|
var loadInBackground = getBoolPref("browser.tabs.loadInBackground");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aEvent && aEvent.shiftKey)
|
|
|
|
loadInBackground = !loadInBackground;
|
|
|
|
|
|
|
|
// As in openNewWindowWith(), we want to pass the charset of the
|
|
|
|
// current document over to a new tab.
|
|
|
|
var wintype = document.documentElement.getAttribute("windowtype");
|
|
|
|
var originCharset;
|
|
|
|
if (wintype == "navigator:browser")
|
|
|
|
originCharset = window.content.document.characterSet;
|
|
|
|
|
|
|
|
// open link in new tab
|
2007-08-25 22:18:47 -07:00
|
|
|
var referrerURI = aDocument ? aDocument.documentURIObject : aReferrer;
|
2007-03-22 10:30:00 -07:00
|
|
|
var browser = top.document.getElementById("content");
|
2009-09-17 06:03:15 -07:00
|
|
|
return browser.loadOneTab(aURL, {
|
|
|
|
referrerURI: referrerURI,
|
|
|
|
charset: originCharset,
|
|
|
|
postData: aPostData,
|
|
|
|
inBackground: loadInBackground,
|
|
|
|
allowThirdPartyFixup: aAllowThirdPartyFixup});
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-25 22:18:47 -07:00
|
|
|
function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup,
|
|
|
|
aReferrer)
|
2007-03-22 10:30:00 -07: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...
|
|
|
|
var charsetArg = null;
|
|
|
|
var wintype = document.documentElement.getAttribute("windowtype");
|
|
|
|
if (wintype == "navigator:browser")
|
|
|
|
charsetArg = "charset=" + window.content.document.characterSet;
|
|
|
|
|
2007-08-25 22:18:47 -07:00
|
|
|
var referrerURI = aDocument ? aDocument.documentURIObject : aReferrer;
|
2008-04-08 11:45:08 -07:00
|
|
|
return window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no",
|
|
|
|
aURL, charsetArg, referrerURI, aPostData,
|
|
|
|
aAllowThirdPartyFixup);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-06-24 04:26:18 -07:00
|
|
|
|
|
|
|
/**
|
2007-10-02 10:54:35 -07:00
|
|
|
* isValidFeed: checks whether the given data represents a valid feed.
|
2007-06-24 04:26:18 -07:00
|
|
|
*
|
2008-09-06 19:28:36 -07:00
|
|
|
* @param aLink
|
2007-10-02 10:54:35 -07:00
|
|
|
* An object representing a feed with title, href and type.
|
2007-06-24 04:26:18 -07:00
|
|
|
* @param aPrincipal
|
|
|
|
* The principal of the document, used for security check.
|
2007-10-02 10:54:35 -07:00
|
|
|
* @param aIsFeed
|
|
|
|
* Whether this is already a known feed or not, if true only a security
|
|
|
|
* check will be performed.
|
2007-06-24 04:26:18 -07:00
|
|
|
*/
|
2008-09-06 19:28:36 -07:00
|
|
|
function isValidFeed(aLink, aPrincipal, aIsFeed)
|
2007-06-24 04:26:18 -07:00
|
|
|
{
|
2008-09-06 19:28:36 -07:00
|
|
|
if (!aLink || !aPrincipal)
|
2007-10-02 10:54:35 -07:00
|
|
|
return false;
|
|
|
|
|
2008-09-06 19:28:36 -07:00
|
|
|
var type = aLink.type.toLowerCase().replace(/^\s+|\s*(?:;.*)?$/g, "");
|
2007-10-02 10:54:35 -07:00
|
|
|
if (!aIsFeed) {
|
|
|
|
aIsFeed = (type == "application/rss+xml" ||
|
|
|
|
type == "application/atom+xml");
|
2007-06-24 04:26:18 -07:00
|
|
|
}
|
|
|
|
|
2007-10-02 10:54:35 -07:00
|
|
|
if (aIsFeed) {
|
|
|
|
try {
|
2008-09-06 19:28:36 -07:00
|
|
|
urlSecurityCheck(aLink.href, aPrincipal,
|
2007-06-24 04:26:18 -07:00
|
|
|
Components.interfaces.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
|
2008-09-06 19:28:36 -07:00
|
|
|
return type || "application/rss+xml";
|
2007-06-24 04:26:18 -07:00
|
|
|
}
|
2007-10-02 10:54:35 -07:00
|
|
|
catch(ex) {
|
2007-06-24 04:26:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-06 19:28:36 -07:00
|
|
|
return null;
|
2007-06-24 04:26:18 -07:00
|
|
|
}
|
2008-02-26 13:13:17 -08:00
|
|
|
|
2008-03-24 10:18:38 -07: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 10:31:45 -08:00
|
|
|
var instantApply = getBoolPref("browser.preferences.instantApply");
|
2008-03-24 10:18:38 -07:00
|
|
|
|
|
|
|
var helpTopic = document.getElementsByTagName("prefwindow")[0].currentPane.helpTopic;
|
|
|
|
openHelpLink(helpTopic, !instantApply);
|
|
|
|
}
|