2006-09-14 09:59:50 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-07-02 02:56:04 +04:00
|
|
|
*
|
2006-09-14 09:59:50 +04:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
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 09:59:50 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
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 09:59:50 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-07-02 02:56:04 +04:00
|
|
|
|
2006-09-14 09:59:24 +04:00
|
|
|
const XREMOTESERVICE_CONTRACTID = "@mozilla.org/browser/xremoteservice;1";
|
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 09:59:05 +04:00
|
|
|
var gHaveUpdatedToolbarState = false;
|
2006-09-14 09:58:58 +04:00
|
|
|
var gClickSelectsAll = -1;
|
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",
|
|
|
|
observe: function(subject, topic, prefName)
|
|
|
|
{
|
|
|
|
// verify that we're changing a button pref
|
|
|
|
if (topic != "nsPref:changed")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var buttonName = prefName.substr(this.domain.length+1);
|
|
|
|
var buttonId = buttonName + "-button";
|
|
|
|
var button = document.getElementById(buttonId);
|
|
|
|
|
2006-09-14 10:03:32 +04:00
|
|
|
// We need to explicitly set "hidden" to "false"
|
|
|
|
// in order for persistence to work correctly
|
2006-09-14 10:03:31 +04:00
|
|
|
var show = pref.getBoolPref(prefName);
|
2006-09-14 10:03:32 +04:00
|
|
|
if (show)
|
|
|
|
button.setAttribute("hidden","false");
|
|
|
|
else
|
|
|
|
button.setAttribute("hidden", "true");
|
2006-09-14 10:03:31 +04:00
|
|
|
|
|
|
|
// If all buttons before the separator are hidden, also hide the separator
|
2006-09-14 10:03:32 +04:00
|
|
|
if (allLeftButtonsAreHidden())
|
|
|
|
document.getElementById("home-bm-separator").setAttribute("hidden", "true");
|
|
|
|
else
|
|
|
|
document.getElementById("home-bm-separator").removeAttribute("hidden");
|
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;
|
|
|
|
|
|
|
|
var stripVisibility = !pref.getBoolPref(prefName);
|
|
|
|
if (gBrowser.mTabContainer.childNodes.length == 1)
|
|
|
|
gBrowser.setStripVisibilityTo(stripVisibility);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 {
|
|
|
|
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
|
|
|
|
pbi.addObserver(observer.domain, observer, false);
|
|
|
|
} catch(ex) {
|
|
|
|
dump("Failed to observe prefs: " + ex + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removePrefListener(observer)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
|
|
|
|
pbi.removeObserver(observer.domain, observer);
|
|
|
|
} catch(ex) {
|
|
|
|
dump("Failed to remove pref observer: " + ex + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 09:55:03 +04:00
|
|
|
function loadEventHandlers(event)
|
|
|
|
{
|
|
|
|
// Filter out events that are not about the document load we are interested in
|
2006-09-14 09:59:56 +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()
|
|
|
|
{
|
|
|
|
var saveFrameItem = document.getElementById("savepage");
|
2006-09-14 09:55:32 +04:00
|
|
|
if (!_content.frames.length || !isDocumentFrame(document.commandDispatcher.focusedWindow))
|
2006-09-14 09:50:25 +04:00
|
|
|
saveFrameItem.setAttribute("hidden", "true");
|
2006-09-14 09:55:08 +04:00
|
|
|
else
|
2006-09-14 09:50:25 +04:00
|
|
|
saveFrameItem.removeAttribute("hidden");
|
|
|
|
}
|
|
|
|
|
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 09:55:36 +04:00
|
|
|
var focusedWindow = document.commandDispatcher.focusedWindow;
|
|
|
|
if (isDocumentFrame(focusedWindow)) {
|
2006-09-14 09:50:25 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////// 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:03:23 +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:01:35 +04:00
|
|
|
var url = getWebNavigation().currentURI.spec
|
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 09:55:08 +04:00
|
|
|
if (url) {
|
|
|
|
try {
|
2006-09-14 10:01:09 +04:00
|
|
|
var autoOpenSearchPanel =
|
|
|
|
pref.getBoolPref("browser.search.opensidebarsearchpanel");
|
2006-09-14 09:47:52 +04:00
|
|
|
|
2006-09-14 10:01:09 +04:00
|
|
|
if (autoOpenSearchPanel || isSearchPanelOpen())
|
|
|
|
{
|
2006-09-14 10:01:17 +04:00
|
|
|
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:01:17 +04:00
|
|
|
var searchInProgressFlag = gSearchService.FindInternetSearchResults(url);
|
2006-09-14 09:47:52 +04:00
|
|
|
|
2006-09-14 10:01:09 +04:00
|
|
|
if (searchInProgressFlag) {
|
|
|
|
if (autoOpenSearchPanel)
|
|
|
|
RevealSearchPanel();
|
|
|
|
}
|
2006-09-14 09:55:08 +04:00
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
}
|
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()
|
|
|
|
{
|
|
|
|
var url;
|
|
|
|
try {
|
2006-09-14 10:00:34 +04:00
|
|
|
url = pref.getComplexValue("browser.startup.homepage",
|
2006-09-14 10:00:40 +04:00
|
|
|
Components.interfaces.nsIPrefLocalizedString).data;
|
2006-09-14 09:55:03 +04:00
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// use this if we can't find the pref
|
|
|
|
if (!url)
|
2006-09-14 09:56:13 +04:00
|
|
|
url = gNavigatorRegionBundle.getString("homePageDefault");
|
2006-09-14 09:55:03 +04:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
var webNavigation = getWebNavigation();
|
|
|
|
|
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");
|
|
|
|
if (backDisabled == webNavigation.canGoBack) {
|
|
|
|
if (backDisabled)
|
|
|
|
backBroadcaster.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
backBroadcaster.setAttribute("disabled", true);
|
|
|
|
}
|
|
|
|
if (forwardDisabled == webNavigation.canGoForward) {
|
|
|
|
if (forwardDisabled)
|
|
|
|
forwardBroadcaster.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
forwardBroadcaster.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 09:59:35 +04:00
|
|
|
var buttonNode = document.getElementById("PersonalToolbar").firstChild;
|
|
|
|
while(buttonNode.tagName != "toolbarseparator") {
|
|
|
|
if(!buttonNode.hasAttribute("hidden") || buttonNode.getAttribute("hidden") == "false")
|
|
|
|
return false;
|
|
|
|
buttonNode = buttonNode.nextSibling;
|
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 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 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:
|
|
|
|
|
|
|
|
// set home button tooltip text
|
|
|
|
var homePage = getHomePage();
|
|
|
|
if (homePage)
|
|
|
|
document.getElementById("home-button").setAttribute("tooltiptext", homePage);
|
|
|
|
|
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:03:31 +04:00
|
|
|
|
|
|
|
addPrefListener(gButtonPrefListener);
|
|
|
|
addPrefListener(gTabStripPrefListener);
|
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");
|
|
|
|
contentArea.addEventListener("load", loadEventHandlers, true);
|
|
|
|
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 10:01:47 +04:00
|
|
|
// XXXjag work-around for bug 113076
|
|
|
|
// there's another bug where we throw an exception when getting
|
|
|
|
// sessionHistory if it is null, which I'm exploiting here to
|
|
|
|
// detect the situation described in bug 113076.
|
2006-09-14 10:04:05 +04:00
|
|
|
// The same problem caused bug 139522, also worked around below.
|
2006-09-14 10:01:47 +04:00
|
|
|
try {
|
|
|
|
getBrowser().sessionHistory;
|
|
|
|
} catch (e) {
|
|
|
|
// sessionHistory wasn't set from the browser's constructor
|
|
|
|
// so we'll just have to set it here.
|
|
|
|
|
|
|
|
// Wire up session and global history before any possible
|
|
|
|
// progress notifications for back/forward button updating
|
|
|
|
webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISHistory);
|
|
|
|
|
|
|
|
// wire up global history. the same applies here.
|
|
|
|
var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"]
|
|
|
|
.getService(Components.interfaces.nsIGlobalHistory);
|
|
|
|
getBrowser().docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).globalHistory = globalHistory;
|
2006-09-14 10:04:05 +04:00
|
|
|
|
|
|
|
const selectedBrowser = getBrowser().selectedBrowser;
|
|
|
|
if (selectedBrowser.securityUI)
|
|
|
|
selectedBrowser.securityUI.init(selectedBrowser.contentWindow);
|
2006-09-14 10:01:47 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:56:43 +04:00
|
|
|
// hook up UI through progress listener
|
2006-09-14 09:59:38 +04:00
|
|
|
getBrowser().addProgressListener(window.XULBrowserWindow);
|
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 09:57:04 +04:00
|
|
|
var uriToLoad;
|
2006-09-14 09:55:34 +04:00
|
|
|
|
2006-09-14 09:59:00 +04:00
|
|
|
// Check for window.arguments[0]. If present, use that for uriToLoad.
|
|
|
|
if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0])
|
|
|
|
uriToLoad = window.arguments[0];
|
|
|
|
|
2006-09-14 09:57:04 +04:00
|
|
|
if (uriToLoad && uriToLoad != "about:blank") {
|
|
|
|
gURLBar.value = uriToLoad;
|
2006-09-14 10:03:57 +04:00
|
|
|
if ("arguments" in window && window.arguments.length >= 3) {
|
|
|
|
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:03:57 +04:00
|
|
|
// Focus the content area unless we're loading a blank page
|
2006-09-14 10:04:00 +04:00
|
|
|
var navBar = document.getElementById("nav-bar");
|
|
|
|
if (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
|
|
|
|
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
|
|
|
|
|
|
|
// hook up remote support
|
|
|
|
if (XREMOTESERVICE_CONTRACTID in Components.classes) {
|
|
|
|
var remoteService;
|
|
|
|
remoteService = Components.classes[XREMOTESERVICE_CONTRACTID]
|
|
|
|
.getService(Components.interfaces.nsIXRemoteService);
|
|
|
|
remoteService.addBrowserInstance(window);
|
|
|
|
}
|
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
|
|
|
|
addEventListener("fullscreen", onFullScreen, 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:03:18 +04:00
|
|
|
|
2006-09-14 10:00:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function LoadBookmarksCallback()
|
|
|
|
{
|
|
|
|
try {
|
2006-09-14 10:01:17 +04:00
|
|
|
if (!gBookmarksService)
|
|
|
|
gBookmarksService = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIBookmarksService);
|
|
|
|
gBookmarksService.ReadBookmarks();
|
2006-09-14 10:00:53 +04:00
|
|
|
// tickle personal toolbar to load personal toolbar items
|
|
|
|
var personalToolbar = document.getElementById("innermostBox");
|
|
|
|
personalToolbar.builder.rebuild();
|
|
|
|
} catch (e) {
|
|
|
|
}
|
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
|
|
|
|
if (element instanceof Components.interfaces.nsIDOMElement)
|
|
|
|
document.commandDispatcher.focusedElement = element;
|
|
|
|
else if (element instanceof Components.interfaces.nsIDOMWindow)
|
|
|
|
document.commandDispatcher.focusedWindow = element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
var history = Components.classes["@mozilla.org/browser/global-history;1"]
|
|
|
|
.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
|
|
|
|
if (XREMOTESERVICE_CONTRACTID in Components.classes) {
|
|
|
|
var remoteService;
|
|
|
|
remoteService = Components.classes[XREMOTESERVICE_CONTRACTID]
|
|
|
|
.getService(Components.interfaces.nsIXRemoteService);
|
|
|
|
remoteService.removeBrowserInstance(window);
|
|
|
|
}
|
|
|
|
|
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 09:57:07 +04:00
|
|
|
window.XULBrowserWindow.destroy();
|
|
|
|
window.XULBrowserWindow = null;
|
|
|
|
|
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 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:00:34 +04:00
|
|
|
var service = pref.getCharPref("browser.translation.service");
|
|
|
|
var serviceDomain = pref.getCharPref("browser.translation.serviceDomain");
|
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 {
|
|
|
|
loadURI(service + escape(targetURI));
|
|
|
|
}
|
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;
|
|
|
|
try {
|
2006-09-14 09:55:03 +04:00
|
|
|
getWebNavigation().gotoIndex(index);
|
2006-09-14 09:44:15 +04:00
|
|
|
}
|
2006-09-14 09:56:14 +04:00
|
|
|
catch(ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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 {
|
|
|
|
getWebNavigation().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 09:50:13 +04:00
|
|
|
function BrowserForward()
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
2006-09-14 09:56:14 +04:00
|
|
|
try {
|
|
|
|
getWebNavigation().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 09:50:13 +04:00
|
|
|
function BrowserBackMenu(event)
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
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 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 09:50:13 +04:00
|
|
|
function BrowserHome()
|
2006-09-14 09:55:03 +04:00
|
|
|
{
|
|
|
|
var homePage = getHomePage();
|
|
|
|
loadURI(homePage);
|
|
|
|
}
|
2006-09-14 09:49:08 +04:00
|
|
|
|
2006-09-14 10:03:34 +04:00
|
|
|
function OpenBookmarkGroup(element, datasource)
|
|
|
|
{
|
|
|
|
if (!datasource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var id = element.getAttribute("id");
|
|
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIRDFService);
|
|
|
|
var resource = rdf.GetResource(id, true);
|
2006-09-14 10:04:07 +04:00
|
|
|
OpenBookmarkGroupFromResource(resource, datasource, rdf);
|
2006-09-14 10:03:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function OpenBookmarkGroupFromResource(resource, datasource, rdf) {
|
|
|
|
var urlResource = rdf.GetResource("http://home.netscape.com/NC-rdf#URL");
|
|
|
|
var rdfContainer = Components.classes["@mozilla.org/rdf/container;1"].getService(Components.interfaces.nsIRDFContainer);
|
|
|
|
rdfContainer.Init(datasource, resource);
|
|
|
|
var containerChildren = rdfContainer.GetElements();
|
|
|
|
var tabPanels = gBrowser.mPanelContainer.childNodes;
|
|
|
|
var tabCount = tabPanels.length;
|
|
|
|
var index = 0;
|
|
|
|
while (containerChildren.hasMoreElements()) {
|
2006-09-14 10:04:07 +04:00
|
|
|
var res = containerChildren.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
|
|
|
|
var target = datasource.GetTarget(res, urlResource, true);
|
2006-09-14 10:03:34 +04:00
|
|
|
if (target) {
|
|
|
|
var uri = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
|
|
|
if (index < tabCount)
|
|
|
|
tabPanels[index].loadURI(uri, null, nsIWebNavigation.LOAD_FLAGS_NONE);
|
|
|
|
else
|
|
|
|
gBrowser.addTab(uri);
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
return; // If the bookmark group was completely invalid, just bail.
|
|
|
|
|
|
|
|
// Select the first tab in the group.
|
|
|
|
var tabs = gBrowser.mTabContainer.childNodes;
|
|
|
|
gBrowser.selectedTab = tabs[0];
|
|
|
|
|
|
|
|
// Close any remaining open tabs that are left over.
|
|
|
|
for (var i = tabCount-1; i >= index; i--)
|
|
|
|
gBrowser.removeTab(tabs[i]);
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:32 +04:00
|
|
|
function OpenBookmarkURL(node, datasources)
|
2006-09-14 09:54:56 +04:00
|
|
|
{
|
2006-09-14 10:03:34 +04:00
|
|
|
if (node.getAttribute("group") == "true")
|
|
|
|
OpenBookmarkGroup(node, datasources);
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
if (node.getAttribute("container") == "true")
|
2006-09-14 09:55:06 +04:00
|
|
|
return;
|
2006-09-14 09:44:15 +04:00
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
var url = node.getAttribute("id");
|
2006-09-14 10:01:10 +04:00
|
|
|
if (!url) // if empty url (most likely a normal menu item like "Manage Bookmarks",
|
|
|
|
return; // don't bother loading it
|
2006-09-14 09:54:56 +04:00
|
|
|
try {
|
|
|
|
// add support for IE favorites under Win32, and NetPositive URLs under BeOS
|
2006-09-14 09:55:06 +04:00
|
|
|
if (datasources) {
|
|
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIRDFService);
|
2006-09-14 09:54:56 +04:00
|
|
|
var src = rdf.GetResource(url, true);
|
|
|
|
var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
|
|
|
|
var target = datasources.GetTarget(src, prop, true);
|
2006-09-14 09:55:06 +04:00
|
|
|
if (target) {
|
|
|
|
target = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
|
|
|
if (target)
|
|
|
|
url = target;
|
|
|
|
}
|
2006-09-14 09:44:15 +04:00
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
} catch (ex) {
|
|
|
|
return;
|
2006-09-14 09:54:56 +04:00
|
|
|
}
|
2006-09-14 09:55:08 +04:00
|
|
|
|
2006-09-14 09:54:56 +04:00
|
|
|
// Ignore "NC:" urls.
|
|
|
|
if (url.substring(0, 3) == "NC:")
|
2006-09-14 09:55:06 +04:00
|
|
|
return;
|
2006-09-14 09:54:56 +04:00
|
|
|
|
|
|
|
// Check if we have a browser window
|
2006-09-14 09:59:57 +04:00
|
|
|
if (_content) {
|
2006-09-14 09:54:56 +04:00
|
|
|
loadURI(url);
|
2006-09-14 09:59:57 +04:00
|
|
|
_content.focus();
|
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
else
|
|
|
|
openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url);
|
2006-09-14 09:54:56 +04:00
|
|
|
}
|
2006-09-14 09:44:13 +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 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:02:32 +04:00
|
|
|
function OpenSearch(tabName, forceDialogFlag, searchStr, newWindowFlag)
|
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 09:59:51 +04:00
|
|
|
loadURI(gNavigatorRegionBundle.getString("otherSearchURL"));
|
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 09:59:51 +04:00
|
|
|
var searchMode = 0;
|
|
|
|
try {
|
2006-09-14 10:00:34 +04:00
|
|
|
searchMode = pref.getIntPref("browser.search.powermode");
|
2006-09-14 09:59:51 +04:00
|
|
|
} catch(ex) {
|
2006-09-14 09:54:29 +04:00
|
|
|
}
|
2006-09-14 10:01:31 +04:00
|
|
|
|
2006-09-14 09:59:51 +04:00
|
|
|
if (forceDialogFlag || searchMode == 1) {
|
|
|
|
// Use a single search dialog
|
|
|
|
var windowManager = Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"]
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
|
|
|
|
var searchWindow = windowManager.getMostRecentWindow("search:window");
|
|
|
|
if (!searchWindow) {
|
|
|
|
openDialog("chrome://communicator/content/search/search.xul", "SearchWindow", "dialog=no,close,chrome,resizable", tabName, searchStr);
|
|
|
|
} else {
|
|
|
|
// Already had one, focus it and load the page
|
|
|
|
searchWindow.focus();
|
|
|
|
|
|
|
|
if ("loadPage" in searchWindow)
|
|
|
|
searchWindow.loadPage(tabName, searchStr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (searchStr) {
|
|
|
|
var escapedSearchStr = escape(searchStr);
|
|
|
|
defaultSearchURL += escapedSearchStr;
|
|
|
|
var searchDS = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
|
|
|
|
.getService(Components.interfaces.nsIInternetSearchService);
|
|
|
|
|
|
|
|
searchDS.RememberLastSearchText(escapedSearchStr);
|
|
|
|
try {
|
2006-09-14 10:00:34 +04:00
|
|
|
var searchEngineURI = pref.getCharPref("browser.search.defaultengine");
|
2006-09-14 09:59:51 +04:00
|
|
|
if (searchEngineURI) {
|
|
|
|
var searchURL = getSearchUrl("actionButton");
|
|
|
|
if (searchURL) {
|
|
|
|
defaultSearchURL = searchURL + escapedSearchStr;
|
|
|
|
} else {
|
2006-09-14 10:03:39 +04:00
|
|
|
searchURL = searchDS.GetInternetSearchURL(searchEngineURI, escapedSearchStr, 0, 0, {value:0});
|
2006-09-14 09:59:51 +04:00
|
|
|
if (searchURL)
|
|
|
|
defaultSearchURL = searchURL;
|
|
|
|
}
|
2006-09-14 09:58:19 +04:00
|
|
|
}
|
2006-09-14 09:59:51 +04:00
|
|
|
} catch (ex) {
|
2006-09-14 09:55:08 +04:00
|
|
|
}
|
2006-09-14 10:01:31 +04:00
|
|
|
|
2006-09-14 10:02:32 +04:00
|
|
|
if (!newWindowFlag)
|
|
|
|
loadURI(defaultSearchURL);
|
|
|
|
else
|
|
|
|
window.open(defaultSearchURL, "_blank");
|
2006-09-14 09:55:08 +04:00
|
|
|
}
|
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 09:53:14 +04:00
|
|
|
var searchPanel = document.getElementById("urn:sidebar:panel:search");
|
2006-09-14 09:55:32 +04:00
|
|
|
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"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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 09:56:12 +04:00
|
|
|
openDialog("chrome://communicator/content/openLocation.xul", "_blank", "chrome,modal,titlebar", window);
|
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) {
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab('about:blank');
|
|
|
|
setTimeout("gURLBar.focus();", 0);
|
|
|
|
}
|
2006-09-14 09:59:38 +04:00
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
/* Called from the openLocation dialog. This allows that dialog to instruct
|
|
|
|
its opener to open a new window and then step completely out of the way.
|
|
|
|
Anything less byzantine is causing horrible crashes, rather believably,
|
|
|
|
though oddly only on Linux. */
|
|
|
|
function delayedOpenWindow(chrome,flags,url)
|
|
|
|
{
|
|
|
|
setTimeout("openDialog('"+chrome+"','_blank','"+flags+"','"+url+"')", 10);
|
|
|
|
}
|
2006-09-14 09:55:06 +04:00
|
|
|
|
2006-09-14 09:59:44 +04:00
|
|
|
/* Required because the tab needs time to set up its content viewers and get the load of
|
|
|
|
the URI kicked off before becoming the active content area. */
|
|
|
|
function delayedOpenTab(url)
|
|
|
|
{
|
|
|
|
setTimeout(function(aTabElt) { getBrowser().selectedTab = aTabElt; }, 0, getBrowser().addTab(url));
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
function BrowserOpenFileWindow()
|
|
|
|
{
|
|
|
|
// Get filepicker component.
|
|
|
|
try {
|
|
|
|
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
|
|
|
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
|
2006-09-14 09:55:56 +04:00
|
|
|
fp.init(window, gNavigatorBundle.getString("openFile"), nsIFilePicker.modeOpen);
|
2006-09-14 09:55:03 +04:00
|
|
|
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText | nsIFilePicker.filterImages |
|
|
|
|
nsIFilePicker.filterXML | nsIFilePicker.filterHTML);
|
|
|
|
|
|
|
|
if (fp.show() == nsIFilePicker.returnOK)
|
|
|
|
openTopWin(fp.fileURL.spec);
|
|
|
|
} catch (ex) {
|
2006-09-14 09:44:15 +04:00
|
|
|
}
|
2006-09-14 09:55:03 +04:00
|
|
|
}
|
2006-09-14 09:44:15 +04:00
|
|
|
|
2006-09-14 09:55:04 +04:00
|
|
|
// Set up a lame hack to avoid opening two bookmarks.
|
|
|
|
// Could otherwise happen with two Ctrl-B's in a row.
|
2006-09-14 09:40:47 +04:00
|
|
|
var gDisableBookmarks = false;
|
2006-09-14 09:55:03 +04:00
|
|
|
function enableBookmarks()
|
|
|
|
{
|
2006-09-14 09:40:47 +04:00
|
|
|
gDisableBookmarks = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function BrowserEditBookmarks()
|
2006-09-14 09:55:06 +04:00
|
|
|
{
|
2006-09-14 09:40:47 +04:00
|
|
|
// Use a single sidebar bookmarks dialog
|
2006-09-14 09:55:03 +04:00
|
|
|
var windowManager = Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"]
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
2006-09-14 09:40:47 +04:00
|
|
|
|
2006-09-14 09:55:03 +04:00
|
|
|
var bookmarksWindow = windowManager.getMostRecentWindow("bookmarks:manager");
|
2006-09-14 09:40:47 +04:00
|
|
|
|
2006-09-14 09:44:15 +04:00
|
|
|
if (bookmarksWindow) {
|
2006-09-14 09:40:47 +04:00
|
|
|
bookmarksWindow.focus();
|
2006-09-14 09:44:15 +04:00
|
|
|
} else {
|
2006-09-14 09:55:03 +04:00
|
|
|
// while disabled, don't open new bookmarks window
|
|
|
|
if (!gDisableBookmarks) {
|
|
|
|
gDisableBookmarks = true;
|
2006-09-14 09:40:47 +04:00
|
|
|
|
2006-09-14 10:01:29 +04:00
|
|
|
open("chrome://communicator/content/bookmarks/bookmarks.xul", "_blank",
|
|
|
|
"chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
|
2006-09-14 09:55:03 +04:00
|
|
|
setTimeout(enableBookmarks, 2000);
|
|
|
|
}
|
1999-07-02 02:56:04 +04:00
|
|
|
}
|
2006-09-14 09:40:47 +04:00
|
|
|
}
|
1999-07-02 02:56:04 +04:00
|
|
|
|
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();
|
|
|
|
if (browser && browser.localName == 'tabbrowser' && browser.mTabContainer.childNodes.length > 1) {
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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:02:24 +04:00
|
|
|
function loadURI(uri, referrer)
|
2006-09-14 09:55:02 +04:00
|
|
|
{
|
2006-09-14 09:55:06 +04:00
|
|
|
try {
|
2006-09-14 10:02:24 +04:00
|
|
|
getWebNavigation().loadURI(uri, nsIWebNavigation.LOAD_FLAGS_NONE, referrer, null, null);
|
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 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:02:25 +04:00
|
|
|
if (pref && pref.getBoolPref("browser.tabs.opentabfor.urlbar") &&
|
|
|
|
getBrowser().localName == "tabbrowser" &&
|
|
|
|
aTriggeringEvent && 'ctrlKey' in aTriggeringEvent &&
|
|
|
|
aTriggeringEvent.ctrlKey) {
|
2006-09-14 09:59:42 +04:00
|
|
|
var t = getBrowser().addTab(getShortcutOrURI(url)); // open link in new tab
|
|
|
|
getBrowser().selectedTab = t;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
loadURI(getShortcutOrURI(url));
|
2006-09-14 09:57:51 +04:00
|
|
|
_content.focus();
|
|
|
|
}
|
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 09:55:06 +04:00
|
|
|
if (shortcutURL && text) {
|
|
|
|
aOffset = shortcutURL.indexOf("%s");
|
|
|
|
if (aOffset >= 0)
|
|
|
|
shortcutURL = shortcutURL.substr(0, aOffset) + text + shortcutURL.substr(aOffset+2);
|
|
|
|
else
|
|
|
|
shortcutURL = null;
|
|
|
|
}
|
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");
|
|
|
|
clipboard.getData(trans, clipboard.kSelectionClipboard);
|
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) {
|
|
|
|
data = data.value.QueryInterface(Components.interfaces.nsISupportsWString);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function OpenMessenger()
|
|
|
|
{
|
2006-09-14 10:01:29 +04:00
|
|
|
open("chrome://messenger/content/messenger.xul", "_blank",
|
|
|
|
"chrome,extrachrome,menubar,resizable,status,toolbar");
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function OpenAddressbook()
|
|
|
|
{
|
2006-09-14 10:01:29 +04:00
|
|
|
open("chrome://messenger/content/addressbook/addressbook.xul", "_blank",
|
|
|
|
"chrome,extrachrome,menubar,resizable,status,toolbar");
|
2006-09-14 09:55:06 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// cannot be found, then just use the _content window...
|
|
|
|
//
|
|
|
|
// XXX: This is a bit of a hack...
|
|
|
|
win = aDocument.defaultView;
|
|
|
|
if (win == window) {
|
|
|
|
win = _content;
|
|
|
|
}
|
|
|
|
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",
|
|
|
|
"scrollbars,resizable,chrome,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 09:56:23 +04:00
|
|
|
function BrowserPageInfo(doc)
|
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",
|
|
|
|
doc);
|
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:00:00 +04:00
|
|
|
var disabledItems = ['cmd_close', 'Browser:SendPage', 'Browser:EditPage', 'Browser:PrintSetup', /*'Browser:PrintPreview',*/
|
2006-09-14 09:55:06 +04:00
|
|
|
'Browser:Print', 'canGoBack', 'canGoForward', 'Browser:Home', 'Browser:AddBookmark', 'cmd_undo',
|
2006-09-14 10:01:33 +04:00
|
|
|
'cmd_redo', 'cmd_cut', 'cmd_copy','cmd_paste', 'cmd_delete', 'cmd_selectAll', 'menu_textZoom'];
|
|
|
|
for (var id in disabledItems) {
|
2006-09-14 09:55:06 +04:00
|
|
|
var broadcaster = document.getElementById(disabledItems[id]);
|
|
|
|
if (broadcaster)
|
|
|
|
broadcaster.setAttribute("disabled", "true");
|
|
|
|
}
|
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);
|
|
|
|
leakDetector.traceObject(_content, leakDetector.verbose);
|
|
|
|
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 09:56:02 +04:00
|
|
|
if ( "HTTPIndex" in _content &&
|
|
|
|
_content.HTTPIndex instanceof Components.interfaces.nsIHTTPIndex ) {
|
2006-09-14 09:55:55 +04:00
|
|
|
_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)
|
|
|
|
{
|
|
|
|
var itemNoOptStyles = menuPopup.firstChild;
|
|
|
|
while (itemNoOptStyles.nextSibling)
|
|
|
|
menuPopup.removeChild(itemNoOptStyles.nextSibling);
|
2006-09-14 09:52:28 +04:00
|
|
|
|
2006-09-14 09:55:06 +04:00
|
|
|
var noOptionalStyles = true;
|
2006-09-14 10:01:43 +04:00
|
|
|
var styleSheets = getAllStyleSheets(window._content);
|
2006-09-14 09:55:06 +04:00
|
|
|
var currentStyleSheets = [];
|
|
|
|
|
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)
|
|
|
|
noOptionalStyles = false;
|
|
|
|
|
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);
|
|
|
|
menuItem.setAttribute("checked", !currentStyleSheet.disabled);
|
|
|
|
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 09:55:06 +04:00
|
|
|
itemNoOptStyles.setAttribute("checked", noOptionalStyles);
|
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 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:03:58 +04:00
|
|
|
.getService(Components.interfaces.nsIXULChromeRegistry);
|
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:03:40 +04:00
|
|
|
var str = Components.classes["@mozilla.org/supports-wstring;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsWString);
|
|
|
|
|
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:00:39 +04:00
|
|
|
Components.interfaces.nsISupportsWString, 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:03:40 +04:00
|
|
|
pref.setComplexValue("general.skins.selectedSkin", Components.interfaces.nsISupportsWString, str);
|
2006-09-14 10:04:06 +04:00
|
|
|
|
|
|
|
// shut down quicklaunch so the next launch will have the new skin
|
|
|
|
var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService();
|
|
|
|
appShell = appShell.QueryInterface(Components.interfaces.nsIAppShellService);
|
|
|
|
try {
|
|
|
|
appShell.nativeAppSupport.isServerMode = false;
|
|
|
|
}
|
|
|
|
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 09:58:58 +04:00
|
|
|
if (gURLBar) {
|
|
|
|
if (gClickSelectsAll == -1)
|
2006-09-14 10:00:34 +04:00
|
|
|
gClickSelectsAll = pref.getBoolPref("browser.urlbar.clickSelectsAll");
|
2006-09-14 09:58:58 +04:00
|
|
|
if (gClickSelectsAll)
|
2006-09-14 09:57:38 +04:00
|
|
|
gURLBar.setSelectionRange(0, gURLBar.textLength);
|
2006-09-14 09:53:25 +04:00
|
|
|
}
|
2006-09-14 09:53:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function URLBarBlurHandler(aEvent)
|
|
|
|
{
|
2006-09-14 09:58:58 +04:00
|
|
|
// XXX why the hell do we have to do this?
|
|
|
|
if (gClickSelectsAll)
|
2006-09-14 09:57:38 +04:00
|
|
|
gURLBar.setSelectionRange(0, 0);
|
2006-09-14 09:54:01 +04:00
|
|
|
}
|
2006-09-14 09:54:28 +04:00
|
|
|
|
2006-09-14 09:58:57 +04:00
|
|
|
function URLBarKeyupHandler(aEvent)
|
|
|
|
{
|
|
|
|
if (aEvent.keyCode == aEvent.DOM_VK_TAB ) {
|
|
|
|
ShowAndSelectContentsOfURLBar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 09:57:38 +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 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:03:30 +04:00
|
|
|
try {
|
|
|
|
addToUrlbarHistory();
|
|
|
|
} 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 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)
|
|
|
|
{
|
|
|
|
if (gHaveUpdatedToolbarState) {
|
|
|
|
updateComponentBarBroadcaster();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var mainWindow = document.getElementById("main-window");
|
2006-09-14 10:01:44 +04:00
|
|
|
if (mainWindow.hasAttribute("chromehidden")) {
|
2006-09-14 09:59:05 +04:00
|
|
|
gHaveUpdatedToolbarState = true;
|
|
|
|
var i;
|
|
|
|
for (i = 0; i < toolbarMenuElt.childNodes.length; ++i)
|
|
|
|
document.getElementById(toolbarMenuElt.childNodes[i].getAttribute("observes")).removeAttribute("checked");
|
|
|
|
var toolbars = document.getElementsByTagName("toolbar");
|
|
|
|
for (i = 0; i < toolbars.length; ++i) {
|
|
|
|
if (toolbars[i].getAttribute("class").indexOf("chromeclass") != -1)
|
|
|
|
toolbars[i].setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
var statusbars = document.getElementsByTagName("statusbar");
|
|
|
|
for (i = 0; i < statusbars.length; ++i) {
|
|
|
|
if (statusbars[i].getAttribute("class").indexOf("chromeclass") != -1)
|
|
|
|
statusbars[i].setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
mainWindow.removeAttribute("chromehidden");
|
|
|
|
}
|
|
|
|
updateComponentBarBroadcaster();
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:02:33 +04:00
|
|
|
// Fill in tooltips for personal toolbar
|
|
|
|
function FillInPTTooltip(tipElement)
|
|
|
|
{
|
|
|
|
|
|
|
|
var title = tipElement.label;
|
|
|
|
var url = tipElement.statusText;
|
|
|
|
|
|
|
|
if (!title && !url) {
|
|
|
|
// bail out early if there is nothing to show
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tooltipTitle = document.getElementById("ptTitleText");
|
|
|
|
var tooltipUrl = document.getElementById("ptUrlText");
|
|
|
|
|
|
|
|
if (title && title != url) {
|
|
|
|
tooltipTitle.removeAttribute("hidden");
|
|
|
|
tooltipTitle.setAttribute("value", title);
|
|
|
|
} else {
|
|
|
|
tooltipTitle.setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
tooltipUrl.removeAttribute("hidden");
|
|
|
|
tooltipUrl.setAttribute("value", url);
|
|
|
|
} else {
|
|
|
|
tooltipUrl.setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true; // show tooltip
|
|
|
|
}
|
2006-09-14 10:03:18 +04:00
|
|
|
|
|
|
|
function BrowserFullScreen()
|
|
|
|
{
|
|
|
|
window.fullScreen = !window.fullScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onFullScreen()
|
|
|
|
{
|
|
|
|
FullScreen.toggle();
|
|
|
|
}
|
|
|
|
|
2006-09-14 10:03:46 +04:00
|
|
|
// Set up a lame hack to avoid opening two bookmarks.
|
|
|
|
// Could otherwise happen with two Ctrl-B's in a row.
|
|
|
|
var gDisableHistory = false;
|
|
|
|
function enableHistory() {
|
|
|
|
gDisableHistory = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function toHistory()
|
|
|
|
{
|
|
|
|
// Use a single sidebar history dialog
|
|
|
|
|
|
|
|
var cwindowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
|
|
|
|
var iwindowManager = Components.interfaces.nsIWindowMediator;
|
|
|
|
var windowManager = cwindowManager.QueryInterface(iwindowManager);
|
|
|
|
|
|
|
|
var historyWindow = windowManager.getMostRecentWindow('history:manager');
|
|
|
|
|
|
|
|
if (historyWindow) {
|
|
|
|
//debug("Reuse existing history window");
|
|
|
|
historyWindow.focus();
|
|
|
|
} else {
|
|
|
|
//debug("Open a new history dialog");
|
|
|
|
|
|
|
|
if (true == gDisableHistory) {
|
|
|
|
//debug("Recently opened one. Wait a little bit.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gDisableHistory = true;
|
|
|
|
|
|
|
|
window.open( "chrome://communicator/content/history/history.xul", "_blank",
|
|
|
|
"chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar" );
|
|
|
|
setTimeout(enableHistory, 2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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"]
|
|
|
|
.getService(Components.interfaces.nsIXULChromeRegistry);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|