2008-09-23 08:19:11 -07:00
|
|
|
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
|
|
|
/*
|
2008-05-13 14:39:17 -07:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
2008-04-18 06:41:49 -07:00
|
|
|
* 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):
|
|
|
|
* Brad Lassey <blassey@mozilla.com>
|
|
|
|
* Mark Finkle <mfinkle@mozilla.com>
|
|
|
|
* Aleks Totic <a@totic.org>
|
2008-06-20 14:01:42 -07:00
|
|
|
* Johnathan Nightingale <johnath@mozilla.com>
|
2008-11-21 21:12:25 -08:00
|
|
|
* Stuart Parmenter <stuart@mozilla.com>
|
2009-03-31 11:45:24 -07:00
|
|
|
* Taras Glek <tglek@mozilla.com>
|
2009-07-27 19:04:22 -07:00
|
|
|
* Roy Frostig <rfrostig@mozilla.com>
|
2009-08-07 18:08:06 -07:00
|
|
|
* Ben Combee <bcombee@mozilla.com>
|
2010-04-29 12:29:01 -07:00
|
|
|
* Matt Brubeck <mbrubeck@mozilla.com>
|
2010-06-25 14:16:01 -07:00
|
|
|
* Benjamin Stover <bstover@mozilla.com>
|
|
|
|
* Miika Jarvinen <mjarvin@gmail.com>
|
|
|
|
* Jaakko Kiviluoto <jaakko.kiviluoto@digia.com>
|
2009-08-10 18:03:42 -07:00
|
|
|
*
|
2008-04-18 06:41:49 -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 ***** */
|
|
|
|
|
2009-03-16 21:27:29 -07:00
|
|
|
let Cc = Components.classes;
|
|
|
|
let Ci = Components.interfaces;
|
|
|
|
let Cu = Components.utils;
|
2008-04-18 06:41:49 -07:00
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
function getBrowser() {
|
2009-01-08 22:51:13 -08:00
|
|
|
return Browser.selectedBrowser;
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
2008-04-18 06:41:49 -07:00
|
|
|
|
2010-09-10 14:22:19 -07:00
|
|
|
const kDefaultBrowserWidth = 980;
|
2010-09-01 13:40:34 -07:00
|
|
|
const kBrowserFormZoomLevelMin = 1.0;
|
|
|
|
const kBrowserFormZoomLevelMax = 2.0;
|
|
|
|
const kBrowserViewZoomLevelPrecision = 10000;
|
2009-03-05 21:42:39 -08:00
|
|
|
|
2010-09-17 10:59:09 -07:00
|
|
|
const kDefaultMetadata = { allowZoom: true };
|
|
|
|
|
2010-05-20 10:52:30 -07:00
|
|
|
// Override sizeToContent in the main window. It breaks things (bug 565887)
|
|
|
|
window.sizeToContent = function() {
|
|
|
|
Components.utils.reportError("window.sizeToContent is not allowed in this window");
|
|
|
|
}
|
|
|
|
|
2010-05-21 10:00:27 -07:00
|
|
|
#ifdef MOZ_CRASH_REPORTER
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "CrashReporter",
|
|
|
|
"@mozilla.org/xre/app-info;1", "nsICrashReporter");
|
|
|
|
#endif
|
|
|
|
|
2010-03-11 06:18:41 -08:00
|
|
|
const endl = '\n';
|
|
|
|
|
2009-08-17 11:16:11 -07:00
|
|
|
function onDebugKeyPress(ev) {
|
2009-07-30 17:31:09 -07:00
|
|
|
if (!ev.ctrlKey)
|
2009-07-17 16:17:57 -07:00
|
|
|
return;
|
|
|
|
|
2009-08-17 11:16:11 -07:00
|
|
|
// use capitals so we require SHIFT here too
|
2009-08-22 11:06:51 -07:00
|
|
|
|
2010-08-19 16:28:44 -07:00
|
|
|
const a = 65;
|
|
|
|
const b = 66;
|
2010-01-14 13:35:08 -08:00
|
|
|
const c = 67;
|
2010-08-27 15:01:32 -07:00
|
|
|
const d = 68;
|
2009-08-17 11:16:11 -07:00
|
|
|
const e = 69;
|
2010-08-27 15:01:32 -07:00
|
|
|
const f = 70; // force GC
|
2009-08-17 11:16:11 -07:00
|
|
|
const g = 71;
|
|
|
|
const h = 72;
|
2010-08-27 15:01:32 -07:00
|
|
|
const i = 73;
|
2009-08-17 11:16:11 -07:00
|
|
|
const j = 74;
|
|
|
|
const k = 75;
|
2010-08-27 15:01:32 -07:00
|
|
|
const l = 76;
|
|
|
|
const m = 77;
|
2009-08-17 11:16:11 -07:00
|
|
|
const n = 78;
|
2010-05-06 06:21:26 -07:00
|
|
|
const o = 79;
|
2010-09-09 21:59:30 -07:00
|
|
|
const p = 80; // fake pinch zoom
|
2010-05-06 06:21:26 -07:00
|
|
|
const q = 81; // toggle orientation
|
2010-08-27 15:01:32 -07:00
|
|
|
const r = 82;
|
2009-08-17 11:16:11 -07:00
|
|
|
const s = 83;
|
2010-07-18 22:27:52 -07:00
|
|
|
const t = 84;
|
2010-08-19 16:28:44 -07:00
|
|
|
const u = 85;
|
2009-08-17 11:16:11 -07:00
|
|
|
const v = 86;
|
|
|
|
const w = 87;
|
|
|
|
const x = 88;
|
|
|
|
const y = 89;
|
2010-08-27 15:01:32 -07:00
|
|
|
const z = 90;
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-07-30 17:31:09 -07:00
|
|
|
switch (ev.charCode) {
|
2009-09-04 22:14:59 -07:00
|
|
|
case f:
|
2010-06-22 06:24:55 -07:00
|
|
|
MemoryObserver.observe();
|
|
|
|
dump("Forced a GC\n");
|
2009-07-17 16:17:57 -07:00
|
|
|
break;
|
2010-05-06 06:21:26 -07:00
|
|
|
#ifndef MOZ_PLATFORM_MAEMO
|
2010-09-09 21:59:30 -07:00
|
|
|
case p:
|
|
|
|
function dispatchMagnifyEvent(aName, aDelta) {
|
|
|
|
let e = document.createEvent("SimpleGestureEvent");
|
|
|
|
e.initSimpleGestureEvent("MozMagnifyGesture"+aName, true, true, window, null,
|
|
|
|
0, 0, 0, 0, false, false, false, false, 0, null, 0, aDelta);
|
|
|
|
document.getElementById("inputhandler-overlay").dispatchEvent(e);
|
|
|
|
}
|
|
|
|
dispatchMagnifyEvent("Start", 0);
|
|
|
|
|
|
|
|
let frame = 0;
|
|
|
|
let timer = new Util.Timeout();
|
|
|
|
timer.interval(100, function() {
|
|
|
|
dispatchMagnifyEvent("Update", 20);
|
|
|
|
if (++frame > 10) {
|
|
|
|
timer.clear();
|
|
|
|
dispatchMagnifyEvent("", frame*20);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
2010-05-06 06:21:26 -07:00
|
|
|
case q:
|
|
|
|
if (Util.isPortrait())
|
|
|
|
window.top.resizeTo(800,480);
|
|
|
|
else
|
|
|
|
window.top.resizeTo(480,800);
|
|
|
|
break;
|
|
|
|
#endif
|
2009-07-17 16:17:57 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
var Browser = {
|
2008-11-21 21:12:25 -08:00
|
|
|
_tabs : [],
|
2009-01-08 22:51:13 -08:00
|
|
|
_selectedTab : null,
|
2009-04-17 14:10:06 -07:00
|
|
|
windowUtils: window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils),
|
2009-08-05 14:06:38 -07:00
|
|
|
controlsScrollbox: null,
|
|
|
|
controlsScrollboxScroller: null,
|
2009-10-20 06:36:26 -07:00
|
|
|
pageScrollbox: null,
|
|
|
|
pageScrollboxScroller: null,
|
2009-10-14 14:19:29 -07:00
|
|
|
styles: {},
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2010-03-26 08:11:03 -07:00
|
|
|
startup: function startup() {
|
2008-11-21 21:12:25 -08:00
|
|
|
var self = this;
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
try {
|
2010-06-09 16:07:12 -07:00
|
|
|
messageManager.loadFrameScript("chrome://browser/content/Util.js", true);
|
2010-06-21 13:36:56 -07:00
|
|
|
messageManager.loadFrameScript("chrome://browser/content/forms.js", true);
|
2010-06-08 08:22:20 -07:00
|
|
|
messageManager.loadFrameScript("chrome://browser/content/content.js", true);
|
|
|
|
} catch (e) {
|
|
|
|
// XXX whatever is calling startup needs to dump errors!
|
|
|
|
dump("###########" + e + "\n");
|
|
|
|
}
|
|
|
|
|
2010-08-12 20:22:00 -07:00
|
|
|
let container = document.getElementById("browsers");
|
2010-08-31 12:25:47 -07:00
|
|
|
// XXX change
|
2009-06-19 14:25:42 -07:00
|
|
|
|
2010-08-19 16:28:44 -07:00
|
|
|
/* handles dispatching clicks on browser into clicks in content or zooms */
|
2010-09-01 15:23:21 -07:00
|
|
|
let inputHandlerOverlay = document.getElementById("inputhandler-overlay");
|
|
|
|
inputHandlerOverlay.customDragger = new Browser.MainDragger();
|
2010-08-12 20:22:00 -07:00
|
|
|
|
2010-09-27 08:11:56 -07:00
|
|
|
let keySender = new ContentCustomKeySender(inputHandlerOverlay);
|
2010-09-22 16:27:11 -07:00
|
|
|
let mouseModule = new MouseModule();
|
|
|
|
let gestureModule = new GestureModule();
|
|
|
|
let scrollWheelModule = new ScrollwheelModule(inputHandlerOverlay);
|
|
|
|
|
2010-09-22 15:08:18 -07:00
|
|
|
ContentTouchHandler.init();
|
|
|
|
|
2010-08-19 16:28:44 -07:00
|
|
|
// Warning, total hack ahead. All of the real-browser related scrolling code
|
|
|
|
// lies in a pretend scrollbox here. Let's not land this as-is. Maybe it's time
|
|
|
|
// to redo all the dragging code.
|
2010-08-12 20:22:00 -07:00
|
|
|
this.contentScrollbox = container;
|
|
|
|
this.contentScrollboxScroller = {
|
|
|
|
scrollBy: function(x, y) {
|
2010-08-30 14:11:49 -07:00
|
|
|
getBrowser().scrollBy(x, y);
|
2010-08-12 20:22:00 -07:00
|
|
|
},
|
2009-07-24 15:51:16 -07:00
|
|
|
|
2010-08-12 20:22:00 -07:00
|
|
|
scrollTo: function(x, y) {
|
2010-08-30 14:11:49 -07:00
|
|
|
getBrowser().scrollTo(x, y);
|
2010-08-12 20:22:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getPosition: function(scrollX, scrollY) {
|
2010-09-15 15:05:50 -07:00
|
|
|
let { x: x, y: y } = getBrowser().getPosition();
|
|
|
|
scrollX.value = x;
|
|
|
|
scrollY.value = y;
|
2010-08-12 20:22:00 -07:00
|
|
|
}
|
|
|
|
};
|
2009-08-05 14:06:38 -07:00
|
|
|
|
2009-08-07 18:08:06 -07:00
|
|
|
/* horizontally scrolling box that holds the sidebars as well as the contentScrollbox */
|
2009-10-14 14:19:29 -07:00
|
|
|
let controlsScrollbox = this.controlsScrollbox = document.getElementById("controls-scrollbox");
|
2009-08-05 14:06:38 -07:00
|
|
|
this.controlsScrollboxScroller = controlsScrollbox.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
2009-08-05 14:31:57 -07:00
|
|
|
controlsScrollbox.customDragger = {
|
2010-08-12 20:22:00 -07:00
|
|
|
isDraggable: function isDraggable(target, content) { return {}; },
|
2009-08-07 18:08:06 -07:00
|
|
|
dragStart: function dragStart(cx, cy, target, scroller) {},
|
2009-08-05 14:31:57 -07:00
|
|
|
dragStop: function dragStop(dx, dy, scroller) { return false; },
|
|
|
|
dragMove: function dragMove(dx, dy, scroller) { return false; }
|
|
|
|
};
|
|
|
|
|
2009-10-20 06:36:26 -07:00
|
|
|
/* vertically scrolling box that contains the url bar, notifications, and content */
|
|
|
|
let pageScrollbox = this.pageScrollbox = document.getElementById("page-scrollbox");
|
|
|
|
this.pageScrollboxScroller = pageScrollbox.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
|
|
|
pageScrollbox.customDragger = controlsScrollbox.customDragger;
|
|
|
|
|
2009-10-14 14:19:29 -07:00
|
|
|
let stylesheet = document.styleSheets[0];
|
2010-05-05 12:51:58 -07:00
|
|
|
for each (let style in ["viewport-width", "viewport-height", "window-width", "window-height", "toolbar-height"]) {
|
2009-10-14 14:19:29 -07:00
|
|
|
let index = stylesheet.insertRule("." + style + " {}", stylesheet.cssRules.length);
|
|
|
|
this.styles[style] = stylesheet.cssRules[index].style;
|
|
|
|
}
|
|
|
|
|
2008-12-19 15:04:16 -08:00
|
|
|
function resizeHandler(e) {
|
|
|
|
if (e.target != window)
|
|
|
|
return;
|
|
|
|
|
2009-03-03 11:20:00 -08:00
|
|
|
let w = window.innerWidth;
|
2009-08-04 16:13:28 -07:00
|
|
|
let h = window.innerHeight;
|
2010-09-23 14:20:44 -07:00
|
|
|
|
|
|
|
// XXX is this code right here actually needed?
|
2009-03-03 11:20:00 -08:00
|
|
|
let maximize = (document.documentElement.getAttribute("sizemode") == "maximized");
|
2009-03-31 11:45:24 -07:00
|
|
|
if (maximize && w > screen.width)
|
2009-03-03 11:20:00 -08:00
|
|
|
return;
|
|
|
|
|
2009-08-05 13:28:43 -07:00
|
|
|
let toolbarHeight = Math.round(document.getElementById("toolbar-main").getBoundingClientRect().height);
|
2009-08-04 16:13:28 -07:00
|
|
|
|
2009-10-14 14:19:29 -07:00
|
|
|
Browser.styles["window-width"].width = w + "px";
|
|
|
|
Browser.styles["window-height"].height = h + "px";
|
|
|
|
Browser.styles["toolbar-height"].height = toolbarHeight + "px";
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2010-04-12 20:34:54 -07:00
|
|
|
// Tell the UI to resize the browser controls
|
2009-03-31 11:45:24 -07:00
|
|
|
BrowserUI.sizeControls(w, h);
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2010-08-27 15:01:32 -07:00
|
|
|
// XXX this should really only happen on browser startup, not every resize
|
|
|
|
Browser.hideSidebars();
|
2009-10-14 14:19:29 -07:00
|
|
|
|
2010-09-23 14:20:44 -07:00
|
|
|
let oldWidth = window.cachedWidth || w;
|
|
|
|
window.cachedWidth = w;
|
|
|
|
|
2010-06-24 15:13:01 -07:00
|
|
|
for (let i = Browser.tabs.length - 1; i >= 0; i--)
|
2010-09-23 14:20:44 -07:00
|
|
|
Browser.tabs[i].updateViewportSize(w / oldWidth);
|
2010-05-05 12:51:58 -07:00
|
|
|
|
2010-09-17 15:54:38 -07:00
|
|
|
// XXX page scrollbox jumps to a strange value on resize. Scrolling it will
|
|
|
|
// bound it to a sane place, but not where we were when the resize began :(
|
|
|
|
Browser.hideTitlebar();
|
|
|
|
|
|
|
|
// XXX Hack. Browser also behaves badly on resize.
|
|
|
|
getBrowser().style.display = "none";
|
|
|
|
getBrowser().style.display = "block";
|
|
|
|
|
2010-02-09 19:15:06 -08:00
|
|
|
let curEl = document.activeElement;
|
2010-09-24 10:58:39 -07:00
|
|
|
if (curEl && curEl.id != "inputhandler-overlay" && curEl.scrollIntoView)
|
2010-03-24 20:02:47 -07:00
|
|
|
curEl.scrollIntoView(false);
|
2008-12-19 15:04:16 -08:00
|
|
|
}
|
|
|
|
window.addEventListener("resize", resizeHandler, false);
|
2009-07-27 19:04:22 -07:00
|
|
|
|
2009-07-20 13:22:22 -07:00
|
|
|
function fullscreenHandler() {
|
|
|
|
if (!window.fullScreen)
|
|
|
|
document.getElementById("toolbar-main").setAttribute("fullscreen", "true");
|
|
|
|
else
|
2009-07-27 19:04:22 -07:00
|
|
|
document.getElementById("toolbar-main").removeAttribute("fullscreen");
|
2009-07-20 13:22:22 -07:00
|
|
|
}
|
|
|
|
window.addEventListener("fullscreen", fullscreenHandler, false);
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-08-13 14:13:17 -07:00
|
|
|
function notificationHandler() {
|
|
|
|
// Let the view know that the layout might have changed
|
2009-08-18 22:17:44 -07:00
|
|
|
Browser.forceChromeReflow();
|
2009-08-13 14:13:17 -07:00
|
|
|
}
|
|
|
|
let notifications = document.getElementById("notifications");
|
|
|
|
notifications.addEventListener("AlertActive", notificationHandler, false);
|
|
|
|
notifications.addEventListener("AlertClose", notificationHandler, false);
|
|
|
|
|
2010-06-30 10:22:57 -07:00
|
|
|
BrowserUI.init();
|
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
window.controllers.appendController(this);
|
2008-07-03 23:16:46 -07:00
|
|
|
window.controllers.appendController(BrowserUI);
|
2008-04-18 06:41:49 -07:00
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
var os = Services.obs;
|
2010-05-19 19:43:02 -07:00
|
|
|
os.addObserver(gXPInstallObserver, "addon-install-blocked", false);
|
2009-04-22 17:47:02 -07:00
|
|
|
os.addObserver(gSessionHistoryObserver, "browser:purge-session-history", false);
|
2008-08-19 19:18:36 -07:00
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
// clear out tabs the user hasn't touched lately on memory crunch
|
|
|
|
os.addObserver(MemoryObserver, "memory-pressure", false);
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-09-22 19:19:24 -07:00
|
|
|
// search engine changes
|
|
|
|
os.addObserver(BrowserSearch, "browser-search-engine-modified", false);
|
|
|
|
|
2008-09-24 09:14:06 -07:00
|
|
|
window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = new nsBrowserAccess();
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
let browsers = document.getElementById("browsers");
|
2009-11-24 10:23:41 -08:00
|
|
|
browsers.addEventListener("command", this._handleContentCommand, true);
|
2008-11-21 21:12:25 -08:00
|
|
|
browsers.addEventListener("DOMUpdatePageReport", gPopupBlockerObserver.onUpdatePageReport, false);
|
2008-06-21 11:51:41 -07:00
|
|
|
|
2010-06-25 21:34:00 -07:00
|
|
|
// Login Manager and Form History initialization
|
2008-04-18 06:41:49 -07:00
|
|
|
Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
2010-06-25 21:34:00 -07:00
|
|
|
Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
|
2008-04-18 06:41:49 -07:00
|
|
|
|
2009-11-24 10:23:41 -08:00
|
|
|
// Make sure we're online before attempting to load
|
|
|
|
Util.forceOnline();
|
|
|
|
|
2010-09-06 03:46:00 -07:00
|
|
|
// If this is an intial window launch the commandline handler passes us the default
|
|
|
|
// page as an argument
|
|
|
|
let defaultURL = this.getHomePage();
|
|
|
|
if (window.arguments && window.arguments[0])
|
|
|
|
defaultURL = window.arguments[0];
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2010-09-06 03:46:00 -07:00
|
|
|
this.addTab(defaultURL, true);
|
2009-09-18 21:23:44 -07:00
|
|
|
|
2009-06-09 10:55:14 -07:00
|
|
|
// JavaScript Error Console
|
2010-07-13 07:36:09 -07:00
|
|
|
if (Services.prefs.getBoolPref("browser.console.showInPanel")){
|
2009-12-17 14:35:48 -08:00
|
|
|
let button = document.getElementById("tool-console");
|
|
|
|
button.hidden = false;
|
2009-06-09 10:55:14 -07:00
|
|
|
}
|
2008-09-30 06:23:18 -07:00
|
|
|
|
2009-09-11 13:53:21 -07:00
|
|
|
// If some add-ons were disabled during during an application update, alert user
|
2010-07-13 07:36:09 -07:00
|
|
|
if (Services.prefs.prefHasUserValue("extensions.disabledAddons")) {
|
|
|
|
let addons = Services.prefs.getCharPref("extensions.disabledAddons").split(",");
|
2009-09-11 13:53:21 -07:00
|
|
|
if (addons.length > 0) {
|
2009-11-19 13:40:13 -08:00
|
|
|
let disabledStrings = Elements.browserBundle.getString("alertAddonsDisabled");
|
2009-09-11 13:53:21 -07:00
|
|
|
let label = PluralForm.get(addons.length, disabledStrings).replace("#1", addons.length);
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-09-11 13:53:21 -07:00
|
|
|
let alerts = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
|
2010-03-04 09:01:07 -08:00
|
|
|
alerts.showAlertNotification(URI_GENERIC_ICON_XPINSTALL, Elements.browserBundle.getString("alertAddons"),
|
2009-09-11 13:53:21 -07:00
|
|
|
label, false, "", null);
|
|
|
|
}
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.prefs.clearUserPref("extensions.disabledAddons");
|
2009-09-11 13:53:21 -07:00
|
|
|
}
|
|
|
|
|
2010-06-21 13:04:59 -07:00
|
|
|
messageManager.addMessageListener("Browser:ViewportMetadata", this);
|
2010-06-25 09:32:46 -07:00
|
|
|
messageManager.addMessageListener("Browser:FormSubmit", this);
|
2010-09-27 08:11:56 -07:00
|
|
|
messageManager.addMessageListener("Browser:KeyPress", this);
|
2010-06-24 15:17:35 -07:00
|
|
|
messageManager.addMessageListener("Browser:ZoomToPoint:Return", this);
|
2010-09-23 12:16:52 -07:00
|
|
|
messageManager.addMessageListener("scroll", this);
|
2010-06-11 07:23:24 -07:00
|
|
|
messageManager.addMessageListener("Browser:MozApplicationManifest", OfflineApps);
|
2010-06-08 08:22:20 -07:00
|
|
|
|
2009-12-03 10:46:35 -08:00
|
|
|
// broadcast a UIReady message so add-ons know we are finished with startup
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("UIReady", true, false);
|
|
|
|
window.dispatchEvent(event);
|
2008-04-18 06:41:49 -07:00
|
|
|
},
|
|
|
|
|
2010-05-28 08:52:07 -07:00
|
|
|
_waitingToClose: false,
|
2010-03-26 08:11:03 -07:00
|
|
|
closing: function closing() {
|
2010-05-28 08:52:07 -07:00
|
|
|
// If we are already waiting for the close prompt, don't show another
|
|
|
|
if (this._waitingToClose)
|
|
|
|
return false;
|
|
|
|
|
2010-03-26 08:11:03 -07:00
|
|
|
// Prompt if we have multiple tabs before closing window
|
2010-03-26 08:21:53 -07:00
|
|
|
let numTabs = this._tabs.length;
|
|
|
|
if (numTabs > 1) {
|
2010-07-13 07:36:09 -07:00
|
|
|
let shouldPrompt = Services.prefs.getBoolPref("browser.tabs.warnOnClose");
|
2010-03-26 08:21:53 -07:00
|
|
|
if (shouldPrompt) {
|
2010-07-13 07:36:09 -07:00
|
|
|
let prompt = Services.prompt;
|
2010-08-12 20:22:00 -07:00
|
|
|
|
2010-03-26 08:21:53 -07:00
|
|
|
// Default to true: if it were false, we wouldn't get this far
|
|
|
|
let warnOnClose = { value: true };
|
|
|
|
|
|
|
|
let messageBase = Elements.browserBundle.getString("tabs.closeWarning");
|
|
|
|
let message = PluralForm.get(numTabs, messageBase).replace("#1", numTabs);
|
|
|
|
|
|
|
|
let title = Elements.browserBundle.getString("tabs.closeWarningTitle");
|
|
|
|
let closeText = Elements.browserBundle.getString("tabs.closeButton");
|
|
|
|
let checkText = Elements.browserBundle.getString("tabs.closeWarningPromptMe");
|
|
|
|
let buttons = (prompt.BUTTON_TITLE_IS_STRING * prompt.BUTTON_POS_0) +
|
|
|
|
(prompt.BUTTON_TITLE_CANCEL * prompt.BUTTON_POS_1);
|
2010-05-28 08:52:07 -07:00
|
|
|
|
|
|
|
this._waitingToClose = true;
|
2010-03-26 08:21:53 -07:00
|
|
|
let pressed = prompt.confirmEx(window, title, message, buttons, closeText, null, null, checkText, warnOnClose);
|
2010-05-28 08:52:07 -07:00
|
|
|
this._waitingToClose = false;
|
2010-03-26 08:21:53 -07:00
|
|
|
|
|
|
|
// Don't set the pref unless they press OK and it's false
|
|
|
|
let reallyClose = (pressed == 0);
|
|
|
|
if (reallyClose && !warnOnClose.value)
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.prefs.setBoolPref("browser.tabs.warnOnClose", false);
|
2010-03-26 08:21:53 -07:00
|
|
|
|
|
|
|
// If we don't want to close, return now. If we are closing, continue with other housekeeping.
|
|
|
|
if (!reallyClose)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-03-26 08:11:03 -07:00
|
|
|
|
|
|
|
// Figure out if there's at least one other browser window around.
|
|
|
|
let lastBrowser = true;
|
2010-07-13 07:36:09 -07:00
|
|
|
let e = Services.wm.getEnumerator("navigator:browser");
|
2010-03-26 08:11:03 -07:00
|
|
|
while (e.hasMoreElements() && lastBrowser) {
|
|
|
|
let win = e.getNext();
|
|
|
|
if (win != window && win.toolbar.visible)
|
|
|
|
lastBrowser = false;
|
|
|
|
}
|
|
|
|
if (!lastBrowser)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Let everyone know we are closing the last browser window
|
|
|
|
let closingCanceled = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.obs.notifyObservers(closingCanceled, "browser-lastwindow-close-requested", null);
|
2010-03-26 08:11:03 -07:00
|
|
|
if (closingCanceled.data)
|
|
|
|
return false;
|
2010-08-12 20:22:00 -07:00
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.obs.notifyObservers(null, "browser-lastwindow-close-granted", null);
|
2010-03-26 08:11:03 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function shutdown() {
|
2009-05-26 18:46:44 -07:00
|
|
|
BrowserUI.uninit();
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
var os = Services.obs;
|
2010-05-19 19:43:02 -07:00
|
|
|
os.removeObserver(gXPInstallObserver, "addon-install-blocked");
|
2009-04-22 17:47:02 -07:00
|
|
|
os.removeObserver(gSessionHistoryObserver, "browser:purge-session-history");
|
2009-09-04 22:14:59 -07:00
|
|
|
os.removeObserver(MemoryObserver, "memory-pressure");
|
2009-09-22 19:19:24 -07:00
|
|
|
os.removeObserver(BrowserSearch, "browser-search-engine-modified");
|
2009-07-30 13:41:04 -07:00
|
|
|
|
2009-05-25 20:38:03 -07:00
|
|
|
window.controllers.removeController(this);
|
|
|
|
window.controllers.removeController(BrowserUI);
|
2009-04-22 17:47:02 -07:00
|
|
|
},
|
|
|
|
|
2010-03-26 08:11:03 -07:00
|
|
|
getHomePage: function () {
|
|
|
|
let url = "about:home";
|
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
url = Services.prefs.getComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString).data;
|
2010-03-26 08:11:03 -07:00
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
return url;
|
|
|
|
},
|
2010-01-05 15:12:04 -08:00
|
|
|
|
2009-04-27 11:49:19 -07:00
|
|
|
get browsers() {
|
2009-09-04 22:14:59 -07:00
|
|
|
return this._tabs.map(function(tab) { return tab.browser; });
|
2009-04-27 11:49:19 -07:00
|
|
|
},
|
|
|
|
|
2009-08-12 13:38:52 -07:00
|
|
|
scrollContentToTop: function scrollContentToTop() {
|
|
|
|
this.contentScrollboxScroller.scrollTo(0, 0);
|
2009-10-21 16:11:38 -07:00
|
|
|
this.pageScrollboxScroller.scrollTo(0, 0);
|
2009-12-10 09:55:27 -08:00
|
|
|
},
|
2010-09-07 15:58:55 -07:00
|
|
|
|
|
|
|
// cmd_scrollBottom does not work in Fennec (Bug 590535).
|
|
|
|
scrollContentToBottom: function scrollContentToBottom() {
|
|
|
|
this.contentScrollboxScroller.scrollTo(0, Number.MAX_VALUE);
|
|
|
|
this.pageScrollboxScroller.scrollTo(0, Number.MAX_VALUE);
|
|
|
|
},
|
2009-12-10 09:55:27 -08:00
|
|
|
|
2009-08-12 13:38:52 -07:00
|
|
|
hideSidebars: function scrollSidebarsOffscreen() {
|
2010-08-12 20:22:00 -07:00
|
|
|
let container = document.getElementById("browsers");
|
2009-10-20 06:36:26 -07:00
|
|
|
let rect = container.getBoundingClientRect();
|
|
|
|
this.controlsScrollboxScroller.scrollBy(Math.round(rect.left), 0);
|
2009-08-12 13:38:52 -07:00
|
|
|
},
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
hideTitlebar: function hideTitlebar() {
|
2010-08-12 20:22:00 -07:00
|
|
|
let container = document.getElementById("browsers");
|
2009-10-21 16:11:38 -07:00
|
|
|
let rect = container.getBoundingClientRect();
|
|
|
|
this.pageScrollboxScroller.scrollBy(0, Math.round(rect.top));
|
|
|
|
this.tryUnfloatToolbar();
|
|
|
|
},
|
|
|
|
|
2010-08-10 14:32:32 -07:00
|
|
|
/**
|
|
|
|
* Load a URI in the current tab, or a new tab if necessary.
|
|
|
|
* @param aURI String
|
|
|
|
* @param aParams Object with optional properties that will be passed to loadURIWithFlags:
|
|
|
|
* flags, referrerURI, charset, postData.
|
|
|
|
*/
|
|
|
|
loadURI: function loadURI(aURI, aParams) {
|
|
|
|
let browser = this.selectedBrowser;
|
|
|
|
|
|
|
|
// We need to keep about: pages opening in new "local" tabs. We also want to spawn
|
|
|
|
// new "remote" tabs if opening web pages from a "local" about: page.
|
|
|
|
let currentURI = browser.currentURI.spec;
|
|
|
|
let useLocal = Util.isLocalScheme(aURI);
|
|
|
|
let hasLocal = Util.isLocalScheme(currentURI);
|
|
|
|
|
|
|
|
if (hasLocal != useLocal) {
|
|
|
|
let oldTab = this.selectedTab;
|
|
|
|
if (currentURI == "about:blank" && !browser.canGoBack && !browser.canGoForward) {
|
|
|
|
this.closeTab(oldTab);
|
|
|
|
oldTab = null;
|
|
|
|
}
|
2010-09-15 03:41:31 -07:00
|
|
|
Browser.addTab(aURI, true, oldTab, aParams);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let params = aParams || {};
|
|
|
|
let flags = params.flags || Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
|
|
|
getBrowser().loadURIWithFlags(aURI, flags, params.referrerURI, params.charset, params.postData);
|
2010-08-10 14:32:32 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
/**
|
2009-04-27 11:49:19 -07:00
|
|
|
* Return the currently active <browser> object
|
2008-07-11 11:51:28 -07:00
|
|
|
*/
|
2009-01-08 22:51:13 -08:00
|
|
|
get selectedBrowser() {
|
|
|
|
return this._selectedTab.browser;
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2010-03-26 08:11:03 -07:00
|
|
|
get tabs() {
|
|
|
|
return this._tabs;
|
|
|
|
},
|
|
|
|
|
2010-06-09 16:07:12 -07:00
|
|
|
getTabForBrowser: function getTabForBrowser(aBrowser) {
|
|
|
|
let tabs = this._tabs;
|
|
|
|
for (let i = 0; i < tabs.length; i++) {
|
|
|
|
if (tabs[i].browser == aBrowser)
|
|
|
|
return tabs[i];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTabAtIndex: function getTabAtIndex(index) {
|
2008-11-21 21:12:25 -08:00
|
|
|
if (index > this._tabs.length || index < 0)
|
|
|
|
return null;
|
|
|
|
return this._tabs[index];
|
|
|
|
},
|
|
|
|
|
2010-06-09 16:07:12 -07:00
|
|
|
getTabFromChrome: function getTabFromChrome(chromeTab) {
|
2008-11-21 21:12:25 -08:00
|
|
|
for (var t = 0; t < this._tabs.length; t++) {
|
2009-06-04 07:57:56 -07:00
|
|
|
if (this._tabs[t].chromeTab == chromeTab)
|
2008-11-21 21:12:25 -08:00
|
|
|
return this._tabs[t];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2010-09-15 03:41:31 -07:00
|
|
|
addTab: function(aURI, aBringFront, aOwner, aParams) {
|
|
|
|
let newTab = new Tab(aURI, aParams);
|
2010-06-15 14:56:13 -07:00
|
|
|
newTab.owner = aOwner || null;
|
2008-11-21 21:12:25 -08:00
|
|
|
this._tabs.push(newTab);
|
|
|
|
|
2010-09-15 03:41:31 -07:00
|
|
|
if (aBringFront)
|
2009-07-17 16:17:57 -07:00
|
|
|
this.selectedTab = newTab;
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("TabOpen", true, false);
|
2009-06-04 07:57:56 -07:00
|
|
|
newTab.chromeTab.dispatchEvent(event);
|
2010-07-28 12:43:14 -07:00
|
|
|
newTab.browser.messageManager.sendAsyncMessage("Browser:TabOpen");
|
2008-11-21 21:12:25 -08:00
|
|
|
|
|
|
|
return newTab;
|
|
|
|
},
|
|
|
|
|
|
|
|
closeTab: function(tab) {
|
|
|
|
if (tab instanceof XULElement)
|
2009-06-04 07:57:56 -07:00
|
|
|
tab = this.getTabFromChrome(tab);
|
2008-11-21 21:12:25 -08:00
|
|
|
|
|
|
|
if (!tab)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let tabIndex = this._tabs.indexOf(tab);
|
2010-06-17 21:31:24 -07:00
|
|
|
if (tabIndex == -1)
|
|
|
|
return;
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
let nextTab = this._selectedTab;
|
2010-06-15 14:56:13 -07:00
|
|
|
if (nextTab == tab) {
|
|
|
|
nextTab = tab.owner || this.getTabAtIndex(tabIndex + 1) || this.getTabAtIndex(tabIndex - 1);
|
2008-11-21 21:12:25 -08:00
|
|
|
if (!nextTab)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-15 14:56:13 -07:00
|
|
|
// Tabs owned by the closed tab are now orphaned.
|
|
|
|
this._tabs.forEach(function(aTab, aIndex, aArray) {
|
|
|
|
if (aTab.owner == tab)
|
|
|
|
aTab.owner = null;
|
|
|
|
});
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("TabClose", true, false);
|
2009-06-04 07:57:56 -07:00
|
|
|
tab.chromeTab.dispatchEvent(event);
|
2010-07-28 12:43:14 -07:00
|
|
|
tab.browser.messageManager.sendAsyncMessage("Browser:TabClose");
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-02-03 18:37:10 -08:00
|
|
|
this.selectedTab = nextTab;
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
tab.destroy();
|
|
|
|
this._tabs.splice(tabIndex, 1);
|
2009-01-08 22:51:13 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
get selectedTab() {
|
|
|
|
return this._selectedTab;
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
set selectedTab(tab) {
|
2008-11-21 21:12:25 -08:00
|
|
|
if (tab instanceof XULElement)
|
2009-06-04 07:57:56 -07:00
|
|
|
tab = this.getTabFromChrome(tab);
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
if (!tab || this._selectedTab == tab)
|
2008-11-21 21:12:25 -08:00
|
|
|
return;
|
|
|
|
|
2010-09-17 11:48:20 -07:00
|
|
|
TapHighlightHelper.hide();
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
if (this._selectedTab) {
|
2010-03-25 21:18:20 -07:00
|
|
|
this._selectedTab.pageScrollOffset = this.getScrollboxPosition(this.pageScrollboxScroller);
|
2010-05-06 07:32:24 -07:00
|
|
|
|
|
|
|
// Make sure we leave the toolbar in an unlocked state
|
|
|
|
if (this._selectedTab.isLoading())
|
|
|
|
BrowserUI.unlockToolbar();
|
2009-09-04 22:14:59 -07:00
|
|
|
}
|
|
|
|
|
2009-11-23 23:46:01 -08:00
|
|
|
let isFirstTab = this._selectedTab == null;
|
|
|
|
let lastTab = this._selectedTab;
|
2010-08-31 12:25:47 -07:00
|
|
|
let oldBrowser = lastTab ? lastTab._browser : null;
|
|
|
|
let browser = tab.browser;
|
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
this._selectedTab = tab;
|
2008-12-19 13:54:11 -08:00
|
|
|
|
2010-05-06 07:32:24 -07:00
|
|
|
// Lock the toolbar if the new tab is still loading
|
|
|
|
if (this._selectedTab.isLoading())
|
|
|
|
BrowserUI.lockToolbar();
|
|
|
|
|
2010-08-31 12:25:47 -07:00
|
|
|
if (oldBrowser) {
|
|
|
|
oldBrowser.setAttribute("type", "content");
|
|
|
|
oldBrowser.style.display = "none";
|
2010-09-27 08:11:56 -07:00
|
|
|
oldBrowser.messageManager.sendAsyncMessage("Browser:Blur", {});
|
2010-08-31 12:25:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (browser) {
|
|
|
|
browser.setAttribute("type", "content-primary");
|
|
|
|
browser.style.display = "";
|
2010-09-27 08:11:56 -07:00
|
|
|
browser.messageManager.sendAsyncMessage("Browser:Focus", {});
|
2010-08-31 12:25:47 -07:00
|
|
|
}
|
2009-08-11 13:51:13 -07:00
|
|
|
|
2009-09-09 20:32:13 -07:00
|
|
|
document.getElementById("tabs").selectedTab = tab.chromeTab;
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-11-23 23:46:01 -08:00
|
|
|
if (!isFirstTab) {
|
2009-09-10 06:24:48 -07:00
|
|
|
// Update all of our UI to reflect the new tab's location
|
2009-09-18 21:17:52 -07:00
|
|
|
BrowserUI.updateURI();
|
2009-09-10 06:24:48 -07:00
|
|
|
getIdentityHandler().checkIdentity();
|
2008-12-02 13:07:33 -08:00
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("TabSelect", true, false);
|
2009-11-23 23:46:01 -08:00
|
|
|
event.lastTab = lastTab;
|
2009-06-04 07:57:56 -07:00
|
|
|
tab.chromeTab.dispatchEvent(event);
|
2009-01-08 22:51:13 -08:00
|
|
|
}
|
2009-08-11 13:51:13 -07:00
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
tab.lastSelected = Date.now();
|
|
|
|
|
2010-03-25 21:18:20 -07:00
|
|
|
if (tab.pageScrollOffset) {
|
|
|
|
let { x: pageScrollX, y: pageScrollY } = tab.pageScrollOffset;
|
|
|
|
Browser.pageScrollboxScroller.scrollTo(pageScrollX, pageScrollY);
|
|
|
|
}
|
2008-07-11 11:51:28 -07:00
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
supportsCommand: function(cmd) {
|
2008-04-18 06:41:49 -07:00
|
|
|
var isSupported = false;
|
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_fullscreen":
|
|
|
|
isSupported = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
isSupported = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return isSupported;
|
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
isCommandEnabled: function(cmd) {
|
2008-04-18 06:41:49 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
doCommand: function(cmd) {
|
2008-04-18 06:41:49 -07:00
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_fullscreen":
|
2008-07-08 18:24:49 -07:00
|
|
|
window.fullScreen = !window.fullScreen;
|
2008-04-18 06:41:49 -07:00
|
|
|
break;
|
|
|
|
}
|
2008-07-10 07:24:48 -07:00
|
|
|
},
|
|
|
|
|
2010-09-14 14:58:10 -07:00
|
|
|
getNotificationBox: function getNotificationBox(aBrowser) {
|
2008-07-10 07:24:48 -07:00
|
|
|
return document.getElementById("notifications");
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
|
|
|
|
2009-11-30 12:19:24 -08:00
|
|
|
removeTransientNotificationsForTab: function removeTransientNotificationsForTab(aTab) {
|
|
|
|
let notificationBox = this.getNotificationBox();
|
|
|
|
let notifications = notificationBox.allNotifications;
|
|
|
|
for (let n = notifications.length - 1; n >= 0; n--) {
|
|
|
|
let notification = notifications[n];
|
|
|
|
if (notification._chromeTab != aTab.chromeTab)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (notification.persistence)
|
|
|
|
notification.persistence--;
|
|
|
|
else if (Date.now() > notification.timeout)
|
|
|
|
notificationBox.removeNotification(notification);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-09 08:52:21 -07:00
|
|
|
/**
|
|
|
|
* Handle command event bubbling up from content. This allows us to do chrome-
|
|
|
|
* privileged things based on buttons in, e.g., unprivileged error pages.
|
|
|
|
* Obviously, care should be taken not to trust events that web pages could have
|
|
|
|
* synthesized.
|
|
|
|
*/
|
2009-08-07 14:59:06 -07:00
|
|
|
_handleContentCommand: function _handleContentCommand(aEvent) {
|
2008-09-09 08:52:21 -07:00
|
|
|
// Don't trust synthetic events
|
|
|
|
if (!aEvent.isTrusted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var ot = aEvent.originalTarget;
|
|
|
|
var errorDoc = ot.ownerDocument;
|
|
|
|
|
|
|
|
// If the event came from an ssl error page, it is probably either the "Add
|
|
|
|
// Exception…" or "Get me out of here!" button
|
2009-09-09 20:21:26 -07:00
|
|
|
if (/^about:certerror\?e=nssBadCert/.test(errorDoc.documentURI)) {
|
|
|
|
if (ot == errorDoc.getElementById("temporaryExceptionButton") ||
|
|
|
|
ot == errorDoc.getElementById("permanentExceptionButton")) {
|
2008-09-09 08:52:21 -07:00
|
|
|
try {
|
2009-10-26 12:16:35 -07:00
|
|
|
// add a new SSL exception for this URL
|
2010-07-13 07:36:09 -07:00
|
|
|
let uri = Services.io.newURI(errorDoc.location.href, null, null);
|
2009-10-26 12:16:35 -07:00
|
|
|
let sslExceptions = new SSLExceptions();
|
|
|
|
|
|
|
|
if (ot == errorDoc.getElementById("permanentExceptionButton")) {
|
|
|
|
sslExceptions.addPermanentException(uri);
|
|
|
|
} else {
|
|
|
|
sslExceptions.addTemporaryException(uri);
|
2008-09-09 08:52:21 -07:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2009-10-26 12:16:35 -07:00
|
|
|
dump("EXCEPTION handle content command: " + e + "\n" );
|
2008-09-09 08:52:21 -07:00
|
|
|
}
|
2008-09-23 08:19:11 -07:00
|
|
|
|
2010-01-14 13:08:40 -08:00
|
|
|
// automatically reload after the exception was added
|
2009-10-26 12:16:35 -07:00
|
|
|
errorDoc.location.reload();
|
2008-09-09 08:52:21 -07:00
|
|
|
}
|
|
|
|
else if (ot == errorDoc.getElementById('getMeOutOfHereButton')) {
|
|
|
|
// Get the start page from the *default* pref branch, not the user's
|
2010-07-13 07:36:09 -07:00
|
|
|
var defaultPrefs = Services.prefs.getDefaultBranch(null);
|
2008-09-09 08:52:21 -07:00
|
|
|
var url = "about:blank";
|
|
|
|
try {
|
|
|
|
url = defaultPrefs.getCharPref("browser.startup.homepage");
|
|
|
|
// If url is a pipe-delimited set of pages, just take the first one.
|
|
|
|
if (url.indexOf("|") != -1)
|
|
|
|
url = url.split("|")[0];
|
|
|
|
} catch (e) { /* Fall back on about blank */ }
|
2008-09-23 08:19:11 -07:00
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
Browser.selectedBrowser.loadURI(url, null, null, false);
|
2008-09-09 08:52:21 -07:00
|
|
|
}
|
2010-01-14 13:08:40 -08:00
|
|
|
}
|
2009-11-24 10:23:41 -08:00
|
|
|
else if (/^about:neterror\?e=netOffline/.test(errorDoc.documentURI)) {
|
2009-11-24 11:27:42 -08:00
|
|
|
if (ot == errorDoc.getElementById("errorTryAgain")) {
|
2009-11-24 10:23:41 -08:00
|
|
|
// Make sure we're online before attempting to load
|
|
|
|
Util.forceOnline();
|
|
|
|
}
|
2008-09-09 08:52:21 -07:00
|
|
|
}
|
2009-07-24 15:51:16 -07:00
|
|
|
},
|
|
|
|
|
2009-07-27 19:04:22 -07:00
|
|
|
/**
|
2009-08-06 15:38:43 -07:00
|
|
|
* Compute the sidebar percentage visibility.
|
2009-07-28 16:14:57 -07:00
|
|
|
*
|
2009-08-14 18:15:18 -07:00
|
|
|
* @param [optional] dx
|
|
|
|
* @param [optional] dy an offset distance at which to perform the visibility
|
|
|
|
* computation
|
2009-07-27 19:04:22 -07:00
|
|
|
*/
|
2009-08-14 18:15:18 -07:00
|
|
|
computeSidebarVisibility: function computeSidebarVisibility(dx, dy) {
|
2010-09-02 18:27:20 -07:00
|
|
|
function visibility(aSidebarRect, aVisibleRect) {
|
|
|
|
let width = aSidebarRect.width;
|
|
|
|
aSidebarRect.restrictTo(aVisibleRect);
|
|
|
|
return aSidebarRect.width / width;
|
2009-07-27 19:04:22 -07:00
|
|
|
}
|
|
|
|
|
2009-08-14 18:15:18 -07:00
|
|
|
if (!dx) dx = 0;
|
|
|
|
if (!dy) dy = 0;
|
|
|
|
|
2010-09-02 18:27:20 -07:00
|
|
|
let [leftSidebar, rightSidebar] = [Elements.tabs.getBoundingClientRect(), Elements.controls.getBoundingClientRect()];
|
|
|
|
if (leftSidebar.left > rightSidebar.left)
|
|
|
|
[rightSidebar, leftSidebar] = [leftSidebar, rightSidebar]; // switch in RTL case
|
2009-07-27 19:04:22 -07:00
|
|
|
|
2010-09-02 18:27:20 -07:00
|
|
|
let visibleRect = new Rect(0, 0, window.innerWidth, 1);
|
2010-09-03 10:01:35 -07:00
|
|
|
let leftRect = new Rect(Math.round(leftSidebar.left) - Math.round(dx), 0, Math.round(leftSidebar.width), 1);
|
|
|
|
let rightRect = new Rect(Math.round(rightSidebar.left) - Math.round(dx), 0, Math.round(rightSidebar.width), 1);
|
2010-08-20 13:32:00 -07:00
|
|
|
|
2010-09-02 18:27:20 -07:00
|
|
|
let leftTotalWidth = leftRect.width;
|
|
|
|
let leftVisibility = visibility(leftRect, visibleRect);
|
2009-07-27 19:04:22 -07:00
|
|
|
|
2010-09-02 18:27:20 -07:00
|
|
|
let rightTotalWidth = rightRect.width;
|
|
|
|
let rightVisibility = visibility(rightRect, visibleRect);
|
2009-07-28 16:14:57 -07:00
|
|
|
|
2010-09-02 18:27:20 -07:00
|
|
|
return [leftVisibility, rightVisibility, leftTotalWidth, rightTotalWidth];
|
2009-08-06 15:38:43 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the horizontal distance needed to scroll in order to snap the
|
|
|
|
* sidebars into place.
|
|
|
|
*
|
|
|
|
* Visibility is computed by creating dummy rectangles for the sidebar and the
|
|
|
|
* visible rect. Sidebar rectangles come from getBoundingClientRect(), so
|
|
|
|
* they are in absolute client coordinates (and since we're in a scrollbox,
|
|
|
|
* this means they are positioned relative to the window, which is anchored at
|
|
|
|
* (0, 0) regardless of the scrollbox's scroll position. The rectangles are
|
|
|
|
* made to have a top of 0 and a height of 1, since these do not affect how we
|
|
|
|
* compute visibility (we care only about width), and using rectangles allows
|
|
|
|
* us to use restrictTo(), which comes in handy.
|
|
|
|
*
|
|
|
|
* @return scrollBy dx needed to make snap happen
|
|
|
|
*/
|
|
|
|
snapSidebars: function snapSidebars() {
|
|
|
|
let [leftvis, ritevis, leftw, ritew] = Browser.computeSidebarVisibility();
|
2009-07-27 19:04:22 -07:00
|
|
|
|
|
|
|
let snappedX = 0;
|
|
|
|
|
|
|
|
if (leftvis != 0 && leftvis != 1) {
|
2009-08-05 16:06:54 -07:00
|
|
|
if (leftvis >= 0.6666) {
|
2009-07-27 19:04:22 -07:00
|
|
|
snappedX = -((1 - leftvis) * leftw);
|
2009-08-05 16:06:54 -07:00
|
|
|
} else {
|
2009-07-27 19:04:22 -07:00
|
|
|
snappedX = leftvis * leftw;
|
2009-08-05 16:06:54 -07:00
|
|
|
}
|
2009-07-27 19:04:22 -07:00
|
|
|
}
|
|
|
|
else if (ritevis != 0 && ritevis != 1) {
|
2009-08-05 16:06:54 -07:00
|
|
|
if (ritevis >= 0.6666) {
|
2009-07-27 19:04:22 -07:00
|
|
|
snappedX = (1 - ritevis) * ritew;
|
2009-08-05 16:06:54 -07:00
|
|
|
} else {
|
2009-07-27 19:04:22 -07:00
|
|
|
snappedX = -ritevis * ritew;
|
2009-08-05 16:06:54 -07:00
|
|
|
}
|
2009-07-27 19:04:22 -07:00
|
|
|
}
|
|
|
|
|
2009-08-17 13:01:27 -07:00
|
|
|
return Math.round(snappedX);
|
2009-07-28 16:14:57 -07:00
|
|
|
},
|
|
|
|
|
2009-08-14 18:15:18 -07:00
|
|
|
tryFloatToolbar: function tryFloatToolbar(dx, dy) {
|
2009-08-14 13:02:23 -07:00
|
|
|
if (this.floatedWhileDragging)
|
2009-08-14 18:15:18 -07:00
|
|
|
return;
|
2009-08-05 13:28:43 -07:00
|
|
|
|
2009-08-14 18:15:18 -07:00
|
|
|
let [leftvis, ritevis, leftw, ritew] = Browser.computeSidebarVisibility(dx, dy);
|
2009-10-15 12:50:32 -07:00
|
|
|
if (leftvis > 0 || ritevis > 0) {
|
2009-08-24 07:18:26 -07:00
|
|
|
BrowserUI.lockToolbar();
|
2009-08-14 13:02:23 -07:00
|
|
|
this.floatedWhileDragging = true;
|
2009-08-06 15:38:43 -07:00
|
|
|
}
|
|
|
|
},
|
2009-08-05 13:28:43 -07:00
|
|
|
|
2009-08-14 18:15:18 -07:00
|
|
|
tryUnfloatToolbar: function tryUnfloatToolbar(dx, dy) {
|
2009-08-14 13:02:23 -07:00
|
|
|
if (!this.floatedWhileDragging)
|
2009-08-17 13:01:27 -07:00
|
|
|
return true;
|
2009-08-05 13:28:43 -07:00
|
|
|
|
2009-08-14 18:15:18 -07:00
|
|
|
let [leftvis, ritevis, leftw, ritew] = Browser.computeSidebarVisibility(dx, dy);
|
2009-10-21 16:11:38 -07:00
|
|
|
if (leftvis == 0 && ritevis == 0) {
|
2009-08-24 07:18:26 -07:00
|
|
|
BrowserUI.unlockToolbar();
|
2009-08-14 13:02:23 -07:00
|
|
|
this.floatedWhileDragging = false;
|
2009-08-17 13:01:27 -07:00
|
|
|
return true;
|
2009-08-05 13:28:43 -07:00
|
|
|
}
|
2009-08-17 13:01:27 -07:00
|
|
|
return false;
|
2009-08-05 13:28:43 -07:00
|
|
|
},
|
|
|
|
|
2010-03-25 21:09:23 -07:00
|
|
|
/** Zoom one step in (negative) or out (positive). */
|
2009-08-12 14:40:43 -07:00
|
|
|
zoom: function zoom(aDirection) {
|
2010-08-30 14:11:49 -07:00
|
|
|
let tab = this.selectedTab;
|
|
|
|
if (!tab.allowZoom)
|
2010-04-29 12:29:01 -07:00
|
|
|
return;
|
|
|
|
|
2010-09-02 16:01:46 -07:00
|
|
|
let oldZoomLevel = tab.browser.scale;
|
|
|
|
let zoomLevel = oldZoomLevel;
|
|
|
|
|
2010-04-12 19:42:35 -07:00
|
|
|
let zoomValues = ZoomManager.zoomValues;
|
2010-07-08 07:20:22 -07:00
|
|
|
let i = zoomValues.indexOf(ZoomManager.snap(zoomLevel)) + (aDirection < 0 ? 1 : -1);
|
2010-04-12 19:42:35 -07:00
|
|
|
if (i >= 0 && i < zoomValues.length)
|
|
|
|
zoomLevel = zoomValues[i];
|
2010-04-08 07:43:04 -07:00
|
|
|
|
2010-08-30 14:11:49 -07:00
|
|
|
zoomLevel = tab.clampZoomLevel(zoomLevel);
|
2010-04-08 07:43:04 -07:00
|
|
|
|
2010-09-13 10:13:17 -07:00
|
|
|
let [centerX, centerY] = this.transformClientToBrowser(window.innerWidth / 2,
|
|
|
|
window.innerHeight / 2);
|
2010-09-02 16:01:46 -07:00
|
|
|
|
|
|
|
let rect = this._getZoomRectForPoint(centerX, centerY, zoomLevel);
|
|
|
|
this.animatedZoomTo(rect);
|
2009-08-12 14:40:43 -07:00
|
|
|
},
|
|
|
|
|
2010-08-02 13:54:52 -07:00
|
|
|
/** Rect should be in browser coordinates. */
|
2010-06-25 06:30:15 -07:00
|
|
|
_getZoomLevelForRect: function _getZoomLevelForRect(rect) {
|
|
|
|
const margin = 15;
|
2010-08-30 14:11:49 -07:00
|
|
|
return this.selectedTab.clampZoomLevel(window.innerWidth / (rect.width + margin * 2));
|
2010-08-02 13:54:52 -07:00
|
|
|
},
|
2010-06-25 06:30:15 -07:00
|
|
|
|
2010-06-24 15:17:35 -07:00
|
|
|
/**
|
|
|
|
* Find an appropriate zoom rect for an element bounding rect, if it exists.
|
|
|
|
* @return Rect in viewport coordinates
|
|
|
|
* */
|
|
|
|
_getZoomRectForRect: function _getZoomRectForRect(rect, y) {
|
2010-09-01 13:35:05 -07:00
|
|
|
let oldZoomLevel = getBrowser().scale;
|
2010-06-25 06:30:15 -07:00
|
|
|
let zoomLevel = this._getZoomLevelForRect(rect);
|
2010-06-24 15:17:35 -07:00
|
|
|
let zoomRatio = oldZoomLevel / zoomLevel;
|
|
|
|
|
|
|
|
// Don't zoom in a marginal amount, but be more lenient for the first zoom.
|
|
|
|
// > 2/3 means operation increases the zoom level by less than 1.5
|
|
|
|
// > 9/10 means operation increases the zoom level by less than 1.1
|
2010-08-30 14:11:49 -07:00
|
|
|
let zoomTolerance = (this.selectedTab.isDefaultZoomLevel()) ? .9 : .6666;
|
2010-06-25 06:30:15 -07:00
|
|
|
if (zoomRatio >= zoomTolerance)
|
2010-06-24 15:17:35 -07:00
|
|
|
return null;
|
2010-06-25 06:30:15 -07:00
|
|
|
else
|
2010-06-24 15:17:35 -07:00
|
|
|
return this._getZoomRectForPoint(rect.center().x, y, zoomLevel);
|
2010-06-21 13:36:56 -07:00
|
|
|
},
|
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
/**
|
2010-01-11 12:43:47 -08:00
|
|
|
* Find a good zoom rectangle for point that is specified in browser coordinates.
|
|
|
|
* @return Rect in viewport coordinates
|
2009-10-21 16:11:38 -07:00
|
|
|
*/
|
|
|
|
_getZoomRectForPoint: function _getZoomRectForPoint(x, y, zoomLevel) {
|
2010-09-17 14:16:43 -07:00
|
|
|
let browser = getBrowser();
|
|
|
|
x = x * browser.scale;
|
|
|
|
y = y * browser.scale;
|
2009-08-17 13:01:27 -07:00
|
|
|
|
2010-04-12 19:42:35 -07:00
|
|
|
zoomLevel = Math.min(ZoomManager.MAX, zoomLevel);
|
2010-09-17 14:16:43 -07:00
|
|
|
let oldScale = browser.scale;
|
|
|
|
let zoomRatio = zoomLevel / oldScale;
|
2010-08-30 14:11:49 -07:00
|
|
|
let newVisW = window.innerWidth / zoomRatio, newVisH = window.innerHeight / zoomRatio;
|
2009-11-12 20:41:45 -08:00
|
|
|
let result = new Rect(x - newVisW / 2, y - newVisH / 2, newVisW, newVisH);
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
// Make sure rectangle doesn't poke out of viewport
|
2010-09-17 14:16:43 -07:00
|
|
|
return result.translateInside(new Rect(0, 0, browser.contentDocumentWidth * oldScale,
|
|
|
|
browser.contentDocumentHeight * oldScale));
|
2009-10-21 16:11:38 -07:00
|
|
|
},
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2010-06-25 14:16:01 -07:00
|
|
|
animatedZoomTo: function animatedZoomTo(rect) {
|
2010-09-15 15:05:50 -07:00
|
|
|
AnimatedZoom.animateTo(rect);
|
2010-06-25 14:16:01 -07:00
|
|
|
},
|
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
setVisibleRect: function setVisibleRect(rect) {
|
2010-09-15 15:05:50 -07:00
|
|
|
let browser = getBrowser();
|
2010-08-30 14:11:49 -07:00
|
|
|
let zoomRatio = window.innerWidth / rect.width;
|
2010-09-15 15:05:50 -07:00
|
|
|
let zoomLevel = browser.scale * zoomRatio;
|
2009-10-21 16:11:38 -07:00
|
|
|
let scrollX = rect.left * zoomRatio;
|
|
|
|
let scrollY = rect.top * zoomRatio;
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-12-08 09:28:01 -08:00
|
|
|
this.hideSidebars();
|
|
|
|
this.hideTitlebar();
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2010-09-15 15:05:50 -07:00
|
|
|
browser.scale = this.selectedTab.clampZoomLevel(zoomLevel);
|
|
|
|
browser.scrollTo(scrollX, scrollY);
|
2009-10-21 16:11:38 -07:00
|
|
|
},
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2010-07-08 07:20:22 -07:00
|
|
|
zoomToPoint: function zoomToPoint(cX, cY, aRect) {
|
2010-08-30 14:11:49 -07:00
|
|
|
let tab = this.selectedTab;
|
|
|
|
if (!tab.allowZoom)
|
2010-07-20 13:49:31 -07:00
|
|
|
return null;
|
2010-06-24 15:17:35 -07:00
|
|
|
|
|
|
|
let zoomRect = null;
|
2010-07-08 07:20:22 -07:00
|
|
|
if (aRect)
|
|
|
|
zoomRect = this._getZoomRectForRect(aRect, cY);
|
2010-06-25 06:30:15 -07:00
|
|
|
|
2010-08-30 14:11:49 -07:00
|
|
|
if (!zoomRect && tab.isDefaultZoomLevel())
|
2010-09-01 13:35:05 -07:00
|
|
|
zoomRect = this._getZoomRectForPoint(cX, cY, getBrowser().scale * 2);
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-07-08 07:20:22 -07:00
|
|
|
if (zoomRect)
|
2010-06-25 14:16:01 -07:00
|
|
|
this.animatedZoomTo(zoomRect);
|
2010-05-04 08:15:57 -07:00
|
|
|
|
|
|
|
return zoomRect;
|
2009-10-21 16:11:38 -07:00
|
|
|
},
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2010-06-25 06:30:15 -07:00
|
|
|
zoomFromPoint: function zoomFromPoint(cX, cY) {
|
2010-08-30 14:11:49 -07:00
|
|
|
let tab = this.selectedTab;
|
|
|
|
if (tab.allowZoom && !tab.isDefaultZoomLevel()) {
|
|
|
|
let zoomLevel = tab.getDefaultZoomLevel();
|
2010-07-08 07:20:22 -07:00
|
|
|
let zoomRect = this._getZoomRectForPoint(cX, cY, zoomLevel);
|
2010-06-25 14:16:01 -07:00
|
|
|
this.animatedZoomTo(zoomRect);
|
2010-06-25 06:30:15 -07:00
|
|
|
}
|
2010-07-08 07:20:22 -07:00
|
|
|
},
|
2010-06-25 06:30:15 -07:00
|
|
|
|
2009-07-28 16:14:57 -07:00
|
|
|
/**
|
|
|
|
* Transform x and y from client coordinates to BrowserView coordinates.
|
|
|
|
*/
|
2009-07-29 12:51:24 -07:00
|
|
|
clientToBrowserView: function clientToBrowserView(x, y) {
|
2010-08-12 20:22:00 -07:00
|
|
|
let container = document.getElementById("browsers");
|
2009-07-28 16:14:57 -07:00
|
|
|
let containerBCR = container.getBoundingClientRect();
|
|
|
|
|
2009-07-30 17:31:09 -07:00
|
|
|
let x0 = Math.round(containerBCR.left);
|
2009-07-31 15:32:48 -07:00
|
|
|
let y0;
|
|
|
|
if (arguments.length > 1)
|
|
|
|
y0 = Math.round(containerBCR.top);
|
|
|
|
|
2010-09-15 15:05:50 -07:00
|
|
|
let scroll = getBrowser().getPosition();
|
|
|
|
return (arguments.length > 1) ? [x - x0 + scroll.x, y - y0 + scroll.y] : (x - x0 + scroll.x);
|
2009-07-31 15:32:48 -07:00
|
|
|
},
|
2009-07-28 16:14:57 -07:00
|
|
|
|
2009-07-31 15:32:48 -07:00
|
|
|
browserViewToClient: function browserViewToClient(x, y) {
|
2010-08-12 20:22:00 -07:00
|
|
|
let container = document.getElementById("browsers");
|
2009-07-31 15:32:48 -07:00
|
|
|
let containerBCR = container.getBoundingClientRect();
|
|
|
|
|
|
|
|
let x0 = Math.round(-containerBCR.left);
|
|
|
|
let y0;
|
|
|
|
if (arguments.length > 1)
|
|
|
|
y0 = Math.round(-containerBCR.top);
|
|
|
|
|
|
|
|
return (arguments.length > 1) ? [x - x0, y - y0] : (x - x0);
|
2009-07-28 16:14:57 -07:00
|
|
|
},
|
|
|
|
|
2009-11-23 23:46:01 -08:00
|
|
|
browserViewToClientRect: function browserViewToClientRect(rect) {
|
2010-08-12 20:22:00 -07:00
|
|
|
let container = document.getElementById("browsers");
|
2009-11-23 23:46:01 -08:00
|
|
|
let containerBCR = container.getBoundingClientRect();
|
|
|
|
return rect.clone().translate(Math.round(containerBCR.left), Math.round(containerBCR.top));
|
|
|
|
},
|
|
|
|
|
2009-08-07 18:08:06 -07:00
|
|
|
/**
|
|
|
|
* turn client coordinates into page-relative ones (adjusted for
|
|
|
|
* zoom and page position)
|
|
|
|
*/
|
|
|
|
transformClientToBrowser: function transformClientToBrowser(cX, cY) {
|
2010-09-01 13:35:05 -07:00
|
|
|
return this.clientToBrowserView(cX, cY).map(function(val) { return val / getBrowser().scale });
|
2009-07-28 16:14:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function for getting the scrollbox position off of a
|
|
|
|
* scrollBoxObject interface. Returns the actual values instead of the
|
|
|
|
* wrapping objects.
|
|
|
|
*
|
|
|
|
* @param scroller a scrollBoxObject on which to call scroller.getPosition()
|
|
|
|
*/
|
|
|
|
getScrollboxPosition: function getScrollboxPosition(scroller) {
|
|
|
|
let x = {};
|
|
|
|
let y = {};
|
|
|
|
scroller.getPosition(x, y);
|
2009-10-15 12:50:32 -07:00
|
|
|
return new Point(x.value, y.value);
|
2009-07-31 15:32:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
forceChromeReflow: function forceChromeReflow() {
|
|
|
|
let dummy = getComputedStyle(document.documentElement, "").width;
|
2010-06-09 16:07:12 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function receiveMessage(aMessage) {
|
2010-06-24 15:17:35 -07:00
|
|
|
let json = aMessage.json;
|
2010-09-23 12:16:52 -07:00
|
|
|
let browser = aMessage.target;
|
|
|
|
|
2010-06-09 16:07:12 -07:00
|
|
|
switch (aMessage.name) {
|
2010-06-21 13:04:59 -07:00
|
|
|
case "Browser:ViewportMetadata":
|
2010-09-23 12:16:52 -07:00
|
|
|
let tab = Browser.getTabForBrowser(browser);
|
2010-06-29 11:33:33 -07:00
|
|
|
// Some browser such as iframes loaded dynamically into the chrome UI
|
|
|
|
// does not have any assigned tab
|
2010-09-27 07:19:24 -07:00
|
|
|
if (tab)
|
2010-06-29 11:33:33 -07:00
|
|
|
tab.updateViewportMetadata(json);
|
2010-06-24 15:17:35 -07:00
|
|
|
break;
|
|
|
|
|
2010-06-25 09:32:46 -07:00
|
|
|
case "Browser:FormSubmit":
|
|
|
|
browser.lastLocation = null;
|
|
|
|
break;
|
|
|
|
|
2010-09-27 08:11:56 -07:00
|
|
|
case "Browser:KeyPress":
|
|
|
|
let event = document.createEvent("KeyEvents");
|
|
|
|
event.initKeyEvent("keypress", true, true, null,
|
|
|
|
json.ctrlKey, json.altKey, json.shiftKey, json.metaKey,
|
|
|
|
json.keyCode, json.charCode)
|
|
|
|
document.getElementById("mainKeyset").dispatchEvent(event);
|
|
|
|
break;
|
|
|
|
|
2010-06-24 15:17:35 -07:00
|
|
|
case "Browser:ZoomToPoint:Return":
|
|
|
|
// JSON-ified rect needs to be recreated so the methods exist
|
2010-06-25 06:30:15 -07:00
|
|
|
let rect = Rect.fromRect(json.rect);
|
|
|
|
if (!Browser.zoomToPoint(json.x, json.y, rect))
|
|
|
|
Browser.zoomFromPoint(json.x, json.y);
|
2010-06-09 16:07:12 -07:00
|
|
|
break;
|
2010-09-23 12:16:52 -07:00
|
|
|
|
|
|
|
case "scroll":
|
|
|
|
if (browser == this.selectedBrowser) {
|
|
|
|
Browser.hideTitlebar();
|
|
|
|
Browser.hideSidebars();
|
|
|
|
}
|
|
|
|
break;
|
2010-06-09 16:07:12 -07:00
|
|
|
}
|
2008-07-25 16:27:31 -07:00
|
|
|
}
|
2008-04-18 06:41:49 -07:00
|
|
|
};
|
|
|
|
|
2010-06-23 12:23:06 -07:00
|
|
|
|
2010-08-31 12:25:47 -07:00
|
|
|
Browser.MainDragger = function MainDragger() {
|
2009-08-05 16:06:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
Browser.MainDragger.prototype = {
|
2010-08-12 20:22:00 -07:00
|
|
|
isDraggable: function isDraggable(target, scroller) {
|
2010-09-01 15:23:21 -07:00
|
|
|
return { x: true, y: true };
|
2010-08-12 20:22:00 -07:00
|
|
|
},
|
2009-11-10 07:48:37 -08:00
|
|
|
|
2009-08-07 18:08:06 -07:00
|
|
|
dragStart: function dragStart(clientX, clientY, target, scroller) {
|
2009-08-05 16:06:54 -07:00
|
|
|
},
|
2009-08-10 18:03:42 -07:00
|
|
|
|
2009-08-05 16:06:54 -07:00
|
|
|
dragStop: function dragStop(dx, dy, scroller) {
|
2009-09-28 11:16:51 -07:00
|
|
|
this.dragMove(Browser.snapSidebars(), 0, scroller);
|
2009-09-01 23:42:25 -07:00
|
|
|
Browser.tryUnfloatToolbar();
|
2009-08-05 16:06:54 -07:00
|
|
|
},
|
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
dragMove: function dragMove(dx, dy, scroller) {
|
2009-10-15 12:50:32 -07:00
|
|
|
let doffset = new Point(dx, dy);
|
2010-06-30 10:37:00 -07:00
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
// First calculate any panning to take sidebars out of view
|
2009-10-20 06:36:26 -07:00
|
|
|
let panOffset = this._panControlsAwayOffset(doffset);
|
2009-08-12 14:40:43 -07:00
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
// Do content panning
|
|
|
|
this._panScroller(Browser.contentScrollboxScroller, doffset);
|
2009-08-05 16:06:54 -07:00
|
|
|
|
2009-10-15 12:50:32 -07:00
|
|
|
// Any leftover panning in doffset would bring controls into view. Add to sidebar
|
2009-09-01 23:42:25 -07:00
|
|
|
// away panning for the total scroll offset.
|
2009-10-20 06:36:26 -07:00
|
|
|
doffset.add(panOffset);
|
2009-10-15 12:50:32 -07:00
|
|
|
Browser.tryFloatToolbar(doffset.x, 0);
|
|
|
|
this._panScroller(Browser.controlsScrollboxScroller, doffset);
|
2009-10-20 06:36:26 -07:00
|
|
|
this._panScroller(Browser.pageScrollboxScroller, doffset);
|
2009-08-05 16:06:54 -07:00
|
|
|
|
2009-10-15 12:50:32 -07:00
|
|
|
return !doffset.equals(dx, dy);
|
2009-08-05 16:06:54 -07:00
|
|
|
},
|
2009-12-01 18:22:10 -08:00
|
|
|
|
2009-10-20 06:36:26 -07:00
|
|
|
/** Return offset that pans controls away from screen. Updates doffset with leftovers. */
|
|
|
|
_panControlsAwayOffset: function(doffset) {
|
|
|
|
let x = 0, y = 0, rect;
|
|
|
|
|
|
|
|
rect = Rect.fromRect(Browser.pageScrollbox.getBoundingClientRect()).map(Math.round);
|
|
|
|
if (doffset.x < 0 && rect.right < window.innerWidth)
|
|
|
|
x = Math.max(doffset.x, rect.right - window.innerWidth);
|
|
|
|
if (doffset.x > 0 && rect.left > 0)
|
|
|
|
x = Math.min(doffset.x, rect.left);
|
|
|
|
|
2010-09-17 15:54:38 -07:00
|
|
|
let height = document.getElementById("content-viewport").getBoundingClientRect().height;
|
2009-10-20 06:36:26 -07:00
|
|
|
rect = Rect.fromRect(Browser.contentScrollbox.getBoundingClientRect()).map(Math.round);
|
2009-10-23 21:04:51 -07:00
|
|
|
if (doffset.y < 0 && rect.bottom < height)
|
|
|
|
y = Math.max(doffset.y, rect.bottom - height);
|
2009-10-20 06:36:26 -07:00
|
|
|
if (doffset.y > 0 && rect.top > 0)
|
|
|
|
y = Math.min(doffset.y, rect.top);
|
|
|
|
|
|
|
|
doffset.subtract(x, y);
|
|
|
|
return new Point(x, y);
|
2009-09-01 23:42:25 -07:00
|
|
|
},
|
2009-08-12 14:40:43 -07:00
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
/** Pan scroller by the given amount. Updates doffset with leftovers. */
|
|
|
|
_panScroller: function _panScroller(scroller, doffset) {
|
2009-10-15 12:50:32 -07:00
|
|
|
let { x: x0, y: y0 } = Browser.getScrollboxPosition(scroller);
|
|
|
|
scroller.scrollBy(doffset.x, doffset.y);
|
|
|
|
let { x: x1, y: y1 } = Browser.getScrollboxPosition(scroller);
|
|
|
|
doffset.subtract(x1 - x0, y1 - y0);
|
2009-08-05 16:06:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-23 12:23:06 -07:00
|
|
|
|
2008-09-24 09:14:06 -07:00
|
|
|
function nsBrowserAccess()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-04-27 11:49:19 -07:00
|
|
|
nsBrowserAccess.prototype = {
|
2008-11-21 21:12:25 -08:00
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (aIID.equals(Ci.nsIBrowserDOMWindow) || aIID.equals(Ci.nsISupports))
|
2008-09-24 09:14:06 -07:00
|
|
|
return this;
|
|
|
|
throw Components.results.NS_NOINTERFACE;
|
|
|
|
},
|
|
|
|
|
2010-05-24 12:27:45 -07:00
|
|
|
_getBrowser: function _getBrowser(aURI, aOpener, aWhere, aContext) {
|
|
|
|
let isExternal = (aContext == Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
|
|
|
|
if (isExternal && aURI && aURI.schemeIs("chrome"))
|
2008-09-24 09:14:06 -07:00
|
|
|
return null;
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2010-05-24 12:27:45 -07:00
|
|
|
let loadflags = isExternal ?
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL :
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
|
|
|
let location;
|
2008-09-24 09:14:06 -07:00
|
|
|
if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW) {
|
|
|
|
switch (aContext) {
|
|
|
|
case Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL :
|
2010-07-13 07:36:09 -07:00
|
|
|
aWhere = Services.prefs.getIntPref("browser.link.open_external");
|
2008-09-24 09:14:06 -07:00
|
|
|
break;
|
|
|
|
default : // OPEN_NEW or an illegal value
|
2010-07-13 07:36:09 -07:00
|
|
|
aWhere = Services.prefs.getIntPref("browser.link.open_newwindow");
|
2008-09-24 09:14:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-24 12:27:45 -07:00
|
|
|
let browser;
|
2008-09-24 09:14:06 -07:00
|
|
|
if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW) {
|
2010-05-24 12:27:45 -07:00
|
|
|
let url = aURI ? aURI.spec : "about:blank";
|
|
|
|
let newWindow = openDialog("chrome://browser/content/browser.xul", "_blank",
|
|
|
|
"all,dialog=no", url, null, null, null);
|
2010-08-26 18:59:20 -07:00
|
|
|
// since newWindow.Browser doesn't exist yet, just return null
|
|
|
|
return null;
|
2010-06-15 14:56:13 -07:00
|
|
|
} else if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWTAB) {
|
|
|
|
browser = Browser.addTab("about:blank", true, Browser.selectedTab).browser;
|
|
|
|
} else { // OPEN_CURRENTWINDOW and illegal values
|
|
|
|
browser = Browser.selectedBrowser;
|
2008-09-24 09:14:06 -07:00
|
|
|
}
|
2010-08-10 14:32:32 -07:00
|
|
|
|
2008-09-24 09:14:06 -07:00
|
|
|
try {
|
2010-05-24 12:27:45 -07:00
|
|
|
let referrer;
|
2008-09-24 09:14:06 -07:00
|
|
|
if (aURI) {
|
|
|
|
if (aOpener) {
|
|
|
|
location = aOpener.location;
|
2010-07-13 07:36:09 -07:00
|
|
|
referrer = Services.io.newURI(location, null, null);
|
2008-09-24 09:14:06 -07:00
|
|
|
}
|
2010-06-04 05:21:10 -07:00
|
|
|
browser.loadURIWithFlags(aURI.spec, loadflags, referrer, null, null);
|
2008-09-24 09:14:06 -07:00
|
|
|
}
|
2010-05-24 12:27:45 -07:00
|
|
|
browser.focus();
|
2008-09-24 09:14:06 -07:00
|
|
|
} catch(e) { }
|
|
|
|
|
2010-05-24 12:27:45 -07:00
|
|
|
return browser;
|
|
|
|
},
|
|
|
|
|
|
|
|
openURI: function(aURI, aOpener, aWhere, aContext) {
|
|
|
|
let browser = this._getBrowser(aURI, aOpener, aWhere, aContext);
|
|
|
|
return browser ? browser.contentWindow : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
openURIInFrame: function(aURI, aOpener, aWhere, aContext) {
|
|
|
|
let browser = this._getBrowser(aURI, aOpener, aWhere, aContext);
|
|
|
|
return browser ? browser.QueryInterface(Ci.nsIFrameLoaderOwner) : null;
|
2008-09-24 09:14:06 -07:00
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
isTabContentWindow: function(aWindow) {
|
2009-04-27 11:49:19 -07:00
|
|
|
return Browser.browsers.some(function (browser) browser.contentWindow == aWindow);
|
2008-09-24 09:14:06 -07:00
|
|
|
}
|
2009-06-29 11:33:05 -07:00
|
|
|
};
|
2008-09-24 09:14:06 -07:00
|
|
|
|
2010-06-23 12:23:06 -07:00
|
|
|
|
2009-08-26 12:29:46 -07:00
|
|
|
const BrowserSearch = {
|
2009-12-15 12:37:02 -08:00
|
|
|
observe: function bs_observe(aSubject, aTopic, aData) {
|
2009-09-22 19:19:24 -07:00
|
|
|
if (aTopic != "browser-search-engine-modified")
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (aData) {
|
|
|
|
case "engine-added":
|
|
|
|
case "engine-removed":
|
2009-09-24 12:15:16 -07:00
|
|
|
// force a rebuild of the prefs list, if needed
|
|
|
|
// XXX this is inefficient, shouldn't have to rebuild the entire list
|
|
|
|
if (ExtensionsView._list)
|
|
|
|
ExtensionsView.getAddonsFromLocal();
|
2009-09-22 19:19:24 -07:00
|
|
|
|
2009-09-24 12:15:16 -07:00
|
|
|
// fall through
|
2009-09-22 19:19:24 -07:00
|
|
|
case "engine-changed":
|
2009-09-24 12:15:16 -07:00
|
|
|
// XXX we should probably also update the ExtensionsView list here once
|
|
|
|
// that's efficient, since the icon can change (happen during an async
|
|
|
|
// installs from the web)
|
2009-09-22 19:19:24 -07:00
|
|
|
|
2009-09-24 12:15:16 -07:00
|
|
|
// blow away our cache
|
|
|
|
this._engines = null;
|
|
|
|
break;
|
2009-09-22 19:19:24 -07:00
|
|
|
case "engine-current":
|
2009-09-24 12:15:16 -07:00
|
|
|
// Not relevant
|
|
|
|
break;
|
2009-09-22 19:19:24 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get engines() {
|
|
|
|
if (this._engines)
|
|
|
|
return this._engines;
|
2010-08-26 16:09:56 -07:00
|
|
|
|
|
|
|
let engines = Services.search.getVisibleEngines({ }).map(
|
|
|
|
function(item, index, array) {
|
|
|
|
return {
|
|
|
|
label: item.name,
|
|
|
|
default: (item == Services.search.defaultEngine),
|
|
|
|
image: item.iconURI ? item.iconURI.spec : null
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return this._engines = engines;
|
2009-09-22 19:19:24 -07:00
|
|
|
},
|
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
updatePageSearchEngines: function updatePageSearchEngines(aNode) {
|
2010-08-17 10:04:00 -07:00
|
|
|
let items = Browser.selectedBrowser.searchEngines.filter(this.isPermanentSearchEngine);
|
2010-06-08 09:11:28 -07:00
|
|
|
if (!items.length)
|
2010-08-13 11:41:00 -07:00
|
|
|
return false;
|
2009-08-26 12:29:46 -07:00
|
|
|
|
|
|
|
// XXX limit to the first search engine for now
|
2010-08-13 11:41:00 -07:00
|
|
|
let engine = items[0];
|
|
|
|
aNode.setAttribute("description", engine.title);
|
|
|
|
aNode.onclick = function() {
|
|
|
|
BrowserSearch.addPermanentSearchEngine(engine);
|
|
|
|
PageActions.hideItem(aNode);
|
|
|
|
};
|
|
|
|
return true;
|
2009-08-26 12:29:46 -07:00
|
|
|
},
|
|
|
|
|
2010-08-17 10:04:00 -07:00
|
|
|
addPermanentSearchEngine: function addPermanentSearchEngine(aEngine) {
|
2009-08-26 12:29:46 -07:00
|
|
|
let iconURL = BrowserUI._favicon.src;
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.search.addEngine(aEngine.href, Ci.nsISearchEngine.DATA_XML, iconURL, false);
|
2009-08-26 12:29:46 -07:00
|
|
|
|
2009-09-22 19:19:24 -07:00
|
|
|
this._engines = null;
|
2009-08-26 12:29:46 -07:00
|
|
|
},
|
|
|
|
|
2010-08-17 10:04:00 -07:00
|
|
|
isPermanentSearchEngine: function isPermanentSearchEngine(aEngine) {
|
|
|
|
return !BrowserSearch.engines.some(function(item) {
|
2010-09-29 11:48:19 -07:00
|
|
|
return aEngine.title == item.label;
|
2010-08-17 10:04:00 -07:00
|
|
|
});
|
2009-08-26 12:29:46 -07:00
|
|
|
}
|
2010-07-20 13:49:31 -07:00
|
|
|
};
|
2009-08-26 12:29:46 -07:00
|
|
|
|
2010-06-23 12:23:06 -07:00
|
|
|
|
2009-09-01 20:39:39 -07:00
|
|
|
/** Watches for mouse events in chrome and sends them to content. */
|
2010-09-22 15:08:18 -07:00
|
|
|
const ContentTouchHandler = {
|
2010-09-22 16:27:11 -07:00
|
|
|
// Use lightweight transactions so that old context menus and tap
|
|
|
|
// highlights don't ever see the light of day.
|
|
|
|
_messageId: 0,
|
|
|
|
|
2010-09-22 15:08:18 -07:00
|
|
|
init: function init() {
|
2010-09-22 16:27:11 -07:00
|
|
|
document.addEventListener("TapDown", this, true);
|
2010-09-22 15:08:18 -07:00
|
|
|
document.addEventListener("TapUp", this, false);
|
|
|
|
document.addEventListener("TapSingle", this, false);
|
|
|
|
document.addEventListener("TapDouble", this, false);
|
2010-09-22 15:12:41 -07:00
|
|
|
document.addEventListener("TapLong", this, false);
|
|
|
|
|
2010-09-22 16:27:11 -07:00
|
|
|
document.addEventListener("PanBegin", this, false);
|
|
|
|
document.addEventListener("PopupChanged", this, false);
|
|
|
|
document.addEventListener("CancelTouchSequence", this, false);
|
2010-09-22 15:12:41 -07:00
|
|
|
|
|
|
|
// Context menus have the following flow:
|
|
|
|
// [parent] mousedown -> TapDown -> Browser:MouseDown
|
|
|
|
// [child] Browser:MouseDown -> contextmenu -> Browser:ContextMenu
|
|
|
|
// [parent] Browser:ContextMenu -> ...* -> TapLong
|
|
|
|
//
|
|
|
|
// * = Here some time will elapse. Although we get the context menu we need
|
|
|
|
// ASAP, we do not act on the context menu until we receive a LongTap.
|
|
|
|
// This is so we can show the context menu as soon as we know it is
|
|
|
|
// a long tap, without waiting for child process.
|
|
|
|
//
|
|
|
|
messageManager.addMessageListener("Browser:ContextMenu", this);
|
2010-09-22 16:27:11 -07:00
|
|
|
|
|
|
|
messageManager.addMessageListener("Browser:Highlight", this);
|
2010-09-22 15:08:18 -07:00
|
|
|
},
|
|
|
|
|
2010-09-22 16:27:11 -07:00
|
|
|
handleEvent: function handleEvent(aEvent) {
|
2010-09-22 16:27:11 -07:00
|
|
|
// ignore content events we generate
|
2010-09-22 16:27:11 -07:00
|
|
|
if (aEvent.target.localName == "browser")
|
2010-09-22 16:27:11 -07:00
|
|
|
return;
|
|
|
|
|
2010-09-22 16:27:11 -07:00
|
|
|
switch (aEvent.type) {
|
2010-09-22 15:08:18 -07:00
|
|
|
case "PanBegin":
|
2010-09-22 16:27:11 -07:00
|
|
|
case "PopupChanged":
|
|
|
|
case "CancelTouchSequence":
|
|
|
|
this._clearPendingMessages();
|
2010-09-22 15:08:18 -07:00
|
|
|
break;
|
2010-09-22 16:27:11 -07:00
|
|
|
|
|
|
|
default: {
|
|
|
|
if (ContextHelper.popupState) {
|
|
|
|
// Don't send content events when there's a popup
|
|
|
|
aEvent.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._targetIsContent(aEvent)) {
|
|
|
|
// Received tap event on something that isn't for content.
|
|
|
|
this._clearPendingMessages();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "TapDown":
|
|
|
|
this.tapDown(aEvent.clientX, aEvent.clientY);
|
|
|
|
break;
|
|
|
|
case "TapUp":
|
|
|
|
this.tapUp(aEvent.clientX, aEvent.clientY);
|
|
|
|
break;
|
|
|
|
case "TapSingle":
|
|
|
|
this.tapSingle(aEvent.clientX, aEvent.clientY, aEvent.modifiers);
|
|
|
|
break;
|
|
|
|
case "TapDouble":
|
2010-09-23 16:20:55 -07:00
|
|
|
this.tapDouble(aEvent.clientX, aEvent.clientY, aEvent.modifiers);
|
2010-09-22 16:27:11 -07:00
|
|
|
break;
|
|
|
|
case "TapLong":
|
|
|
|
this.tapLong();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-22 15:08:18 -07:00
|
|
|
}
|
|
|
|
},
|
2009-09-01 20:39:39 -07:00
|
|
|
|
2010-09-22 15:12:41 -07:00
|
|
|
receiveMessage: function receiveMessage(aMessage) {
|
2010-09-22 16:27:11 -07:00
|
|
|
if (aMessage.json.messageId != this._messageId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Browser:ContextMenu":
|
|
|
|
// Long tap
|
|
|
|
this._contextMenu = { name: aMessage.name, json: aMessage.json, target: aMessage.target };
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Browser:Highlight": {
|
|
|
|
let rects = aMessage.json.rects.map(
|
|
|
|
function(r) new Rect(r.left, r.top, r.width, r.height));
|
|
|
|
TapHighlightHelper.show(rects);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-22 15:12:41 -07:00
|
|
|
},
|
|
|
|
|
2010-09-22 16:27:11 -07:00
|
|
|
/** Invalidates any messages received from content that are sensitive to time. */
|
|
|
|
_clearPendingMessages: function _clearPendingMessages() {
|
|
|
|
this._messageId++;
|
|
|
|
TapHighlightHelper.hide(0);
|
2010-09-22 15:12:41 -07:00
|
|
|
this._contextMenu = null;
|
|
|
|
},
|
|
|
|
|
2010-09-22 15:09:04 -07:00
|
|
|
/**
|
|
|
|
* Check if the event concern the browser content
|
|
|
|
*/
|
|
|
|
_targetIsContent: function _targetIsContent(aEvent) {
|
|
|
|
let target = aEvent.target;
|
|
|
|
return target && target.id == "inputhandler-overlay";
|
|
|
|
},
|
|
|
|
|
2010-06-29 11:15:07 -07:00
|
|
|
_dispatchMouseEvent: function _dispatchMouseEvent(aName, aX, aY, aModifiers) {
|
2010-06-29 23:21:47 -07:00
|
|
|
let aX = aX || 0;
|
|
|
|
let aY = aY || 0;
|
2010-06-29 11:15:07 -07:00
|
|
|
let aModifiers = aModifiers || null;
|
2010-08-31 12:25:47 -07:00
|
|
|
let browser = getBrowser();
|
2010-06-21 13:16:37 -07:00
|
|
|
let [x, y] = Browser.transformClientToBrowser(aX, aY);
|
2010-09-22 16:27:11 -07:00
|
|
|
browser.messageManager.sendAsyncMessage(aName, {
|
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
modifiers: aModifiers,
|
|
|
|
messageId: this._messageId
|
|
|
|
});
|
2010-06-21 13:16:37 -07:00
|
|
|
},
|
2009-12-11 11:41:28 -08:00
|
|
|
|
2010-09-22 15:08:18 -07:00
|
|
|
tapDown: function tapDown(aX, aY) {
|
2010-06-21 13:16:37 -07:00
|
|
|
// Ensure that the content process has gets an activate event
|
2010-09-27 08:11:56 -07:00
|
|
|
let browser = getBrowser();
|
|
|
|
let fl = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
|
|
|
|
browser.focus();
|
|
|
|
try {
|
|
|
|
fl.activateRemoteFrame();
|
|
|
|
} catch (e) {
|
|
|
|
}
|
2010-06-21 13:16:37 -07:00
|
|
|
this._dispatchMouseEvent("Browser:MouseDown", aX, aY);
|
|
|
|
},
|
2009-11-27 21:37:01 -08:00
|
|
|
|
2010-09-22 15:08:18 -07:00
|
|
|
tapUp: function tapUp(aX, aY) {
|
2010-09-17 11:48:20 -07:00
|
|
|
TapHighlightHelper.hide(200);
|
2010-09-22 15:12:41 -07:00
|
|
|
this._contextMenu = null;
|
2010-06-21 13:16:37 -07:00
|
|
|
},
|
2009-11-27 21:37:01 -08:00
|
|
|
|
2010-09-22 15:08:18 -07:00
|
|
|
tapSingle: function tapSingle(aX, aY, aModifiers) {
|
2010-09-17 11:48:20 -07:00
|
|
|
TapHighlightHelper.hide(200);
|
2010-09-22 15:12:41 -07:00
|
|
|
this._contextMenu = null;
|
2010-06-29 11:15:07 -07:00
|
|
|
|
|
|
|
// Cancel the mouse click if we are showing a context menu
|
2010-06-29 23:21:47 -07:00
|
|
|
if (!ContextHelper.popupState)
|
2010-06-29 11:15:07 -07:00
|
|
|
this._dispatchMouseEvent("Browser:MouseUp", aX, aY, aModifiers);
|
2010-06-21 13:16:37 -07:00
|
|
|
},
|
2009-09-01 20:39:39 -07:00
|
|
|
|
2010-09-23 16:20:55 -07:00
|
|
|
tapDouble: function tapDouble(aX, aY, aModifiers) {
|
2010-09-22 16:27:11 -07:00
|
|
|
this._clearPendingMessages();
|
2010-09-23 16:20:55 -07:00
|
|
|
this._dispatchMouseEvent("Browser:ZoomToPoint", aX, aY);
|
2010-06-21 13:16:37 -07:00
|
|
|
},
|
2009-09-01 20:39:39 -07:00
|
|
|
|
2010-09-22 15:12:41 -07:00
|
|
|
tapLong: function tapLong() {
|
|
|
|
if (this._contextMenu) {
|
2010-09-22 16:27:11 -07:00
|
|
|
if (ContextHelper.showPopup(this._contextMenu)) {
|
2010-09-22 15:12:41 -07:00
|
|
|
// Stop all input sequences
|
2010-09-22 16:27:11 -07:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("CancelTouchSequence", true, false);
|
|
|
|
document.dispatchEvent(event);
|
|
|
|
}
|
2010-09-22 15:12:41 -07:00
|
|
|
this._contextMenu = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-21 13:16:37 -07:00
|
|
|
toString: function toString() {
|
2010-09-22 15:08:18 -07:00
|
|
|
return "[ContentTouchHandler] { }";
|
2010-06-21 13:16:37 -07:00
|
|
|
}
|
2009-09-01 20:39:39 -07:00
|
|
|
};
|
|
|
|
|
2010-06-23 12:23:06 -07:00
|
|
|
|
2010-09-27 08:11:56 -07:00
|
|
|
/** Watches for mouse events in chrome and sends them to content. */
|
|
|
|
function ContentCustomKeySender(container) {
|
|
|
|
container.addEventListener("keypress", this, false);
|
|
|
|
container.addEventListener("keyup", this, false);
|
|
|
|
container.addEventListener("keydown", this, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentCustomKeySender.prototype = {
|
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
aEvent.stopPropagation();
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
|
|
|
let browser = getBrowser();
|
|
|
|
if (browser) {
|
|
|
|
browser.messageManager.sendAsyncMessage("Browser:KeyEvent", {
|
|
|
|
type: aEvent.type,
|
|
|
|
keyCode: aEvent.keyCode,
|
|
|
|
charCode: aEvent.charCode,
|
|
|
|
modifiers: this._parseModifiers(aEvent)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_parseModifiers: function _parseModifiers(aEvent) {
|
|
|
|
const masks = Components.interfaces.nsIDOMNSEvent;
|
|
|
|
var mval = 0;
|
|
|
|
if (aEvent.shiftKey)
|
|
|
|
mval |= masks.SHIFT_MASK;
|
|
|
|
if (aEvent.ctrlKey)
|
|
|
|
mval |= masks.CONTROL_MASK;
|
|
|
|
if (aEvent.altKey)
|
|
|
|
mval |= masks.ALT_MASK;
|
|
|
|
if (aEvent.metaKey)
|
|
|
|
mval |= masks.META_MASK;
|
|
|
|
return mval;
|
|
|
|
},
|
|
|
|
|
|
|
|
toString: function toString() {
|
|
|
|
return "[ContentCustomKeySender] { }";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
|
|
|
* Utility class to handle manipulations of the identity indicators in the UI
|
|
|
|
*/
|
|
|
|
function IdentityHandler() {
|
|
|
|
this._staticStrings = {};
|
|
|
|
this._staticStrings[this.IDENTITY_MODE_DOMAIN_VERIFIED] = {
|
2009-11-19 13:40:13 -08:00
|
|
|
encryption_label: Elements.browserBundle.getString("identity.encrypted2")
|
2008-06-20 14:01:42 -07:00
|
|
|
};
|
|
|
|
this._staticStrings[this.IDENTITY_MODE_IDENTIFIED] = {
|
2009-11-19 13:40:13 -08:00
|
|
|
encryption_label: Elements.browserBundle.getString("identity.encrypted2")
|
2008-06-20 14:01:42 -07:00
|
|
|
};
|
|
|
|
this._staticStrings[this.IDENTITY_MODE_UNKNOWN] = {
|
2009-11-19 13:40:13 -08:00
|
|
|
encryption_label: Elements.browserBundle.getString("identity.unencrypted2")
|
2008-06-20 14:01:42 -07:00
|
|
|
};
|
|
|
|
|
2010-08-25 08:27:57 -07:00
|
|
|
// Close the popup when reloading the page
|
|
|
|
document.getElementById("browsers").addEventListener("URLChanged", this, true);
|
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
this._cacheElements();
|
|
|
|
}
|
|
|
|
|
|
|
|
IdentityHandler.prototype = {
|
|
|
|
// Mode strings used to control CSS display
|
|
|
|
IDENTITY_MODE_IDENTIFIED : "verifiedIdentity", // High-quality identity information
|
|
|
|
IDENTITY_MODE_DOMAIN_VERIFIED : "verifiedDomain", // Minimal SSL CA-signed domain verification
|
|
|
|
IDENTITY_MODE_UNKNOWN : "unknownIdentity", // No trusted identity information
|
|
|
|
|
|
|
|
// Cache the most recent SSLStatus and Location seen in checkIdentity
|
|
|
|
_lastStatus : null,
|
|
|
|
_lastLocation : null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build out a cache of the elements that we need frequently.
|
|
|
|
*/
|
2008-11-21 21:12:25 -08:00
|
|
|
_cacheElements: function() {
|
2008-06-20 14:01:42 -07:00
|
|
|
this._identityBox = document.getElementById("identity-box");
|
2009-06-08 11:09:18 -07:00
|
|
|
this._identityPopup = document.getElementById("identity-container");
|
2008-06-20 14:01:42 -07:00
|
|
|
this._identityPopupContentBox = document.getElementById("identity-popup-content-box");
|
|
|
|
this._identityPopupContentHost = document.getElementById("identity-popup-content-host");
|
|
|
|
this._identityPopupContentOwner = document.getElementById("identity-popup-content-owner");
|
|
|
|
this._identityPopupContentSupp = document.getElementById("identity-popup-content-supplemental");
|
|
|
|
this._identityPopupContentVerif = document.getElementById("identity-popup-content-verifier");
|
|
|
|
this._identityPopupEncLabel = document.getElementById("identity-popup-encryption-label");
|
|
|
|
},
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
getIdentityData: function() {
|
2010-06-16 06:53:29 -07:00
|
|
|
return this._lastStatus.serverCert;
|
2008-06-20 14:01:42 -07:00
|
|
|
},
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
|
|
|
* Determine the identity of the page being displayed by examining its SSL cert
|
2009-09-10 06:24:48 -07:00
|
|
|
* (if available) and, if necessary, update the UI to reflect this.
|
2008-06-20 14:01:42 -07:00
|
|
|
*/
|
2009-09-10 06:24:48 -07:00
|
|
|
checkIdentity: function() {
|
2010-06-16 07:47:13 -07:00
|
|
|
let browser = getBrowser();
|
2010-06-16 06:53:29 -07:00
|
|
|
let state = browser.securityUI.state;
|
|
|
|
let location = browser.currentURI;
|
|
|
|
let currentStatus = browser.securityUI.SSLStatus;
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
this._lastStatus = currentStatus;
|
2009-09-10 06:24:48 -07:00
|
|
|
this._lastLocation = {};
|
2010-06-16 06:53:29 -07:00
|
|
|
|
2009-09-10 06:24:48 -07:00
|
|
|
try {
|
2009-09-10 07:17:38 -07:00
|
|
|
// make a copy of the passed in location to avoid cycles
|
2010-06-16 06:53:29 -07:00
|
|
|
this._lastLocation = { host: location.hostPort, hostname: location.host, port: location.port == -1 ? "" : location.port};
|
|
|
|
} catch(e) { }
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2009-03-31 11:45:24 -07:00
|
|
|
if (state & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL)
|
2008-06-20 14:01:42 -07:00
|
|
|
this.setMode(this.IDENTITY_MODE_IDENTIFIED);
|
2009-03-31 11:45:24 -07:00
|
|
|
else if (state & Ci.nsIWebProgressListener.STATE_SECURE_HIGH)
|
2008-06-20 14:01:42 -07:00
|
|
|
this.setMode(this.IDENTITY_MODE_DOMAIN_VERIFIED);
|
|
|
|
else
|
|
|
|
this.setMode(this.IDENTITY_MODE_UNKNOWN);
|
|
|
|
},
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
|
|
|
* Return the eTLD+1 version of the current hostname
|
|
|
|
*/
|
2008-11-21 21:12:25 -08:00
|
|
|
getEffectiveHost: function() {
|
2008-06-20 14:01:42 -07:00
|
|
|
// Cache the eTLDService if this is our first time through
|
|
|
|
if (!this._eTLDService)
|
|
|
|
this._eTLDService = Cc["@mozilla.org/network/effective-tld-service;1"]
|
|
|
|
.getService(Ci.nsIEffectiveTLDService);
|
|
|
|
try {
|
|
|
|
return this._eTLDService.getBaseDomainFromHost(this._lastLocation.hostname);
|
|
|
|
} catch (e) {
|
|
|
|
// If something goes wrong (e.g. hostname is an IP address) just fail back
|
|
|
|
// to the full domain.
|
|
|
|
return this._lastLocation.hostname;
|
|
|
|
}
|
|
|
|
},
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
|
|
|
* Update the UI to reflect the specified mode, which should be one of the
|
|
|
|
* IDENTITY_MODE_* constants.
|
|
|
|
*/
|
2008-11-21 21:12:25 -08:00
|
|
|
setMode: function(newMode) {
|
2009-06-08 11:09:18 -07:00
|
|
|
this._identityBox.setAttribute("mode", newMode);
|
2008-06-20 14:01:42 -07:00
|
|
|
this.setIdentityMessages(newMode);
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Update the popup too, if it's open
|
2009-06-08 11:09:18 -07:00
|
|
|
if (!this._identityPopup.hidden)
|
2008-06-20 14:01:42 -07:00
|
|
|
this.setPopupMessages(newMode);
|
|
|
|
},
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
|
|
|
* Set up the messages for the primary identity UI based on the specified mode,
|
|
|
|
* and the details of the SSL cert, where applicable
|
|
|
|
*
|
|
|
|
* @param newMode The newly set identity mode. Should be one of the IDENTITY_MODE_* constants.
|
|
|
|
*/
|
2008-11-21 21:12:25 -08:00
|
|
|
setIdentityMessages: function(newMode) {
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
if (newMode == this.IDENTITY_MODE_DOMAIN_VERIFIED) {
|
|
|
|
var iData = this.getIdentityData();
|
|
|
|
|
|
|
|
// We need a port number for all lookups. If one hasn't been specified, use
|
|
|
|
// the https default
|
|
|
|
var lookupHost = this._lastLocation.host;
|
|
|
|
if (lookupHost.indexOf(':') < 0)
|
|
|
|
lookupHost += ":443";
|
|
|
|
|
|
|
|
// Cache the override service the first time we need to check it
|
|
|
|
if (!this._overrideService)
|
2009-03-31 11:45:24 -07:00
|
|
|
this._overrideService = Cc["@mozilla.org/security/certoverride;1"].getService(Ci.nsICertOverrideService);
|
2008-06-20 14:01:42 -07:00
|
|
|
|
|
|
|
// Verifier is either the CA Org, for a normal cert, or a special string
|
|
|
|
// for certs that are trusted because of a security exception.
|
2009-11-19 13:40:13 -08:00
|
|
|
var tooltip = strings.getFormattedString("identity.identified.verifier",
|
|
|
|
[iData.caOrg]);
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2010-06-16 06:53:29 -07:00
|
|
|
// Check whether this site is a security exception.
|
|
|
|
if (iData.isException)
|
2009-11-19 13:40:13 -08:00
|
|
|
tooltip = strings.getString("identity.identified.verified_by_you");
|
2008-06-20 14:01:42 -07:00
|
|
|
}
|
|
|
|
else if (newMode == this.IDENTITY_MODE_IDENTIFIED) {
|
|
|
|
// If it's identified, then we can populate the dialog with credentials
|
2008-07-08 18:24:49 -07:00
|
|
|
iData = this.getIdentityData();
|
2009-11-19 13:40:13 -08:00
|
|
|
tooltip = strings.getFormattedString("identity.identified.verifier",
|
|
|
|
[iData.caOrg]);
|
2008-06-20 14:01:42 -07:00
|
|
|
}
|
|
|
|
else {
|
2009-11-19 13:40:13 -08:00
|
|
|
tooltip = strings.getString("identity.unknown.tooltip");
|
2008-06-20 14:01:42 -07:00
|
|
|
}
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Push the appropriate strings out to the UI
|
|
|
|
this._identityBox.tooltipText = tooltip;
|
|
|
|
},
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
|
|
|
* Set up the title and content messages for the identity message popup,
|
|
|
|
* based on the specified mode, and the details of the SSL cert, where
|
|
|
|
* applicable
|
|
|
|
*
|
|
|
|
* @param newMode The newly set identity mode. Should be one of the IDENTITY_MODE_* constants.
|
|
|
|
*/
|
2008-11-21 21:12:25 -08:00
|
|
|
setPopupMessages: function(newMode) {
|
2009-06-08 11:09:18 -07:00
|
|
|
this._identityPopup.setAttribute("mode", newMode);
|
2008-06-20 14:01:42 -07:00
|
|
|
this._identityPopupContentBox.className = newMode;
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Set the static strings up front
|
|
|
|
this._identityPopupEncLabel.textContent = this._staticStrings[newMode].encryption_label;
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Initialize the optional strings to empty values
|
|
|
|
var supplemental = "";
|
|
|
|
var verifier = "";
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
if (newMode == this.IDENTITY_MODE_DOMAIN_VERIFIED) {
|
|
|
|
var iData = this.getIdentityData();
|
|
|
|
var host = this.getEffectiveHost();
|
2009-11-19 13:40:13 -08:00
|
|
|
var owner = strings.getString("identity.ownerUnknown2");
|
2008-06-20 14:01:42 -07:00
|
|
|
verifier = this._identityBox.tooltipText;
|
|
|
|
supplemental = "";
|
|
|
|
}
|
|
|
|
else if (newMode == this.IDENTITY_MODE_IDENTIFIED) {
|
|
|
|
// If it's identified, then we can populate the dialog with credentials
|
|
|
|
iData = this.getIdentityData();
|
|
|
|
host = this.getEffectiveHost();
|
2008-07-08 18:24:49 -07:00
|
|
|
owner = iData.subjectOrg;
|
2008-06-20 14:01:42 -07:00
|
|
|
verifier = this._identityBox.tooltipText;
|
|
|
|
|
|
|
|
// Build an appropriate supplemental block out of whatever location data we have
|
|
|
|
if (iData.city)
|
2009-10-05 12:45:39 -07:00
|
|
|
supplemental += iData.city + " ";
|
2008-06-20 14:01:42 -07:00
|
|
|
if (iData.state && iData.country)
|
2009-11-19 13:40:13 -08:00
|
|
|
supplemental += strings.getFormattedString("identity.identified.state_and_country",
|
|
|
|
[iData.state, iData.country]);
|
2008-06-20 14:01:42 -07:00
|
|
|
else if (iData.state) // State only
|
|
|
|
supplemental += iData.state;
|
|
|
|
else if (iData.country) // Country only
|
|
|
|
supplemental += iData.country;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// These strings will be hidden in CSS anyhow
|
|
|
|
host = "";
|
|
|
|
owner = "";
|
|
|
|
}
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Push the appropriate strings out to the UI
|
|
|
|
this._identityPopupContentHost.textContent = host;
|
|
|
|
this._identityPopupContentOwner.textContent = owner;
|
|
|
|
this._identityPopupContentSupp.textContent = supplemental;
|
|
|
|
this._identityPopupContentVerif.textContent = verifier;
|
2009-08-26 12:29:46 -07:00
|
|
|
|
2010-08-13 11:41:00 -07:00
|
|
|
PageActions.updateSiteMenu();
|
2008-06-20 14:01:42 -07:00
|
|
|
},
|
|
|
|
|
2009-06-08 11:09:18 -07:00
|
|
|
show: function ih_show() {
|
2009-09-14 09:50:21 -07:00
|
|
|
// dismiss any dialog which hide the identity popup
|
2010-08-24 01:42:28 -07:00
|
|
|
BrowserUI.activePanel = null;
|
2009-09-14 09:50:21 -07:00
|
|
|
while (BrowserUI.activeDialog)
|
|
|
|
BrowserUI.activeDialog.close();
|
|
|
|
|
2009-06-08 11:09:18 -07:00
|
|
|
this._identityPopup.hidden = false;
|
|
|
|
this._identityPopup.top = BrowserUI.toolbarH;
|
|
|
|
this._identityPopup.focus();
|
|
|
|
|
2009-08-05 15:49:44 -07:00
|
|
|
this._identityBox.setAttribute("open", "true");
|
2009-08-10 18:03:42 -07:00
|
|
|
|
2009-06-08 11:09:18 -07:00
|
|
|
// Update the popup strings
|
|
|
|
this.setPopupMessages(this._identityBox.getAttribute("mode") || this.IDENTITY_MODE_UNKNOWN);
|
2009-08-14 10:30:50 -07:00
|
|
|
|
2010-05-21 10:05:46 -07:00
|
|
|
BrowserUI.pushPopup(this, [this._identityPopup, this._identityBox, Elements.toolbarContainer]);
|
2009-08-24 07:18:26 -07:00
|
|
|
BrowserUI.lockToolbar();
|
2009-06-08 11:09:18 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function ih_hide() {
|
|
|
|
this._identityPopup.hidden = true;
|
2009-08-05 15:49:44 -07:00
|
|
|
this._identityBox.removeAttribute("open");
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-10-12 11:35:01 -07:00
|
|
|
BrowserUI.popPopup();
|
2009-08-24 07:18:26 -07:00
|
|
|
BrowserUI.unlockToolbar();
|
2008-06-20 14:01:42 -07:00
|
|
|
},
|
|
|
|
|
2010-04-27 13:33:59 -07:00
|
|
|
toggle: function ih_toggle() {
|
2010-08-27 01:24:17 -07:00
|
|
|
// When the urlbar is active the identity button is used to show the
|
|
|
|
// list of search engines
|
|
|
|
if (Elements.urlbarState.getAttribute("mode") == "edit") {
|
|
|
|
CommandUpdater.doCommand("cmd_opensearch");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-27 13:33:59 -07:00
|
|
|
if (this._identityPopup.hidden)
|
|
|
|
this.show();
|
|
|
|
else
|
|
|
|
this.hide();
|
|
|
|
},
|
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
2008-07-08 18:24:49 -07:00
|
|
|
* Click handler for the identity-box element in primary chrome.
|
2008-06-20 14:01:42 -07:00
|
|
|
*/
|
2010-08-25 08:27:57 -07:00
|
|
|
handleIdentityButtonEvent: function(aEvent) {
|
|
|
|
aEvent.stopPropagation();
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2010-08-25 08:27:57 -07:00
|
|
|
if ((aEvent.type == "click" && aEvent.button != 0) ||
|
|
|
|
(aEvent.type == "keypress" && aEvent.charCode != KeyEvent.DOM_VK_SPACE &&
|
|
|
|
aEvent.keyCode != KeyEvent.DOM_VK_RETURN))
|
2008-06-20 14:01:42 -07:00
|
|
|
return; // Left click, space or enter only
|
|
|
|
|
2010-04-27 13:33:59 -07:00
|
|
|
this.toggle();
|
2010-08-26 16:09:56 -07:00
|
|
|
},
|
2010-08-25 08:27:57 -07:00
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
if (aEvent.type == "URLChanged" && !this._identityPopup.hidden)
|
|
|
|
this.hide();
|
2008-06-20 14:01:42 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-07-08 18:24:49 -07:00
|
|
|
var gIdentityHandler;
|
2008-06-20 14:01:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the singleton instance of the identity handler class. Should always be
|
|
|
|
* used instead of referencing the global variable directly or creating new instances
|
|
|
|
*/
|
|
|
|
function getIdentityHandler() {
|
|
|
|
if (!gIdentityHandler)
|
|
|
|
gIdentityHandler = new IdentityHandler();
|
2008-07-08 18:24:49 -07:00
|
|
|
return gIdentityHandler;
|
2008-06-20 14:01:42 -07:00
|
|
|
}
|
2008-07-11 11:51:28 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for blocked popups, triggered by DOMUpdatePageReport events in browser.xml
|
|
|
|
*/
|
|
|
|
const gPopupBlockerObserver = {
|
2009-08-07 14:59:06 -07:00
|
|
|
onUpdatePageReport: function onUpdatePageReport(aEvent)
|
2008-07-11 11:51:28 -07:00
|
|
|
{
|
2009-01-08 22:51:13 -08:00
|
|
|
var cBrowser = Browser.selectedBrowser;
|
2008-07-11 11:51:28 -07:00
|
|
|
if (aEvent.originalTarget != cBrowser)
|
|
|
|
return;
|
2008-07-11 20:09:35 -07:00
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
if (!cBrowser.pageReport)
|
|
|
|
return;
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let result = Services.perms.testExactPermission(Browser.selectedBrowser.currentURI, "popup");
|
2009-09-01 10:02:19 -07:00
|
|
|
if (result == Ci.nsIPermissionManager.DENY_ACTION)
|
|
|
|
return;
|
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
// Only show the notification again if we've not already shown it. Since
|
|
|
|
// notifications are per-browser, we don't need to worry about re-adding
|
|
|
|
// it.
|
|
|
|
if (!cBrowser.pageReport.reported) {
|
2010-07-13 07:36:09 -07:00
|
|
|
if (Services.prefs.getBoolPref("privacy.popups.showBrowserMessage")) {
|
2008-07-11 11:51:28 -07:00
|
|
|
var brandBundle = document.getElementById("bundle_brand");
|
|
|
|
var brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
var message;
|
|
|
|
var popupCount = cBrowser.pageReport.length;
|
2008-07-11 20:09:35 -07:00
|
|
|
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
2008-07-11 11:51:28 -07:00
|
|
|
if (popupCount > 1)
|
2009-11-19 13:40:13 -08:00
|
|
|
message = strings.getFormattedString("popupWarningMultiple", [brandShortName, popupCount]);
|
2008-07-11 11:51:28 -07:00
|
|
|
else
|
2009-11-19 13:40:13 -08:00
|
|
|
message = strings.getFormattedString("popupWarning", [brandShortName]);
|
2008-07-11 20:09:35 -07:00
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
var notificationBox = Browser.getNotificationBox();
|
|
|
|
var notification = notificationBox.getNotificationWithValue("popup-blocked");
|
|
|
|
if (notification) {
|
|
|
|
notification.label = message;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var buttons = [
|
|
|
|
{
|
2009-11-19 13:40:13 -08:00
|
|
|
label: strings.getString("popupButtonAllowOnce"),
|
2009-08-12 09:28:51 -07:00
|
|
|
accessKey: null,
|
|
|
|
callback: function() { gPopupBlockerObserver.showPopupsForSite(); }
|
|
|
|
},
|
|
|
|
{
|
2009-11-19 13:40:13 -08:00
|
|
|
label: strings.getString("popupButtonAlwaysAllow2"),
|
2009-08-12 09:28:51 -07:00
|
|
|
accessKey: null,
|
2010-07-13 07:36:09 -07:00
|
|
|
callback: function() { gPopupBlockerObserver.allowPopupsForSite(true); }
|
2008-07-11 11:51:28 -07:00
|
|
|
},
|
|
|
|
{
|
2009-11-19 13:40:13 -08:00
|
|
|
label: strings.getString("popupButtonNeverWarn2"),
|
2009-08-12 09:28:51 -07:00
|
|
|
accessKey: null,
|
2010-07-13 07:36:09 -07:00
|
|
|
callback: function() { gPopupBlockerObserver.allowPopupsForSite(false); }
|
2008-07-11 11:51:28 -07:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const priority = notificationBox.PRIORITY_WARNING_MEDIUM;
|
|
|
|
notificationBox.appendNotification(message, "popup-blocked",
|
|
|
|
"",
|
|
|
|
priority, buttons);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Record the fact that we've reported this blocked popup, so we don't
|
|
|
|
// show it again.
|
|
|
|
cBrowser.pageReport.reported = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
allowPopupsForSite: function allowPopupsForSite(aAllow) {
|
2009-09-01 10:02:19 -07:00
|
|
|
var currentURI = Browser.selectedBrowser.currentURI;
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.perms.add(currentURI, "popup", aAllow
|
|
|
|
? Ci.nsIPermissionManager.ALLOW_ACTION
|
|
|
|
: Ci.nsIPermissionManager.DENY_ACTION);
|
2009-09-01 10:02:19 -07:00
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
Browser.getNotificationBox().removeCurrentNotification();
|
2009-08-12 09:28:51 -07:00
|
|
|
},
|
2009-08-13 16:41:45 -07:00
|
|
|
|
2009-08-12 09:28:51 -07:00
|
|
|
showPopupsForSite: function showPopupsForSite() {
|
|
|
|
let uri = Browser.selectedBrowser.currentURI;
|
|
|
|
let pageReport = Browser.selectedBrowser.pageReport;
|
|
|
|
if (pageReport) {
|
|
|
|
for (let i = 0; i < pageReport.length; ++i) {
|
|
|
|
var popupURIspec = pageReport[i].popupWindowURI.spec;
|
|
|
|
|
|
|
|
// Sometimes the popup URI that we get back from the pageReport
|
|
|
|
// isn't useful (for instance, netscape.com's popup URI ends up
|
|
|
|
// being "http://www.netscape.com", which isn't really the URI of
|
|
|
|
// the popup they're trying to show). This isn't going to be
|
|
|
|
// useful to the user, so we won't create a menu item for it.
|
|
|
|
if (popupURIspec == "" || popupURIspec == "about:blank" ||
|
|
|
|
popupURIspec == uri.spec)
|
|
|
|
continue;
|
2009-08-13 16:41:45 -07:00
|
|
|
|
2009-08-12 09:28:51 -07:00
|
|
|
let popupFeatures = pageReport[i].popupWindowFeatures;
|
|
|
|
let popupName = pageReport[i].popupWindowName;
|
2009-08-13 16:41:45 -07:00
|
|
|
|
2010-06-15 14:56:13 -07:00
|
|
|
Browser.addTab(popupURIspec, false, Browser.selectedTab);
|
2009-08-12 09:28:51 -07:00
|
|
|
}
|
|
|
|
}
|
2008-07-11 11:51:28 -07:00
|
|
|
}
|
|
|
|
};
|
2008-08-18 12:59:14 -07:00
|
|
|
|
2008-08-19 19:18:36 -07:00
|
|
|
const gXPInstallObserver = {
|
2009-08-07 14:59:06 -07:00
|
|
|
observe: function xpi_observer(aSubject, aTopic, aData)
|
2008-08-19 19:18:36 -07:00
|
|
|
{
|
|
|
|
var brandBundle = document.getElementById("bundle_brand");
|
|
|
|
switch (aTopic) {
|
2010-05-19 19:43:02 -07:00
|
|
|
case "addon-install-blocked":
|
|
|
|
var installInfo = aSubject.QueryInterface(Ci.amIWebInstallInfo);
|
2008-08-19 19:18:36 -07:00
|
|
|
var host = installInfo.originatingURI.host;
|
|
|
|
var brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
var notificationName, messageString, buttons;
|
2009-11-19 13:40:13 -08:00
|
|
|
var strings = Elements.browserBundle;
|
2010-05-19 19:43:02 -07:00
|
|
|
var enabled = true;
|
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
enabled = Services.prefs.getBoolPref("xpinstall.enabled");
|
2010-05-19 19:43:02 -07:00
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
if (!enabled) {
|
2009-06-29 11:33:05 -07:00
|
|
|
notificationName = "xpinstall-disabled";
|
2010-07-13 07:36:09 -07:00
|
|
|
if (Services.prefs.prefIsLocked("xpinstall.enabled")) {
|
2009-11-19 13:40:13 -08:00
|
|
|
messageString = strings.getString("xpinstallDisabledMessageLocked");
|
2008-08-19 19:18:36 -07:00
|
|
|
buttons = [];
|
|
|
|
}
|
|
|
|
else {
|
2009-11-19 13:40:13 -08:00
|
|
|
messageString = strings.getFormattedString("xpinstallDisabledMessage",
|
2008-08-19 19:18:36 -07:00
|
|
|
[brandShortName, host]);
|
|
|
|
buttons = [{
|
2009-11-19 13:40:13 -08:00
|
|
|
label: strings.getString("xpinstallDisabledButton"),
|
2009-10-14 13:36:47 -07:00
|
|
|
accessKey: null,
|
2008-08-19 19:18:36 -07:00
|
|
|
popup: null,
|
|
|
|
callback: function editPrefs() {
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.prefs.setBoolPref("xpinstall.enabled", true);
|
2008-08-19 19:18:36 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-06-29 11:33:05 -07:00
|
|
|
notificationName = "xpinstall";
|
2009-11-19 13:40:13 -08:00
|
|
|
messageString = strings.getFormattedString("xpinstallPromptWarning",
|
2008-08-19 19:18:36 -07:00
|
|
|
[brandShortName, host]);
|
|
|
|
|
|
|
|
buttons = [{
|
2009-11-19 13:40:13 -08:00
|
|
|
label: strings.getString("xpinstallPromptAllowButton"),
|
2009-10-14 13:36:47 -07:00
|
|
|
accessKey: null,
|
2008-08-19 19:18:36 -07:00
|
|
|
popup: null,
|
|
|
|
callback: function() {
|
2010-05-19 19:43:02 -07:00
|
|
|
// Kick off the install
|
|
|
|
installInfo.install();
|
2008-08-19 19:18:36 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
var nBox = Browser.getNotificationBox();
|
|
|
|
if (!nBox.getNotificationWithValue(notificationName)) {
|
|
|
|
const priority = nBox.PRIORITY_WARNING_MEDIUM;
|
|
|
|
const iconURL = "chrome://mozapps/skin/update/update.png";
|
|
|
|
nBox.appendNotification(messageString, notificationName, iconURL, priority, buttons);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-22 17:47:02 -07:00
|
|
|
const gSessionHistoryObserver = {
|
|
|
|
observe: function sho_observe(subject, topic, data) {
|
|
|
|
if (topic != "browser:purge-session-history")
|
|
|
|
return;
|
|
|
|
|
|
|
|
let back = document.getElementById("cmd_back");
|
|
|
|
back.setAttribute("disabled", "true");
|
|
|
|
let forward = document.getElementById("cmd_forward");
|
|
|
|
forward.setAttribute("disabled", "true");
|
|
|
|
|
|
|
|
let urlbar = document.getElementById("urlbar-edit");
|
|
|
|
if (urlbar) {
|
|
|
|
// Clear undo history of the URL bar
|
2009-06-29 11:33:05 -07:00
|
|
|
urlbar.editor.transactionManager.clear();
|
2009-04-22 17:47:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
var MemoryObserver = {
|
2009-12-15 12:37:02 -08:00
|
|
|
observe: function mo_observe() {
|
2010-06-22 06:24:55 -07:00
|
|
|
window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils).garbageCollect();
|
|
|
|
Components.utils.forceGC();
|
2009-09-04 22:14:59 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-14 14:58:10 -07:00
|
|
|
function getNotificationBox(aBrowser) {
|
|
|
|
return Browser.getNotificationBox(aBrowser);
|
2008-08-19 19:18:36 -07:00
|
|
|
}
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2010-07-16 08:48:52 -07:00
|
|
|
function importDialog(aParent, aSrc, aArguments) {
|
2009-09-02 07:15:22 -07:00
|
|
|
// load the dialog with a synchronous XHR
|
|
|
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
|
2010-07-16 08:48:52 -07:00
|
|
|
xhr.open("GET", aSrc, false);
|
2009-09-02 07:15:22 -07:00
|
|
|
xhr.overrideMimeType("text/xml");
|
|
|
|
xhr.send(null);
|
|
|
|
if (!xhr.responseXML)
|
|
|
|
return null;
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-11-12 20:51:29 -08:00
|
|
|
let currentNode;
|
2010-07-16 08:48:52 -07:00
|
|
|
let nodeIterator = xhr.responseXML.createNodeIterator(xhr.responseXML, NodeFilter.SHOW_TEXT, null, false);
|
2009-11-12 20:51:29 -08:00
|
|
|
while (currentNode = nodeIterator.nextNode()) {
|
|
|
|
let trimmed = currentNode.nodeValue.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
|
|
|
|
if (!trimmed.length)
|
|
|
|
currentNode.parentNode.removeChild(currentNode);
|
|
|
|
}
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-09-02 07:15:22 -07:00
|
|
|
let doc = xhr.responseXML.documentElement;
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-09-02 07:15:22 -07:00
|
|
|
var dialog = null;
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2010-08-24 01:53:22 -07:00
|
|
|
// we need to insert before menulist-container if we want it to show correctly
|
|
|
|
// for prompt.select for instance
|
|
|
|
let menulistContainer = document.getElementById("menulist-container");
|
|
|
|
let parentNode = menulistContainer.parentNode;
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-10-12 12:05:46 -07:00
|
|
|
// emit DOMWillOpenModalDialog event
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("DOMWillOpenModalDialog", true, false);
|
2010-07-16 08:48:52 -07:00
|
|
|
let dispatcher = aParent || getBrowser();
|
2009-10-12 12:05:46 -07:00
|
|
|
dispatcher.dispatchEvent(event);
|
|
|
|
|
2010-01-14 13:08:40 -08:00
|
|
|
// create a full-screen semi-opaque box as a background
|
2009-09-02 07:15:22 -07:00
|
|
|
let back = document.createElement("box");
|
|
|
|
back.setAttribute("class", "modal-block");
|
|
|
|
dialog = back.appendChild(document.importNode(doc, true));
|
2010-08-24 01:53:22 -07:00
|
|
|
parentNode.insertBefore(back, menulistContainer);
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2010-07-16 08:48:52 -07:00
|
|
|
dialog.arguments = aArguments;
|
|
|
|
dialog.parent = aParent;
|
2009-09-02 07:15:22 -07:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2009-09-30 10:13:54 -07:00
|
|
|
function showDownloadManager(aWindowContext, aID, aReason) {
|
|
|
|
BrowserUI.showPanel("downloads-container");
|
2009-04-22 07:59:52 -07:00
|
|
|
// TODO: select the download with aID
|
|
|
|
}
|
|
|
|
|
2009-04-08 22:13:16 -07:00
|
|
|
var AlertsHelper = {
|
|
|
|
_timeoutID: -1,
|
|
|
|
_listener: null,
|
|
|
|
_cookie: "",
|
|
|
|
_clickable: false,
|
2010-08-23 23:34:10 -07:00
|
|
|
get container() {
|
2010-09-02 18:27:20 -07:00
|
|
|
delete this.container;
|
|
|
|
let container = document.getElementById("alerts-container");
|
|
|
|
|
|
|
|
// Move the popup on the other side if we are in RTL
|
|
|
|
let [leftSidebar, rightSidebar] = [Elements.tabs.getBoundingClientRect(), Elements.controls.getBoundingClientRect()];
|
|
|
|
if (leftSidebar.left > rightSidebar.left) {
|
|
|
|
container.removeAttribute("right");
|
|
|
|
container.setAttribute("left", "0");
|
2010-08-23 23:34:10 -07:00
|
|
|
}
|
2010-09-02 18:27:20 -07:00
|
|
|
|
|
|
|
let self = this;
|
|
|
|
container.addEventListener("transitionend", function() {
|
|
|
|
self.alertTransitionOver();
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
return this.container = container;
|
2010-08-23 23:34:10 -07:00
|
|
|
},
|
2009-04-08 22:13:16 -07:00
|
|
|
|
|
|
|
showAlertNotification: function ah_show(aImageURL, aTitle, aText, aTextClickable, aCookie, aListener) {
|
|
|
|
this._clickable = aTextClickable || false;
|
|
|
|
this._listener = aListener || null;
|
|
|
|
this._cookie = aCookie || "";
|
|
|
|
|
|
|
|
document.getElementById("alerts-image").setAttribute("src", aImageURL);
|
|
|
|
document.getElementById("alerts-title").value = aTitle;
|
|
|
|
document.getElementById("alerts-text").textContent = aText;
|
2010-08-23 23:34:10 -07:00
|
|
|
|
|
|
|
let container = this.container;
|
2009-04-08 22:13:16 -07:00
|
|
|
container.hidden = false;
|
2010-08-23 23:34:10 -07:00
|
|
|
container.height = container.getBoundingClientRect().height;
|
|
|
|
container.classList.add("showing");
|
2009-04-08 22:13:16 -07:00
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let timeout = Services.prefs.getIntPref("alerts.totalOpenTime");
|
2009-04-08 22:13:16 -07:00
|
|
|
let self = this;
|
2010-08-23 23:34:10 -07:00
|
|
|
if (this._timeoutID)
|
|
|
|
clearTimeout(this._timeoutID);
|
2009-04-08 22:13:16 -07:00
|
|
|
this._timeoutID = setTimeout(function() { self._timeoutAlert(); }, timeout);
|
|
|
|
},
|
2010-08-23 23:34:10 -07:00
|
|
|
|
2009-04-08 22:13:16 -07:00
|
|
|
_timeoutAlert: function ah__timeoutAlert() {
|
|
|
|
this._timeoutID = -1;
|
2010-08-23 23:34:10 -07:00
|
|
|
|
|
|
|
this.container.classList.remove("showing");
|
2009-04-08 22:13:16 -07:00
|
|
|
if (this._listener)
|
|
|
|
this._listener.observe(null, "alertfinished", this._cookie);
|
2010-08-23 23:34:10 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
alertTransitionOver: function ah_alertTransitionOver() {
|
|
|
|
let container = this.container;
|
|
|
|
if (!container.classList.contains("showing")) {
|
|
|
|
container.height = 0;
|
|
|
|
container.hidden = true;
|
|
|
|
}
|
2009-04-08 22:13:16 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
click: function ah_click(aEvent) {
|
|
|
|
if (this._clickable && this._listener)
|
|
|
|
this._listener.observe(null, "alertclickcallback", this._cookie);
|
|
|
|
|
|
|
|
if (this._timeoutID != -1) {
|
|
|
|
clearTimeout(this._timeoutID);
|
|
|
|
this._timeoutAlert();
|
|
|
|
}
|
|
|
|
}
|
2009-06-29 11:33:05 -07:00
|
|
|
};
|
2008-11-21 21:12:25 -08:00
|
|
|
|
|
|
|
function ProgressController(tab) {
|
|
|
|
this._tab = tab;
|
2009-09-10 06:24:48 -07:00
|
|
|
|
|
|
|
// Properties used to cache security state used to update the UI
|
|
|
|
this.state = null;
|
|
|
|
this._hostChanged = false; // onLocationChange will flip this bit
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
ProgressController.prototype = {
|
|
|
|
get browser() {
|
|
|
|
return this._tab.browser;
|
|
|
|
},
|
|
|
|
|
2009-08-03 20:32:17 -07:00
|
|
|
onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
|
2009-12-15 11:59:01 -08:00
|
|
|
// ignore notification that aren't about the main document (iframes, etc)
|
2010-06-09 13:07:32 -07:00
|
|
|
if (aWebProgress.windowId != this._tab.browser.contentWindowId && this._tab.browser.contentWindowId)
|
2009-12-15 11:59:01 -08:00
|
|
|
return;
|
|
|
|
|
2009-12-17 12:33:27 -08:00
|
|
|
// If you want to observe other state flags, be sure they're listed in the
|
|
|
|
// Tab._createBrowser's call to addProgressListener
|
2008-11-21 21:12:25 -08:00
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
|
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_START)
|
|
|
|
this._networkStart();
|
|
|
|
else if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP)
|
|
|
|
this._networkStop();
|
|
|
|
}
|
2010-05-21 10:00:27 -07:00
|
|
|
|
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT) {
|
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_START) {
|
|
|
|
#ifdef MOZ_CRASH_REPORTER
|
|
|
|
if (aRequest instanceof Ci.nsIChannel && CrashReporter.enabled)
|
|
|
|
CrashReporter.annotateCrashReport("URL", aRequest.URI.spec);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
|
2010-01-11 03:11:20 -08:00
|
|
|
this._documentStop();
|
|
|
|
}
|
|
|
|
}
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-09-10 06:24:48 -07:00
|
|
|
/** This method is called to indicate progress changes for the currently loading page. */
|
2009-12-15 12:37:02 -08:00
|
|
|
onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal) {
|
2009-12-17 12:33:27 -08:00
|
|
|
// To use this method, add NOTIFY_PROGRESS to the flags in Tab._createBrowser
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-09-10 06:24:48 -07:00
|
|
|
/** This method is called to indicate a change to the current location. */
|
2009-12-15 12:37:02 -08:00
|
|
|
onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI) {
|
2010-04-07 09:57:12 -07:00
|
|
|
// ignore notification that aren't about the main document (iframes, etc)
|
2010-06-09 13:07:32 -07:00
|
|
|
if (aWebProgress.windowId != this._tab.browser.contentWindowId)
|
2010-04-07 09:57:12 -07:00
|
|
|
return;
|
|
|
|
|
2010-06-04 06:15:13 -07:00
|
|
|
let spec = aLocationURI ? aLocationURI.spec : "";
|
|
|
|
let location = spec.split("#")[0]; // Ignore fragment identifier changes.
|
2009-01-16 08:07:08 -08:00
|
|
|
|
2009-11-30 12:52:25 -08:00
|
|
|
this._hostChanged = true;
|
2010-01-19 06:34:47 -08:00
|
|
|
|
2010-06-04 06:15:13 -07:00
|
|
|
if (location != this.browser.lastLocation) {
|
2010-09-17 11:48:20 -07:00
|
|
|
TapHighlightHelper.hide();
|
|
|
|
|
2010-06-04 06:15:13 -07:00
|
|
|
this.browser.lastLocation = location;
|
2009-11-30 12:19:24 -08:00
|
|
|
Browser.removeTransientNotificationsForTab(this._tab);
|
2010-01-14 12:44:28 -08:00
|
|
|
this._tab.resetZoomLevel();
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-11-30 12:19:24 -08:00
|
|
|
if (this._tab == Browser.selectedTab) {
|
|
|
|
BrowserUI.updateURI();
|
2009-12-15 12:38:44 -08:00
|
|
|
|
2010-06-04 06:15:13 -07:00
|
|
|
// We're about to have new page content, so scroll the content area
|
|
|
|
// to the top so the new paints will draw correctly.
|
|
|
|
// (background tabs are delayed scrolled to top in _documentStop)
|
|
|
|
Browser.scrollContentToTop();
|
2009-11-30 12:19:24 -08:00
|
|
|
}
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-10 06:24:48 -07:00
|
|
|
/**
|
|
|
|
* This method is called to indicate a status changes for the currently
|
|
|
|
* loading page. The message is already formatted for display.
|
|
|
|
*/
|
2009-12-15 12:37:02 -08:00
|
|
|
onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
|
2009-12-17 12:33:27 -08:00
|
|
|
// To use this method, add NOTIFY_STATUS to the flags in Tab._createBrowser
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-09-10 06:24:48 -07:00
|
|
|
/** This method is called when the security state of the browser changes. */
|
2009-12-15 12:37:02 -08:00
|
|
|
onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) {
|
2009-09-10 06:24:48 -07:00
|
|
|
// Don't need to do anything if the data we use to update the UI hasn't changed
|
|
|
|
if (this.state == aState && !this._hostChanged)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._hostChanged = false;
|
|
|
|
this.state = aState;
|
|
|
|
|
|
|
|
if (this._tab == Browser.selectedTab) {
|
|
|
|
getIdentityHandler().checkIdentity();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (aIID.equals(Ci.nsIWebProgressListener) ||
|
|
|
|
aIID.equals(Ci.nsISupportsWeakReference) ||
|
|
|
|
aIID.equals(Ci.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
2009-08-03 20:32:17 -07:00
|
|
|
_networkStart: function _networkStart() {
|
2009-08-12 17:41:31 -07:00
|
|
|
this._tab.startLoading();
|
|
|
|
|
2010-04-08 07:44:53 -07:00
|
|
|
if (this._tab == Browser.selectedTab) {
|
2008-11-21 21:12:25 -08:00
|
|
|
BrowserUI.update(TOOLBARSTATE_LOADING);
|
2009-03-05 21:42:39 -08:00
|
|
|
|
2010-04-08 07:44:53 -07:00
|
|
|
// We should at least show something in the URLBar until
|
|
|
|
// the load has progressed further along
|
|
|
|
if (this._tab.browser.currentURI.spec == "about:blank")
|
|
|
|
BrowserUI.updateURI();
|
|
|
|
}
|
|
|
|
|
2009-07-21 08:28:29 -07:00
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("URLChanged", true, false);
|
|
|
|
this.browser.dispatchEvent(event);
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-07-22 06:12:02 -07:00
|
|
|
_networkStop: function _networkStop() {
|
2009-08-12 17:41:31 -07:00
|
|
|
this._tab.endLoading();
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2010-06-14 09:59:08 -07:00
|
|
|
if (this._tab == Browser.selectedTab)
|
2008-11-21 21:12:25 -08:00
|
|
|
BrowserUI.update(TOOLBARSTATE_LOADED);
|
2009-06-16 14:04:48 -07:00
|
|
|
|
2009-11-22 20:27:31 -08:00
|
|
|
if (this.browser.currentURI.spec != "about:blank")
|
|
|
|
this._tab.updateThumbnail();
|
2010-01-11 03:11:20 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_documentStop: function _documentStop() {
|
2010-06-24 15:13:01 -07:00
|
|
|
// Make sure the URLbar is in view. If this were the selected tab,
|
|
|
|
// onLocationChange would scroll to top.
|
|
|
|
this._tab.pageScrollOffset = new Point(0, 0);
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-10-14 13:36:47 -07:00
|
|
|
var OfflineApps = {
|
2010-06-08 08:22:20 -07:00
|
|
|
offlineAppRequested: function(aRequest) {
|
2010-07-13 07:36:09 -07:00
|
|
|
if (!Services.prefs.getBoolPref("browser.offline-apps.notify"))
|
2009-10-14 13:36:47 -07:00
|
|
|
return;
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
|
2009-10-14 13:36:47 -07:00
|
|
|
|
|
|
|
// don't bother showing UI if the user has already made a decision
|
2010-07-13 07:36:09 -07:00
|
|
|
if (Services.perms.testExactPermission(currentURI, "offline-app") != Ci.nsIPermissionManager.UNKNOWN_ACTION)
|
2009-10-14 13:36:47 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
if (Services.prefs.getBoolPref("offline-apps.allow_by_default")) {
|
2009-10-14 13:36:47 -07:00
|
|
|
// all pages can use offline capabilities, no need to ask the user
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
// this pref isn't set by default, ignore failures
|
|
|
|
}
|
|
|
|
|
|
|
|
let host = currentURI.asciiHost;
|
|
|
|
let notificationID = "offline-app-requested-" + host;
|
|
|
|
let notificationBox = Browser.getNotificationBox();
|
|
|
|
|
|
|
|
let notification = notificationBox.getNotificationWithValue(notificationID);
|
2009-11-19 13:40:13 -08:00
|
|
|
let strings = Elements.browserBundle;
|
2009-10-14 13:36:47 -07:00
|
|
|
if (notification) {
|
2010-06-08 08:22:20 -07:00
|
|
|
notification.documents.push(aRequest);
|
2009-10-14 13:36:47 -07:00
|
|
|
} else {
|
|
|
|
let buttons = [{
|
2009-11-19 13:40:13 -08:00
|
|
|
label: strings.getString("offlineApps.allow"),
|
2009-10-14 13:36:47 -07:00
|
|
|
accessKey: null,
|
|
|
|
callback: function() {
|
|
|
|
for (let i = 0; i < notification.documents.length; i++)
|
|
|
|
OfflineApps.allowSite(notification.documents[i]);
|
|
|
|
}
|
|
|
|
},{
|
2009-11-19 13:40:13 -08:00
|
|
|
label: strings.getString("offlineApps.never"),
|
2009-10-14 13:36:47 -07:00
|
|
|
accessKey: null,
|
|
|
|
callback: function() {
|
|
|
|
for (let i = 0; i < notification.documents.length; i++)
|
|
|
|
OfflineApps.disallowSite(notification.documents[i]);
|
|
|
|
}
|
|
|
|
},{
|
2009-11-19 13:40:13 -08:00
|
|
|
label: strings.getString("offlineApps.notNow"),
|
2009-10-14 13:36:47 -07:00
|
|
|
accessKey: null,
|
|
|
|
callback: function() { /* noop */ }
|
|
|
|
}];
|
|
|
|
|
|
|
|
const priority = notificationBox.PRIORITY_INFO_LOW;
|
2009-11-19 13:40:13 -08:00
|
|
|
let message = strings.getFormattedString("offlineApps.available", [host]);
|
2009-10-14 13:36:47 -07:00
|
|
|
notification = notificationBox.appendNotification(message, notificationID,
|
|
|
|
"", priority, buttons);
|
2010-06-08 08:22:20 -07:00
|
|
|
notification.documents = [aRequest];
|
2009-10-14 13:36:47 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
allowSite: function(aRequest) {
|
2010-07-13 07:36:09 -07:00
|
|
|
let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
|
|
|
|
Services.perms.add(currentURI, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
|
2009-10-14 13:36:47 -07:00
|
|
|
|
|
|
|
// When a site is enabled while loading, manifest resources will start
|
|
|
|
// fetching immediately. This one time we need to do it ourselves.
|
2010-06-08 08:22:20 -07:00
|
|
|
this._startFetching(aRequest);
|
2009-10-14 13:36:47 -07:00
|
|
|
},
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
disallowSite: function(aRequest) {
|
2010-07-13 07:36:09 -07:00
|
|
|
let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
|
|
|
|
Services.perms.add(currentURI, "offline-app", Ci.nsIPermissionManager.DENY_ACTION);
|
2009-10-14 13:36:47 -07:00
|
|
|
},
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
_startFetching: function(aRequest) {
|
2010-07-13 07:36:09 -07:00
|
|
|
let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
|
|
|
|
let manifestURI = Services.io.newURI(aRequest.manifest, aRequest.charset, currentURI);
|
2009-10-14 13:36:47 -07:00
|
|
|
|
|
|
|
let updateService = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(Ci.nsIOfflineCacheUpdateService);
|
2010-06-08 08:22:20 -07:00
|
|
|
updateService.scheduleUpdate(manifestURI, currentURI);
|
2009-10-14 13:36:47 -07:00
|
|
|
},
|
|
|
|
|
2010-06-09 19:12:05 -07:00
|
|
|
receiveMessage: function receiveMessage(aMessage) {
|
2010-06-11 07:23:24 -07:00
|
|
|
if (aMessage.name == "Browser:MozApplicationManifest") {
|
2010-06-08 08:22:20 -07:00
|
|
|
this.offlineAppRequested(aMessage.json);
|
|
|
|
}
|
2009-10-14 13:36:47 -07:00
|
|
|
}
|
|
|
|
};
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2010-09-15 03:41:31 -07:00
|
|
|
function Tab(aURI, aParams) {
|
2009-08-11 13:51:13 -07:00
|
|
|
this._id = null;
|
|
|
|
this._browser = null;
|
|
|
|
this._state = null;
|
|
|
|
this._listener = null;
|
|
|
|
this._loading = false;
|
|
|
|
this._chromeTab = null;
|
2010-09-22 10:31:11 -07:00
|
|
|
this._metadata = null;
|
2010-06-15 14:56:13 -07:00
|
|
|
this.owner = null;
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
// Set to 0 since new tabs that have not been viewed yet are good tabs to
|
|
|
|
// toss if app needs more memory.
|
|
|
|
this.lastSelected = 0;
|
|
|
|
|
2010-09-15 03:41:31 -07:00
|
|
|
// aParams is an object that contains some properties for the initial tab
|
|
|
|
// loading like flags, a referrerURI, a charset or even a postData.
|
|
|
|
this.create(aURI, aParams || {});
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Tab.prototype = {
|
|
|
|
get browser() {
|
|
|
|
return this._browser;
|
|
|
|
},
|
|
|
|
|
2009-06-04 07:57:56 -07:00
|
|
|
get chromeTab() {
|
|
|
|
return this._chromeTab;
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2010-09-22 10:31:11 -07:00
|
|
|
get metadata() {
|
|
|
|
return this._metadata || kDefaultMetadata;
|
|
|
|
},
|
2010-05-05 12:51:58 -07:00
|
|
|
|
2010-09-22 10:31:11 -07:00
|
|
|
/** Update browser styles when the viewport metadata changes. */
|
|
|
|
updateViewportMetadata: function updateViewportMetadata(aMetadata) {
|
|
|
|
this._metadata = aMetadata;
|
2010-05-05 12:51:58 -07:00
|
|
|
this.updateViewportSize();
|
|
|
|
},
|
|
|
|
|
2010-09-23 14:20:44 -07:00
|
|
|
/**
|
|
|
|
* Update browser size when the metadata or the window size changes.
|
|
|
|
* If the window size changes, aRatio = (new width / old width).
|
|
|
|
*/
|
|
|
|
updateViewportSize: function updateViewportSize(aRatio) {
|
2010-05-05 12:51:58 -07:00
|
|
|
let browser = this._browser;
|
2010-05-27 13:01:41 -07:00
|
|
|
if (!browser)
|
2010-05-05 12:51:58 -07:00
|
|
|
return;
|
|
|
|
|
2010-09-23 14:20:44 -07:00
|
|
|
let screenW = window.innerWidth;
|
|
|
|
let screenH = window.innerHeight;
|
|
|
|
|
2010-09-22 10:31:11 -07:00
|
|
|
let metadata = this.metadata;
|
|
|
|
if (!metadata.autoSize) {
|
|
|
|
let viewportW = metadata.width;
|
|
|
|
let viewportH = metadata.height;
|
2010-05-05 12:51:58 -07:00
|
|
|
|
|
|
|
// If (scale * width) < device-width, increase the width (bug 561413).
|
2010-09-22 10:31:11 -07:00
|
|
|
let maxInitialZoom = metadata.defaultZoom || metadata.maxZoom;
|
2010-05-05 12:51:58 -07:00
|
|
|
if (maxInitialZoom && viewportW)
|
|
|
|
viewportW = Math.max(viewportW, screenW / maxInitialZoom);
|
|
|
|
|
|
|
|
let validW = viewportW > 0;
|
|
|
|
let validH = viewportH > 0;
|
|
|
|
|
|
|
|
if (validW && !validH) {
|
|
|
|
viewportH = viewportW * (screenH / screenW);
|
|
|
|
} else if (!validW && validH) {
|
|
|
|
viewportW = viewportH * (screenW / screenH);
|
|
|
|
} else {
|
|
|
|
viewportW = kDefaultBrowserWidth;
|
|
|
|
viewportH = kDefaultBrowserWidth * (screenH / screenW);
|
|
|
|
}
|
|
|
|
|
2010-09-15 15:05:50 -07:00
|
|
|
browser.setWindowSize(viewportW, viewportH);
|
2010-09-23 14:20:44 -07:00
|
|
|
|
|
|
|
if (aRatio) {
|
|
|
|
let pos = browser.getPosition();
|
|
|
|
|
|
|
|
// zoom to keep the same portion of the document visible
|
|
|
|
let oldScale = browser.scale;
|
|
|
|
let newScale = this.clampZoomLevel(oldScale * aRatio);
|
|
|
|
browser.scale = newScale;
|
|
|
|
|
|
|
|
// ...and keep the same top-left corner of the visible rect
|
|
|
|
let scaleRatio = newScale / oldScale;
|
|
|
|
browser.scrollTo(pos.x * scaleRatio, pos.y * scaleRatio);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let w = screenW;
|
|
|
|
let h = screenH;
|
2010-09-22 10:31:11 -07:00
|
|
|
if (metadata.defaultZoom != 1.0) {
|
2010-08-27 15:01:32 -07:00
|
|
|
let dpiScale = Services.prefs.getIntPref("zoom.dpiScale") / 100;
|
|
|
|
w /= dpiScale;
|
|
|
|
h /= dpiScale;
|
|
|
|
}
|
|
|
|
|
2010-09-15 15:05:50 -07:00
|
|
|
browser.setWindowSize(w, h);
|
2010-05-05 12:51:58 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
startLoading: function startLoading() {
|
2009-12-15 11:59:01 -08:00
|
|
|
if (this._loading) throw "Already Loading!";
|
2009-08-12 17:41:31 -07:00
|
|
|
this._loading = true;
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
endLoading: function endLoading() {
|
2009-12-15 11:59:01 -08:00
|
|
|
if (!this._loading) throw "Not Loading!";
|
2009-08-12 17:41:31 -07:00
|
|
|
this._loading = false;
|
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
isLoading: function isLoading() {
|
2009-08-12 17:41:31 -07:00
|
|
|
return this._loading;
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2010-09-15 03:41:31 -07:00
|
|
|
create: function create(aURI, aParams) {
|
2009-09-09 20:32:13 -07:00
|
|
|
this._chromeTab = document.getElementById("tabs").addTab();
|
2010-09-15 03:41:31 -07:00
|
|
|
let browser = this._createBrowser(aURI);
|
|
|
|
|
|
|
|
// Attach a separate progress listener to the browser
|
|
|
|
let flags = Ci.nsIWebProgress.NOTIFY_LOCATION |
|
|
|
|
Ci.nsIWebProgress.NOTIFY_SECURITY |
|
|
|
|
Ci.nsIWebProgress.NOTIFY_STATE_NETWORK |
|
|
|
|
Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT;
|
|
|
|
this._listener = new ProgressController(this);
|
|
|
|
browser.webProgress.addProgressListener(this._listener, flags);
|
|
|
|
|
|
|
|
let flags = aParams.flags || Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
|
|
|
browser.loadURIWithFlags(aURI, flags, aParams.referrerURI, aParams.charset, aParams.postData);
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
destroy: function destroy() {
|
2009-06-04 07:57:56 -07:00
|
|
|
document.getElementById("tabs").removeTab(this._chromeTab);
|
|
|
|
this._chromeTab = null;
|
2009-12-15 12:37:02 -08:00
|
|
|
this._destroyBrowser();
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2010-06-17 09:27:26 -07:00
|
|
|
_createBrowser: function _createBrowser(aURI) {
|
2008-11-21 21:12:25 -08:00
|
|
|
if (this._browser)
|
|
|
|
throw "Browser already exists";
|
|
|
|
|
2009-06-04 07:57:56 -07:00
|
|
|
// Create the browser using the current width the dynamically size the height
|
2008-11-21 21:12:25 -08:00
|
|
|
let browser = this._browser = document.createElement("browser");
|
2010-08-27 15:01:32 -07:00
|
|
|
browser.setAttribute("class", "window-width window-height");
|
2010-07-18 22:27:52 -07:00
|
|
|
this._chromeTab.linkedBrowser = browser;
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-06-04 07:57:56 -07:00
|
|
|
browser.setAttribute("type", "content");
|
2010-06-16 07:47:13 -07:00
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let useRemote = Services.prefs.getBoolPref("browser.tabs.remote");
|
2010-07-02 10:48:46 -07:00
|
|
|
let useLocal = Util.isLocalScheme(aURI);
|
2010-06-17 09:27:26 -07:00
|
|
|
browser.setAttribute("remote", (!useLocal && useRemote) ? "true" : "false");
|
2010-08-12 20:22:00 -07:00
|
|
|
|
2009-06-04 07:57:56 -07:00
|
|
|
// Append the browser to the document, which should start the page load
|
2008-11-21 21:12:25 -08:00
|
|
|
document.getElementById("browsers").appendChild(browser);
|
2010-09-23 10:07:28 -07:00
|
|
|
browser.style.display = "none";
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-07-22 06:12:02 -07:00
|
|
|
// stop about:blank from loading
|
|
|
|
browser.stop();
|
|
|
|
|
2010-09-27 08:11:56 -07:00
|
|
|
|
2010-08-27 16:25:53 -07:00
|
|
|
let self = this;
|
|
|
|
browser.messageManager.addMessageListener("MozScrolledAreaChanged", function() {
|
|
|
|
self.updateDefaultZoomLevel();
|
|
|
|
});
|
2010-09-15 14:11:37 -07:00
|
|
|
|
|
|
|
return browser;
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
_destroyBrowser: function _destroyBrowser() {
|
2009-09-04 22:14:59 -07:00
|
|
|
if (this._browser) {
|
2009-12-15 12:37:02 -08:00
|
|
|
var browser = this._browser;
|
|
|
|
browser.removeProgressListener(this._listener);
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
this._browser = null;
|
2009-12-15 12:37:02 -08:00
|
|
|
this._listener = null;
|
2009-12-10 09:55:27 -08:00
|
|
|
this._loading = false;
|
2009-12-15 11:59:01 -08:00
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
Util.executeSoon(function() {
|
|
|
|
document.getElementById("browsers").removeChild(browser);
|
2010-01-14 13:08:40 -08:00
|
|
|
});
|
2009-09-04 22:14:59 -07:00
|
|
|
}
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2010-08-27 16:25:53 -07:00
|
|
|
clampZoomLevel: function clampZoomLevel(zl) {
|
|
|
|
let browser = this._browser;
|
2010-08-30 14:11:49 -07:00
|
|
|
let bounded = Math.min(Math.max(ZoomManager.MIN, zl), ZoomManager.MAX);
|
2010-08-27 16:25:53 -07:00
|
|
|
|
2010-09-22 10:31:11 -07:00
|
|
|
let md = this.metadata;
|
2010-08-30 14:11:49 -07:00
|
|
|
if (md && md.minZoom)
|
|
|
|
bounded = Math.max(bounded, md.minZoom);
|
|
|
|
if (md && md.maxZoom)
|
|
|
|
bounded = Math.min(bounded, md.maxZoom);
|
2010-08-27 16:25:53 -07:00
|
|
|
|
2010-08-30 14:11:49 -07:00
|
|
|
bounded = Math.max(bounded, this.getPageZoomLevel());
|
2010-08-27 16:25:53 -07:00
|
|
|
|
2010-08-30 14:11:49 -07:00
|
|
|
let rounded = Math.round(bounded * kBrowserViewZoomLevelPrecision) / kBrowserViewZoomLevelPrecision;
|
|
|
|
return rounded || 1.0;
|
2010-08-27 16:25:53 -07:00
|
|
|
},
|
|
|
|
|
2010-09-15 15:05:50 -07:00
|
|
|
/** Record the initial zoom level when a page first loads. */
|
2010-01-14 12:44:28 -08:00
|
|
|
resetZoomLevel: function resetZoomLevel() {
|
2010-09-15 15:05:50 -07:00
|
|
|
this._defaultZoomLevel = this._browser.scale;
|
2010-08-27 16:25:53 -07:00
|
|
|
},
|
2010-08-27 15:01:32 -07:00
|
|
|
|
2010-08-27 16:25:53 -07:00
|
|
|
/**
|
2010-09-15 15:05:50 -07:00
|
|
|
* Recalculate default zoom level when page size changes, and update zoom
|
|
|
|
* level if we are at default.
|
2010-08-27 16:25:53 -07:00
|
|
|
*/
|
|
|
|
updateDefaultZoomLevel: function updateDefaultZoomLevel() {
|
|
|
|
let browser = this._browser;
|
2010-09-28 14:16:01 -07:00
|
|
|
if (!browser)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let isDefault = this.isDefaultZoomLevel();
|
2010-08-30 14:11:49 -07:00
|
|
|
this._defaultZoomLevel = this.getDefaultZoomLevel();
|
|
|
|
if (isDefault)
|
2010-09-15 15:05:50 -07:00
|
|
|
browser.scale = this._defaultZoomLevel;
|
2010-08-30 14:11:49 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
isDefaultZoomLevel: function isDefaultZoomLevel() {
|
2010-09-15 15:05:50 -07:00
|
|
|
return this._browser.scale == this._defaultZoomLevel;
|
2010-08-27 16:25:53 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultZoomLevel: function getDefaultZoomLevel() {
|
2010-09-22 10:31:11 -07:00
|
|
|
let md = this.metadata;
|
2010-08-27 16:25:53 -07:00
|
|
|
if (md && md.defaultZoom)
|
|
|
|
return this.clampZoomLevel(md.defaultZoom);
|
|
|
|
|
|
|
|
let pageZoom = this.getPageZoomLevel();
|
|
|
|
|
|
|
|
// If pageZoom is "almost" 100%, zoom in to exactly 100% (bug 454456).
|
|
|
|
let granularity = Services.prefs.getIntPref("browser.ui.zoom.pageFitGranularity");
|
|
|
|
let threshold = 1 - 1 / granularity;
|
|
|
|
if (threshold < pageZoom && pageZoom < 1)
|
|
|
|
pageZoom = 1;
|
|
|
|
|
|
|
|
return this.clampZoomLevel(pageZoom);
|
|
|
|
},
|
|
|
|
|
|
|
|
getPageZoomLevel: function getPageZoomLevel() {
|
2010-09-15 15:05:50 -07:00
|
|
|
let browserW = this._browser.contentDocumentWidth;
|
2010-08-27 16:25:53 -07:00
|
|
|
return this._browser.getBoundingClientRect().width / browserW;
|
2010-01-14 12:44:28 -08:00
|
|
|
},
|
|
|
|
|
2010-08-30 14:11:49 -07:00
|
|
|
get allowZoom() {
|
2010-09-22 10:31:11 -07:00
|
|
|
return this.metadata.allowZoom;
|
2010-08-30 14:11:49 -07:00
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
updateThumbnail: function updateThumbnail() {
|
2010-09-24 17:41:10 -07:00
|
|
|
let browser = this._browser;
|
|
|
|
|
|
|
|
// Do not repaint thumbnail if we already painted for this load. Bad things
|
|
|
|
// happen when we do async canvas draws in quick succession.
|
|
|
|
if (!browser || this._thumbnailWindowId == browser.contentWindowId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Do not try to paint thumbnails if contentWindowWidth/Height have not been
|
|
|
|
// set yet. This also blows up for async canvas draws.
|
|
|
|
if (!browser.contentWindowWidth || !browser.contentWindowHeight)
|
2008-11-21 21:12:25 -08:00
|
|
|
return;
|
|
|
|
|
2010-09-24 17:41:10 -07:00
|
|
|
this._thumbnailWindowId = browser.contentWindowId;
|
|
|
|
this._chromeTab.updateThumbnail(browser, browser.contentWindowWidth, browser.contentWindowHeight);
|
2009-09-04 22:14:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
toString: function() {
|
2010-06-23 12:23:06 -07:00
|
|
|
return "[Tab " + (this._browser ? this._browser.currentURI.spec : "(no browser)") + "]";
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
2009-06-29 11:33:05 -07:00
|
|
|
};
|
2010-09-03 13:23:55 -07:00
|
|
|
|
|
|
|
// Helper used to hide IPC / non-IPC differences for rendering to a canvas
|
|
|
|
function rendererFactory(aBrowser, aCanvas) {
|
|
|
|
let wrapper = {};
|
|
|
|
|
|
|
|
if (aBrowser.contentWindow) {
|
|
|
|
let ctx = aCanvas.getContext("2d");
|
|
|
|
let draw = function(browser, aLeft, aTop, aWidth, aHeight, aColor, aFlags) {
|
|
|
|
ctx.drawWindow(browser.contentWindow, aLeft, aTop, aWidth, aHeight, aColor, aFlags);
|
|
|
|
let e = document.createEvent("HTMLEvents");
|
|
|
|
e.initEvent("MozAsyncCanvasRender", true, true);
|
|
|
|
aCanvas.dispatchEvent(e);
|
|
|
|
};
|
|
|
|
wrapper.checkBrowser = function(browser) {
|
|
|
|
return browser.contentWindow;
|
|
|
|
};
|
|
|
|
wrapper.drawContent = function(callback) {
|
|
|
|
callback(ctx, draw);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let ctx = aCanvas.MozGetIPCContext("2d");
|
|
|
|
let draw = function(browser, aLeft, aTop, aWidth, aHeight, aColor, aFlags) {
|
|
|
|
ctx.asyncDrawXULElement(browser, aLeft, aTop, aWidth, aHeight, aColor, aFlags);
|
|
|
|
};
|
|
|
|
wrapper.checkBrowser = function(browser) {
|
|
|
|
return !browser.contentWindow;
|
|
|
|
};
|
|
|
|
wrapper.drawContent = function(callback) {
|
|
|
|
callback(ctx, draw);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
}
|