2008-09-26 00:34:54 -07:00
|
|
|
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
2008-05-02 13:15:45 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Mobile Browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Mark Finkle <mfinkle@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2008-10-01 12:54:16 -07:00
|
|
|
Components.utils.import("resource://gre/modules/utils.js");
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
const TOOLBARSTATE_LOADING = 1;
|
|
|
|
const TOOLBARSTATE_LOADED = 2;
|
|
|
|
|
2008-09-10 17:38:02 -07:00
|
|
|
const UIMODE_NONE = 0;
|
|
|
|
const UIMODE_URLVIEW = 1;
|
|
|
|
const UIMODE_URLEDIT = 2;
|
2009-02-24 22:20:45 -08:00
|
|
|
const UIMODE_TABS = 3;
|
|
|
|
const UIMODE_CONTROLS = 4;
|
|
|
|
const UIMODE_PANEL = 5;
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2008-09-13 14:11:48 -07:00
|
|
|
const kMaxEngines = 4;
|
2008-08-19 23:09:22 -07:00
|
|
|
const kDefaultFavIconURL = "chrome://browser/skin/images/default-favicon.png";
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2008-09-29 06:53:49 -07:00
|
|
|
[
|
2009-03-05 15:30:28 -08:00
|
|
|
[
|
|
|
|
"gHistSvc",
|
|
|
|
"@mozilla.org/browser/nav-history-service;1",
|
|
|
|
[Ci.nsINavHistoryService, Ci.nsIBrowserHistory]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"gURIFixup",
|
|
|
|
"@mozilla.org/docshell/urifixup;1",
|
|
|
|
[Ci.nsIURIFixup]
|
2009-03-05 18:45:52 -08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
"gPrefService",
|
|
|
|
"@mozilla.org/preferences-service;1",
|
|
|
|
[Ci.nsIPrefBranch2]
|
2009-03-05 15:30:28 -08:00
|
|
|
]
|
|
|
|
].forEach(function (service) {
|
|
|
|
let [name, contract, ifaces] = service;
|
2008-09-29 06:53:49 -07:00
|
|
|
window.__defineGetter__(name, function () {
|
|
|
|
delete window[name];
|
2009-03-05 15:30:28 -08:00
|
|
|
window[name] = Cc[contract].getService(ifaces.splice(0, 1)[0]);
|
|
|
|
if (ifaces.length)
|
|
|
|
ifaces.forEach(function (i) window[name].QueryInterface(i));
|
|
|
|
return window[name];
|
2008-09-29 06:53:49 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2008-07-03 23:39:25 -07:00
|
|
|
var BrowserUI = {
|
2008-05-02 13:15:45 -07:00
|
|
|
_panel : null,
|
|
|
|
_edit : null,
|
|
|
|
_throbber : null,
|
2008-07-16 08:41:38 -07:00
|
|
|
_autocompleteNavbuttons : null,
|
2008-05-02 13:15:45 -07:00
|
|
|
_favicon : null,
|
2008-11-10 09:55:22 -08:00
|
|
|
_faviconLink : null,
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2008-08-19 23:09:22 -07:00
|
|
|
_titleChanged : function(aDocument) {
|
2009-01-08 22:51:13 -08:00
|
|
|
var browser = Browser.selectedBrowser;
|
2008-08-19 23:09:22 -07:00
|
|
|
if (browser && aDocument != browser.contentDocument)
|
2008-05-02 13:15:45 -07:00
|
|
|
return;
|
|
|
|
|
2008-09-27 07:07:04 -07:00
|
|
|
var caption = aDocument.title;
|
|
|
|
if (!caption) {
|
|
|
|
caption = this.getDisplayURI(browser);
|
|
|
|
if (caption == "about:blank")
|
|
|
|
caption = "";
|
|
|
|
}
|
2008-12-10 23:05:55 -08:00
|
|
|
this._edit.value = caption;
|
2008-08-19 23:09:22 -07:00
|
|
|
|
|
|
|
var docElem = document.documentElement;
|
|
|
|
var title = "";
|
|
|
|
if (aDocument.title)
|
|
|
|
title = aDocument.title + docElem.getAttribute("titleseparator");
|
|
|
|
document.title = title + docElem.getAttribute("titlemodifier");
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_linkAdded : function(aEvent) {
|
|
|
|
var link = aEvent.originalTarget;
|
2008-11-10 09:57:53 -08:00
|
|
|
if (!link || !link.href)
|
2008-05-02 13:15:45 -07:00
|
|
|
return;
|
|
|
|
|
2008-11-10 09:55:22 -08:00
|
|
|
if (/\bicon\b/i(link.rel)) {
|
2008-11-12 19:53:15 -08:00
|
|
|
this._faviconLink = link.href;
|
2009-01-30 08:58:26 -08:00
|
|
|
|
|
|
|
// If the link changes after pageloading, update it right away.
|
|
|
|
// otherwise we wait until the pageload finishes
|
|
|
|
if (this._favicon.src != "")
|
|
|
|
this._setIcon(this._faviconLink);
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-08-19 23:09:22 -07:00
|
|
|
_tabSelect : function(aEvent) {
|
2009-01-08 22:51:13 -08:00
|
|
|
var browser = Browser.selectedBrowser;
|
2008-08-19 23:09:22 -07:00
|
|
|
this._titleChanged(browser.contentDocument);
|
2008-09-14 07:53:25 -07:00
|
|
|
this._favicon.src = browser.mIconURL || kDefaultFavIconURL;
|
2008-12-06 21:08:17 -08:00
|
|
|
|
|
|
|
// for new tabs, _tabSelect & update(TOOLBARSTATE_LOADED) are called when
|
|
|
|
// about:blank is loaded. set _faviconLink here so it is not overriden in update
|
|
|
|
this._faviconLink = this._favicon.src;
|
2008-11-21 21:12:25 -08:00
|
|
|
this.updateIcon();
|
2008-08-19 23:09:22 -07:00
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
_setIcon : function(aURI) {
|
|
|
|
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
2008-12-29 14:54:42 -08:00
|
|
|
try {
|
|
|
|
var faviconURI = ios.newURI(aURI, null, null);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
faviconURI = null;
|
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
|
|
|
|
var fis = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService);
|
2008-12-29 14:54:42 -08:00
|
|
|
if (!faviconURI || faviconURI.schemeIs("javascript") || fis.isFailedFavicon(faviconURI))
|
2008-08-19 23:09:22 -07:00
|
|
|
faviconURI = ios.newURI(kDefaultFavIconURL, null, null);
|
|
|
|
|
|
|
|
var browser = getBrowser();
|
|
|
|
browser.mIconURL = faviconURI.spec;
|
|
|
|
|
|
|
|
fis.setAndLoadFaviconForPage(browser.currentURI, faviconURI, true);
|
2008-09-14 07:53:25 -07:00
|
|
|
this._favicon.src = faviconURI.spec;
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2008-09-10 17:38:02 -07:00
|
|
|
_showToolbar : function(aShow) {
|
|
|
|
if (aShow) {
|
2008-11-21 21:12:25 -08:00
|
|
|
ws.freeze("toolbar-main");
|
|
|
|
ws.moveFrozenTo("toolbar-main", 0, 0);
|
2008-08-19 12:19:47 -07:00
|
|
|
}
|
2008-09-10 17:38:02 -07:00
|
|
|
else {
|
2008-11-21 21:12:25 -08:00
|
|
|
ws.unfreeze("toolbar-main");
|
2008-08-19 12:19:47 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-11 18:11:46 -07:00
|
|
|
_editToolbar : function(aEdit) {
|
2008-12-09 22:21:08 -08:00
|
|
|
var icons = document.getElementById("urlbar-icons");
|
2008-09-11 18:11:46 -07:00
|
|
|
if (aEdit) {
|
2008-12-09 22:21:08 -08:00
|
|
|
icons.setAttribute("mode", "edit");
|
2008-12-10 23:05:55 -08:00
|
|
|
this._edit.readOnly = false;
|
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
let urlString = this.getDisplayURI(Browser.selectedBrowser);
|
2008-12-10 23:05:55 -08:00
|
|
|
if (urlString == "about:blank")
|
|
|
|
urlString = "";
|
|
|
|
this._edit.value = urlString;
|
|
|
|
|
2008-09-13 14:11:48 -07:00
|
|
|
this._edit.inputField.focus();
|
2009-01-14 14:12:36 -08:00
|
|
|
this._edit.select();
|
2008-09-11 18:11:46 -07:00
|
|
|
}
|
|
|
|
else {
|
2008-12-09 22:21:08 -08:00
|
|
|
icons.setAttribute("mode", "view");
|
2008-12-10 23:05:55 -08:00
|
|
|
this._edit.readOnly = true;
|
2008-12-22 11:05:00 -08:00
|
|
|
this._edit.inputField.blur();
|
2008-09-11 18:11:46 -07:00
|
|
|
this._edit.reallyClosePopup();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-26 22:34:27 -07:00
|
|
|
_initPanel : function() {
|
|
|
|
let addons = document.getElementById("addons-container");
|
|
|
|
if (!addons.hasAttribute("src"))
|
|
|
|
addons.setAttribute("src", "chrome://mozapps/content/extensions/extensions.xul");
|
|
|
|
let dloads = document.getElementById("downloads-container");
|
|
|
|
if (!dloads.hasAttribute("src"))
|
|
|
|
dloads.setAttribute("src", "chrome://mozapps/content/downloads/downloads.xul");
|
2008-08-19 12:19:47 -07:00
|
|
|
},
|
|
|
|
|
2008-09-28 06:45:47 -07:00
|
|
|
switchPane : function(id) {
|
|
|
|
document.getElementById("panel-items").selectedPanel = document.getElementById(id);
|
|
|
|
},
|
|
|
|
|
2009-03-31 11:45:24 -07:00
|
|
|
sizeControls : function(windowW, windowH) {
|
2009-02-04 15:03:36 -08:00
|
|
|
let toolbar = document.getElementById("toolbar-main");
|
2009-01-16 14:54:59 -08:00
|
|
|
if (!this._toolbarH)
|
2009-02-04 15:03:36 -08:00
|
|
|
this._toolbarH = toolbar.boxObject.height;
|
|
|
|
|
|
|
|
toolbar.width = windowW;
|
|
|
|
|
2009-01-13 14:04:36 -08:00
|
|
|
let popup = document.getElementById("popup_autocomplete");
|
2009-01-16 14:54:59 -08:00
|
|
|
popup.height = windowH - this._toolbarH;
|
|
|
|
popup.width = windowW;
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-02-04 15:03:36 -08:00
|
|
|
// notification box
|
2009-01-13 13:44:11 -08:00
|
|
|
document.getElementById("notifications").width = windowW;
|
2009-02-04 15:03:36 -08:00
|
|
|
|
|
|
|
// sidebars
|
|
|
|
let sideBarHeight = windowH - this._toolbarH;
|
|
|
|
document.getElementById("browser-controls").height = sideBarHeight;
|
|
|
|
document.getElementById("tabs-container").height = sideBarHeight;
|
2008-08-19 12:19:47 -07:00
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
init : function() {
|
2008-07-03 23:39:25 -07:00
|
|
|
this._edit = document.getElementById("urlbar-edit");
|
2008-12-10 23:05:55 -08:00
|
|
|
this._edit.addEventListener("click", this, false);
|
2008-07-03 23:39:25 -07:00
|
|
|
this._edit.addEventListener("blur", this, false);
|
2008-07-16 08:41:38 -07:00
|
|
|
this._edit.addEventListener("keypress", this, true);
|
2008-07-03 23:39:25 -07:00
|
|
|
this._throbber = document.getElementById("urlbar-throbber");
|
|
|
|
this._favicon = document.getElementById("urlbar-favicon");
|
2008-05-02 13:15:45 -07:00
|
|
|
this._favicon.addEventListener("error", this, false);
|
2008-07-16 08:41:38 -07:00
|
|
|
this._autocompleteNavbuttons = document.getElementById("autocomplete_navbuttons");
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
// XXX these really want to listen whatever is the current browser, not any browser
|
|
|
|
let browsers = document.getElementById("browsers");
|
|
|
|
browsers.addEventListener("DOMTitleChanged", this, true);
|
|
|
|
browsers.addEventListener("DOMLinkAdded", this, true);
|
2008-07-17 15:03:44 -07:00
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
document.getElementById("tabs").addEventListener("TabSelect", this, true);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
update : function(aState) {
|
2008-12-09 22:21:08 -08:00
|
|
|
var icons = document.getElementById("urlbar-icons");
|
2008-08-19 23:09:22 -07:00
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
switch (aState) {
|
|
|
|
case TOOLBARSTATE_LOADED:
|
2008-12-09 22:21:08 -08:00
|
|
|
icons.setAttribute("mode", "view");
|
2008-11-21 21:12:25 -08:00
|
|
|
|
|
|
|
if (!this._faviconLink) {
|
2009-01-08 22:51:13 -08:00
|
|
|
this._faviconLink = Browser.selectedBrowser.currentURI.prePath + "/favicon.ico";
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
|
|
|
this._setIcon(this._faviconLink);
|
|
|
|
this.updateIcon();
|
2008-12-06 21:08:17 -08:00
|
|
|
this._faviconLink = null;
|
2008-11-21 21:12:25 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOOLBARSTATE_LOADING:
|
|
|
|
this.show(UIMODE_URLVIEW);
|
2008-12-09 22:21:08 -08:00
|
|
|
icons.setAttribute("mode", "loading");
|
2008-11-21 21:12:25 -08:00
|
|
|
this._favicon.src = "";
|
|
|
|
this._faviconLink = null;
|
|
|
|
this.updateIcon();
|
|
|
|
break;
|
2008-10-22 08:39:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
updateIcon : function() {
|
2009-01-08 22:51:13 -08:00
|
|
|
if (Browser.selectedTab.isLoading()) {
|
2008-11-21 21:12:25 -08:00
|
|
|
this._throbber.hidden = false;
|
2008-10-22 08:39:00 -07:00
|
|
|
this._throbber.setAttribute("loading", "true");
|
2008-11-21 21:12:25 -08:00
|
|
|
this._favicon.hidden = true;
|
2008-10-22 08:39:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2008-11-21 21:12:25 -08:00
|
|
|
this._favicon.hidden = false;
|
|
|
|
this._throbber.hidden = true;
|
2008-10-22 08:39:00 -07:00
|
|
|
this._throbber.removeAttribute("loading");
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-27 07:07:04 -07:00
|
|
|
getDisplayURI : function(browser) {
|
|
|
|
var uri = browser.currentURI;
|
|
|
|
|
|
|
|
if (!this._URIFixup)
|
|
|
|
this._URIFixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
|
|
|
|
|
|
|
|
try {
|
|
|
|
uri = this._URIFixup.createExposableURI(uri);
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
return uri.spec;
|
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
/* Set the location to the current content */
|
|
|
|
setURI : function() {
|
2009-01-08 22:51:13 -08:00
|
|
|
var browser = Browser.selectedBrowser;
|
2008-09-06 21:06:04 -07:00
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
// FIXME: deckbrowser should not fire TabSelect on the initial tab (bug 454028)
|
2008-09-06 21:06:04 -07:00
|
|
|
if (!browser.currentURI)
|
|
|
|
return;
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
var back = document.getElementById("cmd_back");
|
|
|
|
var forward = document.getElementById("cmd_forward");
|
|
|
|
|
|
|
|
back.setAttribute("disabled", !browser.canGoBack);
|
|
|
|
forward.setAttribute("disabled", !browser.canGoForward);
|
|
|
|
|
|
|
|
// Check for a bookmarked page
|
2008-12-15 08:44:27 -08:00
|
|
|
this.updateStar();
|
2008-07-03 23:39:25 -07:00
|
|
|
|
2008-09-27 07:07:04 -07:00
|
|
|
var urlString = this.getDisplayURI(browser);
|
2008-07-03 23:39:25 -07:00
|
|
|
if (urlString == "about:blank") {
|
|
|
|
urlString = "";
|
2008-09-10 17:38:02 -07:00
|
|
|
this.show(UIMODE_URLEDIT);
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
|
2008-07-03 23:39:25 -07:00
|
|
|
this._edit.value = urlString;
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
goToURI : function(aURI) {
|
2008-07-16 08:41:38 -07:00
|
|
|
this._edit.reallyClosePopup();
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
if (!aURI)
|
|
|
|
aURI = this._edit.value;
|
2008-05-06 07:56:21 -07:00
|
|
|
|
2008-07-15 08:21:39 -07:00
|
|
|
var flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
|
|
|
|
getBrowser().loadURIWithFlags(aURI, flags, null, null);
|
2009-03-05 15:30:28 -08:00
|
|
|
|
|
|
|
gHistSvc.markPageAsTyped(gURIFixup.createFixupURI(aURI, 0));
|
|
|
|
|
2008-09-10 17:38:02 -07:00
|
|
|
this.show(UIMODE_URLVIEW);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
search : function() {
|
|
|
|
var queryURI = "http://www.google.com/search?q=" + this._edit.value + "&hl=en&lr=&btnG=Search";
|
|
|
|
getBrowser().loadURI(queryURI, null, null, false);
|
2008-07-03 23:39:25 -07:00
|
|
|
|
2008-09-10 17:38:02 -07:00
|
|
|
this.show(UIMODE_URLVIEW);
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
|
|
|
|
2008-12-09 10:38:31 -08:00
|
|
|
showAutoComplete : function(showDefault) {
|
2008-09-13 14:11:48 -07:00
|
|
|
this.updateSearchEngines();
|
2008-12-09 10:38:31 -08:00
|
|
|
this._edit.showHistoryPopup();
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
doButtonSearch : function(button) {
|
2008-07-16 08:41:38 -07:00
|
|
|
if (!("engine" in button) || !button.engine)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var urlbar = this._edit;
|
|
|
|
urlbar.open = false;
|
|
|
|
var value = urlbar.value;
|
|
|
|
|
|
|
|
var submission = button.engine.getSubmission(value, null);
|
|
|
|
getBrowser().loadURI(submission.uri.spec, null, submission.postData, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
engines : null,
|
|
|
|
updateSearchEngines : function () {
|
|
|
|
if (this.engines)
|
|
|
|
return;
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
var searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
2008-07-16 08:41:38 -07:00
|
|
|
var engines = searchService.getVisibleEngines({ });
|
|
|
|
this.engines = engines;
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2008-07-16 08:41:38 -07:00
|
|
|
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
var container = this._autocompleteNavbuttons;
|
2008-09-13 14:11:48 -07:00
|
|
|
for (var e = 0; e < kMaxEngines && e < engines.length; e++) {
|
2008-07-16 08:41:38 -07:00
|
|
|
var button = document.createElementNS(kXULNS, "toolbarbutton");
|
|
|
|
var engine = engines[e];
|
|
|
|
button.id = engine.name;
|
|
|
|
button.setAttribute("label", engine.name);
|
2008-09-13 14:11:48 -07:00
|
|
|
button.className = "searchengine";
|
2008-07-16 08:41:38 -07:00
|
|
|
if (engine.iconURI)
|
|
|
|
button.setAttribute("image", engine.iconURI.spec);
|
2008-09-13 14:11:48 -07:00
|
|
|
container.appendChild(button);
|
2008-07-16 08:41:38 -07:00
|
|
|
button.engine = engine;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-10 17:38:02 -07:00
|
|
|
mode : UIMODE_NONE,
|
2008-07-25 11:10:35 -07:00
|
|
|
show : function(aMode) {
|
|
|
|
if (this.mode == aMode)
|
|
|
|
return;
|
2008-09-10 13:54:32 -07:00
|
|
|
|
2008-07-25 11:10:35 -07:00
|
|
|
this.mode = aMode;
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2008-12-09 20:27:49 -08:00
|
|
|
let container = document.getElementById("browser-container");
|
|
|
|
let panelUI = document.getElementById("panel-container");
|
2008-07-25 11:10:35 -07:00
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
if (aMode == UIMODE_URLVIEW) {
|
2008-12-18 14:36:59 -08:00
|
|
|
this._showToolbar(false);
|
2008-09-11 18:11:46 -07:00
|
|
|
this._editToolbar(false);
|
2008-09-26 00:34:54 -07:00
|
|
|
|
2008-12-09 20:27:49 -08:00
|
|
|
panelUI.hidden = true;
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
2008-09-10 17:38:02 -07:00
|
|
|
else if (aMode == UIMODE_URLEDIT) {
|
|
|
|
this._showToolbar(true);
|
2008-09-11 18:11:46 -07:00
|
|
|
this._editToolbar(true);
|
2008-07-25 11:10:35 -07:00
|
|
|
|
2008-12-09 20:27:49 -08:00
|
|
|
panelUI.hidden = true;
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
2008-09-10 17:38:02 -07:00
|
|
|
else if (aMode == UIMODE_PANEL) {
|
2008-12-09 20:27:49 -08:00
|
|
|
panelUI.hidden = false;
|
|
|
|
panelUI.width = container.boxObject.width;
|
|
|
|
panelUI.height = container.boxObject.height;
|
|
|
|
this._initPanel();
|
2008-09-11 18:11:46 -07:00
|
|
|
}
|
|
|
|
else if (aMode == UIMODE_TABS || aMode == UIMODE_CONTROLS) {
|
2008-12-09 20:27:49 -08:00
|
|
|
panelUI.hidden = true;
|
2008-08-19 19:18:36 -07:00
|
|
|
}
|
2008-09-10 17:38:02 -07:00
|
|
|
else if (aMode == UIMODE_NONE) {
|
|
|
|
this._showToolbar(false);
|
2008-07-25 11:10:35 -07:00
|
|
|
this._edit.reallyClosePopup();
|
2008-12-09 20:27:49 -08:00
|
|
|
panelUI.hidden = true;
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-12-15 08:44:27 -08:00
|
|
|
updateStar : function() {
|
|
|
|
var star = document.getElementById("tool-star");
|
2009-01-08 22:51:13 -08:00
|
|
|
if (PlacesUtils.getMostRecentBookmarkForURI(Browser.selectedBrowser.currentURI) != -1)
|
2008-12-15 08:44:27 -08:00
|
|
|
star.setAttribute("starred", "true");
|
|
|
|
else
|
|
|
|
star.removeAttribute("starred");
|
|
|
|
},
|
|
|
|
|
|
|
|
goToBookmark : function(aEvent) {
|
|
|
|
if (aEvent.originalTarget.localName == "button")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var list = document.getElementById("urllist-items")
|
|
|
|
BrowserUI.goToURI(list.selectedItem.value)
|
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
showHistory : function() {
|
2009-02-24 22:20:45 -08:00
|
|
|
// XXX Fix me with a real UI
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
showBookmarks : function () {
|
2009-02-24 22:20:45 -08:00
|
|
|
BookmarkList.show();
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2008-07-25 11:10:35 -07:00
|
|
|
newTab : function() {
|
2008-12-18 14:36:59 -08:00
|
|
|
ws.panTo(0, -60, true);
|
2009-01-08 22:51:13 -08:00
|
|
|
Browser.addTab("about:blank", true);
|
2008-09-10 17:38:02 -07:00
|
|
|
this.show(UIMODE_URLEDIT);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2008-09-28 23:43:33 -07:00
|
|
|
closeTab : function(aTab) {
|
2008-11-21 21:12:25 -08:00
|
|
|
Browser.closeTab(aTab);
|
2008-09-28 23:43:33 -07:00
|
|
|
},
|
|
|
|
|
2008-07-25 11:10:35 -07:00
|
|
|
selectTab : function(aTab) {
|
2009-01-08 22:51:13 -08:00
|
|
|
Browser.selectedTab = aTab;
|
2009-02-10 13:52:23 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
hideTabs : function() {
|
|
|
|
ws.panTo(0, 0);
|
2008-09-11 18:11:46 -07:00
|
|
|
this.show(UIMODE_NONE);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function (aEvent) {
|
|
|
|
switch (aEvent.type) {
|
2008-07-03 23:39:25 -07:00
|
|
|
// Browser events
|
2008-05-02 13:15:45 -07:00
|
|
|
case "DOMTitleChanged":
|
2008-08-19 23:09:22 -07:00
|
|
|
this._titleChanged(aEvent.target);
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
|
|
|
case "DOMLinkAdded":
|
|
|
|
this._linkAdded(aEvent);
|
|
|
|
break;
|
2008-08-19 23:09:22 -07:00
|
|
|
case "TabSelect":
|
|
|
|
this._tabSelect(aEvent);
|
|
|
|
break;
|
2008-07-03 23:39:25 -07:00
|
|
|
// URL textbox events
|
2008-05-02 13:15:45 -07:00
|
|
|
case "click":
|
2008-11-12 18:40:57 -08:00
|
|
|
this.doCommand("cmd_openLocation");
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
|
|
|
case "keypress":
|
2008-07-16 08:41:38 -07:00
|
|
|
if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE) {
|
|
|
|
this._edit.reallyClosePopup();
|
2008-09-10 17:38:02 -07:00
|
|
|
this.show(UIMODE_URLVIEW);
|
2008-07-16 08:41:38 -07:00
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
2008-07-03 23:39:25 -07:00
|
|
|
// Favicon events
|
2008-05-02 13:15:45 -07:00
|
|
|
case "error":
|
2008-09-14 07:53:25 -07:00
|
|
|
this._favicon.src = "chrome://browser/skin/images/default-favicon.png";
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
supportsCommand : function(cmd) {
|
|
|
|
var isSupported = false;
|
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_back":
|
|
|
|
case "cmd_forward":
|
|
|
|
case "cmd_reload":
|
|
|
|
case "cmd_stop":
|
|
|
|
case "cmd_search":
|
|
|
|
case "cmd_go":
|
2008-11-12 18:40:57 -08:00
|
|
|
case "cmd_openLocation":
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_star":
|
|
|
|
case "cmd_bookmarks":
|
2009-03-19 16:20:32 -07:00
|
|
|
case "cmd_quit":
|
|
|
|
case "cmd_close":
|
2008-07-25 11:10:35 -07:00
|
|
|
case "cmd_menu":
|
|
|
|
case "cmd_newTab":
|
|
|
|
case "cmd_closeTab":
|
2008-08-19 19:18:36 -07:00
|
|
|
case "cmd_actions":
|
2008-09-10 17:38:02 -07:00
|
|
|
case "cmd_panel":
|
2008-09-06 23:54:06 -07:00
|
|
|
case "cmd_sanitize":
|
2008-10-09 21:11:27 -07:00
|
|
|
case "cmd_zoomin":
|
|
|
|
case "cmd_zoomout":
|
2008-05-02 13:15:45 -07:00
|
|
|
isSupported = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
isSupported = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return isSupported;
|
|
|
|
},
|
|
|
|
|
|
|
|
isCommandEnabled : function(cmd) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
doCommand : function(cmd) {
|
|
|
|
var browser = getBrowser();
|
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_back":
|
|
|
|
browser.goBack();
|
|
|
|
break;
|
|
|
|
case "cmd_forward":
|
|
|
|
browser.goForward();
|
|
|
|
break;
|
|
|
|
case "cmd_reload":
|
|
|
|
browser.reload();
|
|
|
|
break;
|
|
|
|
case "cmd_stop":
|
|
|
|
browser.stop();
|
|
|
|
break;
|
|
|
|
case "cmd_search":
|
|
|
|
this.search();
|
|
|
|
break;
|
|
|
|
case "cmd_go":
|
|
|
|
this.goToURI();
|
|
|
|
break;
|
2008-11-12 18:40:57 -08:00
|
|
|
case "cmd_openLocation":
|
|
|
|
this.show(UIMODE_URLEDIT);
|
2008-12-09 10:38:31 -08:00
|
|
|
setTimeout(function () { BrowserUI.showAutoComplete(); }, 0);
|
2008-11-12 18:40:57 -08:00
|
|
|
break;
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_star":
|
|
|
|
{
|
|
|
|
var bookmarkURI = browser.currentURI;
|
2009-03-03 06:31:51 -08:00
|
|
|
var bookmarkTitle = browser.contentDocument.title || bookmarkURI.spec;
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2008-10-01 12:54:16 -07:00
|
|
|
if (PlacesUtils.getMostRecentBookmarkForURI(bookmarkURI) == -1) {
|
|
|
|
var bookmarkId = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder, bookmarkURI, PlacesUtils.bookmarks.DEFAULT_INDEX, bookmarkTitle);
|
2008-12-15 08:44:27 -08:00
|
|
|
BrowserUI.updateStar();
|
2008-05-02 13:15:45 -07:00
|
|
|
|
|
|
|
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
2008-07-03 23:39:25 -07:00
|
|
|
var favicon = document.getElementById("urlbar-favicon");
|
2008-05-02 13:15:45 -07:00
|
|
|
var faviconURI = ios.newURI(favicon.src, null, null);
|
|
|
|
|
2008-10-01 12:54:16 -07:00
|
|
|
PlacesUtils.favicons.setAndLoadFaviconForPage(bookmarkURI, faviconURI, true);
|
2008-07-25 11:10:35 -07:00
|
|
|
|
2008-09-10 17:38:02 -07:00
|
|
|
this.show(UIMODE_NONE);
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BookmarkHelper.edit(bookmarkURI);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "cmd_bookmarks":
|
2008-07-03 23:39:25 -07:00
|
|
|
this.showBookmarks();
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
2009-03-19 16:20:32 -07:00
|
|
|
case "cmd_quit":
|
|
|
|
goQuitApplication();
|
|
|
|
break;
|
|
|
|
case "cmd_close":
|
|
|
|
close();
|
|
|
|
break;
|
2008-07-25 11:10:35 -07:00
|
|
|
case "cmd_menu":
|
|
|
|
break;
|
|
|
|
case "cmd_newTab":
|
|
|
|
this.newTab();
|
|
|
|
break;
|
|
|
|
case "cmd_closeTab":
|
2008-11-21 21:12:25 -08:00
|
|
|
this.closeTab();
|
2008-08-19 19:18:36 -07:00
|
|
|
break;
|
2008-09-06 23:54:06 -07:00
|
|
|
case "cmd_sanitize":
|
|
|
|
Sanitizer.sanitize();
|
2008-08-19 19:18:36 -07:00
|
|
|
break;
|
2008-09-10 17:38:02 -07:00
|
|
|
case "cmd_panel":
|
|
|
|
{
|
2008-09-11 18:11:46 -07:00
|
|
|
var mode = (this.mode != UIMODE_PANEL ? UIMODE_PANEL : UIMODE_CONTROLS);
|
2008-09-10 17:38:02 -07:00
|
|
|
this.show(mode);
|
2008-09-10 12:30:52 -07:00
|
|
|
break;
|
2008-09-10 17:38:02 -07:00
|
|
|
}
|
2008-10-09 21:11:27 -07:00
|
|
|
case "cmd_zoomin":
|
2008-12-09 13:43:20 -08:00
|
|
|
Browser.canvasBrowser.zoom(-1);
|
2008-10-09 21:11:27 -07:00
|
|
|
break;
|
|
|
|
case "cmd_zoomout":
|
2008-12-09 13:43:20 -08:00
|
|
|
Browser.canvasBrowser.zoom(1);
|
2008-10-09 21:11:27 -07:00
|
|
|
break;
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var BookmarkHelper = {
|
2009-02-24 22:20:45 -08:00
|
|
|
_panel: null,
|
|
|
|
_editor: null,
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
edit: function(aURI) {
|
2009-02-24 22:20:45 -08:00
|
|
|
let itemId = PlacesUtils.getMostRecentBookmarkForURI(aURI);
|
|
|
|
if (itemId == -1)
|
|
|
|
return;
|
|
|
|
|
2009-04-08 22:40:05 -07:00
|
|
|
let title = PlacesUtils.bookmarks.getItemTitle(itemId);
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
let container = document.getElementById("browser-container");
|
|
|
|
this._panel = document.getElementById("bookmark-container");
|
|
|
|
this._panel.hidden = false;
|
|
|
|
this._panel.width = container.boxObject.width;
|
|
|
|
|
|
|
|
this._editor = document.getElementById("bookmark-edit");
|
2009-04-08 22:40:05 -07:00
|
|
|
this._editor.setAttribute("title", title);
|
|
|
|
this._editor.setAttribute("uri", aURI.spec);
|
2009-02-24 22:20:45 -08:00
|
|
|
this._editor.init(itemId);
|
|
|
|
this._editor.startEditing();
|
|
|
|
|
2008-07-14 14:11:15 -07:00
|
|
|
window.addEventListener("keypress", this, true);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
close: function() {
|
2008-07-14 14:11:15 -07:00
|
|
|
window.removeEventListener("keypress", this, true);
|
2008-12-15 08:44:27 -08:00
|
|
|
BrowserUI.updateStar();
|
2009-02-24 22:20:45 -08:00
|
|
|
|
|
|
|
if (this._editor.isEditing)
|
|
|
|
this._editor.stopEditing();
|
|
|
|
this._panel.hidden = true;
|
2009-04-08 22:40:05 -07:00
|
|
|
|
|
|
|
this._editor.removeAttribute("title");
|
|
|
|
this._editor.removeAttribute("uri");
|
2008-07-14 14:11:15 -07:00
|
|
|
},
|
2008-07-15 08:21:39 -07:00
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
handleEvent: function(aEvent) {
|
2008-12-15 08:44:27 -08:00
|
|
|
if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE)
|
2009-02-24 22:20:45 -08:00
|
|
|
this.close();
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
};
|
2009-02-24 22:20:45 -08:00
|
|
|
|
|
|
|
var BookmarkList = {
|
|
|
|
_panel: null,
|
|
|
|
_bookmarks: null,
|
|
|
|
|
|
|
|
show: function() {
|
|
|
|
let container = document.getElementById("browser-container");
|
|
|
|
this._panel = document.getElementById("bookmarklist-container");
|
|
|
|
this._panel.width = container.boxObject.width;
|
|
|
|
this._panel.height = container.boxObject.height;
|
2009-04-08 22:40:05 -07:00
|
|
|
this._panel.hidden = false;
|
2009-02-24 22:20:45 -08:00
|
|
|
|
|
|
|
this._bookmarks = document.getElementById("bookmark-items");
|
|
|
|
this._bookmarks.manageUI = false;
|
|
|
|
this._bookmarks.openFolder();
|
|
|
|
|
|
|
|
window.addEventListener("keypress", this, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
window.removeEventListener("keypress", this, true);
|
|
|
|
BrowserUI.updateStar();
|
|
|
|
|
|
|
|
if (this._bookmarks.isEditing)
|
|
|
|
this._bookmarks.stopEditing();
|
|
|
|
this._bookmarks.blur();
|
|
|
|
|
|
|
|
this._panel.hidden = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleManage: function() {
|
|
|
|
this._bookmarks.manageUI = !(this._bookmarks.manageUI);
|
|
|
|
},
|
|
|
|
|
|
|
|
openBookmark: function() {
|
|
|
|
let item = this._bookmarks.activeItem;
|
2009-02-24 22:20:45 -08:00
|
|
|
if (item.spec) {
|
2009-02-24 22:20:45 -08:00
|
|
|
this._panel.hidden = true;
|
2009-02-24 22:20:45 -08:00
|
|
|
BrowserUI.goToURI(item.spec)
|
2009-02-24 22:20:45 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE)
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
var FolderPicker = {
|
2009-02-24 22:20:45 -08:00
|
|
|
_control: null,
|
|
|
|
_panel: null,
|
|
|
|
|
|
|
|
show: function(aControl) {
|
|
|
|
let container = document.getElementById("browser-container");
|
|
|
|
this._panel = document.getElementById("folder-container");
|
|
|
|
this._panel.hidden = false;
|
|
|
|
this._panel.width = container.boxObject.width;
|
|
|
|
this._panel.height = container.boxObject.height;
|
|
|
|
|
|
|
|
this._control = aControl;
|
|
|
|
|
|
|
|
let folders = document.getElementById("folder-items");
|
|
|
|
folders.openFolder();
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
this._panel.hidden = true;
|
|
|
|
},
|
|
|
|
|
2009-02-24 22:20:45 -08:00
|
|
|
moveItem: function() {
|
2009-02-24 22:20:45 -08:00
|
|
|
let folders = document.getElementById("folder-items");
|
2009-02-24 22:20:45 -08:00
|
|
|
let itemId = (this._control.activeItem ? this._control.activeItem.itemId : this._control.itemId);
|
|
|
|
let folderId = PlacesUtils.bookmarks.getFolderIdForItem(itemId);
|
2009-02-24 22:20:45 -08:00
|
|
|
if (folders.selectedItem.itemId != folderId) {
|
2009-02-24 22:20:45 -08:00
|
|
|
PlacesUtils.bookmarks.moveItem(itemId, folders.selectedItem.itemId, PlacesUtils.bookmarks.DEFAULT_INDEX);
|
|
|
|
if (this._control.removeItem)
|
|
|
|
this._control.removeItem(this._control.activeItem);
|
2009-02-24 22:20:45 -08:00
|
|
|
}
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
};
|