summaryrefslogtreecommitdiffstats
path: root/toolkit/components/formautofill/content
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/components/formautofill/content
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/formautofill/content')
-rw-r--r--toolkit/components/formautofill/content/RequestAutocompleteUI.jsm58
-rw-r--r--toolkit/components/formautofill/content/requestAutocomplete.js85
-rw-r--r--toolkit/components/formautofill/content/requestAutocomplete.xhtml31
3 files changed, 174 insertions, 0 deletions
diff --git a/toolkit/components/formautofill/content/RequestAutocompleteUI.jsm b/toolkit/components/formautofill/content/RequestAutocompleteUI.jsm
new file mode 100644
index 000000000..74c4834ba
--- /dev/null
+++ b/toolkit/components/formautofill/content/RequestAutocompleteUI.jsm
@@ -0,0 +1,58 @@
+/* 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/. */
+
+/*
+ * Handles the requestAutocomplete user interface.
+ */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = [
+ "RequestAutocompleteUI",
+];
+
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Promise",
+ "resource://gre/modules/Promise.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+ "resource://gre/modules/Task.jsm");
+
+/**
+ * Handles the requestAutocomplete user interface.
+ */
+this.RequestAutocompleteUI = function (aAutofillData) {
+ this._autofillData = aAutofillData;
+}
+
+this.RequestAutocompleteUI.prototype = {
+ _autofillData: null,
+
+ show: Task.async(function* () {
+ // Create a new promise and store the function that will resolve it. This
+ // will be called by the UI once the selection has been made.
+ let resolveFn;
+ let uiPromise = new Promise(resolve => resolveFn = resolve);
+
+ // Wrap the callback function so that it survives XPCOM.
+ let args = {
+ resolveFn: resolveFn,
+ autofillData: this._autofillData,
+ };
+ args.wrappedJSObject = args;
+
+ // Open the window providing the function to call when it closes.
+ Services.ww.openWindow(null,
+ "chrome://formautofill/content/requestAutocomplete.xhtml",
+ "Toolkit:RequestAutocomplete",
+ "chrome,dialog=no,resizable",
+ args);
+
+ // Wait for the window to be closed and the operation confirmed.
+ return yield uiPromise;
+ }),
+};
diff --git a/toolkit/components/formautofill/content/requestAutocomplete.js b/toolkit/components/formautofill/content/requestAutocomplete.js
new file mode 100644
index 000000000..47d500964
--- /dev/null
+++ b/toolkit/components/formautofill/content/requestAutocomplete.js
@@ -0,0 +1,85 @@
+/* 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/. */
+
+/*
+ * Implementation of "requestAutocomplete.xhtml".
+ */
+
+"use strict";
+
+var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Promise",
+ "resource://gre/modules/Promise.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+ "resource://gre/modules/Task.jsm");
+
+const RequestAutocompleteDialog = {
+ resolveFn: null,
+ autofillData: null,
+
+ onLoad: function () {
+ Task.spawn(function* () {
+ let args = window.arguments[0].wrappedJSObject;
+ this.resolveFn = args.resolveFn;
+ this.autofillData = args.autofillData;
+
+ window.sizeToContent();
+
+ Services.obs.notifyObservers(window,
+ "formautofill-window-initialized", "");
+ }.bind(this)).catch(Cu.reportError);
+ },
+
+ onAccept: function () {
+ // TODO: Replace with autofill storage module (bug 1018304).
+ const dummyDB = {
+ "": {
+ "name": "Mozzy La",
+ "street-address": "331 E Evelyn Ave",
+ "address-level2": "Mountain View",
+ "address-level1": "CA",
+ "country": "US",
+ "postal-code": "94041",
+ "email": "email@example.org",
+ }
+ };
+
+ let result = { fields: [] };
+ for (let section of this.autofillData.sections) {
+ for (let addressSection of section.addressSections) {
+ let addressType = addressSection.addressType;
+ if (!(addressType in dummyDB)) {
+ continue;
+ }
+
+ for (let field of addressSection.fields) {
+ let fieldName = field.fieldName;
+ if (!(fieldName in dummyDB[addressType])) {
+ continue;
+ }
+
+ result.fields.push({
+ section: section.name,
+ addressType: addressType,
+ contactType: field.contactType,
+ fieldName: field.fieldName,
+ value: dummyDB[addressType][fieldName],
+ });
+ }
+ }
+ }
+
+ window.close();
+ this.resolveFn(result);
+ },
+
+ onCancel: function () {
+ window.close();
+ this.resolveFn({ canceled: true });
+ },
+};
diff --git a/toolkit/components/formautofill/content/requestAutocomplete.xhtml b/toolkit/components/formautofill/content/requestAutocomplete.xhtml
new file mode 100644
index 000000000..269e55bd6
--- /dev/null
+++ b/toolkit/components/formautofill/content/requestAutocomplete.xhtml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-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/. -->
+
+<!DOCTYPE html [
+ <!ENTITY % htmlDTD PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
+ %htmlDTD;
+ <!ENTITY % requestAutocompleteDTD SYSTEM "chrome://formautofill/locale/requestAutocomplete.dtd">
+ %requestAutocompleteDTD;
+ <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd" >
+ %globalDTD;
+]>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>requestAutocomplete demo window</title>
+ <link rel="stylesheet"
+ href="chrome://mozapps/skin/formautofill/requestAutocomplete.css" />
+ <script type="application/javascript;version=1.7"
+ src="chrome://formautofill/content/requestAutocomplete.js" />
+ </head>
+ <body dir="&locale.dir;" onload="RequestAutocompleteDialog.onLoad();">
+ <h1>requestAutocomplete</h1>
+ <p>This is a demo window.</p>
+ <input id="accept" type="button" value="(OK)"
+ onclick="RequestAutocompleteDialog.onAccept();" />
+ <input id="cancel" type="button" value="(Cancel)"
+ onclick="RequestAutocompleteDialog.onCancel();" />
+ </body>
+</html>