2006-09-14 09:59:50 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2006-09-14 10:09:07 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-07-02 02:56:04 +04:00
|
|
|
*
|
2006-09-14 10:09:07 +04:00
|
|
|
* 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/
|
1999-07-02 02:56:04 +04:00
|
|
|
*
|
2006-09-14 09:59:50 +04:00
|
|
|
* 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.
|
1999-07-02 02:56:04 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2006-09-14 10:09:07 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2006-09-14 09:59:50 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2006-09-14 09:55:08 +04:00
|
|
|
* Contributor(s):
|
|
|
|
* Blake Ross <blakeross@telocity.com>
|
|
|
|
* Peter Annema <disttsc@bart.nl>
|
2006-09-14 10:04:27 +04:00
|
|
|
* Dean Tessman <dean_tessman@hotmail.com>
|
2006-09-14 09:59:50 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2006-09-14 10:09:07 +04:00
|
|
|
* either of 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"),
|
2006-09-14 09:59:50 +04:00
|
|
|
* 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
|
2006-09-14 10:09:07 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2006-09-14 09:59:50 +04:00
|
|
|
* 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
|
2006-09-14 10:09:07 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2006-09-14 09:59:50 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-07-02 02:56:04 +04:00
|
|
|
|
2006-09-14 10:10:38 +04:00
|
|
|
const REMOTESERVICE_CONTRACTID = "@mozilla.org/toolkit/remote-service;1";
|
2006-09-14 10:07:36 +04:00
|
|
|
const XUL_NAMESPACE = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
2006-09-14 09:53:12 +04:00
|
|
|
var gURLBar = null;
|
2006-09-14 09:57:38 +04:00
|
|
|
var gProxyButton = null;
|
2006-09-14 10:00:54 +04:00
|
|
|
var gProxyFavIcon = null;
|
|
|
|
var gProxyDeck = null;
|
2006-09-14 10:01:17 +04:00
|
|
|
var gBookmarksService = null;
|
2006-09-14 10:01:19 +04:00
|
|
|
var gSearchService = null;
|
2006-09-14 09:55:56 +04:00
|
|
|
var gNavigatorBundle;
|
|
|
|
var gBrandBundle;
|
2006-09-14 09:56:13 +04:00
|
|
|
var gNavigatorRegionBundle;
|
|
|
|
var gBrandRegionBundle;
|
2006-09-14 10:00:54 +04:00
|
|
|
var gLastValidURLStr = "";
|
|
|
|
var gLastValidURL = null;
|
2006-09-14 10:04:27 +04:00
|
|
|
var gClickSelectsAll = false;
|
2006-09-14 10:07:06 +04:00
|
|
|
var gClickAtEndSelects = false;
|
2006-09-14 10:04:27 +04:00
|
|
|
var gIgnoreFocus = false;
|
2006-09-14 10:04:29 +04:00
|
|
|
var gIgnoreClick = false;
|
2006-09-14 10:05:12 +04:00
|
|
|
var gURIFixup = null;
|
1999-11-16 07:50:32 +03:00
|
|
|
|
2006-09-14 10:00:34 +04:00
|
|
|
var pref = null;
|
1999-11-16 07:50:32 +03:00
|
|
|
|
2006-09-14 09:55:08 +04:00
|
|
|
var appCore = null;
|
2006-09-14 09:48:04 +04:00
|
|
|
|
2006-09-14 09:57:07 +04:00
|
|
|
//cached elements
|
2006-09-14 09:56:01 +04:00
|
|
|
var gBrowser = null;
|
2006-09-14 09:50:25 +04:00
|
|
|
|
|
|
|
// focused frame URL
|
|
|
|
var gFocusedURL = null;
|
2006-09-14 10:01:45 +04:00
|
|
|
var gFocusedDocument = null;
|
2006-09-14 09:50:25 +04:00
|
|
|
|
2006-09-14 10:03:31 +04:00
|
|
|
// Pref listener constants
|
|
|
|
const gButtonPrefListener =
|
|
|
|
{
|
|
|
|
domain: "browser.toolbars.showbutton",
|
2006-09-14 10:08:55 +04:00
|
|
|
init: function()
|
|
|
|
{
|
|
|
|
var array = pref.getChildList(this.domain, {});
|
|
|
|
for (var i in array)
|
2006-09-14 10:08:56 +04:00
|
|
|
this.updateButton(array[i]);
|
|
|
|
this.updateSeparator();
|
2006-09-14 10:08:55 +04:00
|
|
|
},
|
2006-09-14 10:03:31 +04:00
|
|
|
observe: function(subject, topic, prefName)
|
|
|
|
{
|
|
|
|
// verify that we're changing a button pref
|
|
|
|
if (topic != "nsPref:changed")
|
|
|
|
return;
|
|
|
|
|
2006-09-14 10:08:56 +04:00
|
|
|
this.updateButton(prefName);
|
|
|
|
this.updateSeparator();
|
|
|
|
},
|
|
|
|
updateButton: function(prefName)
|
|
|
|
{
|
2006-09-14 10:03:31 +04:00
|
|
|
var buttonName = prefName.substr(this.domain.length+1);
|
|
|
|
var buttonId = buttonName + "-button";
|
|
|
|
var button = document.getElementById(buttonId);
|
2006-09-14 10:08:56 +04:00
|
|
|
if (button)
|
|
|
|
button.hidden = !pref.getBoolPref(prefName);
|
|
|
|
},
|
|
|
|
updateSeparator: function()
|
|
|
|
{
|
2006-09-14 10:03:31 +04:00
|
|
|
// If all buttons before the separator are hidden, also hide the separator
|
2006-09-14 10:08:56 +04:00
|
|
|
var separator = document.getElementById("home-bm-separator");
|
|
|
|
separator.hidden = allLeftButtonsAreHidden();
|
2006-09-14 10:03:31 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const gTabStripPrefListener =
|
|
|
|
{
|
|
|
|
domain: "browser.tabs.autoHide",
|
|
|
|
observe: function(subject, topic, prefName)
|
|
|
|
{
|
|
|
|
// verify that we're changing the tab browser strip auto hide pref
|
|
|
|
if (topic != "nsPref:changed")
|
|
|
|
return;
|
|
|
|
|
2006-09-14 10:10:57 +04:00
|
|
|
if (gBrowser.tabContainer.childNodes.length == 1 && window.toolbar.visible) {
|
|
|
|
var stripVisibility = !pref.getBoolPref(prefName);
|
2006-09-14 10:03:31 +04:00
|
|
|
gBrowser.setStripVisibilityTo(stripVisibility);
|
2006-09-14 10:04:26 +04:00
|
|
|
pref.setBoolPref("browser.tabs.forceHide", false);
|
|
|
|
}
|
2006-09-14 10:03:31 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-09-14 10:05:11 +04:00
|
|
|
const gHomepagePrefListener =
|
|
|
|
{
|
|
|
|
domain: "browser.startup.homepage",
|
|
|
|
observe: function(subject, topic, prefName)
|
|
|
|
{
|
|
|
|
// verify that we're changing the home page pref
|
|
|
|
if (topic != "nsPref:changed")
|
|
|
|
return;
|
|
|
|
|
2006-09-14 10:06:35 +04:00
|
|
|
updateHomeButtonTooltip();
|
2006-09-14 10:05:11 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-09-14 10:05:18 +04:00
|
|
|
// popup window permission change listener
|
|
|
|
const gPopupPermListener = {
|
|
|
|
|
|
|
|
observe: function(subject, topic, data) {
|
|
|
|
if (topic == "popup-perm-close") {
|
|
|
|
// close the window if we're a popup and our opener's URI matches
|
|
|
|
// the URI in the notification
|
|
|
|
var popupOpenerURI = maybeInitPopupContext();
|
|
|
|
if (popupOpenerURI) {
|
|
|
|
const IOS = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
closeURI = IOS.newURI(data, null, null);
|
|
|
|
if (closeURI.host == popupOpenerURI.host)
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-09-14 10:07:44 +04:00
|
|
|
const POPUP_TYPE = "popup";
|
2006-09-14 10:06:48 +04:00
|
|
|
const gPopupPrefListener =
|
|
|
|
{
|
|
|
|
domain: "dom.disable_open_during_load",
|
|
|
|
observe: function(subject, topic, prefName)
|
|
|
|
{
|
|
|
|
if (topic != "nsPref:changed" || prefName != this.domain)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var browsers = getBrowser().browsers;
|
|
|
|
var policy = pref.getBoolPref(prefName);
|
|
|
|
|
2006-09-14 10:07:22 +04:00
|
|
|
if (policy && pref.getBoolPref("privacy.popups.first_popup"))
|
|
|
|
pref.setBoolPref("privacy.popups.first_popup", false);
|
|
|
|
|
2006-09-14 10:06:48 +04:00
|
|
|
var hosts = [];
|
|
|
|
|
2006-09-14 10:08:12 +04:00
|
|
|
var permManager = Components.classes["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Components.interfaces.nsIPermissionManager);
|
2006-09-14 10:06:48 +04:00
|
|
|
|
2006-09-14 10:08:12 +04:00
|
|
|
var enumerator = permManager.enumerator;
|
2006-09-14 10:06:48 +04:00
|
|
|
var count=0;
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
var permission = enumerator.getNext()
|
|
|
|
.QueryInterface(Components.interfaces.nsIPermission);
|
2006-09-14 10:08:12 +04:00
|
|
|
if (permission.type == POPUP_TYPE && permission.capability == policy)
|
2006-09-14 10:06:48 +04:00
|
|
|
hosts[permission.host] = permission.host;
|
|
|
|
}
|
|
|
|
|
|
|
|
var popupIcon = document.getElementById("popupIcon");
|
|
|
|
|
2006-09-14 10:07:22 +04:00
|
|
|
if (!policy) {
|
2006-09-14 10:06:48 +04:00
|
|
|
for (var i = 0; i < browsers.length; i++) {
|
|
|
|
if (browsers[i].popupDomain in hosts)
|
|
|
|
break;
|
|
|
|
browsers[i].popupDomain = null;
|
|
|
|
popupIcon.hidden = true;
|
|
|
|
}
|
2006-09-14 10:07:22 +04:00
|
|
|
} else {
|
2006-09-14 10:07:21 +04:00
|
|
|
for (i = 0; i < browsers.length; i++) {
|
2006-09-14 10:06:48 +04:00
|
|
|
if (browsers[i].popupDomain in hosts) {
|
|
|
|
browsers[i].popupDomain = null;
|
|
|
|
popupIcon.hidden = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-09-14 10:03:31 +04:00
|
|
|
/**
|
|
|
|
* Pref listener handler functions.
|
|
|
|
* Both functions assume that observer.domain is set to
|
|
|
|
* the pref domain we want to start/stop listening to.
|
|
|
|
*/
|
|
|
|
function addPrefListener(observer)
|
|
|
|
{
|
|
|
|
try {
|
2006-09-14 10:10:36 +04:00
|
|
|
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranch2);
|
2006-09-14 10:03:31 +04:00
|
|
|
pbi.addObserver(observer.domain, observer, false);
|
|
|
|
} catch(ex) {
|
|
|
|
dump("Failed to observe prefs: " + ex + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removePrefListener(observer)
|
|
|
|
{
|
|
|
|
try {
|
2006-09-14 10:10:36 +04:00
|
|
|
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranch2);
|
2006-09-14 10:03:31 +04:00
|
|
|
pbi.removeObserver(observer.domain, observer);
|
|
|
|
} catch(ex) {
|
|
|
|
dump("Failed to remove pref observer: " + ex + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:05:18 +04:00
|
|
|
function addPopupPermListener(observer)
|
|
|
|
{
|
|
|
|
const OS = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
OS.addObserver(observer, "popup-perm-close", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function removePopupPermListener(observer)
|
|
|
|
{
|
|
|
|
const OS = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
OS.removeObserver(observer, "popup-perm-close");
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
/**
|
2006-09-14 09:54:30 +04:00
|
|
|
* We can avoid adding multiple load event listeners and save some time by adding
|
2006-09-14 09:55:06 +04:00
|
|
|
* one listener that calls all real handlers.
|
|
|
|
*/
|
|
|
|
|
2006-09-14 10:10:49 +04:00
|
|
|
function pageShowEventHandlers(event)
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
|
|
|
// Filter out events that are not about the document load we are interested in
|
2006-09-14 10:09:37 +04:00
|
|
|
if (event.originalTarget == content.document) {
|
2006-09-14 09:55:03 +04:00
|
|
|
UpdateBookmarksLastVisitedDate(event);
|
|
|
|
UpdateInternetSearchResults(event);
|
|
|
|
checkForDirectoryListing();
|
|
|
|
postURLToNativeWidget();
|
|
|
|
}
|
|
|
|
}
|
2006-09-14 09:54:30 +04:00
|
|
|
|
2006-09-14 09:55:08 +04:00
|
|
|
/**
|
2006-09-14 09:50:25 +04:00
|
|
|
* Determine whether or not the content area is displaying a page with frames,
|
|
|
|
* and if so, toggle the display of the 'save frame as' menu item.
|
|
|
|
**/
|
|
|
|
function getContentAreaFrameCount()
|
|
|
|
{
|
2006-09-14 10:10:18 +04:00
|
|
|
var saveFrameItem = document.getElementById("saveframe");
|
2006-09-14 10:06:36 +04:00
|
|
|
if (!content || !content.frames.length || !isContentFrame(document.commandDispatcher.focusedWindow))
|
2006-09-14 09:50:25 +04:00
|
|
|
saveFrameItem.setAttribute("hidden", "true");
|
2006-09-14 10:10:18 +04:00
|
|
|
else {
|
|
|
|
var autoDownload = pref.getBoolPref("browser.download.autoDownload");
|
|
|
|
goSetMenuValue("saveframe", autoDownload ? "valueSave" : "valueSaveAs");
|
2006-09-14 09:50:25 +04:00
|
|
|
saveFrameItem.removeAttribute("hidden");
|
2006-09-14 10:10:18 +04:00
|
|
|
}
|
2006-09-14 09:50:25 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:32 +04:00
|
|
|
// When a content area frame is focused, update the focused frame URL
|
2006-09-14 09:50:25 +04:00
|
|
|
function contentAreaFrameFocus()
|
|
|
|
{
|
2006-09-14 10:11:05 +04:00
|
|
|
const focusedWindow = document.commandDispatcher.focusedWindow;
|
2006-09-14 10:11:14 +04:00
|
|
|
if (focusedWindow && focusedWindow.top == window.content) {
|
2006-09-14 10:09:12 +04:00
|
|
|
gFocusedURL = focusedWindow.location.href;
|
2006-09-14 10:01:45 +04:00
|
|
|
gFocusedDocument = focusedWindow.document;
|
2006-09-14 09:50:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:06:35 +04:00
|
|
|
function updateHomeButtonTooltip()
|
|
|
|
{
|
|
|
|
var homePage = getHomePage();
|
|
|
|
var tooltip = document.getElementById("home-button-tooltip-inner");
|
|
|
|
|
|
|
|
while (tooltip.firstChild)
|
|
|
|
tooltip.removeChild(tooltip.firstChild);
|
|
|
|
|
|
|
|
for (var i in homePage) {
|
|
|
|
var label = document.createElementNS(XUL_NAMESPACE, "label");
|
|
|
|
label.setAttribute("value", homePage[i]);
|
|
|
|
tooltip.appendChild(label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:50:25 +04:00
|
|
|
//////////////////////////////// BOOKMARKS ////////////////////////////////////
|
1999-11-22 22:55:47 +03:00
|
|
|
|
1999-09-07 12:52:22 +04:00
|
|
|
function UpdateBookmarksLastVisitedDate(event)
|
1999-08-07 00:49:16 +04:00
|
|
|
{
|
2006-09-14 10:01:35 +04:00
|
|
|
var url = getWebNavigation().currentURI.spec;
|
2006-09-14 09:55:08 +04:00
|
|
|
if (url) {
|
2006-09-14 09:55:32 +04:00
|
|
|
// if the URL is bookmarked, update its "Last Visited" date
|
2006-09-14 10:01:17 +04:00
|
|
|
if (!gBookmarksService)
|
|
|
|
gBookmarksService = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIBookmarksService);
|
2006-09-14 09:40:43 +04:00
|
|
|
|
2006-09-14 10:09:37 +04:00
|
|
|
gBookmarksService.updateLastVisitedDate(url, content.document.characterSet);
|
2006-09-14 09:55:08 +04:00
|
|
|
}
|
1999-12-19 09:53:18 +03:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:01:34 +04:00
|
|
|
function HandleBookmarkIcon(iconURL, addFlag)
|
|
|
|
{
|
2006-09-14 10:11:07 +04:00
|
|
|
var url = content.document.documentURI;
|
2006-09-14 10:01:34 +04:00
|
|
|
if (url) {
|
|
|
|
// update URL with new icon reference
|
|
|
|
if (!gBookmarksService)
|
|
|
|
gBookmarksService = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIBookmarksService);
|
2006-09-14 10:03:23 +04:00
|
|
|
if (addFlag) gBookmarksService.updateBookmarkIcon(url, iconURL);
|
|
|
|
else gBookmarksService.removeBookmarkIcon(url, iconURL);
|
2006-09-14 10:01:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:08 +04:00
|
|
|
function UpdateInternetSearchResults(event)
|
2006-09-14 09:47:52 +04:00
|
|
|
{
|
2006-09-14 10:01:35 +04:00
|
|
|
var url = getWebNavigation().currentURI.spec;
|
2006-09-14 10:11:25 +04:00
|
|
|
if (url && isSearchPanelOpen())
|
|
|
|
{
|
|
|
|
if (!gSearchService)
|
|
|
|
gSearchService = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
|
|
|
|
.getService(Components.interfaces.nsIInternetSearchService);
|
2006-09-14 09:47:52 +04:00
|
|
|
|
2006-09-14 10:11:25 +04:00
|
|
|
gSearchService.FindInternetSearchResults(url);
|
2006-09-14 09:55:08 +04:00
|
|
|
}
|
2006-09-14 09:47:52 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:02 +04:00
|
|
|
function getBrowser()
|
|
|
|
{
|
2006-09-14 09:56:01 +04:00
|
|
|
if (!gBrowser)
|
|
|
|
gBrowser = document.getElementById("content");
|
|
|
|
return gBrowser;
|
2006-09-14 09:55:02 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
function getHomePage()
|
|
|
|
{
|
2006-09-14 10:06:35 +04:00
|
|
|
var URIs = [];
|
2006-09-14 09:55:03 +04:00
|
|
|
try {
|
2006-09-14 10:06:35 +04:00
|
|
|
URIs[0] = pref.getComplexValue("browser.startup.homepage",
|
|
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
|
|
|
var count = pref.getIntPref("browser.startup.homepage.count");
|
|
|
|
for (var i = 1; i < count; ++i) {
|
|
|
|
URIs[i] = pref.getComplexValue("browser.startup.homepage."+i,
|
|
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:06:35 +04:00
|
|
|
return URIs;
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:48:04 +04:00
|
|
|
function UpdateBackForwardButtons()
|
|
|
|
{
|
2006-09-14 09:55:03 +04:00
|
|
|
var backBroadcaster = document.getElementById("canGoBack");
|
|
|
|
var forwardBroadcaster = document.getElementById("canGoForward");
|
2006-09-14 10:11:27 +04:00
|
|
|
var upBroadcaster = document.getElementById("canGoUp");
|
2006-09-14 10:07:36 +04:00
|
|
|
var browser = getBrowser();
|
2006-09-14 09:55:03 +04:00
|
|
|
|
2006-09-14 09:57:15 +04:00
|
|
|
// Avoid setting attributes on broadcasters if the value hasn't changed!
|
|
|
|
// Remember, guys, setting attributes on elements is expensive! They
|
|
|
|
// get inherited into anonymous content, broadcast to other widgets, etc.!
|
|
|
|
// Don't do it if the value hasn't changed! - dwh
|
|
|
|
|
2006-09-14 10:01:44 +04:00
|
|
|
var backDisabled = backBroadcaster.hasAttribute("disabled");
|
|
|
|
var forwardDisabled = forwardBroadcaster.hasAttribute("disabled");
|
2006-09-14 10:11:27 +04:00
|
|
|
var upDisabled = upBroadcaster.hasAttribute("disabled");
|
2006-09-14 10:07:36 +04:00
|
|
|
if (backDisabled == browser.canGoBack) {
|
2006-09-14 10:01:44 +04:00
|
|
|
if (backDisabled)
|
|
|
|
backBroadcaster.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
backBroadcaster.setAttribute("disabled", true);
|
|
|
|
}
|
2006-09-14 10:07:36 +04:00
|
|
|
if (forwardDisabled == browser.canGoForward) {
|
2006-09-14 10:01:44 +04:00
|
|
|
if (forwardDisabled)
|
|
|
|
forwardBroadcaster.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
forwardBroadcaster.setAttribute("disabled", true);
|
|
|
|
}
|
2006-09-14 10:11:27 +04:00
|
|
|
if (upDisabled != !browser.currentURI.spec.replace(/[#?].*$/, "").match(/\/[^\/]+\/./)) {
|
|
|
|
if (upDisabled)
|
|
|
|
upBroadcaster.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
upBroadcaster.setAttribute("disabled", true);
|
|
|
|
}
|
2006-09-14 09:48:04 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:59:35 +04:00
|
|
|
// Function allLeftButtonsAreHidden
|
|
|
|
// Returns true if all the buttons left of the separator in the personal
|
|
|
|
// toolbar are hidden, false otherwise.
|
|
|
|
// Used by nsButtonPrefListener to hide the separator if needed
|
2006-09-14 09:59:51 +04:00
|
|
|
function allLeftButtonsAreHidden()
|
|
|
|
{
|
2006-09-14 10:06:50 +04:00
|
|
|
var buttonNode = document.getElementById("home-bm-separator").previousSibling;
|
|
|
|
while (buttonNode) {
|
|
|
|
if (buttonNode.localName != "tooltip" && !buttonNode.hidden)
|
2006-09-14 09:59:35 +04:00
|
|
|
return false;
|
2006-09-14 10:06:50 +04:00
|
|
|
buttonNode = buttonNode.previousSibling;
|
2006-09-14 09:55:38 +04:00
|
|
|
}
|
2006-09-14 09:59:35 +04:00
|
|
|
return true;
|
2006-09-14 09:55:38 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:08:17 +04:00
|
|
|
const gTabOpenObserver = {
|
|
|
|
observe: function(subject, topic, data)
|
|
|
|
{
|
|
|
|
if (topic != "open-new-tab-request" || subject != window)
|
|
|
|
return;
|
2006-09-14 10:04:20 +04:00
|
|
|
|
2006-09-14 10:08:17 +04:00
|
|
|
delayedOpenTab(data);
|
|
|
|
}
|
|
|
|
};
|
2006-09-14 10:04:20 +04:00
|
|
|
|
2006-09-14 10:10:34 +04:00
|
|
|
const nsIBrowserDOMWindow = Components.interfaces.nsIBrowserDOMWindow;
|
|
|
|
const nsIInterfaceRequestor = Components.interfaces.nsIInterfaceRequestor;
|
|
|
|
|
|
|
|
function nsBrowserAccess() {
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBrowserAccess.prototype = {
|
|
|
|
openURI: function openURI(aURI, aOpener, aWhere, aContext) {
|
2006-09-14 10:11:11 +04:00
|
|
|
var loadflags = aContext == nsIBrowserDOMWindow.OPEN_EXTERNAL ?
|
|
|
|
nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL :
|
|
|
|
nsIWebNavigation.LOAD_FLAGS_NONE;
|
2006-09-14 10:10:51 +04:00
|
|
|
|
2006-09-14 10:10:34 +04:00
|
|
|
if (aWhere == nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW)
|
|
|
|
if (aContext == nsIBrowserDOMWindow.OPEN_EXTERNAL)
|
|
|
|
aWhere = pref.getIntPref("browser.link.open_external");
|
|
|
|
else
|
|
|
|
aWhere = pref.getIntPref("browser.link.open_newwindow");
|
|
|
|
var uri = aURI ? aURI.spec : "about:blank";
|
|
|
|
var referrer = aOpener ? aOpener.QueryInterface(nsIInterfaceRequestor)
|
|
|
|
.getInterface(nsIWebNavigation)
|
|
|
|
.currentURI : null;
|
|
|
|
switch (aWhere) {
|
|
|
|
case nsIBrowserDOMWindow.OPEN_NEWWINDOW:
|
|
|
|
return window.openDialog(getBrowserURL(), "_blank", "all,dialog=no",
|
|
|
|
uri, null, referrer);
|
|
|
|
case nsIBrowserDOMWindow.OPEN_NEWTAB:
|
2006-09-14 10:11:30 +04:00
|
|
|
var newTab = gBrowser.addTab("about:blank", null, null,
|
|
|
|
!pref.getBoolPref("browser.tabs.loadDivertedInBackground"));
|
2006-09-14 10:10:34 +04:00
|
|
|
var browser = gBrowser.getBrowserForTab(newTab);
|
|
|
|
try {
|
2006-09-14 10:10:50 +04:00
|
|
|
browser.loadURIWithFlags(uri, loadflags, referrer);
|
2006-09-14 10:10:34 +04:00
|
|
|
} catch (e) {}
|
|
|
|
return browser.contentWindow;
|
|
|
|
default:
|
|
|
|
if (!aOpener) {
|
2006-09-14 10:10:52 +04:00
|
|
|
gBrowser.loadURIWithFlags(uri, loadflags);
|
2006-09-14 10:10:34 +04:00
|
|
|
return content;
|
|
|
|
}
|
2006-09-14 10:11:22 +04:00
|
|
|
aOpener = aOpener.top;
|
2006-09-14 10:10:34 +04:00
|
|
|
try {
|
|
|
|
aOpener.QueryInterface(nsIInterfaceRequestor)
|
|
|
|
.getInterface(nsIWebNavigation)
|
2006-09-14 10:10:50 +04:00
|
|
|
.loadURI(uri, loadflags, referrer, null, null);
|
2006-09-14 10:10:34 +04:00
|
|
|
} catch (e) {}
|
|
|
|
return aOpener;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isTabContentWindow: function isTabContentWindow(aWindow) {
|
|
|
|
var browsers = gBrowser.browsers;
|
|
|
|
for (var i = 0; browsers.item(i); i++)
|
|
|
|
if (browsers[i].contentWindow == aWindow)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:47:51 +04:00
|
|
|
function Startup()
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 09:56:43 +04:00
|
|
|
// init globals
|
2006-09-14 09:55:56 +04:00
|
|
|
gNavigatorBundle = document.getElementById("bundle_navigator");
|
|
|
|
gBrandBundle = document.getElementById("bundle_brand");
|
2006-09-14 09:56:13 +04:00
|
|
|
gNavigatorRegionBundle = document.getElementById("bundle_navigator_region");
|
|
|
|
gBrandRegionBundle = document.getElementById("bundle_brand_region");
|
2006-09-14 09:55:56 +04:00
|
|
|
|
2006-09-14 09:56:44 +04:00
|
|
|
gBrowser = document.getElementById("content");
|
2006-09-14 09:56:43 +04:00
|
|
|
gURLBar = document.getElementById("urlbar");
|
2006-09-14 09:57:38 +04:00
|
|
|
|
2006-09-14 10:00:54 +04:00
|
|
|
SetPageProxyState("invalid", null);
|
2006-09-14 09:56:43 +04:00
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
var webNavigation;
|
|
|
|
try {
|
2006-09-14 09:44:15 +04:00
|
|
|
// Create the browser instance component.
|
2006-09-14 09:55:03 +04:00
|
|
|
appCore = Components.classes["@mozilla.org/appshell/component/browser/instance;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIBrowserInstance);
|
|
|
|
if (!appCore)
|
2006-09-14 09:59:53 +04:00
|
|
|
throw "couldn't create a browser instance";
|
2006-09-14 09:55:03 +04:00
|
|
|
|
2006-09-14 10:00:34 +04:00
|
|
|
// Get the preferences service
|
|
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
|
|
pref = prefService.getBranch(null);
|
|
|
|
|
2006-09-14 10:07:42 +04:00
|
|
|
window.tryToClose = WindowIsClosing;
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
webNavigation = getWebNavigation();
|
|
|
|
if (!webNavigation)
|
2006-09-14 09:59:53 +04:00
|
|
|
throw "no XBL binding for browser";
|
2006-09-14 09:55:03 +04:00
|
|
|
} catch (e) {
|
2006-09-14 09:59:53 +04:00
|
|
|
alert("Error launching browser window:" + e);
|
2006-09-14 09:55:03 +04:00
|
|
|
window.close(); // Give up.
|
2006-09-14 09:55:24 +04:00
|
|
|
return;
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:50:32 +04:00
|
|
|
|
2006-09-14 09:56:44 +04:00
|
|
|
// Do all UI building here:
|
|
|
|
|
2006-09-14 10:08:55 +04:00
|
|
|
// Ensure button visibility matches prefs
|
|
|
|
gButtonPrefListener.init();
|
|
|
|
|
2006-09-14 09:56:44 +04:00
|
|
|
// set home button tooltip text
|
2006-09-14 10:06:35 +04:00
|
|
|
updateHomeButtonTooltip();
|
2006-09-14 09:56:44 +04:00
|
|
|
|
2006-09-14 09:56:43 +04:00
|
|
|
// initialize observers and listeners
|
2006-09-14 09:57:07 +04:00
|
|
|
window.XULBrowserWindow = new nsBrowserStatusHandler();
|
2006-09-14 10:09:56 +04:00
|
|
|
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIWebNavigation)
|
|
|
|
.QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
|
|
|
|
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIXULWindow)
|
|
|
|
.XULBrowserWindow = window.XULBrowserWindow;
|
2006-09-14 10:03:31 +04:00
|
|
|
|
|
|
|
addPrefListener(gButtonPrefListener);
|
|
|
|
addPrefListener(gTabStripPrefListener);
|
2006-09-14 10:05:11 +04:00
|
|
|
addPrefListener(gHomepagePrefListener);
|
2006-09-14 10:05:18 +04:00
|
|
|
addPopupPermListener(gPopupPermListener);
|
2006-09-14 10:07:22 +04:00
|
|
|
addPrefListener(gPopupPrefListener);
|
2006-09-14 09:56:43 +04:00
|
|
|
|
2006-09-14 09:57:40 +04:00
|
|
|
window.browserContentListener =
|
|
|
|
new nsBrowserContentListener(window, getBrowser());
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
// Initialize browser instance..
|
|
|
|
appCore.setWebShellWindow(window);
|
2006-09-14 09:55:08 +04:00
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
// Add a capturing event listener to the content area
|
|
|
|
// (rjc note: not the entire window, otherwise we'll get sidebar pane loads too!)
|
|
|
|
// so we'll be notified when onloads complete.
|
|
|
|
var contentArea = document.getElementById("appcontent");
|
2006-09-14 10:10:59 +04:00
|
|
|
contentArea.addEventListener("pageshow", pageShowEventHandlers, true);
|
2006-09-14 09:55:03 +04:00
|
|
|
contentArea.addEventListener("focus", contentAreaFrameFocus, true);
|
|
|
|
|
2006-09-14 09:58:28 +04:00
|
|
|
var turboMode = false;
|
2006-09-14 09:55:03 +04:00
|
|
|
// set default character set if provided
|
2006-09-14 09:56:15 +04:00
|
|
|
if ("arguments" in window && window.arguments.length > 1 && window.arguments[1]) {
|
2006-09-14 09:55:03 +04:00
|
|
|
if (window.arguments[1].indexOf("charset=") != -1) {
|
|
|
|
var arrayArgComponents = window.arguments[1].split("=");
|
|
|
|
if (arrayArgComponents) {
|
|
|
|
//we should "inherit" the charset menu setting in a new window
|
2006-09-14 10:02:22 +04:00
|
|
|
getMarkupDocumentViewer().defaultCharacterSet = arrayArgComponents[1];
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:58:28 +04:00
|
|
|
} else if (window.arguments[1].indexOf("turbo=yes") != -1) {
|
2006-09-14 10:02:22 +04:00
|
|
|
turboMode = true;
|
2006-09-14 09:50:51 +04:00
|
|
|
}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:54:28 +04:00
|
|
|
|
2006-09-14 09:55:34 +04:00
|
|
|
//initConsoleListener();
|
|
|
|
|
2006-09-14 09:56:43 +04:00
|
|
|
// hook up UI through progress listener
|
2006-09-14 10:04:17 +04:00
|
|
|
getBrowser().addProgressListener(window.XULBrowserWindow, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
|
2006-09-14 09:56:40 +04:00
|
|
|
|
2006-09-14 09:55:26 +04:00
|
|
|
// load appropriate initial page from commandline
|
2006-09-14 09:55:34 +04:00
|
|
|
var isPageCycling = false;
|
1999-07-14 04:03:57 +04:00
|
|
|
|
2006-09-14 09:55:26 +04:00
|
|
|
// page cycling for tinderbox tests
|
|
|
|
if (!appCore.cmdLineURLUsed)
|
|
|
|
isPageCycling = appCore.startPageCycler();
|
2006-09-14 09:55:03 +04:00
|
|
|
|
2006-09-14 09:55:26 +04:00
|
|
|
// only load url passed in when we're not page cycling
|
|
|
|
if (!isPageCycling) {
|
2006-09-14 10:07:10 +04:00
|
|
|
var uriToLoad = "";
|
2006-09-14 09:55:34 +04:00
|
|
|
|
2006-09-14 10:07:37 +04:00
|
|
|
// Check window.arguments[0]. If not null then use it for uriArray
|
|
|
|
// otherwise the new window is being called when another browser
|
|
|
|
// window already exists so use the New Window pref for uriArray
|
|
|
|
if ("arguments" in window && window.arguments.length >= 1) {
|
|
|
|
var uriArray;
|
|
|
|
if (window.arguments[0]) {
|
|
|
|
uriArray = window.arguments[0].toString().split('\n'); // stringify and split
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
switch (pref.getIntPref("browser.windows.loadOnNewWindow"))
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
var handler = Components.classes['@mozilla.org/commandlinehandler/general-startup;1?type=browser']
|
|
|
|
.getService(Components.interfaces.nsICmdLineHandler);
|
|
|
|
uriArray = handler.defaultArgs.split('\n');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
uriArray = ["about:blank"];
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
uriArray = getHomePage();
|
|
|
|
break;
|
|
|
|
case 2:
|
2006-09-14 10:08:20 +04:00
|
|
|
var history = Components.classes["@mozilla.org/browser/global-history;2"]
|
2006-09-14 10:07:38 +04:00
|
|
|
.getService(Components.interfaces.nsIBrowserHistory);
|
2006-09-14 10:07:37 +04:00
|
|
|
uriArray = [history.lastPageVisited];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
uriArray = ["about:blank"];
|
|
|
|
}
|
|
|
|
}
|
2006-09-14 10:06:37 +04:00
|
|
|
uriToLoad = uriArray.splice(0, 1)[0];
|
2006-09-14 10:07:09 +04:00
|
|
|
|
2006-09-14 10:06:35 +04:00
|
|
|
if (uriArray.length > 0)
|
|
|
|
window.setTimeout(function(arg) { for (var i in arg) gBrowser.addTab(arg[i]); }, 0, uriArray);
|
|
|
|
}
|
2006-09-14 09:59:00 +04:00
|
|
|
|
2006-09-14 10:07:10 +04:00
|
|
|
if (/^\s*$/.test(uriToLoad))
|
|
|
|
uriToLoad = "about:blank";
|
|
|
|
|
2006-09-14 10:10:19 +04:00
|
|
|
var browser = getBrowser();
|
|
|
|
browser.popupDomain = null;
|
|
|
|
browser.popupUrls = [];
|
|
|
|
browser.popupFeatures = [];
|
|
|
|
|
2006-09-14 10:07:09 +04:00
|
|
|
if (uriToLoad != "about:blank") {
|
2006-09-14 09:57:04 +04:00
|
|
|
gURLBar.value = uriToLoad;
|
2006-09-14 10:10:19 +04:00
|
|
|
browser.userTypedValue = uriToLoad;
|
2006-09-14 10:11:33 +04:00
|
|
|
if ("arguments" in window && window.arguments.length >= 4) {
|
|
|
|
loadURI(uriToLoad, window.arguments[2], window.arguments[3]);
|
|
|
|
} else if ("arguments" in window && window.arguments.length == 3) {
|
2006-09-14 10:03:57 +04:00
|
|
|
loadURI(uriToLoad, window.arguments[2]);
|
2006-09-14 10:02:24 +04:00
|
|
|
} else {
|
|
|
|
loadURI(uriToLoad);
|
|
|
|
}
|
2006-09-14 09:57:04 +04:00
|
|
|
}
|
2006-09-14 09:56:40 +04:00
|
|
|
|
2006-09-14 09:58:28 +04:00
|
|
|
// Close the window now, if it's for turbo mode startup.
|
|
|
|
if ( turboMode ) {
|
|
|
|
// Set "command line used" flag. If we don't do this, then when a cmd line url
|
|
|
|
// for a "real* invocation comes in, we will override it with the "cmd line url"
|
|
|
|
// from the turbo-mode process (i.e., the home page).
|
|
|
|
appCore.cmdLineURLUsed = true;
|
|
|
|
// For some reason, window.close() directly doesn't work, so do it in the future.
|
|
|
|
window.setTimeout( "window.close()", 100 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:08:27 +04:00
|
|
|
// Focus the content area unless we're loading a blank page, or if
|
|
|
|
// we weren't passed any arguments. This "breaks" the
|
|
|
|
// javascript:window.open(); case where we don't get any arguments
|
|
|
|
// either, but we're loading about:blank, but focusing the content
|
|
|
|
// are is arguably correct in that case as well since the opener
|
|
|
|
// is very likely to put some content in the new window, and then
|
|
|
|
// the focus should be in the content area.
|
2006-09-14 10:04:00 +04:00
|
|
|
var navBar = document.getElementById("nav-bar");
|
2006-09-14 10:08:27 +04:00
|
|
|
if ("arguments" in window && uriToLoad == "about:blank" && !navBar.hidden && window.locationbar.visible)
|
2006-09-14 10:01:48 +04:00
|
|
|
setTimeout(WindowFocusTimerCallback, 0, gURLBar);
|
2006-09-14 10:03:57 +04:00
|
|
|
else
|
2006-09-14 10:09:37 +04:00
|
|
|
setTimeout(WindowFocusTimerCallback, 0, content);
|
2006-09-14 09:56:42 +04:00
|
|
|
|
2006-09-14 10:01:51 +04:00
|
|
|
// Perform default browser checking (after window opens).
|
|
|
|
setTimeout( checkForDefaultBrowser, 0 );
|
2006-09-14 09:59:24 +04:00
|
|
|
|
2006-09-14 10:10:34 +04:00
|
|
|
// hook up browser access support
|
|
|
|
window.browserDOMWindow = new nsBrowserAccess();
|
|
|
|
|
2006-09-14 09:59:24 +04:00
|
|
|
// hook up remote support
|
2006-09-14 10:10:38 +04:00
|
|
|
if (REMOTESERVICE_CONTRACTID in Components.classes) {
|
|
|
|
var remoteService =
|
|
|
|
Components.classes[REMOTESERVICE_CONTRACTID]
|
|
|
|
.getService(Components.interfaces.nsIRemoteService);
|
|
|
|
remoteService.registerWindow(window);
|
2006-09-14 10:04:20 +04:00
|
|
|
|
2006-09-14 10:08:17 +04:00
|
|
|
var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
observerService.addObserver(gTabOpenObserver, "open-new-tab-request", false);
|
2006-09-14 09:59:24 +04:00
|
|
|
}
|
2006-09-14 09:55:34 +04:00
|
|
|
}
|
2006-09-14 10:03:18 +04:00
|
|
|
|
|
|
|
// called when we go into full screen, even if it is
|
|
|
|
// initiated by a web page script
|
2006-09-14 10:11:29 +04:00
|
|
|
addEventListener("fullscreen", onFullScreen, true);
|
2006-09-14 10:03:18 +04:00
|
|
|
|
2006-09-14 10:11:28 +04:00
|
|
|
addEventListener("PopupWindow", onPopupWindow, true);
|
|
|
|
addEventListener("DOMPopupBlocked", onPopupBlocked, true);
|
2006-09-14 10:06:48 +04:00
|
|
|
|
2006-09-14 10:04:27 +04:00
|
|
|
// does clicking on the urlbar select its contents?
|
|
|
|
gClickSelectsAll = pref.getBoolPref("browser.urlbar.clickSelectsAll");
|
2006-09-14 10:07:06 +04:00
|
|
|
gClickAtEndSelects = pref.getBoolPref("browser.urlbar.clickAtEndSelects");
|
2006-09-14 10:04:27 +04:00
|
|
|
|
2006-09-14 10:10:09 +04:00
|
|
|
// BiDi UI
|
|
|
|
gShowBiDi = isBidiEnabled();
|
|
|
|
if (gShowBiDi) {
|
|
|
|
document.getElementById("documentDirection-swap").hidden = false;
|
|
|
|
document.getElementById("textfieldDirection-separator").hidden = false;
|
|
|
|
document.getElementById("textfieldDirection-swap").hidden = false;
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:00:53 +04:00
|
|
|
// now load bookmarks after a delay
|
2006-09-14 10:01:08 +04:00
|
|
|
setTimeout(LoadBookmarksCallback, 0);
|
2006-09-14 10:00:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function LoadBookmarksCallback()
|
|
|
|
{
|
2006-09-14 10:07:21 +04:00
|
|
|
// loads the services
|
|
|
|
initServices();
|
|
|
|
initBMService();
|
2006-09-14 10:07:28 +04:00
|
|
|
BMSVC.readBookmarks();
|
2006-09-14 10:07:21 +04:00
|
|
|
var bt = document.getElementById("bookmarks-ptf");
|
2006-09-14 10:07:24 +04:00
|
|
|
if (bt) {
|
|
|
|
bt.database.AddObserver(BookmarksToolbarRDFObserver);
|
|
|
|
}
|
|
|
|
window.addEventListener("resize", BookmarksToolbar.resizeFunc, false);
|
2006-09-14 10:07:21 +04:00
|
|
|
controllers.appendController(BookmarksMenuController);
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 09:59:54 +04:00
|
|
|
function WindowFocusTimerCallback(element)
|
|
|
|
{
|
|
|
|
// This fuction is a redo of the fix for jag bug 91884
|
|
|
|
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowWatcher);
|
|
|
|
if (window == ww.activeWindow) {
|
|
|
|
element.focus();
|
|
|
|
} else {
|
|
|
|
// set the element in command dispatcher so focus will restore properly
|
|
|
|
// when the window does become active
|
2006-09-14 10:07:35 +04:00
|
|
|
|
2006-09-14 10:07:40 +04:00
|
|
|
if (element instanceof Components.interfaces.nsIDOMWindow) {
|
|
|
|
document.commandDispatcher.focusedWindow = element;
|
|
|
|
document.commandDispatcher.focusedElement = null;
|
|
|
|
} else if (element instanceof Components.interfaces.nsIDOMElement) {
|
|
|
|
document.commandDispatcher.focusedWindow = element.ownerDocument.defaultView;
|
2006-09-14 09:59:54 +04:00
|
|
|
document.commandDispatcher.focusedElement = element;
|
2006-09-14 10:07:40 +04:00
|
|
|
}
|
2006-09-14 09:59:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:59:51 +04:00
|
|
|
function BrowserFlushBookmarksAndHistory()
|
|
|
|
{
|
2006-09-14 10:03:35 +04:00
|
|
|
// Flush bookmarks and history (used when window closes or is cached).
|
2006-09-14 09:59:51 +04:00
|
|
|
try {
|
|
|
|
// If bookmarks are dirty, flush 'em to disk
|
|
|
|
var bmks = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIRDFRemoteDataSource);
|
|
|
|
bmks.Flush();
|
|
|
|
|
|
|
|
// give history a chance at flushing to disk also
|
2006-09-14 10:08:20 +04:00
|
|
|
var history = Components.classes["@mozilla.org/browser/global-history;2"]
|
2006-09-14 09:59:51 +04:00
|
|
|
.getService(Components.interfaces.nsIRDFRemoteDataSource);
|
|
|
|
history.Flush();
|
|
|
|
} catch(ex) {
|
|
|
|
}
|
2006-09-14 09:58:23 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
function Shutdown()
|
|
|
|
{
|
2006-09-14 09:59:24 +04:00
|
|
|
// remove remote support
|
2006-09-14 10:10:39 +04:00
|
|
|
if (REMOTESERVICE_CONTRACTID in Components.classes) {
|
2006-09-14 10:08:17 +04:00
|
|
|
var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
observerService.removeObserver(gTabOpenObserver, "open-new-tab-request", false);
|
2006-09-14 09:59:24 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:10:34 +04:00
|
|
|
// shut down browser access support
|
|
|
|
window.browserDOMWindow = null;
|
|
|
|
|
2006-09-14 09:56:40 +04:00
|
|
|
try {
|
2006-09-14 09:59:41 +04:00
|
|
|
getBrowser().removeProgressListener(window.XULBrowserWindow);
|
2006-09-14 09:56:40 +04:00
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:08:18 +04:00
|
|
|
var bt = document.getElementById("bookmarks-ptf");
|
|
|
|
if (bt) {
|
|
|
|
bt.database.RemoveObserver(BookmarksToolbarRDFObserver);
|
|
|
|
}
|
|
|
|
controllers.removeController(BookmarksMenuController);
|
|
|
|
|
2006-09-14 09:57:07 +04:00
|
|
|
window.XULBrowserWindow.destroy();
|
|
|
|
window.XULBrowserWindow = null;
|
2006-09-14 10:09:56 +04:00
|
|
|
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIWebNavigation)
|
|
|
|
.QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
|
|
|
|
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Components.interfaces.nsIXULWindow)
|
|
|
|
.XULBrowserWindow = null;
|
2006-09-14 09:57:07 +04:00
|
|
|
|
2006-09-14 09:58:23 +04:00
|
|
|
BrowserFlushBookmarksAndHistory();
|
1999-07-02 02:56:04 +04:00
|
|
|
|
2006-09-14 09:55:38 +04:00
|
|
|
// unregister us as a pref listener
|
2006-09-14 10:03:31 +04:00
|
|
|
removePrefListener(gButtonPrefListener);
|
|
|
|
removePrefListener(gTabStripPrefListener);
|
2006-09-14 10:05:11 +04:00
|
|
|
removePrefListener(gHomepagePrefListener);
|
2006-09-14 10:05:18 +04:00
|
|
|
removePopupPermListener(gPopupPermListener);
|
2006-09-14 10:06:48 +04:00
|
|
|
removePrefListener(gPopupPrefListener);
|
2006-09-14 09:56:42 +04:00
|
|
|
|
2006-09-14 09:57:40 +04:00
|
|
|
window.browserContentListener.close();
|
2006-09-14 09:55:03 +04:00
|
|
|
// Close the app core.
|
|
|
|
if (appCore)
|
|
|
|
appCore.close();
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
function Translate()
|
|
|
|
{
|
2006-09-14 10:08:26 +04:00
|
|
|
var service = pref.getComplexValue("browser.translation.service",
|
|
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
|
|
|
var serviceDomain = pref.getComplexValue("browser.translation.serviceDomain",
|
|
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
2006-09-14 10:01:35 +04:00
|
|
|
var targetURI = getWebNavigation().currentURI.spec;
|
1999-07-14 04:03:57 +04:00
|
|
|
|
2006-09-14 09:58:20 +04:00
|
|
|
// if we're already viewing a translated page, then just reload
|
|
|
|
if (targetURI.indexOf(serviceDomain) >= 0)
|
|
|
|
BrowserReload();
|
|
|
|
else {
|
2006-09-14 10:08:16 +04:00
|
|
|
loadURI(encodeURI(service + targetURI));
|
2006-09-14 09:58:20 +04:00
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
2006-09-14 09:44:13 +04:00
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
function gotoHistoryIndex(aEvent)
|
|
|
|
{
|
|
|
|
var index = aEvent.target.getAttribute("index");
|
2006-09-14 09:56:14 +04:00
|
|
|
if (!index)
|
|
|
|
return false;
|
2006-09-14 10:07:36 +04:00
|
|
|
|
|
|
|
if (index == "back")
|
|
|
|
gBrowser.goBackGroup();
|
|
|
|
else if (index == "forward")
|
|
|
|
gBrowser.goForwardGroup();
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
getWebNavigation().gotoIndex(index);
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-09-14 09:56:14 +04:00
|
|
|
}
|
|
|
|
return true;
|
2006-09-14 09:56:42 +04:00
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:44:13 +04:00
|
|
|
|
2006-09-14 09:50:13 +04:00
|
|
|
function BrowserBack()
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 09:56:14 +04:00
|
|
|
try {
|
2006-09-14 10:07:36 +04:00
|
|
|
getBrowser().goBack();
|
2006-09-14 09:56:42 +04:00
|
|
|
}
|
2006-09-14 09:56:14 +04:00
|
|
|
catch(ex) {
|
|
|
|
}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:44:13 +04:00
|
|
|
|
2006-09-14 10:07:34 +04:00
|
|
|
function BrowserHandleBackspace()
|
|
|
|
{
|
|
|
|
// The order of seeing keystrokes is this:
|
|
|
|
// 1) Chrome, 2) Typeahead, 3) [platform]HTMLBindings.xml
|
|
|
|
// Rather than have typeaheadfind responsible for making VK_BACK
|
|
|
|
// go back in history, we handle backspace it here as follows:
|
|
|
|
// When backspace is pressed, it might mean back
|
|
|
|
// in typeaheadfind if that's active, or it might mean back in history
|
|
|
|
|
|
|
|
var typeAhead = null;
|
2006-09-14 10:11:31 +04:00
|
|
|
const TYPE_AHEAD_FIND_CONTRACTID = "@mozilla.org/suitetypeaheadfind;1";
|
2006-09-14 10:07:34 +04:00
|
|
|
if (TYPE_AHEAD_FIND_CONTRACTID in Components.classes) {
|
|
|
|
typeAhead = Components.classes[TYPE_AHEAD_FIND_CONTRACTID]
|
2006-09-14 10:11:31 +04:00
|
|
|
.getService(Components.interfaces.nsISuiteTypeAheadFind);
|
2006-09-14 10:07:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!typeAhead || !typeAhead.backOneChar()) {
|
2006-09-14 10:10:33 +04:00
|
|
|
switch (pref.getIntPref("browser.backspace_action")) {
|
|
|
|
case 0:
|
|
|
|
BrowserBack();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
goDoCommand("cmd_scrollPageUp");
|
|
|
|
break;
|
|
|
|
}
|
2006-09-14 10:07:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:50:13 +04:00
|
|
|
function BrowserForward()
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 09:56:14 +04:00
|
|
|
try {
|
2006-09-14 10:07:36 +04:00
|
|
|
getBrowser().goForward();
|
2006-09-14 09:56:42 +04:00
|
|
|
}
|
2006-09-14 09:56:14 +04:00
|
|
|
catch(ex) {
|
|
|
|
}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:49:28 +04:00
|
|
|
|
2006-09-14 10:11:27 +04:00
|
|
|
function BrowserUp()
|
|
|
|
{
|
|
|
|
loadURI(getBrowser().currentURI.spec.replace(/[#?].*$/, "").replace(/\/[^\/]*.$/, "/"));
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:10:46 +04:00
|
|
|
function BrowserHandleShiftBackspace()
|
|
|
|
{
|
|
|
|
switch (pref.getIntPref("browser.backspace_action")) {
|
|
|
|
case 0:
|
|
|
|
BrowserForward();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
goDoCommand("cmd_scrollPageDown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:07:36 +04:00
|
|
|
function SetGroupHistory(popupMenu, direction)
|
|
|
|
{
|
|
|
|
while (popupMenu.firstChild)
|
|
|
|
popupMenu.removeChild(popupMenu.firstChild);
|
|
|
|
|
|
|
|
var menuItem = document.createElementNS(XUL_NAMESPACE, "menuitem");
|
|
|
|
var label = gNavigatorBundle.getString("tabs.historyItem");
|
|
|
|
menuItem.setAttribute("label", label);
|
|
|
|
menuItem.setAttribute("index", direction);
|
|
|
|
popupMenu.appendChild(menuItem);
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:50:13 +04:00
|
|
|
function BrowserBackMenu(event)
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 10:07:36 +04:00
|
|
|
if (gBrowser.backBrowserGroup.length != 0) {
|
|
|
|
SetGroupHistory(event.target, "back");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:59:06 +04:00
|
|
|
return FillHistoryMenu(event.target, "back");
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:49:28 +04:00
|
|
|
|
2006-09-14 09:50:13 +04:00
|
|
|
function BrowserForwardMenu(event)
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 10:07:36 +04:00
|
|
|
if (gBrowser.forwardBrowserGroup.length != 0) {
|
|
|
|
SetGroupHistory(event.target, "forward");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:59:06 +04:00
|
|
|
return FillHistoryMenu(event.target, "forward");
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
1999-07-02 02:56:04 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
function BrowserStop()
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 09:56:14 +04:00
|
|
|
try {
|
2006-09-14 09:59:21 +04:00
|
|
|
const stopFlags = nsIWebNavigation.STOP_ALL;
|
|
|
|
getWebNavigation().stop(stopFlags);
|
2006-09-14 09:56:42 +04:00
|
|
|
}
|
2006-09-14 09:56:14 +04:00
|
|
|
catch(ex) {
|
|
|
|
}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:49:47 +04:00
|
|
|
|
2006-09-14 09:56:12 +04:00
|
|
|
function BrowserReload()
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 09:56:36 +04:00
|
|
|
const reloadFlags = nsIWebNavigation.LOAD_FLAGS_NONE;
|
2006-09-14 09:57:18 +04:00
|
|
|
return BrowserReloadWithFlags(reloadFlags);
|
2006-09-14 09:56:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function BrowserReloadSkipCache()
|
|
|
|
{
|
|
|
|
// Bypass proxy and cache.
|
2006-09-14 09:56:36 +04:00
|
|
|
const reloadFlags = nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
2006-09-14 09:57:18 +04:00
|
|
|
return BrowserReloadWithFlags(reloadFlags);
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:49:08 +04:00
|
|
|
|
2006-09-14 10:10:14 +04:00
|
|
|
function BrowserHome(aEvent)
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 10:10:14 +04:00
|
|
|
var tab;
|
2006-09-14 09:55:03 +04:00
|
|
|
var homePage = getHomePage();
|
2006-09-14 10:10:15 +04:00
|
|
|
var target = aEvent ? BookmarksUtils.getBrowserTargetFromEvent(aEvent) : "current";
|
2006-09-14 10:10:14 +04:00
|
|
|
|
2006-09-14 10:06:35 +04:00
|
|
|
if (homePage.length == 1) {
|
2006-09-14 10:10:14 +04:00
|
|
|
switch (target) {
|
|
|
|
case "current":
|
|
|
|
loadURI(homePage[0]);
|
|
|
|
break;
|
|
|
|
case "tab":
|
|
|
|
tab = gBrowser.addTab(homePage[0]);
|
|
|
|
if (!BookmarksUtils.shouldLoadTabInBackground(aEvent))
|
|
|
|
gBrowser.selectedTab = tab;
|
|
|
|
break;
|
|
|
|
case "window":
|
|
|
|
openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", homePage[0]);
|
|
|
|
}
|
2006-09-14 10:06:35 +04:00
|
|
|
} else {
|
2006-09-14 10:10:14 +04:00
|
|
|
if (target == "window")
|
|
|
|
openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", homePage.join("\n"));
|
|
|
|
else {
|
|
|
|
var URIs = [];
|
|
|
|
for (var i in homePage)
|
|
|
|
URIs.push({URI: homePage[i]});
|
|
|
|
|
|
|
|
tab = gBrowser.loadGroup(URIs);
|
|
|
|
|
|
|
|
if (!BookmarksUtils.shouldLoadTabInBackground(aEvent))
|
|
|
|
gBrowser.selectedTab = tab;
|
|
|
|
}
|
2006-09-14 10:06:35 +04:00
|
|
|
}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:49:08 +04:00
|
|
|
|
2006-09-14 10:03:42 +04:00
|
|
|
function addBookmarkAs()
|
|
|
|
{
|
|
|
|
const browsers = gBrowser.browsers;
|
|
|
|
if (browsers.length > 1)
|
|
|
|
BookmarksUtils.addBookmarkForTabBrowser(gBrowser);
|
|
|
|
else
|
|
|
|
BookmarksUtils.addBookmarkForBrowser(gBrowser.webNavigation, true);
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:04:18 +04:00
|
|
|
function addGroupmarkAs()
|
|
|
|
{
|
|
|
|
BookmarksUtils.addBookmarkForTabBrowser(gBrowser, true);
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:11:21 +04:00
|
|
|
function updateGroupmarkCommand()
|
2006-09-14 10:04:18 +04:00
|
|
|
{
|
|
|
|
const disabled = gBrowser.browsers.length == 1;
|
2006-09-14 10:11:21 +04:00
|
|
|
document.getElementById("Browser:AddGroupmarkAs")
|
|
|
|
.setAttribute("disabled", disabled);
|
2006-09-14 10:04:18 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:59:51 +04:00
|
|
|
function readRDFString(aDS,aRes,aProp)
|
|
|
|
{
|
|
|
|
var n = aDS.GetTarget(aRes, aProp, true);
|
|
|
|
return n ? n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : "";
|
2006-09-14 09:57:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function ensureDefaultEnginePrefs(aRDF,aDS)
|
2006-09-14 09:59:51 +04:00
|
|
|
{
|
2006-09-14 10:00:39 +04:00
|
|
|
var mPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2006-09-14 10:00:40 +04:00
|
|
|
var defaultName = mPrefs.getComplexValue("browser.search.defaultenginename", Components.interfaces.nsIPrefLocalizedString).data;
|
2006-09-14 09:59:51 +04:00
|
|
|
var kNC_Root = aRDF.GetResource("NC:SearchEngineRoot");
|
|
|
|
var kNC_child = aRDF.GetResource("http://home.netscape.com/NC-rdf#child");
|
|
|
|
var kNC_Name = aRDF.GetResource("http://home.netscape.com/NC-rdf#Name");
|
2006-09-14 09:57:52 +04:00
|
|
|
|
2006-09-14 09:59:51 +04:00
|
|
|
var arcs = aDS.GetTargets(kNC_Root, kNC_child, true);
|
|
|
|
while (arcs.hasMoreElements()) {
|
|
|
|
var engineRes = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
|
|
|
|
var name = readRDFString(aDS, engineRes, kNC_Name);
|
|
|
|
if (name == defaultName)
|
|
|
|
mPrefs.setCharPref("browser.search.defaultengine", engineRes.Value);
|
2006-09-14 09:57:52 +04:00
|
|
|
}
|
2006-09-14 09:59:51 +04:00
|
|
|
}
|
2006-09-14 09:57:52 +04:00
|
|
|
|
2006-09-14 09:59:51 +04:00
|
|
|
function ensureSearchPref()
|
|
|
|
{
|
|
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
|
|
|
|
var ds = rdf.GetDataSource("rdf:internetsearch");
|
2006-09-14 10:00:39 +04:00
|
|
|
var mPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2006-09-14 10:03:59 +04:00
|
|
|
var kNC_Name = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
|
|
|
|
var defaultEngine;
|
2006-09-14 09:59:51 +04:00
|
|
|
try {
|
|
|
|
defaultEngine = mPrefs.getCharPref("browser.search.defaultengine");
|
|
|
|
} catch(ex) {
|
|
|
|
ensureDefaultEnginePrefs(rdf, ds);
|
|
|
|
defaultEngine = mPrefs.getCharPref("browser.search.defaultengine");
|
|
|
|
}
|
|
|
|
}
|
2006-09-14 09:57:52 +04:00
|
|
|
|
2006-09-14 09:59:51 +04:00
|
|
|
function getSearchUrl(attr)
|
|
|
|
{
|
|
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
|
|
|
|
var ds = rdf.GetDataSource("rdf:internetsearch");
|
|
|
|
var kNC_Root = rdf.GetResource("NC:SearchEngineRoot");
|
2006-09-14 10:00:39 +04:00
|
|
|
var mPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2006-09-14 09:59:51 +04:00
|
|
|
var defaultEngine = mPrefs.getCharPref("browser.search.defaultengine");
|
|
|
|
var engineRes = rdf.GetResource(defaultEngine);
|
|
|
|
var prop = "http://home.netscape.com/NC-rdf#" + attr;
|
|
|
|
var kNC_attr = rdf.GetResource(prop);
|
|
|
|
var searchURL = readRDFString(ds, engineRes, kNC_attr);
|
|
|
|
return searchURL;
|
2006-09-14 09:58:19 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:04:30 +04:00
|
|
|
function QualifySearchTerm()
|
|
|
|
{
|
|
|
|
// If the text in the URL bar is the same as the currently loaded
|
|
|
|
// page's URL then treat this as an empty search term. This way
|
|
|
|
// the user is taken to the search page where s/he can enter a term.
|
2006-09-14 10:07:39 +04:00
|
|
|
if (gBrowser.userTypedValue !== null)
|
2006-09-14 10:04:30 +04:00
|
|
|
return document.getElementById("urlbar").value;
|
|
|
|
return "";
|
|
|
|
}
|
2006-09-14 09:58:19 +04:00
|
|
|
|
2006-09-14 10:11:32 +04:00
|
|
|
function OpenSearch(tabName, searchStr, newWindowOrTabFlag, reverseBackgroundPref)
|
1999-08-06 03:09:42 +04:00
|
|
|
{
|
2006-09-14 09:56:38 +04:00
|
|
|
//This function needs to be split up someday.
|
2006-09-14 09:57:41 +04:00
|
|
|
|
2006-09-14 09:55:08 +04:00
|
|
|
var autoOpenSearchPanel = false;
|
|
|
|
var defaultSearchURL = null;
|
2006-09-14 09:56:13 +04:00
|
|
|
var fallbackDefaultSearchURL = gNavigatorRegionBundle.getString("fallbackDefaultSearchURL");
|
2006-09-14 09:57:52 +04:00
|
|
|
ensureSearchPref()
|
2006-09-14 09:57:41 +04:00
|
|
|
//Check to see if search string contains "://" or "ftp." or white space.
|
2006-09-14 09:56:38 +04:00
|
|
|
//If it does treat as url and match for pattern
|
2006-09-14 09:57:41 +04:00
|
|
|
|
2006-09-14 09:59:51 +04:00
|
|
|
var urlmatch= /(:\/\/|^ftp\.)[^ \S]+$/
|
|
|
|
var forceAsURL = urlmatch.test(searchStr);
|
2006-09-14 09:56:38 +04:00
|
|
|
|
2006-09-14 09:55:08 +04:00
|
|
|
try {
|
2006-09-14 10:00:34 +04:00
|
|
|
autoOpenSearchPanel = pref.getBoolPref("browser.search.opensidebarsearchpanel");
|
|
|
|
defaultSearchURL = pref.getComplexValue("browser.search.defaulturl",
|
2006-09-14 10:00:40 +04:00
|
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
2006-09-14 09:55:08 +04:00
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:32 +04:00
|
|
|
// Fallback to a default url (one that we can get sidebar search results for)
|
2006-09-14 09:55:08 +04:00
|
|
|
if (!defaultSearchURL)
|
|
|
|
defaultSearchURL = fallbackDefaultSearchURL;
|
2006-09-14 09:56:42 +04:00
|
|
|
|
2006-09-14 10:01:31 +04:00
|
|
|
if (!searchStr) {
|
2006-09-14 10:04:24 +04:00
|
|
|
BrowserSearchInternet();
|
2006-09-14 09:55:08 +04:00
|
|
|
} else {
|
2006-09-14 09:56:42 +04:00
|
|
|
|
2006-09-14 09:59:51 +04:00
|
|
|
//Check to see if location bar field is a url
|
|
|
|
//If it is a url go to URL. A Url is "://" or "." as commented above
|
|
|
|
//Otherwise search on entry
|
|
|
|
if (forceAsURL) {
|
|
|
|
BrowserLoadURL()
|
2006-09-14 10:01:31 +04:00
|
|
|
} else {
|
2006-09-14 10:09:57 +04:00
|
|
|
if (searchStr) {
|
|
|
|
var escapedSearchStr = encodeURIComponent(searchStr);
|
|
|
|
defaultSearchURL += escapedSearchStr;
|
|
|
|
var searchDS = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
|
|
|
|
.getService(Components.interfaces.nsIInternetSearchService);
|
2006-09-14 09:59:51 +04:00
|
|
|
|
2006-09-14 10:09:57 +04:00
|
|
|
searchDS.RememberLastSearchText(escapedSearchStr);
|
|
|
|
try {
|
|
|
|
var searchEngineURI = pref.getCharPref("browser.search.defaultengine");
|
|
|
|
if (searchEngineURI) {
|
|
|
|
var searchURL = getSearchUrl("actionButton");
|
|
|
|
if (searchURL) {
|
|
|
|
defaultSearchURL = searchURL + escapedSearchStr;
|
|
|
|
} else {
|
|
|
|
searchURL = searchDS.GetInternetSearchURL(searchEngineURI, escapedSearchStr, 0, 0, {value:0});
|
|
|
|
if (searchURL)
|
|
|
|
defaultSearchURL = searchURL;
|
2006-09-14 09:58:19 +04:00
|
|
|
}
|
2006-09-14 09:55:08 +04:00
|
|
|
}
|
2006-09-14 10:09:57 +04:00
|
|
|
} catch (ex) {
|
2006-09-14 09:55:08 +04:00
|
|
|
}
|
2006-09-14 10:09:57 +04:00
|
|
|
|
2006-09-14 10:11:32 +04:00
|
|
|
if (!newWindowOrTabFlag)
|
2006-09-14 10:09:57 +04:00
|
|
|
loadURI(defaultSearchURL);
|
2006-09-14 10:11:32 +04:00
|
|
|
else if (!pref.getBoolPref("browser.search.opentabforcontextsearch"))
|
2006-09-14 10:09:57 +04:00
|
|
|
window.open(defaultSearchURL, "_blank");
|
2006-09-14 10:11:32 +04:00
|
|
|
else {
|
|
|
|
var newTab = gBrowser.addTab(defaultSearchURL);
|
|
|
|
var loadInBackground = pref.getBoolPref("browser.tabs.loadInBackground");
|
|
|
|
if (reverseBackgroundPref)
|
|
|
|
loadInBackground = !loadInBackground;
|
|
|
|
if (!loadInBackground)
|
|
|
|
gBrowser.selectedTab = newTab;
|
|
|
|
}
|
2006-09-14 09:54:29 +04:00
|
|
|
}
|
2006-09-14 09:55:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// should we try and open up the sidebar to show the "Search Results" panel?
|
|
|
|
if (autoOpenSearchPanel)
|
|
|
|
RevealSearchPanel();
|
2006-09-14 09:40:43 +04:00
|
|
|
}
|
1999-12-30 17:16:17 +03:00
|
|
|
|
2006-09-14 09:40:43 +04:00
|
|
|
function RevealSearchPanel()
|
|
|
|
{
|
2006-09-14 10:09:27 +04:00
|
|
|
// first lets check if the search panel will be shown at all
|
|
|
|
// by checking the sidebar datasource to see if there is an entry
|
|
|
|
// for the search panel, and if it is excluded for navigator or not
|
|
|
|
|
|
|
|
var searchPanelExists = false;
|
|
|
|
|
|
|
|
if (document.getElementById("urn:sidebar:panel:search")) {
|
|
|
|
var myPanel = document.getElementById("urn:sidebar:panel:search");
|
|
|
|
var panel = sidebarObj.panels.get_panel_from_header_node(myPanel);
|
|
|
|
|
|
|
|
searchPanelExists = !panel.is_excluded();
|
|
|
|
} else if (sidebarObj.never_built) {
|
|
|
|
|
|
|
|
try{
|
|
|
|
var datasource = RDF.GetDataSourceBlocking(sidebarObj.datasource_uri);
|
|
|
|
var aboutValue = RDF.GetResource("urn:sidebar:panel:search");
|
|
|
|
|
|
|
|
// check if the panel is even in the list by checking for its content
|
|
|
|
var contentProp = RDF.GetResource("http://home.netscape.com/NC-rdf#content");
|
|
|
|
var content = datasource.GetTarget(aboutValue, contentProp, true);
|
|
|
|
|
|
|
|
if (content instanceof Components.interfaces.nsIRDFLiteral){
|
|
|
|
// the search panel entry exists, now check if it is excluded
|
|
|
|
// for navigator
|
|
|
|
var excludeProp = RDF.GetResource("http://home.netscape.com/NC-rdf#exclude");
|
|
|
|
var exclude = datasource.GetTarget(aboutValue, excludeProp, true);
|
|
|
|
|
|
|
|
if (exclude instanceof Components.interfaces.nsIRDFLiteral) {
|
|
|
|
searchPanelExists = (exclude.Value.indexOf("navigator:browser") < 0);
|
|
|
|
} else {
|
|
|
|
// panel exists and no exclude set
|
|
|
|
searchPanelExists = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(e){
|
|
|
|
searchPanelExists = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (searchPanelExists) {
|
|
|
|
// make sure the sidebar is open, else SidebarSelectPanel() will fail
|
|
|
|
if (sidebar_is_hidden())
|
|
|
|
SidebarShowHide();
|
|
|
|
|
|
|
|
if (sidebar_is_collapsed())
|
|
|
|
SidebarExpandCollapse();
|
|
|
|
|
|
|
|
var searchPanel = document.getElementById("urn:sidebar:panel:search");
|
|
|
|
if (searchPanel)
|
|
|
|
SidebarSelectPanel(searchPanel, true, true); // lives in sidebarOverlay.js
|
|
|
|
}
|
1999-08-06 03:09:42 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:01:09 +04:00
|
|
|
function isSearchPanelOpen()
|
|
|
|
{
|
|
|
|
return ( !sidebar_is_hidden() &&
|
|
|
|
!sidebar_is_collapsed() &&
|
|
|
|
SidebarGetLastSelectedPanel() == "urn:sidebar:panel:search"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:04:24 +04:00
|
|
|
function BrowserSearchInternet()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var searchEngineURI = pref.getCharPref("browser.search.defaultengine");
|
|
|
|
if (searchEngineURI) {
|
|
|
|
var searchRoot = getSearchUrl("searchForm");
|
|
|
|
if (searchRoot) {
|
|
|
|
loadURI(searchRoot);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Get a search URL and guess that the front page of the site has a search form.
|
|
|
|
var searchDS = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
|
|
|
|
.getService(Components.interfaces.nsIInternetSearchService);
|
2006-09-14 10:08:24 +04:00
|
|
|
var searchURL = searchDS.GetInternetSearchURL(searchEngineURI, "ABC", 0, 0, {value:0});
|
2006-09-14 10:04:24 +04:00
|
|
|
if (searchURL) {
|
|
|
|
searchRoot = searchURL.match(/[a-z]+:\/\/[a-z.-]+/);
|
|
|
|
if (searchRoot) {
|
|
|
|
loadURI(searchRoot + "/");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback if the stuff above fails: use the hard-coded search engine
|
|
|
|
loadURI(gNavigatorRegionBundle.getString("otherSearchURL"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-14 04:13:21 +04:00
|
|
|
//Note: BrowserNewEditorWindow() was moved to globalOverlay.xul and renamed to NewEditorWindow()
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
function BrowserOpenWindow()
|
|
|
|
{
|
|
|
|
//opens a window where users can select a web location to open
|
2006-09-14 10:11:40 +04:00
|
|
|
var params = { browser: window, action: null, url: "" };
|
|
|
|
openDialog("chrome://communicator/content/openLocation.xul", "_blank", "chrome,modal,titlebar", params);
|
|
|
|
var url = getShortcutOrURI(params.url);
|
|
|
|
switch (params.action) {
|
|
|
|
case "0": // current window
|
|
|
|
loadURI(url, null, nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
|
|
|
|
break;
|
|
|
|
case "1": // new window
|
|
|
|
openDialog(getBrowserURL(), "_blank", "all,dialog=no", url, null, null,
|
|
|
|
nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
|
|
|
|
break;
|
|
|
|
case "2": // edit
|
|
|
|
editPage(url);
|
|
|
|
break;
|
|
|
|
case "3": // new tab
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab(url, null, null, false,
|
|
|
|
nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
|
|
|
|
break;
|
|
|
|
}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:47:23 +04:00
|
|
|
|
2006-09-14 09:59:38 +04:00
|
|
|
function BrowserOpenTab()
|
|
|
|
{
|
2006-09-14 10:03:46 +04:00
|
|
|
if (!gInPrintPreviewMode) {
|
2006-09-14 10:07:26 +04:00
|
|
|
var uriToLoad;
|
|
|
|
try {
|
|
|
|
switch ( pref.getIntPref("browser.tabs.loadOnNewTab") )
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
var handler = Components.classes['@mozilla.org/commandlinehandler/general-startup;1?type=browser']
|
|
|
|
.getService(Components.interfaces.nsICmdLineHandler);
|
|
|
|
uriToLoad = handler.defaultArgs.split("\n")[0];
|
|
|
|
if (!/\S/.test(uriToLoad))
|
|
|
|
uriToLoad = "about:blank";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
uriToLoad = "about:blank";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
uriToLoad = pref.getCharPref("browser.startup.homepage");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
uriToLoad = getWebNavigation().currentURI.spec;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
2006-09-14 10:07:09 +04:00
|
|
|
uriToLoad = "about:blank";
|
2006-09-14 10:07:26 +04:00
|
|
|
}
|
2006-09-14 10:07:09 +04:00
|
|
|
|
2006-09-14 10:07:07 +04:00
|
|
|
gBrowser.selectedTab = gBrowser.addTab(uriToLoad);
|
|
|
|
var navBar = document.getElementById("nav-bar");
|
|
|
|
if (uriToLoad == "about:blank" && !navBar.hidden && window.locationbar.visible)
|
|
|
|
setTimeout("gURLBar.focus();", 0);
|
|
|
|
else
|
|
|
|
setTimeout("content.focus();", 0);
|
2006-09-14 10:03:46 +04:00
|
|
|
}
|
2006-09-14 09:59:38 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:08:57 +04:00
|
|
|
/* Show file picker dialog configured for opening a file, and return
|
|
|
|
* the selected nsIFileURL instance. */
|
|
|
|
function selectFileToOpen(label, prefRoot)
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 10:08:57 +04:00
|
|
|
var fileURL = null;
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
// Get filepicker component.
|
2006-09-14 10:08:57 +04:00
|
|
|
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
|
|
|
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
|
|
|
fp.init(window, gNavigatorBundle.getString(label), nsIFilePicker.modeOpen);
|
|
|
|
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText | nsIFilePicker.filterImages |
|
|
|
|
nsIFilePicker.filterXML | nsIFilePicker.filterHTML);
|
|
|
|
|
|
|
|
const filterIndexPref = prefRoot + "filterIndex";
|
|
|
|
const lastDirPref = prefRoot + "dir";
|
|
|
|
|
|
|
|
// use a pref to remember the filterIndex selected by the user.
|
|
|
|
var index = 0;
|
|
|
|
try {
|
|
|
|
index = pref.getIntPref(filterIndexPref);
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
fp.filterIndex = index;
|
|
|
|
|
|
|
|
// use a pref to remember the displayDirectory selected by the user.
|
2006-09-14 09:55:03 +04:00
|
|
|
try {
|
2006-09-14 10:09:08 +04:00
|
|
|
fp.displayDirectory = pref.getComplexValue(lastDirPref, Components.interfaces.nsILocalFile);
|
2006-09-14 09:55:03 +04:00
|
|
|
} catch (ex) {
|
2006-09-14 09:44:15 +04:00
|
|
|
}
|
2006-09-14 10:08:57 +04:00
|
|
|
|
|
|
|
if (fp.show() == nsIFilePicker.returnOK) {
|
|
|
|
pref.setIntPref(filterIndexPref, fp.filterIndex);
|
|
|
|
pref.setComplexValue(lastDirPref,
|
|
|
|
Components.interfaces.nsILocalFile,
|
2006-09-14 10:09:08 +04:00
|
|
|
fp.file.parent);
|
2006-09-14 10:08:57 +04:00
|
|
|
fileURL = fp.fileURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fileURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
function BrowserOpenFileWindow()
|
|
|
|
{
|
|
|
|
try {
|
2006-09-14 10:09:08 +04:00
|
|
|
openTopWin(selectFileToOpen("openFile", "browser.open.").spec);
|
2006-09-14 10:08:57 +04:00
|
|
|
} catch (e) {}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:44:15 +04:00
|
|
|
|
2006-09-14 09:40:47 +04:00
|
|
|
function BrowserEditBookmarks()
|
2006-09-14 09:55:06 +04:00
|
|
|
{
|
2006-09-14 10:08:07 +04:00
|
|
|
toOpenWindowByType("bookmarks:manager", "chrome://communicator/content/bookmarks/bookmarksManager.xul");
|
2006-09-14 09:40:47 +04:00
|
|
|
}
|
1999-07-02 02:56:04 +04:00
|
|
|
|
2006-09-14 10:07:05 +04:00
|
|
|
function updateCloseItems()
|
|
|
|
{
|
|
|
|
var browser = getBrowser();
|
2006-09-14 10:10:35 +04:00
|
|
|
if (browser && browser.getStripVisibility()) {
|
2006-09-14 10:07:05 +04:00
|
|
|
document.getElementById('menu_closeOtherTabs').hidden = false;
|
2006-09-25 07:49:14 +04:00
|
|
|
if (browser.tabContainer.childNodes.length > 1) {
|
|
|
|
document.getElementById('menu_close').setAttribute('label', gNavigatorBundle.getString('tabs.closeTab'));
|
2006-09-14 10:07:05 +04:00
|
|
|
document.getElementById('cmd_closeOtherTabs').removeAttribute('disabled');
|
2006-09-25 07:49:14 +04:00
|
|
|
document.getElementById('menu_closeWindow').hidden = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById('menu_close').setAttribute('label', gNavigatorBundle.getString('tabs.close'));
|
2006-09-14 10:07:05 +04:00
|
|
|
document.getElementById('cmd_closeOtherTabs').setAttribute('disabled', 'true');
|
2006-09-25 07:49:14 +04:00
|
|
|
document.getElementById('menu_closeWindow').hidden = true;
|
|
|
|
}
|
2006-09-14 10:07:05 +04:00
|
|
|
} else {
|
|
|
|
document.getElementById('menu_close').setAttribute('label', gNavigatorBundle.getString('tabs.close'));
|
|
|
|
document.getElementById('menu_closeWindow').hidden = true;
|
|
|
|
document.getElementById('menu_closeOtherTabs').hidden = true;
|
|
|
|
}
|
2006-10-03 03:28:20 +04:00
|
|
|
var recentTabsItem = document.getElementById("menu_recentTabs");
|
2006-10-17 03:05:05 +04:00
|
|
|
recentTabsItem.setAttribute("disabled", !browser || browser.getUndoList().length == 0);
|
2006-10-03 03:28:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateRecentTabs(menupopup)
|
|
|
|
{
|
|
|
|
var browser = getBrowser();
|
|
|
|
|
|
|
|
while (menupopup.hasChildNodes())
|
|
|
|
menupopup.removeChild(menupopup.lastChild);
|
|
|
|
|
|
|
|
var list = browser.getUndoList();
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
|
var menuitem = document.createElement("menuitem");
|
|
|
|
var label = list[i];
|
|
|
|
if (i < 9) {
|
|
|
|
label = gNavigatorBundle.getFormattedString("tabs.recentlyClosed.format", [i + 1, label]);
|
|
|
|
menuitem.setAttribute("accesskey", i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
menuitem.setAttribute("key", "key_restoreTab");
|
|
|
|
|
|
|
|
menuitem.setAttribute("label", label);
|
|
|
|
menuitem.setAttribute("value", i);
|
|
|
|
menupopup.appendChild(menuitem);
|
|
|
|
}
|
2006-09-14 10:07:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function BrowserCloseOtherTabs()
|
|
|
|
{
|
|
|
|
var browser = getBrowser();
|
|
|
|
browser.removeAllTabsBut(browser.mCurrentTab);
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:00:36 +04:00
|
|
|
function BrowserCloseTabOrWindow()
|
2006-09-14 09:55:06 +04:00
|
|
|
{
|
2006-09-14 10:00:35 +04:00
|
|
|
var browser = getBrowser();
|
2006-09-14 10:08:22 +04:00
|
|
|
if (browser.tabContainer.childNodes.length > 1) {
|
2006-09-14 10:00:35 +04:00
|
|
|
// Just close up a tab.
|
2006-09-14 10:00:37 +04:00
|
|
|
browser.removeCurrentTab();
|
2006-09-14 10:00:35 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:00:36 +04:00
|
|
|
BrowserCloseWindow();
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:07:43 +04:00
|
|
|
function BrowserTryToCloseWindow()
|
|
|
|
{
|
|
|
|
//give tryToClose a chance to veto if it is defined
|
|
|
|
if (typeof(window.tryToClose) != "function" || window.tryToClose())
|
|
|
|
BrowserCloseWindow();
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:00:36 +04:00
|
|
|
function BrowserCloseWindow()
|
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
// This code replicates stuff in Shutdown(). It is here because
|
|
|
|
// window.screenX and window.screenY have real values. We need
|
|
|
|
// to fix this eventually but by replicating the code here, we
|
|
|
|
// provide a means of saving position (it just requires that the
|
|
|
|
// user close the window via File->Close (vs. close box).
|
2006-09-14 10:00:35 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
// Get the current window position/size.
|
|
|
|
var x = window.screenX;
|
|
|
|
var y = window.screenY;
|
|
|
|
var h = window.outerHeight;
|
|
|
|
var w = window.outerWidth;
|
|
|
|
|
|
|
|
// Store these into the window attributes (for persistence).
|
|
|
|
var win = document.getElementById( "main-window" );
|
|
|
|
win.setAttribute( "x", x );
|
|
|
|
win.setAttribute( "y", y );
|
|
|
|
win.setAttribute( "height", h );
|
|
|
|
win.setAttribute( "width", w );
|
|
|
|
|
|
|
|
window.close();
|
|
|
|
}
|
1999-09-17 03:44:07 +04:00
|
|
|
|
2006-09-14 10:11:33 +04:00
|
|
|
function loadURI(uri, referrer, flags)
|
2006-09-14 09:55:02 +04:00
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
try {
|
2006-09-14 10:11:33 +04:00
|
|
|
getBrowser().loadURIWithFlags(uri, flags, referrer);
|
2006-09-14 09:55:06 +04:00
|
|
|
} catch (e) {
|
|
|
|
}
|
2006-09-14 09:55:02 +04:00
|
|
|
}
|
2006-09-14 09:54:56 +04:00
|
|
|
|
2006-09-14 10:02:25 +04:00
|
|
|
function BrowserLoadURL(aTriggeringEvent)
|
2006-09-14 09:55:06 +04:00
|
|
|
{
|
|
|
|
var url = gURLBar.value;
|
2006-09-14 10:09:51 +04:00
|
|
|
|
|
|
|
// Remove leading and trailing spaces first
|
|
|
|
url = url.replace(/^\s+/, '').replace(/\s+$/, '');
|
|
|
|
|
2006-09-14 09:57:51 +04:00
|
|
|
if (url.match(/^view-source:/)) {
|
2006-09-14 10:03:45 +04:00
|
|
|
BrowserViewSourceOfURL(url.replace(/^view-source:/, ""), null, null);
|
2006-09-14 09:57:51 +04:00
|
|
|
} else {
|
2006-09-14 10:05:08 +04:00
|
|
|
// Check the pressed modifiers: (also see bug 97123)
|
|
|
|
// Modifier Mac | Modifier PC | Action
|
|
|
|
// -------------+-------------+-----------
|
|
|
|
// Command | Control | New Window/Tab
|
|
|
|
// Shift+Cmd | Shift+Ctrl | New Window/Tab behind current one
|
|
|
|
// Option | Shift | Save URL (show Filepicker)
|
|
|
|
|
|
|
|
// If false, the save modifier is Alt, which is Option on Mac.
|
|
|
|
var modifierIsShift = true;
|
|
|
|
try {
|
|
|
|
modifierIsShift = pref.getBoolPref("ui.key.saveLink.shift");
|
|
|
|
}
|
|
|
|
catch (ex) {}
|
|
|
|
|
|
|
|
var shiftPressed = false;
|
|
|
|
var saveModifier = false; // if the save modifier was pressed
|
|
|
|
if (aTriggeringEvent && 'shiftKey' in aTriggeringEvent &&
|
|
|
|
'altKey' in aTriggeringEvent) {
|
|
|
|
saveModifier = modifierIsShift ? aTriggeringEvent.shiftKey
|
|
|
|
: aTriggeringEvent.altKey;
|
|
|
|
shiftPressed = aTriggeringEvent.shiftKey;
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:07:39 +04:00
|
|
|
var browser = getBrowser();
|
2006-09-14 10:05:08 +04:00
|
|
|
url = getShortcutOrURI(url);
|
|
|
|
// Accept both Control and Meta (=Command) as New-Window-Modifiers
|
|
|
|
if (aTriggeringEvent &&
|
2006-09-14 10:05:09 +04:00
|
|
|
(('ctrlKey' in aTriggeringEvent && aTriggeringEvent.ctrlKey) ||
|
|
|
|
('metaKey' in aTriggeringEvent && aTriggeringEvent.metaKey))) {
|
2006-09-14 10:05:08 +04:00
|
|
|
// Check if user requests Tabs instead of windows
|
|
|
|
var openTab = false;
|
|
|
|
try {
|
|
|
|
openTab = pref.getBoolPref("browser.tabs.opentabfor.urlbar");
|
|
|
|
}
|
|
|
|
catch (ex) {}
|
|
|
|
|
2006-09-14 10:07:39 +04:00
|
|
|
if (openTab) {
|
2006-09-14 10:05:08 +04:00
|
|
|
// Open link in new tab
|
2006-09-14 10:11:33 +04:00
|
|
|
var t = browser.addTab(url, null, null, false,
|
|
|
|
nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
|
2006-09-14 10:07:39 +04:00
|
|
|
|
2006-09-14 10:05:08 +04:00
|
|
|
// Focus new tab unless shift is pressed
|
2006-09-14 10:07:39 +04:00
|
|
|
if (!shiftPressed) {
|
|
|
|
browser.userTypedValue = null;
|
|
|
|
browser.selectedTab = t;
|
|
|
|
}
|
|
|
|
} else {
|
2006-09-14 10:05:08 +04:00
|
|
|
// Open a new window with the URL
|
2006-09-14 10:11:33 +04:00
|
|
|
var newWin = openDialog(getBrowserURL(), "_blank", "all,dialog=no", url,
|
|
|
|
null, null, nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
|
2006-09-14 10:05:08 +04:00
|
|
|
// Reset url in the urlbar, copied from handleURLBarRevert()
|
2006-09-14 10:07:39 +04:00
|
|
|
var oldURL = browser.currentURI.spec;
|
2006-09-14 10:05:08 +04:00
|
|
|
if (oldURL != "about:blank") {
|
|
|
|
gURLBar.value = oldURL;
|
|
|
|
SetPageProxyState("valid", null);
|
2006-09-14 10:07:39 +04:00
|
|
|
} else
|
2006-09-14 10:05:08 +04:00
|
|
|
gURLBar.value = "";
|
|
|
|
|
2006-09-14 10:07:39 +04:00
|
|
|
browser.userTypedValue = null;
|
|
|
|
|
2006-09-14 10:05:08 +04:00
|
|
|
// Focus old window if shift was pressed, as there's no
|
|
|
|
// way to open a new window in the background
|
|
|
|
// XXX this doesn't seem to work
|
|
|
|
if (shiftPressed) {
|
|
|
|
//newWin.blur();
|
|
|
|
content.focus();
|
|
|
|
}
|
|
|
|
}
|
2006-09-14 10:07:39 +04:00
|
|
|
} else if (saveModifier) {
|
2006-09-14 10:05:12 +04:00
|
|
|
try {
|
|
|
|
// Firstly, fixup the url so that (e.g.) "www.foo.com" works
|
2006-09-14 10:06:40 +04:00
|
|
|
const nsIURIFixup = Components.interfaces.nsIURIFixup;
|
2006-09-14 10:05:12 +04:00
|
|
|
if (!gURIFixup)
|
|
|
|
gURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
2006-09-14 10:06:40 +04:00
|
|
|
.getService(nsIURIFixup);
|
2006-09-14 10:05:12 +04:00
|
|
|
url = gURIFixup.createFixupURI(url, nsIURIFixup.FIXUP_FLAGS_MAKE_ALTERNATE_URI).spec;
|
|
|
|
// Open filepicker to save the url
|
|
|
|
saveURL(url, "");
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
// XXX Do nothing for now.
|
|
|
|
// Do we want to put up an alert in the future? Mmm, l10n...
|
|
|
|
}
|
2006-09-14 10:07:39 +04:00
|
|
|
} else {
|
2006-09-14 10:05:08 +04:00
|
|
|
// No modifier was pressed, load the URL normally and
|
|
|
|
// focus the content area
|
2006-09-14 10:11:33 +04:00
|
|
|
loadURI(url, null, nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
|
2006-09-14 10:05:08 +04:00
|
|
|
content.focus();
|
2006-09-14 09:59:42 +04:00
|
|
|
}
|
2006-09-14 09:57:51 +04:00
|
|
|
}
|
2006-09-14 09:55:29 +04:00
|
|
|
}
|
2006-09-14 09:43:54 +04:00
|
|
|
|
2006-09-14 09:56:12 +04:00
|
|
|
function getShortcutOrURI(url)
|
2006-09-14 09:55:29 +04:00
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
// rjc: added support for URL shortcuts (3/30/1999)
|
|
|
|
try {
|
2006-09-14 10:01:17 +04:00
|
|
|
if (!gBookmarksService)
|
|
|
|
gBookmarksService = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIBookmarksService);
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 10:03:23 +04:00
|
|
|
var shortcutURL = gBookmarksService.resolveKeyword(url);
|
2006-09-14 09:55:06 +04:00
|
|
|
if (!shortcutURL) {
|
|
|
|
// rjc: add support for string substitution with shortcuts (4/4/2000)
|
|
|
|
// (see bug # 29871 for details)
|
|
|
|
var aOffset = url.indexOf(" ");
|
|
|
|
if (aOffset > 0) {
|
|
|
|
var cmd = url.substr(0, aOffset);
|
|
|
|
var text = url.substr(aOffset+1);
|
2006-09-14 10:03:23 +04:00
|
|
|
shortcutURL = gBookmarksService.resolveKeyword(cmd);
|
2006-09-14 10:10:11 +04:00
|
|
|
// Bug 123006 : %s replace and URI escape, %S replace with raw value
|
2006-09-14 09:55:06 +04:00
|
|
|
if (shortcutURL && text) {
|
2006-09-14 10:11:06 +04:00
|
|
|
var encodedText = null;
|
|
|
|
var charset = "";
|
|
|
|
const re = /^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/;
|
|
|
|
var matches = shortcutURL.match(re);
|
|
|
|
if (matches) {
|
|
|
|
shortcutURL = matches[1];
|
|
|
|
charset = matches[2];
|
|
|
|
}
|
|
|
|
else if (/%s/.test(shortcutURL)) {
|
|
|
|
try {
|
|
|
|
charset = BMSVC.getLastCharset(shortcutURL);
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (charset)
|
|
|
|
encodedText = escape(convertFromUnicode(charset, text));
|
|
|
|
else // default case: charset=UTF-8
|
|
|
|
encodedText = encodeURIComponent(text);
|
|
|
|
|
|
|
|
if (encodedText && /%[sS]/.test(shortcutURL))
|
|
|
|
shortcutURL = shortcutURL.replace(/%s/g, encodedText)
|
|
|
|
.replace(/%S/g, text);
|
|
|
|
else
|
|
|
|
shortcutURL = null;
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
2006-09-14 09:53:13 +04:00
|
|
|
}
|
2006-09-14 09:43:54 +04:00
|
|
|
}
|
1999-07-02 02:56:04 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
if (shortcutURL)
|
|
|
|
url = shortcutURL;
|
1999-12-29 01:07:19 +03:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
} catch (ex) {
|
2006-09-14 09:44:15 +04:00
|
|
|
}
|
2006-09-14 09:56:12 +04:00
|
|
|
return url;
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
2006-09-14 09:50:21 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
function readFromClipboard()
|
|
|
|
{
|
|
|
|
var url;
|
2006-09-14 09:50:21 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
try {
|
|
|
|
// Get clipboard.
|
|
|
|
var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
|
|
|
|
.getService(Components.interfaces.nsIClipboard);
|
2006-09-14 09:50:21 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
// Create tranferable that will transfer the text.
|
|
|
|
var trans = Components.classes["@mozilla.org/widget/transferable;1"]
|
|
|
|
.createInstance(Components.interfaces.nsITransferable);
|
2006-09-14 09:50:21 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
trans.addDataFlavor("text/unicode");
|
2006-09-14 10:08:08 +04:00
|
|
|
// If available, use selection clipboard, otherwise global one
|
|
|
|
if (clipboard.supportsSelectionClipboard())
|
|
|
|
clipboard.getData(trans, clipboard.kSelectionClipboard);
|
|
|
|
else
|
|
|
|
clipboard.getData(trans, clipboard.kGlobalClipboard);
|
2006-09-14 09:49:58 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
var data = {};
|
|
|
|
var dataLen = {};
|
|
|
|
trans.getTransferData("text/unicode", data, dataLen);
|
|
|
|
|
|
|
|
if (data) {
|
2006-09-14 10:05:07 +04:00
|
|
|
data = data.value.QueryInterface(Components.interfaces.nsISupportsString);
|
2006-09-14 09:55:06 +04:00
|
|
|
url = data.data.substring(0, dataLen.value / 2);
|
2006-09-14 09:49:58 +04:00
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
} catch (ex) {
|
2006-09-14 09:44:13 +04:00
|
|
|
}
|
1999-07-22 04:27:14 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:03:45 +04:00
|
|
|
function BrowserViewSourceOfDocument(aDocument)
|
2006-09-14 09:55:06 +04:00
|
|
|
{
|
2006-09-14 10:03:45 +04:00
|
|
|
var docCharset;
|
|
|
|
var pageCookie;
|
|
|
|
var webNav;
|
|
|
|
|
|
|
|
// Get the document charset
|
|
|
|
docCharset = "charset=" + aDocument.characterSet;
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 10:03:45 +04:00
|
|
|
// Get the nsIWebNavigation associated with the document
|
|
|
|
try {
|
|
|
|
var win;
|
|
|
|
var ifRequestor;
|
|
|
|
|
|
|
|
// Get the DOMWindow for the requested document. If the DOMWindow
|
2006-09-14 10:09:37 +04:00
|
|
|
// cannot be found, then just use the content window...
|
2006-09-14 10:03:45 +04:00
|
|
|
//
|
|
|
|
// XXX: This is a bit of a hack...
|
|
|
|
win = aDocument.defaultView;
|
|
|
|
if (win == window) {
|
2006-09-14 10:09:37 +04:00
|
|
|
win = content;
|
2006-09-14 10:03:45 +04:00
|
|
|
}
|
|
|
|
ifRequestor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
|
|
|
|
|
|
|
|
webNav = ifRequestor.getInterface(Components.interfaces.nsIWebNavigation);
|
|
|
|
} catch(err) {
|
|
|
|
// If nsIWebNavigation cannot be found, just get the one for the whole
|
|
|
|
// window...
|
|
|
|
webNav = getWebNavigation();
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Get the 'PageDescriptor' for the current document. This allows the
|
|
|
|
// view-source to access the cached copy of the content rather than
|
|
|
|
// refetching it from the network...
|
|
|
|
//
|
|
|
|
try{
|
|
|
|
var PageLoader = webNav.QueryInterface(Components.interfaces.nsIWebPageDescriptor);
|
|
|
|
|
|
|
|
pageCookie = PageLoader.currentDescriptor;
|
|
|
|
} catch(err) {
|
|
|
|
// If no page descriptor is available, just use the view-source URL...
|
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 10:03:45 +04:00
|
|
|
BrowserViewSourceOfURL(webNav.currentURI.spec, docCharset, pageCookie);
|
2006-09-14 09:57:51 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:03:45 +04:00
|
|
|
function BrowserViewSourceOfURL(url, charset, pageCookie)
|
2006-09-14 09:57:51 +04:00
|
|
|
{
|
|
|
|
// try to open a view-source window while inheriting the charset (if any)
|
2006-09-14 09:55:06 +04:00
|
|
|
openDialog("chrome://navigator/content/viewSource.xul",
|
|
|
|
"_blank",
|
2006-09-14 10:08:06 +04:00
|
|
|
"all,dialog=no",
|
2006-09-14 10:03:45 +04:00
|
|
|
url, charset, pageCookie);
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:03:33 +04:00
|
|
|
// doc=null for regular page info, doc=owner document for frame info.
|
2006-09-14 10:11:10 +04:00
|
|
|
function BrowserPageInfo(doc, initialTab)
|
2006-09-14 09:55:06 +04:00
|
|
|
{
|
|
|
|
window.openDialog("chrome://navigator/content/pageInfo.xul",
|
|
|
|
"_blank",
|
2006-09-14 09:56:23 +04:00
|
|
|
"chrome,dialog=no",
|
2006-09-14 10:11:10 +04:00
|
|
|
{doc: doc, initialTab: initialTab});
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
2006-09-14 09:50:19 +04:00
|
|
|
|
1999-09-19 11:11:34 +04:00
|
|
|
function hiddenWindowStartup()
|
|
|
|
{
|
2006-09-14 09:58:24 +04:00
|
|
|
// focus the hidden window
|
|
|
|
window.focus();
|
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
// Disable menus which are not appropriate
|
2006-09-14 10:07:27 +04:00
|
|
|
var disabledItems = ['cmd_close', 'Browser:SendPage', 'Browser:EditPage',
|
2006-09-14 10:10:35 +04:00
|
|
|
'Browser:SavePage', 'cmd_printSetup', /*'Browser:PrintPreview',*/
|
2006-09-14 10:07:27 +04:00
|
|
|
'Browser:Print', 'canGoBack', 'canGoForward',
|
|
|
|
'Browser:Home', 'Browser:AddBookmark',
|
|
|
|
'Browser:AddBookmarkAs', 'Browser:AddGroupmarkAs',
|
|
|
|
'cmd_undo', 'cmd_redo', 'cmd_cut', 'cmd_copy',
|
|
|
|
'cmd_paste', 'cmd_delete', 'cmd_selectAll',
|
2006-09-14 10:10:21 +04:00
|
|
|
'menu_textZoom', 'cmd_minimizeWindow', 'cmd_zoomWindow'];
|
|
|
|
var broadcaster;
|
|
|
|
|
2006-09-14 10:01:33 +04:00
|
|
|
for (var id in disabledItems) {
|
2006-09-14 10:10:21 +04:00
|
|
|
broadcaster = document.getElementById(disabledItems[id]);
|
2006-09-14 09:55:06 +04:00
|
|
|
if (broadcaster)
|
|
|
|
broadcaster.setAttribute("disabled", "true");
|
|
|
|
}
|
2006-09-14 10:07:27 +04:00
|
|
|
|
2006-09-14 10:10:21 +04:00
|
|
|
// also hide the window list separator
|
|
|
|
var separator = document.getElementById("sep-window-list");
|
|
|
|
if (separator)
|
|
|
|
separator.setAttribute("hidden", "true");
|
|
|
|
|
2006-09-14 10:10:20 +04:00
|
|
|
// Get the preferences service
|
|
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
|
|
pref = prefService.getBranch(null);
|
|
|
|
|
|
|
|
// init global strings bundle
|
|
|
|
gNavigatorBundle = document.getElementById("bundle_navigator");
|
|
|
|
|
2006-09-14 10:07:27 +04:00
|
|
|
// now load bookmarks after a delay
|
|
|
|
setTimeout(hiddenWindowLoadBookmarksCallback, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hiddenWindowLoadBookmarksCallback()
|
|
|
|
{
|
|
|
|
// loads the services
|
|
|
|
initServices();
|
|
|
|
initBMService();
|
|
|
|
BMSVC.readBookmarks();
|
1999-09-19 11:11:34 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:53:10 +04:00
|
|
|
// Initialize the LeakDetector class.
|
|
|
|
function LeakDetector(verbose)
|
2006-09-14 09:53:02 +04:00
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
this.verbose = verbose;
|
2006-09-14 09:54:00 +04:00
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 09:59:04 +04:00
|
|
|
const NS_LEAKDETECTOR_CONTRACTID = "@mozilla.org/xpcom/leakdetector;1";
|
|
|
|
|
|
|
|
if (NS_LEAKDETECTOR_CONTRACTID in Components.classes) {
|
|
|
|
try {
|
|
|
|
LeakDetector.prototype = Components.classes[NS_LEAKDETECTOR_CONTRACTID]
|
|
|
|
.createInstance(Components.interfaces.nsILeakDetector);
|
|
|
|
} catch (err) {
|
|
|
|
LeakDetector.prototype = Object.prototype;
|
|
|
|
}
|
|
|
|
} else {
|
2006-09-14 09:55:06 +04:00
|
|
|
LeakDetector.prototype = Object.prototype;
|
2006-09-14 09:53:02 +04:00
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 09:53:10 +04:00
|
|
|
var leakDetector = new LeakDetector(false);
|
2006-09-14 09:53:02 +04:00
|
|
|
|
|
|
|
// Dumps current set of memory leaks.
|
2006-09-14 09:53:10 +04:00
|
|
|
function dumpMemoryLeaks()
|
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
leakDetector.dumpLeaks();
|
2006-09-14 09:53:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Traces all objects reachable from the chrome document.
|
|
|
|
function traceChrome()
|
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
leakDetector.traceObject(document, leakDetector.verbose);
|
2006-09-14 09:53:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Traces all objects reachable from the content document.
|
|
|
|
function traceDocument()
|
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
// keep the chrome document out of the dump.
|
|
|
|
leakDetector.markObject(document, true);
|
2006-09-14 10:09:37 +04:00
|
|
|
leakDetector.traceObject(content, leakDetector.verbose);
|
2006-09-14 09:55:06 +04:00
|
|
|
leakDetector.markObject(document, false);
|
1999-10-16 01:35:11 +04:00
|
|
|
}
|
2006-09-14 09:51:02 +04:00
|
|
|
|
2006-09-14 09:53:10 +04:00
|
|
|
// Controls whether or not we do verbose tracing.
|
|
|
|
function traceVerbose(verbose)
|
2006-09-14 09:53:02 +04:00
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
leakDetector.verbose = (verbose == "true");
|
2006-09-14 09:53:02 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:51:02 +04:00
|
|
|
var consoleListener = {
|
2006-09-14 09:55:06 +04:00
|
|
|
observe: function (aMsgObject)
|
|
|
|
{
|
|
|
|
const nsIScriptError = Components.interfaces.nsIScriptError;
|
|
|
|
var scriptError = aMsgObject.QueryInterface(nsIScriptError);
|
|
|
|
var isWarning = scriptError.flags & nsIScriptError.warningFlag != 0;
|
|
|
|
if (!isWarning) {
|
|
|
|
var statusbarDisplay = document.getElementById("statusbar-display");
|
|
|
|
statusbarDisplay.setAttribute("error", "true");
|
|
|
|
statusbarDisplay.addEventListener("click", loadErrorConsole, true);
|
2006-09-14 09:56:42 +04:00
|
|
|
statusbarDisplay.label = gNavigatorBundle.getString("jserror");
|
2006-09-14 09:55:06 +04:00
|
|
|
this.isShowingError = true;
|
|
|
|
}
|
|
|
|
},
|
2006-09-14 09:51:02 +04:00
|
|
|
|
|
|
|
// whether or not an error alert is being displayed
|
2006-09-14 09:53:12 +04:00
|
|
|
isShowingError: false
|
2006-09-14 09:51:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
function initConsoleListener()
|
|
|
|
{
|
|
|
|
/**
|
2006-09-14 09:55:38 +04:00
|
|
|
* XXX - console launch hookup requires some work that I'm not sure
|
|
|
|
* how to do.
|
2006-09-14 09:51:02 +04:00
|
|
|
*
|
2006-09-14 09:55:38 +04:00
|
|
|
* 1) ideally, the notification would disappear when the
|
|
|
|
* document that had the error was flushed. how do I know when
|
|
|
|
* this happens? All the nsIScriptError object I get tells me
|
|
|
|
* is the URL. Where is it located in the content area?
|
|
|
|
* 2) the notification service should not display chrome
|
|
|
|
* script errors. web developers and users are not interested
|
|
|
|
* in the failings of our shitty, exception unsafe js. One
|
|
|
|
* could argue that this should also extend to the console by
|
|
|
|
* default (although toggle-able via setting for chrome
|
|
|
|
* authors) At any rate, no status indication should be given
|
|
|
|
* for chrome script errors.
|
2006-09-14 09:55:06 +04:00
|
|
|
*
|
|
|
|
* As a result I am commenting out this for the moment.
|
2006-09-14 09:55:32 +04:00
|
|
|
*
|
|
|
|
|
|
|
|
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
|
|
|
|
.getService(Components.interfaces.nsIConsoleService);
|
|
|
|
|
|
|
|
if (consoleService)
|
|
|
|
consoleService.registerListener(consoleListener);
|
|
|
|
*/
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
2006-09-14 09:51:02 +04:00
|
|
|
|
|
|
|
function loadErrorConsole(aEvent)
|
|
|
|
{
|
|
|
|
if (aEvent.detail == 2)
|
|
|
|
toJavaScriptConsole();
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearErrorNotification()
|
|
|
|
{
|
|
|
|
var statusbarDisplay = document.getElementById("statusbar-display");
|
|
|
|
statusbarDisplay.removeAttribute("error");
|
|
|
|
statusbarDisplay.removeEventListener("click", loadErrorConsole, true);
|
|
|
|
consoleListener.isShowingError = false;
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:59:04 +04:00
|
|
|
const NS_URLWIDGET_CONTRACTID = "@mozilla.org/urlwidget;1";
|
2006-09-14 09:56:42 +04:00
|
|
|
var urlWidgetService = null;
|
2006-09-14 09:59:04 +04:00
|
|
|
if (NS_URLWIDGET_CONTRACTID in Components.classes) {
|
|
|
|
urlWidgetService = Components.classes[NS_URLWIDGET_CONTRACTID]
|
2006-09-14 09:56:42 +04:00
|
|
|
.getService(Components.interfaces.nsIUrlWidget);
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:51:12 +04:00
|
|
|
//Posts the currently displayed url to a native widget so third-party apps can observe it.
|
2006-09-14 09:55:06 +04:00
|
|
|
function postURLToNativeWidget()
|
|
|
|
{
|
2006-09-14 09:55:33 +04:00
|
|
|
if (urlWidgetService) {
|
2006-09-14 10:01:35 +04:00
|
|
|
var url = getWebNavigation().currentURI.spec;
|
2006-09-14 09:55:33 +04:00
|
|
|
try {
|
|
|
|
urlWidgetService.SetURLToHiddenControl(url, window);
|
|
|
|
} catch(ex) {
|
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkForDirectoryListing()
|
|
|
|
{
|
2006-09-14 10:09:37 +04:00
|
|
|
if ( "HTTPIndex" in content &&
|
|
|
|
content.HTTPIndex instanceof Components.interfaces.nsIHTTPIndex ) {
|
|
|
|
content.defaultCharacterset = getMarkupDocumentViewer().defaultCharacterSet;
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
2006-09-14 09:51:34 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:52:28 +04:00
|
|
|
/**
|
2006-09-14 09:55:06 +04:00
|
|
|
* Use Stylesheet functions.
|
2006-09-14 09:52:28 +04:00
|
|
|
* Written by Tim Hill (bug 6782)
|
2006-09-14 10:01:43 +04:00
|
|
|
* Frameset handling by Neil Rashbrook <neil@parkwaycc.co.uk>
|
2006-09-14 09:52:28 +04:00
|
|
|
**/
|
2006-09-14 10:01:43 +04:00
|
|
|
function getStyleSheetArray(frame)
|
|
|
|
{
|
|
|
|
var styleSheets = frame.document.styleSheets;
|
|
|
|
var styleSheetsArray = new Array(styleSheets.length);
|
|
|
|
for (var i = 0; i < styleSheets.length; i++) {
|
|
|
|
styleSheetsArray[i] = styleSheets[i];
|
2006-09-14 09:52:28 +04:00
|
|
|
}
|
2006-09-14 10:01:43 +04:00
|
|
|
return styleSheetsArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllStyleSheets(frameset)
|
|
|
|
{
|
|
|
|
var styleSheetsArray = getStyleSheetArray(frameset);
|
|
|
|
for (var i = 0; i < frameset.frames.length; i++) {
|
|
|
|
var frameSheets = getAllStyleSheets(frameset.frames[i]);
|
|
|
|
styleSheetsArray = styleSheetsArray.concat(frameSheets);
|
|
|
|
}
|
|
|
|
return styleSheetsArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
function stylesheetFillPopup(menuPopup)
|
|
|
|
{
|
2006-09-14 10:09:55 +04:00
|
|
|
/* Clear menu */
|
|
|
|
var itemPersistentOnly = menuPopup.firstChild.nextSibling;
|
|
|
|
while (itemPersistentOnly.nextSibling)
|
|
|
|
menuPopup.removeChild(itemPersistentOnly.nextSibling);
|
2006-09-14 09:52:28 +04:00
|
|
|
|
2006-09-14 10:09:37 +04:00
|
|
|
var styleSheets = getAllStyleSheets(window.content);
|
2006-09-14 09:55:06 +04:00
|
|
|
var currentStyleSheets = [];
|
2006-09-14 10:09:55 +04:00
|
|
|
var styleDisabled = getMarkupDocumentViewer().authorStyleDisabled;
|
|
|
|
var altStyleSelected = false;
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 10:01:43 +04:00
|
|
|
for (var i = 0; i < styleSheets.length; ++i) {
|
2006-09-14 09:55:06 +04:00
|
|
|
var currentStyleSheet = styleSheets[i];
|
|
|
|
|
|
|
|
if (currentStyleSheet.title) {
|
|
|
|
if (!currentStyleSheet.disabled)
|
2006-09-14 10:09:55 +04:00
|
|
|
altStyleSelected = true;
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 09:57:08 +04:00
|
|
|
var lastWithSameTitle = null;
|
2006-09-14 09:55:06 +04:00
|
|
|
if (currentStyleSheet.title in currentStyleSheets)
|
|
|
|
lastWithSameTitle = currentStyleSheets[currentStyleSheet.title];
|
|
|
|
|
|
|
|
if (!lastWithSameTitle) {
|
2006-09-14 10:03:41 +04:00
|
|
|
var menuItem = document.createElement("menuitem");
|
|
|
|
menuItem.setAttribute("type", "radio");
|
2006-09-14 09:56:42 +04:00
|
|
|
menuItem.setAttribute("label", currentStyleSheet.title);
|
2006-09-14 09:55:06 +04:00
|
|
|
menuItem.setAttribute("data", currentStyleSheet.title);
|
2006-09-14 10:09:55 +04:00
|
|
|
menuItem.setAttribute("checked", !currentStyleSheet.disabled && !styleDisabled);
|
2006-09-14 09:55:06 +04:00
|
|
|
menuPopup.appendChild(menuItem);
|
|
|
|
currentStyleSheets[currentStyleSheet.title] = menuItem;
|
|
|
|
} else {
|
|
|
|
if (currentStyleSheet.disabled)
|
2006-09-14 10:01:17 +04:00
|
|
|
lastWithSameTitle.removeAttribute("checked");
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
2006-09-14 09:52:28 +04:00
|
|
|
}
|
|
|
|
}
|
2006-09-14 10:09:55 +04:00
|
|
|
menuPopup.firstChild.setAttribute("checked", styleDisabled);
|
|
|
|
itemPersistentOnly.setAttribute("checked", !altStyleSelected && !styleDisabled);
|
|
|
|
itemPersistentOnly.hidden = (window.content.document.preferredStylesheetSet) ? true : false;
|
2006-09-14 09:52:28 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:01:43 +04:00
|
|
|
function stylesheetInFrame(frame, title) {
|
|
|
|
var docStyleSheets = frame.document.styleSheets;
|
|
|
|
|
|
|
|
for (var i = 0; i < docStyleSheets.length; ++i) {
|
|
|
|
if (docStyleSheets[i].title == title)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function stylesheetSwitchFrame(frame, title) {
|
|
|
|
var docStyleSheets = frame.document.styleSheets;
|
2006-09-14 09:52:28 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
for (var i = 0; i < docStyleSheets.length; ++i) {
|
|
|
|
var docStyleSheet = docStyleSheets[i];
|
|
|
|
|
|
|
|
if (docStyleSheet.title)
|
|
|
|
docStyleSheet.disabled = (docStyleSheet.title != title);
|
|
|
|
else if (docStyleSheet.disabled)
|
|
|
|
docStyleSheet.disabled = false;
|
|
|
|
}
|
2006-09-14 09:52:58 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:01:43 +04:00
|
|
|
function stylesheetSwitchAll(frameset, title) {
|
|
|
|
if (!title || stylesheetInFrame(frameset, title)) {
|
|
|
|
stylesheetSwitchFrame(frameset, title);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < frameset.frames.length; i++) {
|
|
|
|
stylesheetSwitchAll(frameset.frames[i], title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:09:55 +04:00
|
|
|
function setStyleDisabled(disabled) {
|
|
|
|
getMarkupDocumentViewer().authorStyleDisabled = disabled;
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:52:58 +04:00
|
|
|
function applyTheme(themeName)
|
|
|
|
{
|
2006-09-14 10:04:04 +04:00
|
|
|
var id = themeName.getAttribute('id');
|
|
|
|
var name=id.substring('urn:mozilla.skin.'.length, id.length);
|
2006-09-14 10:01:17 +04:00
|
|
|
if (!name)
|
2006-09-14 09:58:16 +04:00
|
|
|
return;
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
2006-09-14 10:09:58 +04:00
|
|
|
.getService(Components.interfaces.nsIChromeRegistrySea);
|
2006-09-14 09:58:16 +04:00
|
|
|
|
2006-09-14 09:58:31 +04:00
|
|
|
var oldTheme = false;
|
2006-09-14 09:58:16 +04:00
|
|
|
try {
|
2006-09-14 10:01:17 +04:00
|
|
|
oldTheme = !chromeRegistry.checkThemeVersion(name);
|
2006-09-14 09:58:16 +04:00
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:05:07 +04:00
|
|
|
var str = Components.classes["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsString);
|
2006-09-14 10:03:40 +04:00
|
|
|
|
2006-09-14 09:58:31 +04:00
|
|
|
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
2006-09-14 09:58:16 +04:00
|
|
|
if (oldTheme) {
|
|
|
|
var title = gNavigatorBundle.getString("oldthemetitle");
|
|
|
|
var message = gNavigatorBundle.getString("oldTheme");
|
|
|
|
|
|
|
|
message = message.replace(/%theme_name%/, themeName.getAttribute("displayName"));
|
|
|
|
message = message.replace(/%brand%/g, gBrandBundle.getString("brandShortName"));
|
|
|
|
|
|
|
|
if (promptService.confirm(window, title, message)){
|
2006-09-14 10:01:44 +04:00
|
|
|
var inUse = chromeRegistry.isSkinSelected(name, true);
|
2006-09-14 09:58:16 +04:00
|
|
|
|
2006-09-14 10:01:44 +04:00
|
|
|
chromeRegistry.uninstallSkin( name, true );
|
2006-09-14 09:58:31 +04:00
|
|
|
// XXX - this sucks and should only be temporary.
|
2006-09-14 10:03:40 +04:00
|
|
|
|
2006-09-14 10:00:39 +04:00
|
|
|
str.data = true;
|
2006-09-14 10:01:44 +04:00
|
|
|
pref.setComplexValue("general.skins.removelist." + name,
|
2006-09-14 10:05:07 +04:00
|
|
|
Components.interfaces.nsISupportsString, str);
|
2006-09-14 09:58:31 +04:00
|
|
|
|
2006-09-14 09:58:16 +04:00
|
|
|
if (inUse)
|
|
|
|
chromeRegistry.refreshSkins();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2006-09-14 09:52:58 +04:00
|
|
|
|
2006-09-14 10:03:40 +04:00
|
|
|
// XXX XXX BAD BAD BAD BAD !! XXX XXX
|
|
|
|
// we STILL haven't fixed editor skin switch problems
|
|
|
|
// hacking around it yet again
|
2006-09-14 09:52:58 +04:00
|
|
|
|
2006-09-14 10:04:04 +04:00
|
|
|
str.data = name;
|
2006-09-14 10:05:07 +04:00
|
|
|
pref.setComplexValue("general.skins.selectedSkin", Components.interfaces.nsISupportsString, str);
|
2006-09-14 10:04:06 +04:00
|
|
|
|
|
|
|
// shut down quicklaunch so the next launch will have the new skin
|
2006-09-14 10:10:12 +04:00
|
|
|
var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
|
|
|
|
.getService(Components.interfaces.nsIAppStartup);
|
2006-09-14 10:04:06 +04:00
|
|
|
try {
|
2006-09-14 10:10:12 +04:00
|
|
|
appStartup.nativeAppSupport.isServerMode = false;
|
2006-09-14 10:04:06 +04:00
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:03:40 +04:00
|
|
|
if (promptService) {
|
|
|
|
var dialogTitle = gNavigatorBundle.getString("switchskinstitle");
|
|
|
|
var brandName = gBrandBundle.getString("brandShortName");
|
|
|
|
var msg = gNavigatorBundle.getFormattedString("switchskins", [brandName]);
|
|
|
|
promptService.alert(window, dialogTitle, msg);
|
|
|
|
}
|
|
|
|
}
|
2006-09-14 09:58:16 +04:00
|
|
|
|
2006-09-14 09:52:58 +04:00
|
|
|
function getNewThemes()
|
|
|
|
{
|
2006-09-14 09:56:13 +04:00
|
|
|
loadURI(gBrandRegionBundle.getString("getNewThemesURL"));
|
2006-09-14 09:52:28 +04:00
|
|
|
}
|
2006-09-14 09:53:22 +04:00
|
|
|
|
2006-09-14 09:58:58 +04:00
|
|
|
function URLBarFocusHandler(aEvent)
|
2006-09-14 09:53:22 +04:00
|
|
|
{
|
2006-09-14 10:04:29 +04:00
|
|
|
if (gIgnoreFocus)
|
|
|
|
gIgnoreFocus = false;
|
|
|
|
else if (gClickSelectsAll)
|
|
|
|
gURLBar.select();
|
2006-09-14 09:54:01 +04:00
|
|
|
}
|
2006-09-14 09:54:28 +04:00
|
|
|
|
2006-09-14 10:04:27 +04:00
|
|
|
function URLBarMouseDownHandler(aEvent)
|
|
|
|
{
|
2006-09-14 10:04:29 +04:00
|
|
|
if (gURLBar.hasAttribute("focused")) {
|
|
|
|
gIgnoreClick = true;
|
|
|
|
} else {
|
|
|
|
gIgnoreFocus = true;
|
|
|
|
gIgnoreClick = false;
|
|
|
|
gURLBar.setSelectionRange(0, 0);
|
2006-09-14 10:04:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:04:29 +04:00
|
|
|
function URLBarClickHandler(aEvent)
|
2006-09-14 10:04:27 +04:00
|
|
|
{
|
2006-09-14 10:07:06 +04:00
|
|
|
if (!gIgnoreClick && gClickSelectsAll && gURLBar.selectionStart == gURLBar.selectionEnd)
|
|
|
|
if (gClickAtEndSelects || gURLBar.selectionStart < gURLBar.value.length)
|
|
|
|
gURLBar.select();
|
2006-09-14 09:58:57 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:54:28 +04:00
|
|
|
// This function gets the "windows hooks" service and has it check its setting
|
|
|
|
// This will do nothing on platforms other than Windows.
|
2006-09-14 09:55:03 +04:00
|
|
|
function checkForDefaultBrowser()
|
|
|
|
{
|
2006-09-14 09:59:04 +04:00
|
|
|
const NS_WINHOOKS_CONTRACTID = "@mozilla.org/winhooks;1";
|
2006-09-14 10:02:29 +04:00
|
|
|
var dialogShown = false;
|
2006-09-14 09:59:04 +04:00
|
|
|
if (NS_WINHOOKS_CONTRACTID in Components.classes) {
|
|
|
|
try {
|
2006-09-14 10:02:29 +04:00
|
|
|
dialogShown = Components.classes[NS_WINHOOKS_CONTRACTID]
|
|
|
|
.getService(Components.interfaces.nsIWindowsHooks)
|
|
|
|
.checkSettings(window);
|
2006-09-14 09:59:04 +04:00
|
|
|
} catch(e) {
|
|
|
|
}
|
2006-09-14 10:02:29 +04:00
|
|
|
|
|
|
|
if (dialogShown)
|
|
|
|
{
|
|
|
|
// Force the sidebar to build since the windows
|
|
|
|
// integration dialog may have come up.
|
|
|
|
SidebarRebuild();
|
|
|
|
}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
|
|
|
}
|
2006-09-14 09:57:01 +04:00
|
|
|
|
|
|
|
function ShowAndSelectContentsOfURLBar()
|
|
|
|
{
|
|
|
|
var navBar = document.getElementById("nav-bar");
|
|
|
|
|
|
|
|
// If it's hidden, show it.
|
|
|
|
if (navBar.getAttribute("hidden") == "true")
|
|
|
|
goToggleToolbar('nav-bar','cmd_viewnavbar');
|
2006-09-14 09:59:51 +04:00
|
|
|
|
2006-09-14 09:57:05 +04:00
|
|
|
if (gURLBar.value)
|
|
|
|
gURLBar.select();
|
2006-09-14 09:57:01 +04:00
|
|
|
else
|
2006-09-14 09:57:05 +04:00
|
|
|
gURLBar.focus();
|
2006-09-14 09:57:01 +04:00
|
|
|
}
|
2006-09-14 09:57:14 +04:00
|
|
|
|
|
|
|
// If "ESC" is pressed in the url bar, we replace the urlbar's value with the url of the page
|
|
|
|
// and highlight it, unless it is about:blank, where we reset it to "".
|
2006-09-14 09:57:38 +04:00
|
|
|
function handleURLBarRevert()
|
2006-09-14 09:57:14 +04:00
|
|
|
{
|
2006-09-14 10:01:35 +04:00
|
|
|
var url = getWebNavigation().currentURI.spec;
|
2006-09-14 09:57:14 +04:00
|
|
|
var throbberElement = document.getElementById("navigator-throbber");
|
|
|
|
|
2006-09-14 09:57:38 +04:00
|
|
|
var isScrolling = gURLBar.userAction == "scrolling";
|
|
|
|
|
|
|
|
// don't revert to last valid url unless page is NOT loading
|
|
|
|
// and user is NOT key-scrolling through autocomplete list
|
2006-09-14 10:01:44 +04:00
|
|
|
if (!throbberElement.hasAttribute("busy") && !isScrolling) {
|
2006-09-14 10:07:39 +04:00
|
|
|
if (url != "about:blank") {
|
2006-09-14 09:57:14 +04:00
|
|
|
gURLBar.value = url;
|
|
|
|
gURLBar.select();
|
2006-09-14 10:00:54 +04:00
|
|
|
SetPageProxyState("valid", null); // XXX Build a URI and pass it in here.
|
2006-09-14 09:57:14 +04:00
|
|
|
} else { //if about:blank, urlbar becomes ""
|
|
|
|
gURLBar.value = "";
|
|
|
|
}
|
2006-09-14 10:07:39 +04:00
|
|
|
|
|
|
|
gBrowser.userTypedValue = null;
|
2006-09-14 09:57:14 +04:00
|
|
|
}
|
2006-09-14 09:57:38 +04:00
|
|
|
|
|
|
|
// tell widget to revert to last typed text only if the user
|
|
|
|
// was scrolling when they hit escape
|
|
|
|
return isScrolling;
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:02:25 +04:00
|
|
|
function handleURLBarCommand(aUserAction, aTriggeringEvent)
|
2006-09-14 09:57:38 +04:00
|
|
|
{
|
2006-09-14 10:09:51 +04:00
|
|
|
try {
|
2006-09-14 10:10:56 +04:00
|
|
|
addToUrlbarHistory(gURLBar.value);
|
2006-09-14 10:03:30 +04:00
|
|
|
} catch (ex) {
|
|
|
|
// Things may go wrong when adding url to session history,
|
|
|
|
// but don't let that interfere with the loading of the url.
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:02:25 +04:00
|
|
|
BrowserLoadURL(aTriggeringEvent);
|
2006-09-14 09:57:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function UpdatePageProxyState()
|
|
|
|
{
|
2006-09-14 10:00:54 +04:00
|
|
|
if (gURLBar.value != gLastValidURLStr)
|
|
|
|
SetPageProxyState("invalid", null);
|
2006-09-14 09:57:38 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:00:54 +04:00
|
|
|
function SetPageProxyState(aState, aURI)
|
2006-09-14 09:57:38 +04:00
|
|
|
{
|
|
|
|
if (!gProxyButton)
|
|
|
|
gProxyButton = document.getElementById("page-proxy-button");
|
2006-09-14 10:00:54 +04:00
|
|
|
if (!gProxyFavIcon)
|
|
|
|
gProxyFavIcon = document.getElementById("page-proxy-favicon");
|
|
|
|
if (!gProxyDeck)
|
|
|
|
gProxyDeck = document.getElementById("page-proxy-deck");
|
2006-09-14 09:57:38 +04:00
|
|
|
|
|
|
|
gProxyButton.setAttribute("pageproxystate", aState);
|
|
|
|
|
|
|
|
if (aState == "valid") {
|
2006-09-14 10:00:54 +04:00
|
|
|
gLastValidURLStr = gURLBar.value;
|
2006-09-14 09:57:38 +04:00
|
|
|
gURLBar.addEventListener("input", UpdatePageProxyState, false);
|
2006-09-14 10:00:55 +04:00
|
|
|
if (gBrowser.shouldLoadFavIcon(aURI)) {
|
|
|
|
var favStr = gBrowser.buildFavIconString(aURI);
|
|
|
|
if (favStr != gProxyFavIcon.src) {
|
|
|
|
gBrowser.loadFavIcon(aURI, "src", gProxyFavIcon);
|
2006-09-14 10:00:54 +04:00
|
|
|
gProxyDeck.selectedIndex = 0;
|
|
|
|
}
|
2006-09-14 10:00:55 +04:00
|
|
|
else gProxyDeck.selectedIndex = 1;
|
2006-09-14 10:00:54 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
gProxyDeck.selectedIndex = 0;
|
|
|
|
gProxyFavIcon.removeAttribute("src");
|
|
|
|
}
|
|
|
|
} else if (aState == "invalid") {
|
2006-09-14 09:57:38 +04:00
|
|
|
gURLBar.removeEventListener("input", UpdatePageProxyState, false);
|
2006-09-14 10:00:54 +04:00
|
|
|
gProxyDeck.selectedIndex = 0;
|
|
|
|
}
|
2006-09-14 09:57:14 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:57:38 +04:00
|
|
|
function PageProxyDragGesture(aEvent)
|
2006-09-14 09:57:14 +04:00
|
|
|
{
|
2006-09-14 09:59:51 +04:00
|
|
|
if (gProxyButton.getAttribute("pageproxystate") == "valid") {
|
2006-09-14 09:57:38 +04:00
|
|
|
nsDragAndDrop.startDrag(aEvent, proxyIconDNDObserver);
|
2006-09-14 09:59:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2006-09-14 09:57:14 +04:00
|
|
|
}
|
2006-09-14 09:57:38 +04:00
|
|
|
|
2006-09-14 10:07:18 +04:00
|
|
|
function handlePageProxyClick(aEvent)
|
|
|
|
{
|
|
|
|
switch (aEvent.button) {
|
|
|
|
case 0:
|
|
|
|
// bug 52784 - select location field contents
|
|
|
|
gURLBar.select();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// bug 111337 - load url/keyword from clipboard
|
|
|
|
return middleMousePaste(aEvent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:59:05 +04:00
|
|
|
function updateComponentBarBroadcaster()
|
|
|
|
{
|
|
|
|
var compBarBroadcaster = document.getElementById('cmd_viewcomponentbar');
|
|
|
|
var taskBarBroadcaster = document.getElementById('cmd_viewtaskbar');
|
|
|
|
var compBar = document.getElementById('component-bar');
|
|
|
|
if (taskBarBroadcaster.getAttribute('checked') == 'true') {
|
|
|
|
compBarBroadcaster.removeAttribute('disabled');
|
|
|
|
if (compBar.getAttribute('hidden') != 'true')
|
|
|
|
compBarBroadcaster.setAttribute('checked', 'true');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
compBarBroadcaster.setAttribute('disabled', 'true');
|
|
|
|
compBarBroadcaster.removeAttribute('checked');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateToolbarStates(toolbarMenuElt)
|
|
|
|
{
|
|
|
|
updateComponentBarBroadcaster();
|
2006-09-14 10:04:26 +04:00
|
|
|
|
|
|
|
const tabbarMenuItem = document.getElementById("menuitem_showhide_tabbar");
|
|
|
|
// Make show/hide menu item reflect current state
|
|
|
|
const visibility = gBrowser.getStripVisibility();
|
|
|
|
tabbarMenuItem.setAttribute("checked", visibility);
|
|
|
|
|
|
|
|
// Don't allow the tab bar to be shown/hidden when more than one tab is open
|
|
|
|
// or when we have 1 tab and the autoHide pref is set
|
|
|
|
const disabled = gBrowser.browsers.length > 1 ||
|
|
|
|
pref.getBoolPref("browser.tabs.autoHide");
|
|
|
|
tabbarMenuItem.setAttribute("disabled", disabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showHideTabbar()
|
|
|
|
{
|
|
|
|
const visibility = gBrowser.getStripVisibility();
|
|
|
|
pref.setBoolPref("browser.tabs.forceHide", visibility);
|
|
|
|
gBrowser.setStripVisibilityTo(!visibility);
|
2006-09-14 09:59:05 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:03:18 +04:00
|
|
|
function BrowserFullScreen()
|
|
|
|
{
|
|
|
|
window.fullScreen = !window.fullScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFullScreen()
|
|
|
|
{
|
|
|
|
FullScreen.toggle();
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:07:22 +04:00
|
|
|
function onPopupWindow(aEvent) {
|
|
|
|
var firstPopup = pref.getBoolPref("privacy.popups.first_popup");
|
|
|
|
var blockingEnabled = pref.getBoolPref("dom.disable_open_during_load");
|
|
|
|
if (blockingEnabled) {
|
|
|
|
pref.setBoolPref("privacy.popups.first_popup", false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (firstPopup) {
|
|
|
|
var showDialog = true;
|
|
|
|
var specialList = "";
|
|
|
|
try {
|
|
|
|
specialList = pref.getComplexValue("privacy.popups.default_whitelist",
|
|
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
|
|
|
}
|
|
|
|
catch(ex) { }
|
|
|
|
if (specialList) {
|
|
|
|
hosts = specialList.split(",");
|
|
|
|
var browser = getBrowserForDocument(aEvent.target);
|
|
|
|
if (!browser)
|
|
|
|
return;
|
|
|
|
var currentHost = browser.currentURI.hostPort;
|
|
|
|
for (var i = 0; i < hosts.length; i++) {
|
|
|
|
var nextHost = hosts[i];
|
|
|
|
if (nextHost == currentHost ||
|
|
|
|
"."+nextHost == currentHost.substr(currentHost.length - (nextHost.length+1))) {
|
|
|
|
showDialog = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showDialog) {
|
2006-09-14 10:10:37 +04:00
|
|
|
window.openDialog("chrome://communicator/content/permissions/aboutPopups.xul", "",
|
2006-09-14 10:08:10 +04:00
|
|
|
"chrome,centerscreen,dependent", true);
|
2006-09-14 10:07:22 +04:00
|
|
|
pref.setBoolPref("privacy.popups.first_popup", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-14 10:06:48 +04:00
|
|
|
|
|
|
|
function onPopupBlocked(aEvent) {
|
|
|
|
var playSound = pref.getBoolPref("privacy.popups.sound_enabled");
|
|
|
|
|
|
|
|
if (playSound) {
|
|
|
|
var sound = Components.classes["@mozilla.org/sound;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISound);
|
|
|
|
|
|
|
|
var soundUrlSpec = pref.getCharPref("privacy.popups.sound_url");
|
|
|
|
|
|
|
|
if (!soundUrlSpec)
|
|
|
|
sound.beep();
|
|
|
|
|
|
|
|
if (soundUrlSpec.substr(0, 7) == "file://") {
|
|
|
|
var soundUrl = Components.classes["@mozilla.org/network/standard-url;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIFileURL);
|
|
|
|
soundUrl.spec = soundUrlSpec;
|
|
|
|
var file = soundUrl.file;
|
|
|
|
if (file.exists)
|
|
|
|
sound.play(soundUrl);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sound.playSystemSound(soundUrlSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var showIcon = pref.getBoolPref("privacy.popups.statusbar_icon_enabled");
|
|
|
|
if (showIcon) {
|
2006-09-14 10:07:22 +04:00
|
|
|
var browser = getBrowserForDocument(aEvent.target);
|
|
|
|
if (browser) {
|
|
|
|
var hostPort = browser.currentURI.hostPort;
|
|
|
|
browser.popupDomain = hostPort;
|
|
|
|
if (browser == getBrowser().selectedBrowser) {
|
|
|
|
var popupIcon = document.getElementById("popupIcon");
|
|
|
|
popupIcon.hidden = false;
|
2006-09-14 10:08:19 +04:00
|
|
|
}
|
2006-09-14 10:09:26 +04:00
|
|
|
// Check for duplicates, remove the old occurence of this url,
|
|
|
|
// to update the features, and put it at the end of the list.
|
|
|
|
for (var i = 0; i < browser.popupUrls.length; ++i) {
|
|
|
|
if (browser.popupUrls[i].equals(aEvent.popupWindowURI)) {
|
|
|
|
browser.popupUrls.splice(i, 1);
|
|
|
|
browser.popupFeatures.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Limit the length of the menu to some reasonable size.
|
|
|
|
// We only add one item every time, so no need for more complex stuff.
|
|
|
|
if (browser.popupUrls.length >= 100) {
|
|
|
|
browser.popupUrls.shift();
|
|
|
|
browser.popupFeatures.shift();
|
|
|
|
}
|
|
|
|
browser.popupUrls.push(aEvent.popupWindowURI);
|
|
|
|
browser.popupFeatures.push(aEvent.popupWindowFeatures);
|
2006-09-14 10:06:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:07:22 +04:00
|
|
|
function getBrowserForDocument(doc) {
|
|
|
|
var browsers = getBrowser().browsers;
|
|
|
|
for (var i = 0; i < browsers.length; i++) {
|
|
|
|
if (browsers[i].contentDocument == doc)
|
|
|
|
return browsers[i];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:06:49 +04:00
|
|
|
function StatusbarViewPopupManager() {
|
2006-09-14 10:06:48 +04:00
|
|
|
var hostPort = "";
|
|
|
|
try {
|
|
|
|
hostPort = getBrowser().selectedBrowser.currentURI.hostPort;
|
|
|
|
}
|
|
|
|
catch(ex) { }
|
|
|
|
|
2006-09-14 10:07:22 +04:00
|
|
|
// open whitelist with site prefilled to unblock
|
2006-09-14 10:11:26 +04:00
|
|
|
viewPopups(hostPort);
|
2006-09-14 10:06:48 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:09:26 +04:00
|
|
|
function popupBlockerMenuShowing(event) {
|
|
|
|
var separator = document.getElementById("popupMenuSeparator");
|
|
|
|
|
2006-09-14 10:10:19 +04:00
|
|
|
if (separator)
|
|
|
|
separator.hidden = !createShowPopupsMenu(event.target);
|
2006-09-14 10:09:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function createShowPopupsMenu(parent) {
|
|
|
|
while (parent.lastChild && parent.lastChild.hasAttribute("uri"))
|
|
|
|
parent.removeChild(parent.lastChild);
|
|
|
|
|
|
|
|
var browser = getBrowser().selectedBrowser;
|
|
|
|
|
2006-09-14 10:10:19 +04:00
|
|
|
if (browser.popupUrls.length == 0)
|
|
|
|
return false;
|
|
|
|
|
2006-09-14 10:09:26 +04:00
|
|
|
for (var i = 0; i < browser.popupUrls.length; i++) {
|
|
|
|
var menuitem = document.createElement("menuitem");
|
|
|
|
menuitem.setAttribute("label", gNavigatorBundle.getFormattedString('popupMenuShow', [browser.popupUrls[i].spec]));
|
|
|
|
menuitem.setAttribute("uri", browser.popupUrls[i].spec);
|
|
|
|
menuitem.setAttribute("features", browser.popupFeatures[i]);
|
|
|
|
parent.appendChild(menuitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function popupBlockerMenuCommand(target) {
|
|
|
|
var uri = target.getAttribute("uri");
|
|
|
|
if (uri) {
|
|
|
|
window.content.open(uri, "", target.getAttribute("features"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:03:46 +04:00
|
|
|
function toHistory()
|
|
|
|
{
|
2006-09-14 10:08:07 +04:00
|
|
|
toOpenWindowByType("history:manager", "chrome://communicator/content/history/history.xul");
|
2006-09-14 10:03:46 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 10:04:04 +04:00
|
|
|
function checkTheme()
|
|
|
|
{
|
|
|
|
var theSkinKids = document.getElementById("theme");
|
|
|
|
var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
2006-09-14 10:09:58 +04:00
|
|
|
.getService(Components.interfaces.nsIChromeRegistrySea);
|
2006-09-14 10:04:04 +04:00
|
|
|
for (var i = 0; i < theSkinKids.childNodes.length; ++i) {
|
|
|
|
var child = theSkinKids.childNodes[i];
|
|
|
|
var id=child.getAttribute("id");
|
|
|
|
if (id.length > 0) {
|
|
|
|
var themeName = id.substring('urn:mozilla:skin:'.length, id.length);
|
|
|
|
var selected = chromeRegistry.isSkinSelected(themeName, true);
|
|
|
|
if (selected == Components.interfaces.nsIChromeRegistry.FULL) {
|
|
|
|
var menuitem=document.getElementById(id);
|
|
|
|
menuitem.setAttribute("checked", true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-14 10:05:18 +04:00
|
|
|
|
|
|
|
// opener may not have been initialized by load time (chrome windows only)
|
|
|
|
// so call this function some time later.
|
|
|
|
function maybeInitPopupContext()
|
|
|
|
{
|
|
|
|
// it's not a popup with no opener
|
|
|
|
if (!window.content.opener)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// are we a popup window?
|
|
|
|
const CI = Components.interfaces;
|
|
|
|
var xulwin = window
|
|
|
|
.QueryInterface(CI.nsIInterfaceRequestor)
|
|
|
|
.getInterface(CI.nsIWebNavigation)
|
|
|
|
.QueryInterface(CI.nsIDocShellTreeItem).treeOwner
|
|
|
|
.QueryInterface(CI.nsIInterfaceRequestor)
|
|
|
|
.getInterface(CI.nsIXULWindow);
|
|
|
|
if (xulwin.contextFlags &
|
|
|
|
CI.nsIWindowCreator2.PARENT_IS_LOADING_OR_RUNNING_TIMEOUT) {
|
|
|
|
// return our opener's URI
|
|
|
|
const IOS = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(CI.nsIIOService);
|
2006-09-14 10:11:05 +04:00
|
|
|
return IOS.newURI(window.content.opener.location.href, null, null);
|
2006-09-14 10:05:18 +04:00
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2006-09-14 10:07:42 +04:00
|
|
|
|
|
|
|
function WindowIsClosing()
|
|
|
|
{
|
|
|
|
var browser = getBrowser();
|
2006-09-14 10:08:22 +04:00
|
|
|
var cn = browser.tabContainer.childNodes;
|
2006-09-14 10:08:21 +04:00
|
|
|
var numtabs = cn.length;
|
2006-09-14 10:07:42 +04:00
|
|
|
var reallyClose = true;
|
|
|
|
|
|
|
|
if (numtabs > 1) {
|
|
|
|
var shouldPrompt = pref.getBoolPref("browser.tabs.warnOnClose");
|
|
|
|
if (shouldPrompt) {
|
|
|
|
var promptService =
|
|
|
|
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPromptService);
|
|
|
|
//default to true: if it were false, we wouldn't get this far
|
|
|
|
var warnOnClose = {value:true};
|
|
|
|
|
|
|
|
var buttonPressed = promptService.confirmEx(window,
|
|
|
|
gNavigatorBundle.getString('tabs.closeWarningTitle'),
|
|
|
|
gNavigatorBundle.getFormattedString("tabs.closeWarning", [numtabs]),
|
|
|
|
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0)
|
|
|
|
+ (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
|
|
|
|
gNavigatorBundle.getString('tabs.closeButton'),
|
|
|
|
null, null,
|
|
|
|
gNavigatorBundle.getString('tabs.closeWarningPromptMe'),
|
|
|
|
warnOnClose);
|
|
|
|
reallyClose = (buttonPressed == 0);
|
|
|
|
//don't set the pref unless they press OK and it's false
|
|
|
|
if (reallyClose && !warnOnClose.value) {
|
|
|
|
pref.setBoolPref("browser.tabs.warnOnClose", false);
|
|
|
|
}
|
|
|
|
} //if the warn-me pref was true
|
|
|
|
} //if multiple tabs are open
|
2006-09-14 10:08:21 +04:00
|
|
|
|
|
|
|
for (var i = 0; reallyClose && i < numtabs; ++i) {
|
|
|
|
var ds = browser.getBrowserForTab(cn[i]).docShell;
|
|
|
|
|
|
|
|
if (ds.contentViewer && !ds.contentViewer.permitUnload())
|
|
|
|
reallyClose = false;
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:07:42 +04:00
|
|
|
return reallyClose;
|
|
|
|
}
|
2006-09-14 10:08:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* file upload support
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This function returns the URI of the currently focused content frame
|
|
|
|
* or frameset.
|
|
|
|
*/
|
|
|
|
function getCurrentURI()
|
|
|
|
{
|
|
|
|
const CI = Components.interfaces;
|
|
|
|
|
|
|
|
var focusedWindow = document.commandDispatcher.focusedWindow;
|
|
|
|
var contentFrame = isContentFrame(focusedWindow) ? focusedWindow : window.content;
|
|
|
|
|
|
|
|
var nav = contentFrame.QueryInterface(CI.nsIInterfaceRequestor)
|
|
|
|
.getInterface(CI.nsIWebNavigation);
|
|
|
|
return nav.currentURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadFile(fileURL)
|
|
|
|
{
|
|
|
|
const CI = Components.interfaces;
|
|
|
|
|
|
|
|
var targetBaseURI = getCurrentURI();
|
|
|
|
|
|
|
|
// generate the target URI. we use fileURL.file.leafName to get the
|
|
|
|
// unicode value of the target filename w/o any URI-escaped chars.
|
|
|
|
// this gives the protocol handler the best chance of generating a
|
|
|
|
// properly formatted URI spec. we pass null for the origin charset
|
|
|
|
// parameter since we want the URI to inherit the origin charset
|
|
|
|
// property from targetBaseURI.
|
|
|
|
|
|
|
|
var leafName = fileURL.file.leafName;
|
|
|
|
|
|
|
|
const IOS = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(CI.nsIIOService);
|
|
|
|
var targetURI = IOS.newURI(leafName, null, targetBaseURI);
|
|
|
|
|
|
|
|
// ok, start uploading...
|
|
|
|
|
|
|
|
var dialog = Components.classes["@mozilla.org/progressdialog;1"]
|
|
|
|
.createInstance(CI.nsIProgressDialog);
|
|
|
|
|
|
|
|
var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
|
|
|
|
.createInstance(CI.nsIWebBrowserPersist);
|
|
|
|
|
2006-09-14 10:11:13 +04:00
|
|
|
dialog.init(fileURL, targetURI, leafName, null, Date.now()*1000, null, persist);
|
2006-09-14 10:08:57 +04:00
|
|
|
dialog.open(window);
|
|
|
|
|
|
|
|
persist.progressListener = dialog;
|
|
|
|
persist.saveURI(fileURL, null, null, null, null, targetURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
function BrowserUploadFile()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
uploadFile(selectFileToOpen("uploadFile", "browser.upload."));
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is called whenever the file menu is about to be displayed.
|
|
|
|
* Enable the upload menu item if appropriate. */
|
|
|
|
function updateFileUploadItem()
|
|
|
|
{
|
|
|
|
var canUpload = false;
|
|
|
|
try {
|
|
|
|
canUpload = getCurrentURI().schemeIs('ftp');
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
var item = document.getElementById('Browser:UploadFile');
|
|
|
|
if (canUpload)
|
|
|
|
item.removeAttribute('disabled');
|
|
|
|
else
|
|
|
|
item.setAttribute('disabled', 'true');
|
|
|
|
}
|
2006-09-14 10:10:09 +04:00
|
|
|
|
|
|
|
function isBidiEnabled()
|
|
|
|
{
|
|
|
|
var rv = false;
|
|
|
|
|
|
|
|
var systemLocale;
|
|
|
|
try {
|
|
|
|
var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
|
2006-09-14 10:11:08 +04:00
|
|
|
.getService(Components.interfaces.nsILocaleService);
|
2006-09-14 10:10:09 +04:00
|
|
|
systemLocale = localeService.getSystemLocale().getCategory("NSILOCALE_CTYPE");
|
|
|
|
rv = /^(he|ar|syr|fa|ur)-/.test(systemLocale);
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
if (!rv) {
|
|
|
|
// check the overriding pref
|
2006-09-14 10:11:08 +04:00
|
|
|
rv = pref.getBoolPref("bidi.browser.ui");
|
2006-09-14 10:10:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
function SwitchDocumentDirection(aWindow)
|
|
|
|
{
|
|
|
|
aWindow.document.dir = (aWindow.document.dir == "ltr" ? "rtl" : "ltr");
|
|
|
|
|
|
|
|
for (var run = 0; run < aWindow.frames.length; run++)
|
|
|
|
SwitchDocumentDirection(aWindow.frames[run]);
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:10:18 +04:00
|
|
|
function updateSavePageItems()
|
|
|
|
{
|
|
|
|
var autoDownload = pref.getBoolPref("browser.download.autoDownload");
|
|
|
|
goSetMenuValue("savepage", autoDownload ? "valueSave" : "valueSaveAs");
|
|
|
|
}
|
2006-09-14 10:11:06 +04:00
|
|
|
|
|
|
|
function convertFromUnicode(charset, str)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var unicodeConverter = Components
|
|
|
|
.classes["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
|
|
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
|
|
|
|
unicodeConverter.charset = charset;
|
|
|
|
str = unicodeConverter.ConvertFromUnicode(str);
|
|
|
|
return str + unicodeConverter.Finish();
|
|
|
|
} catch(ex) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|