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>
|
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
|
|
|
|
2009-09-04 10:44:55 -07:00
|
|
|
const kDefaultBrowserWidth = 800;
|
2009-03-05 21:42:39 -08:00
|
|
|
|
2010-03-11 06:18:41 -08:00
|
|
|
// how many milliseconds before the mousedown and the overlay of an element
|
|
|
|
const kTapOverlayTimeout = 200;
|
|
|
|
|
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-07-17 16:17:57 -07:00
|
|
|
function debug() {
|
|
|
|
let bv = Browser._browserView;
|
|
|
|
let tc = bv._tileManager._tileCache;
|
2009-10-20 06:36:26 -07:00
|
|
|
let scrollbox = document.getElementById("content-scrollbox")
|
2009-09-14 22:56:18 -07:00
|
|
|
.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-07-20 13:48:26 -07:00
|
|
|
let x = {};
|
|
|
|
let y = {};
|
2009-07-17 16:17:57 -07:00
|
|
|
let w = {};
|
|
|
|
let h = {};
|
2009-07-20 13:48:26 -07:00
|
|
|
scrollbox.getPosition(x, y);
|
2009-07-17 16:17:57 -07:00
|
|
|
scrollbox.getScrolledSize(w, h);
|
2009-07-20 13:48:26 -07:00
|
|
|
let container = document.getElementById("tile-container");
|
|
|
|
let [x, y] = [x.value, y.value];
|
2009-07-17 16:17:57 -07:00
|
|
|
let [w, h] = [w.value, h.value];
|
|
|
|
if (bv) {
|
|
|
|
dump('----------------------DEBUG!-------------------------\n');
|
|
|
|
dump(bv._browserViewportState.toString() + endl);
|
|
|
|
|
|
|
|
dump(endl);
|
|
|
|
|
2009-08-03 20:32:17 -07:00
|
|
|
dump('location from Browser: ' + Browser.selectedBrowser.contentWindow.location + endl);
|
|
|
|
dump('location from BV : ' + bv.getBrowser().contentWindow.location + endl);
|
|
|
|
|
|
|
|
dump(endl + endl);
|
|
|
|
|
2009-07-17 16:17:57 -07:00
|
|
|
let cr = bv._tileManager._criticalRect;
|
|
|
|
dump('criticalRect from BV: ' + (cr ? cr.toString() : null) + endl);
|
2009-08-11 13:51:13 -07:00
|
|
|
dump('visibleRect from BV : ' + bv.getVisibleRect().toString() + endl);
|
2009-07-28 16:14:57 -07:00
|
|
|
dump('visibleRect from foo: ' + Browser.getVisibleRect().toString() + endl);
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-07-30 17:31:09 -07:00
|
|
|
dump('bv batchops depth: ' + bv._batchOps.length + endl);
|
2009-07-27 19:04:22 -07:00
|
|
|
dump('renderpause depth: ' + bv._renderMode + endl);
|
2009-07-17 16:17:57 -07:00
|
|
|
|
|
|
|
dump(endl);
|
|
|
|
|
2009-07-30 17:31:09 -07:00
|
|
|
dump('window.innerWidth : ' + window.innerWidth + endl);
|
|
|
|
dump('window.innerHeight: ' + window.innerHeight + endl);
|
2009-07-28 16:14:57 -07:00
|
|
|
|
|
|
|
dump(endl);
|
|
|
|
|
2009-07-17 16:17:57 -07:00
|
|
|
dump('container width,height from BV: ' + bv._container.style.width + ', '
|
|
|
|
+ bv._container.style.height + endl);
|
|
|
|
dump('container width,height via DOM: ' + container.style.width + ', '
|
|
|
|
+ container.style.height + endl);
|
|
|
|
|
|
|
|
dump(endl);
|
|
|
|
|
|
|
|
dump('scrollbox position : ' + x + ', ' + y + endl);
|
|
|
|
dump('scrollbox scrolledsize: ' + w + ', ' + h + endl);
|
|
|
|
|
2009-07-20 13:48:26 -07:00
|
|
|
|
2009-10-20 06:36:26 -07:00
|
|
|
let sb = document.getElementById("content-scrollbox");
|
2009-07-20 13:48:26 -07:00
|
|
|
dump('container location: ' + Math.round(container.getBoundingClientRect().left) + " " +
|
|
|
|
Math.round(container.getBoundingClientRect().top) + endl);
|
|
|
|
|
2009-08-03 09:44:17 -07:00
|
|
|
dump(endl);
|
2009-07-20 13:48:26 -07:00
|
|
|
|
2009-08-03 09:44:17 -07:00
|
|
|
let mouseModule = ih._modules[0];
|
|
|
|
dump('ih grabber : ' + ih._grabber + endl);
|
|
|
|
dump('ih grabdepth: ' + ih._grabDepth + endl);
|
|
|
|
dump('ih listening: ' + !ih._ignoreEvents + endl);
|
|
|
|
dump('ih suppress : ' + ih._suppressNextClick + endl);
|
|
|
|
dump('mouseModule : ' + mouseModule + endl);
|
2009-07-20 13:48:26 -07:00
|
|
|
|
2009-07-17 16:17:57 -07:00
|
|
|
dump(endl);
|
|
|
|
|
|
|
|
dump('tilecache capacity: ' + bv._tileManager._tileCache.getCapacity() + endl);
|
|
|
|
dump('tilecache size : ' + bv._tileManager._tileCache.size + endl);
|
|
|
|
dump('tilecache iBound : ' + bv._tileManager._tileCache.iBound + endl);
|
|
|
|
dump('tilecache jBound : ' + bv._tileManager._tileCache.jBound + endl);
|
|
|
|
|
|
|
|
dump('-----------------------------------------------------\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function debugTile(i, j) {
|
|
|
|
let bv = Browser._browserView;
|
|
|
|
let tc = bv._tileManager._tileCache;
|
|
|
|
let t = tc.getTile(i, j);
|
|
|
|
|
|
|
|
dump('------ DEBUGGING TILE (' + i + ',' + j + ') --------\n');
|
|
|
|
|
|
|
|
dump('in bounds: ' + tc.inBounds(i, j) + endl);
|
2009-07-30 17:31:09 -07:00
|
|
|
dump('occupied : ' + tc.isOccupied(i, j) + endl);
|
2009-07-17 16:17:57 -07:00
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
dump('toString : ' + t.toString(true) + endl);
|
|
|
|
dump('free : ' + t.free + endl);
|
|
|
|
dump('dirtyRect: ' + t._dirtyTileCanvasRect + endl);
|
|
|
|
|
|
|
|
let len = tc._tilePool.length;
|
|
|
|
for (let k = 0; k < len; ++k)
|
|
|
|
if (tc._tilePool[k] === t)
|
|
|
|
dump('found in tilePool at index ' + k + endl);
|
|
|
|
}
|
|
|
|
|
|
|
|
dump('------------------------------------\n');
|
|
|
|
}
|
|
|
|
|
2009-08-17 11:16:11 -07:00
|
|
|
function onDebugKeyPress(ev) {
|
2009-07-17 16:17:57 -07:00
|
|
|
let bv = Browser._browserView;
|
|
|
|
|
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
|
|
|
|
2009-08-17 11:16:11 -07:00
|
|
|
const a = 65; // debug all critical tiles
|
|
|
|
const b = 66; // dump an ASCII graphic of the tile map
|
2010-01-14 13:35:08 -08:00
|
|
|
const c = 67;
|
2009-08-17 11:16:11 -07:00
|
|
|
const d = 68; // debug dump
|
|
|
|
const e = 69;
|
2009-09-04 22:14:59 -07:00
|
|
|
const f = 70; // free memory by clearing a tab.
|
2009-08-17 11:16:11 -07:00
|
|
|
const g = 71;
|
|
|
|
const h = 72;
|
|
|
|
const i = 73; // toggle info click mode
|
|
|
|
const j = 74;
|
|
|
|
const k = 75;
|
|
|
|
const l = 76; // restart lazy crawl
|
|
|
|
const m = 77; // fix mouseout
|
|
|
|
const n = 78;
|
2010-05-06 06:21:26 -07:00
|
|
|
const o = 79;
|
2009-08-17 11:16:11 -07:00
|
|
|
const p = 80; // debug tiles in pool order
|
2010-05-06 06:21:26 -07:00
|
|
|
const q = 81; // toggle orientation
|
2009-08-17 11:16:11 -07:00
|
|
|
const r = 82; // reset visible rect
|
|
|
|
const s = 83;
|
|
|
|
const t = 84; // debug given list of tiles separated by space
|
|
|
|
const u = 85;
|
|
|
|
const v = 86;
|
|
|
|
const w = 87;
|
|
|
|
const x = 88;
|
|
|
|
const y = 89;
|
|
|
|
const z = 90; // set zoom level to 1
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-07-30 17:31:09 -07:00
|
|
|
if (window.tileMapMode) {
|
|
|
|
function putChar(ev, col, row) {
|
|
|
|
let tile = tc.getTile(col, row);
|
|
|
|
switch (ev.charCode) {
|
|
|
|
case h: // held tiles
|
|
|
|
dump(tile ? (tile.free ? '*' : 'h') : ' ');
|
|
|
|
break;
|
|
|
|
case d: // dirty tiles
|
|
|
|
dump(tile ? (tile.isDirty() ? 'd' : '*') : ' ');
|
|
|
|
break;
|
|
|
|
case o: // occupied tileholders
|
|
|
|
dump(tc.isOccupied(col, row) ? 'o' : ' ');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let tc = Browser._browserView._tileManager._tileCache;
|
|
|
|
let col, row;
|
|
|
|
|
|
|
|
dump(endl);
|
|
|
|
|
|
|
|
dump(' ');
|
|
|
|
for (col = 0; col < tc.iBound; ++col)
|
|
|
|
dump(col % 10);
|
|
|
|
|
|
|
|
dump(endl);
|
|
|
|
|
|
|
|
for (row = 0; row < tc.jBound; ++row) {
|
|
|
|
|
|
|
|
dump((row % 10) + ' ');
|
|
|
|
|
|
|
|
for (col = 0; col < tc.iBound; ++col) {
|
|
|
|
putChar(ev, col, row);
|
|
|
|
}
|
|
|
|
|
|
|
|
dump(endl);
|
|
|
|
}
|
|
|
|
dump(endl + endl);
|
|
|
|
|
|
|
|
for (let ii = 0; ii < tc._tilePool.length; ++ii) {
|
|
|
|
let tile = tc._tilePool[ii];
|
|
|
|
putChar(ev, tile.i, tile.j);
|
|
|
|
}
|
|
|
|
|
|
|
|
dump(endl + endl);
|
|
|
|
|
|
|
|
window.tileMapMode = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ev.charCode) {
|
2009-09-04 22:14:59 -07:00
|
|
|
case f:
|
|
|
|
var result = Browser.sacrificeTab();
|
|
|
|
if (result)
|
|
|
|
dump("Freed a tab\n");
|
|
|
|
else
|
|
|
|
dump("There are no tabs left to free\n");
|
|
|
|
break;
|
|
|
|
|
2009-07-20 13:48:26 -07:00
|
|
|
case r:
|
2009-08-10 18:03:42 -07:00
|
|
|
bv.onAfterVisibleMove();
|
|
|
|
//bv.setVisibleRect(Browser.getVisibleRect());
|
2009-07-20 13:48:26 -07:00
|
|
|
|
2009-07-17 16:17:57 -07:00
|
|
|
case d:
|
|
|
|
debug();
|
|
|
|
|
|
|
|
break;
|
|
|
|
case l:
|
|
|
|
bv._tileManager.restartLazyCrawl(bv._tileManager._criticalRect);
|
|
|
|
|
|
|
|
break;
|
2009-07-30 17:31:09 -07:00
|
|
|
case b:
|
|
|
|
window.tileMapMode = true;
|
2009-07-17 16:17:57 -07:00
|
|
|
break;
|
|
|
|
case t:
|
|
|
|
let ijstrs = window.prompt('row,col plz').split(' ');
|
|
|
|
for each (let ijstr in ijstrs) {
|
2009-07-21 12:28:30 -07:00
|
|
|
let [i, j] = ijstr.split(',').map(function (x) { return parseInt(x); });
|
2009-07-17 16:17:57 -07:00
|
|
|
debugTile(i, j);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case a:
|
|
|
|
let cr = bv._tileManager._criticalRect;
|
2009-07-28 16:14:57 -07:00
|
|
|
dump('>>>>>> critical rect is ' + (cr ? cr.toString() : cr) + '\n');
|
2009-07-17 16:17:57 -07:00
|
|
|
if (cr) {
|
|
|
|
let starti = cr.left >> kTileExponentWidth;
|
|
|
|
let endi = cr.right >> kTileExponentWidth;
|
|
|
|
|
|
|
|
let startj = cr.top >> kTileExponentHeight;
|
|
|
|
let endj = cr.bottom >> kTileExponentHeight;
|
|
|
|
|
|
|
|
for (var jj = startj; jj <= endj; ++jj)
|
|
|
|
for (var ii = starti; ii <= endi; ++ii)
|
|
|
|
debugTile(ii, jj);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case i:
|
|
|
|
window.infoMode = !window.infoMode;
|
|
|
|
break;
|
|
|
|
case m:
|
2009-12-10 10:17:39 -08:00
|
|
|
Util.dumpLn("renderMode:", bv._renderMode);
|
|
|
|
Util.dumpLn("batchOps:",bv._batchOps.length);
|
2009-07-29 13:27:42 -07:00
|
|
|
bv.resumeRendering();
|
2009-07-17 16:17:57 -07:00
|
|
|
break;
|
2009-07-30 17:31:09 -07:00
|
|
|
case p:
|
|
|
|
let tc = bv._tileManager._tileCache;
|
|
|
|
dump('************* TILE POOL ****************\n');
|
|
|
|
for (let ii = 0, len = tc._tilePool.length; ii < len; ++ii) {
|
|
|
|
if (window.infoMode)
|
|
|
|
debugTile(tc._tilePool[ii].i, tc._tilePool[ii].j);
|
|
|
|
else
|
|
|
|
dump(tc._tilePool[ii].i + ',' + tc._tilePool[ii].j + '\n');
|
|
|
|
}
|
|
|
|
dump('****************************************\n');
|
|
|
|
break;
|
2010-05-06 06:21:26 -07:00
|
|
|
#ifndef MOZ_PLATFORM_MAEMO
|
|
|
|
case q:
|
|
|
|
if (Util.isPortrait())
|
|
|
|
window.top.resizeTo(800,480);
|
|
|
|
else
|
|
|
|
window.top.resizeTo(480,800);
|
|
|
|
break;
|
|
|
|
#endif
|
2009-07-29 15:44:41 -07:00
|
|
|
case z:
|
|
|
|
bv.setZoomLevel(1.0);
|
|
|
|
break;
|
2009-07-17 16:17:57 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-07-30 17:31:09 -07:00
|
|
|
window.infoMode = false;
|
|
|
|
window.tileMapMode = false;
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-07-21 12:28:30 -07:00
|
|
|
var ih = null;
|
2009-07-20 18:32:52 -07:00
|
|
|
|
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
|
|
|
contentScrollbox: null,
|
|
|
|
contentScrollboxScroller: null,
|
|
|
|
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-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-01-05 15:12:04 -08:00
|
|
|
let needOverride = Util.needHomepageOverride();
|
|
|
|
if (needOverride == "new profile")
|
|
|
|
this.initNewProfile();
|
|
|
|
|
2009-07-20 13:48:26 -07:00
|
|
|
let container = document.getElementById("tile-container");
|
2009-08-10 18:03:42 -07:00
|
|
|
let bv = this._browserView = new BrowserView(container, Browser.getVisibleRect);
|
2009-06-19 14:25:42 -07:00
|
|
|
|
2009-08-07 18:08:06 -07:00
|
|
|
/* handles dispatching clicks on tiles into clicks in content or zooms */
|
2009-09-01 20:39:39 -07:00
|
|
|
container.customClicker = new ContentCustomClicker(bv);
|
2009-07-24 15:51:16 -07:00
|
|
|
|
2009-10-14 14:19:29 -07:00
|
|
|
/* scrolling box that contains tiles */
|
2009-10-20 06:36:26 -07:00
|
|
|
let contentScrollbox = this.contentScrollbox = document.getElementById("content-scrollbox");
|
2009-08-05 14:06:38 -07:00
|
|
|
this.contentScrollboxScroller = contentScrollbox.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
2009-08-07 18:08:06 -07:00
|
|
|
contentScrollbox.customDragger = new Browser.MainDragger(bv);
|
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 = {
|
2009-11-10 07:48:37 -08:00
|
|
|
isDraggable: function isDraggable(target, content) { return false; },
|
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-03-03 15:10:24 -08:00
|
|
|
// during startup a lot of viewportHandler calls happen due to content and window resizes
|
2009-07-17 16:17:57 -07:00
|
|
|
bv.beginBatchOperation();
|
2009-06-24 09:42:53 -07:00
|
|
|
|
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-07-22 06:12:02 -07:00
|
|
|
// XXX is this code right here actually needed?
|
2009-03-03 11:20:00 -08:00
|
|
|
let w = window.innerWidth;
|
2009-08-04 16:13:28 -07:00
|
|
|
let h = window.innerHeight;
|
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-07-17 16:17:57 -07:00
|
|
|
bv.beginBatchOperation();
|
|
|
|
|
2009-08-05 13:28:43 -07:00
|
|
|
let toolbarHeight = Math.round(document.getElementById("toolbar-main").getBoundingClientRect().height);
|
2009-10-14 14:19:29 -07:00
|
|
|
let scaledDefaultH = (kDefaultBrowserWidth * (h / w));
|
|
|
|
let scaledScreenH = (window.screen.width * (h / w));
|
2010-05-05 12:51:55 -07:00
|
|
|
let dpiScale = gPrefService.getIntPref("zoom.dpiScale") / 100;
|
2009-08-04 16:13:28 -07:00
|
|
|
|
2010-05-05 12:51:55 -07:00
|
|
|
Browser.styles["viewport-width"].width = (w / dpiScale) + "px";
|
|
|
|
Browser.styles["viewport-height"].height = (h / dpiScale) + "px";
|
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
|
|
|
// Cause a resize of the viewport if the current browser holds a XUL document
|
|
|
|
let browser = Browser.selectedBrowser;
|
|
|
|
if (browser.contentDocument instanceof XULDocument)
|
|
|
|
BrowserView.Util.ensureMozScrolledAreaEvent(browser, w, h);
|
|
|
|
|
|
|
|
// 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-04-13 13:10:54 -07:00
|
|
|
// XXX During the launch, the resize of the window arrive after we add
|
|
|
|
// the first tab, so we need to force the viewport state for this case
|
|
|
|
// see bug 558840
|
|
|
|
let bvs = bv._browserViewportState;
|
|
|
|
if (bvs.viewportRect.width == 1 && bvs.viewportRect.height == 1) {
|
|
|
|
bvs.viewportRect.width = window.innerWidth;
|
|
|
|
bvs.viewportRect.height = window.innerHeight;
|
|
|
|
}
|
|
|
|
|
2009-11-25 11:07:00 -08:00
|
|
|
bv.updateDefaultZoom();
|
|
|
|
if (bv.isDefaultZoom())
|
|
|
|
// XXX this should really only happen on browser startup, not every resize
|
2009-11-24 11:44:05 -08:00
|
|
|
Browser.hideSidebars();
|
2009-11-25 11:07:00 -08:00
|
|
|
bv.onAfterVisibleMove();
|
2009-10-14 14:19:29 -07:00
|
|
|
|
2010-05-05 12:51:58 -07:00
|
|
|
for (let i = Browser._tabs.length - 1; i >= 0; i--)
|
|
|
|
Browser._tabs[i].updateViewportSize();
|
|
|
|
|
2009-07-17 16:17:57 -07:00
|
|
|
bv.commitBatchOperation();
|
2010-02-09 19:15:06 -08:00
|
|
|
|
|
|
|
let curEl = document.activeElement;
|
|
|
|
if (curEl && 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
|
|
|
bv.onAfterVisibleMove();
|
|
|
|
}
|
|
|
|
let notifications = document.getElementById("notifications");
|
|
|
|
notifications.addEventListener("AlertActive", notificationHandler, false);
|
|
|
|
notifications.addEventListener("AlertClose", notificationHandler, false);
|
|
|
|
|
2010-03-24 11:22:18 -07:00
|
|
|
// Add context helper to the content area only
|
|
|
|
container.addEventListener("contextmenu", ContextHelper, false);
|
|
|
|
|
2008-11-21 21:12:25 -08:00
|
|
|
// initialize input handling
|
2009-07-28 11:29:04 -07:00
|
|
|
ih = new InputHandler(container);
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2008-12-04 11:16:52 -08: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
|
|
|
|
2008-08-19 19:18:36 -07:00
|
|
|
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
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);
|
2010-06-04 01:59:57 -07:00
|
|
|
os.addObserver(FormSubmitObserver, "formsubmit", 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
|
|
|
|
2009-11-24 10:23:41 -08:00
|
|
|
// Login Manager
|
2008-04-18 06:41:49 -07:00
|
|
|
Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
|
|
|
|
2009-11-24 10:23:41 -08:00
|
|
|
// Make sure we're online before attempting to load
|
|
|
|
Util.forceOnline();
|
|
|
|
|
|
|
|
// Command line arguments/initial homepage
|
2010-03-26 08:11:03 -07:00
|
|
|
let whereURI = this.getHomePage();
|
2010-04-05 10:37:17 -07:00
|
|
|
if (needOverride == "new profile")
|
2009-11-13 11:36:39 -08:00
|
|
|
whereURI = "about:firstrun";
|
2009-09-18 21:23:44 -07:00
|
|
|
|
2008-07-21 14:00:55 -07:00
|
|
|
// If this is an intial window launch (was a nsICommandLine passed via window params)
|
|
|
|
// we execute some logic to load the initial launch page
|
2009-09-18 21:23:44 -07:00
|
|
|
if (window.arguments && window.arguments[0] &&
|
2009-09-21 03:04:50 -07:00
|
|
|
window.arguments[0] instanceof Ci.nsICommandLine) {
|
2008-05-02 13:15:45 -07:00
|
|
|
try {
|
2009-09-18 21:23:44 -07:00
|
|
|
var cmdLine = window.arguments[0];
|
2008-07-21 14:00:55 -07:00
|
|
|
|
|
|
|
// Check for and use a single commandline parameter
|
2008-05-02 13:15:45 -07:00
|
|
|
if (cmdLine.length == 1) {
|
2008-07-21 14:00:55 -07:00
|
|
|
// Assume the first arg is a URI if it is not a flag
|
2008-05-13 14:39:17 -07:00
|
|
|
var uri = cmdLine.getArgument(0);
|
2008-05-17 23:35:30 -07:00
|
|
|
if (uri != "" && uri[0] != '-') {
|
2008-05-13 14:39:17 -07:00
|
|
|
whereURI = cmdLine.resolveURI(uri);
|
|
|
|
if (whereURI)
|
|
|
|
whereURI = whereURI.spec;
|
|
|
|
}
|
2008-05-02 13:15:45 -07:00
|
|
|
}
|
2008-04-18 06:41:49 -07:00
|
|
|
|
2008-07-21 14:00:55 -07:00
|
|
|
// Check for the "url" flag
|
2008-07-22 06:38:26 -07:00
|
|
|
var uriFlag = cmdLine.handleFlagWithParam("url", false);
|
2008-07-21 14:00:55 -07:00
|
|
|
if (uriFlag) {
|
|
|
|
whereURI = cmdLine.resolveURI(uriFlag);
|
|
|
|
if (whereURI)
|
|
|
|
whereURI = whereURI.spec;
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
2008-04-18 06:41:49 -07:00
|
|
|
}
|
2009-06-24 09:42:53 -07:00
|
|
|
|
2009-09-18 21:23:44 -07:00
|
|
|
this.addTab(whereURI, true);
|
|
|
|
|
2009-06-09 10:55:14 -07:00
|
|
|
// JavaScript Error Console
|
|
|
|
if (gPrefService.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-07-17 16:17:57 -07:00
|
|
|
bv.commitBatchOperation();
|
2009-07-22 06:12:02 -07:00
|
|
|
|
2009-09-11 13:53:21 -07:00
|
|
|
// If some add-ons were disabled during during an application update, alert user
|
|
|
|
if (gPrefService.prefHasUserValue("extensions.disabledAddons")) {
|
|
|
|
let addons = gPrefService.getCharPref("extensions.disabledAddons").split(",");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
gPrefService.clearUserPref("extensions.disabledAddons");
|
|
|
|
}
|
|
|
|
|
2009-10-29 15:58:40 -07:00
|
|
|
// Force commonly used border-images into the image cache
|
|
|
|
ImagePreloader.cache();
|
2009-11-23 23:46:01 -08:00
|
|
|
|
2010-06-09 16:07:12 -07:00
|
|
|
messageManager.addMessageListener("FennecViewportMetadata", this);
|
2010-06-08 08:22:20 -07:00
|
|
|
messageManager.addMessageListener("MozApplicationManifest", OfflineApps);
|
|
|
|
|
2009-11-23 23:46:01 -08:00
|
|
|
this._pluginObserver = new PluginObserver(bv);
|
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) {
|
|
|
|
let shouldPrompt = gPrefService.getBoolPref("browser.tabs.warnOnClose");
|
|
|
|
if (shouldPrompt) {
|
|
|
|
let prompt = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
gPrefService.setBoolPref("browser.tabs.warnOnClose", false);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
let e = gWindowMediator.getEnumerator("navigator:browser");
|
|
|
|
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);
|
|
|
|
gObserverService.notifyObservers(closingCanceled, "browser-lastwindow-close-requested", null);
|
|
|
|
if (closingCanceled.data)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
gObserverService.notifyObservers(null, "browser-lastwindow-close-granted", null);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function shutdown() {
|
2009-10-14 12:04:33 -07:00
|
|
|
this._browserView.uninit();
|
2009-05-26 18:46:44 -07:00
|
|
|
BrowserUI.uninit();
|
2009-11-23 23:46:01 -08:00
|
|
|
this._pluginObserver.stop();
|
2009-05-26 18:46:44 -07:00
|
|
|
|
2009-04-22 17:47:02 -07:00
|
|
|
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
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");
|
2010-06-04 01:59:57 -07:00
|
|
|
os.removeObserver(FormSubmitObserver, "formsubmit");
|
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-01-05 15:12:04 -08:00
|
|
|
initNewProfile: function initNewProfile() {
|
|
|
|
},
|
2010-06-04 01:59:57 -07:00
|
|
|
|
2010-03-26 08:11:03 -07:00
|
|
|
getHomePage: function () {
|
|
|
|
let url = "about:home";
|
|
|
|
try {
|
|
|
|
url = gPrefService.getComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString).data;
|
|
|
|
} 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-08-12 13:38:52 -07:00
|
|
|
this._browserView.onAfterVisibleMove();
|
|
|
|
},
|
|
|
|
|
2009-12-10 09:55:27 -08:00
|
|
|
/** Let current browser's scrollbox know about where content has been panned. */
|
|
|
|
scrollBrowserToContent: function scrollBrowserToContent() {
|
|
|
|
let browser = this.selectedBrowser;
|
|
|
|
if (browser) {
|
|
|
|
let scroll = Browser.getScrollboxPosition(Browser.contentScrollboxScroller);
|
|
|
|
let windowUtils = BrowserView.Util.getBrowserDOMWindowUtils(browser);
|
|
|
|
browser.contentWindow.scrollTo(scroll.x, scroll.y);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Update viewport to location of browser's scrollbars. */
|
|
|
|
scrollContentToBrowser: function scrollContentToBrowser() {
|
|
|
|
let pos = BrowserView.Util.getContentScrollOffset(this.selectedBrowser);
|
|
|
|
if (pos.y != 0)
|
|
|
|
Browser.hideTitlebar();
|
2010-01-11 03:11:20 -08:00
|
|
|
|
2009-12-10 09:55:27 -08:00
|
|
|
Browser.contentScrollboxScroller.scrollTo(pos.x, pos.y);
|
2010-01-11 03:11:20 -08:00
|
|
|
this._browserView.onAfterVisibleMove();
|
2009-12-10 09:55:27 -08:00
|
|
|
},
|
|
|
|
|
2009-08-12 13:38:52 -07:00
|
|
|
hideSidebars: function scrollSidebarsOffscreen() {
|
2009-10-20 06:36:26 -07:00
|
|
|
let container = this.contentScrollbox;
|
|
|
|
let rect = container.getBoundingClientRect();
|
|
|
|
this.controlsScrollboxScroller.scrollBy(Math.round(rect.left), 0);
|
2009-08-12 13:38:52 -07:00
|
|
|
this._browserView.onAfterVisibleMove();
|
|
|
|
},
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
hideTitlebar: function hideTitlebar() {
|
|
|
|
let container = this.contentScrollbox;
|
|
|
|
let rect = container.getBoundingClientRect();
|
|
|
|
this.pageScrollboxScroller.scrollBy(0, Math.round(rect.top));
|
|
|
|
this.tryUnfloatToolbar();
|
|
|
|
this._browserView.onAfterVisibleMove();
|
|
|
|
},
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2009-10-09 05:34:02 -07:00
|
|
|
getTabForDocument: function(aDocument) {
|
|
|
|
let tabs = this._tabs;
|
|
|
|
for (let i = 0; i < tabs.length; i++) {
|
2009-12-09 00:03:04 -08:00
|
|
|
if (tabs[i].browser.contentDocument == aDocument)
|
2009-10-09 05:34:02 -07:00
|
|
|
return tabs[i];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
addTab: function(uri, bringFront) {
|
2008-11-21 21:12:25 -08:00
|
|
|
let newTab = new Tab();
|
|
|
|
this._tabs.push(newTab);
|
|
|
|
|
2009-07-17 16:17:57 -07:00
|
|
|
if (bringFront)
|
|
|
|
this.selectedTab = newTab;
|
|
|
|
|
|
|
|
newTab.load(uri);
|
|
|
|
|
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);
|
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);
|
|
|
|
|
2009-01-08 22:51:13 -08:00
|
|
|
let nextTab = this._selectedTab;
|
|
|
|
if (this._selectedTab == tab) {
|
2008-11-21 21:12:25 -08:00
|
|
|
nextTab = this.getTabAtIndex(tabIndex + 1) || this.getTabAtIndex(tabIndex - 1);
|
|
|
|
if (!nextTab)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("TabClose", true, false);
|
2009-06-04 07:57:56 -07:00
|
|
|
tab.chromeTab.dispatchEvent(event);
|
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) {
|
2009-07-17 16:17:57 -07:00
|
|
|
let bv = this._browserView;
|
|
|
|
|
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;
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
if (this._selectedTab) {
|
2010-03-25 21:18:20 -07:00
|
|
|
this._selectedTab.contentScrollOffset = this.getScrollboxPosition(this.contentScrollboxScroller);
|
|
|
|
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;
|
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();
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
tab.ensureBrowserExists();
|
|
|
|
|
2009-07-17 16:17:57 -07:00
|
|
|
bv.beginBatchOperation();
|
2009-08-11 13:51:13 -07:00
|
|
|
|
2009-11-25 11:07:00 -08:00
|
|
|
bv.setBrowser(tab.browser, tab.browserViewportState);
|
2009-08-11 13:51:13 -07:00
|
|
|
bv.forceContainerResize();
|
2010-04-09 21:22:13 -07:00
|
|
|
bv.updateDefaultZoom();
|
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
|
|
|
// XXX incorrect behavior if page was scrolled by tab in the background.
|
|
|
|
if (tab.contentScrollOffset) {
|
|
|
|
let { x: scrollX, y: scrollY } = tab.contentScrollOffset;
|
2009-09-04 22:14:59 -07:00
|
|
|
Browser.contentScrollboxScroller.scrollTo(scrollX, scrollY);
|
|
|
|
}
|
2010-03-25 21:18:20 -07:00
|
|
|
if (tab.pageScrollOffset) {
|
|
|
|
let { x: pageScrollX, y: pageScrollY } = tab.pageScrollOffset;
|
|
|
|
Browser.pageScrollboxScroller.scrollTo(pageScrollX, pageScrollY);
|
|
|
|
}
|
2009-09-04 22:14:59 -07:00
|
|
|
|
2009-12-10 10:17:39 -08:00
|
|
|
bv.setAggressive(!tab._loading);
|
|
|
|
|
2009-08-11 13:51:13 -07:00
|
|
|
bv.commitBatchOperation();
|
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
|
|
|
},
|
|
|
|
|
2009-11-30 12:19:24 -08:00
|
|
|
getNotificationBox: function getNotificationBox() {
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
/** Returns true iff a tab's browser has been destroyed to free up memory. */
|
|
|
|
sacrificeTab: function sacrificeTab() {
|
|
|
|
let tabToClear = this._tabs.reduce(function(prevTab, currentTab) {
|
|
|
|
if (currentTab == Browser.selectedTab || !currentTab.browser) {
|
|
|
|
return prevTab;
|
|
|
|
} else {
|
|
|
|
return (prevTab && prevTab.lastSelected <= currentTab.lastSelected) ? prevTab : currentTab;
|
|
|
|
}
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
if (tabToClear) {
|
|
|
|
tabToClear.saveState();
|
|
|
|
tabToClear._destroyBrowser();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
let uri = gIOService.newURI(errorDoc.location.href, null, null);
|
|
|
|
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
|
|
|
|
var defaultPrefs = Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Ci.nsIPrefService).getDefaultBranch(null);
|
|
|
|
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-08-06 15:38:43 -07:00
|
|
|
* @return [leftVisibility, rightVisiblity, leftTotalWidth, rightTotalWidth]
|
2009-07-27 19:04:22 -07:00
|
|
|
*/
|
2009-08-14 18:15:18 -07:00
|
|
|
computeSidebarVisibility: function computeSidebarVisibility(dx, dy) {
|
2009-07-27 19:04:22 -07:00
|
|
|
function visibility(bar, visrect) {
|
2009-10-15 12:50:32 -07:00
|
|
|
let w = bar.width;
|
|
|
|
bar.restrictTo(visrect);
|
|
|
|
return bar.width / w;
|
2009-07-27 19:04:22 -07:00
|
|
|
}
|
|
|
|
|
2009-08-14 18:15:18 -07:00
|
|
|
if (!dx) dx = 0;
|
|
|
|
if (!dy) dy = 0;
|
|
|
|
|
2009-07-27 19:04:22 -07:00
|
|
|
let leftbarCBR = document.getElementById('tabs-container').getBoundingClientRect();
|
|
|
|
let ritebarCBR = document.getElementById('browser-controls').getBoundingClientRect();
|
|
|
|
|
2009-10-15 12:50:32 -07:00
|
|
|
let leftbar = new Rect(Math.round(leftbarCBR.left) - dx, 0, Math.round(leftbarCBR.width), 1);
|
|
|
|
let ritebar = new Rect(Math.round(ritebarCBR.left) - dx, 0, Math.round(ritebarCBR.width), 1);
|
2009-07-27 19:04:22 -07:00
|
|
|
let leftw = leftbar.width;
|
|
|
|
let ritew = ritebar.width;
|
|
|
|
|
2009-10-15 12:50:32 -07:00
|
|
|
let visrect = new Rect(0, 0, window.innerWidth, 1);
|
2009-07-28 16:14:57 -07:00
|
|
|
|
2009-08-06 15:38:43 -07:00
|
|
|
let leftvis = visibility(leftbar, visrect);
|
|
|
|
let ritevis = visibility(ritebar, visrect);
|
|
|
|
|
|
|
|
return [leftvis, ritevis, leftw, ritew];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2009-12-10 11:00:46 -08:00
|
|
|
let bv = this._browserView;
|
2010-04-29 12:29:01 -07:00
|
|
|
if (!bv.allowZoom)
|
|
|
|
return;
|
|
|
|
|
2010-04-12 19:42:35 -07:00
|
|
|
let zoomLevel = bv.getZoomLevel();
|
|
|
|
|
|
|
|
let zoomValues = ZoomManager.zoomValues;
|
|
|
|
var i = zoomValues.indexOf(ZoomManager.snap(zoomLevel)) + (aDirection < 0 ? 1 : -1);
|
|
|
|
if (i >= 0 && i < zoomValues.length)
|
|
|
|
zoomLevel = zoomValues[i];
|
2010-04-08 07:43:04 -07:00
|
|
|
|
|
|
|
zoomLevel = Math.max(zoomLevel, bv.getPageZoomLevel());
|
|
|
|
|
2009-12-10 11:00:46 -08:00
|
|
|
let center = this.getVisibleRect().center().map(bv.viewportToBrowser);
|
2010-04-08 07:43:04 -07:00
|
|
|
this.setVisibleRect(this._getZoomRectForPoint(center.x, center.y, zoomLevel));
|
2009-08-12 14:40:43 -07:00
|
|
|
},
|
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
/**
|
2009-10-23 21:04:51 -07:00
|
|
|
* Find the needed zoom level for zooming on an element
|
2009-10-21 16:11:38 -07:00
|
|
|
*/
|
2009-10-23 21:04:51 -07:00
|
|
|
_getZoomLevelForElement: function _getZoomLevelForElement(element) {
|
2009-10-21 16:11:38 -07:00
|
|
|
const margin = 15;
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-10-23 21:04:51 -07:00
|
|
|
let bv = this._browserView;
|
|
|
|
let elRect = bv.browserToViewportRect(Browser.getBoundingContentRect(element));
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-10-23 21:04:51 -07:00
|
|
|
let vis = bv.getVisibleRect();
|
2010-04-29 12:29:01 -07:00
|
|
|
return bv.clampZoomLevel(bv.getZoomLevel() * vis.width / (elRect.width + margin * 2));
|
2009-10-21 16:11:38 -07:00
|
|
|
},
|
2009-08-17 13:01:27 -07:00
|
|
|
|
2010-01-14 13:08:40 -08:00
|
|
|
/**
|
2010-01-11 12:43:47 -08:00
|
|
|
* Find an appropriate zoom rect for an element, if it exists.
|
|
|
|
* @return Rect in viewport coordinates
|
|
|
|
* */
|
2009-12-08 09:28:01 -08:00
|
|
|
_getZoomRectForElement: function _getZoomRectForElement(element, elementY) {
|
|
|
|
let bv = this._browserView;
|
|
|
|
let oldZoomLevel = bv.getZoomLevel();
|
|
|
|
let zoomLevel = this._getZoomLevelForElement(element);
|
|
|
|
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
|
|
|
|
let zoomTolerance = (bv.isDefaultZoom()) ? .9 : .6666;
|
|
|
|
if (zoomRatio >= zoomTolerance) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
let elRect = this.getBoundingContentRect(element);
|
|
|
|
return this._getZoomRectForPoint(elRect.center().x, elementY, zoomLevel);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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) {
|
2009-12-08 09:28:01 -08:00
|
|
|
let bv = this._browserView;
|
2009-10-21 16:11:38 -07:00
|
|
|
let vis = bv.getVisibleRect();
|
|
|
|
x = bv.browserToViewport(x);
|
|
|
|
y = bv.browserToViewport(y);
|
2009-08-17 13:01:27 -07:00
|
|
|
|
2010-04-12 19:42:35 -07:00
|
|
|
zoomLevel = Math.min(ZoomManager.MAX, zoomLevel);
|
2009-10-21 16:11:38 -07:00
|
|
|
let zoomRatio = zoomLevel / bv.getZoomLevel();
|
|
|
|
let newVisW = vis.width / zoomRatio, newVisH = vis.height / 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
|
|
|
|
return result.translateInside(bv._browserViewportState.viewportRect);
|
|
|
|
},
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
setVisibleRect: function setVisibleRect(rect) {
|
2009-12-08 09:28:01 -08:00
|
|
|
let bv = this._browserView;
|
2009-10-21 16:11:38 -07:00
|
|
|
let vis = bv.getVisibleRect();
|
|
|
|
let zoomRatio = vis.width / rect.width;
|
|
|
|
let zoomLevel = bv.getZoomLevel() * zoomRatio;
|
|
|
|
let scrollX = rect.left * zoomRatio;
|
|
|
|
let scrollY = rect.top * zoomRatio;
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-11-12 20:41:45 -08:00
|
|
|
// The order of operations below is important for artifacting and for performance. Important
|
|
|
|
// side effects of functions are noted below.
|
|
|
|
|
|
|
|
// Hardware scrolling happens immediately when scrollTo is called. Hide to prevent artifacts.
|
2010-01-11 12:43:47 -08:00
|
|
|
bv.beginOffscreenOperation(rect);
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-11-12 20:41:45 -08:00
|
|
|
// We must scroll to the correct area before TileManager is informed of the change
|
|
|
|
// so that only one render is done. Ensures setZoomLevel puts it off.
|
|
|
|
bv.beginBatchOperation();
|
|
|
|
|
|
|
|
// Critical rect changes when controls are hidden. Must hide before tilemanager viewport.
|
2009-12-08 09:28:01 -08:00
|
|
|
this.hideSidebars();
|
|
|
|
this.hideTitlebar();
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
bv.setZoomLevel(zoomLevel);
|
2009-11-12 20:41:45 -08:00
|
|
|
|
|
|
|
// Ensure container is big enough for scroll values.
|
|
|
|
bv.forceContainerResize();
|
2009-12-08 09:28:01 -08:00
|
|
|
this.forceChromeReflow();
|
|
|
|
this.contentScrollboxScroller.scrollTo(scrollX, scrollY);
|
2009-10-21 16:11:38 -07:00
|
|
|
bv.onAfterVisibleMove();
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-11-12 20:41:45 -08:00
|
|
|
// Inform tile manager, which happens to render new tiles too. Must call in case a batch
|
|
|
|
// operation was in progress before zoom.
|
|
|
|
bv.forceViewportChange();
|
|
|
|
|
|
|
|
bv.commitBatchOperation();
|
2009-10-21 16:11:38 -07:00
|
|
|
bv.commitOffscreenOperation();
|
|
|
|
},
|
2009-07-31 15:32:48 -07:00
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
zoomToPoint: function zoomToPoint(cX, cY) {
|
2009-12-08 09:28:01 -08:00
|
|
|
let [elementX, elementY] = this.transformClientToBrowser(cX, cY);
|
|
|
|
let zoomRect = null;
|
|
|
|
let element = this.elementFromPoint(elementX, elementY);
|
2009-11-25 11:07:00 -08:00
|
|
|
let bv = this._browserView;
|
2009-12-08 09:28:01 -08:00
|
|
|
if (element)
|
|
|
|
zoomRect = this._getZoomRectForElement(element, elementY);
|
|
|
|
if (!zoomRect && bv.isDefaultZoom())
|
|
|
|
zoomRect = this._getZoomRectForPoint(elementX, elementY, bv.getZoomLevel() * 2);
|
2009-10-23 21:04:51 -07:00
|
|
|
|
2010-05-04 08:15:57 -07:00
|
|
|
if (zoomRect)
|
2009-12-08 09:28:01 -08:00
|
|
|
this.setVisibleRect(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
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
zoomFromPoint: function zoomFromPoint(cX, cY) {
|
|
|
|
let bv = this._browserView;
|
2009-11-25 11:07:00 -08:00
|
|
|
if (!bv.isDefaultZoom()) {
|
2010-04-08 07:43:04 -07:00
|
|
|
let zoomLevel = bv.getDefaultZoomLevel();
|
2009-10-21 16:11:38 -07:00
|
|
|
let [elementX, elementY] = this.transformClientToBrowser(cX, cY);
|
|
|
|
let zoomRect = this._getZoomRectForPoint(elementX, elementY, zoomLevel);
|
|
|
|
this.setVisibleRect(zoomRect);
|
|
|
|
}
|
2009-07-31 15:32:48 -07:00
|
|
|
},
|
|
|
|
|
2009-12-11 11:41:28 -08:00
|
|
|
getContentClientRects: function getContentClientRects(contentElem) {
|
|
|
|
// XXX don't copy getBoundingContentRect
|
|
|
|
let browser = Browser._browserView.getBrowser();
|
|
|
|
|
|
|
|
if (!browser)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
let offset = BrowserView.Util.getContentScrollOffset(browser);
|
|
|
|
let nativeRects = contentElem.getClientRects();
|
|
|
|
|
|
|
|
// step out of iframes and frames, offsetting scroll values
|
|
|
|
let rect;
|
2009-12-15 11:59:01 -08:00
|
|
|
let cw = browser.contentWindow;
|
|
|
|
for (let frame = contentElem.ownerDocument.defaultView; frame != cw; frame = frame.parent) {
|
2009-12-11 11:41:28 -08:00
|
|
|
// adjust client coordinates' origin to be top left of iframe viewport
|
|
|
|
rect = frame.frameElement.getBoundingClientRect();
|
2010-05-14 09:14:04 -07:00
|
|
|
let left = frame.getComputedStyle(frame.frameElement, "").borderLeftWidth;
|
|
|
|
let top = frame.getComputedStyle(frame.frameElement, "").borderTopWidth;
|
|
|
|
offset.add(rect.left + parseInt(left), rect.top + parseInt(top));
|
2009-12-11 11:41:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
let result = [];
|
|
|
|
let r;
|
|
|
|
for (let i = nativeRects.length - 1; i >= 0; i--) {
|
|
|
|
r = nativeRects[i];
|
|
|
|
result.push(new Rect(r.left + offset.x, r.top + offset.y, r.width, r.height));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2009-07-31 15:32:48 -07:00
|
|
|
getBoundingContentRect: function getBoundingContentRect(contentElem) {
|
2009-12-09 00:03:04 -08:00
|
|
|
let document = contentElem.ownerDocument;
|
|
|
|
while(document.defaultView.frameElement)
|
|
|
|
document = document.defaultView.frameElement.ownerDocument;
|
|
|
|
|
|
|
|
let tab = Browser.getTabForDocument(document);
|
|
|
|
if (!tab || !tab.browser)
|
2009-07-31 15:32:48 -07:00
|
|
|
return null;
|
|
|
|
|
2009-12-09 00:03:04 -08:00
|
|
|
let browser = tab.browser;
|
2009-10-21 16:11:38 -07:00
|
|
|
let offset = BrowserView.Util.getContentScrollOffset(browser);
|
2009-07-31 15:32:48 -07:00
|
|
|
|
|
|
|
let r = contentElem.getBoundingClientRect();
|
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
// step out of iframes and frames, offsetting scroll values
|
|
|
|
for (let frame = contentElem.ownerDocument.defaultView; frame != browser.contentWindow; frame = frame.parent) {
|
|
|
|
// adjust client coordinates' origin to be top left of iframe viewport
|
|
|
|
let rect = frame.frameElement.getBoundingClientRect();
|
2010-05-14 09:14:04 -07:00
|
|
|
let left = frame.getComputedStyle(frame.frameElement, "").borderLeftWidth;
|
|
|
|
let top = frame.getComputedStyle(frame.frameElement, "").borderTopWidth;
|
|
|
|
offset.add(rect.left + parseInt(left), rect.top + parseInt(top));
|
2009-10-21 16:11:38 -07:00
|
|
|
}
|
2009-08-04 16:40:39 -07:00
|
|
|
|
2009-10-21 16:11:38 -07:00
|
|
|
return new Rect(r.left + offset.x, r.top + offset.y, r.width, r.height);
|
2009-07-31 15:32:48 -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) {
|
2009-07-28 16:14:57 -07:00
|
|
|
let container = document.getElementById("tile-container");
|
|
|
|
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);
|
|
|
|
|
|
|
|
return (arguments.length > 1) ? [x - x0, y - y0] : (x - x0);
|
|
|
|
},
|
2009-07-28 16:14:57 -07:00
|
|
|
|
2009-07-31 15:32:48 -07:00
|
|
|
browserViewToClient: function browserViewToClient(x, y) {
|
|
|
|
let container = document.getElementById("tile-container");
|
|
|
|
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) {
|
|
|
|
let container = document.getElementById("tile-container");
|
|
|
|
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) {
|
|
|
|
return this.clientToBrowserView(cX, cY).map(this._browserView.viewportToBrowser);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2009-09-09 18:52:46 -07:00
|
|
|
* @param x,y Browser coordinates
|
|
|
|
* @return Element at position, null if no active browser or no element found
|
2009-08-07 18:08:06 -07:00
|
|
|
*/
|
|
|
|
elementFromPoint: function elementFromPoint(x, y) {
|
|
|
|
let browser = this._browserView.getBrowser();
|
2010-05-03 08:42:56 -07:00
|
|
|
if (!browser)
|
|
|
|
return null;
|
2009-08-10 18:03:42 -07:00
|
|
|
|
2009-09-09 18:52:46 -07:00
|
|
|
// browser's elementFromPoint expect browser-relative client coordinates.
|
|
|
|
// subtract browser's scroll values to adjust
|
2009-08-07 18:08:06 -07:00
|
|
|
let cwu = BrowserView.Util.getBrowserDOMWindowUtils(browser);
|
2009-09-09 18:52:46 -07:00
|
|
|
let scrollX = {}, scrollY = {};
|
2009-08-10 18:03:42 -07:00
|
|
|
cwu.getScrollXY(false, scrollX, scrollY);
|
2009-08-07 18:08:06 -07:00
|
|
|
x = x - scrollX.value;
|
|
|
|
y = y - scrollY.value;
|
2010-04-08 11:50:05 -07:00
|
|
|
let elem = ElementTouchHelper.getClosest(cwu, x, y);
|
2009-08-07 18:08:06 -07:00
|
|
|
|
|
|
|
// step through layers of IFRAMEs and FRAMES to find innermost element
|
|
|
|
while (elem && (elem instanceof HTMLIFrameElement || elem instanceof HTMLFrameElement)) {
|
2009-09-09 18:52:46 -07:00
|
|
|
// adjust client coordinates' origin to be top left of iframe viewport
|
2010-05-14 09:14:04 -07:00
|
|
|
let win = elem.ownerDocument.defaultView;
|
|
|
|
let left = win.getComputedStyle(elem, "").borderLeftWidth;
|
|
|
|
let top = win.getComputedStyle(elem, "").borderTopWidth;
|
|
|
|
|
2009-09-09 18:52:46 -07:00
|
|
|
let rect = elem.getBoundingClientRect();
|
2010-05-14 09:14:04 -07:00
|
|
|
x = Math.max(0, x - (rect.left + parseInt(left)));
|
|
|
|
y = Math.max(0, y - (rect.top + parseInt(top)));
|
|
|
|
|
2010-04-08 11:50:05 -07:00
|
|
|
let windowUtils = elem.contentDocument.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
elem = ElementTouchHelper.getClosest(windowUtils, x, y);
|
2009-08-07 18:08:06 -07:00
|
|
|
}
|
2009-08-10 18:03:42 -07:00
|
|
|
|
2009-08-07 18:08:06 -07:00
|
|
|
return elem;
|
|
|
|
},
|
2009-08-10 18:03:42 -07:00
|
|
|
|
2009-07-28 16:14:57 -07:00
|
|
|
/**
|
|
|
|
* Return the visible rect in coordinates with origin at the (left, top) of
|
|
|
|
* the tile container, i.e. BrowserView coordinates.
|
|
|
|
*/
|
|
|
|
getVisibleRect: function getVisibleRect() {
|
2009-10-23 21:04:51 -07:00
|
|
|
let stack = document.getElementById("tile-stack");
|
2009-07-28 16:14:57 -07:00
|
|
|
let container = document.getElementById("tile-container");
|
|
|
|
let containerBCR = container.getBoundingClientRect();
|
|
|
|
|
|
|
|
let x = Math.round(-containerBCR.left);
|
|
|
|
let y = Math.round(-containerBCR.top);
|
|
|
|
let w = window.innerWidth;
|
2009-10-23 21:04:51 -07:00
|
|
|
let h = stack.getBoundingClientRect().height;
|
2009-07-28 16:14:57 -07:00
|
|
|
|
2009-10-15 12:50:32 -07:00
|
|
|
return new Rect(x, y, w, h);
|
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) {
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "FennecViewportMetadata":
|
|
|
|
let tab = Browser.getTabForBrowser(aMessage.target);
|
|
|
|
tab.updateViewportMetadata(aMessage.json);
|
|
|
|
break;
|
|
|
|
}
|
2008-07-25 16:27:31 -07:00
|
|
|
}
|
2008-04-18 06:41:49 -07:00
|
|
|
};
|
|
|
|
|
2009-08-05 16:06:54 -07:00
|
|
|
Browser.MainDragger = function MainDragger(browserView) {
|
|
|
|
this.bv = browserView;
|
2009-08-07 18:08:06 -07:00
|
|
|
this.draggedFrame = null;
|
2009-11-30 10:25:06 -08:00
|
|
|
this.contentScrollbox = null;
|
2009-08-05 16:06:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
Browser.MainDragger.prototype = {
|
2009-11-10 07:48:37 -08:00
|
|
|
isDraggable: function isDraggable(target, scroller) { return true; },
|
|
|
|
|
2009-08-07 18:08:06 -07:00
|
|
|
dragStart: function dragStart(clientX, clientY, target, scroller) {
|
2010-01-13 12:30:08 -08:00
|
|
|
// Make sure pausing occurs before any early returns.
|
|
|
|
this.bv.pauseRendering();
|
|
|
|
|
2010-04-05 06:50:04 -07:00
|
|
|
// XXX shouldn't know about observer
|
|
|
|
// adding pause in pauseRendering isn't so great, because tiles will hardly ever prefetch while
|
|
|
|
// loading state is going (and already, the idle timer is bigger during loading so it doesn't fit
|
|
|
|
// into the aggressive flag).
|
|
|
|
this.bv._idleServiceObserver.pause();
|
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
let [x, y] = Browser.transformClientToBrowser(clientX, clientY);
|
|
|
|
let element = Browser.elementFromPoint(x, y);
|
2009-12-01 18:22:10 -08:00
|
|
|
|
2010-04-05 06:50:04 -07:00
|
|
|
this.draggedFrame = null;
|
|
|
|
this.contentScrollbox = null;
|
2009-12-01 18:22:10 -08:00
|
|
|
|
2010-04-05 06:50:04 -07:00
|
|
|
// Check if we are in a scrollable HTML element
|
|
|
|
let htmlElement = element;
|
|
|
|
if (htmlElement && htmlElement instanceof HTMLElement) {
|
|
|
|
let win = htmlElement.ownerDocument.defaultView;
|
|
|
|
for (; htmlElement; htmlElement = htmlElement.parentNode) {
|
|
|
|
try {
|
|
|
|
let cs = win.getComputedStyle(htmlElement, null);
|
|
|
|
let overflowX = cs.getPropertyValue("overflow-x");
|
|
|
|
let overflowY = cs.getPropertyValue("overflow-y");
|
|
|
|
|
2010-04-19 12:24:15 -07:00
|
|
|
let scrollableY = overflowY != "hidden" && overflowY != "visible" && htmlElement.clientHeight < htmlElement.scrollHeight;
|
|
|
|
let scrollableX = overflowX != "hidden" && overflowX != "visible" && htmlElement.clientWidth < htmlElement.scrollWidth
|
2010-04-13 12:21:35 -07:00
|
|
|
&& !(htmlElement instanceof HTMLSelectElement); // Bug 295977
|
|
|
|
|
|
|
|
if (scrollableX || scrollableY) {
|
2010-04-05 06:50:04 -07:00
|
|
|
this.contentScrollbox = this._createDivScrollBox(htmlElement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch(e) {}
|
|
|
|
}
|
|
|
|
}
|
2009-12-01 18:22:10 -08:00
|
|
|
|
2010-04-05 06:50:04 -07:00
|
|
|
// Check if we are in XUL land
|
|
|
|
let xulElement = element;
|
|
|
|
if (xulElement && xulElement instanceof XULElement) {
|
|
|
|
for (; xulElement; xulElement = xulElement.parentNode) {
|
|
|
|
if (xulElement.localName == "treechildren") {
|
|
|
|
this.contentScrollbox = this._createTreeScrollBox(xulElement.parentNode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let wrapper = xulElement.wrappedJSObject;
|
|
|
|
let scrollable = false;
|
|
|
|
try {
|
|
|
|
scrollable = (wrapper.scrollBoxObject != null) || (wrapper.boxObject.QueryInterface(Ci.nsIScrollBoxObject));
|
|
|
|
} catch(e) {}
|
|
|
|
if (scrollable) {
|
|
|
|
this.contentScrollbox = wrapper.scrollBoxObject || wrapper.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-01 14:00:27 -07:00
|
|
|
|
2010-04-05 06:50:04 -07:00
|
|
|
if (element)
|
|
|
|
this.draggedFrame = element.ownerDocument.defaultView;
|
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-01 23:42:25 -07:00
|
|
|
this.draggedFrame = null;
|
2009-09-28 11:16:51 -07:00
|
|
|
this.dragMove(Browser.snapSidebars(), 0, scroller);
|
2009-08-10 18:03:42 -07:00
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
Browser.tryUnfloatToolbar();
|
2009-08-05 13:28:43 -07:00
|
|
|
|
2009-08-05 16:06:54 -07:00
|
|
|
this.bv.resumeRendering();
|
2010-01-12 10:10:17 -08:00
|
|
|
|
|
|
|
// XXX shouldn't know about observer
|
|
|
|
this.bv._idleServiceObserver.resume();
|
2009-08-05 16:06:54 -07:00
|
|
|
},
|
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
dragMove: function dragMove(dx, dy, scroller) {
|
|
|
|
let elem = this.draggedFrame;
|
2009-10-15 12:50:32 -07:00
|
|
|
let doffset = new Point(dx, dy);
|
2009-09-01 23:42:25 -07:00
|
|
|
let render = false;
|
2009-08-17 13:01:27 -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-11-30 10:25:06 -08:00
|
|
|
// do HTML overflow or XUL panning
|
2010-03-24 08:31:09 -07:00
|
|
|
if (this.contentScrollbox && !doffset.isZero()) {
|
2009-12-01 18:22:10 -08:00
|
|
|
this._panScrollbox(this.contentScrollbox, doffset);
|
2010-03-24 08:31:09 -07:00
|
|
|
render = true;
|
|
|
|
}
|
2009-12-01 18:22:10 -08:00
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
// Do all iframe panning
|
|
|
|
if (elem) {
|
2009-10-15 12:50:32 -07:00
|
|
|
while (elem.frameElement && !doffset.isZero()) {
|
2009-09-01 23:42:25 -07:00
|
|
|
this._panFrame(elem, doffset);
|
|
|
|
elem = elem.frameElement;
|
|
|
|
render = true;
|
2009-08-05 16:06:54 -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-08-12 13:38:52 -07:00
|
|
|
this.bv.onAfterVisibleMove();
|
2009-08-05 16:06:54 -07:00
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
if (render)
|
|
|
|
this.bv.renderNow();
|
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-11-30 10:25:06 -08:00
|
|
|
/**
|
|
|
|
* builds a minimal implementation of scrollBoxObject for div
|
|
|
|
*/
|
|
|
|
_createDivScrollBox: function(div) {
|
|
|
|
let sbo = {
|
2010-04-01 14:00:27 -07:00
|
|
|
getScrolledSize: function(width, height) {
|
|
|
|
width.value = div.scrollWidth;
|
|
|
|
height.value = div.scrollHeight;
|
|
|
|
},
|
2010-04-05 06:50:04 -07:00
|
|
|
|
2010-04-01 14:00:27 -07:00
|
|
|
getPosition: function(x, y) {
|
|
|
|
x.value = div.scrollLeft;
|
|
|
|
y.value = div.scrollTop;
|
|
|
|
},
|
2010-04-05 06:50:04 -07:00
|
|
|
|
2010-04-01 14:00:27 -07:00
|
|
|
scrollBy: function(dx, dy) {
|
|
|
|
div.scrollTop += dy;
|
|
|
|
div.scrollLeft += dx;
|
|
|
|
}
|
2010-04-05 06:50:04 -07:00
|
|
|
}
|
|
|
|
return sbo;
|
2009-11-30 10:25:06 -08:00
|
|
|
},
|
2009-08-05 16:06:54 -07:00
|
|
|
|
2010-04-05 06:50:04 -07:00
|
|
|
/**
|
2009-11-30 10:25:06 -08:00
|
|
|
* builds a minimal implementation of scrollBoxObject for trees
|
|
|
|
*/
|
|
|
|
_createTreeScrollBox: function(tree) {
|
|
|
|
let treeBox = tree.boxObject.QueryInterface(Ci.nsITreeBoxObject);
|
|
|
|
let sbo = {
|
|
|
|
pageLength: treeBox.getPageLength(),
|
|
|
|
rowHeight: treeBox.rowHeight,
|
|
|
|
rowWidth: treeBox.rowWidth,
|
|
|
|
rowCount: treeBox.view.rowCount,
|
|
|
|
targetY: treeBox.getFirstVisibleRow() * treeBox.rowHeight,
|
|
|
|
getScrolledSize: function(width, height) {
|
|
|
|
width.value = this.rowWidth;
|
|
|
|
height.value = this.rowHeight * this.rowCount;
|
|
|
|
},
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-11-30 10:25:06 -08:00
|
|
|
getPosition: function(x, y) {
|
|
|
|
x.value = treeBox.horizontalPosition;
|
|
|
|
y.value = this.targetY;
|
|
|
|
},
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-11-30 10:25:06 -08:00
|
|
|
scrollBy: function(dx, dy) {
|
|
|
|
this.targetY += dy;
|
|
|
|
if (this.targetY < 0)
|
|
|
|
this.targetY = 0;
|
|
|
|
let targetRow = Math.floor(this.targetY / this.rowHeight);
|
|
|
|
if ((targetRow + this.pageLength) > this.rowCount) {
|
|
|
|
targetRow = this.rowCount - this.pageLength;
|
|
|
|
this.targetY = targetRow * this.rowHeight;
|
|
|
|
}
|
|
|
|
treeBox.scrollToRow(targetRow);
|
|
|
|
treeBox.scrollToHorizontalPosition(treeBox.horizontalPosition + dx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sbo;
|
|
|
|
},
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-11-30 10:25:06 -08:00
|
|
|
/**
|
|
|
|
* pans a scrollbox, updating doffset
|
|
|
|
*/
|
|
|
|
_panScrollbox: function(sbo, doffset) {
|
|
|
|
let origX = {}, origY = {}, newX = {}, newY = {};
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-11-30 10:25:06 -08:00
|
|
|
sbo.getPosition(origX, origY);
|
|
|
|
sbo.scrollBy(doffset.x, doffset.y);
|
|
|
|
sbo.getPosition(newX, newY);
|
|
|
|
|
|
|
|
doffset.subtract(newX.value - origX.value, newY.value - origY.value);
|
|
|
|
},
|
2010-01-14 13:08:40 -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);
|
|
|
|
|
2009-10-23 21:04:51 -07:00
|
|
|
let height = document.getElementById("tile-stack").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-11 13:51:13 -07:00
|
|
|
},
|
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
/** Pan frame by the given amount. Updates doffset with leftovers. */
|
|
|
|
_panFrame: function _panFrame(frame, doffset) {
|
|
|
|
let origX = {}, origY = {}, newX = {}, newY = {};
|
|
|
|
let windowUtils = frame.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
2009-08-11 13:51:13 -07:00
|
|
|
|
2009-09-01 23:42:25 -07:00
|
|
|
windowUtils.getScrollXY(false, origX, origY);
|
2009-10-15 12:50:32 -07:00
|
|
|
frame.scrollBy(doffset.x, doffset.y);
|
2009-09-01 23:42:25 -07:00
|
|
|
windowUtils.getScrollXY(false, newX, newY);
|
2009-08-11 13:51:13 -07:00
|
|
|
|
2009-10-15 12:50:32 -07:00
|
|
|
doffset.subtract(newX.value - origX.value, newY.value - origY.value);
|
2009-08-05 16:06:54 -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 :
|
|
|
|
aWhere = gPrefService.getIntPref("browser.link.open_external");
|
|
|
|
break;
|
|
|
|
default : // OPEN_NEW or an illegal value
|
|
|
|
aWhere = gPrefService.getIntPref("browser.link.open_newwindow");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
browser = newWindow.Browser.selectedBrowser;
|
2009-09-10 06:24:48 -07:00
|
|
|
} else {
|
2008-11-21 21:12:25 -08:00
|
|
|
if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWTAB)
|
2010-05-24 12:27:45 -07:00
|
|
|
browser = Browser.addTab("about:blank", true).browser;
|
|
|
|
else // OPEN_CURRENTWINDOW and illegal values
|
|
|
|
browser = Browser.selectedBrowser;
|
2008-09-24 09:14:06 -07:00
|
|
|
}
|
2010-05-24 12:27:45 -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;
|
2009-10-09 05:34:02 -07:00
|
|
|
referrer = gIOService.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
|
|
|
|
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 searchService() {
|
|
|
|
delete this.searchService;
|
|
|
|
return this.searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
|
|
|
|
},
|
|
|
|
|
|
|
|
get engines() {
|
|
|
|
if (this._engines)
|
|
|
|
return this._engines;
|
2010-01-14 13:08:40 -08:00
|
|
|
return this._engines = this.searchService.getVisibleEngines({ });
|
2009-09-22 19:19:24 -07:00
|
|
|
},
|
|
|
|
|
2009-08-26 12:29:46 -07:00
|
|
|
updatePageSearchEngines: function() {
|
2010-03-29 13:41:03 -07:00
|
|
|
PageActions.removeItems("search");
|
|
|
|
|
2010-06-08 09:11:28 -07:00
|
|
|
let items = Browser.selectedBrowser.searchEngines;
|
|
|
|
if (!items.length)
|
2009-08-26 12:29:46 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// XXX limit to the first search engine for now
|
2010-03-29 13:41:03 -07:00
|
|
|
let kMaxSearchEngine = 1;
|
|
|
|
for (let i = 0; i < kMaxSearchEngine; i++) {
|
2010-06-08 09:11:28 -07:00
|
|
|
let engine = items[i];
|
2010-03-29 13:41:03 -07:00
|
|
|
let item = PageActions.appendItem("search",
|
2010-03-24 12:55:09 -07:00
|
|
|
Elements.browserBundle.getString("pageactions.search.addNew"),
|
2010-03-29 13:41:03 -07:00
|
|
|
engine.title);
|
2010-03-24 12:55:09 -07:00
|
|
|
|
|
|
|
item.engine = engine;
|
|
|
|
item.onclick = function() {
|
|
|
|
BrowserSearch.addPermanentSearchEngine(item.engine);
|
|
|
|
PageActions.removeItem(item);
|
|
|
|
};
|
2009-08-26 12:29:46 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addPermanentSearchEngine: function (aEngine) {
|
|
|
|
let iconURL = BrowserUI._favicon.src;
|
2009-09-22 19:19:24 -07:00
|
|
|
this.searchService.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
|
|
|
},
|
|
|
|
|
|
|
|
updateSearchButtons: function() {
|
2010-04-08 07:54:18 -07:00
|
|
|
let container = document.getElementById("search-buttons");
|
|
|
|
if (this._engines && container.hasChildNodes())
|
2009-08-26 12:29:46 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Clean the previous search engines button
|
|
|
|
while (container.hasChildNodes())
|
|
|
|
container.removeChild(container.lastChild);
|
|
|
|
|
2009-09-22 19:19:24 -07:00
|
|
|
let engines = this.engines;
|
2010-04-08 07:54:18 -07:00
|
|
|
for (let e = 0; e < engines.length; e++) {
|
|
|
|
let button = document.createElement("radio");
|
|
|
|
let engine = engines[e];
|
2009-08-26 12:29:46 -07:00
|
|
|
button.id = engine.name;
|
|
|
|
button.setAttribute("label", engine.name);
|
|
|
|
button.className = "searchengine";
|
|
|
|
if (engine.iconURI)
|
|
|
|
button.setAttribute("src", engine.iconURI.spec);
|
|
|
|
container.appendChild(button);
|
|
|
|
button.engine = engine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-01 20:39:39 -07:00
|
|
|
/** Watches for mouse events in chrome and sends them to content. */
|
|
|
|
function ContentCustomClicker(browserView) {
|
|
|
|
this._browserView = browserView;
|
2009-12-11 11:41:28 -08:00
|
|
|
this._overlay = document.getElementById("content-overlay");
|
2010-03-11 06:18:41 -08:00
|
|
|
this._overlayTimeout = 0;
|
2009-12-11 11:41:28 -08:00
|
|
|
this._width = 0;
|
|
|
|
this._height = 0;
|
2009-09-01 20:39:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ContentCustomClicker.prototype = {
|
|
|
|
/** Dispatch a mouse event with chrome client coordinates. */
|
2010-04-08 11:50:05 -07:00
|
|
|
_dispatchMouseEvent: function _dispatchMouseEvent(element, name, cX, cY) {
|
2009-09-01 20:39:39 -07:00
|
|
|
let browser = this._browserView.getBrowser();
|
|
|
|
if (browser) {
|
2009-09-28 11:16:55 -07:00
|
|
|
let [x, y] = Browser.transformClientToBrowser(cX, cY);
|
|
|
|
let cwu = BrowserView.Util.getBrowserDOMWindowUtils(browser);
|
2010-04-13 13:14:44 -07:00
|
|
|
let scrollX = {}, scrollY = {};
|
|
|
|
cwu.getScrollXY(false, scrollX, scrollY);
|
2010-04-08 11:50:05 -07:00
|
|
|
|
|
|
|
// the element can be out of the cX/cY point because of the touch radius
|
2010-05-03 08:42:56 -07:00
|
|
|
// ignore the redirection if the element is a HTMLHtmlElement (bug 562981)
|
2010-04-13 13:14:44 -07:00
|
|
|
let rect = Browser.getBoundingContentRect(element);
|
2010-05-03 08:42:56 -07:00
|
|
|
if (!rect.isEmpty() && !(element instanceof HTMLHtmlElement) &&
|
|
|
|
((x < rect.left || (x > rect.left + rect.width)) || (y < rect.top || (y > rect.top + rect.height)))) {
|
2010-04-08 11:50:05 -07:00
|
|
|
|
2010-04-13 13:14:44 -07:00
|
|
|
let point = rect.center();
|
|
|
|
x = point.x;
|
|
|
|
y = point.y;
|
2010-04-08 11:50:05 -07:00
|
|
|
}
|
|
|
|
|
2010-04-13 13:14:44 -07:00
|
|
|
x = x - scrollX.value;
|
|
|
|
y = y - scrollY.value;
|
2010-04-08 11:50:05 -07:00
|
|
|
cwu.sendMouseEvent(name, x, y, 0, 1, 0, true);
|
2009-09-01 20:39:39 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-11 11:41:28 -08:00
|
|
|
/** Returns a node if selecting this node causes a focus. */
|
2009-12-15 12:37:02 -08:00
|
|
|
_getFocusable: function _getFocusable(node) {
|
2010-04-08 11:50:05 -07:00
|
|
|
if (node && node.mozMatchesSelector("*:link,*:visited,*:link *,*:visited *,*[role=button],button,input,option,select,textarea,label"))
|
2009-12-11 11:41:28 -08:00
|
|
|
return node;
|
|
|
|
return null;
|
|
|
|
},
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2010-03-11 06:18:41 -08:00
|
|
|
_showCanvas: function _showCanvas(cX, cY) {
|
2009-12-11 11:41:28 -08:00
|
|
|
// This code is sensitive to performance. Please profile changes you make to
|
|
|
|
// keep this running fast.
|
|
|
|
let bv = this._browserView;
|
|
|
|
let overlay = this._overlay;
|
|
|
|
let ctx = overlay.getContext("2d");
|
|
|
|
let [elementX, elementY] = Browser.transformClientToBrowser(cX, cY);
|
|
|
|
let element = this._getFocusable(Browser.elementFromPoint(elementX, elementY));
|
|
|
|
if (!element)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let rects = Browser.getContentClientRects(element);
|
|
|
|
let union = rects.reduce(function(a, b) {
|
|
|
|
return a.expandToContain(b);
|
|
|
|
}, new Rect(0, 0, 0, 0)).map(bv.browserToViewport);
|
|
|
|
|
|
|
|
let vis = Browser.getVisibleRect();
|
|
|
|
let canvasArea = vis.intersect(union);
|
|
|
|
this._ensureSize(canvasArea.width, canvasArea.height);
|
|
|
|
|
|
|
|
ctx.save();
|
|
|
|
ctx.translate(-canvasArea.left, -canvasArea.top);
|
|
|
|
bv.browserToViewportCanvasContext(ctx);
|
|
|
|
|
|
|
|
overlay.style.left = canvasArea.left + "px";
|
|
|
|
overlay.style.top = canvasArea.top + "px";
|
|
|
|
ctx.fillStyle = "rgba(0, 145, 255, .5)";
|
|
|
|
let rect;
|
2009-12-15 09:40:19 -08:00
|
|
|
let i;
|
|
|
|
for (i = rects.length - 1; i >= 0; i--) {
|
2009-12-11 11:41:28 -08:00
|
|
|
rect = rects[i];
|
|
|
|
ctx.fillRect(rect.left, rect.top, rect.width, rect.height);
|
|
|
|
}
|
|
|
|
ctx.restore();
|
|
|
|
overlay.style.display = "block";
|
2009-09-01 20:39:39 -07:00
|
|
|
},
|
|
|
|
|
2010-03-11 06:18:41 -08:00
|
|
|
/** Stop highlighting current element. */
|
|
|
|
_hideCanvas: function _hideCanvas() {
|
|
|
|
let overlay = this._overlay;
|
|
|
|
overlay.style.display = "none";
|
|
|
|
overlay.getContext("2d").clearRect(0, 0, this._width, this._height);
|
|
|
|
|
|
|
|
if (this._overlayTimeout) {
|
|
|
|
clearTimeout(this._overlayTimeout);
|
|
|
|
this._overlayTimeout = 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Make sure canvas is at least width x height. */
|
|
|
|
_ensureSize: function _ensureSize(width, height) {
|
|
|
|
if (this._width <= width) {
|
|
|
|
this._width = width;
|
|
|
|
this._overlay.width = width;
|
|
|
|
}
|
|
|
|
if (this._height <= height) {
|
|
|
|
this._height = height;
|
|
|
|
this._overlay.height = height;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mouseDown: function mouseDown(cX, cY) {
|
|
|
|
if (!this._overlayTimeout)
|
|
|
|
this._overlayTimeout = setTimeout(function(self) { self._showCanvas(cX, cY); }, kTapOverlayTimeout, this);
|
|
|
|
},
|
|
|
|
|
2009-09-01 20:39:39 -07:00
|
|
|
mouseUp: function mouseUp(cX, cY) {
|
|
|
|
},
|
|
|
|
|
2009-12-11 11:41:28 -08:00
|
|
|
panBegin: function panBegin() {
|
|
|
|
this._hideCanvas();
|
|
|
|
},
|
|
|
|
|
2009-10-23 09:02:40 -07:00
|
|
|
singleClick: function singleClick(cX, cY, modifiers) {
|
2009-12-11 11:41:28 -08:00
|
|
|
this._hideCanvas();
|
|
|
|
|
2009-11-27 21:37:01 -08:00
|
|
|
let [elementX, elementY] = Browser.transformClientToBrowser(cX, cY);
|
|
|
|
let element = Browser.elementFromPoint(elementX, elementY);
|
2009-10-23 09:02:40 -07:00
|
|
|
if (modifiers == 0) {
|
2009-11-27 21:37:01 -08:00
|
|
|
if (element instanceof HTMLOptionElement)
|
|
|
|
element = element.parentNode;
|
|
|
|
|
2010-03-30 10:56:06 -07:00
|
|
|
if (gPrefService.getBoolPref("formhelper.enabled")) {
|
|
|
|
if (FormHelper.canShowUIFor(element) && FormHelper.open(element))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (SelectHelper.canShowUIFor(element)) {
|
|
|
|
SelectHelper.show(element);
|
2009-11-27 21:37:01 -08:00
|
|
|
return;
|
2010-03-30 10:56:06 -07:00
|
|
|
}
|
2009-11-27 21:37:01 -08:00
|
|
|
|
2010-04-01 14:17:43 -07:00
|
|
|
gFocusManager.setFocus(element, Ci.nsIFocusManager.FLAG_NOSCROLL);
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
Util.executeSoon(function() {
|
2010-04-08 11:50:05 -07:00
|
|
|
self._dispatchMouseEvent(element, "mousedown", cX, cY);
|
|
|
|
self._dispatchMouseEvent(element, "mouseup", cX, cY);
|
2010-04-01 14:17:43 -07:00
|
|
|
});
|
2009-10-23 09:02:40 -07:00
|
|
|
}
|
|
|
|
else if (modifiers == Ci.nsIDOMNSEvent.CONTROL_MASK) {
|
|
|
|
let uri = Util.getHrefForElement(element);
|
|
|
|
if (uri)
|
|
|
|
Browser.addTab(uri, false);
|
|
|
|
}
|
2009-09-01 20:39:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
doubleClick: function doubleClick(cX1, cY1, cX2, cY2) {
|
2009-12-11 11:41:28 -08:00
|
|
|
this._hideCanvas();
|
|
|
|
|
2009-10-23 22:06:29 -07:00
|
|
|
const kDoubleClickRadius = 32;
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-10-23 22:06:29 -07:00
|
|
|
let maxRadius = kDoubleClickRadius * Browser._browserView.getZoomLevel();
|
|
|
|
let isClickInRadius = (Math.abs(cX1 - cX2) < maxRadius && Math.abs(cY1 - cY2) < maxRadius);
|
|
|
|
if (isClickInRadius && !Browser.zoomToPoint(cX1, cY1))
|
|
|
|
Browser.zoomFromPoint(cX1, cY1);
|
2009-09-01 20:39:39 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
toString: function toString() {
|
|
|
|
return "[ContentCustomClicker] { }";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-04-08 11:50:05 -07:00
|
|
|
/** Watches for mouse click in content and redirect them to the best found target **/
|
|
|
|
const ElementTouchHelper = {
|
2010-04-10 20:55:05 -07:00
|
|
|
get radius() {
|
|
|
|
delete this.radius;
|
|
|
|
return this.radius = { "top": gPrefService.getIntPref("browser.ui.touch.top"),
|
|
|
|
"right": gPrefService.getIntPref("browser.ui.touch.right"),
|
|
|
|
"bottom": gPrefService.getIntPref("browser.ui.touch.bottom"),
|
|
|
|
"left": gPrefService.getIntPref("browser.ui.touch.left")
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
get weight() {
|
|
|
|
delete this.weight;
|
|
|
|
return this.weight = { "visited": gPrefService.getIntPref("browser.ui.touch.weight.visited")
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2010-04-08 11:50:05 -07:00
|
|
|
/* Retrieve the closest element to a point by looking at borders position */
|
|
|
|
getClosest: function getClosest(aWindowUtils, aX, aY) {
|
|
|
|
let target = aWindowUtils.elementFromPoint(aX, aY,
|
|
|
|
true, /* ignore root scroll frame*/
|
|
|
|
false); /* don't flush layout */
|
|
|
|
|
2010-05-12 09:17:54 -07:00
|
|
|
let nodes = aWindowUtils.nodesFromRect(aX, aY, this.radius.top,
|
2010-04-10 20:55:05 -07:00
|
|
|
this.radius.right,
|
2010-05-12 09:17:54 -07:00
|
|
|
this.radius.bottom,
|
2010-04-10 20:55:05 -07:00
|
|
|
this.radius.left, true, false);
|
2010-04-08 11:50:05 -07:00
|
|
|
|
2010-05-04 08:15:57 -07:00
|
|
|
// return early if the click is just over a clickable element
|
|
|
|
if (this._isElementClickable(target, nodes))
|
|
|
|
return target;
|
|
|
|
|
2010-04-08 11:50:05 -07:00
|
|
|
let threshold = Number.POSITIVE_INFINITY;
|
|
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
|
|
let current = nodes[i];
|
|
|
|
if (!current.mozMatchesSelector || !this._isElementClickable(current))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let rect = current.getBoundingClientRect();
|
|
|
|
let distance = this._computeDistanceFromRect(aX, aY, rect);
|
|
|
|
|
|
|
|
// increase a little bit the weight for already visited items
|
|
|
|
if (current && current.mozMatchesSelector("*:visited"))
|
2010-04-10 20:55:05 -07:00
|
|
|
distance *= (this.weight.visited / 100);
|
2010-04-08 11:50:05 -07:00
|
|
|
|
|
|
|
if (distance < threshold) {
|
|
|
|
target = current;
|
|
|
|
threshold = distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
},
|
|
|
|
|
2010-05-04 08:15:57 -07:00
|
|
|
_els: Cc["@mozilla.org/eventlistenerservice;1"].getService(Ci.nsIEventListenerService),
|
|
|
|
_clickableEvents: ["mousedown", "mouseup", "click"],
|
|
|
|
_hasMouseListener: function _hasMouseListener(aElement) {
|
|
|
|
let els = this._els;
|
|
|
|
let listeners = els.getListenerInfoFor(aElement, {});
|
|
|
|
for (let i = 0; i < listeners.length; i++) {
|
|
|
|
if (this._clickableEvents.indexOf(listeners[i].type) != -1)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_isElementClickable: function _isElementClickable(aElement, aElementsInRect) {
|
|
|
|
let isClickable = this._hasMouseListener(aElement);
|
|
|
|
|
|
|
|
// If possible looks in the parents node to find a target
|
2010-05-14 09:14:04 -07:00
|
|
|
if (aElement && !isClickable && aElementsInRect) {
|
2010-05-04 08:15:57 -07:00
|
|
|
let parentNode = aElement.parentNode;
|
|
|
|
let count = aElementsInRect.length;
|
|
|
|
for (let i = 0; i < count && parentNode; i++) {
|
|
|
|
if (aElementsInRect[i] != parentNode)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
isClickable = this._hasMouseListener(parentNode);
|
|
|
|
if (isClickable)
|
|
|
|
break;
|
|
|
|
|
|
|
|
parentNode = parentNode.parentNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aElement && (isClickable || aElement.mozMatchesSelector("*:link,*:visited,*[role=button],button,input,select,label"));
|
2010-04-08 11:50:05 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_computeDistanceFromRect: function _computeDistanceFromRect(aX, aY, aRect) {
|
|
|
|
let x = 0, y = 0;
|
|
|
|
let xmost = aRect.left + aRect.width;
|
|
|
|
let ymost = aRect.top + aRect.height;
|
|
|
|
|
|
|
|
// compute horizontal distance from left/right border depending if X is
|
|
|
|
// before/inside/after the element's rectangle
|
|
|
|
if (aRect.left < aX && aX < xmost)
|
|
|
|
x = Math.min(xmost - aX, aX - aRect.left);
|
|
|
|
else if (aX < aRect.left)
|
|
|
|
x = aRect.left - aX;
|
|
|
|
else if (aX > xmost)
|
|
|
|
x = aX - xmost;
|
|
|
|
|
|
|
|
// compute vertical distance from top/bottom border depending if Y is
|
|
|
|
// above/inside/below the element's rectangle
|
|
|
|
if (aRect.top < aY && aY < ymost)
|
|
|
|
y = Math.min(ymost - aY, aY - aRect.top);
|
|
|
|
else if (aY < aRect.top)
|
|
|
|
y = aRect.top - aY;
|
|
|
|
if (aY > ymost)
|
|
|
|
y = aY - ymost;
|
|
|
|
|
|
|
|
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
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");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to parse out the important parts of _lastStatus (of the SSL cert in
|
|
|
|
* particular) for use in constructing identity UI strings
|
2009-09-10 06:24:48 -07:00
|
|
|
*/
|
2008-11-21 21:12:25 -08:00
|
|
|
getIdentityData: function() {
|
2008-06-20 14:01:42 -07:00
|
|
|
var result = {};
|
2009-03-31 11:45:24 -07:00
|
|
|
var status = this._lastStatus.QueryInterface(Ci.nsISSLStatus);
|
2008-06-20 14:01:42 -07:00
|
|
|
var cert = status.serverCert;
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Human readable name of Subject
|
|
|
|
result.subjectOrg = cert.organization;
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// SubjectName fields, broken up for individual access
|
|
|
|
if (cert.subjectName) {
|
|
|
|
result.subjectNameFields = {};
|
|
|
|
cert.subjectName.split(",").forEach(function(v) {
|
|
|
|
var field = v.split("=");
|
|
|
|
this[field[0]] = field[1];
|
|
|
|
}, result.subjectNameFields);
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Call out city, state, and country specifically
|
|
|
|
result.city = result.subjectNameFields.L;
|
|
|
|
result.state = result.subjectNameFields.ST;
|
|
|
|
result.country = result.subjectNameFields.C;
|
|
|
|
}
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Human readable name of Certificate Authority
|
|
|
|
result.caOrg = cert.issuerOrganization || cert.issuerCommonName;
|
|
|
|
result.cert = cert;
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
return result;
|
|
|
|
},
|
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() {
|
|
|
|
let state = Browser.selectedTab.getIdentityState();
|
|
|
|
let location = getBrowser().contentWindow.location;
|
|
|
|
let currentStatus = getBrowser().securityUI.QueryInterface(Ci.nsISSLStatusProvider).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 = {};
|
|
|
|
try {
|
2009-09-10 07:17:38 -07:00
|
|
|
// make a copy of the passed in location to avoid cycles
|
2009-09-10 06:24:48 -07:00
|
|
|
this._lastLocation = { host: location.host, hostname: location.hostname, port: location.port };
|
|
|
|
} catch (ex) { }
|
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
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Check whether this site is a security exception. XPConnect does the right
|
|
|
|
// thing here in terms of converting _lastLocation.port from string to int, but
|
|
|
|
// the overrideService doesn't like undefined ports, so make sure we have
|
|
|
|
// something in the default case (bug 432241).
|
2008-07-08 18:24:49 -07:00
|
|
|
if (this._overrideService.hasMatchingOverride(this._lastLocation.hostname,
|
2008-06-20 14:01:42 -07:00
|
|
|
(this._lastLocation.port || 443),
|
|
|
|
iData.cert, {}, {}))
|
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
|
|
|
|
|
|
|
// Update the search engines results
|
|
|
|
BrowserSearch.updatePageSearchEngines();
|
2010-03-24 12:55:09 -07:00
|
|
|
|
|
|
|
// Update the per site permissions results
|
|
|
|
PageActions.updatePagePermissions();
|
2010-04-05 07:48:52 -07:00
|
|
|
|
|
|
|
PageActions.updatePageSaveAs();
|
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
|
|
|
|
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() {
|
|
|
|
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
|
|
|
*/
|
2008-11-21 21:12:25 -08:00
|
|
|
handleIdentityButtonEvent: function(event) {
|
2008-06-20 14:01:42 -07:00
|
|
|
event.stopPropagation();
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
if ((event.type == "click" && event.button != 0) ||
|
|
|
|
(event.type == "keypress" && event.charCode != KeyEvent.DOM_VK_SPACE &&
|
|
|
|
event.keyCode != KeyEvent.DOM_VK_RETURN))
|
|
|
|
return; // Left click, space or enter only
|
|
|
|
|
2010-04-27 13:33:59 -07:00
|
|
|
this.toggle();
|
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-03-31 11:45:24 -07:00
|
|
|
_kIPM: Ci.nsIPermissionManager,
|
2008-07-11 11:51:28 -07:00
|
|
|
|
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;
|
|
|
|
|
2009-09-01 10:02:19 -07:00
|
|
|
let pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
|
|
|
|
let result = pm.testExactPermission(Browser.selectedBrowser.currentURI, "popup");
|
|
|
|
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) {
|
|
|
|
if(gPrefService.getBoolPref("privacy.popups.showBrowserMessage")) {
|
|
|
|
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,
|
2009-09-01 10:02:19 -07:00
|
|
|
callback: function() { gPopupBlockerObserver.allowPopupsForSite(); }
|
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,
|
2009-09-01 10:02:19 -07:00
|
|
|
callback: function() { gPopupBlockerObserver.denyPopupsForSite(); }
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-01 10:02:19 -07:00
|
|
|
allowPopupsForSite: function allowPopupsForSite(aEvent) {
|
|
|
|
var currentURI = Browser.selectedBrowser.currentURI;
|
2009-03-31 11:45:24 -07:00
|
|
|
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(this._kIPM);
|
2008-07-11 11:51:28 -07:00
|
|
|
pm.add(currentURI, "popup", this._kIPM.ALLOW_ACTION);
|
|
|
|
|
|
|
|
Browser.getNotificationBox().removeCurrentNotification();
|
|
|
|
},
|
|
|
|
|
2009-09-01 10:02:19 -07:00
|
|
|
denyPopupsForSite: function denyPopupsForSite(aEvent) {
|
|
|
|
var currentURI = Browser.selectedBrowser.currentURI;
|
|
|
|
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(this._kIPM);
|
|
|
|
pm.add(currentURI, "popup", this._kIPM.DENY_ACTION);
|
|
|
|
|
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
|
|
|
|
2009-08-12 09:28:51 -07:00
|
|
|
Browser.addTab(popupURIspec, false);
|
|
|
|
}
|
|
|
|
}
|
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 {
|
|
|
|
enabled = gPrefService.getBoolPref("xpinstall.enabled");
|
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
if (!enabled) {
|
2009-06-29 11:33:05 -07:00
|
|
|
notificationName = "xpinstall-disabled";
|
2008-08-19 19:18:36 -07:00
|
|
|
if (gPrefService.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() {
|
|
|
|
gPrefService.setBoolPref("xpinstall.enabled", true);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-04 01:59:57 -07:00
|
|
|
var FormSubmitObserver = {
|
|
|
|
notify: function notify(aFormElement, aWindow, aActionURI, aCancelSubmit) {
|
|
|
|
let doc = aWindow.content.top.document;
|
|
|
|
let tab = Browser.getTabForDocument(doc);
|
|
|
|
if (tab)
|
2010-06-04 06:15:13 -07:00
|
|
|
tab.browser.lastLocation = null;
|
2010-06-04 01:59:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface : function(aIID) {
|
|
|
|
if (!aIID.equals(Ci.nsIFormSubmitObserver) &&
|
|
|
|
!aIID.equals(Ci.nsISupports))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
var MemoryObserver = {
|
2009-12-15 12:37:02 -08:00
|
|
|
observe: function mo_observe() {
|
2009-09-04 22:14:59 -07:00
|
|
|
let memory = Cc["@mozilla.org/xpcom/memory-service;1"].getService(Ci.nsIMemory);
|
|
|
|
do {
|
2010-01-14 13:08:40 -08:00
|
|
|
Browser.windowUtils.garbageCollect();
|
2009-09-04 22:14:59 -07:00
|
|
|
} while (memory.isLowMemory() && Browser.sacrificeTab());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-08-18 12:59:14 -07:00
|
|
|
function getNotificationBox(aWindow) {
|
|
|
|
return Browser.getNotificationBox();
|
2008-08-19 19:18:36 -07:00
|
|
|
}
|
2008-11-21 21:12:25 -08:00
|
|
|
|
2009-10-12 12:05:46 -07:00
|
|
|
function importDialog(parent, src, arguments) {
|
2009-09-02 07:15:22 -07:00
|
|
|
// load the dialog with a synchronous XHR
|
|
|
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
|
|
|
|
xhr.open("GET", src, false);
|
|
|
|
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;
|
|
|
|
let nodeIterator = xhr.responseXML.createNodeIterator(xhr.responseXML,
|
|
|
|
NodeFilter.SHOW_TEXT,
|
|
|
|
null,
|
|
|
|
false);
|
|
|
|
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
|
|
|
|
2009-09-02 07:15:22 -07:00
|
|
|
// we need to insert before select-container if we want it to show correctly
|
|
|
|
let selectContainer = document.getElementById("select-container");
|
|
|
|
let parent = selectContainer.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);
|
|
|
|
let dispatcher = parent || getBrowser();
|
|
|
|
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));
|
|
|
|
parent.insertBefore(back, selectContainer);
|
2010-01-14 13:08:40 -08:00
|
|
|
|
2009-09-02 07:15:22 -07:00
|
|
|
dialog.arguments = arguments;
|
2009-10-12 12:05:46 -07:00
|
|
|
dialog.parent = parent;
|
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,
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
let container = document.getElementById("alerts-container");
|
|
|
|
container.hidden = false;
|
|
|
|
|
|
|
|
let rect = container.getBoundingClientRect();
|
|
|
|
container.top = window.innerHeight - (rect.height + 20);
|
|
|
|
container.left = window.innerWidth - (rect.width + 20);
|
|
|
|
|
|
|
|
let timeout = gPrefService.getIntPref("alerts.totalOpenTime");
|
|
|
|
let self = this;
|
|
|
|
this._timeoutID = setTimeout(function() { self._timeoutAlert(); }, timeout);
|
|
|
|
},
|
|
|
|
|
|
|
|
_timeoutAlert: function ah__timeoutAlert() {
|
|
|
|
this._timeoutID = -1;
|
|
|
|
let container = document.getElementById("alerts-container");
|
|
|
|
container.hidden = true;
|
|
|
|
|
|
|
|
if (this._listener)
|
|
|
|
this._listener.observe(null, "alertfinished", this._cookie);
|
|
|
|
|
|
|
|
// TODO: add slide to UI
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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
|
|
|
// broadcast a URLChanged message for consumption by InputHandler
|
|
|
|
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
|
|
|
|
2009-09-10 06:24:48 -07:00
|
|
|
if (this._tab == Browser.selectedTab) {
|
2008-11-21 21:12:25 -08:00
|
|
|
BrowserUI.update(TOOLBARSTATE_LOADED);
|
2009-02-05 23:35:29 -08:00
|
|
|
this.browser.docShell.isOffScreenBrowser = true;
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
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() {
|
|
|
|
if (this._tab == Browser.selectedTab) {
|
|
|
|
// XXX Sometimes MozScrollSizeChange has not occurred, so the scroll pane will not
|
|
|
|
// be resized yet. We are assuming this event is on the queue, so scroll the pane
|
|
|
|
// "soon."
|
|
|
|
Util.executeSoon(function() {
|
|
|
|
let scroll = Browser.getScrollboxPosition(Browser.contentScrollboxScroller);
|
|
|
|
if (scroll.isZero())
|
|
|
|
Browser.scrollContentToBrowser();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let scroll = BrowserView.Util.getContentScrollOffset(this._tab.browser);
|
2010-03-25 21:18:20 -07:00
|
|
|
this._tab.contentScrollOffset = new Point(scroll.x, scroll.y);
|
2010-05-05 09:47:12 -07:00
|
|
|
|
|
|
|
// If the document content is scrolled to the top, make sure the URLbar is in view.
|
|
|
|
// If this were the selected tab, onLocationChange would scroll to top.
|
|
|
|
if (scroll.isZero())
|
|
|
|
this._tab.pageScrollOffset = new Point(0, 0);
|
2010-01-11 03:11:20 -08:00
|
|
|
}
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-10-14 13:36:47 -07:00
|
|
|
var OfflineApps = {
|
|
|
|
get _pm() {
|
|
|
|
delete this._pm;
|
|
|
|
return this._pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
|
|
|
|
},
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
offlineAppRequested: function(aRequest) {
|
2009-10-14 13:36:47 -07:00
|
|
|
if (!gPrefService.getBoolPref("browser.offline-apps.notify"))
|
|
|
|
return;
|
|
|
|
|
2010-06-08 08:22:20 -07:00
|
|
|
let currentURI = gIOService.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
|
|
|
|
if (this._pm.testExactPermission(currentURI, "offline-app") != Ci.nsIPermissionManager.UNKNOWN_ACTION)
|
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (gPrefService.getBoolPref("offline-apps.allow_by_default")) {
|
|
|
|
// 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) {
|
|
|
|
let currentURI = gIOService.newURI(aRequest.location, aRequest.charset, null);
|
|
|
|
this._pm.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) {
|
|
|
|
let currentURI = gIOService.newURI(aRequest.location, aRequest.charset, null);
|
|
|
|
this._pm.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) {
|
|
|
|
let currentURI = gIOService.newURI(aRequest.location, aRequest.charset, null);
|
|
|
|
let manifestURI = gIOService.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-08 08:22:20 -07:00
|
|
|
if (aMessage.name == "MozApplicationManifest") {
|
|
|
|
this.offlineAppRequested(aMessage.json);
|
|
|
|
}
|
2009-10-14 13:36:47 -07:00
|
|
|
}
|
|
|
|
};
|
2008-11-21 21:12:25 -08:00
|
|
|
|
|
|
|
function Tab() {
|
2009-08-11 13:51:13 -07:00
|
|
|
this._id = null;
|
|
|
|
this._browser = null;
|
|
|
|
this._browserViewportState = null;
|
|
|
|
this._state = null;
|
|
|
|
this._listener = null;
|
|
|
|
this._loading = false;
|
|
|
|
this._chromeTab = null;
|
2009-12-10 09:55:27 -08:00
|
|
|
this._resizeAndPaint = Util.bind(this._resizeAndPaint, this);
|
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;
|
|
|
|
|
2009-07-17 16:17:57 -07:00
|
|
|
this.create();
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Tab.prototype = {
|
|
|
|
get browser() {
|
|
|
|
return this._browser;
|
|
|
|
},
|
|
|
|
|
2009-08-11 13:51:13 -07:00
|
|
|
get browserViewportState() {
|
|
|
|
return this._browserViewportState;
|
|
|
|
},
|
|
|
|
|
2009-06-04 07:57:56 -07:00
|
|
|
get chromeTab() {
|
|
|
|
return this._chromeTab;
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
/**
|
2009-11-24 13:59:35 -08:00
|
|
|
* Throttles redraws to once every 2 seconds while loading the page, zooming to fit page if
|
2009-09-04 22:14:59 -07:00
|
|
|
* user hasn't started zooming.
|
|
|
|
*/
|
2009-12-15 12:37:02 -08:00
|
|
|
_resizeAndPaint: function _resizeAndPaint() {
|
2009-08-12 17:41:31 -07:00
|
|
|
let bv = Browser._browserView;
|
2009-12-15 11:59:01 -08:00
|
|
|
|
2009-08-12 17:41:31 -07:00
|
|
|
bv.commitBatchOperation();
|
2009-12-10 09:55:27 -08:00
|
|
|
|
2009-12-15 11:59:01 -08:00
|
|
|
// kick ourselves off 2s later while we're still loading
|
|
|
|
bv.beginBatchOperation();
|
|
|
|
this._loadingTimeout = setTimeout(this._resizeAndPaint, 2000);
|
2009-12-10 09:55:27 -08:00
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
_startResizeAndPaint: function _startResizeAndPaint() {
|
2009-12-15 11:59:01 -08:00
|
|
|
if (this._loadingTimeout)
|
|
|
|
throw "Already have a loading timeout";
|
|
|
|
|
|
|
|
Browser._browserView.beginBatchOperation();
|
2009-12-10 09:55:27 -08:00
|
|
|
this._loadingTimeout = setTimeout(this._resizeAndPaint, 2000);
|
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
_stopResizeAndPaint: function _stopResizeAndPaint() {
|
2009-12-15 11:59:01 -08:00
|
|
|
if (!this._loadingTimeout)
|
|
|
|
throw "No loading timeout!";
|
|
|
|
|
|
|
|
clearTimeout(this._loadingTimeout);
|
|
|
|
delete this._loadingTimeout;
|
|
|
|
Browser._browserView.commitBatchOperation();
|
2009-08-12 17:41:31 -07:00
|
|
|
},
|
|
|
|
|
2010-05-05 12:51:58 -07:00
|
|
|
/** Update browser styles when the viewport metadata changes. */
|
2010-06-09 16:07:12 -07:00
|
|
|
updateViewportMetadata: function updateViewportMetadata(metaData) {
|
2010-05-05 12:51:58 -07:00
|
|
|
let browser = this._browser;
|
|
|
|
if (!browser)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._browserViewportState.metaData = metaData;
|
|
|
|
|
|
|
|
// Remove any previous styles.
|
|
|
|
browser.className = "";
|
|
|
|
browser.style.removeProperty("width");
|
|
|
|
browser.style.removeProperty("height");
|
|
|
|
|
|
|
|
// Add classes for auto-sizing viewports.
|
|
|
|
if (metaData.autoSize) {
|
|
|
|
if (metaData.defaultZoom == 1.0) {
|
|
|
|
browser.classList.add("window-width");
|
|
|
|
browser.classList.add("window-height");
|
|
|
|
} else {
|
|
|
|
browser.classList.add("viewport-width");
|
|
|
|
browser.classList.add("viewport-height");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.updateViewportSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Update browser size when the metadata or the window size changes. */
|
|
|
|
updateViewportSize: function updateViewportSize() {
|
|
|
|
let browser = this._browser;
|
2010-05-27 13:01:41 -07:00
|
|
|
if (!browser)
|
2010-05-05 12:51:58 -07:00
|
|
|
return;
|
|
|
|
|
2010-05-27 13:01:41 -07:00
|
|
|
let metaData = this._browserViewportState.metaData || {};
|
2010-05-05 12:51:58 -07:00
|
|
|
if (!metaData.autoSize) {
|
|
|
|
let screenW = window.innerWidth;
|
|
|
|
let screenH = window.innerHeight;
|
|
|
|
let viewportW = metaData.width;
|
|
|
|
let viewportH = metaData.height;
|
|
|
|
|
|
|
|
// If (scale * width) < device-width, increase the width (bug 561413).
|
|
|
|
let maxInitialZoom = metaData.defaultZoom || metaData.maxZoom;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
browser.style.width = viewportW + "px";
|
|
|
|
browser.style.height = viewportH + "px";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some documents are not firing MozScrolledAreaChanged and/or fired it for
|
|
|
|
// sub-documents only
|
|
|
|
let doc = browser.contentDocument;
|
|
|
|
if (doc instanceof XULDocument || doc.body instanceof HTMLFrameSetElement) {
|
|
|
|
let [width, height] = BrowserView.Util.getBrowserDimensions(browser);
|
|
|
|
BrowserView.Util.ensureMozScrolledAreaEvent(browser, width, height);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-10 06:24:48 -07:00
|
|
|
/** Returns tab's identity state for updating security UI. */
|
2009-12-15 12:37:02 -08:00
|
|
|
getIdentityState: function getIdentityState() {
|
2009-09-10 06:24:48 -07:00
|
|
|
return this._listener.state;
|
|
|
|
},
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!this._loadingTimeout) {
|
2009-12-10 10:17:39 -08:00
|
|
|
let bv = Browser._browserView;
|
2009-12-15 11:59:01 -08:00
|
|
|
|
|
|
|
this._startResizeAndPaint();
|
2010-01-11 03:11:20 -08:00
|
|
|
if (this == Browser.selectedTab) {
|
2010-01-15 10:42:22 -08:00
|
|
|
bv.invalidateEntireView();
|
2009-12-10 10:17:39 -08:00
|
|
|
bv.setAggressive(false);
|
2010-01-11 03:11:20 -08:00
|
|
|
// Sync up browser so previous and forward scroll positions are set. This is a good time to do
|
|
|
|
// this because the resulting invalidation is irrelevant.
|
2010-01-14 12:44:28 -08:00
|
|
|
bv.ignorePageScroll(true);
|
2010-01-11 03:11:20 -08:00
|
|
|
Browser.scrollBrowserToContent();
|
|
|
|
}
|
2009-08-12 17:41:31 -07:00
|
|
|
}
|
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!";
|
|
|
|
|
2010-05-05 12:51:58 -07:00
|
|
|
this.setIcon(this._browser.mIconURL);
|
2009-08-12 17:41:31 -07:00
|
|
|
this._loading = false;
|
2009-09-04 22:14:59 -07:00
|
|
|
|
2010-01-14 12:44:28 -08:00
|
|
|
if (this == Browser.selectedTab) {
|
|
|
|
let bv = Browser._browserView;
|
|
|
|
bv.ignorePageScroll(false);
|
|
|
|
bv.setAggressive(true);
|
|
|
|
}
|
2009-12-10 10:17:39 -08:00
|
|
|
|
2009-12-10 09:55:27 -08:00
|
|
|
this._stopResizeAndPaint();
|
2009-12-15 12:37:02 -08:00
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
// if this tab was sacrificed previously, restore its state
|
|
|
|
this.restoreState();
|
2009-08-12 17:41:31 -07:00
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
load: function load(uri) {
|
2009-07-17 16:17:57 -07:00
|
|
|
this._browser.setAttribute("src", uri);
|
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
create: function create() {
|
2009-09-04 22:14:59 -07:00
|
|
|
// Initialize a viewport state for BrowserView
|
|
|
|
this._browserViewportState = BrowserView.Util.createBrowserViewportState();
|
|
|
|
|
2009-09-09 20:32:13 -07:00
|
|
|
this._chromeTab = document.getElementById("tabs").addTab();
|
2009-07-17 16:17:57 -07:00
|
|
|
this._createBrowser();
|
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
|
|
|
},
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
/** Create browser if it doesn't already exist. */
|
2009-12-15 12:37:02 -08:00
|
|
|
ensureBrowserExists: function ensureBrowserExists() {
|
2009-09-04 22:14:59 -07:00
|
|
|
if (!this._browser) {
|
|
|
|
this._createBrowser();
|
|
|
|
this.browser.contentDocument.location = this._state._url;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
_createBrowser: function _createBrowser() {
|
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");
|
2009-07-17 16:17:57 -07:00
|
|
|
|
2009-10-14 14:19:29 -07:00
|
|
|
browser.setAttribute("style", "overflow: -moz-hidden-unscrollable; visibility: hidden;");
|
2009-06-04 07:57:56 -07:00
|
|
|
browser.setAttribute("type", "content");
|
2010-06-08 08:22:20 -07:00
|
|
|
browser.setAttribute("remote", "false");
|
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);
|
|
|
|
|
2009-07-22 06:12:02 -07:00
|
|
|
// stop about:blank from loading
|
|
|
|
browser.stop();
|
|
|
|
|
2009-06-04 07:57:56 -07:00
|
|
|
// Attach a separate progress listener to the browser
|
2009-12-17 11:16:29 -08:00
|
|
|
let flags = Ci.nsIWebProgress.NOTIFY_LOCATION |
|
|
|
|
Ci.nsIWebProgress.NOTIFY_SECURITY |
|
2010-01-11 03:11:20 -08:00
|
|
|
Ci.nsIWebProgress.NOTIFY_STATE_NETWORK |
|
|
|
|
Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT;
|
2008-11-21 21:12:25 -08:00
|
|
|
this._listener = new ProgressController(this);
|
2009-12-17 11:16:29 -08:00
|
|
|
browser.webProgress.addProgressListener(this._listener, flags);
|
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
|
|
|
|
|
|
|
try { // this will throw if we're not loading
|
|
|
|
this._stopResizeAndPaint();
|
|
|
|
} catch(ex) {}
|
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
|
|
|
},
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
/** Serializes as much state as possible of the current content. */
|
2009-12-15 12:37:02 -08:00
|
|
|
saveState: function saveState() {
|
2008-11-21 21:12:25 -08:00
|
|
|
let state = { };
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
var browser = this._browser;
|
2008-11-21 21:12:25 -08:00
|
|
|
var doc = browser.contentDocument;
|
2009-09-04 22:14:59 -07:00
|
|
|
state._url = doc.location.href;
|
2009-10-15 12:50:32 -07:00
|
|
|
state._scroll = BrowserView.Util.getContentScrollOffset(this.browser);
|
2008-11-21 21:12:25 -08:00
|
|
|
if (doc instanceof HTMLDocument) {
|
|
|
|
var tags = ["input", "textarea", "select"];
|
|
|
|
|
|
|
|
for (var t = 0; t < tags.length; t++) {
|
|
|
|
var elements = doc.getElementsByTagName(tags[t]);
|
|
|
|
for (var e = 0; e < elements.length; e++) {
|
|
|
|
var element = elements[e];
|
|
|
|
var id;
|
|
|
|
if (element.id)
|
|
|
|
id = "#" + element.id;
|
|
|
|
else if (element.name)
|
|
|
|
id = "$" + element.name;
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
state[id] = element.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._state = state;
|
|
|
|
},
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
/** Restores serialized content from saveState. */
|
2009-12-15 12:37:02 -08:00
|
|
|
restoreState: function restoreState() {
|
2008-11-21 21:12:25 -08:00
|
|
|
let state = this._state;
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let doc = this._browser.contentDocument;
|
2009-09-04 22:14:59 -07:00
|
|
|
|
|
|
|
for (var item in state) {
|
2008-11-21 21:12:25 -08:00
|
|
|
var elem = null;
|
|
|
|
if (item.charAt(0) == "#") {
|
|
|
|
elem = doc.getElementById(item.substring(1));
|
2009-09-04 22:14:59 -07:00
|
|
|
} else if (item.charAt(0) == "$") {
|
2008-11-21 21:12:25 -08:00
|
|
|
var list = doc.getElementsByName(item.substring(1));
|
|
|
|
if (list.length)
|
|
|
|
elem = list[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elem)
|
|
|
|
elem.value = state[item];
|
|
|
|
}
|
|
|
|
|
2009-10-15 12:50:32 -07:00
|
|
|
this.browser.contentWindow.scrollX = state._scroll.x;
|
|
|
|
this.browser.contentWindow.scrollY = state._scroll.y;
|
2009-09-04 22:14:59 -07:00
|
|
|
|
|
|
|
this._state = null;
|
2008-11-21 21:12:25 -08:00
|
|
|
},
|
|
|
|
|
2010-01-14 12:44:28 -08:00
|
|
|
/* Set up the initial zoom level. While the bvs.defaultZoomLevel of a tab is
|
|
|
|
equal to bvs.zoomLevel this mean that not user action has happended and
|
|
|
|
we can safely alter the zoom on a window resize or on a page load
|
|
|
|
*/
|
|
|
|
resetZoomLevel: function resetZoomLevel() {
|
|
|
|
let bvs = this._browserViewportState;
|
|
|
|
bvs.defaultZoomLevel = bvs.zoomLevel;
|
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
updateThumbnail: function updateThumbnail() {
|
2008-11-21 21:12:25 -08:00
|
|
|
if (!this._browser)
|
|
|
|
return;
|
|
|
|
|
2010-04-13 13:10:54 -07:00
|
|
|
let bv = Browser._browserView;
|
|
|
|
let browserView = (Browser.selectedBrowser == this._browser && bv.isDefaultZoom()) ? Browser._browserView
|
|
|
|
: null;
|
2009-08-22 11:06:51 -07:00
|
|
|
this._chromeTab.updateThumbnail(this._browser, browserView);
|
2009-09-04 22:14:59 -07:00
|
|
|
},
|
|
|
|
|
2009-12-15 12:37:02 -08:00
|
|
|
setIcon: function setIcon(aURI) {
|
2009-10-09 05:34:02 -07:00
|
|
|
let faviconURI = null;
|
|
|
|
if (aURI) {
|
|
|
|
try {
|
|
|
|
faviconURI = gIOService.newURI(aURI, null, null);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
faviconURI = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!faviconURI || faviconURI.schemeIs("javascript") || gFaviconService.isFailedFavicon(faviconURI)) {
|
|
|
|
try {
|
2009-10-20 12:16:00 -07:00
|
|
|
// Use documentURIObject in the favicon construction so that we
|
|
|
|
// do the right thing with about:-style error pages. Bug 515188
|
|
|
|
faviconURI = gIOService.newURI(this._browser.contentDocument.documentURIObject.prePath + "/favicon.ico", null, null);
|
2009-10-09 05:34:02 -07:00
|
|
|
gFaviconService.setAndLoadFaviconForPage(this._browser.currentURI, faviconURI, true);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
faviconURI = null;
|
|
|
|
}
|
|
|
|
if (faviconURI && gFaviconService.isFailedFavicon(faviconURI))
|
|
|
|
faviconURI = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._browser.mIconURL = faviconURI ? faviconURI.spec : "";
|
|
|
|
},
|
|
|
|
|
2009-09-04 22:14:59 -07:00
|
|
|
toString: function() {
|
|
|
|
return "[Tab " + (this._browser ? this._browser.contentDocument.location.toString() : "(no browser)") + "]";
|
2008-11-21 21:12:25 -08:00
|
|
|
}
|
2009-06-29 11:33:05 -07:00
|
|
|
};
|
2009-10-29 15:58:40 -07:00
|
|
|
|
|
|
|
var ImagePreloader = {
|
|
|
|
cache: function ip_cache() {
|
|
|
|
// Preload images used in border-image CSS
|
|
|
|
let images = ["button-active", "button-default",
|
|
|
|
"buttondark-active", "buttondark-default",
|
|
|
|
"toggleon-active", "toggleon-inactive",
|
|
|
|
"toggleoff-active", "toggleoff-inactive",
|
|
|
|
"toggleleft-active", "toggleleft-inactive",
|
|
|
|
"togglemiddle-active", "togglemiddle-inactive",
|
|
|
|
"toggleright-active", "toggleright-inactive",
|
|
|
|
"toggleboth-active", "toggleboth-inactive",
|
|
|
|
"toggledarkleft-active", "toggledarkleft-inactive",
|
|
|
|
"toggledarkmiddle-active", "toggledarkmiddle-inactive",
|
|
|
|
"toggledarkright-active", "toggledarkright-inactive",
|
|
|
|
"toggledarkboth-active", "toggledarkboth-inactive",
|
2009-11-12 11:14:57 -08:00
|
|
|
"toolbarbutton-active", "toolbarbutton-default",
|
|
|
|
"addons-active", "addons-default",
|
|
|
|
"downloads-active", "downloads-default",
|
|
|
|
"preferences-active", "preferences-default",
|
|
|
|
"settings-active", "settings-open"];
|
2009-10-29 15:58:40 -07:00
|
|
|
|
|
|
|
let size = screen.width > 400 ? "-64" : "-36";
|
|
|
|
for (let i = 0; i < images.length; i++) {
|
|
|
|
let image = new Image();
|
|
|
|
image.src = "chrome://browser/skin/images/" + images[i] + size + ".png";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-23 23:46:01 -08:00
|
|
|
|
|
|
|
const nsIObjectLoadingContent = Ci.nsIObjectLoadingContent_MOZILLA_1_9_2_BRANCH || Ci.nsIObjectLoadingContent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows fast-path embed rendering by letting objects know where to absolutely
|
|
|
|
* render on the screen.
|
|
|
|
*/
|
|
|
|
function PluginObserver(bv) {
|
|
|
|
this._emptyRect = new Rect(0, 0, 0, 0);
|
|
|
|
this._contentShowing = document.getElementById("observe_contentShowing");
|
|
|
|
this._bv = bv;
|
|
|
|
this._started = false;
|
2009-12-04 12:03:56 -08:00
|
|
|
this._isRendering = false;
|
2010-01-26 14:22:23 -08:00
|
|
|
|
2010-01-26 15:39:31 -08:00
|
|
|
let disabled = gPrefService.getBoolPref("plugin.disable");
|
|
|
|
if (!disabled)
|
2010-01-26 14:22:23 -08:00
|
|
|
this.start();
|
2009-11-23 23:46:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginObserver.prototype = {
|
2009-12-04 12:03:56 -08:00
|
|
|
// When calculating critical rect, subtract N pixels around popup boxes
|
|
|
|
POPUP_PADDING: 4,
|
|
|
|
|
2009-11-23 23:46:01 -08:00
|
|
|
/** Starts flash objects fast path. */
|
|
|
|
start: function() {
|
|
|
|
if (this._started)
|
|
|
|
return;
|
|
|
|
this._started = true;
|
|
|
|
|
|
|
|
document.getElementById("tabs-container").addEventListener("TabSelect", this, false);
|
|
|
|
this._contentShowing.addEventListener("broadcast", this, false);
|
|
|
|
let browsers = document.getElementById("browsers");
|
|
|
|
browsers.addEventListener("RenderStateChanged", this, false);
|
2010-01-26 14:22:24 -08:00
|
|
|
gObserverService.addObserver(this, "plugin-changed-event", false);
|
2009-12-04 12:03:56 -08:00
|
|
|
Elements.stack.addEventListener("PopupChanged", this, false);
|
2009-11-23 23:46:01 -08:00
|
|
|
|
|
|
|
let browser = Browser.selectedBrowser;
|
|
|
|
if (browser) {
|
|
|
|
browser.addEventListener("ZoomChanged", this, false);
|
|
|
|
browser.addEventListener("MozAfterPaint", this, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Stops listening for events. */
|
|
|
|
stop: function() {
|
|
|
|
if (!this._started)
|
|
|
|
return;
|
|
|
|
this._started = false;
|
|
|
|
|
|
|
|
document.getElementById("tabs-container").removeEventListener("TabSelect", this, false);
|
|
|
|
this._contentShowing.removeEventListener("broadcast", this, false);
|
|
|
|
let browsers = document.getElementById("browsers");
|
|
|
|
browsers.removeEventListener("RenderStateChanged", this, false);
|
2010-01-26 14:22:24 -08:00
|
|
|
gObserverService.removeObserver(this, "plugin-changed-event");
|
2009-12-04 12:03:56 -08:00
|
|
|
Elements.stack.removeEventListener("PopupChanged", this, false);
|
2009-11-23 23:46:01 -08:00
|
|
|
|
|
|
|
let browser = Browser.selectedBrowser;
|
|
|
|
if (browser) {
|
|
|
|
browser.removeEventListener("ZoomChanged", this, false);
|
|
|
|
browser.removeEventListener("MozAfterPaint", this, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/** Observe listens for plugin change events and maintains an embed cache. */
|
|
|
|
observe: function observe(subject, topic, data) {
|
2010-01-26 14:22:23 -08:00
|
|
|
if (topic == "plugin-changed-event")
|
|
|
|
this.updateCurrentBrowser();
|
2009-11-23 23:46:01 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/** Update flash objects */
|
|
|
|
handleEvent: function handleEvent(ev) {
|
|
|
|
if (ev.type == "TabSelect") {
|
|
|
|
if (ev.lastTab) {
|
|
|
|
let browser = ev.lastTab.browser;
|
|
|
|
let oldDoc = browser.contentDocument;
|
2010-01-13 10:23:39 -08:00
|
|
|
|
2009-11-23 23:46:01 -08:00
|
|
|
browser.removeEventListener("ZoomChanged", this, false);
|
|
|
|
browser.removeEventListener("MozAfterPaint", this, false);
|
2010-01-22 09:52:24 -08:00
|
|
|
this.updateEmbedRegions(this.getPluginNodes(oldDoc), this._emptyRect);
|
2009-11-23 23:46:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
let browser = Browser.selectedBrowser;
|
|
|
|
browser.addEventListener("ZoomChanged", this, false);
|
|
|
|
browser.addEventListener("MozAfterPaint", this, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateCurrentBrowser();
|
|
|
|
},
|
|
|
|
|
2010-01-22 09:52:24 -08:00
|
|
|
/** Find all embedded objects in document and its frames */
|
|
|
|
getPluginNodes: function getPluginNodes(doc) {
|
|
|
|
let docs = Util.getAllDocuments(doc);
|
|
|
|
let result = [];
|
|
|
|
|
|
|
|
let i;
|
|
|
|
let plugins;
|
|
|
|
for (i = 0; i < docs.length; i++) {
|
|
|
|
plugins = docs[i].querySelectorAll("embed,object");
|
|
|
|
result.push.apply(result, Array.prototype.slice.call(plugins));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2009-11-23 23:46:01 -08:00
|
|
|
/** Update the current browser's flash objects. */
|
|
|
|
updateCurrentBrowser: function updateCurrentBrowser() {
|
|
|
|
let doc = Browser.selectedTab.browser.contentDocument;
|
|
|
|
|
|
|
|
let rect = this.getCriticalRect();
|
2010-01-13 10:23:39 -08:00
|
|
|
if (rect == this._emptyRect && !this._isRendering)
|
|
|
|
return;
|
|
|
|
|
2009-12-04 12:03:56 -08:00
|
|
|
if (this._isRendering) {
|
|
|
|
// Update immediately if not just starting to render
|
|
|
|
if (rect == this._emptyRect)
|
|
|
|
this._isRendering = false;
|
2010-01-22 09:52:24 -08:00
|
|
|
this.updateEmbedRegions(this.getPluginNodes(doc), rect);
|
2009-11-23 23:46:01 -08:00
|
|
|
} else {
|
|
|
|
// Wait a moment so that any chrome redraws occur first.
|
|
|
|
let self = this;
|
|
|
|
setTimeout(function() {
|
2009-12-04 12:03:56 -08:00
|
|
|
self._isRendering = true;
|
2009-11-23 23:46:01 -08:00
|
|
|
// Recalculate critical rect so we don't render when we ought not to.
|
2010-01-22 09:52:24 -08:00
|
|
|
self.updateEmbedRegions(self.getPluginNodes(doc), self.getCriticalRect());
|
2009-11-23 23:46:01 -08:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-12-01 10:49:53 -08:00
|
|
|
/** More accurate version of finding the current visible region. Returns client coords. */
|
2009-11-23 23:46:01 -08:00
|
|
|
getCriticalRect: function getCriticalRect() {
|
|
|
|
let bv = this._bv;
|
2010-01-22 09:52:24 -08:00
|
|
|
if (Browser.selectedTab._loading)
|
|
|
|
return this._emptyRect;
|
2009-11-23 23:46:01 -08:00
|
|
|
if (!bv.isRendering())
|
|
|
|
return this._emptyRect;
|
|
|
|
if (Elements.contentShowing.hasAttribute("disabled"))
|
|
|
|
return this._emptyRect;
|
|
|
|
|
|
|
|
let vs = bv._browserViewportState;
|
|
|
|
let vr = bv.getVisibleRect();
|
|
|
|
let crit = BrowserView.Util.visibleRectToCriticalRect(vr, vs);
|
2009-12-01 10:49:53 -08:00
|
|
|
crit = Browser.browserViewToClientRect(crit);
|
2009-11-23 23:46:01 -08:00
|
|
|
|
|
|
|
if (BrowserUI.isToolbarLocked()) {
|
2010-05-21 10:05:46 -07:00
|
|
|
let urlbarRect = Elements.toolbarContainer.getBoundingClientRect();
|
2009-12-01 10:49:53 -08:00
|
|
|
// Subtract urlbar area from critical rect area. In general subtracting a rect from another
|
|
|
|
// results in a region that can be described by a union of rects. Luckily in this case,
|
|
|
|
// we can cheat because the resulting area is still just one rect.
|
2009-12-04 12:03:56 -08:00
|
|
|
crit.top = Math.max(Math.round(urlbarRect.height) + 1, crit.top);
|
|
|
|
// XXX we add 1 to the height so that flash overlays don't leak into URL bar (otherwise
|
|
|
|
// you may see a strip of junk if you pop up the identity panel over flash)
|
|
|
|
}
|
|
|
|
|
|
|
|
let popup = BrowserUI._popup;
|
|
|
|
if (popup) {
|
|
|
|
let p = this.POPUP_PADDING;
|
|
|
|
let elements = BrowserUI._popup.elements;
|
|
|
|
for (let i = elements.length - 1; i >= 0; i--) {
|
|
|
|
let popupRect = Rect.fromRect(elements[i].getBoundingClientRect()).expandToIntegers();
|
|
|
|
// XXX Our CSS shadows don't seem to be included in getBoundingClientRect. Compensate
|
|
|
|
// with some padding; may need to be changed depending on the theme. Otherwise, flash
|
|
|
|
// can "leak into" the popup.
|
|
|
|
popupRect.setBounds(popupRect.left - p, popupRect.top - p, popupRect.right + p, popupRect.bottom + p);
|
|
|
|
let areaRects = crit.subtract(popupRect);
|
|
|
|
if (areaRects.length == 1) {
|
|
|
|
// Yay, critical region is still just a rect!
|
|
|
|
crit = areaRects[0];
|
|
|
|
} else if (areaRects.length > 1) {
|
|
|
|
// Critical region is a union of rects. Give up.
|
|
|
|
return this._emptyRect;
|
|
|
|
}
|
|
|
|
}
|
2009-11-23 23:46:01 -08:00
|
|
|
}
|
2009-12-04 12:03:56 -08:00
|
|
|
|
2009-11-23 23:46:01 -08:00
|
|
|
return crit;
|
|
|
|
},
|
|
|
|
|
2009-12-01 10:49:53 -08:00
|
|
|
/**
|
|
|
|
* Tell embedded objects where to absolutely render, using crit for clipping.
|
|
|
|
* @param crit Specified in client coordinates
|
|
|
|
*/
|
2009-11-23 23:46:01 -08:00
|
|
|
updateEmbedRegions: function updateEmbedRegions(objects, crit) {
|
|
|
|
let bv = this._bv;
|
|
|
|
let oprivate, r, dest, clip;
|
|
|
|
for (let i = objects.length - 1; i >= 0; i--) {
|
|
|
|
r = bv.browserToViewportRect(Browser.getBoundingContentRect(objects[i]));
|
|
|
|
dest = Browser.browserViewToClientRect(r);
|
2009-12-01 10:49:53 -08:00
|
|
|
clip = dest.intersect(crit).translate(-dest.left, -dest.top);
|
2009-11-23 23:46:01 -08:00
|
|
|
oprivate = objects[i].QueryInterface(nsIObjectLoadingContent);
|
2009-12-15 09:40:19 -08:00
|
|
|
try {
|
|
|
|
oprivate.setAbsoluteScreenPosition(Browser.contentScrollbox, dest, clip);
|
2010-01-14 13:08:40 -08:00
|
|
|
} catch(e) {};
|
2009-11-23 23:46:01 -08:00
|
|
|
}
|
2010-01-26 14:22:23 -08:00
|
|
|
}
|
2009-11-23 23:46:01 -08:00
|
|
|
};
|