Bug 1023484 - Improvements and test for the initial requestAutocomplete stub. r=MattN

--HG--
rename : toolkit/components/formautofill/AutofillController.js => toolkit/components/formautofill/FormAutofillContentService.js
rename : toolkit/components/formautofill/nsIAutofillController.idl => toolkit/components/formautofill/nsIFormAutofillContentService.idl
This commit is contained in:
Paolo Amadini 2014-06-24 12:15:02 +01:00
Родитель 80952d18ee
Коммит 9fde0e4ab8
12 изменённых файлов: 134 добавлений и 58 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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<nsIDOMWindow> win = do_QueryInterface(OwnerDoc()->GetScriptHandlingObject(dummy));
nsCOMPtr<nsIAutofillController> controller(do_GetService("@mozilla.org/autofill-controller;1"));
nsCOMPtr<nsIDOMWindow> window =
do_QueryInterface(OwnerDoc()->GetScriptHandlingObject(dummy));
nsCOMPtr<nsIFormAutofillContentService> 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<AutocompleteErrorEvent> event =
AutocompleteErrorEvent::Constructor(this, NS_LITERAL_STRING("autocompleteerror"), init);
(new AsyncEventDispatcher(this, event))->PostDOMEvent();
return;
}
controller->RequestAutocomplete(this, win);
formAutofillContentService->RequestAutocomplete(this, window);
}
bool

Просмотреть файл

@ -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

Просмотреть файл

@ -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]);

Просмотреть файл

@ -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]);

Просмотреть файл

@ -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}

Просмотреть файл

@ -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',
]

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -4,3 +4,4 @@ support-files =
head.js
[test_infrastructure.html]
[test_requestAutocomplete_disabled.html]

Просмотреть файл

@ -0,0 +1,31 @@
<!DOCTYPE HTML><html><head><meta charset="utf-8"></head><body>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<form id="form">
</form>
<script type="application/javascript;version=1.7" src="head.js"></script>
<script type="application/javascript;version=1.7">
/*
* Tests the cases where the requestAutocomplete method returns "disabled".
*/
"use strict";
/**
* Tests the case where the feature is disabled globally.
*/
add_task(function* test_disabled_globally() {
let promise = TestUtils.waitForEvent($("form"), "autocompleteerror");
$("form").requestAutocomplete();
let errorEvent = yield promise;
Assert.equal(errorEvent.reason, "disabled");
});
add_task(terminationTaskFn);
</script>
</body></html>