Commit 44f8883c authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

rule-based: Add new API for the extension to reset the engine state.

Right now, the extension may need to reset the state of an engine w/o
deactivating it. For example, if the user starts voice input, we need
to reset the engine state (voice input is not an engine; if it was an
engine, everything will work because we would deactivate the current
engine before starting voice input).

So far, this has been fine because the extension contained both UI
and IME code. But when we move to a native model, UI will no longer
contain IME code, so it will need to signal to IMF to reset the state
of the engine.

We add a new private API for resetting the engine.

Bug: 1009903
Change-Id: I7e0b9a18a308d5e9834a4a341d71192b37745b98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1971047Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726156}
parent d8fa0cc3
...@@ -463,6 +463,17 @@ InputMethodPrivateSetSelectionRangeFunction::Run() { ...@@ -463,6 +463,17 @@ InputMethodPrivateSetSelectionRangeFunction::Run() {
return RespondNow(OneArgument(std::make_unique<base::Value>(true))); return RespondNow(OneArgument(std::make_unique<base::Value>(true)));
} }
ExtensionFunction::ResponseAction InputMethodPrivateResetFunction::Run() {
std::string error;
InputMethodEngineBase* engine =
GetEngineIfActive(browser_context(), extension_id(), &error);
if (!engine)
return RespondNow(Error(InformativeError(error, function_name())));
engine->Reset();
return RespondNow(NoArguments());
}
InputMethodAPI::InputMethodAPI(content::BrowserContext* context) InputMethodAPI::InputMethodAPI(content::BrowserContext* context)
: context_(context) { : context_(context) {
EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName); EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName);
......
...@@ -264,6 +264,25 @@ class InputMethodPrivateSetSelectionRangeFunction : public ExtensionFunction { ...@@ -264,6 +264,25 @@ class InputMethodPrivateSetSelectionRangeFunction : public ExtensionFunction {
INPUTMETHODPRIVATE_SETSELECTIONRANGE) INPUTMETHODPRIVATE_SETSELECTIONRANGE)
}; };
class InputMethodPrivateResetFunction : public ExtensionFunction {
public:
InputMethodPrivateResetFunction() = default;
InputMethodPrivateResetFunction(const InputMethodPrivateResetFunction&) =
delete;
InputMethodPrivateResetFunction& operator=(
const InputMethodPrivateResetFunction&) = delete;
protected:
~InputMethodPrivateResetFunction() override = default;
// ExtensionFunction:
ResponseAction Run() override;
private:
DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.reset",
INPUTMETHODPRIVATE_RESET)
};
class InputMethodAPI : public BrowserContextKeyedAPI, class InputMethodAPI : public BrowserContextKeyedAPI,
public extensions::EventRouter::Observer { public extensions::EventRouter::Observer {
public: public:
......
...@@ -518,6 +518,11 @@ ...@@ -518,6 +518,11 @@
] ]
} }
] ]
}, {
"name": "reset",
"type": "function",
"description": "Resets the current engine to its initial state. Fires an OnReset event.",
"parameters": []
} }
], ],
"events": [ "events": [
......
...@@ -1487,6 +1487,7 @@ enum HistogramValue { ...@@ -1487,6 +1487,7 @@ enum HistogramValue {
ENTERPRISEREPORTINGPRIVATE_GETDEVICEINFO = 1424, ENTERPRISEREPORTINGPRIVATE_GETDEVICEINFO = 1424,
PRINTING_GETPRINTERS = 1425, PRINTING_GETPRINTERS = 1425,
WEBCAMPRIVATE_SET_HOME = 1426, WEBCAMPRIVATE_SET_HOME = 1426,
INPUTMETHODPRIVATE_RESET = 1427,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -269,6 +269,11 @@ chrome.inputMethodPrivate.setSetting = function(engineID, key, value, callback) ...@@ -269,6 +269,11 @@ chrome.inputMethodPrivate.setSetting = function(engineID, key, value, callback)
*/ */
chrome.inputMethodPrivate.setCompositionRange = function(parameters, callback) {}; chrome.inputMethodPrivate.setCompositionRange = function(parameters, callback) {};
/**
* Resets the current engine to its initial state. Fires an OnReset event.
*/
chrome.inputMethodPrivate.reset = function() {};
/** /**
* Fired when the input method is changed. * Fired when the input method is changed.
* @type {!ChromeEvent} * @type {!ChromeEvent}
......
...@@ -21579,6 +21579,7 @@ to ensure that the crash string is shown properly on the user-facing crash UI. ...@@ -21579,6 +21579,7 @@ to ensure that the crash string is shown properly on the user-facing crash UI.
<int value="1424" label="ENTERPRISEREPORTINGPRIVATE_GETDEVICEINFO"/> <int value="1424" label="ENTERPRISEREPORTINGPRIVATE_GETDEVICEINFO"/>
<int value="1425" label="PRINTING_GETPRINTERS"/> <int value="1425" label="PRINTING_GETPRINTERS"/>
<int value="1426" label="WEBCAMPRIVATE_SET_HOME"/> <int value="1426" label="WEBCAMPRIVATE_SET_HOME"/>
<int value="1427" label="INPUTMETHODPRIVATE_RESET"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment