summaryrefslogtreecommitdiff
path: root/components/cookie
diff options
context:
space:
mode:
Diffstat (limited to 'components/cookie')
-rw-r--r--components/cookie/content/cookieAcceptDialog.js203
-rw-r--r--components/cookie/content/cookieAcceptDialog.xul118
-rw-r--r--components/cookie/jar.mn8
-rw-r--r--components/cookie/locale/cookieAcceptDialog.dtd21
-rw-r--r--components/cookie/locale/cookieAcceptDialog.properties21
-rw-r--r--components/cookie/moz.build6
6 files changed, 377 insertions, 0 deletions
diff --git a/components/cookie/content/cookieAcceptDialog.js b/components/cookie/content/cookieAcceptDialog.js
new file mode 100644
index 000000000..5f5760305
--- /dev/null
+++ b/components/cookie/content/cookieAcceptDialog.js
@@ -0,0 +1,203 @@
+// -*- indent-tabs-mode: nil; js-indent-level: 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/. */
+
+const nsICookieAcceptDialog = Components.interfaces.nsICookieAcceptDialog;
+const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
+const nsICookie = Components.interfaces.nsICookie;
+const nsICookiePromptService = Components.interfaces.nsICookiePromptService;
+
+Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
+
+var params;
+var cookieBundle;
+var gDateService = null;
+
+var showDetails = "";
+var hideDetails = "";
+var detailsAccessKey = "";
+
+function onload()
+{
+ doSetOKCancel(cookieAcceptNormal, cookieDeny, cookieAcceptSession);
+
+ var dialog = document.documentElement;
+
+ document.getElementById("Button2").collapsed = false;
+
+ document.getElementById("ok").label = dialog.getAttribute("acceptLabel");
+ document.getElementById("ok").accessKey = dialog.getAttribute("acceptKey");
+ document.getElementById("Button2").label = dialog.getAttribute("extra1Label");
+ document.getElementById("Button2").accessKey = dialog.getAttribute("extra1Key");
+ document.getElementById("cancel").label = dialog.getAttribute("cancelLabel");
+ document.getElementById("cancel").accessKey = dialog.getAttribute("cancelKey");
+
+ // hook up button icons where implemented
+ document.getElementById("ok").setAttribute("icon", "accept");
+ document.getElementById("cancel").setAttribute("icon", "cancel");
+ document.getElementById("disclosureButton").setAttribute("icon", "properties");
+
+ // Initialize the date formatter
+ if (!gDateService) {
+ const nsScriptableDateFormat_CONTRACTID = "@mozilla.org/intl/scriptabledateformat;1";
+ const nsIScriptableDateFormat = Components.interfaces.nsIScriptableDateFormat;
+ gDateService = Components.classes[nsScriptableDateFormat_CONTRACTID]
+ .getService(nsIScriptableDateFormat);
+ }
+
+ cookieBundle = document.getElementById("cookieBundle");
+
+ // cache strings
+ if (!showDetails) {
+ showDetails = cookieBundle.getString('showDetails');
+ }
+ if (!hideDetails) {
+ hideDetails = cookieBundle.getString('hideDetails');
+ }
+ detailsAccessKey = cookieBundle.getString('detailsAccessKey');
+
+ if (document.getElementById('infobox').hidden) {
+ document.getElementById('disclosureButton').setAttribute("label", showDetails);
+ } else {
+ document.getElementById('disclosureButton').setAttribute("label", hideDetails);
+ }
+ document.getElementById('disclosureButton').setAttribute("accesskey", detailsAccessKey);
+
+ if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) {
+ try {
+ params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
+ var cookie = params.objects.queryElementAt(0, nsICookie);
+ var cookiesFromHost = params.GetInt(nsICookieAcceptDialog.COOKIESFROMHOST);
+
+ var messageFormat;
+ if (params.GetInt(nsICookieAcceptDialog.CHANGINGCOOKIE))
+ messageFormat = 'permissionToModifyCookie';
+ else if (cookiesFromHost > 1)
+ messageFormat = 'permissionToSetAnotherCookie';
+ else if (cookiesFromHost == 1)
+ messageFormat = 'permissionToSetSecondCookie';
+ else
+ messageFormat = 'permissionToSetACookie';
+
+ var hostname = params.GetString(nsICookieAcceptDialog.HOSTNAME);
+
+ var messageText;
+ if (cookie)
+ messageText = cookieBundle.getFormattedString(messageFormat, [hostname, cookiesFromHost]);
+ else
+ // No cookies means something went wrong. Bring up the dialog anyway
+ // to not make the mess worse.
+ messageText = cookieBundle.getFormattedString(messageFormat, ["", cookiesFromHost]);
+
+ var messageParent = document.getElementById("dialogtextbox");
+ var messageParagraphs = messageText.split("\n");
+
+ // use value for the header, so it doesn't wrap.
+ var headerNode = document.getElementById("dialog-header");
+ headerNode.setAttribute("value", messageParagraphs[0]);
+
+ // use childnodes here, the text can wrap
+ for (var i = 1; i < messageParagraphs.length; i++) {
+ var descriptionNode = document.createElement("description");
+ text = document.createTextNode(messageParagraphs[i]);
+ descriptionNode.appendChild(text);
+ messageParent.appendChild(descriptionNode);
+ }
+
+ if (cookie) {
+ document.getElementById('ifl_name').setAttribute("value", cookie.name);
+ document.getElementById('ifl_value').setAttribute("value", cookie.value);
+ document.getElementById('ifl_host').setAttribute("value", cookie.host);
+ document.getElementById('ifl_path').setAttribute("value", cookie.path);
+ document.getElementById('ifl_isSecure').setAttribute("value",
+ cookie.isSecure ?
+ cookieBundle.getString("forSecureOnly") : cookieBundle.getString("forAnyConnection")
+ );
+ document.getElementById('ifl_expires').setAttribute("value", GetExpiresString(cookie.expires));
+ document.getElementById('ifl_isDomain').setAttribute("value",
+ cookie.isDomain ?
+ cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")
+ );
+ }
+ // set default result to not accept the cookie
+ params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 0);
+ // and to not persist
+ params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, 0);
+ } catch (e) {
+ }
+ }
+
+ // The Private Browsing service might not be available
+ try {
+ if (window.opener && PrivateBrowsingUtils.isWindowPrivate(window.opener)) {
+ var persistCheckbox = document.getElementById("persistDomainAcceptance");
+ persistCheckbox.removeAttribute("checked");
+ persistCheckbox.setAttribute("disabled", "true");
+ }
+ } catch (ex) {}
+}
+
+function showhideinfo()
+{
+ var infobox=document.getElementById('infobox');
+
+ if (infobox.hidden) {
+ infobox.setAttribute("hidden", "false");
+ document.getElementById('disclosureButton').setAttribute("label", hideDetails);
+ } else {
+ infobox.setAttribute("hidden", "true");
+ document.getElementById('disclosureButton').setAttribute("label", showDetails);
+ }
+ sizeToContent();
+}
+
+function cookieAcceptNormal()
+{
+ // accept the cookie normally
+ params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.ACCEPT_COOKIE);
+ // And remember that when needed
+ params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
+ window.close();
+}
+
+function cookieAcceptSession()
+{
+ // accept for the session only
+ params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.ACCEPT_SESSION_COOKIE);
+ // And remember that when needed
+ params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
+ window.close();
+}
+
+function cookieDeny()
+{
+ // say that the cookie was rejected
+ params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.DENY_COOKIE);
+ // And remember that when needed
+ params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
+ window.close();
+}
+
+function GetExpiresString(secondsUntilExpires) {
+ if (secondsUntilExpires) {
+ var date = new Date(1000*secondsUntilExpires);
+
+ // if a server manages to set a really long-lived cookie, the dateservice
+ // can't cope with it properly, so we'll return a descriptive string instead.
+ var expiry = "";
+ try {
+ expiry = gDateService.FormatDateTime("", gDateService.dateFormatLong,
+ gDateService.timeFormatSeconds,
+ date.getFullYear(), date.getMonth()+1,
+ date.getDate(), date.getHours(),
+ date.getMinutes(), date.getSeconds());
+ } catch (ex) {
+ // Expiry duration was out of range for the date formatter, meaning a silly long time.
+ expiry = cookieBundle.getString("expireInAVeryLongTime");
+ }
+ return expiry;
+ }
+ return cookieBundle.getString("expireAtEndOfSession");
+}
diff --git a/components/cookie/content/cookieAcceptDialog.xul b/components/cookie/content/cookieAcceptDialog.xul
new file mode 100644
index 000000000..99fd92c0c
--- /dev/null
+++ b/components/cookie/content/cookieAcceptDialog.xul
@@ -0,0 +1,118 @@
+<?xml version="1.0"?>
+
+<!-- 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://global/skin/" type="text/css"?>
+
+<!DOCTYPE dialog SYSTEM "chrome://cookie/locale/cookieAcceptDialog.dtd">
+
+<!-- use a overlay te be able to put the accept/deny buttons not on the bottom -->
+<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
+
+<!-- use buttons="disclosure" to hide ok/cancel buttons. Those are added manually later -->
+<dialog id="cookieAcceptDialog"
+ acceptLabel="&button.allow.label;"
+ acceptKey="&button.allow.accesskey;"
+ extra1Label="&button.session.label;"
+ extra1Key="&button.session.accesskey;"
+ cancelLabel="&button.deny.label;"
+ cancelKey="&button.deny.accesskey;"
+ onload="onload();"
+ ondialogaccept="return doOKButton();"
+ title="&dialog.title;"
+ buttons="disclosure"
+ aria-describedby="dialog-header"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script src="cookieAcceptDialog.js" type="application/javascript"/>
+ <stringbundle id="cookieBundle"
+ src="chrome://cookie/locale/cookieAcceptDialog.properties"/>
+
+ <vbox>
+ <hbox>
+ <hbox align="start">
+ <image id="infoicon" class="spaced alert-icon"/>
+ </hbox>
+
+ <vbox flex="1">
+ <!-- text -->
+ <vbox id="dialogtextbox">
+ <description id="dialog-header" class="header"/>
+ </vbox>
+
+ <hbox id="checkboxContainer">
+ <checkbox id="persistDomainAcceptance"
+ label="&dialog.remember.label;"
+ accesskey="&dialog.remember.accesskey;"
+ persist="checked"/>
+ </hbox>
+ </vbox>
+
+ </hbox>
+
+ <hbox>
+ <button id="disclosureButton" dlgtype="disclosure" class="exit-dialog"
+ oncommand="showhideinfo();"/>
+ <spacer flex="1"/>
+ <hbox id="okCancelButtonsRight"/>
+ </hbox>
+
+ <vbox id="infobox" hidden="true" persist="hidden">
+ <separator class="groove"/>
+ <grid flex="1">
+ <columns>
+ <column/>
+ <column flex="1"/>
+ </columns>
+ <rows>
+
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label value="&props.name.label;" control="ifl_name"/>
+ </hbox>
+ <textbox id="ifl_name" readonly="true" class="plain"/>
+ </row>
+
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label value="&props.value.label;" control="ifl_value"/>
+ </hbox>
+ <textbox id="ifl_value" readonly="true" class="plain"/>
+ </row>
+
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label id="ifl_isDomain" value="&props.domain.label;" control="ifl_host"/>
+ </hbox>
+ <textbox id="ifl_host" readonly="true" class="plain"/>
+ </row>
+
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label value="&props.path.label;" control="ifl_path"/>
+ </hbox>
+ <textbox id="ifl_path" readonly="true" class="plain"/>
+ </row>
+
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label value="&props.secure.label;" control="ifl_isSecure"/>
+ </hbox>
+ <textbox id="ifl_isSecure" readonly="true" class="plain"/>
+ </row>
+
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label value="&props.expires.label;" control="ifl_expires"/>
+ </hbox>
+ <textbox id="ifl_expires" readonly="true" class="plain"/>
+ </row>
+
+ </rows>
+ </grid>
+ </vbox>
+ </vbox>
+</dialog>
+
diff --git a/components/cookie/jar.mn b/components/cookie/jar.mn
new file mode 100644
index 000000000..2826bbcd6
--- /dev/null
+++ b/components/cookie/jar.mn
@@ -0,0 +1,8 @@
+# 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/.
+
+toolkit.jar:
+% content cookie %content/cookie/
+ content/cookie/cookieAcceptDialog.xul (content/cookieAcceptDialog.xul)
+ content/cookie/cookieAcceptDialog.js (content/cookieAcceptDialog.js)
diff --git a/components/cookie/locale/cookieAcceptDialog.dtd b/components/cookie/locale/cookieAcceptDialog.dtd
new file mode 100644
index 000000000..52664f1de
--- /dev/null
+++ b/components/cookie/locale/cookieAcceptDialog.dtd
@@ -0,0 +1,21 @@
+<!-- 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/. -->
+
+<!ENTITY props.name.label "Name:">
+<!ENTITY props.value.label "Content:">
+<!ENTITY props.domain.label "Host:">
+<!ENTITY props.path.label "Path:">
+<!ENTITY props.secure.label "Send For:">
+<!ENTITY props.expires.label "Expires:">
+
+<!ENTITY button.allow.label "Allow">
+<!ENTITY button.allow.accesskey "A">
+<!ENTITY button.session.label "Allow for Session">
+<!ENTITY button.session.accesskey "S">
+<!ENTITY button.deny.label "Deny">
+<!ENTITY button.deny.accesskey "D">
+
+<!ENTITY dialog.title "Confirm setting cookie">
+<!ENTITY dialog.remember.label "Use my choice for all cookies from this site">
+<!ENTITY dialog.remember.accesskey "U">
diff --git a/components/cookie/locale/cookieAcceptDialog.properties b/components/cookie/locale/cookieAcceptDialog.properties
new file mode 100644
index 000000000..698c6f010
--- /dev/null
+++ b/components/cookie/locale/cookieAcceptDialog.properties
@@ -0,0 +1,21 @@
+# 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/.
+
+hostColon=Host:
+domainColon=Domain:
+forSecureOnly=Encrypted connections only
+forAnyConnection=Any type of connection
+expireAtEndOfSession=At end of session
+# LOCALIZATION NOTE (expireInAVeryLongTime) This string is used if a cookie won't expire for a literal life age and then some.
+expireInAVeryLongTime=Not in your lifetime
+
+showDetails=Show Details
+hideDetails=Hide Details
+detailsAccessKey=T
+
+permissionToSetACookie = The site %S wants to set a cookie.
+permissionToSetSecondCookie = The site %S wants to set a second cookie.
+# LOCALIZATION NOTE (PermissionToSetAnotherCookie): First %S: sitename, second %S: number of cookies already present for that site
+permissionToSetAnotherCookie = The site %S wants to set another cookie.\nYou already have %S cookies from this site.
+permissionToModifyCookie = The site %S wants to modify an existing cookie.
diff --git a/components/cookie/moz.build b/components/cookie/moz.build
new file mode 100644
index 000000000..aee4b90a5
--- /dev/null
+++ b/components/cookie/moz.build
@@ -0,0 +1,6 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# 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/.
+
+JAR_MANIFESTS += ['jar.mn']