diff options
Diffstat (limited to 'comm/suite/browser/pageinfo')
-rw-r--r-- | comm/suite/browser/pageinfo/feeds.js | 31 | ||||
-rw-r--r-- | comm/suite/browser/pageinfo/feeds.xml | 40 | ||||
-rw-r--r-- | comm/suite/browser/pageinfo/pageInfo.css | 18 | ||||
-rw-r--r-- | comm/suite/browser/pageinfo/pageInfo.js | 1177 | ||||
-rw-r--r-- | comm/suite/browser/pageinfo/pageInfo.xul | 531 | ||||
-rw-r--r-- | comm/suite/browser/pageinfo/permissions.js | 204 | ||||
-rw-r--r-- | comm/suite/browser/pageinfo/security.js | 354 |
7 files changed, 2355 insertions, 0 deletions
diff --git a/comm/suite/browser/pageinfo/feeds.js b/comm/suite/browser/pageinfo/feeds.js new file mode 100644 index 0000000000..194f436d23 --- /dev/null +++ b/comm/suite/browser/pageinfo/feeds.js @@ -0,0 +1,31 @@ +/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +function initFeedTab(feeds) +{ + for (let feed of feeds) { + let [name, type, url] = feed; + addRow(name, type, url); + } + + var feedListbox = document.getElementById("feedListbox"); + document.getElementById("feedTab").hidden = feedListbox.getRowCount() == 0; +} + +function onSubscribeFeed(event) +{ + var listbox = document.getElementById("feedListbox"); + subscribeToFeed(listbox.selectedItem.getAttribute("feedURL"), event); +} + +function addRow(name, type, url) +{ + var item = document.createElement("richlistitem"); + item.setAttribute("feed", "true"); + item.setAttribute("name", name); + item.setAttribute("type", type); + item.setAttribute("feedURL", url); + document.getElementById("feedListbox").appendChild(item); +} diff --git a/comm/suite/browser/pageinfo/feeds.xml b/comm/suite/browser/pageinfo/feeds.xml new file mode 100644 index 0000000000..c487e30f55 --- /dev/null +++ b/comm/suite/browser/pageinfo/feeds.xml @@ -0,0 +1,40 @@ +<?xml version="1.0"?><!-- -*- Mode: nXML; indent-tabs-mode: nil -*- --> +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + +<!DOCTYPE bindings [ + <!ENTITY % pageInfoDTD SYSTEM "chrome://navigator/locale/pageInfo.dtd"> + %pageInfoDTD; +]> + +<bindings id="feedBindings" + xmlns="http://www.mozilla.org/xbl" + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + xmlns:xbl="http://www.mozilla.org/xbl"> + + <binding id="feed" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem"> + <content> + <xul:vbox flex="1"> + <xul:hbox flex="1"> + <xul:textbox flex="1" readonly="true" xbl:inherits="value=name" + class="feedTitle"/> + <xul:label xbl:inherits="value=type"/> + </xul:hbox> + <xul:vbox align="start" flex="1"> + <xul:hbox> + <xul:label xbl:inherits="value=feedURL,tooltiptext=feedURL" + class="text-link" + flex="1" + onclick="openUILink(this.value, event);" crop="end"/> + </xul:hbox> + </xul:vbox> + <xul:hbox flex="1" class="feed-subscribe"> + <xul:spacer flex="1"/> + <xul:button label="&feedSubscribe;" accesskey="&feedSubscribe.accesskey;" + oncommand="onSubscribeFeed(event)"/> + </xul:hbox> + </xul:vbox> + </content> + </binding> +</bindings> diff --git a/comm/suite/browser/pageinfo/pageInfo.css b/comm/suite/browser/pageinfo/pageInfo.css new file mode 100644 index 0000000000..749c01a434 --- /dev/null +++ b/comm/suite/browser/pageinfo/pageInfo.css @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +richlistitem[feed] { + -moz-binding: url("chrome://navigator/content/pageinfo/feeds.xml#feed"); +} + +#thepreviewimage { + display: block; +/* This following entry can be removed when Bug 522850 is fixed. */ + min-width: 1px; +} + +.urltext:-moz-locale-dir(rtl) { + direction: ltr !important; + text-align: end !important; +} diff --git a/comm/suite/browser/pageinfo/pageInfo.js b/comm/suite/browser/pageinfo/pageInfo.js new file mode 100644 index 0000000000..d4f59be55c --- /dev/null +++ b/comm/suite/browser/pageinfo/pageInfo.js @@ -0,0 +1,1177 @@ +/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); +var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); + +XPCOMUtils.defineLazyModuleGetters(this, { + Downloads: "resource://gre/modules/Downloads.jsm", + FileUtils: "resource://gre/modules/FileUtils.jsm", +}); + +//******** define a js object to implement nsITreeView +function pageInfoTreeView(treeid, copycol) +{ + /* copycol is the index number for the column that we want to add to + * the copy-n-paste buffer when the user hits accel-c. + */ + this.treeid = treeid; + this.copycol = copycol; + this.rows = 0; + this.tree = null; + this.data = [ ]; + this.selection = null; + this.sortcol = -1; + this.sortdir = false; +} + +pageInfoTreeView.prototype = { + get rowCount() { return this.rows; }, + + setTree: function(tree) + { + this.tree = tree; + }, + + getCellText: function(row, column) + { + // row can be null, but js arrays are 0-indexed. + return this.data[row][column.index] || ""; + }, + + setCellValue: function(row, column, value) + { + }, + + setCellText: function(row, column, value) + { + this.data[row][column.index] = value; + }, + + addRow: function(row) + { + this.rows = this.data.push(row); + this.rowCountChanged(this.rows - 1, 1); + if (this.selection.count == 0 && this.rowCount && !gImageElement) { + this.selection.select(0); + } + }, + + addRows: function(rows) + { + for (let row of rows) { + this.addRow(row); + } + }, + + rowCountChanged: function(index, count) + { + this.tree.rowCountChanged(index, count); + }, + + invalidate: function() + { + this.tree.invalidate(); + }, + + clear: function() + { + if (this.tree) + this.tree.rowCountChanged(0, -this.rows); + this.rows = 0; + this.data = []; + }, + + cycleHeader: function cycleHeader(col) + { + this.doSort(col, col.index); + }, + + doSort: function doSort(col, index, comparator) + { + var tree = document.getElementById(this.treeid); + if (!comparator) { + comparator = function comparator(a, b) { + return (a || "").toLowerCase().localeCompare((b || "").toLowerCase()); + }; + } + + this.sortdir = gTreeUtils.sort(tree, this, this.data, index, + comparator, this.sortcol, this.sortdir); + + Array.from(this.tree.columns).forEach(function(treecol) { + treecol.element.removeAttribute("sortActive"); + treecol.element.removeAttribute("sortDirection"); + }); + col.element.setAttribute("sortActive", true); + col.element.setAttribute("sortDirection", this.sortdir ? + "ascending" : "descending"); + + this.sortcol = index; + }, + + getRowProperties: function(row) { return ""; }, + getCellProperties: function(row, column) { return ""; }, + getColumnProperties: function(column) { return ""; }, + isContainer: function(index) { return false; }, + isContainerOpen: function(index) { return false; }, + isSeparator: function(index) { return false; }, + isSorted: function() { return this.sortcol > -1 }, + canDrop: function(index, orientation) { return false; }, + drop: function(row, orientation) { return false; }, + getParentIndex: function(index) { return -1; }, + hasNextSibling: function(index, after) { return false; }, + getLevel: function(index) { return 0; }, + getImageSrc: function(row, column) { }, + getProgressMode: function(row, column) { }, + getCellValue: function(row, column) { + let col = (column != null) ? column : this.copycol; + return (row < 0 || col < 0) ? "" : (this.data[row][col] || ""); + }, + toggleOpenState: function(index) { }, + selectionChanged: function() { }, + cycleCell: function(row, column) { }, + isEditable: function(row, column) { return false; }, + isSelectable: function(row, column) { return false; }, +}; + +// mmm, yummy. global variables. +var gDocInfo = null; +var gImageElement = null; + +// column number to help using the data array +const COL_IMAGE_ADDRESS = 0; +const COL_IMAGE_TYPE = 1; +const COL_IMAGE_SIZE = 2; +const COL_IMAGE_ALT = 3; +const COL_IMAGE_COUNT = 4; +const COL_IMAGE_NODE = 5; +const COL_IMAGE_BG = 6; +const COL_IMAGE_SIZENUM = 7; +const COL_IMAGE_PERSIST = 8; +const COL_IMAGE_MIME = 9; + +// column number to copy from, second argument to pageInfoTreeView's constructor +const COPYCOL_NONE = -1; +const COPYCOL_META_CONTENT = 1; +const COPYCOL_FORM_ACTION = 2; +const COPYCOL_FIELD_VALUE = 3; +const COPYCOL_LINK_ADDRESS = 1; +const COPYCOL_IMAGE = COL_IMAGE_ADDRESS; + +// one nsITreeView for each tree in the window +var gMetaView = new pageInfoTreeView("metatree", COPYCOL_META_CONTENT); +var gFormView = new pageInfoTreeView("formtree", COPYCOL_FORM_ACTION); +var gFieldView = new pageInfoTreeView("formpreview", COPYCOL_FIELD_VALUE); +var gLinkView = new pageInfoTreeView("linktree", COPYCOL_LINK_ADDRESS); +var gImageView = new pageInfoTreeView("imagetree", COPYCOL_IMAGE); + +gImageView.getCellProperties = function(row, col) { + var data = gImageView.data[row]; + var item = gImageView.data[row][COL_IMAGE_NODE]; + var properties = col.id == "image-address" ? "ltr" : ""; + if (!checkProtocol(data) || item.HTMLEmbedElement || + (item.HTMLObjectElement && !item.type.startsWith("image/"))) + properties += " broken"; + + return properties; +}; + +gFormView.getCellProperties = function(row, col) { + return col.id == "form-action" ? "ltr" : ""; +}; + +gLinkView.getCellProperties = function(row, col) { + return col.id == "link-address" ? "ltr" : ""; +}; + +gImageView.cycleHeader = function(col) +{ + var index = col.index; + var comparator; + switch (col.index) { + case COL_IMAGE_SIZE: + index = COL_IMAGE_SIZENUM; + case COL_IMAGE_COUNT: + comparator = function numComparator(a, b) { return a - b; }; + break; + } + + this.doSort(col, index, comparator); +}; + +var gImageHash = { }; + +// localized strings (will be filled in when the document is loaded) +// this isn't all of them, these are just the ones that would otherwise have been loaded inside a loop +var gStrings = { }; +var gBundle; + +const DRAGSERVICE_CONTRACTID = "@mozilla.org/widget/dragservice;1"; +const TRANSFERABLE_CONTRACTID = "@mozilla.org/widget/transferable;1"; +const STRING_CONTRACTID = "@mozilla.org/supports-string;1"; + +var loadContextInfo = Services.loadContextInfo.fromLoadContext( + window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsILoadContext), false); +var diskStorage = Services.cache2.diskCacheStorage(loadContextInfo, false); + +const nsICertificateDialogs = Ci.nsICertificateDialogs; +const CERTIFICATEDIALOGS_CONTRACTID = "@mozilla.org/nsCertificateDialogs;1" + +/* Overlays register functions here. + * These arrays are used to hold callbacks that Page Info will call at + * various stages. Use them by simply appending a function to them. + * For example, add a function to onLoadRegistry by invoking + * "onLoadRegistry.push(XXXLoadFunc);" + * The XXXLoadFunc should be unique to the overlay module, and will be + * invoked as "XXXLoadFunc();" + */ + +// These functions are called to build the data displayed in the Page +// Info window. +var onLoadRegistry = [ ]; + +// These functions are called to remove old data still displayed in +// the window when the document whose information is displayed +// changes. For example, the list of images in the Media tab +// is cleared. +var onResetRegistry = [ ]; + +// These functions are called once when all the elements in all of the target +// document (and all of its subframes, if any) have been processed +var onFinished = [ ]; + +// These functions are called once when the Page Info window is closed. +var onUnloadRegistry = [ ]; + +/* Called when PageInfo window is loaded. Arguments are: + * window.arguments[0] - (optional) an object consisting of + * - doc: (optional) document to use for source. if not provided, + * the calling window's document will be used + * - initialTab: (optional) id of the inital tab to display + */ +function onLoadPageInfo() +{ + gBundle = document.getElementById("pageinfobundle"); + var strNames = ["unknown", "notSet", "mediaImg", "mediaBGImg", + "mediaBorderImg", "mediaListImg", "mediaCursor", + "mediaObject", "mediaEmbed", "mediaLink", "mediaInput", + "mediaVideo", "mediaAudio", + "formTitle", "formUntitled", "formDefaultTarget", + "formChecked", "formUnchecked", "formPassword", "linkAnchor", + "linkArea", "linkSubmission", "linkSubmit", "linkRel", + "linkStylesheet", "linkRev", "linkX", "linkScript", + "linkScriptInline", "yes"]; + strNames.forEach(function(n) { gStrings[n] = gBundle.getString(n); }); + + var args = "arguments" in window && + window.arguments.length >= 1 && + window.arguments[0]; + + // init views + function initView(treeid, view) + { + document.getElementById(treeid).view = view; + } + + initView("imagetree", gImageView); + initView("formtree", gFormView); + initView("formpreview", gFieldView); + initView("linktree", gLinkView); + initPermission(); + + /* Select the requested tab, if the name is specified */ + loadTab(args); + Services.obs.notifyObservers(window, "page-info-dialog-loaded"); +} + +function loadPageInfo(frameOuterWindowID, imageElement, browser) +{ + browser = browser || window.opener.gBrowser.selectedBrowser; + let mm = browser.messageManager; + + gStrings["application/rss+xml"] = gBundle.getString("feedRss"); + gStrings["application/atom+xml"] = gBundle.getString("feedAtom"); + gStrings["text/xml"] = gBundle.getString("feedXML"); + gStrings["application/xml"] = gBundle.getString("feedXML"); + gStrings["application/rdf+xml"] = gBundle.getString("feedXML"); + + // Look for pageInfoListener in content.js. + // Sends message to listener with arguments. + mm.sendAsyncMessage("PageInfo:getData", {strings: gStrings, + frameOuterWindowID: frameOuterWindowID}, + { imageElement }); + + let pageInfoData; + + // Get initial pageInfoData needed to display the general, feeds, permission + // and security tabs. + mm.addMessageListener("PageInfo:data", function onmessage(message) { + mm.removeMessageListener("PageInfo:data", onmessage); + pageInfoData = message.data; + let docInfo = pageInfoData.docInfo; + let windowInfo = pageInfoData.windowInfo; + let uri = makeURI(docInfo.documentURIObject.spec); + let principal = docInfo.principal; + gDocInfo = docInfo; + + gImageElement = pageInfoData.imageInfo; + + var titleFormat = windowInfo.isTopWindow ? "pageInfo.page.title" + : "pageInfo.frame.title"; + document.title = gBundle.getFormattedString(titleFormat, + [docInfo.location]); + + document.getElementById("main-window").setAttribute("relatedUrl", + docInfo.location); + + makeGeneralTab(pageInfoData.metaViewRows, docInfo); + initFeedTab(pageInfoData.feeds); + onLoadPermission(uri, principal); + securityOnLoad(uri, windowInfo); + }); + + // Get the media elements from content script to setup the media tab. + mm.addMessageListener("PageInfo:mediaData", function onmessage(message) { + // Page info window was closed. + if (window.closed) { + mm.removeMessageListener("PageInfo:mediaData", onmessage); + return; + } + + // The page info media fetching has been completed. + if (message.data.isComplete) { + mm.removeMessageListener("PageInfo:mediaData", onmessage); + onFinished.forEach(function(func) { func(pageInfoData); }); + return; + } + + if (message.data.imageItems) { + for (let item of message.data.imageItems) { + addImage(item); + } + selectImage(); + } + + if (message.data.linkItems) { + gLinkView.addRows(message.data.linkItems); + } + + if (message.data.formItems) { + gFormView.addRows(message.data.formItems); + } + }); + + /* Call registered overlay init functions */ + onLoadRegistry.forEach(function(func) { func(); }); +} + +function resetPageInfo(args) +{ + /* Reset Media tab */ + // Remove the observer, only if there is at least 1 image. + if (gImageView.data.length != 0) { + Services.obs.removeObserver(imagePermissionObserver, "perm-changed"); + } + + /* Reset tree views */ + gMetaView.clear(); + gFormView.clear(); + gFieldView.clear(); + gLinkView.clear(); + gImageView.clear(); + gImageHash = {}; + + /* Reset Feeds Tab */ + var feedListbox = document.getElementById("feedListbox"); + while (feedListbox.hasChildNodes()) + feedListbox.lastChild.remove(); + + /* Call registered overlay reset functions */ + onResetRegistry.forEach(function(func) { func(); }); + + /* Rebuild the data */ + loadTab(args); + + Services.obs.notifyObservers(window, "page-info-dialog-reset"); +} + +function onUnloadPageInfo() +{ + // Remove the observer, only if there is at least 1 image. + if (gImageView.data.length != 0) { + Services.obs.removeObserver(imagePermissionObserver, "perm-changed"); + } + + /* Call registered overlay unload functions */ + onUnloadRegistry.forEach(function(func) { func(); }); +} + +function doHelpButton() +{ + const helpTopics = { + "generalTab": "pageinfo_general", + "mediaTab": "pageinfo_media", + // "feedTab": "pageinfo_feed", + // "permTab": "pageinfo_permissions", + "formsTab": "pageinfo_forms", + "linksTab": "pageinfo_links", + "securityTab": "pageinfo_security" + }; + + var tabbox = document.getElementById("tabbox"); + var helpdoc = helpTopics[tabbox.selectedTab.id] || "nav-page-info"; + openHelp(helpdoc, "chrome://communicator/locale/help/suitehelp.rdf"); +} + +function showTab(id) +{ + var tabbox = document.getElementById("tabbox"); + var selectedTab = document.getElementById(id) || + document.getElementById(id + "Tab") || // Firefox compatibility sillyness + document.getElementById("generalTab"); + tabbox.selectedTab = selectedTab; + selectedTab.focus(); +} + +function loadTab(args) +{ + // If the "View Image Info" context menu item was used, the related image + // element is provided as an argument. This can't be a background image. + let imageElement = args && args.imageElement; + let frameOuterWindowID = args && args.frameOuterWindowID; + let browser = args && args.browser; + + /* Load the page info */ + loadPageInfo(frameOuterWindowID, imageElement, browser); + + /* Select the requested tab, if the name is specified */ + var initialTab = (args && args.initialTab) || "generalTab"; + showTab(initialTab); +} + +function onClickMore() +{ + showTab("securityTab"); +} + +function openCacheEntry(key, cb) +{ + var checkCacheListener = { + onCacheEntryCheck: function(entry, appCache) { + return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED; + }, + onCacheEntryAvailable: function(entry, isNew, appCache, status) { + cb(entry); + } + }; + diskStorage.asyncOpenURI(Services.io.newURI(key, null, null), "", + Ci.nsICacheStorage.OPEN_READONLY, + checkCacheListener); +} + +function makeGeneralTab(metaViewRows, docInfo) +{ + var title = (docInfo.title) ? docInfo.title : gBundle.getString("noPageTitle"); + document.getElementById("titletext").value = title; + + var url = docInfo.location.toString(); + setItemValue("urltext", url); + + var referrer = ("referrer" in docInfo && docInfo.referrer); + setItemValue("refertext", referrer); + + var mode = ("compatMode" in docInfo && docInfo.compatMode == "BackCompat") ? "generalQuirksMode" : "generalStrictMode"; + document.getElementById("modetext").value = gBundle.getString(mode); + + // find out the mime type + var mimeType = docInfo.contentType; + setItemValue("typetext", mimeType); + + // get the document characterset + var encoding = docInfo.characterSet; + document.getElementById("encodingtext").value = encoding; + + var length = metaViewRows.length; + + var metaGroup = document.getElementById("metaTags"); + if (!length) { + metaGroup.collapsed = true; + } + else { + var metaTagsCaption = document.getElementById("metaTagsCaption"); + if (length == 1) + metaTagsCaption.label = gBundle.getString("generalMetaTag"); + else + metaTagsCaption.label = gBundle.getFormattedString("generalMetaTags", [length]); + var metaTree = document.getElementById("metatree"); + metaTree.view = gMetaView; + + // Add the metaViewRows onto the general tab's meta info tree. + gMetaView.addRows(metaViewRows); + + metaGroup.collapsed = false; + } + + // get the date of last modification + var modifiedText = formatDate(docInfo.lastModified, gStrings.notSet); + document.getElementById("modifiedtext").value = modifiedText; + + // get cache info + var cacheKey = url.replace(/#.*$/, ""); + openCacheEntry(cacheKey, function(cacheEntry) { + var sizeText; + if (cacheEntry) { + var pageSize = cacheEntry.dataSize; + var kbSize = formatNumber(Math.round(pageSize / 1024 * 100) / 100); + sizeText = gBundle.getFormattedString("generalSize", [kbSize, formatNumber(pageSize)]); + } + setItemValue("sizetext", sizeText); + }); +} + +function ensureSelection(view) +{ + // only select something if nothing is currently selected + // and if there's anything to select + if (view.selection && view.selection.count == 0 && view.rowCount) + view.selection.select(0); +} + +function addImage(imageViewRow) +{ + let [url, type, alt, elem, isBg] = imageViewRow; + + if (!url) + return; + + if (!gImageHash.hasOwnProperty(url)) + gImageHash[url] = { }; + if (!gImageHash[url].hasOwnProperty(type)) + gImageHash[url][type] = { }; + if (!gImageHash[url][type].hasOwnProperty(alt)) { + gImageHash[url][type][alt] = gImageView.data.length; + var row = [url, type, gStrings.unknown, alt, 1, elem, isBg, -1, null, null]; + gImageView.addRow(row); + + // Fill in cache data asynchronously + openCacheEntry(url, function(cacheEntry) { + if (cacheEntry) { + // Update the corresponding data entries from the cache. + var imageSize = cacheEntry.dataSize; + // If it is not -1 then replace with actual value, else keep as unknown. + if (imageSize && imageSize != -1) { + var kbSize = Math.round(imageSize / 1024 * 100) / 100; + row[2] = gBundle.getFormattedString("mediaFileSize", + [formatNumber(kbSize)]); + row[7] = imageSize; + } + row[8] = cacheEntry.persistent; + row[9] = getContentTypeFromHeaders(cacheEntry); + // Invalidate the row to trigger a repaint. + gImageView.tree.invalidateRow(gImageView.data.indexOf(row)); + } + }); + + // Add the observer, only once. + if (gImageView.data.length == 1) { + Services.obs.addObserver(imagePermissionObserver, "perm-changed"); + } + } + else { + var i = gImageHash[url][type][alt]; + gImageView.data[i][COL_IMAGE_COUNT]++; + // The same image can occur several times on the page at different sizes. + // If the "View Image Info" context menu item was used, ensure we select + // the correct element. + if (!gImageView.data[i][COL_IMAGE_BG] && + gImageElement && url == gImageElement.currentSrc && + gImageElement.width == elem.width && + gImageElement.height == elem.height && + gImageElement.imageText == elem.imageText) { + gImageView.data[i][COL_IMAGE_NODE] = elem; + } + } +} + +//******** Form Stuff +function onFormSelect() +{ + if (gFormView.selection.count == 1) + { + var formPreview = document.getElementById("formpreview"); + gFieldView.clear(); + formPreview.view = gFieldView; + + var clickedRow = gFormView.selection.currentIndex; + // form-node; + var form = gFormView.data[clickedRow][3]; + + var ft = null; + if (form.name) + ft = gBundle.getFormattedString("formTitle", [form.name]); + + setItemValue("formenctype", form.encoding, gStrings.default); + setItemValue("formtarget", form.target, gStrings.formDefaultTarget); + document.getElementById("formname").value = ft || gStrings.formUntitled; + + gFieldView.addRows(form.formfields); + } +} + +//******** Link Stuff +function onBeginLinkDrag(event,urlField,descField) +{ + if (event.originalTarget.localName != "treechildren") + return; + + var tree = event.target; + if (!("treeBoxObject" in tree)) + tree = tree.parentNode; + + var row = tree.treeBoxObject.getRowAt(event.clientX, event.clientY); + if (row == -1) + return; + + // Adding URL flavor + var col = tree.columns[urlField]; + var url = tree.view.getCellText(row, col); + col = tree.columns[descField]; + var desc = tree.view.getCellText(row, col); + + var dataTransfer = event.dataTransfer; + dataTransfer.setData("text/x-moz-url", url + "\n" + desc); + dataTransfer.setData("text/url-list", url); + dataTransfer.setData("text/plain", url); +} + +//******** Image Stuff +function getSelectedRows(tree) { + var start = { }; + var end = { }; + var numRanges = tree.view.selection.getRangeCount(); + + var rowArray = [ ]; + for (var t = 0; t < numRanges; t++) { + tree.view.selection.getRangeAt(t, start, end); + for (var v = start.value; v <= end.value; v++) + rowArray.push(v); + } + + return rowArray; +} + +function getSelectedRow(tree) { + var rows = getSelectedRows(tree); + return (rows.length == 1) ? rows[0] : -1; +} + +function selectSaveFolder(aCallback) { + return selectSaveFolderTask(aCallback).catch(Cu.reportError); +} + +async function selectSaveFolderTask(aCallback) { + let titleText = gBundle.getString("mediaSelectFolder"); + let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); + + fp.init(window, titleText, Ci.nsIFilePicker.modeGetFolder); + fp.appendFilters(Ci.nsIFilePicker.filterAll); + try { + let initialDir = Services.prefs.getComplexValue("browser.download.dir", + Ci.nsIFile); + if (!initialDir) { + let downloadsDir = await Downloads.getSystemDownloadsDirectory(); + initialDir = new FileUtils.File(downloadsDir); + } + + fp.displayDirectory = initialDir; + } catch (ex) { + } + + let result = await new Promise(resolve => fp.open(resolve)); + + if (result == Ci.nsIFilePicker.returnOK) { + aCallback(fp.file.QueryInterface(Ci.nsIFile)); + } else { + aCallback(null); + } +} + +function saveMedia() +{ + var tree = document.getElementById("imagetree"); + var rowArray = getSelectedRows(tree); + if (rowArray.length == 1) { + let row = rowArray[0]; + let item = gImageView.data[row][COL_IMAGE_NODE]; + let url = gImageView.data[row][COL_IMAGE_ADDRESS]; + + if (url) { + let titleKey = "SaveImageTitle"; + + if (item instanceof HTMLVideoElement) + titleKey = "SaveVideoTitle"; + else if (item instanceof HTMLAudioElement) + titleKey = "SaveAudioTitle"; + + saveURL(url, null, titleKey, false, false, makeURI(item.baseURI), + null, gDocInfo.isContentWindowPrivate, + gDocument.nodePrincipal); + } + } else { + selectSaveFolder(function(aDirectory) { + if (aDirectory) { + var saveAnImage = function(aURIString, aChosenData, aBaseURI) { + uniqueFile(aChosenData.file); + internalSave(aURIString, null, null, null, null, false, + "SaveImageTitle", aChosenData, aBaseURI, null, false, + null, gDocInfo.isContentWindowPrivate, + gDocument.nodePrincipal); + }; + + for (var i = 0; i < rowArray.length; i++) { + let v = rowArray[i]; + let dir = aDirectory.clone(); + let item = gImageView.data[v][COL_IMAGE_NODE]; + let uriString = gImageView.data[v][COL_IMAGE_ADDRESS]; + let uri = makeURI(uriString); + + try { + uri.QueryInterface(Ci.nsIURL); + dir.append(decodeURIComponent(uri.fileName)); + } catch (ex) { + // data:/blob: uris + // Supply a dummy filename, otherwise Download Manager + // will try to delete the base directory on failure. + dir.append(gImageView.data[v][COL_IMAGE_TYPE]); + } + + if (i == 0) { + saveAnImage(uriString, new AutoChosen(dir, uri), makeURI(item.baseURI)); + } else { + // This delay is a hack which prevents the download manager + // from opening many times. See bug 377339. + setTimeout(saveAnImage, 200, uriString, new AutoChosen(dir, uri), + makeURI(item.baseURI)); + } + } + } + }); + } +} + +function onBlockImage(aChecked) +{ + var uri = makeURI(document.getElementById("imageurltext").value); + if (aChecked) + Services.perms.add(uri, "image", Services.perms.DENY_ACTION); + else + Services.perms.remove(uri, "image"); +} + +function onImageSelect() +{ + var previewBox = document.getElementById("mediaPreviewBox"); + var mediaSaveBox = document.getElementById("mediaSaveBox"); + var mediaSaveButton = document.getElementById("imagesaveasbutton"); + var splitter = document.getElementById("mediaSplitter"); + var tree = document.getElementById("imagetree"); + var count = tree.view.selection.count; + + if (count == 0) + { + previewBox.collapsed = true; + mediaSaveBox.collapsed = true; + mediaSaveButton.disabled = true; + splitter.collapsed = true; + tree.flex = 1; + } + else if (count > 1) + { + previewBox.collapsed = true; + mediaSaveBox.collapsed = false; + mediaSaveButton.disabled = false; + splitter.collapsed = true; + tree.flex = 1; + } + else + { + previewBox.collapsed = false; + mediaSaveBox.collapsed = true; + mediaSaveButton.disabled = false; + splitter.collapsed = false; + tree.flex = 0; + makePreview(tree.view.selection.currentIndex); + } +} + +// Makes the media preview (image, video, etc) for the selected row on +// the media tab. +function makePreview(row) +{ + var [url, type, sizeText, alt, count, item, isBG, imageSize, persistent, cachedType] = gImageView.data[row]; + var isAudio = false; + + setItemValue("imageurltext", url); + setItemValue("imagetext", item.imageText); + setItemValue("imagelongdesctext", item.longDesc); + + // get cache info + var sourceText; + switch (persistent) { + case true: + sourceText = gBundle.getString("generalDiskCache"); + break; + case false: + sourceText = gBundle.getString("generalMemoryCache"); + break; + default: + sourceText = gBundle.getString("generalNotCached"); + break; + } + setItemValue("imagesourcetext", sourceText); + + // find out the file size + var sizeText; + if (imageSize && imageSize != -1) { + var kbSize = Math.round(imageSize / 1024 * 100) / 100; + sizeText = gBundle.getFormattedString("generalSize", + [formatNumber(kbSize), + formatNumber(imageSize)]); + } + else + sizeText = gBundle.getString("mediaUnknownNotCached"); + setItemValue("imagesizetext", sizeText); + + var mimeType = item.mimeType || cachedType; + var numFrames = item.numFrames; + + var imageType; + if (mimeType) { + // We found the type, try to display it nicely + let imageMimeType = /^image\/(.*)/i.exec(mimeType); + if (imageMimeType) { + imageType = imageMimeType[1].toUpperCase(); + if (numFrames > 1) + imageType = gBundle.getFormattedString("mediaAnimatedImageType", + [imageType, numFrames]); + else + imageType = gBundle.getFormattedString("mediaImageType", [imageType]); + } + else { + // the MIME type doesn't begin with image/, display the raw type + imageType = mimeType; + } + } + else { + // We couldn't find the type, fall back to the value in the treeview + imageType = type; + } + + setItemValue("imagetypetext", imageType); + + var imageContainer = document.getElementById("theimagecontainer"); + var oldImage = document.getElementById("thepreviewimage"); + + var isProtocolAllowed = checkProtocol(gImageView.data[row]); + var isImageType = mimeType && mimeType.startsWith("image/"); + + var newImage = new Image; + newImage.id = "thepreviewimage"; + var physWidth = 0, physHeight = 0; + var width = 0, height = 0; + + if ((item.HTMLLinkElement || item.HTMLInputElement || + item.HTMLImageElement || item.SVGImageElement || + (item.HTMLObjectElement && isImageType) || + (item.HTMLEmbedElement && isImageType) || + isBG) && isProtocolAllowed) { + // We need to wait for the image to finish loading before + // using width & height. + newImage.addEventListener("loadend", function() { + physWidth = newImage.width || 0; + physHeight = newImage.height || 0; + + // "width" and "height" attributes must be set to newImage, + // even if there is no "width" or "height attribute in item; + // otherwise, the preview image cannot be displayed correctly. + // Since the image might have been loaded out-of-process, we expect + // the item to tell us its width / height dimensions. Failing that + // the item should tell us the natural dimensions of the image. Finally + // failing that, we'll assume that the image was never loaded in the + // other process (this can be true for favicons, for example), and so + // we'll assume that we can use the natural dimensions of the newImage + // we just created. If the natural dimensions of newImage are not known + // then the image is probably broken. + if (!isBG) { + newImage.width = ("width" in item && item.width) || + newImage.naturalWidth; + newImage.height = ("height" in item && item.height) || + newImage.naturalHeight; + } + else { + // The width and height of an HTML tag should not be used for its + // background image (for example, "table" can have "width" or "height" + // attributes). + newImage.width = item.naturalWidth || newImage.naturalWidth; + newImage.height = item.naturalHeight || newImage.naturalHeight; + } + + if (item.SVGImageElement) { + newImage.width = item.SVGImageElementWidth; + newImage.height = item.SVGImageElementHeight; + } + + width = newImage.width; + height = newImage.height; + + document.getElementById("theimagecontainer").collapsed = false + document.getElementById("brokenimagecontainer").collapsed = true; + + let imageSize = ""; + if (url) { + if (width != physWidth || height != physHeight) { + imageSize = gBundle.getFormattedString("mediaDimensionsScaled", + [formatNumber(physWidth), + formatNumber(physHeight), + formatNumber(width), + formatNumber(height)]); + } else { + imageSize = gBundle.getFormattedString("mediaDimensions", + [formatNumber(width), + formatNumber(height)]); + } + } + setItemValue("imagedimensiontext", imageSize); + }, {once: true}); + + newImage.setAttribute("src", url); + } + else { + // Handle the case where newImage is not used for width & height. + if (item.HTMLVideoElement && isProtocolAllowed) { + newImage = document.createElementNS("http://www.w3.org/1999/xhtml", "video"); + newImage.id = "thepreviewimage"; + newImage.src = url; + newImage.controls = true; + width = physWidth = item.videoWidth; + height = physHeight = item.videoHeight; + + document.getElementById("theimagecontainer").collapsed = false + document.getElementById("brokenimagecontainer").collapsed = true; + } + else if (item.HTMLAudioElement && isProtocolAllowed) { + newImage = new Audio; + newImage.id = "thepreviewimage"; + newImage.src = url; + newImage.controls = true; + newImage.preload = "metadata"; + isAudio = true; + + document.getElementById("theimagecontainer").collapsed = false + document.getElementById("brokenimagecontainer").collapsed = true; + } + else { + // fallback image for protocols not allowed (e.g., javascript:) + // or elements not [yet] handled (e.g., object, embed). + document.getElementById("brokenimagecontainer").collapsed = false; + document.getElementById("theimagecontainer").collapsed = true; + } + + let imageSize = ""; + if (url && !isAudio) { + imageSize = gBundle.getFormattedString("mediaDimensions", + [formatNumber(width), + formatNumber(height)]); + } + setItemValue("imagedimensiontext", imageSize); + } + + makeBlockImage(url); + + oldImage.remove(); + imageContainer.appendChild(newImage); +} + +function makeBlockImage(url) +{ + var checkbox = document.getElementById("blockImage"); + var imagePref = Services.prefs.getIntPref("permissions.default.image"); + if (!(/^https?:/.test(url)) || imagePref == 2) + // We can't block the images from this host because either is is not + // for http(s) or we don't load images at all + checkbox.hidden = true; + else { + var uri = makeURI(url); + if (uri.host) { + checkbox.hidden = false; + checkbox.label = gBundle.getFormattedString("mediaBlockImage", [uri.host]); + var perm = Services.perms.testPermission(uri, "image"); + checkbox.checked = perm == Services.perms.DENY_ACTION; + } + else + checkbox.hidden = true; + } +} + +var imagePermissionObserver = { + observe: function (aSubject, aTopic, aData) + { + if (document.getElementById("mediaPreviewBox").collapsed) + return; + + if (aTopic == "perm-changed") { + var permission = aSubject.QueryInterface(Ci.nsIPermission); + if (permission.type == "image") { + var imageTree = document.getElementById("imagetree"); + var row = imageTree.currentIndex; + var item = gImageView.data[row][COL_IMAGE_NODE]; + var url = gImageView.data[row][COL_IMAGE_ADDRESS]; + if (permission.matchesURI(makeURI(url), true)) + makeBlockImage(url); + } + } + } +} + +function getContentTypeFromHeaders(cacheEntryDescriptor) +{ + if (!cacheEntryDescriptor) + return null; + + let headers = cacheEntryDescriptor.getMetaDataElement("response-head"); + let type = /^Content-Type:\s*(.*?)\s*(?:\;|$)/mi.exec(headers); + return type && type[1]; +} + +function setItemValue(id, value, defaultString = gStrings.notSet) +{ + var item = document.getElementById(id); + if (value) { + item.disabled = false; + item.value = value; + } + else + { + item.value = defaultString; + item.disabled = true; + } +} + +function formatNumber(number) +{ + return (+number).toLocaleString(); // coerce number to a numeric value before calling toLocaleString() +} + +function formatDate(datestr, unknown) +{ + var date = new Date(datestr); + if (!date.valueOf()) + return unknown; + + const dateTimeFormatter = new Services.intl.DateTimeFormat(undefined, { + dateStyle: "full", timeStyle: "long"}); + return dateTimeFormatter.format(date); +} + +function getSelectedItems(linksMode) +{ + // linksMode is a boolean that is used to determine + // whether the getSelectedItems() function needs to + // run with urlSecurityCheck() or not. + + var elem = document.commandDispatcher.focusedElement; + + var view = elem.view; + var selection = view.selection; + var text = [], tmp = ''; + var min = {}, max = {}; + + var count = selection.getRangeCount(); + + for (var i = 0; i < count; i++) { + selection.getRangeAt(i, min, max); + + for (var row = min.value; row <= max.value; row++) { + tmp = view.getCellValue(row, null); + if (tmp) + { + try { + if (linksMode) + urlSecurityCheck(tmp, gDocInfo.principal); + text.push(tmp); + } + catch (e) { + } + } + } + } + + return text; +} + +function doCopy(isLinkMode) +{ + var text = getSelectedItems(isLinkMode); + + Cc["@mozilla.org/widget/clipboardhelper;1"] + .getService(Ci.nsIClipboardHelper) + .copyString(text.join("\n")); +} + +function doSelectAllMedia() +{ + var tree = document.getElementById("imagetree"); + + if (tree) + tree.view.selection.selectAll(); +} + +function doSelectAll() +{ + var elem = document.commandDispatcher.focusedElement; + + if (elem && "treeBoxObject" in elem) + elem.view.selection.selectAll(); +} + +function selectImage() { + if (!gImageElement) + return; + + var tree = document.getElementById("imagetree"); + for (var i = 0; i < tree.view.rowCount; i++) { + // If the image row element is the image selected from + // the "View Image Info" context menu item. + let image = gImageView.data[i][COL_IMAGE_NODE]; + if (!gImageView.data[i][COL_IMAGE_BG] && + gImageElement.currentSrc == gImageView.data[i][COL_IMAGE_ADDRESS] && + gImageElement.width == image.width && + gImageElement.height == image.height && + gImageElement.imageText == image.imageText) { + tree.view.selection.select(i); + tree.treeBoxObject.ensureRowIsVisible(i); + tree.focus(); + return; + } + } +} + +function checkProtocol(img) +{ + var url = img[COL_IMAGE_ADDRESS]; + return /^data:image\//i.test(url) || + /^(https?|ftp|file|about|chrome|resource):/.test(url); +} + +function onOpenIn(mode) +{ + var linkList = getSelectedItems(true); + + if (linkList.length) + openUILinkArrayIn(linkList, mode); +} diff --git a/comm/suite/browser/pageinfo/pageInfo.xul b/comm/suite/browser/pageinfo/pageInfo.xul new file mode 100644 index 0000000000..8f4dc2ae96 --- /dev/null +++ b/comm/suite/browser/pageinfo/pageInfo.xul @@ -0,0 +1,531 @@ +<?xml version="1.0"?><!-- -*- Mode: nXML; indent-tabs-mode: nil -*- --> +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + +<?xml-stylesheet href="chrome://navigator/skin/" type="text/css"?> +<?xml-stylesheet href="chrome://navigator/content/pageinfo/pageInfo.css" type="text/css"?> +<?xml-stylesheet href="chrome://navigator/skin/pageInfo.css" type="text/css"?> + +<!DOCTYPE window [ + <!ENTITY % pageInfoDTD SYSTEM "chrome://navigator/locale/pageInfo.dtd"> + %pageInfoDTD; +]> + +<window id="main-window" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + windowtype="Browser:page-info" + onload="onLoadPageInfo()" + onunload="onUnloadPageInfo()" + align="stretch" style="&pageInfoWindow.dimensions;" + persist="screenX screenY width height sizemode"> + + <script src="chrome://global/content/globalOverlay.js"/> + <script src="chrome://global/content/contentAreaUtils.js"/> + <script src="chrome://global/content/treeUtils.js"/> + <script src="chrome://communicator/content/utilityOverlay.js"/> + <script src="chrome://navigator/content/pageinfo/pageInfo.js"/> + <script src="chrome://navigator/content/pageinfo/feeds.js"/> + <script src="chrome://navigator/content/pageinfo/permissions.js"/> + <script src="chrome://navigator/content/pageinfo/security.js"/> + <script src="chrome://help/content/contextHelp.js"/> + <script src="chrome://communicator/content/tasksOverlay.js"/> + + <stringbundleset id="pageinfobundleset"> + <stringbundle id="pageinfobundle" src="chrome://navigator/locale/pageInfo.properties"/> + <stringbundle id="pkiBundle" src="chrome://pippki/locale/pippki.properties"/> + </stringbundleset> + + <commandset id="pageInfoCommandSet"> + <command id="cmd_close" oncommand="window.close();"/> + <command id="cmd_help" oncommand="doHelpButton();"/> + <command id="cmd_copy" oncommand="doCopy(false);"/> + <command id="cmd_selectall" oncommand="doSelectAll();"/> + + <!-- links tab --> + <command id="cmd_openInNewTab" oncommand="onOpenIn('tab');"/> + <command id="cmd_openInNewWindow" oncommand="onOpenIn('window');"/> + <command id="cmd_copyLinks" oncommand="doCopy(true);"/> + </commandset> + + <keyset> + <key key="&closeWindow.key;" modifiers="accel" command="cmd_close"/> + <key keycode="VK_ESCAPE" command="cmd_close"/> + <key key="." modifiers="meta" command="cmd_close"/> + <key keycode="VK_F1" command="cmd_help"/> + <key key="&openHelpMac.key;" modifiers="meta" command="cmd_help"/> + <key key="©.key;" modifiers="accel" command="cmd_copy"/> + <key key="&selectall.key;" modifiers="accel" command="cmd_selectall"/> + <key key="&selectall.key;" modifiers="alt" command="cmd_selectall"/> + </keyset> + + <menupopup id="picontext"> + <menuitem id="menu_selectall" label="&selectall.label;" command="cmd_selectall" accesskey="&selectall.accesskey;"/> + <menuitem id="menu_copy" label="©.label;" command="cmd_copy" accesskey="©.accesskey;"/> + </menupopup> + + <menupopup id="piLinksContext"> + <menuitem id="menu_openInNewTab" + label="&openInNewTab.label;" + command="cmd_openInNewTab" + accesskey="&openInNewTab.accesskey;"/> + <menuitem id="menu_openInNewWindow" + label="&openInNewWindow.label;" + command="cmd_openInNewWindow" + accesskey="&openInNewWindow.accesskey;"/> + <menuitem id="menu_selectall_links" + label="&selectall.label;" + command="cmd_selectall" + accesskey="&selectall.accesskey;"/> + <menuitem id="menu_copyLinks" + label="©Links.label;" + command="cmd_copyLinks" + accesskey="©Links.accesskey;"/> + </menupopup> + + <tabbox id="tabbox" flex="1"> + <vbox id="dragbox"> + <tabs id="tabs" + onselect="[gImageView, gFormView, gLinkView].forEach(ensureSelection);"> + <tab id="generalTab" + label="&generalTab;" + accesskey="&generalTab.accesskey;"/> + <tab id="mediaTab" + label="&mediaTab;" + accesskey="&mediaTab.accesskey;"/> + <tab id="feedTab" + label="&feedTab;" + accesskey="&feedTab.accesskey;"/> + <tab id="permTab" + label="&permTab;" + accesskey="&permTab.accesskey;"/> + <tab id="formsTab" + label="&formsTab;" + accesskey="&formsTab.accesskey;"/> + <tab id="linksTab" + label="&linksTab;" + accesskey="&linksTab.accesskey;"/> + <tab id="securityTab" + label="&securityTab;" + accesskey="&securityTab.accesskey;"/> + <!-- Others added by overlay --> + </tabs> + </vbox> + + <tabpanels id="mainDeck" flex="1"> + <!-- General page information --> + <vbox id="generalPanel"> + <grid> + <columns> + <column/> + <column class="gridSeparator"/> + <column flex="1"/> + </columns> + <rows> + <row id="generalTitle"> + <label control="titletext" value="&generalTitle;"/> + <separator/> + <textbox readonly="true" id="titletext"/> + </row> + <row> + <label control="urltext" value="&generalURL;"/> + <separator/> + <textbox readonly="true" id="urltext" class="urltext"/> + </row> + <row> + <separator class="thin"/> + </row> + <row> + <label control="typetext" value="&generalType;"/> + <separator/> + <textbox readonly="true" id="typetext"/> + </row> + <row> + <label control="modetext" value="&generalMode;"/> + <separator/> + <textbox readonly="true" crop="end" id="modetext"/> + </row> + <row> + <label control="encodingtext" value="&generalEncoding2;"/> + <separator/> + <textbox readonly="true" id="encodingtext"/> + </row> + <row> + <label control="sizetext" value="&generalSize;"/> + <separator/> + <textbox readonly="true" id="sizetext"/> + </row> + <row> + <label control="refertext" value="&generalReferrer;"/> + <separator/> + <textbox readonly="true" id="refertext" class="urltext"/> + </row> + <row> + <separator class="thin"/> + </row> + <row> + <label control="modifiedtext" value="&generalModified;"/> + <separator/> + <textbox readonly="true" id="modifiedtext"/> + </row> + </rows> + </grid> + <separator class="thin"/> + <groupbox id="metaTags" flex="1"> + <caption id="metaTagsCaption"/> + <tree id="metatree" flex="1" hidecolumnpicker="true" contextmenu="picontext"> + <treecols> + <treecol id="meta-name" label="&generalMetaName;" + persist="width" flex="1"/> + <splitter class="tree-splitter"/> + <treecol id="meta-content" label="&generalMetaContent;" + persist="width" flex="4"/> + </treecols> + <treechildren flex="1"/> + </tree> + </groupbox> + <groupbox id="securityBox"> + <caption id="securityBoxCaption" label="&securityHeader;"/> + <description id="general-security-identity" class="indent header"/> + <description id="general-security-privacy" class="indent header"/> + <hbox align="right"> + <button id="security-view-details" label="&generalSecurityDetails;" + accesskey="&generalSecurityDetails.accesskey;" + oncommand="onClickMore();"/> + </hbox> + </groupbox> + </vbox> + + <!-- Media information --> + <vbox id="mediaPanel"> + <tree id="imagetree" onselect="onImageSelect();" contextmenu="picontext" + ondragstart="onBeginLinkDrag(event,'image-address','image-alt')"> + <treecols> + <treecol sortSeparators="true" primary="true" persist="width" flex="10" + width="10" id="image-address" label="&mediaAddress;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="2" + width="2" id="image-type" label="&mediaType;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" hidden="true" persist="hidden width" flex="2" + width="2" id="image-size" label="&mediaSize;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" hidden="true" persist="hidden width" flex="4" + width="4" id="image-alt" label="&mediaAltHeader;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" hidden="true" persist="hidden width" flex="1" + width="1" id="image-count" label="&mediaCount;"/> + </treecols> + <treechildren flex="1"/> + </tree> + <splitter orient="vertical" id="mediaSplitter"/> + <vbox flex="1" id="mediaPreviewBox"> + <grid id="mediaGrid"> + <columns> + <column id="mediaLabelColumn"/> + <column class="gridSeparator"/> + <column flex="1"/> + </columns> + <rows> + <row> + <label control="imageurltext" value="&mediaLocation;"/> + <separator/> + <textbox readonly="true" id="imageurltext" class="urltext"/> + </row> + <row> + <label control="imagetypetext" value="&generalType;"/> + <separator/> + <textbox readonly="true" id="imagetypetext"/> + </row> + <row> + <label control="imagesourcetext" value="&generalSource;"/> + <separator/> + <textbox readonly="true" id="imagesourcetext"/> + </row> + <row> + <label control="imagesizetext" value="&generalSize;"/> + <separator/> + <textbox readonly="true" id="imagesizetext"/> + </row> + <row> + <label control="imagedimensiontext" value="&mediaDimension;"/> + <separator/> + <textbox readonly="true" id="imagedimensiontext"/> + </row> + <row> + <label control="imagetext" value="&mediaText;"/> + <separator/> + <textbox readonly="true" id="imagetext"/> + </row> + <row> + <label control="imagelongdesctext" value="&mediaLongdesc;"/> + <separator/> + <textbox readonly="true" id="imagelongdesctext"/> + </row> + </rows> + </grid> + <hbox align="end"> + <vbox> + <checkbox id="blockImage" + hidden="true" + oncommand="onBlockImage(this.checked);" + accesskey="&mediaBlockImage.accesskey;"/> + <label control="thepreviewimage" value="&mediaPreview;" class="header"/> + </vbox> + <spacer flex="1"/> + <button label="&selectall.label;" accesskey="&selectall.accesskey;" + id="selectallbutton" + oncommand="doSelectAllMedia();"/> + <button label="&mediaSaveAs;" accesskey="&mediaSaveAs.accesskey;" + icon="save" id="imagesaveasbutton" disabled="true" + oncommand="saveMedia();"/> + </hbox> + <vbox class="inset iframe" flex="1" pack="center"> + <hbox id="theimagecontainer" pack="center"> + <image id="thepreviewimage"/> + </hbox> + <hbox id="brokenimagecontainer" pack="center" collapsed="true"> + <image id="brokenimage" src="resource://gre-resources/broken-image.png"/> + </hbox> + </vbox> + </vbox> + <hbox id="mediaSaveBox" collapsed="true"> + <spacer flex="1"/> + <button label="&mediaSaveAs;" accesskey="&mediaSaveAs2.accesskey;" + icon="save" oncommand="saveMedia();"/> + </hbox> + </vbox> + + <!-- Feeds --> + <vbox id="feedPanel"> + <richlistbox id="feedListbox" flex="1"/> + </vbox> + + <!-- Permissions --> + <vbox id="permPanel"> + <hbox> + <label control="hostText" value="&permissionsFor;"/> + <textbox id="hostText" class="header" readonly="true" + crop="end" flex="1"/> + </hbox> + + <!-- + The richlist below is generated by permissions.js. + The labels point to the radio groups to give the radio buttons + an accessible context. The accessible context for the preceeding + checkbox is already taken care of through the richlistitem grouping. + --> + <richlistbox id="permList" flex="1"/> + </vbox> + + <!-- Form information --> + <vbox> + <tree id="formtree" class="fixedsize" onselect="onFormSelect();" contextmenu="picontext"> + <treecols> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" primary="true" persist="width" flex="1" + width="1" id="form-name" label="&formName;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="3" + width="3" id="form-method" label="&formMethod;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="2" + width="2" id="form-action" label="&formAction;"/> + </treecols> + <treechildren flex="1"/> + </tree> + <splitter orient="vertical"/> + <vbox flex="1"> + <textbox readonly="true" class="header" id="formname"/> + <grid> + <columns> + <column/> + <column style="width: .5em;"/> + <column flex="1"/> + </columns> + <rows> + <row> + <label control="formenctype" value="&formEncoding;"/> + <separator/> + <textbox readonly="true" id="formenctype"/> + </row> + <row> + <label control="formtarget" value="&formTarget;"/> + <separator/> + <textbox readonly="true" class="label" id="formtarget"/> + </row> + </rows> + </grid> + <label control="formpreview" class="header" value="&formFields;"/> + <tree id="formpreview" flex="1" contextmenu="picontext"> + <treecols> + <treecol sortSeparators="true" primary="true" persist="width" flex="3" + width="3" id="field-label" label="&formLabel;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="3" + width="3" id="field-field" label="&formFName;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="1" + width="1" id="field-type" label="&formType;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="3" + width="3" id="field-value" label="&formCValue;"/> + </treecols> + <treechildren flex="1"/> + </tree> + </vbox> + </vbox> + + <!-- Link info --> + <vbox> + <tree id="linktree" + flex="1" + ondragstart="onBeginLinkDrag(event,'link-address','link-name')" + contextmenu="piLinksContext"> + <treecols> + <treecol sortSeparators="true" primary="true" persist="width" flex="5" + width="5" id="link-name" label="&linkName;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="7" + width="7" id="link-address" label="&linkAddress;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="2" + width="2" id="link-type" label="&linkType;"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="2" + width="2" id="link-target" label="&linkTarget;" hidden="true"/> + <splitter class="tree-splitter"/> + <treecol sortSeparators="true" persist="hidden width" flex="1" + width="1" id="link-accesskey" label="&linkAccessKey;" hidden="true"/> + </treecols> + <treechildren flex="1"/> + </tree> + </vbox> + + <!-- Security & Privacy --> + <vbox id="securityPanel"> + <!-- Identity Section --> + <groupbox id="security-identity-groupbox" flex="1"> + <caption id="security-identity" label="&securityView.identity.header;"/> + <hbox> + <image id="identity-icon"/> + <grid flex="1"> + <columns> + <column/> + <column flex="1"/> + </columns> + <rows> + <row><!-- Domain --> + <label control="security-identity-domain-value" + id="security-identity-domain-label" + class="fieldLabel" + value="&securityView.identity.domain;"/> + <textbox id="security-identity-domain-value" + class="fieldValue" readonly="true"/> + </row> + <row><!-- Owner --> + <label control="security-identity-owner-value" + id="security-identity-owner-label" + class="fieldLabel" + value="&securityView.identity.owner;"/> + <textbox id="security-identity-owner-value" + class="fieldValue" readonly="true"/> + </row> + <row><!-- Verifier --> + <label control="security-identity-verifier-value" + id="security-identity-verifier-label" + class="fieldLabel" + value="&securityView.identity.verifier;"/> + <textbox id="security-identity-verifier-value" + class="fieldValue" readonly="true"/> + </row> + <!-- Certificate Validity --> + <row id="security-identity-validity-row"> + <label id="security-identity-validity-label" + class="fieldLabel" + value="&securityView.identity.validity;" + control="security-identity-validity-value"/> + <textbox id="security-identity-validity-value" + class="fieldValue" readonly="true" /> + </row> + </rows> + </grid> + </hbox> + <spacer flex="1"/> + <hbox pack="end"><!-- Cert button --> + <button id="security-view-cert" label="&securityView.certView;" + accesskey="&securityView.accesskey;" + oncommand="security.viewCert();"/> + </hbox> + </groupbox> + + <!-- Privacy & History section --> + <groupbox id="security-privacy-groupbox" flex="1"> + <caption id="security-privacy" label="&securityView.privacy.header;" /> + <grid> + <columns> + <column flex="1"/> + <column flex="1"/> + </columns> + <rows> + <row align="center"><!-- History --> + <label id="security-privacy-history-label" + control="security-privacy-history-value" + class="fieldLabel">&securityView.privacy.history;</label> + <textbox id="security-privacy-history-value" + class="fieldValue" + value="&securityView.unknown;" + readonly="true"/> + </row> + <row align="center"><!-- Cookies --> + <label id="security-privacy-cookies-label" + control="security-privacy-cookies-value" + class="fieldLabel">&securityView.privacy.cookies;</label> + <hbox align="center"> + <textbox id="security-privacy-cookies-value" + class="fieldValue" + value="&securityView.unknown;" + flex="1" + readonly="true"/> + <button id="security-view-cookies" + label="&securityView.privacy.viewCookies;" + accesskey="&securityView.privacy.viewCookies.accessKey;" + oncommand="security.viewCookies();"/> + </hbox> + </row> + <row align="center"><!-- Passwords --> + <label id="security-privacy-passwords-label" + control="security-privacy-passwords-value" + class="fieldLabel">&securityView.privacy.passwords;</label> + <hbox align="center"> + <textbox id="security-privacy-passwords-value" + class="fieldValue" + value="&securityView.unknown;" + flex="1" + readonly="true"/> + <button id="security-view-password" + label="&securityView.privacy.viewPasswords;" + accesskey="&securityView.privacy.viewPasswords.accessKey;" + oncommand="security.viewPasswords();"/> + </hbox> + </row> + </rows> + </grid> + </groupbox> + + <!-- Technical Details section --> + <groupbox id="security-technical-groupbox" flex="1"> + <caption id="security-technical" label="&securityView.technical.header;" /> + <vbox flex="1"> + <label id="security-technical-shortform" class="fieldValue"/> + <description id="security-technical-longform1" class="fieldLabel"/> + <description id="security-technical-longform2" class="fieldLabel"/> + <description id="security-technical-certificate-transparency" class="fieldLabel"/> + </vbox> + </groupbox> + </vbox> + + <!-- Others added by overlay --> + </tabpanels> + </tabbox> +</window> diff --git a/comm/suite/browser/pageinfo/permissions.js b/comm/suite/browser/pageinfo/permissions.js new file mode 100644 index 0000000000..7d126d6ea7 --- /dev/null +++ b/comm/suite/browser/pageinfo/permissions.js @@ -0,0 +1,204 @@ +/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. */ + +const { SitePermissions } = ChromeUtils.import("resource:///modules/SitePermissions.jsm"); +const { BrowserUtils } = ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm""); + +var gPermPrincipal; + +// Array of permissionIDs sorted alphabetically by label. +var gPermissions = SitePermissions.listPermissions().sort((a, b) => { + let firstLabel = SitePermissions.getPermissionLabel(a); + let secondLabel = SitePermissions.getPermissionLabel(b); + return firstLabel.localeCompare(secondLabel); +}); + +var permissionObserver = { + observe: function (aSubject, aTopic, aData) + { + if (aTopic == "perm-changed") { + var permission = aSubject.QueryInterface(Ci.nsIPermission); + if (permission.matches(gPermPrincipal, true) && + gPermissions.includes(permission.type)) { + initRow(permission.type); + } + } + } +}; + +function initPermission() +{ + onUnloadRegistry.push(onUnloadPermission); + onResetRegistry.push(onUnloadPermission); +} + +function onLoadPermission(uri, principal) +{ + var permTab = document.getElementById("permTab"); + if (!SitePermissions.isSupportedPrincipal(principal)) { + permTab.hidden = true; + return; + } + + gPermPrincipal = principal; + if (gPermPrincipal && !gPermPrincipal.isSystemPrincipal) { + var hostText = document.getElementById("hostText"); + hostText.value = gPermPrincipal.origin; + Services.obs.addObserver(permissionObserver, "perm-changed"); + } + for (var i of gPermissions) + initRow(i); + permTab.hidden = false; +} + +function onUnloadPermission() +{ + if (gPermPrincipal && !gPermPrincipal.isSystemPrincipal) { + Services.obs.removeObserver(permissionObserver, "perm-changed"); + } +} + +function initRow(aPartId) +{ + createRow(aPartId); + + var checkbox = document.getElementById(aPartId + "Def"); + var command = document.getElementById("cmd_" + aPartId + "Toggle"); + if (gPermPrincipal && gPermPrincipal.isSystemPrincipal) { + checkbox.checked = false; + checkbox.setAttribute("disabled", "true"); + command.setAttribute("disabled", "true"); + document.getElementById(aPartId + "RadioGroup").selectedItem = null; + return; + } + checkbox.removeAttribute("disabled"); + var {state} = SitePermissions.getForPrincipal(gPermPrincipal, aPartId); + let defaultState = SitePermissions.getDefault(aPartId); + + // Since cookies preferences have many different possible configuration states + // we don't consider any permission except "no permission" to be default. + if (aPartId == "cookie") { + state = Services.perms.testPermissionFromPrincipal(gPermPrincipal, "cookie"); + + if (state == SitePermissions.UNKNOWN) { + checkbox.checked = true; + command.setAttribute("disabled", "true"); + // Don't select any item in the radio group, as we can't + // confidently say that all cookies on the site will be allowed. + let radioGroup = document.getElementById("cookieRadioGroup"); + radioGroup.selectedItem = null; + } else { + checkbox.checked = false; + command.removeAttribute("disabled"); + } + + setRadioState(aPartId, state); + return; + } + + if (state != defaultState) { + checkbox.checked = false; + command.removeAttribute("disabled"); + } + else { + checkbox.checked = true; + command.setAttribute("disabled", "true"); + } + setRadioState(aPartId, state); +} + +function createRow(aPartId) { + let rowId = "perm-" + aPartId + "-row"; + if (document.getElementById(rowId)) + return; + + let commandId = "cmd_" + aPartId + "Toggle"; + let labelId = "perm-" + aPartId + "-label"; + let radiogroupId = aPartId + "RadioGroup"; + + let command = document.createElement("command"); + command.setAttribute("id", commandId); + command.setAttribute("oncommand", "onRadioClick('" + aPartId + "');"); + document.getElementById("pageInfoCommandSet").appendChild(command); + + let row = document.createElement("richlistitem"); + row.setAttribute("id", rowId); + row.setAttribute("class", "permission"); + row.setAttribute("orient", "vertical"); + + let label = document.createElement("label"); + label.setAttribute("id", labelId); + label.setAttribute("control", radiogroupId); + label.setAttribute("value", SitePermissions.getPermissionLabel(aPartId)); + label.setAttribute("class", "permissionLabel"); + row.appendChild(label); + + let controls = document.createElement("hbox"); + controls.setAttribute("role", "group"); + controls.setAttribute("aria-labelledby", labelId); + + let checkbox = document.createElement("checkbox"); + checkbox.setAttribute("id", aPartId + "Def"); + checkbox.setAttribute("oncommand", "onCheckboxClick('" + aPartId + "');"); + checkbox.setAttribute("label", gBundle.getString("permissions.useDefault")); + controls.appendChild(checkbox); + + let spacer = document.createElement("spacer"); + spacer.setAttribute("flex", "1"); + controls.appendChild(spacer); + + let radiogroup = document.createElement("radiogroup"); + radiogroup.setAttribute("id", radiogroupId); + radiogroup.setAttribute("orient", "horizontal"); + for (let state of SitePermissions.getAvailableStates(aPartId)) { + let radio = document.createElement("radio"); + radio.setAttribute("id", aPartId + "#" + state); + radio.setAttribute("label", SitePermissions.getMultichoiceStateLabel(aPartId, state)); + radio.setAttribute("command", commandId); + radiogroup.appendChild(radio); + } + controls.appendChild(radiogroup); + + row.appendChild(controls); + + document.getElementById("permList").appendChild(row); +} + +function onCheckboxClick(aPartId) +{ + var command = document.getElementById("cmd_" + aPartId + "Toggle"); + var checkbox = document.getElementById(aPartId + "Def"); + if (checkbox.checked) { + SitePermissions.removeFromPrincipal(gPermPrincipal, aPartId); + command.setAttribute("disabled", "true"); + } + else { + onRadioClick(aPartId); + command.removeAttribute("disabled"); + } +} + +function onRadioClick(aPartId) +{ + var radioGroup = document.getElementById(aPartId + "RadioGroup"); + let permission; + if (radioGroup.selectedItem) { + permission = parseInt(radioGroup.selectedItem.id.split("#")[1]); + } else { + permission = SitePermissions.getDefault(aPartId); + } + SitePermissions.setForPrincipal(gPermPrincipal, aPartId, permission); +} + +function setRadioState(aPartId, aValue) +{ + var radio = document.getElementById(aPartId + "#" + aValue); + if (radio) { + radio.radioGroup.selectedItem = radio; + } +} diff --git a/comm/suite/browser/pageinfo/security.js b/comm/suite/browser/pageinfo/security.js new file mode 100644 index 0000000000..f6357c9ac4 --- /dev/null +++ b/comm/suite/browser/pageinfo/security.js @@ -0,0 +1,354 @@ +/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +ChromeUtils.defineModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); + +var security = { + init: function(uri, windowInfo) { + this.uri = uri; + this.windowInfo = windowInfo; + }, + + // Display the server certificate (static) + viewCert : function() { + var cert = security._cert; + viewCertHelper(window, cert); + }, + + _getSecurityInfo : function() { + // We don't have separate info for a frame, return null until further notice + // (see bug 138479) + if (!this.windowInfo.isTopWindow) + return null; + + var hostName = this.windowInfo.hostName; + + var ui = security._getSecurityUI(); + if (!ui) + return null; + + var isBroken = + (ui.state & Ci.nsIWebProgressListener.STATE_IS_BROKEN); + var isMixed = + (ui.state & (Ci.nsIWebProgressListener.STATE_LOADED_MIXED_ACTIVE_CONTENT | + Ci.nsIWebProgressListener.STATE_LOADED_MIXED_DISPLAY_CONTENT)); + var isInsecure = + (ui.state & Ci.nsIWebProgressListener.STATE_IS_INSECURE); + var isEV = + (ui.state & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL); + var status = ui.QueryInterface(Ci.nsISSLStatusProvider).SSLStatus; + + if (!isInsecure && status) { + status.QueryInterface(Ci.nsISSLStatus); + var cert = status.serverCert; + var issuerName = cert.issuerOrganization || cert.issuerName; + + var retval = { + hostName : hostName, + cAName : issuerName, + encryptionAlgorithm : undefined, + encryptionStrength : undefined, + version: undefined, + isBroken : isBroken, + isMixed : isMixed, + isEV : isEV, + cert : cert, + certificateTransparency : undefined, + }; + + var version; + try { + retval.encryptionAlgorithm = status.cipherName; + retval.encryptionStrength = status.secretKeyLength; + version = status.protocolVersion; + } + catch (e) { + } + + switch (version) { + case Ci.nsISSLStatus.SSL_VERSION_3: + retval.version = "SSL 3"; + break; + case Ci.nsISSLStatus.TLS_VERSION_1: + retval.version = "TLS 1.0"; + break; + case Ci.nsISSLStatus.TLS_VERSION_1_1: + retval.version = "TLS 1.1"; + break; + case Ci.nsISSLStatus.TLS_VERSION_1_2: + retval.version = "TLS 1.2"; + break; + case Ci.nsISSLStatus.TLS_VERSION_1_3: + retval.version = "TLS 1.3"; + break; + } + + // Select the status text to display for Certificate Transparency. + // Since we do not yet enforce the CT Policy on secure connections, + // we must not complain on policy discompliance (it might be viewed + // as a security issue by the user). + switch (status.certificateTransparencyStatus) { + case Ci.nsISSLStatus.CERTIFICATE_TRANSPARENCY_NOT_APPLICABLE: + case Ci.nsISSLStatus.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS: + case Ci.nsISSLStatus.CERTIFICATE_TRANSPARENCY_POLICY_NOT_DIVERSE_SCTS: + retval.certificateTransparency = null; + break; + case Ci.nsISSLStatus.CERTIFICATE_TRANSPARENCY_POLICY_COMPLIANT: + retval.certificateTransparency = "Compliant"; + break; + } + + return retval; + } + return { + hostName : hostName, + cAName : "", + encryptionAlgorithm : "", + encryptionStrength : 0, + version: "", + isBroken : isBroken, + isMixed : isMixed, + isEV : isEV, + cert : null, + certificateTransparency : null, + }; + }, + + // Find the secureBrowserUI object (if present) + _getSecurityUI : function() { + if (window.opener.gBrowser) + return window.opener.gBrowser.securityUI; + return null; + }, + + /** + * Open the cookie manager window + */ + viewCookies : function() + { + var eTLD; + try { + eTLD = Services.eTLD.getBaseDomain(this.uri); + } catch (e) { + // getBaseDomain will fail if the host is an IP address or is empty + eTLD = this.uri.asciiHost; + } + + toDataManager(eTLD + '|cookies'); + }, + + /** + * Open the login manager window + */ + viewPasswords : function() + { + toDataManager(this._getSecurityInfo().hostName + '|passwords'); + }, + + _cert : null +}; + +function securityOnLoad(uri, windowInfo) { + security.init(uri, windowInfo); + + var info = security._getSecurityInfo(); + if (!info || uri.scheme === "about") { + document.getElementById("securityTab").hidden = true; + document.getElementById("securityBox").hidden = true; + return; + } + + document.getElementById("securityTab").hidden = false; + document.getElementById("securityBox").hidden = false; + + const pageInfoBundle = document.getElementById("pageinfobundle"); + + /* Set Identity section text */ + setText("security-identity-domain-value", info.hostName); + + var owner; + var verifier; + var generalPageIdentityString; + var identityClass; + var validity; + if (info.cert && !info.isBroken) { + validity = info.cert.validity.notAfterLocalDay; + + // Try to pull out meaningful values. Technically these fields are optional + // so we'll employ fallbacks where appropriate. The EV spec states that Org + // fields must be specified for subject and issuer so that case is simpler. + if (info.isEV) { + owner = info.cert.organization; + verifier = info.cAName; + generalPageIdentityString = + pageInfoBundle.getFormattedString("generalSiteIdentity", + [owner, verifier]); + identityClass = "verifiedIdentity"; + } else { + // Technically, a non-EV cert might specify an owner in the O field or + // not, depending on the CA's issuing policies. However we don't have any + // programmatic way to tell those apart, and no policy way to establish + // which organization vetting standards are good enough (that's what EV is + // for) so we default to treating these certs as domain-validated only. + owner = pageInfoBundle.getString("securityNoOwner"); + verifier = info.cAName || info.cert.issuerCommonName || info.cert.issuerName; + generalPageIdentityString = owner; + identityClass = "verifiedDomain"; + } + } else { + // We don't have valid identity credentials. + owner = pageInfoBundle.getString("securityNoOwner"); + verifier = pageInfoBundle.getString("notSet"); + generalPageIdentityString = owner; + identityClass = ""; + } + + setText("security-identity-owner-value", owner); + setText("security-identity-verifier-value", verifier); + setText("general-security-identity", generalPageIdentityString); + document.getElementById("identity-icon").className = identityClass; + if (validity) { + setText("security-identity-validity-value", validity); + } else { + document.getElementById("security-identity-validity-row").hidden = true; + } + + /* Manage the View Cert button*/ + if (info.cert) + security._cert = info.cert; + document.getElementById("security-view-cert").collapsed = !info.cert; + + /* Set Privacy & History section text */ + var yesStr = pageInfoBundle.getString("yes"); + var noStr = pageInfoBundle.getString("no"); + + var hasCookies = hostHasCookies(uri); + setText("security-privacy-cookies-value", hasCookies ? yesStr : noStr); + document.getElementById("security-view-cookies").disabled = !hasCookies; + var hasPasswords = realmHasPasswords(uri); + setText("security-privacy-passwords-value", hasPasswords ? yesStr : noStr); + document.getElementById("security-view-password").disabled = !hasPasswords; + + var visitCount = previousVisitCount(info.hostName); + let visitCountStr = visitCount > 0 + ? PluralForm.get(visitCount, pageInfoBundle.getString("securityVisitsNumber")) + .replace("#1", visitCount.toLocaleString()) + : pageInfoBundle.getString("securityNoVisits"); + setText("security-privacy-history-value", visitCountStr); + + /* Set the Technical Detail section messages */ + const pkiBundle = document.getElementById("pkiBundle"); + var hdr; + var msg1; + var msg2; + + if (info.isBroken) { + if (info.isMixed) { + hdr = pkiBundle.getString("pageInfo_MixedContent"); + msg1 = pkiBundle.getString("pageInfo_MixedContent2"); + } else { + hdr = pkiBundle.getFormattedString("pageInfo_BrokenEncryption", + [info.encryptionAlgorithm, + info.encryptionStrength + "", + info.version]); + msg1 = pkiBundle.getString("pageInfo_WeakCipher"); + } + msg2 = pkiBundle.getString("pageInfo_Privacy_None2"); + } else if (info.encryptionStrength > 0) { + hdr = pkiBundle.getFormattedString("pageInfo_EncryptionWithBitsAndProtocol", + [info.encryptionAlgorithm, + info.encryptionStrength + "", + info.version]); + msg1 = pkiBundle.getString("pageInfo_Privacy_Encrypted1"); + msg2 = pkiBundle.getString("pageInfo_Privacy_Encrypted2"); + security._cert = info.cert; + } else { + hdr = pkiBundle.getString("pageInfo_NoEncryption"); + if (info.hostName != null) { + msg1 = pkiBundle.getFormattedString("pageInfo_Privacy_None1", [info.hostName]); + } else { + msg1 = pkiBundle.getString("pageInfo_Privacy_None4"); + } + msg2 = pkiBundle.getString("pageInfo_Privacy_None2"); + } + setText("security-technical-shortform", hdr); + setText("security-technical-longform1", msg1); + setText("security-technical-longform2", msg2); + setText("general-security-privacy", hdr); + + const ctStatus = + document.getElementById("security-technical-certificate-transparency"); + if (info.certificateTransparency) { + ctStatus.hidden = false; + ctStatus.value = pkiBundle.getString( + "pageInfo_CertificateTransparency_" + info.certificateTransparency); + } else { + ctStatus.hidden = true; + } +} + +function setText(id, value) +{ + var element = document.getElementById(id); + if (!element) + return; + if (element.localName == "textbox" || element.localName == "label") + element.value = value; + else + element.textContent = value; +} + +function viewCertHelper(parent, cert) +{ + if (!cert) + return; + + var cd = Cc[CERTIFICATEDIALOGS_CONTRACTID].getService(nsICertificateDialogs); + cd.viewCert(parent, cert); +} + +/** + * Return true iff we have cookies for uri. + */ +function hostHasCookies(aUri) { + return Services.cookies.countCookiesFromHost(aUri.asciiHost) > 0; +} + +/** + * Return true iff realm (proto://host:port) (extracted from uri) has + * saved passwords + */ +function realmHasPasswords(aUri) { + return Services.logins.countLogins(aUri.prePath, "", "") > 0; +} + +/** + * Return the number of previous visits recorded for host before today. + * + * @param host - the domain name to look for in history + */ +function previousVisitCount(host, endTimeReference) { + if (!host) + return false; + + var historyService = Cc["@mozilla.org/browser/nav-history-service;1"] + .getService(Ci.nsINavHistoryService); + + var options = historyService.getNewQueryOptions(); + options.resultType = options.RESULTS_AS_VISIT; + + // Search for visits to this host before today + var query = historyService.getNewQuery(); + query.endTimeReference = query.TIME_RELATIVE_TODAY; + query.endTime = 0; + query.domain = host; + + var result = historyService.executeQuery(query, options); + result.root.containerOpen = true; + var cc = result.root.childCount; + result.root.containerOpen = false; + return cc; +} |