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>
|
2010-10-16 06:25:15 -07:00
|
|
|
* Matt Brubeck <mbrubeck@mozilla.com>
|
2008-05-02 13:15:45 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2010-03-22 07:05:27 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-07-13 07:36:09 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2010-03-22 07:05:27 -07:00
|
|
|
|
2008-09-29 06:53:49 -07:00
|
|
|
[
|
2010-09-03 02:01:25 -07:00
|
|
|
["AllPagesList", "popup_autocomplete", "cmd_openLocation"],
|
|
|
|
["HistoryList", "history-items", "cmd_history"],
|
|
|
|
["BookmarkList", "bookmarks-items", "cmd_bookmarks"],
|
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
|
|
|
["RemoteTabsList", "remotetabs-items", "cmd_remoteTabs"]
|
|
|
|
#endif
|
|
|
|
].forEach(function(aPanel) {
|
|
|
|
let [name, id, command] = aPanel;
|
|
|
|
XPCOMUtils.defineLazyGetter(window, name, function() {
|
|
|
|
return new AwesomePanel(id, command);
|
2008-09-29 06:53:49 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-09-03 02:01:25 -07:00
|
|
|
/**
|
|
|
|
* Cache of commonly used elements.
|
|
|
|
*/
|
|
|
|
let Elements = {};
|
|
|
|
|
|
|
|
[
|
|
|
|
["contentShowing", "bcast_contentShowing"],
|
|
|
|
["urlbarState", "bcast_urlbarState"],
|
|
|
|
["stack", "stack"],
|
|
|
|
["tabs", "tabs-container"],
|
|
|
|
["controls", "browser-controls"],
|
|
|
|
["panelUI", "panel-container"],
|
|
|
|
["toolbarContainer", "toolbar-container"],
|
2010-11-18 06:47:16 -08:00
|
|
|
["browsers", "browsers"],
|
|
|
|
["contentViewport", "content-viewport"],
|
|
|
|
["contentNavigator", "content-navigator"]
|
2010-09-03 02:01:25 -07:00
|
|
|
].forEach(function (aElementGlobal) {
|
|
|
|
let [name, id] = aElementGlobal;
|
|
|
|
XPCOMUtils.defineLazyGetter(Elements, name, function() {
|
|
|
|
return document.getElementById(id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-01-03 12:07:41 -08:00
|
|
|
/**
|
|
|
|
* Cache of commonly used string bundles.
|
|
|
|
*/
|
|
|
|
var Strings = {};
|
|
|
|
[
|
|
|
|
["browser", "chrome://browser/locale/browser.properties"],
|
|
|
|
["brand", "chrome://branding/locale/brand.properties"]
|
|
|
|
].forEach(function (aStringBundle) {
|
|
|
|
let [name, bundle] = aStringBundle;
|
|
|
|
XPCOMUtils.defineLazyGetter(Strings, name, function() {
|
|
|
|
return Services.strings.createBundle(bundle);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-09-03 02:01:25 -07:00
|
|
|
const TOOLBARSTATE_LOADING = 1;
|
|
|
|
const TOOLBARSTATE_LOADED = 2;
|
|
|
|
|
2008-07-03 23:39:25 -07:00
|
|
|
var BrowserUI = {
|
2010-11-02 12:20:11 -07:00
|
|
|
_edit: null,
|
|
|
|
_title: null,
|
|
|
|
_throbber: null,
|
|
|
|
_favicon: null,
|
2009-07-08 07:55:07 -07:00
|
|
|
_dialogs: [],
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
_domWillOpenModalDialog: function(aBrowser) {
|
2009-09-30 12:14:06 -07:00
|
|
|
// We're about to open a modal dialog, make sure the opening
|
|
|
|
// tab is brought to the front.
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
for (let i = 0; i < Browser.tabs.length; i++) {
|
|
|
|
if (Browser._tabs[i].browser == aBrowser) {
|
|
|
|
Browser.selectedTab = Browser.tabs[i];
|
2009-10-14 13:44:09 -07:00
|
|
|
break;
|
2009-09-30 12:14:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_titleChanged: function(aBrowser) {
|
2010-10-10 14:23:28 -07:00
|
|
|
let browser = Browser.selectedBrowser;
|
2010-06-08 08:22:20 -07:00
|
|
|
if (browser && aBrowser != browser)
|
2008-05-02 13:15:45 -07:00
|
|
|
return;
|
|
|
|
|
2010-10-10 14:23:28 -07:00
|
|
|
let url = this.getDisplayURI(browser);
|
|
|
|
let caption = browser.contentTitle || url;
|
2010-04-08 22:08:53 -07:00
|
|
|
|
2010-12-09 08:06:21 -08:00
|
|
|
if (browser.contentTitle == "" && !Util.isURLEmpty(browser.userTypedValue))
|
|
|
|
caption = browser.userTypedValue;
|
|
|
|
else if (Util.isURLEmpty(url))
|
2010-04-08 22:08:53 -07:00
|
|
|
caption = "";
|
2009-09-18 21:17:52 -07:00
|
|
|
|
2010-11-02 12:20:11 -07:00
|
|
|
if (caption) {
|
|
|
|
this._title.value = caption;
|
|
|
|
this._title.classList.remove("placeholder");
|
|
|
|
} else {
|
|
|
|
this._title.value = this._title.getAttribute("placeholder");
|
|
|
|
this._title.classList.add("placeholder");
|
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2009-07-16 08:45:50 -07:00
|
|
|
/*
|
|
|
|
* Dispatched by window.close() to allow us to turn window closes into tabs
|
|
|
|
* closes.
|
|
|
|
*/
|
2010-06-08 08:22:20 -07:00
|
|
|
_domWindowClose: function(aBrowser) {
|
|
|
|
// Find the relevant tab, and close it.
|
|
|
|
let browsers = Browser.browsers;
|
|
|
|
for (let i = 0; i < browsers.length; i++) {
|
|
|
|
if (browsers[i] == aBrowser) {
|
2009-07-16 08:45:50 -07:00
|
|
|
Browser.closeTab(Browser.getTabAtIndex(i));
|
2010-06-08 08:22:20 -07:00
|
|
|
return { preventDefault: true };
|
2009-07-16 08:45:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_updateButtons: function(aBrowser) {
|
2009-11-22 20:08:18 -08:00
|
|
|
let back = document.getElementById("cmd_back");
|
|
|
|
let forward = document.getElementById("cmd_forward");
|
2009-06-24 15:43:26 -07:00
|
|
|
|
|
|
|
back.setAttribute("disabled", !aBrowser.canGoBack);
|
|
|
|
forward.setAttribute("disabled", !aBrowser.canGoForward);
|
|
|
|
},
|
|
|
|
|
2010-04-29 22:28:40 -07:00
|
|
|
_updateToolbar: function _updateToolbar() {
|
2010-08-26 15:48:27 -07:00
|
|
|
let mode = Elements.urlbarState.getAttribute("mode");
|
2010-11-17 02:18:21 -08:00
|
|
|
if (mode == "edit" && this.activePanel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Browser.selectedTab.isLoading() && mode != "loading")
|
2010-08-26 15:48:27 -07:00
|
|
|
Elements.urlbarState.setAttribute("mode", "loading");
|
2010-11-17 02:18:21 -08:00
|
|
|
else if (mode != "view")
|
2010-08-26 15:48:27 -07:00
|
|
|
Elements.urlbarState.setAttribute("mode", "view");
|
2009-11-22 20:08:18 -08:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_tabSelect: function(aEvent) {
|
2009-11-22 20:08:18 -08:00
|
|
|
let browser = Browser.selectedBrowser;
|
2010-06-08 08:22:20 -07:00
|
|
|
this._titleChanged(browser);
|
2010-04-29 22:28:40 -07:00
|
|
|
this._updateToolbar();
|
2009-06-24 15:43:26 -07:00
|
|
|
this._updateButtons(browser);
|
2009-10-09 05:34:02 -07:00
|
|
|
this._updateIcon(browser.mIconURL);
|
2009-07-05 09:22:09 -07:00
|
|
|
this.updateStar();
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2009-08-24 07:18:26 -07:00
|
|
|
_toolbarLocked: 0,
|
2009-11-23 23:46:01 -08:00
|
|
|
|
|
|
|
isToolbarLocked: function isToolbarLocked() {
|
|
|
|
return this._toolbarLocked;
|
|
|
|
},
|
|
|
|
|
2009-08-24 07:18:26 -07:00
|
|
|
lockToolbar: function lockToolbar() {
|
|
|
|
this._toolbarLocked++;
|
|
|
|
document.getElementById("toolbar-moveable-container").top = "0";
|
2009-11-02 21:13:42 -08:00
|
|
|
if (this._toolbarLocked == 1)
|
|
|
|
Browser.forceChromeReflow();
|
2009-08-24 07:18:26 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-24 07:18:26 -07:00
|
|
|
unlockToolbar: function unlockToolbar() {
|
|
|
|
if (!this._toolbarLocked)
|
|
|
|
return;
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-24 07:18:26 -07:00
|
|
|
this._toolbarLocked--;
|
2009-08-26 10:18:13 -07:00
|
|
|
if (!this._toolbarLocked)
|
2009-08-24 07:18:26 -07:00
|
|
|
document.getElementById("toolbar-moveable-container").top = "";
|
|
|
|
},
|
|
|
|
|
2010-11-02 12:20:11 -07:00
|
|
|
_setURL: function _setURL(aURL) {
|
2010-10-14 06:15:29 -07:00
|
|
|
if (this.activePanel)
|
2010-11-02 12:20:11 -07:00
|
|
|
this._edit.defaultValue = aURL;
|
2009-09-18 21:17:52 -07:00
|
|
|
else
|
2010-11-02 12:20:11 -07:00
|
|
|
this._edit.value = aURL;
|
2009-09-18 21:17:52 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_editURI: function _editURI(aEdit) {
|
2010-10-14 06:15:29 -07:00
|
|
|
Elements.urlbarState.setAttribute("mode", "edit");
|
|
|
|
this._edit.defaultValue = this._edit.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
_showURI: function _showURI() {
|
|
|
|
// Replace the web page title by the url of the page
|
|
|
|
let urlString = this.getDisplayURI(Browser.selectedBrowser);
|
|
|
|
if (Util.isURLEmpty(urlString))
|
|
|
|
urlString = "";
|
|
|
|
|
|
|
|
this._edit.value = urlString;
|
2008-09-11 18:11:46 -07:00
|
|
|
},
|
|
|
|
|
2010-10-10 14:23:28 -07:00
|
|
|
updateAwesomeHeader: function updateAwesomeHeader(aString) {
|
2010-10-14 06:15:29 -07:00
|
|
|
document.getElementById("awesome-header").hidden = (aString != "");
|
|
|
|
|
2010-10-10 14:23:28 -07:00
|
|
|
// During an awesome search we always show the popup_autocomplete/AllPagesList
|
|
|
|
// panel since this looks in every places and the rationale behind typing
|
|
|
|
// is to find something, whereever it is.
|
|
|
|
if (this.activePanel != AllPagesList) {
|
|
|
|
let inputField = this._edit;
|
|
|
|
let oldClickSelectsAll = inputField.clickSelectsAll;
|
|
|
|
inputField.clickSelectsAll = false;
|
|
|
|
|
|
|
|
this.activePanel = AllPagesList;
|
|
|
|
|
|
|
|
// changing the searchString property call updateAwesomeHeader again
|
|
|
|
inputField.controller.searchString = aString;
|
|
|
|
inputField.readOnly = false;
|
|
|
|
inputField.clickSelectsAll = oldClickSelectsAll;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("onsearchbegin", true, true);
|
|
|
|
this._edit.dispatchEvent(event);
|
2010-08-24 01:42:28 -07:00
|
|
|
},
|
|
|
|
|
2009-07-08 07:55:07 -07:00
|
|
|
_closeOrQuit: function _closeOrQuit() {
|
|
|
|
// Close active dialog, if we have one. If not then close the application.
|
2010-08-24 01:42:28 -07:00
|
|
|
if (this.activePanel) {
|
|
|
|
this.activePanel = null;
|
|
|
|
} else if (this.activeDialog) {
|
|
|
|
this.activeDialog.close();
|
2010-03-30 10:27:59 -07:00
|
|
|
} else {
|
|
|
|
// Check to see if we should really close the window
|
|
|
|
if (Browser.closing())
|
|
|
|
window.close();
|
|
|
|
}
|
2009-07-08 07:55:07 -07:00
|
|
|
},
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
_activePanel: null,
|
|
|
|
get activePanel() {
|
|
|
|
return this._activePanel;
|
|
|
|
},
|
|
|
|
|
|
|
|
set activePanel(aPanel) {
|
2010-08-27 01:25:04 -07:00
|
|
|
if (this._activePanel == aPanel)
|
|
|
|
return;
|
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
let awesomePanel = document.getElementById("awesome-panels");
|
|
|
|
let awesomeHeader = document.getElementById("awesome-header");
|
|
|
|
|
|
|
|
let willShowPanel = (!this._activePanel && aPanel);
|
|
|
|
if (willShowPanel) {
|
|
|
|
this.pushDialog(aPanel);
|
|
|
|
this._edit.attachController();
|
|
|
|
this._editURI();
|
|
|
|
awesomePanel.hidden = awesomeHeader.hidden = false;
|
|
|
|
};
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
if (aPanel) {
|
|
|
|
aPanel.open();
|
2010-10-14 06:15:29 -07:00
|
|
|
if (this._edit.value == "")
|
|
|
|
this._showURI();
|
2010-08-24 01:42:28 -07:00
|
|
|
}
|
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
let willHidePanel = (this._activePanel && !aPanel);
|
|
|
|
if (willHidePanel) {
|
|
|
|
awesomePanel.hidden = true;
|
|
|
|
awesomeHeader.hidden = false;
|
|
|
|
this._edit.reset();
|
|
|
|
this._edit.detachController();
|
|
|
|
this.popDialog();
|
|
|
|
}
|
2010-10-10 14:23:28 -07:00
|
|
|
|
2010-08-27 01:25:04 -07:00
|
|
|
if (this._activePanel)
|
2010-08-24 01:42:28 -07:00
|
|
|
this._activePanel.close();
|
2010-10-10 14:23:28 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
// The readOnly state of the field enabled/disabled the VKB
|
2010-11-04 11:47:09 -07:00
|
|
|
let isReadOnly = !(aPanel == AllPagesList && Util.isPortrait() && (willShowPanel || !this._edit.readOnly));
|
2010-10-14 06:15:29 -07:00
|
|
|
this._edit.readOnly = isReadOnly;
|
|
|
|
if (isReadOnly)
|
|
|
|
this._edit.blur();
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
this._activePanel = aPanel;
|
2010-10-14 06:15:29 -07:00
|
|
|
if (willHidePanel || willShowPanel) {
|
|
|
|
let event = document.createEvent("UIEvents");
|
|
|
|
event.initUIEvent("NavigationPanel" + (willHidePanel ? "Hidden" : "Shown"), true, true, window, false);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
}
|
2010-08-24 01:42:28 -07:00
|
|
|
},
|
|
|
|
|
2009-07-08 07:55:07 -07:00
|
|
|
get activeDialog() {
|
|
|
|
// Return the topmost dialog
|
|
|
|
if (this._dialogs.length)
|
|
|
|
return this._dialogs[this._dialogs.length - 1];
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
pushDialog: function pushDialog(aDialog) {
|
2009-07-08 07:55:07 -07:00
|
|
|
// If we have a dialog push it on the stack and set the attr for CSS
|
|
|
|
if (aDialog) {
|
2009-08-24 07:18:26 -07:00
|
|
|
this.lockToolbar();
|
2009-07-08 07:55:07 -07:00
|
|
|
this._dialogs.push(aDialog);
|
2009-07-20 13:22:22 -07:00
|
|
|
document.getElementById("toolbar-main").setAttribute("dialog", "true");
|
2009-11-23 09:23:59 -08:00
|
|
|
Elements.contentShowing.setAttribute("disabled", "true");
|
2009-07-08 07:55:07 -07:00
|
|
|
}
|
|
|
|
},
|
2009-07-21 08:28:29 -07:00
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
popDialog: function popDialog() {
|
2009-08-24 07:22:26 -07:00
|
|
|
if (this._dialogs.length) {
|
2009-07-08 07:55:07 -07:00
|
|
|
this._dialogs.pop();
|
2009-08-24 07:22:26 -07:00
|
|
|
this.unlockToolbar();
|
|
|
|
}
|
2009-07-08 07:55:07 -07:00
|
|
|
|
|
|
|
// If no more dialogs are being displayed, remove the attr for CSS
|
2009-11-23 09:23:59 -08:00
|
|
|
if (!this._dialogs.length) {
|
2009-07-20 13:22:22 -07:00
|
|
|
document.getElementById("toolbar-main").removeAttribute("dialog");
|
2009-11-23 09:23:59 -08:00
|
|
|
Elements.contentShowing.removeAttribute("disabled");
|
|
|
|
}
|
2009-07-08 07:55:07 -07:00
|
|
|
},
|
|
|
|
|
2009-08-14 10:30:50 -07:00
|
|
|
pushPopup: function pushPopup(aPanel, aElements) {
|
2009-12-04 12:03:56 -08:00
|
|
|
this._hidePopup();
|
2010-01-15 21:41:48 -08:00
|
|
|
this._popup = { "panel": aPanel,
|
2009-08-14 10:30:50 -07:00
|
|
|
"elements": (aElements instanceof Array) ? aElements : [aElements] };
|
2010-10-14 10:19:04 -07:00
|
|
|
this._dispatchPopupChanged(true);
|
2009-08-14 10:30:50 -07:00
|
|
|
},
|
|
|
|
|
2010-11-01 08:42:13 -07:00
|
|
|
popPopup: function popPopup(aPanel) {
|
2010-11-01 16:58:56 -07:00
|
|
|
if (!this._popup || aPanel != this._popup.panel)
|
2010-11-01 08:42:13 -07:00
|
|
|
return;
|
2009-08-14 10:30:50 -07:00
|
|
|
this._popup = null;
|
2010-10-14 10:19:04 -07:00
|
|
|
this._dispatchPopupChanged(false);
|
2009-08-14 10:30:50 -07:00
|
|
|
},
|
|
|
|
|
2010-10-14 10:19:04 -07:00
|
|
|
_dispatchPopupChanged: function _dispatchPopupChanged(aVisible) {
|
2009-12-04 12:03:56 -08:00
|
|
|
let stack = document.getElementById("stack");
|
2010-10-14 10:19:04 -07:00
|
|
|
let event = document.createEvent("UIEvents");
|
|
|
|
event.initUIEvent("PopupChanged", true, true, window, aVisible);
|
2009-12-04 12:03:56 -08:00
|
|
|
event.popup = this._popup;
|
|
|
|
stack.dispatchEvent(event);
|
|
|
|
},
|
|
|
|
|
|
|
|
_hidePopup: function _hidePopup() {
|
2009-08-14 10:30:50 -07:00
|
|
|
if (!this._popup)
|
|
|
|
return;
|
2009-12-04 12:03:56 -08:00
|
|
|
let panel = this._popup.panel;
|
|
|
|
if (panel.hide)
|
|
|
|
panel.hide();
|
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-12-04 12:03:56 -08:00
|
|
|
_isEventInsidePopup: function _isEventInsidePopup(aEvent) {
|
|
|
|
if (!this._popup)
|
2009-12-17 14:35:48 -08:00
|
|
|
return false;
|
2009-12-04 12:03:56 -08:00
|
|
|
let elements = this._popup.elements;
|
2009-10-28 23:12:10 -07:00
|
|
|
let targetNode = aEvent ? aEvent.target : null;
|
2009-12-04 12:03:56 -08:00
|
|
|
while (targetNode && elements.indexOf(targetNode) == -1)
|
2009-08-14 10:30:50 -07:00
|
|
|
targetNode = targetNode.parentNode;
|
2009-12-04 12:03:56 -08:00
|
|
|
return targetNode ? true : false;
|
2009-08-14 10:30:50 -07:00
|
|
|
},
|
|
|
|
|
2010-09-30 14:30:27 -07:00
|
|
|
switchPane: function switchPane(aPanelId) {
|
|
|
|
let button = document.getElementsByAttribute("linkedpanel", aPanelId)[0];
|
2009-11-03 10:32:44 -08:00
|
|
|
if (button)
|
|
|
|
button.checked = true;
|
2009-12-17 14:35:48 -08:00
|
|
|
|
2010-06-14 06:14:16 -07:00
|
|
|
this.blurFocusedElement();
|
|
|
|
|
2010-09-30 14:30:27 -07:00
|
|
|
let pane = document.getElementById(aPanelId);
|
2009-12-17 14:35:48 -08:00
|
|
|
document.getElementById("panel-items").selectedPanel = pane;
|
2008-09-28 06:45:47 -07:00
|
|
|
},
|
|
|
|
|
2009-05-28 22:58:30 -07:00
|
|
|
get toolbarH() {
|
|
|
|
if (!this._toolbarH) {
|
|
|
|
let toolbar = document.getElementById("toolbar-main");
|
|
|
|
this._toolbarH = toolbar.boxObject.height;
|
|
|
|
}
|
|
|
|
return this._toolbarH;
|
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
get sidebarW() {
|
2010-09-02 18:27:20 -07:00
|
|
|
delete this._sidebarW;
|
|
|
|
return this._sidebarW = Elements.controls.getBoundingClientRect().width;
|
2009-08-17 14:05:06 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-08-17 14:05:06 -07:00
|
|
|
get starButton() {
|
|
|
|
delete this.starButton;
|
|
|
|
return this.starButton = document.getElementById("tool-star");
|
|
|
|
},
|
2009-05-28 22:58:30 -07:00
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
sizeControls: function(windowW, windowH) {
|
2009-10-15 09:54:36 -07:00
|
|
|
// tabs
|
|
|
|
document.getElementById("tabs").resize();
|
|
|
|
|
2010-08-24 01:42:28 -07:00
|
|
|
// awesomebar and related panels
|
|
|
|
let popup = document.getElementById("awesome-panels");
|
2009-05-28 22:58:30 -07:00
|
|
|
popup.top = this.toolbarH;
|
2009-09-01 20:35:08 -07:00
|
|
|
popup.height = windowH - this.toolbarH;
|
|
|
|
popup.width = windowW;
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2010-07-19 07:51:03 -07:00
|
|
|
// content navigator helper
|
|
|
|
let contentHelper = document.getElementById("content-navigator");
|
2011-01-19 10:30:06 -08:00
|
|
|
contentHelper.top = windowH;
|
2008-08-19 12:19:47 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
init: function() {
|
2008-07-03 23:39:25 -07:00
|
|
|
this._edit = document.getElementById("urlbar-edit");
|
2010-11-02 12:20:11 -07:00
|
|
|
this._title = document.getElementById("urlbar-title");
|
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);
|
|
|
|
|
2010-06-24 15:25:40 -07:00
|
|
|
this._edit.addEventListener("click", this, false);
|
|
|
|
this._edit.addEventListener("mousedown", this, false);
|
2009-07-14 07:16:23 -07:00
|
|
|
|
2010-10-14 10:19:04 -07:00
|
|
|
window.addEventListener("NavigationPanelShown", this, false);
|
|
|
|
window.addEventListener("NavigationPanelHidden", this, false);
|
2010-08-26 15:48:27 -07:00
|
|
|
|
2011-01-05 08:59:32 -08:00
|
|
|
Elements.tabs.addEventListener("TabSelect", this, true);
|
|
|
|
Elements.tabs.addEventListener("TabOpen", this, true);
|
2010-12-15 22:45:40 -08:00
|
|
|
|
|
|
|
Elements.browsers.addEventListener("PanFinished", this, true);
|
2010-12-29 07:40:51 -08:00
|
|
|
Elements.browsers.addEventListener("SizeChanged", this, true);
|
2009-07-14 07:16:23 -07:00
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
// listen content messages
|
|
|
|
messageManager.addMessageListener("DOMLinkAdded", this);
|
|
|
|
messageManager.addMessageListener("DOMTitleChanged", this);
|
|
|
|
messageManager.addMessageListener("DOMWillOpenModalDialog", this);
|
|
|
|
messageManager.addMessageListener("DOMWindowClose", this);
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2010-06-29 11:15:07 -07:00
|
|
|
messageManager.addMessageListener("Browser:OpenURI", this);
|
|
|
|
messageManager.addMessageListener("Browser:SaveAs:Return", this);
|
2010-06-09 19:12:05 -07:00
|
|
|
|
2009-08-14 10:30:50 -07:00
|
|
|
// listening mousedown for automatically dismiss some popups (e.g. larry)
|
|
|
|
window.addEventListener("mousedown", this, true);
|
2009-07-16 08:45:50 -07:00
|
|
|
|
2009-08-24 08:00:28 -07:00
|
|
|
// listening escape to dismiss dialog on VK_ESCAPE
|
|
|
|
window.addEventListener("keypress", this, true);
|
|
|
|
|
2010-04-27 13:33:59 -07:00
|
|
|
// listening AppCommand to handle special keys
|
|
|
|
window.addEventListener("AppCommand", this, true);
|
|
|
|
|
2010-10-12 11:30:19 -07:00
|
|
|
// We can delay some initialization until after startup. We wait until
|
|
|
|
// the first page is shown, then dispatch a UIReadyDelayed event.
|
2010-10-11 08:13:33 -07:00
|
|
|
messageManager.addMessageListener("pageshow", function() {
|
|
|
|
if (getBrowser().currentURI.spec == "about:blank")
|
|
|
|
return;
|
|
|
|
|
|
|
|
messageManager.removeMessageListener("pageshow", arguments.callee, true);
|
2010-06-21 13:16:37 -07:00
|
|
|
|
2011-01-02 08:56:56 -08:00
|
|
|
setTimeout(function() {
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("UIReadyDelayed", true, false);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
}, 0);
|
2010-10-12 11:30:19 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Delay the panel UI and Sync initialization.
|
|
|
|
window.addEventListener("UIReadyDelayed", function(aEvent) {
|
|
|
|
window.removeEventListener(aEvent.type, arguments.callee, false);
|
|
|
|
|
2009-12-17 14:35:48 -08:00
|
|
|
// We unhide the panelUI so the XBL and settings can initialize
|
|
|
|
Elements.panelUI.hidden = false;
|
2010-03-20 14:33:35 -07:00
|
|
|
|
|
|
|
// Init the views
|
2009-12-17 14:35:48 -08:00
|
|
|
ExtensionsView.init();
|
|
|
|
DownloadsView.init();
|
|
|
|
PreferencesView.init();
|
|
|
|
ConsoleView.init();
|
2010-06-29 08:09:04 -07:00
|
|
|
|
2010-08-04 16:19:16 -07:00
|
|
|
#ifdef MOZ_IPC
|
2010-07-30 12:48:52 -07:00
|
|
|
// Pre-start the content process
|
|
|
|
Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
|
|
|
.ensureContentProcess();
|
2010-08-04 16:19:16 -07:00
|
|
|
#endif
|
2010-07-30 12:48:52 -07:00
|
|
|
|
2010-08-24 01:49:32 -07:00
|
|
|
#ifdef MOZ_SERVICES_SYNC
|
2010-06-29 08:09:04 -07:00
|
|
|
// Init the sync system
|
|
|
|
WeaveGlue.init();
|
2010-08-24 01:49:32 -07:00
|
|
|
#endif
|
2010-06-21 13:36:56 -07:00
|
|
|
|
2011-01-05 08:59:32 -08:00
|
|
|
// Init helpers
|
|
|
|
BadgeHandlers.register(BrowserUI._edit.popup);
|
|
|
|
FormHelperUI.init();
|
|
|
|
FindHelperUI.init();
|
|
|
|
PageActions.init();
|
|
|
|
FullScreenVideo.init();
|
|
|
|
NewTabPopup.init();
|
2010-12-28 20:39:36 -08:00
|
|
|
|
|
|
|
#ifdef MOZ_UPDATER
|
|
|
|
// Check for updates in progress
|
|
|
|
let updatePrompt = Cc["@mozilla.org/updates/update-prompt;1"].createInstance(Ci.nsIUpdatePrompt);
|
|
|
|
updatePrompt.checkForUpdates();
|
|
|
|
#endif
|
2011-01-05 08:59:32 -08:00
|
|
|
}, false);
|
2011-01-20 11:21:55 -08:00
|
|
|
|
|
|
|
#ifndef MOZ_OFFICIAL_BRANDING
|
|
|
|
setTimeout(function() {
|
|
|
|
let startup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup_MOZILLA_2_0).getStartupInfo();
|
|
|
|
for (let name in startup) {
|
|
|
|
if (name != "process")
|
|
|
|
Services.console.logStringMessage("[timing] " + name + ": " + (startup[name] - startup.process) + "ms");
|
|
|
|
}
|
|
|
|
}, 3000);
|
|
|
|
#endif
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
uninit: function() {
|
2009-05-26 18:46:44 -07:00
|
|
|
ExtensionsView.uninit();
|
2009-10-14 12:04:33 -07:00
|
|
|
ConsoleView.uninit();
|
2009-05-26 18:46:44 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
update: function(aState) {
|
2009-10-09 05:34:02 -07:00
|
|
|
let browser = Browser.selectedBrowser;
|
2009-09-08 11:14:59 -07:00
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
switch (aState) {
|
|
|
|
case TOOLBARSTATE_LOADED:
|
2010-11-17 02:18:21 -08:00
|
|
|
this._updateToolbar();
|
2009-10-09 05:34:02 -07:00
|
|
|
|
|
|
|
this._updateIcon(browser.mIconURL);
|
2010-06-02 10:04:03 -07:00
|
|
|
this.unlockToolbar();
|
2008-11-21 21:12:25 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOOLBARSTATE_LOADING:
|
2010-11-17 02:18:21 -08:00
|
|
|
this._updateToolbar();
|
2009-06-18 22:14:04 -07:00
|
|
|
|
2009-10-09 05:34:02 -07:00
|
|
|
browser.mIconURL = "";
|
|
|
|
this._updateIcon();
|
2010-06-02 10:04:03 -07:00
|
|
|
this.lockToolbar();
|
2008-11-21 21:12:25 -08:00
|
|
|
break;
|
2008-10-22 08:39:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
_updateIcon: function(aIconSrc) {
|
2009-10-09 05:34:02 -07:00
|
|
|
this._favicon.src = aIconSrc || "";
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
getDisplayURI: function(browser) {
|
2010-03-31 06:39:05 -07:00
|
|
|
let uri = browser.currentURI;
|
2008-09-27 07:07:04 -07:00
|
|
|
try {
|
2010-07-22 20:55:58 -07:00
|
|
|
uri = gURIFixup.createExposableURI(uri);
|
2008-09-27 07:07:04 -07:00
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
return uri.spec;
|
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
/* Set the location to the current content */
|
2010-07-18 22:27:52 -07:00
|
|
|
updateURI: function() {
|
2010-10-14 06:15:29 -07:00
|
|
|
let 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;
|
|
|
|
|
2009-06-24 15:43:26 -07:00
|
|
|
// Update the navigation buttons
|
|
|
|
this._updateButtons(browser);
|
2008-05-02 13:15:45 -07:00
|
|
|
|
|
|
|
// Check for a bookmarked page
|
2008-12-15 08:44:27 -08:00
|
|
|
this.updateStar();
|
2008-07-03 23:39:25 -07:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
let urlString = this.getDisplayURI(browser);
|
2010-04-08 22:08:53 -07:00
|
|
|
if (Util.isURLEmpty(urlString))
|
2008-07-03 23:39:25 -07:00
|
|
|
urlString = "";
|
2008-05-02 13:15:45 -07:00
|
|
|
|
2010-11-02 12:20:11 -07:00
|
|
|
this._setURL(urlString);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
goToURI: function(aURI) {
|
2009-09-13 21:49:09 -07:00
|
|
|
aURI = aURI || this._edit.value;
|
2008-05-02 13:15:45 -07:00
|
|
|
if (!aURI)
|
2009-09-13 21:49:09 -07:00
|
|
|
return;
|
|
|
|
|
2009-11-24 10:23:41 -08:00
|
|
|
// Make sure we're online before attempting to load
|
|
|
|
Util.forceOnline();
|
|
|
|
|
2009-10-28 20:55:47 -07:00
|
|
|
// Give the new page lots of room
|
|
|
|
Browser.hideSidebars();
|
2010-10-14 06:15:29 -07:00
|
|
|
this.closeAutoComplete();
|
2009-10-28 20:55:47 -07:00
|
|
|
|
2009-10-08 22:49:43 -07:00
|
|
|
this._edit.value = aURI;
|
2008-05-06 07:56:21 -07:00
|
|
|
|
2010-11-01 16:36:07 -07:00
|
|
|
let postData = {};
|
|
|
|
aURI = Browser.getShortcutOrURI(aURI, postData);
|
|
|
|
Browser.loadURI(aURI, { flags: Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP, postData: postData });
|
2010-07-23 06:02:44 -07:00
|
|
|
|
2010-07-22 20:55:58 -07:00
|
|
|
// Delay doing the fixup so the raw URI is passed to loadURIWithFlags
|
|
|
|
// and the proper third-party fixup can be done
|
|
|
|
let fixupFlags = Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
|
|
|
|
let uri = gURIFixup.createFixupURI(aURI, fixupFlags);
|
2010-05-25 08:32:24 -07:00
|
|
|
gHistSvc.markPageAsTyped(uri);
|
2010-12-09 08:06:21 -08:00
|
|
|
|
|
|
|
this._titleChanged(Browser.selectedBrowser);
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
showAutoComplete: function showAutoComplete() {
|
2009-09-18 21:17:52 -07:00
|
|
|
if (this.isAutoCompleteOpen())
|
|
|
|
return;
|
2009-12-03 06:04:57 -08:00
|
|
|
|
2010-11-04 11:42:07 -07:00
|
|
|
this.hidePanel();
|
2010-05-21 10:05:46 -07:00
|
|
|
this._hidePopup();
|
2010-08-24 01:42:28 -07:00
|
|
|
this.activePanel = AllPagesList;
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2010-10-14 06:15:29 -07:00
|
|
|
closeAutoComplete: function closeAutoComplete() {
|
|
|
|
if (this.isAutoCompleteOpen())
|
|
|
|
this._edit.popup.closePopup();
|
2010-09-09 02:08:43 -07:00
|
|
|
|
|
|
|
this.activePanel = null;
|
2009-11-30 22:04:55 -08:00
|
|
|
},
|
2008-07-16 08:41:38 -07:00
|
|
|
|
2009-09-18 21:17:52 -07:00
|
|
|
isAutoCompleteOpen: function isAutoCompleteOpen() {
|
2010-10-10 14:23:28 -07:00
|
|
|
return this.activePanel == AllPagesList;
|
2009-09-18 21:17:52 -07:00
|
|
|
},
|
|
|
|
|
2010-08-26 16:09:56 -07:00
|
|
|
doOpenSearch: function doOpenSearch(aName) {
|
2010-08-25 08:44:18 -07:00
|
|
|
// save the current value of the urlbar
|
|
|
|
let searchValue = this._edit.value;
|
2009-10-28 20:55:47 -07:00
|
|
|
|
|
|
|
// Give the new page lots of room
|
|
|
|
Browser.hideSidebars();
|
2010-10-14 06:15:29 -07:00
|
|
|
this.closeAutoComplete();
|
2008-07-16 08:41:38 -07:00
|
|
|
|
2009-11-24 10:23:41 -08:00
|
|
|
// Make sure we're online before attempting to load
|
|
|
|
Util.forceOnline();
|
|
|
|
|
2010-08-26 16:09:56 -07:00
|
|
|
let engine = Services.search.getEngineByName(aName);
|
|
|
|
let submission = engine.getSubmission(searchValue, null);
|
2010-12-29 07:39:37 -08:00
|
|
|
Browser.selectedBrowser.userTypedValue = submission.uri.spec;
|
2010-08-10 14:32:32 -07:00
|
|
|
Browser.loadURI(submission.uri.spec, { postData: submission.postData });
|
2010-12-29 07:39:37 -08:00
|
|
|
|
|
|
|
this._titleChanged(Browser.selectedBrowser);
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
|
|
|
|
2010-09-30 14:28:07 -07:00
|
|
|
updateUIFocus: function _updateUIFocus() {
|
2010-11-29 10:15:03 -08:00
|
|
|
if (Elements.contentShowing.getAttribute("disabled") == "true")
|
|
|
|
Browser.selectedBrowser.messageManager.sendAsyncMessage("Browser:Blur", { });
|
2010-09-30 14:14:47 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
updateStar: function() {
|
2010-12-29 13:35:06 -08:00
|
|
|
PlacesUtils.asyncGetBookmarkIds(getBrowser().currentURI, function (aItemIds) {
|
|
|
|
if (aItemIds.length)
|
|
|
|
this.starButton.setAttribute("starred", "true");
|
|
|
|
else
|
|
|
|
this.starButton.removeAttribute("starred");
|
|
|
|
}, this);
|
2008-12-15 08:44:27 -08:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
newTab: function newTab(aURI, aOwner) {
|
2009-08-26 10:24:27 -07:00
|
|
|
aURI = aURI || "about:blank";
|
2010-06-15 14:56:13 -07:00
|
|
|
let tab = Browser.addTab(aURI, true, aOwner);
|
2009-08-26 10:24:27 -07:00
|
|
|
|
2009-09-22 15:05:20 -07:00
|
|
|
this.hidePanel();
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2009-09-18 21:17:52 -07:00
|
|
|
if (aURI == "about:blank") {
|
2009-11-30 22:04:55 -08:00
|
|
|
// Display awesomebar UI
|
2010-10-14 06:15:29 -07:00
|
|
|
this.showAutoComplete();
|
2009-09-18 21:17:52 -07:00
|
|
|
}
|
2009-10-28 20:55:47 -07:00
|
|
|
else {
|
|
|
|
// Give the new page lots of room
|
|
|
|
Browser.hideSidebars();
|
2010-10-14 06:15:29 -07:00
|
|
|
this.closeAutoComplete();
|
2009-10-28 20:55:47 -07:00
|
|
|
}
|
|
|
|
|
2009-08-25 20:45:11 -07:00
|
|
|
return tab;
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
|
|
|
|
2010-07-16 08:48:53 -07:00
|
|
|
newOrSelectTab: function newOrSelectTab(aURI, aOwner) {
|
|
|
|
let tabs = Browser.tabs;
|
|
|
|
for (let i = 0; i < tabs.length; i++) {
|
|
|
|
if (tabs[i].browser.currentURI.spec == aURI) {
|
|
|
|
Browser.selectedTab = tabs[i];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.newTab(aURI, aOwner);
|
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
closeTab: function closeTab(aTab) {
|
2009-06-15 05:44:30 -07:00
|
|
|
// If no tab is passed in, assume the current tab
|
|
|
|
Browser.closeTab(aTab || Browser.selectedTab);
|
2008-09-28 23:43:33 -07:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
selectTab: function selectTab(aTab) {
|
2010-09-09 03:16:43 -07:00
|
|
|
this.activePanel = null;
|
2009-01-08 22:51:13 -08:00
|
|
|
Browser.selectedTab = aTab;
|
2009-02-10 13:52:23 -08:00
|
|
|
},
|
|
|
|
|
2010-07-18 22:27:52 -07:00
|
|
|
undoCloseTab: function undoCloseTab(aIndex) {
|
|
|
|
let tab = null;
|
|
|
|
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
|
|
|
|
if (ss.getClosedTabCount(window) > (aIndex || 0)) {
|
2010-11-10 13:49:23 -08:00
|
|
|
let chromeTab = ss.undoCloseTab(window, aIndex || 0);
|
|
|
|
tab = Browser.getTabFromChrome(chromeTab);
|
2010-07-18 22:27:52 -07:00
|
|
|
}
|
|
|
|
return tab;
|
|
|
|
},
|
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
isTabsVisible: function isTabsVisible() {
|
2009-08-28 12:08:39 -07:00
|
|
|
// The _1, _2 and _3 are to make the js2 emacs mode happy
|
|
|
|
let [leftvis,_1,_2,_3] = Browser.computeSidebarVisibility();
|
2009-08-25 21:49:26 -07:00
|
|
|
return (leftvis > 0.002);
|
|
|
|
},
|
|
|
|
|
2009-04-17 07:41:44 -07:00
|
|
|
showPanel: function showPanel(aPage) {
|
2010-09-29 12:54:50 -07:00
|
|
|
if (this.activePanel)
|
|
|
|
this.activePanel = null;
|
|
|
|
|
2009-12-17 14:35:48 -08:00
|
|
|
Elements.panelUI.left = 0;
|
|
|
|
Elements.panelUI.hidden = false;
|
2009-11-23 09:23:59 -08:00
|
|
|
Elements.contentShowing.setAttribute("disabled", "true");
|
|
|
|
|
2009-04-17 07:41:44 -07:00
|
|
|
if (aPage != undefined)
|
|
|
|
this.switchPane(aPage);
|
|
|
|
},
|
|
|
|
|
|
|
|
hidePanel: function hidePanel() {
|
2010-06-22 13:20:56 -07:00
|
|
|
if (!this.isPanelVisible())
|
|
|
|
return;
|
2009-12-17 14:35:48 -08:00
|
|
|
Elements.panelUI.hidden = true;
|
2009-11-23 09:23:59 -08:00
|
|
|
Elements.contentShowing.removeAttribute("disabled");
|
2010-06-14 06:14:16 -07:00
|
|
|
this.blurFocusedElement();
|
2008-05-02 13:15:45 -07:00
|
|
|
},
|
2009-12-17 14:35:48 -08:00
|
|
|
|
|
|
|
isPanelVisible: function isPanelVisible() {
|
|
|
|
return (!Elements.panelUI.hidden && Elements.panelUI.left == 0);
|
|
|
|
},
|
|
|
|
|
2010-06-14 06:14:16 -07:00
|
|
|
blurFocusedElement: function blurFocusedElement() {
|
|
|
|
let focusedElement = document.commandDispatcher.focusedElement;
|
|
|
|
if (focusedElement)
|
|
|
|
focusedElement.blur();
|
|
|
|
},
|
|
|
|
|
2009-09-23 09:09:44 -07:00
|
|
|
switchTask: function switchTask() {
|
|
|
|
try {
|
|
|
|
let phone = Cc["@mozilla.org/phone/support;1"].createInstance(Ci.nsIPhoneSupport);
|
|
|
|
phone.switchTask();
|
|
|
|
} catch(e) { }
|
|
|
|
},
|
2010-01-15 21:41:48 -08:00
|
|
|
|
2010-08-17 09:38:45 -07:00
|
|
|
handleEscape: function (aEvent) {
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
|
2010-08-27 01:24:17 -07:00
|
|
|
// Check open popups
|
|
|
|
if (this._popup) {
|
|
|
|
this._hidePopup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check active panel
|
2010-09-07 10:53:10 -07:00
|
|
|
if (this.activePanel) {
|
|
|
|
this.activePanel = null;
|
2010-08-24 01:43:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-28 11:32:17 -07:00
|
|
|
// Check open dialogs
|
|
|
|
let dialog = this.activeDialog;
|
|
|
|
if (dialog) {
|
|
|
|
dialog.close();
|
|
|
|
return;
|
|
|
|
}
|
2010-07-28 17:41:42 -07:00
|
|
|
|
2010-04-28 11:32:17 -07:00
|
|
|
// Check open modal elements
|
|
|
|
let modalElementsLength = document.getElementsByClassName("modal-block").length;
|
2010-07-28 14:27:23 -07:00
|
|
|
if (modalElementsLength > 0)
|
2010-04-28 11:32:17 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Check open panel
|
|
|
|
if (this.isPanelVisible()) {
|
|
|
|
this.hidePanel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-28 16:19:00 -07:00
|
|
|
// Check content helper
|
|
|
|
let contentHelper = document.getElementById("content-navigator");
|
|
|
|
if (contentHelper.isActive) {
|
2010-11-10 07:57:55 -08:00
|
|
|
contentHelper.model.hide();
|
2010-09-28 16:19:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-28 11:32:17 -07:00
|
|
|
// Only if there are no dialogs, popups, or panels open
|
2010-06-15 14:56:13 -07:00
|
|
|
let tab = Browser.selectedTab;
|
|
|
|
let browser = tab.browser;
|
|
|
|
|
2010-09-30 14:05:43 -07:00
|
|
|
if (browser.canGoBack) {
|
2010-06-15 14:56:13 -07:00
|
|
|
browser.goBack();
|
2010-09-30 14:05:43 -07:00
|
|
|
} else if (tab.owner) {
|
2010-06-15 14:56:13 -07:00
|
|
|
this.closeTab(tab);
|
2010-09-30 14:05:43 -07:00
|
|
|
}
|
2010-06-17 10:36:38 -07:00
|
|
|
#ifdef ANDROID
|
2010-09-30 14:05:43 -07:00
|
|
|
else {
|
2010-06-17 10:36:38 -07:00
|
|
|
window.QueryInterface(Ci.nsIDOMChromeWindow).minimize();
|
2010-09-30 14:05:43 -07:00
|
|
|
if (tab.closeOnExit)
|
|
|
|
this.closeTab(tab);
|
|
|
|
}
|
2010-06-17 10:36:38 -07:00
|
|
|
#endif
|
2010-04-28 11:32:17 -07:00
|
|
|
},
|
|
|
|
|
2010-06-09 19:12:05 -07:00
|
|
|
handleEvent: function handleEvent(aEvent) {
|
2008-05-02 13:15:45 -07:00
|
|
|
switch (aEvent.type) {
|
2008-07-03 23:39:25 -07:00
|
|
|
// Browser events
|
2008-08-19 23:09:22 -07:00
|
|
|
case "TabSelect":
|
|
|
|
this._tabSelect(aEvent);
|
|
|
|
break;
|
2009-08-25 21:49:26 -07:00
|
|
|
case "TabOpen":
|
2009-12-01 20:20:58 -08:00
|
|
|
{
|
2010-04-14 09:59:47 -07:00
|
|
|
// Workaround to hide the tabstrip if it is partially visible
|
|
|
|
// See bug 524469
|
2010-11-04 10:14:11 -07:00
|
|
|
let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
|
2010-04-14 09:59:47 -07:00
|
|
|
if (tabsVisibility > 0.0 && tabsVisibility < 1.0)
|
|
|
|
Browser.hideSidebars();
|
2009-12-01 20:20:58 -08:00
|
|
|
|
2009-08-25 21:49:26 -07:00
|
|
|
break;
|
2009-12-01 20:20:58 -08:00
|
|
|
}
|
2010-10-06 08:08:56 -07:00
|
|
|
case "PanFinished":
|
|
|
|
let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
|
|
|
|
if (tabsVisibility == 0.0)
|
|
|
|
document.getElementById("tabs").removeClosedTab();
|
|
|
|
break;
|
2010-12-29 07:40:51 -08:00
|
|
|
case "SizeChanged":
|
2010-12-30 01:05:30 -08:00
|
|
|
this.sizeControls(ViewableAreaObserver.width, ViewableAreaObserver.height);
|
2010-12-29 07:40:51 -08:00
|
|
|
break;
|
2010-04-06 16:42:36 -07:00
|
|
|
// Window events
|
2008-05-02 13:15:45 -07:00
|
|
|
case "keypress":
|
2010-04-28 11:32:17 -07:00
|
|
|
if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE)
|
2010-08-17 09:38:45 -07:00
|
|
|
this.handleEscape(aEvent);
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
2010-04-27 13:33:59 -07:00
|
|
|
case "AppCommand":
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
switch (aEvent.command) {
|
|
|
|
case "Menu":
|
|
|
|
this.doCommand("cmd_menu");
|
|
|
|
break;
|
|
|
|
case "Search":
|
2010-11-03 06:45:19 -07:00
|
|
|
if (!this.activePanel)
|
|
|
|
AllPagesList.doCommand();
|
|
|
|
else
|
|
|
|
this.doCommand("cmd_opensearch");
|
2010-04-27 13:33:59 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-04-06 16:42:36 -07:00
|
|
|
// URL textbox events
|
2010-05-24 09:11:23 -07:00
|
|
|
case "click":
|
2010-11-02 12:20:11 -07:00
|
|
|
if (this._edit.readOnly)
|
2010-10-10 14:23:28 -07:00
|
|
|
this._edit.readOnly = false;
|
2010-04-06 16:42:36 -07:00
|
|
|
break;
|
2009-07-21 17:05:01 -07:00
|
|
|
case "mousedown":
|
2009-12-04 12:03:56 -08:00
|
|
|
if (!this._isEventInsidePopup(aEvent))
|
|
|
|
this._hidePopup();
|
2009-07-21 17:05:01 -07:00
|
|
|
break;
|
2008-07-03 23:39:25 -07:00
|
|
|
// Favicon events
|
2008-05-02 13:15:45 -07:00
|
|
|
case "error":
|
2009-10-09 05:34:02 -07:00
|
|
|
this._favicon.src = "";
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
2010-08-26 15:48:27 -07:00
|
|
|
// Awesome popup event
|
2010-10-14 10:19:04 -07:00
|
|
|
case "NavigationPanelShown":
|
2010-11-02 12:20:11 -07:00
|
|
|
this._edit.collapsed = false;
|
|
|
|
this._title.collapsed = true;
|
|
|
|
|
|
|
|
if (!this._edit.readOnly)
|
|
|
|
this._edit.focus();
|
2010-10-21 10:53:15 -07:00
|
|
|
|
|
|
|
// Disabled the search button if no search engines are available
|
|
|
|
let button = document.getElementById("urlbar-icons");
|
|
|
|
if (BrowserSearch.engines.length)
|
|
|
|
button.removeAttribute("disabled");
|
|
|
|
else
|
|
|
|
button.setAttribute("disabled", "true");
|
|
|
|
|
2010-08-26 15:48:27 -07:00
|
|
|
break;
|
2010-11-03 06:45:19 -07:00
|
|
|
case "NavigationPanelHidden": {
|
2010-11-02 12:20:11 -07:00
|
|
|
this._edit.collapsed = true;
|
|
|
|
this._title.collapsed = false;
|
2010-11-17 02:18:21 -08:00
|
|
|
this._updateToolbar();
|
2010-11-02 12:20:11 -07:00
|
|
|
|
2010-11-03 06:45:19 -07:00
|
|
|
let button = document.getElementById("urlbar-icons");
|
|
|
|
button.removeAttribute("open");
|
|
|
|
button.removeAttribute("disabled");
|
2010-08-26 15:48:27 -07:00
|
|
|
break;
|
2010-11-03 06:45:19 -07:00
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-09 19:12:05 -07:00
|
|
|
receiveMessage: function receiveMessage(aMessage) {
|
2010-06-08 08:22:20 -07:00
|
|
|
let browser = aMessage.target;
|
2010-06-21 13:16:37 -07:00
|
|
|
let json = aMessage.json;
|
2010-06-08 08:22:20 -07:00
|
|
|
switch (aMessage.name) {
|
|
|
|
case "DOMTitleChanged":
|
|
|
|
this._titleChanged(browser);
|
|
|
|
break;
|
|
|
|
case "DOMWillOpenModalDialog":
|
|
|
|
return this._domWillOpenModalDialog(browser);
|
|
|
|
break;
|
|
|
|
case "DOMWindowClose":
|
|
|
|
return this._domWindowClose(browser);
|
|
|
|
break;
|
|
|
|
case "DOMLinkAdded":
|
|
|
|
if (Browser.selectedBrowser == browser)
|
|
|
|
this._updateIcon(Browser.selectedBrowser.mIconURL);
|
|
|
|
break;
|
2010-06-09 19:12:05 -07:00
|
|
|
case "Browser:SaveAs:Return":
|
|
|
|
if (json.type != Ci.nsIPrintSettings.kOutputFormatPDF)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
|
|
|
let db = dm.DBConnection;
|
|
|
|
let stmt = db.createStatement("UPDATE moz_downloads SET endTime = :endTime, state = :state WHERE id = :id");
|
|
|
|
stmt.params.endTime = Date.now() * 1000;
|
|
|
|
stmt.params.state = Ci.nsIDownloadManager.DOWNLOAD_FINISHED;
|
|
|
|
stmt.params.id = json.id;
|
|
|
|
stmt.execute();
|
|
|
|
stmt.finalize();
|
|
|
|
|
|
|
|
let download = dm.getDownload(json.id);
|
2010-11-16 15:38:47 -08:00
|
|
|
#ifdef ANDROID
|
|
|
|
// since our content process doesn't have write permissions to the
|
|
|
|
// downloads dir, we save it to the tmp dir and then move it here
|
|
|
|
let dlFile = download.targetFile;
|
|
|
|
if (!dlFile.exists())
|
2010-12-27 18:50:30 -08:00
|
|
|
dlFile.create(file.NORMAL_FILE_TYPE, 0666);
|
2011-01-10 21:56:29 -08:00
|
|
|
let tmpDir = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
|
2010-11-16 15:38:47 -08:00
|
|
|
let tmpFile = tmpDir.clone();
|
|
|
|
tmpFile.append(dlFile.leafName);
|
|
|
|
|
|
|
|
// we sometimes race with the content process, so make sure its finished
|
|
|
|
// creating/writing the file
|
|
|
|
while (!tmpFile.exists());
|
|
|
|
tmpFile.moveTo(dlFile.parent, dlFile.leafName);
|
|
|
|
#endif
|
2010-06-09 19:12:05 -07:00
|
|
|
try {
|
|
|
|
DownloadsView.downloadCompleted(download);
|
|
|
|
let element = DownloadsView.getElementForDownload(json.id);
|
|
|
|
element.setAttribute("state", Ci.nsIDownloadManager.DOWNLOAD_FINISHED);
|
|
|
|
element.setAttribute("endTime", Date.now());
|
|
|
|
element.setAttribute("referrer", json.referrer);
|
|
|
|
DownloadsView._updateTime(element);
|
|
|
|
DownloadsView._updateStatus(element);
|
|
|
|
}
|
|
|
|
catch(e) {}
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.obs.notifyObservers(download, "dl-done", null);
|
2010-06-09 19:12:05 -07:00
|
|
|
break;
|
2010-06-21 13:16:37 -07:00
|
|
|
|
2010-06-29 11:15:07 -07:00
|
|
|
case "Browser:OpenURI":
|
2010-11-22 12:08:49 -08:00
|
|
|
let referrerURI = null;
|
|
|
|
if (json.referrer)
|
|
|
|
referrerURI = Services.io.newURI(json.referrer, null, null);
|
|
|
|
Browser.addTab(json.uri, json.bringFront, Browser.selectedTab, { referrerURI: referrerURI });
|
2010-09-22 16:27:11 -07:00
|
|
|
break;
|
2010-06-08 08:22:20 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
supportsCommand : function(cmd) {
|
|
|
|
var isSupported = false;
|
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_back":
|
|
|
|
case "cmd_forward":
|
|
|
|
case "cmd_reload":
|
2010-02-16 15:38:37 -08:00
|
|
|
case "cmd_forceReload":
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_stop":
|
|
|
|
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":
|
2010-08-26 16:09:56 -07:00
|
|
|
case "cmd_opensearch":
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_bookmarks":
|
2010-08-24 01:42:28 -07:00
|
|
|
case "cmd_history":
|
|
|
|
case "cmd_remoteTabs":
|
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":
|
2010-07-18 22:27:52 -07:00
|
|
|
case "cmd_undoCloseTab":
|
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":
|
2010-04-30 12:30:28 -07:00
|
|
|
case "cmd_volumeLeft":
|
|
|
|
case "cmd_volumeRight":
|
2010-04-12 07:58:38 -07:00
|
|
|
case "cmd_lockscreen":
|
2008-05-02 13:15:45 -07:00
|
|
|
isSupported = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
isSupported = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return isSupported;
|
|
|
|
},
|
|
|
|
|
|
|
|
isCommandEnabled : function(cmd) {
|
2010-09-23 02:00:00 -07:00
|
|
|
let elem = document.getElementById(cmd);
|
|
|
|
if (elem && (elem.getAttribute("disabled") == "true"))
|
|
|
|
return false;
|
2008-05-02 13:15:45 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
doCommand : function(cmd) {
|
2010-09-23 02:00:00 -07:00
|
|
|
if (!this.isCommandEnabled(cmd))
|
|
|
|
return;
|
2010-08-24 01:42:28 -07:00
|
|
|
let browser = getBrowser();
|
2008-05-02 13:15:45 -07:00
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_back":
|
|
|
|
browser.goBack();
|
|
|
|
break;
|
|
|
|
case "cmd_forward":
|
|
|
|
browser.goForward();
|
|
|
|
break;
|
|
|
|
case "cmd_reload":
|
|
|
|
browser.reload();
|
|
|
|
break;
|
2010-02-16 15:38:37 -08:00
|
|
|
case "cmd_forceReload":
|
|
|
|
{
|
2010-04-30 13:53:25 -07:00
|
|
|
// Simulate a new page
|
2010-06-04 06:15:13 -07:00
|
|
|
browser.lastLocation = null;
|
2010-04-30 13:53:25 -07:00
|
|
|
|
2010-02-16 15:38:37 -08:00
|
|
|
const reloadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY |
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
|
|
|
|
browser.reloadWithFlags(reloadFlags);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_stop":
|
|
|
|
browser.stop();
|
|
|
|
break;
|
|
|
|
case "cmd_go":
|
|
|
|
this.goToURI();
|
|
|
|
break;
|
2008-11-12 18:40:57 -08:00
|
|
|
case "cmd_openLocation":
|
2010-10-14 06:15:29 -07:00
|
|
|
this.showAutoComplete();
|
2008-11-12 18:40:57 -08:00
|
|
|
break;
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_star":
|
|
|
|
{
|
2010-12-30 09:58:31 -08:00
|
|
|
BookmarkPopup.toggle();
|
|
|
|
if (!this.starButton.hasAttribute("starred")) {
|
|
|
|
this.starButton.setAttribute("starred", "true");
|
|
|
|
BookmarkPopup.autoHide();
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
2009-08-17 14:05:06 -07:00
|
|
|
|
2010-12-30 09:58:31 -08:00
|
|
|
let bookmarkURI = browser.currentURI;
|
|
|
|
PlacesUtils.asyncGetBookmarkIds(bookmarkURI, function (aItemIds) {
|
|
|
|
if (!aItemIds.length) {
|
|
|
|
let bookmarkTitle = browser.contentTitle || bookmarkURI.spec;
|
|
|
|
try {
|
|
|
|
let bookmarkService = PlacesUtils.bookmarks;
|
|
|
|
let bookmarkId = bookmarkService.insertBookmark(BookmarkList.panel.mobileRoot, bookmarkURI,
|
|
|
|
bookmarkService.DEFAULT_INDEX,
|
|
|
|
bookmarkTitle);
|
|
|
|
} catch (e) {
|
|
|
|
// Insert failed; reset the star state.
|
|
|
|
this.updateStar();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Used for browser-chrome tests
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("BookmarkCreated", true, false);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
}, this);
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-08-26 16:09:56 -07:00
|
|
|
case "cmd_opensearch":
|
2010-10-19 17:51:12 -07:00
|
|
|
this.blurFocusedElement();
|
2010-10-19 15:54:45 -07:00
|
|
|
BrowserSearch.toggle();
|
2010-08-26 16:09:56 -07:00
|
|
|
break;
|
2008-05-02 13:15:45 -07:00
|
|
|
case "cmd_bookmarks":
|
2010-08-24 01:42:28 -07:00
|
|
|
this.activePanel = BookmarkList;
|
|
|
|
break;
|
|
|
|
case "cmd_history":
|
|
|
|
this.activePanel = HistoryList;
|
|
|
|
break;
|
|
|
|
case "cmd_remoteTabs":
|
|
|
|
this.activePanel = RemoteTabsList;
|
2008-05-02 13:15:45 -07:00
|
|
|
break;
|
2009-03-19 16:20:32 -07:00
|
|
|
case "cmd_quit":
|
2011-01-04 11:22:30 -08:00
|
|
|
GlobalOverlay.goQuitApplication();
|
2009-03-19 16:20:32 -07:00
|
|
|
break;
|
|
|
|
case "cmd_close":
|
2009-07-08 07:55:07 -07:00
|
|
|
this._closeOrQuit();
|
2009-03-19 16:20:32 -07:00
|
|
|
break;
|
2008-07-25 11:10:35 -07:00
|
|
|
case "cmd_menu":
|
2010-11-09 13:42:16 -08:00
|
|
|
AppMenu.toggle();
|
2008-07-25 11:10:35 -07:00
|
|
|
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;
|
2010-07-18 22:27:52 -07:00
|
|
|
case "cmd_undoCloseTab":
|
|
|
|
this.undoCloseTab();
|
|
|
|
break;
|
2008-09-06 23:54:06 -07:00
|
|
|
case "cmd_sanitize":
|
2009-05-20 10:31:53 -07:00
|
|
|
{
|
2011-01-03 12:07:41 -08:00
|
|
|
let title = Strings.browser.GetStringFromName("clearPrivateData.title");
|
|
|
|
let message = Strings.browser.GetStringFromName("clearPrivateData.message");
|
2010-12-21 09:42:04 -08:00
|
|
|
let clear = Services.prompt.confirm(window, title, message);
|
|
|
|
if (clear) {
|
|
|
|
// disable the button temporarily to indicate something happened
|
|
|
|
let button = document.getElementById("prefs-clear-data");
|
|
|
|
button.disabled = true;
|
|
|
|
setTimeout(function() { button.disabled = false; }, 5000);
|
|
|
|
|
|
|
|
Sanitizer.sanitize();
|
|
|
|
}
|
2008-08-19 19:18:36 -07:00
|
|
|
break;
|
2009-05-20 10:31:53 -07:00
|
|
|
}
|
2008-09-10 17:38:02 -07:00
|
|
|
case "cmd_panel":
|
|
|
|
{
|
2009-12-17 14:35:48 -08:00
|
|
|
if (BrowserUI.isPanelVisible())
|
2009-04-17 07:41:44 -07:00
|
|
|
this.hidePanel();
|
2009-12-17 14:35:48 -08:00
|
|
|
else
|
|
|
|
this.showPanel();
|
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":
|
2009-11-24 11:44:05 -08:00
|
|
|
Browser.zoom(-1);
|
2008-10-09 21:11:27 -07:00
|
|
|
break;
|
|
|
|
case "cmd_zoomout":
|
2009-11-24 11:44:05 -08:00
|
|
|
Browser.zoom(1);
|
2008-10-09 21:11:27 -07:00
|
|
|
break;
|
2010-04-30 12:30:28 -07:00
|
|
|
case "cmd_volumeLeft":
|
|
|
|
// Zoom in (portrait) or out (landscape)
|
|
|
|
Browser.zoom(Util.isPortrait() ? -1 : 1);
|
|
|
|
break;
|
|
|
|
case "cmd_volumeRight":
|
|
|
|
// Zoom out (portrait) or in (landscape)
|
|
|
|
Browser.zoom(Util.isPortrait() ? 1 : -1);
|
|
|
|
break;
|
2010-04-12 07:58:38 -07:00
|
|
|
case "cmd_lockscreen":
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
let locked = Services.prefs.getBoolPref("toolkit.screen.lock");
|
|
|
|
Services.prefs.setBoolPref("toolkit.screen.lock", !locked);
|
2010-05-06 12:16:58 -07:00
|
|
|
|
2011-01-03 12:07:41 -08:00
|
|
|
let strings = Strings.browser;
|
2010-05-06 12:16:58 -07:00
|
|
|
let alerts = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
|
2011-01-03 12:07:41 -08:00
|
|
|
alerts.showAlertNotification(null, strings.GetStringFromName("alertLockScreen"),
|
|
|
|
strings.GetStringFromName("alertLockScreen." + (!locked ? "locked" : "unlocked")), false, "", null);
|
2010-04-12 07:58:38 -07:00
|
|
|
break;
|
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|