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-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 ***** */
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2008-05-02 13:15:45 -07:00
|
|
|
const Cu = Components.utils;
|
2008-04-18 06:41:49 -07:00
|
|
|
|
2008-07-16 08:41:38 -07:00
|
|
|
const FINDSTATE_FIND = 0;
|
|
|
|
const FINDSTATE_FIND_AGAIN = 1;
|
|
|
|
const FINDSTATE_FIND_PREVIOUS = 2;
|
|
|
|
|
2008-07-09 11:33:03 -07:00
|
|
|
Cu.import("resource://gre/modules/SpatialNavigation.js");
|
2008-07-09 10:33:40 -07:00
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
// create a lazy-initialized handle for the pref service on the global object
|
|
|
|
// in the style of bug 385809
|
|
|
|
__defineGetter__("gPrefService", function () {
|
|
|
|
delete gPrefService;
|
2008-07-29 17:24:16 -07:00
|
|
|
var gPrefService;
|
2008-07-11 11:51:28 -07:00
|
|
|
return gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch2);
|
|
|
|
});
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
function getBrowser() {
|
|
|
|
return Browser.content.browser;
|
|
|
|
}
|
2008-04-18 06:41:49 -07:00
|
|
|
|
|
|
|
var Browser = {
|
|
|
|
_content : null,
|
|
|
|
|
|
|
|
startup : function() {
|
|
|
|
window.controllers.appendController(this);
|
2008-07-03 23:16:46 -07:00
|
|
|
window.controllers.appendController(BrowserUI);
|
2008-04-18 06:41:49 -07:00
|
|
|
|
|
|
|
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
|
|
|
var styleSheets = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
|
|
|
|
|
|
|
|
// Should we hide the cursors
|
2008-07-24 12:48:40 -07:00
|
|
|
var hideCursor = gPrefService.getBoolPref("browser.ui.cursor") == false;
|
2008-04-18 06:41:49 -07:00
|
|
|
if (hideCursor) {
|
|
|
|
window.QueryInterface(Ci.nsIDOMChromeWindow).setCursor("none");
|
|
|
|
|
|
|
|
var styleURI = ios.newURI("chrome://browser/content/content.css", null, null);
|
|
|
|
styleSheets.loadAndRegisterSheet(styleURI, styleSheets.AGENT_SHEET);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load styles for scrollbars
|
|
|
|
var styleURI = ios.newURI("chrome://browser/content/scrollbars.css", null, null);
|
|
|
|
styleSheets.loadAndRegisterSheet(styleURI, styleSheets.AGENT_SHEET);
|
|
|
|
|
|
|
|
this._content = document.getElementById("content");
|
2008-07-24 11:50:32 -07:00
|
|
|
this._content.progressListenerCreator = function (content, browser) {
|
|
|
|
return new ProgressController(content, browser);
|
|
|
|
};
|
|
|
|
|
2008-08-19 19:18:36 -07:00
|
|
|
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
|
|
|
os.addObserver(gXPInstallObserver, "xpinstall-install-blocked", false);
|
|
|
|
os.addObserver(gXPInstallObserver, "xpinstall-download-started", false);
|
|
|
|
|
2008-08-19 23:09:22 -07:00
|
|
|
BrowserUI.init();
|
|
|
|
|
2008-09-24 09:14:06 -07:00
|
|
|
window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = new nsBrowserAccess();
|
|
|
|
|
2008-09-09 08:52:21 -07:00
|
|
|
this._content.addEventListener("command", this._handleContentCommand, false);
|
2008-08-19 23:09:22 -07:00
|
|
|
this._content.addEventListener("DOMUpdatePageReport", gPopupBlockerObserver.onUpdatePageReport, false);
|
2008-07-25 11:10:35 -07:00
|
|
|
this._content.tabList = document.getElementById("tab-list");
|
2008-07-24 11:50:32 -07:00
|
|
|
this._content.newTab(true);
|
2008-06-21 11:51:41 -07:00
|
|
|
|
2008-09-29 09:35:08 -07:00
|
|
|
var deckbrowser = this.content;
|
|
|
|
function panCallback(aElement) {
|
|
|
|
// SpatialNav calls commandDispatcher.advanceFocus/rewindFocus, which
|
|
|
|
// can mess the scroll state up. Reset it.
|
|
|
|
deckbrowser.browser.contentWindow.scrollTo(0, 0);
|
|
|
|
|
|
|
|
if (!aElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
deckbrowser.ensureElementIsVisible(aElement);
|
|
|
|
}
|
|
|
|
SpatialNavigation.init(this.content, panCallback);
|
2008-07-09 10:33:40 -07:00
|
|
|
|
2008-07-16 17:07:43 -07:00
|
|
|
this.setupGeolocationPrompt();
|
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
|
|
|
|
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
|
2008-04-18 06:41:49 -07:00
|
|
|
if (window.arguments && window.arguments[0]) {
|
2008-07-21 14:00:55 -07:00
|
|
|
var whereURI = null;
|
|
|
|
|
2008-05-02 13:15:45 -07:00
|
|
|
try {
|
2008-07-21 14:00:55 -07:00
|
|
|
// Try to access the commandline
|
2008-05-02 13:15:45 -07:00
|
|
|
var cmdLine = window.arguments[0].QueryInterface(Ci.nsICommandLine);
|
2008-07-21 14:00:55 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
// Check for and use a default homepage
|
2008-07-24 12:48:40 -07:00
|
|
|
whereURI = gPrefService.getCharPref("browser.startup.homepage");
|
2008-07-21 14:00:55 -07:00
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
// 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) {}
|
|
|
|
|
|
|
|
if (whereURI) {
|
2008-07-25 11:10:35 -07:00
|
|
|
var self = this;
|
|
|
|
setTimeout(function() { self.currentBrowser.loadURI(whereURI, null, null, false); }, 0);
|
2008-07-21 14:00:55 -07:00
|
|
|
}
|
2008-04-18 06:41:49 -07:00
|
|
|
}
|
2008-09-30 06:23:18 -07:00
|
|
|
|
2008-09-30 08:01:27 -07:00
|
|
|
var disablePlugins = true;
|
|
|
|
try { disablePlugins = gPrefService.getBoolPref("temporary.disablePlugins"); } catch (ex) { }
|
|
|
|
if (disablePlugins)
|
2008-09-30 06:23:18 -07:00
|
|
|
{
|
|
|
|
document.getElementById("plugins.enabled").pref.value = false;
|
|
|
|
this.setPluginState(false);
|
|
|
|
}
|
2008-09-30 08:01:27 -07:00
|
|
|
gPrefService.setBoolPref("temporary.disablePlugins", false);
|
2008-04-18 06:41:49 -07:00
|
|
|
},
|
|
|
|
|
2008-09-23 08:19:11 -07:00
|
|
|
setPluginState: function(state)
|
|
|
|
{
|
|
|
|
var phs = Components.classes["@mozilla.org/plugin/host;1"]
|
|
|
|
.getService(Components.interfaces.nsIPluginHost);
|
|
|
|
var plugins = phs.getPluginTags({ });
|
2008-09-26 22:34:27 -07:00
|
|
|
for (var i = 0; i < plugins.length; ++i)
|
2008-09-23 08:19:11 -07:00
|
|
|
plugins[i].disabled = state;
|
|
|
|
},
|
|
|
|
|
2008-07-16 17:07:43 -07:00
|
|
|
setupGeolocationPrompt: function() {
|
2008-07-24 11:50:32 -07:00
|
|
|
try {
|
|
|
|
var geolocationService = Cc["@mozilla.org/geolocation/service;1"].getService(Ci.nsIGeolocationService);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-16 17:07:43 -07:00
|
|
|
geolocationService.prompt = function(request) {
|
|
|
|
var notificationBox = Browser.getNotificationBox();
|
|
|
|
var notification = notificationBox.getNotificationWithValue("geolocation");
|
|
|
|
|
|
|
|
if (!notification) {
|
|
|
|
var bundle_browser = document.getElementById("bundle_browser");
|
|
|
|
var buttons = [{
|
2008-10-01 13:36:38 -07:00
|
|
|
label: bundle_browser.getString("geolocation.exactLocation"),
|
|
|
|
subLabel: bundle_browser.getString("geolocation.exactLocation.subLabel"),
|
|
|
|
accessKey: bundle_browser.getString("geolocation.exactLocationKey"),
|
2008-08-05 13:19:22 -07:00
|
|
|
callback: function(){request.allow()}
|
2008-07-16 17:07:43 -07:00
|
|
|
},
|
|
|
|
{
|
2008-10-01 13:36:38 -07:00
|
|
|
label: bundle_browser.getString("geolocation.neighborhoodLocation"),
|
|
|
|
subLabel: bundle_browser.getString("geolocation.neighborhoodLocation.subLabel"),
|
|
|
|
accessKey: bundle_browser.getString("geolocation.neighborhoodLocationKey"),
|
2008-08-05 13:19:22 -07:00
|
|
|
callback: function(){request.allowButFuzz()}
|
2008-07-16 17:07:43 -07:00
|
|
|
},
|
|
|
|
{
|
2008-10-01 13:36:38 -07:00
|
|
|
label: bundle_browser.getString("geolocation.nothingLocation"),
|
2008-09-07 05:12:05 -07:00
|
|
|
subLabel: "",
|
2008-10-01 13:36:38 -07:00
|
|
|
accessKey: bundle_browser.getString("geolocation.nothingLocationKey"),
|
2008-08-05 13:19:22 -07:00
|
|
|
callback: function(){request.cancel()}
|
2008-07-16 17:07:43 -07:00
|
|
|
}];
|
|
|
|
|
2008-07-21 14:00:55 -07:00
|
|
|
var message = bundle_browser.getFormattedString("geolocation.requestMessage", [request.requestingURI.spec]);
|
2008-09-07 05:12:05 -07:00
|
|
|
var notification = notificationBox.appendNotification(message,
|
|
|
|
"geolocation", null, // todo "chrome://browser/skin/Info.png",
|
|
|
|
notificationBox.PRIORITY_INFO_HIGH, buttons);
|
|
|
|
var children = notification.childNodes;
|
|
|
|
for (var b = 0; b < children.length; b++)
|
|
|
|
children[b].setAttribute("sublabel", children[b].buttonInfo.subLabel);
|
2008-07-16 17:07:43 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2008-08-05 13:19:22 -07:00
|
|
|
}
|
2008-07-16 17:07:43 -07:00
|
|
|
},
|
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
get content() {
|
|
|
|
return this._content;
|
|
|
|
},
|
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
/**
|
|
|
|
* Return the currently active <browser> object, since a <deckbrowser> may
|
|
|
|
* have more than one
|
|
|
|
*/
|
|
|
|
get currentBrowser() {
|
|
|
|
return this._content.browser;
|
|
|
|
},
|
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
supportsCommand : function(cmd) {
|
|
|
|
var isSupported = false;
|
|
|
|
switch (cmd) {
|
|
|
|
case "cmd_fullscreen":
|
|
|
|
case "cmd_downloads":
|
|
|
|
isSupported = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
isSupported = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return isSupported;
|
|
|
|
},
|
|
|
|
|
|
|
|
isCommandEnabled : function(cmd) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
doCommand : function(cmd) {
|
|
|
|
var browser = this.content.browser;
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
getNotificationBox : function() {
|
|
|
|
return document.getElementById("notifications");
|
2008-07-16 08:41:38 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
findState: FINDSTATE_FIND,
|
|
|
|
openFind: function(aState) {
|
|
|
|
this.findState = aState;
|
|
|
|
|
|
|
|
var findbar = document.getElementById("findbar");
|
|
|
|
var browser = findbar.browser;
|
|
|
|
if (!browser) {
|
|
|
|
browser = this.content.browser;
|
|
|
|
findbar.browser = browser;
|
|
|
|
}
|
|
|
|
|
|
|
|
var panel = document.getElementById("findpanel");
|
|
|
|
if (panel.state == "open")
|
|
|
|
this.doFind(null);
|
|
|
|
else
|
|
|
|
panel.openPopup(document.getElementById("findpanel-placeholder"), "before_start");
|
|
|
|
},
|
|
|
|
|
|
|
|
doFind: function (aEvent) {
|
|
|
|
var findbar = document.getElementById("findbar");
|
|
|
|
if (Browser.findState == FINDSTATE_FIND)
|
|
|
|
findbar.onFindCommand();
|
|
|
|
else
|
|
|
|
findbar.onFindAgainCommand(Browser.findState == FINDSTATE_FIND_PREVIOUS);
|
2008-08-05 13:19:22 -07:00
|
|
|
},
|
2008-08-19 19:18:36 -07:00
|
|
|
|
2008-08-05 13:19:22 -07:00
|
|
|
translatePhoneNumbers: function() {
|
2008-07-25 16:27:31 -07:00
|
|
|
let doc = getBrowser().contentDocument;
|
|
|
|
let textnodes = doc.evaluate("//text()",
|
|
|
|
doc,
|
|
|
|
null,
|
|
|
|
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
|
|
|
|
null);
|
|
|
|
let s, node, lastLastIndex;
|
|
|
|
let re = /(\+?1? ?-?\(?\d{3}\)?[ +-\.]\d{3}[ +-\.]\d{4})/
|
2008-08-05 13:19:22 -07:00
|
|
|
for (var i = 0; i < textnodes.snapshotLength; i++) {
|
|
|
|
node = textnodes.snapshotItem(i);
|
|
|
|
s = node.data;
|
|
|
|
if (s.match(re)) {
|
|
|
|
s = s.replace(re, "<a href='tel:$1'> $1 </a>");
|
|
|
|
try {
|
|
|
|
let replacement = doc.createElement("span");
|
|
|
|
replacement.innerHTML = s;
|
|
|
|
node.parentNode.insertBefore(replacement, node);
|
|
|
|
node.parentNode.removeChild(node);
|
|
|
|
} catch(e) {
|
|
|
|
//do nothing, but continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 08:52:21 -07:00
|
|
|
},
|
2008-09-23 08:19:11 -07:00
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
_handleContentCommand: function (aEvent) {
|
|
|
|
// 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
|
|
|
|
if (/^about:neterror\?e=nssBadCert/.test(errorDoc.documentURI)) {
|
|
|
|
if (ot == errorDoc.getElementById('exceptionDialogButton')) {
|
|
|
|
var params = { exceptionAdded : false };
|
2008-09-23 08:19:11 -07:00
|
|
|
|
2008-09-09 08:52:21 -07:00
|
|
|
try {
|
|
|
|
switch (gPrefService.getIntPref("browser.ssl_override_behavior")) {
|
|
|
|
case 2 : // Pre-fetch & pre-populate
|
|
|
|
params.prefetchCert = true;
|
|
|
|
case 1 : // Pre-populate
|
|
|
|
params.location = errorDoc.location.href;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
Components.utils.reportError("Couldn't get ssl_override pref: " + e);
|
|
|
|
}
|
2008-09-23 08:19:11 -07:00
|
|
|
|
2008-09-09 08:52:21 -07:00
|
|
|
window.openDialog('chrome://pippki/content/exceptionDialog.xul',
|
|
|
|
'','chrome,centerscreen,modal', params);
|
2008-09-23 08:19:11 -07:00
|
|
|
|
2008-09-09 08:52:21 -07:00
|
|
|
// If the user added the exception cert, attempt to reload the page
|
|
|
|
if (params.exceptionAdded)
|
|
|
|
errorDoc.location.reload();
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2008-09-09 08:52:21 -07:00
|
|
|
Browser.currentBrowser.loadURI(url, null, null, false);
|
|
|
|
}
|
|
|
|
}
|
2008-07-25 16:27:31 -07:00
|
|
|
}
|
2008-04-18 06:41:49 -07:00
|
|
|
};
|
|
|
|
|
2008-07-24 11:50:32 -07:00
|
|
|
function ProgressController(aTabBrowser, aBrowser) {
|
2008-06-21 11:51:41 -07:00
|
|
|
this._tabbrowser = aTabBrowser;
|
2008-07-24 11:50:32 -07:00
|
|
|
this.init(aBrowser);
|
2008-04-18 06:41:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ProgressController.prototype = {
|
|
|
|
_browser : null,
|
|
|
|
|
|
|
|
init : function(aBrowser) {
|
|
|
|
this._browser = aBrowser;
|
|
|
|
},
|
|
|
|
|
|
|
|
onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus) {
|
2008-10-04 00:52:16 -07:00
|
|
|
// we currently only care about state changes for the main document,
|
|
|
|
// not sub-frames
|
2008-10-04 00:29:08 -07:00
|
|
|
if (aWebProgress.DOMWindow != this._browser.contentWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
|
2008-10-04 00:29:08 -07:00
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_START)
|
2008-10-04 00:52:16 -07:00
|
|
|
BrowserUI.update(TOOLBARSTATE_LOADING, this._browser);
|
2008-10-04 00:29:08 -07:00
|
|
|
else if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP)
|
2008-10-04 00:52:16 -07:00
|
|
|
BrowserUI.update(TOOLBARSTATE_LOADED, this._browser);
|
2008-04-18 06:41:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT) {
|
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
|
|
|
|
aWebProgress.DOMWindow.focus();
|
2008-07-25 16:27:31 -07:00
|
|
|
Browser.translatePhoneNumbers();
|
2008-07-24 11:50:32 -07:00
|
|
|
this._tabbrowser.updateBrowser(this._browser, true);
|
2008-09-18 11:07:16 -07:00
|
|
|
this._tabbrowser.updateCanvasState();
|
2008-04-18 06:41:49 -07:00
|
|
|
//aWebProgress.DOMWindow.scrollbars.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// This method is called to indicate progress changes for the currently
|
|
|
|
// loading page.
|
|
|
|
onProgressChange : function(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal) {
|
|
|
|
},
|
|
|
|
|
|
|
|
// This method is called to indicate a change to the current location.
|
2008-07-11 11:51:28 -07:00
|
|
|
onLocationChange : function(aWebProgress, aRequest, aLocationURI) {
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
var location = aLocationURI ? aLocationURI.spec : "";
|
2008-06-20 14:01:42 -07:00
|
|
|
this._hostChanged = true;
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
// This code here does not compare uris exactly when determining
|
|
|
|
// whether or not the message(s) should be hidden since the message
|
|
|
|
// may be prematurely hidden when an install is invoked by a click
|
|
|
|
// on a link that looks like this:
|
|
|
|
//
|
|
|
|
// <a href="#" onclick="return install();">Install Foo</a>
|
|
|
|
//
|
|
|
|
// - which fires a onLocationChange message to uri + '#'...
|
|
|
|
cBrowser = Browser.currentBrowser;
|
|
|
|
if (cBrowser.lastURI) {
|
|
|
|
var oldSpec = cBrowser.lastURI.spec;
|
|
|
|
var oldIndexOfHash = oldSpec.indexOf("#");
|
|
|
|
if (oldIndexOfHash != -1)
|
|
|
|
oldSpec = oldSpec.substr(0, oldIndexOfHash);
|
|
|
|
var newSpec = location;
|
|
|
|
var newIndexOfHash = newSpec.indexOf("#");
|
|
|
|
if (newIndexOfHash != -1)
|
|
|
|
newSpec = newSpec.substr(0, newSpec.indexOf("#"));
|
|
|
|
if (newSpec != oldSpec) {
|
|
|
|
// Remove all the notifications, except for those which want to
|
|
|
|
// persist across the first location change.
|
|
|
|
var nBox = Browser.getNotificationBox();
|
|
|
|
nBox.removeTransientNotifications();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cBrowser.lastURI = aLocationURI;
|
|
|
|
|
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
if (aWebProgress.DOMWindow == this._browser.contentWindow) {
|
2008-07-03 23:16:46 -07:00
|
|
|
BrowserUI.setURI();
|
2008-07-24 11:50:32 -07:00
|
|
|
this._tabbrowser.updateBrowser(this._browser, false);
|
2008-04-18 06:41:49 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// This method is called to indicate a status changes for the currently
|
|
|
|
// loading page. The message is already formatted for display.
|
|
|
|
onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage) {
|
|
|
|
},
|
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Properties used to cache security state used to update the UI
|
|
|
|
_state: null,
|
|
|
|
_host: undefined,
|
|
|
|
_hostChanged: false, // onLocationChange will flip this bit
|
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
// This method is called when the security state of the browser changes.
|
|
|
|
onSecurityChange : function(aWebProgress, aRequest, aState) {
|
2008-06-20 14:01:42 -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._state = aState;
|
|
|
|
|
|
|
|
try {
|
|
|
|
this._host = getBrowser().contentWindow.location.host;
|
|
|
|
} catch(ex) {
|
|
|
|
this._host = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._hostChanged = false;
|
|
|
|
|
2008-07-08 18:24:49 -07:00
|
|
|
// Don't pass in the actual location object, since it can cause us to
|
2008-06-20 14:01:42 -07:00
|
|
|
// hold on to the window object too long. Just pass in the fields we
|
|
|
|
// care about. (bug 424829)
|
|
|
|
var location = getBrowser().contentWindow.location;
|
|
|
|
var locationObj = {};
|
|
|
|
try {
|
|
|
|
locationObj.host = location.host;
|
|
|
|
locationObj.hostname = location.hostname;
|
|
|
|
locationObj.port = location.port;
|
|
|
|
} catch (ex) {
|
|
|
|
// Can sometimes throw if the URL being visited has no host/hostname,
|
|
|
|
// e.g. about:blank. The _state for these pages means we won't need these
|
|
|
|
// properties anyways, though.
|
|
|
|
}
|
|
|
|
getIdentityHandler().checkIdentity(this._state, locationObj);
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-04-18 06:41:49 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface : function(aIID) {
|
|
|
|
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
};
|
2008-06-20 14:01:42 -07:00
|
|
|
|
2008-09-24 09:14:06 -07:00
|
|
|
function nsBrowserAccess()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBrowserAccess.prototype =
|
|
|
|
{
|
|
|
|
QueryInterface : function(aIID)
|
|
|
|
{
|
|
|
|
if (aIID.equals(Ci.nsIBrowserDOMWindow) ||
|
|
|
|
aIID.equals(Ci.nsISupports))
|
|
|
|
return this;
|
|
|
|
throw Components.results.NS_NOINTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
openURI : function(aURI, aOpener, aWhere, aContext)
|
|
|
|
{
|
|
|
|
var isExternal = (aContext == Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
|
|
|
|
|
|
|
|
if (isExternal && aURI && aURI.schemeIs("chrome")) {
|
|
|
|
dump("use -chrome command-line option to load external chrome urls\n");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var loadflags = isExternal ?
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL :
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
|
|
|
var location;
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var newWindow;
|
|
|
|
if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW) {
|
|
|
|
var url = aURI ? aURI.spec : "about:blank";
|
|
|
|
newWindow = openDialog("chrome://browser/content/browser.xul", "_blank",
|
|
|
|
"all,dialog=no", url, null, null, null);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aWhere == Ci.nsIBrowserDOMWindow.OPEN_NEWTAB) {
|
|
|
|
var tab = Browser._content.newTab(true);
|
|
|
|
if (tab) {
|
|
|
|
var content = Browser._content;
|
|
|
|
var browser = content.getBrowserForDisplay(content.getDisplayForTab(tab));
|
|
|
|
newWindow = browser.contentWindow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newWindow = aOpener ? aOpener.top : browser.contentWindow;
|
|
|
|
}
|
|
|
|
}
|
2008-09-26 22:34:27 -07:00
|
|
|
|
2008-09-24 09:14:06 -07:00
|
|
|
try {
|
|
|
|
var referrer;
|
|
|
|
if (aURI) {
|
|
|
|
if (aOpener) {
|
|
|
|
location = aOpener.location;
|
|
|
|
referrer = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService)
|
|
|
|
.newURI(location, null, null);
|
|
|
|
}
|
|
|
|
newWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.loadURI(aURI.spec, loadflags, referrer, null, null);
|
|
|
|
}
|
|
|
|
newWindow.focus();
|
|
|
|
} catch(e) { }
|
|
|
|
|
|
|
|
return newWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
isTabContentWindow : function(aWindow)
|
|
|
|
{
|
|
|
|
return Browser._content.browsers.some(function (browser) browser.contentWindow == aWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
|
|
|
* Utility class to handle manipulations of the identity indicators in the UI
|
|
|
|
*/
|
|
|
|
function IdentityHandler() {
|
|
|
|
this._stringBundle = document.getElementById("bundle_browser");
|
|
|
|
this._staticStrings = {};
|
|
|
|
this._staticStrings[this.IDENTITY_MODE_DOMAIN_VERIFIED] = {
|
2008-07-08 18:24:49 -07:00
|
|
|
encryption_label: this._stringBundle.getString("identity.encrypted")
|
2008-06-20 14:01:42 -07:00
|
|
|
};
|
|
|
|
this._staticStrings[this.IDENTITY_MODE_IDENTIFIED] = {
|
|
|
|
encryption_label: this._stringBundle.getString("identity.encrypted")
|
|
|
|
};
|
|
|
|
this._staticStrings[this.IDENTITY_MODE_UNKNOWN] = {
|
2008-07-08 18:24:49 -07:00
|
|
|
encryption_label: this._stringBundle.getString("identity.unencrypted")
|
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.
|
|
|
|
*/
|
|
|
|
_cacheElements : function() {
|
|
|
|
this._identityPopup = document.getElementById("identity-popup");
|
|
|
|
this._identityBox = document.getElementById("identity-box");
|
|
|
|
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");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for mouseclicks on the "More Information" button in the
|
|
|
|
* "identity-popup" panel.
|
|
|
|
*/
|
|
|
|
handleMoreInfoClick : function(event) {
|
|
|
|
displaySecurityInfo();
|
|
|
|
event.stopPropagation();
|
|
|
|
},
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
/**
|
|
|
|
* Helper to parse out the important parts of _lastStatus (of the SSL cert in
|
|
|
|
* particular) for use in constructing identity UI strings
|
|
|
|
*/
|
|
|
|
getIdentityData : function() {
|
|
|
|
var result = {};
|
|
|
|
var status = this._lastStatus.QueryInterface(Components.interfaces.nsISSLStatus);
|
|
|
|
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
|
|
|
|
* (if available) and, if necessary, update the UI to reflect this. Intended to
|
|
|
|
* be called by onSecurityChange
|
2008-07-08 18:24:49 -07:00
|
|
|
*
|
2008-06-20 14:01:42 -07:00
|
|
|
* @param PRUint32 state
|
|
|
|
* @param JS Object location that mirrors an nsLocation (i.e. has .host and
|
|
|
|
* .hostname and .port)
|
|
|
|
*/
|
|
|
|
checkIdentity : function(state, location) {
|
|
|
|
var currentStatus = getBrowser().securityUI
|
|
|
|
.QueryInterface(Components.interfaces.nsISSLStatusProvider)
|
|
|
|
.SSLStatus;
|
|
|
|
this._lastStatus = currentStatus;
|
|
|
|
this._lastLocation = location;
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
if (state & Components.interfaces.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL)
|
|
|
|
this.setMode(this.IDENTITY_MODE_IDENTIFIED);
|
|
|
|
else if (state & Components.interfaces.nsIWebProgressListener.STATE_SECURE_HIGH)
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
getEffectiveHost : function() {
|
|
|
|
// 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.
|
|
|
|
*/
|
|
|
|
setMode : function(newMode) {
|
|
|
|
if (!this._identityBox) {
|
|
|
|
// No identity box means the identity box is not visible, in which
|
|
|
|
// case there's nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._identityBox.className = newMode;
|
|
|
|
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
|
|
|
|
if (this._identityPopup.state == "open")
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
setIdentityMessages : function(newMode) {
|
|
|
|
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)
|
|
|
|
this._overrideService = Components.classes["@mozilla.org/security/certoverride;1"]
|
|
|
|
.getService(Components.interfaces.nsICertOverrideService);
|
|
|
|
|
|
|
|
// Verifier is either the CA Org, for a normal cert, or a special string
|
|
|
|
// for certs that are trusted because of a security exception.
|
|
|
|
var tooltip = this._stringBundle.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, {}, {}))
|
|
|
|
tooltip = this._stringBundle.getString("identity.identified.verified_by_you");
|
|
|
|
}
|
|
|
|
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();
|
2008-06-20 14:01:42 -07:00
|
|
|
tooltip = this._stringBundle.getFormattedString("identity.identified.verifier",
|
|
|
|
[iData.caOrg]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tooltip = this._stringBundle.getString("identity.unknown.tooltip");
|
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
setPopupMessages : function(newMode) {
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
this._identityPopup.className = newMode;
|
|
|
|
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
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
if (newMode == this.IDENTITY_MODE_DOMAIN_VERIFIED) {
|
|
|
|
var iData = this.getIdentityData();
|
|
|
|
var host = this.getEffectiveHost();
|
|
|
|
var owner = this._stringBundle.getString("identity.ownerUnknown2");
|
|
|
|
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)
|
2008-07-08 18:24:49 -07:00
|
|
|
supplemental += iData.city + "\n";
|
2008-06-20 14:01:42 -07:00
|
|
|
if (iData.state && iData.country)
|
|
|
|
supplemental += this._stringBundle.getFormattedString("identity.identified.state_and_country",
|
|
|
|
[iData.state, iData.country]);
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
hideIdentityPopup : function() {
|
|
|
|
this._identityPopup.hidePopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
|
|
|
handleIdentityButtonEvent : function(event) {
|
2008-07-08 18:24:49 -07:00
|
|
|
|
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
|
|
|
|
|
|
|
|
// Make sure that the display:none style we set in xul is removed now that
|
|
|
|
// the popup is actually needed
|
|
|
|
this._identityPopup.hidden = false;
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Tell the popup to consume dismiss clicks, to avoid bug 395314
|
|
|
|
this._identityPopup.popupBoxObject
|
|
|
|
.setConsumeRollupEvent(Ci.nsIPopupBoxObject.ROLLUP_CONSUME);
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Update the popup strings
|
|
|
|
this.setPopupMessages(this._identityBox.className);
|
2008-07-08 18:24:49 -07:00
|
|
|
|
2008-06-20 14:01:42 -07:00
|
|
|
// Now open the popup, anchored off the primary chrome element
|
|
|
|
this._identityPopup.openPopup(this._identityBox, 'after_start');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 = {
|
|
|
|
_kIPM: Components.interfaces.nsIPermissionManager,
|
|
|
|
|
|
|
|
onUpdatePageReport: function (aEvent)
|
|
|
|
{
|
|
|
|
var cBrowser = Browser.currentBrowser;
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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 bundle_browser = document.getElementById("bundle_browser");
|
|
|
|
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
|
|
|
|
2008-07-11 11:51:28 -07:00
|
|
|
if (popupCount > 1)
|
|
|
|
message = bundle_browser.getFormattedString("popupWarningMultiple", [brandShortName, popupCount]);
|
|
|
|
else
|
|
|
|
message = bundle_browser.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 = [
|
|
|
|
{
|
|
|
|
label: bundle_browser.getString("popupButtonAlwaysAllow"),
|
|
|
|
accessKey: bundle_browser.getString("popupButtonAlwaysAllow.accesskey"),
|
|
|
|
callback: function() { gPopupBlockerObserver.toggleAllowPopupsForSite(); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: bundle_browser.getString("popupButtonNeverWarn"),
|
|
|
|
accessKey: bundle_browser.getString("popupButtonNeverWarn.accesskey"),
|
|
|
|
callback: function() { gPopupBlockerObserver.dontShowMessage(); }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleAllowPopupsForSite: function (aEvent)
|
|
|
|
{
|
|
|
|
var currentURI = Browser.currentBrowser.webNavigation.currentURI;
|
|
|
|
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(this._kIPM);
|
|
|
|
pm.add(currentURI, "popup", this._kIPM.ALLOW_ACTION);
|
|
|
|
|
|
|
|
Browser.getNotificationBox().removeCurrentNotification();
|
|
|
|
},
|
|
|
|
|
|
|
|
dontShowMessage: function ()
|
|
|
|
{
|
|
|
|
var showMessage = gPrefService.getBoolPref("privacy.popups.showBrowserMessage");
|
|
|
|
gPrefService.setBoolPref("privacy.popups.showBrowserMessage", !showMessage);
|
|
|
|
Browser.getNotificationBox().removeCurrentNotification();
|
|
|
|
}
|
|
|
|
};
|
2008-08-18 12:59:14 -07:00
|
|
|
|
2008-08-19 19:18:36 -07:00
|
|
|
const gXPInstallObserver = {
|
|
|
|
observe: function (aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
var brandBundle = document.getElementById("bundle_brand");
|
|
|
|
var browserBundle = document.getElementById("bundle_browser");
|
|
|
|
switch (aTopic) {
|
|
|
|
case "xpinstall-install-blocked":
|
|
|
|
var installInfo = aSubject.QueryInterface(Components.interfaces.nsIXPIInstallInfo);
|
|
|
|
var host = installInfo.originatingURI.host;
|
|
|
|
var brandShortName = brandBundle.getString("brandShortName");
|
|
|
|
var notificationName, messageString, buttons;
|
|
|
|
if (!gPrefService.getBoolPref("xpinstall.enabled")) {
|
|
|
|
notificationName = "xpinstall-disabled"
|
|
|
|
if (gPrefService.prefIsLocked("xpinstall.enabled")) {
|
|
|
|
messageString = browserBundle.getString("xpinstallDisabledMessageLocked");
|
|
|
|
buttons = [];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
messageString = browserBundle.getFormattedString("xpinstallDisabledMessage",
|
|
|
|
[brandShortName, host]);
|
|
|
|
buttons = [{
|
|
|
|
label: browserBundle.getString("xpinstallDisabledButton"),
|
|
|
|
accessKey: browserBundle.getString("xpinstallDisabledButton.accesskey"),
|
|
|
|
popup: null,
|
|
|
|
callback: function editPrefs() {
|
|
|
|
gPrefService.setBoolPref("xpinstall.enabled", true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notificationName = "xpinstall"
|
|
|
|
messageString = browserBundle.getFormattedString("xpinstallPromptWarning",
|
|
|
|
[brandShortName, host]);
|
|
|
|
|
|
|
|
buttons = [{
|
|
|
|
label: browserBundle.getString("xpinstallPromptAllowButton"),
|
|
|
|
accessKey: browserBundle.getString("xpinstallPromptAllowButton.accesskey"),
|
|
|
|
popup: null,
|
|
|
|
callback: function() {
|
|
|
|
// Force the addon manager panel to appear
|
|
|
|
CommandUpdater.doCommand("cmd_addons");
|
|
|
|
|
|
|
|
var mgr = Cc["@mozilla.org/xpinstall/install-manager;1"].createInstance(Ci.nsIXPInstallManager);
|
|
|
|
mgr.initManagerWithInstallInfo(installInfo);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-08-18 12:59:14 -07:00
|
|
|
function getNotificationBox(aWindow) {
|
|
|
|
return Browser.getNotificationBox();
|
2008-08-19 19:18:36 -07:00
|
|
|
}
|