diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index ce9d05ec7bfb..d76962c45499 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -486,7 +486,7 @@ @BINPATH@/components/FormHistoryStartup.js @BINPATH@/components/nsInputListAutoComplete.js @BINPATH@/components/formautofill.manifest -@BINPATH@/components/AutofillController.js +@BINPATH@/components/FormAutofillContentService.js @BINPATH@/components/contentSecurityPolicy.manifest @BINPATH@/components/contentSecurityPolicy.js @BINPATH@/components/contentAreaDropListener.manifest diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index 913d27bf1696..f4a7891bf4ef 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -455,7 +455,7 @@ @BINPATH@/components/FormHistoryStartup.js @BINPATH@/components/nsInputListAutoComplete.js @BINPATH@/components/formautofill.manifest -@BINPATH@/components/AutofillController.js +@BINPATH@/components/FormAutofillContentService.js @BINPATH@/components/contentSecurityPolicy.manifest @BINPATH@/components/contentSecurityPolicy.js @BINPATH@/components/contentAreaDropListener.manifest diff --git a/content/html/content/src/HTMLFormElement.cpp b/content/html/content/src/HTMLFormElement.cpp index 127d0d7dfad2..04264236e05e 100644 --- a/content/html/content/src/HTMLFormElement.cpp +++ b/content/html/content/src/HTMLFormElement.cpp @@ -29,7 +29,7 @@ #include "nsAutoPtr.h" #include "nsTArray.h" #include "nsIMutableArray.h" -#include "nsIAutofillController.h" +#include "nsIFormAutofillContentService.h" // form submission #include "nsIFormSubmitObserver.h" @@ -306,10 +306,12 @@ void HTMLFormElement::RequestAutocomplete() { bool dummy; - nsCOMPtr win = do_QueryInterface(OwnerDoc()->GetScriptHandlingObject(dummy)); - nsCOMPtr controller(do_GetService("@mozilla.org/autofill-controller;1")); + nsCOMPtr window = + do_QueryInterface(OwnerDoc()->GetScriptHandlingObject(dummy)); + nsCOMPtr formAutofillContentService = + do_GetService("@mozilla.org/formautofill/content-service;1"); - if (!controller || !win) { + if (!formAutofillContentService || !window) { AutocompleteErrorEventInit init; init.mBubbles = true; init.mCancelable = false; @@ -317,11 +319,12 @@ HTMLFormElement::RequestAutocomplete() nsRefPtr event = AutocompleteErrorEvent::Constructor(this, NS_LITERAL_STRING("autocompleteerror"), init); + (new AsyncEventDispatcher(this, event))->PostDOMEvent(); return; } - controller->RequestAutocomplete(this, win); + formAutofillContentService->RequestAutocomplete(this, window); } bool diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in index 520a0021d1be..36c22ff40018 100644 --- a/mobile/android/installer/package-manifest.in +++ b/mobile/android/installer/package-manifest.in @@ -379,7 +379,7 @@ @BINPATH@/components/FormHistoryStartup.js @BINPATH@/components/nsInputListAutoComplete.js @BINPATH@/components/formautofill.manifest -@BINPATH@/components/AutofillController.js +@BINPATH@/components/FormAutofillContentService.js @BINPATH@/components/contentSecurityPolicy.manifest @BINPATH@/components/contentSecurityPolicy.js @BINPATH@/components/contentAreaDropListener.manifest diff --git a/toolkit/components/formautofill/AutofillController.js b/toolkit/components/formautofill/AutofillController.js deleted file mode 100644 index 36f1d7604f93..000000000000 --- a/toolkit/components/formautofill/AutofillController.js +++ /dev/null @@ -1,32 +0,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/. */ -"use strict"; - -const { classes: Cc, interfaces: Ci, utils: Cu } = Components; - -Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); - -function AutofillController() {} - -AutofillController.prototype = { - _dispatchAsync: function (fn) { - Services.tm.currentThread.dispatch(fn, Ci.nsIThread.DISPATCH_NORMAL); - }, - - _dispatchDisabled: function (form, win, message) { - Services.console.logStringMessage("requestAutocomplete disabled: " + message); - let evt = new win.AutocompleteErrorEvent("autocompleteerror", { bubbles: true, reason: "disabled" }); - form.dispatchEvent(evt); - }, - - requestAutocomplete: function (form, win) { - this._dispatchAsync(() => this._dispatchDisabled(form, win, "not implemented")); - }, - - classID: Components.ID("{ed9c2c3c-3f86-4ae5-8e31-10f71b0f19e6}"), - QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutofillController]) -}; - -this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AutofillController]); diff --git a/toolkit/components/formautofill/FormAutofillContentService.js b/toolkit/components/formautofill/FormAutofillContentService.js new file mode 100644 index 000000000000..99f16c247e09 --- /dev/null +++ b/toolkit/components/formautofill/FormAutofillContentService.js @@ -0,0 +1,41 @@ +/* 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/. */ + +/* + * Implements a service used by DOM content to request Form Autofill, in + * particular when the requestAutocomplete method of Form objects is invoked. + * + * See the nsIFormAutofillContentService documentation for details. + */ + +"use strict"; + +const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; + +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +function FormAutofillContentService() { +} + +FormAutofillContentService.prototype = { + classID: Components.ID("{ed9c2c3c-3f86-4ae5-8e31-10f71b0f19e6}"), + QueryInterface: XPCOMUtils.generateQI([Ci.nsIFormAutofillContentService]), + + // nsIFormAutofillContentService + requestAutocomplete: function (aForm, aWindow) { + Services.console.logStringMessage("requestAutocomplete not implemented."); + + // We will return "disabled" for now. + let event = new aWindow.AutocompleteErrorEvent("autocompleteerror", + { bubbles: true, + reason: "disabled" }); + + // Ensure the event is always dispatched on the next tick. + Services.tm.currentThread.dispatch(() => aForm.dispatchEvent(event), + Ci.nsIThread.DISPATCH_NORMAL); + }, +}; + +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FormAutofillContentService]); diff --git a/toolkit/components/formautofill/formautofill.manifest b/toolkit/components/formautofill/formautofill.manifest index 097770137635..15c3c20fa45b 100644 --- a/toolkit/components/formautofill/formautofill.manifest +++ b/toolkit/components/formautofill/formautofill.manifest @@ -1,2 +1,2 @@ -component {ed9c2c3c-3f86-4ae5-8e31-10f71b0f19e6} AutofillController.js -contract @mozilla.org/autofill-controller;1 {ed9c2c3c-3f86-4ae5-8e31-10f71b0f19e6} +component {ed9c2c3c-3f86-4ae5-8e31-10f71b0f19e6} FormAutofillContentService.js +contract @mozilla.org/formautofill/content-service;1 {ed9c2c3c-3f86-4ae5-8e31-10f71b0f19e6} diff --git a/toolkit/components/formautofill/moz.build b/toolkit/components/formautofill/moz.build index 3b57381d3b06..e781588eaff3 100644 --- a/toolkit/components/formautofill/moz.build +++ b/toolkit/components/formautofill/moz.build @@ -18,12 +18,12 @@ XPCSHELL_TESTS_MANIFESTS += [ ] XPIDL_SOURCES += [ - 'nsIAutofillController.idl', + 'nsIFormAutofillContentService.idl', ] XPIDL_MODULE = 'toolkit_formautofill' EXTRA_COMPONENTS += [ - 'AutofillController.js', 'formautofill.manifest', + 'FormAutofillContentService.js', ] diff --git a/toolkit/components/formautofill/nsIAutofillController.idl b/toolkit/components/formautofill/nsIAutofillController.idl deleted file mode 100644 index 2939021e3140..000000000000 --- a/toolkit/components/formautofill/nsIAutofillController.idl +++ /dev/null @@ -1,14 +0,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/. */ - -#include "nsISupports.idl" - -interface nsIDOMHTMLFormElement; -interface nsIDOMWindow; - -[scriptable, uuid(cbf47f9d-a13d-4fad-8221-8964086b1b8a)] -interface nsIAutofillController : nsISupports -{ - void requestAutocomplete(in nsIDOMHTMLFormElement form, in nsIDOMWindow window); -}; diff --git a/toolkit/components/formautofill/nsIFormAutofillContentService.idl b/toolkit/components/formautofill/nsIFormAutofillContentService.idl new file mode 100644 index 000000000000..300645e7419c --- /dev/null +++ b/toolkit/components/formautofill/nsIFormAutofillContentService.idl @@ -0,0 +1,46 @@ +/* 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/. */ + +#include "nsISupports.idl" + +interface nsIDOMHTMLFormElement; +interface nsIDOMWindow; + +/** + * Defines a service used by DOM content to request Form Autofill, in particular + * when the requestAutocomplete method of Form objects is invoked. + * + * This service lives in the process that hosts the requesting DOM content. + * This means that, in a multi-process (e10s) environment, there can be an + * instance of the service for each content process, in addition to an instance + * for the chrome process. + * + * @remarks The service implementation uses a child-side message manager to + * communicate with a parent-side message manager living in the chrome + * process, where most of the processing is located. + */ +[scriptable, uuid(1db29340-99df-4845-9102-0c5d281b2fe8)] +interface nsIFormAutofillContentService : nsISupports +{ + /** + * Invoked by the requestAutocomplete method of the DOM Form object. + * + * The application is expected to display a user interface asking for the + * details that are relevant to the form being filled in. The application + * should use the "autocomplete" attributes on the input elements as hints + * about which type of information is being requested. + * + * The processing will result in either an "autocomplete" simple DOM Event or + * an AutocompleteErrorEvent being fired on the form. + * + * @param aForm + * The form on which the requestAutocomplete method was invoked. + * @param aWindow + * The window where the form is located. This must be specified even + * for elements that are not in a document, and is used to generate the + * DOM events resulting from the operation. + */ + void requestAutocomplete(in nsIDOMHTMLFormElement aForm, + in nsIDOMWindow aWindow); +}; diff --git a/toolkit/components/formautofill/test/chrome/chrome.ini b/toolkit/components/formautofill/test/chrome/chrome.ini index 0b1b5c8f996c..e183cccde80e 100644 --- a/toolkit/components/formautofill/test/chrome/chrome.ini +++ b/toolkit/components/formautofill/test/chrome/chrome.ini @@ -4,3 +4,4 @@ support-files = head.js [test_infrastructure.html] +[test_requestAutocomplete_disabled.html] diff --git a/toolkit/components/formautofill/test/chrome/test_requestAutocomplete_disabled.html b/toolkit/components/formautofill/test/chrome/test_requestAutocomplete_disabled.html new file mode 100644 index 000000000000..bb57b59ab4d1 --- /dev/null +++ b/toolkit/components/formautofill/test/chrome/test_requestAutocomplete_disabled.html @@ -0,0 +1,31 @@ + + + +
+
+ + + +