Bug 1300992 - Part 1: Communication between processes, r=MattN

MozReview-Commit-ID: IfeRsX9ErBj

--HG--
extra : rebase_source : 665eea3a69fccbefb6abcefeb3bc22119381e133
This commit is contained in:
steveck-chung 2016-12-30 17:00:27 +08:00
parent 79f756b89f
commit 8e2984c403
5 changed files with 111 additions and 15 deletions

View File

@ -4,8 +4,11 @@ module.exports = { // eslint-disable-line no-undef
"extends": "../../.eslintrc.js",
"globals": {
"addMessageListener": false,
"Components": true,
"dump": true,
"removeMessageListener": false,
"sendAsyncMessage": false,
"TextDecoder": false,
"TextEncoder": false,
},

View File

@ -56,6 +56,7 @@ let FormAutofillParent = {
let mm = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
mm.addMessageListener("FormAutofill:PopulateFieldValues", this);
mm.addMessageListener("FormAutofill:GetProfiles", this);
},
/**
@ -70,6 +71,9 @@ let FormAutofillParent = {
case "FormAutofill:PopulateFieldValues":
this._populateFieldValues(data, target);
break;
case "FormAutofill:GetProfiles":
this._getProfiles(data, target);
break;
}
},
@ -98,6 +102,7 @@ let FormAutofillParent = {
let mm = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
mm.removeMessageListener("FormAutofill:PopulateFieldValues", this);
mm.removeMessageListener("FormAutofill:GetProfiles", this);
},
/**
@ -118,6 +123,35 @@ let FormAutofillParent = {
target.sendAsyncMessage("FormAutofill:fillForm", {fields});
},
/**
* Get the profile data from profile store and return profiles back to content process.
*
* @private
* @param {string} data.searchString
* The typed string for filtering out the matched profile.
* @param {string} data.info
* The input autocomplete property's information.
* @param {nsIFrameMessageManager} target
* Content's message manager.
*/
_getProfiles({searchString, info}, target) {
// TODO: These mock data should be replaced by form autofill API
// let profiles = this._profileStore.getAll();
let profiles = [{
guid: "test-guid-1",
organization: "Sesame Street",
streetAddress: "123 Sesame Street.",
tel: "1-345-345-3456",
}, {
guid: "test-guid-2",
organization: "Mozilla",
streetAddress: "331 E. Evelyn Avenue",
tel: "1-650-903-0800",
}];
target.messageManager.sendAsyncMessage("FormAutofill:Profiles", profiles);
},
/**
* Transforms a word with hyphen into camel case.
* (e.g. transforms "address-type" into "addressType".)

View File

@ -2,6 +2,8 @@
* 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/. */
/* global content */
/*
* Form Autofill frame script.
*/
@ -227,28 +229,69 @@ AutofillProfileAutoCompleteSearch.prototype = {
* @param {Object} listener the listener to notify when the search is complete
*/
startSearch(searchString, searchParam, previousResult, listener) {
// TODO: These mock data should be replaced by form autofill API
let fieldName = "name";
let profiles = [{
guid: "test-guid-1",
organization: "Sesame Street",
streetAddress: "123 Sesame Street.",
tel: "1-345-345-3456.",
}, {
guid: "test-guid-2",
organization: "Mozilla",
streetAddress: "331 E. Evelyn Avenue",
tel: "1-650-903-0800",
}];
let result = new ProfileAutoCompleteResult(searchString, fieldName, profiles, {});
this.forceStop = false;
let inputInfo;
listener.onSearchResult(this, result);
this.getInputInfo().then((info) => {
inputInfo = info;
return this.getProfiles({info, searchString});
}).then((profiles) => {
if (this.forceStop) {
return;
}
let result = new ProfileAutoCompleteResult(searchString, inputInfo, profiles, {});
listener.onSearchResult(this, result);
});
},
/**
* Stops an asynchronous search that is in progress
*/
stopSearch() {
this.forceStop = true;
},
/**
* Get the profile data from parent process for AutoComplete result.
*
* @private
* @param {Object} data
* Parameters for querying the corresponding result.
* @param {string} data.searchString
* The typed string for filtering out the matched profile.
* @param {string} data.info
* The input autocomplete property's information.
* @returns {Promise}
* Promise that resolves when profiles returned from parent process.
*/
getProfiles(data) {
return new Promise((resolve) => {
addMessageListener("FormAutofill:Profiles", function getResult(result) {
removeMessageListener("FormAutofill:Profiles", getResult);
resolve(result.data);
});
sendAsyncMessage("FormAutofill:GetProfiles", data);
});
},
/**
* Get the input's information from FormAutofill heuristics.
*
* @returns {Promise}
* Promise that resolves when profiles returned from heuristics getInfo API.
*/
getInputInfo() {
let input = formFillController.getFocusedInput();
// It could be synchronous API since FormAutofillHeuristics.getInfo is still
// not in parent process yet.
return new Promise((resolve) => {
resolve(FormAutofillHeuristics.getInfo(input));
});
},
};
@ -337,4 +380,5 @@ var FormAutofillContent = {
},
};
FormAutofillContent.init();

View File

@ -316,6 +316,14 @@ nsFormFillController::MarkAsAutofillField(nsIDOMHTMLInputElement *aInput)
return NS_OK;
}
NS_IMETHODIMP
nsFormFillController::GetFocusedInput(nsIDOMHTMLInputElement** aRetVal) {
if (!aRetVal) {
return NS_ERROR_INVALID_POINTER;
}
*aRetVal = mFocusedInput;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
//// nsIAutoCompleteInput

View File

@ -51,4 +51,11 @@ interface nsIFormFillController : nsISupports
* @param aInput - The HTML <input> element to mark
*/
void markAsAutofillField(in nsIDOMHTMLInputElement aInput);
/**
* Return the focused input which is cached in form fill controller.
*
* @returns The focused input.
*/
nsIDOMHTMLInputElement getFocusedInput();
};