Bug 1020440 - Create DOM interfaces and stub for requestAutocomplete. r=smaug,MattN
authorBrian Nicholson <bnicholson@mozilla.com>
Fri, 06 Jun 2014 13:06:15 -0700
changeset 206550 568758b30cb2027cc61ea17c8f7e9da35583e298
parent 206549 123b94215b3ef74457aeafd820698f03ad2dacf5
child 206551 3761ada3b5d2c1607dae166592a3d22347e4f19c
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, MattN
bugs1020440
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1020440 - Create DOM interfaces and stub for requestAutocomplete. r=smaug,MattN
b2g/installer/package-manifest.in
browser/installer/package-manifest.in
content/html/content/src/HTMLFormElement.cpp
content/html/content/src/HTMLFormElement.h
dom/webidl/AutocompleteErrorEvent.webidl
dom/webidl/HTMLFormElement.webidl
dom/webidl/moz.build
mobile/android/installer/package-manifest.in
modules/libpref/src/init/all.js
toolkit/components/formautofill/AutofillController.js
toolkit/components/formautofill/formautofill.manifest
toolkit/components/formautofill/moz.build
toolkit/components/formautofill/nsIAutofillController.idl
toolkit/components/moz.build
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -481,16 +481,18 @@
 @BINPATH@/components/nsHandlerService.js
 @BINPATH@/components/nsWebHandlerApp.manifest
 @BINPATH@/components/nsWebHandlerApp.js
 @BINPATH@/components/satchel.manifest
 @BINPATH@/components/nsFormAutoComplete.js
 @BINPATH@/components/nsFormHistory.js
 @BINPATH@/components/FormHistoryStartup.js
 @BINPATH@/components/nsInputListAutoComplete.js
+@BINPATH@/components/formautofill.manifest
+@BINPATH@/components/AutofillController.js
 @BINPATH@/components/contentSecurityPolicy.manifest
 @BINPATH@/components/contentSecurityPolicy.js
 @BINPATH@/components/contentAreaDropListener.manifest
 @BINPATH@/components/contentAreaDropListener.js
 @BINPATH@/components/messageWakeupService.js
 @BINPATH@/components/messageWakeupService.manifest
 @BINPATH@/components/SettingsManager.js
 @BINPATH@/components/SettingsManager.manifest
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -449,16 +449,18 @@
 @BINPATH@/components/nsHandlerService.js
 @BINPATH@/components/nsWebHandlerApp.manifest
 @BINPATH@/components/nsWebHandlerApp.js
 @BINPATH@/components/satchel.manifest
 @BINPATH@/components/nsFormAutoComplete.js
 @BINPATH@/components/nsFormHistory.js
 @BINPATH@/components/FormHistoryStartup.js
 @BINPATH@/components/nsInputListAutoComplete.js
+@BINPATH@/components/formautofill.manifest
+@BINPATH@/components/AutofillController.js
 @BINPATH@/components/contentSecurityPolicy.manifest
 @BINPATH@/components/contentSecurityPolicy.js
 @BINPATH@/components/contentAreaDropListener.manifest
 @BINPATH@/components/contentAreaDropListener.js
 @BINPATH@/browser/components/BrowserProfileMigrators.manifest
 @BINPATH@/browser/components/ProfileMigrator.js
 @BINPATH@/browser/components/ChromeProfileMigrator.js
 @BINPATH@/browser/components/FirefoxProfileMigrator.js
--- a/content/html/content/src/HTMLFormElement.cpp
+++ b/content/html/content/src/HTMLFormElement.cpp
@@ -5,16 +5,17 @@
 
 #include "mozilla/dom/HTMLFormElement.h"
 
 #include "jsapi.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
+#include "mozilla/dom/AutocompleteErrorEvent.h"
 #include "mozilla/dom/HTMLFormControlsCollection.h"
 #include "mozilla/dom/HTMLFormElementBinding.h"
 #include "mozilla/Move.h"
 #include "nsIHTMLDocument.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsIDocument.h"
@@ -23,16 +24,17 @@
 #include "nsError.h"
 #include "nsContentUtils.h"
 #include "nsInterfaceHashtable.h"
 #include "nsContentList.h"
 #include "nsCOMArray.h"
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "nsIMutableArray.h"
+#include "nsIAutofillController.h"
 
 // form submission
 #include "nsIFormSubmitObserver.h"
 #include "nsIObserverService.h"
 #include "nsICategoryManager.h"
 #include "nsCategoryManagerUtils.h"
 #include "nsISimpleEnumerator.h"
 #include "nsRange.h"
@@ -295,16 +297,38 @@ HTMLFormElement::Reset()
 
 NS_IMETHODIMP
 HTMLFormElement::CheckValidity(bool* retVal)
 {
   *retVal = CheckValidity();
   return NS_OK;
 }
 
+void
+HTMLFormElement::RequestAutocomplete()
+{
+  bool dummy;
+  nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(OwnerDoc()->GetScriptHandlingObject(dummy));
+  nsCOMPtr<nsIAutofillController> controller(do_GetService("@mozilla.org/autofill-controller;1"));
+
+  if (!controller || !win) {
+    AutocompleteErrorEventInit init;
+    init.mBubbles = true;
+    init.mCancelable = false;
+    init.mReason = AutoCompleteErrorReason::Disabled;
+
+    nsRefPtr<AutocompleteErrorEvent> event =
+      AutocompleteErrorEvent::Constructor(this, NS_LITERAL_STRING("autocompleteerror"), init);
+    (new AsyncEventDispatcher(this, event))->PostDOMEvent();
+    return;
+  }
+
+  controller->RequestAutocomplete(this, win);
+}
+
 bool
 HTMLFormElement::ParseAttribute(int32_t aNamespaceID,
                                 nsIAtom* aAttribute,
                                 const nsAString& aValue,
                                 nsAttrValue& aResult)
 {
   if (aNamespaceID == kNameSpaceID_None) {
     if (aAttribute == nsGkAtoms::method) {
--- a/content/html/content/src/HTMLFormElement.h
+++ b/content/html/content/src/HTMLFormElement.h
@@ -405,16 +405,18 @@ public:
 #ifdef DEBUG
   static void
   AssertDocumentOrder(const nsTArray<nsGenericHTMLFormElement*>& aControls,
                       nsIContent* aForm);
 #endif
 
   js::ExpandoAndGeneration mExpandoAndGeneration;
 
+  void RequestAutocomplete();
+
 protected:
   virtual JSObject* WrapNode(JSContext* aCx) MOZ_OVERRIDE;
 
   void PostPasswordEvent();
   void EventHandled() { mFormPasswordEventDispatcher = nullptr; }
 
   class FormPasswordEventDispatcher MOZ_FINAL : public AsyncEventDispatcher
   {
new file mode 100644
--- /dev/null
+++ b/dom/webidl/AutocompleteErrorEvent.webidl
@@ -0,0 +1,23 @@
+/* -*- Mode: IDL; 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/. */
+
+enum AutoCompleteErrorReason {
+  "",
+  "cancel",
+  "disabled",
+  "invalid"
+};
+
+[Pref="dom.forms.requestAutocomplete",
+ Constructor(DOMString type, optional AutocompleteErrorEventInit eventInitDict)]
+interface AutocompleteErrorEvent : Event
+{
+  readonly attribute AutoCompleteErrorReason reason;
+};
+
+dictionary AutocompleteErrorEventInit : EventInit
+{
+  AutoCompleteErrorReason reason = "";
+};
--- a/dom/webidl/HTMLFormElement.webidl
+++ b/dom/webidl/HTMLFormElement.webidl
@@ -40,9 +40,12 @@ interface HTMLFormElement : HTMLElement 
   getter Element (unsigned long index);
   // TODO this should be: getter (RadioNodeList or HTMLInputElement or HTMLImageElement) (DOMString name);
   getter nsISupports (DOMString name);
 
   [Throws]
   void submit();
   void reset();
   boolean checkValidity();
+
+  [Pref="dom.forms.requestAutocomplete"]
+  void requestAutocomplete();
 };
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -618,16 +618,17 @@ if CONFIG['MOZ_B2G_FM']:
     ]
 
 if not CONFIG['MOZ_DISABLE_CRYPTOLEGACY']:
     WEBIDL_FILES += [
         'CRMFObject.webidl',
     ]
 
 GENERATED_EVENTS_WEBIDL_FILES = [
+    'AutocompleteErrorEvent.webidl',
     'BlobEvent.webidl',
     'CallGroupErrorEvent.webidl',
     'CFStateChangeEvent.webidl',
     'DataErrorEvent.webidl',
     'DataStoreChangeEvent.webidl',
     'DeviceLightEvent.webidl',
     'DeviceProximityEvent.webidl',
     'DownloadEvent.webidl',
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -374,16 +374,18 @@
 @BINPATH@/components/nsHandlerService.js
 @BINPATH@/components/nsWebHandlerApp.manifest
 @BINPATH@/components/nsWebHandlerApp.js
 @BINPATH@/components/satchel.manifest
 @BINPATH@/components/nsFormAutoComplete.js
 @BINPATH@/components/nsFormHistory.js
 @BINPATH@/components/FormHistoryStartup.js
 @BINPATH@/components/nsInputListAutoComplete.js
+@BINPATH@/components/formautofill.manifest
+@BINPATH@/components/AutofillController.js
 @BINPATH@/components/contentSecurityPolicy.manifest
 @BINPATH@/components/contentSecurityPolicy.js
 @BINPATH@/components/contentAreaDropListener.manifest
 @BINPATH@/components/contentAreaDropListener.js
 @BINPATH@/components/messageWakeupService.js
 @BINPATH@/components/messageWakeupService.manifest
 #ifdef MOZ_ENABLE_DBUS
 @BINPATH@/components/@DLL_PREFIX@dbusservice@DLL_SUFFIX@
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -767,16 +767,19 @@ pref("dom.forms.number", true);
 
 // Enable <input type=color> by default. It will be turned off for remaining
 // platforms which don't have a color picker implemented yet.
 pref("dom.forms.color", true);
 
 // Support for new @autocomplete values
 pref("dom.forms.autocomplete.experimental", false);
 
+// Enables requestAutocomplete DOM API on forms.
+pref("dom.forms.requestAutocomplete", false);
+
 // Enables system messages and activities
 pref("dom.sysmsg.enabled", false);
 
 // Enable pre-installed applications.
 pref("dom.webapps.useCurrentProfile", false);
 
 pref("dom.cycle_collector.incremental", true);
 
new file mode 100644
--- /dev/null
+++ b/toolkit/components/formautofill/AutofillController.js
@@ -0,0 +1,32 @@
+/* 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]);
new file mode 100644
--- /dev/null
+++ b/toolkit/components/formautofill/formautofill.manifest
@@ -0,0 +1,2 @@
+component {ed9c2c3c-3f86-4ae5-8e31-10f71b0f19e6} AutofillController.js
+contract @mozilla.org/autofill-controller;1 {ed9c2c3c-3f86-4ae5-8e31-10f71b0f19e6}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/formautofill/moz.build
@@ -0,0 +1,16 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+XPIDL_SOURCES += [
+    'nsIAutofillController.idl',
+]
+
+XPIDL_MODULE = 'toolkit_formautofill'
+
+EXTRA_COMPONENTS += [
+    'AutofillController.js',
+    'formautofill.manifest',
+]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/formautofill/nsIAutofillController.idl
@@ -0,0 +1,14 @@
+/* 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);
+};
--- a/toolkit/components/moz.build
+++ b/toolkit/components/moz.build
@@ -18,16 +18,17 @@ PARALLEL_DIRS += [
     'contentprefs',
     'cookie',
     'crashmonitor',
     'diskspacewatcher',
     'downloads',
     'exthelper',
     'filepicker',
     'finalizationwitness',
+    'formautofill',
     'find',
     'jsdownloads',
     'mediasniffer',
     'microformats',
     'osfile',
     'parentalcontrols',
     'passwordmgr',
     'perf',