Commit f758f12b authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Send OnFocus proto message when focusing on an input field.

Add a new file containing protobufs to communicate between Chrome and
the new native input engine. Add an OnFocus proto message.

Send the OnFocus proto when focusing on an input field.

Bug: 1019541
Change-Id: Ia890efb881f92bfb5fe161208c83c9ed3a6368f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2370885Reviewed-by: default avatarOliver Chang <ochang@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804838}
parent 859591e3
...@@ -154,7 +154,7 @@ void NativeInputMethodEngine::ImeObserver::OnActivate( ...@@ -154,7 +154,7 @@ void NativeInputMethodEngine::ImeObserver::OnActivate(
new_engine_id, remote_to_engine_.BindNewPipeAndPassReceiver(), new_engine_id, remote_to_engine_.BindNewPipeAndPassReceiver(),
receiver_from_engine_.BindNewPipeAndPassRemote(), {}, receiver_from_engine_.BindNewPipeAndPassRemote(), {},
base::BindOnce(&ImeObserver::OnConnected, base::Unretained(this), base::BindOnce(&ImeObserver::OnConnected, base::Unretained(this),
base::Time::Now())); base::Time::Now(), new_engine_id));
} else { } else {
// Release the IME service. // Release the IME service.
// TODO(b/147709499): A better way to cleanup all. // TODO(b/147709499): A better way to cleanup all.
...@@ -168,6 +168,11 @@ void NativeInputMethodEngine::ImeObserver::OnFocus( ...@@ -168,6 +168,11 @@ void NativeInputMethodEngine::ImeObserver::OnFocus(
if (assistive_suggester_->IsAssistiveFeatureEnabled()) if (assistive_suggester_->IsAssistiveFeatureEnabled())
assistive_suggester_->OnFocus(context.id); assistive_suggester_->OnFocus(context.id);
if (active_engine_id_ && ShouldUseFstMojoEngine(*active_engine_id_) &&
remote_to_engine_.is_bound()) {
remote_to_engine_->OnFocus();
}
base_observer_->OnFocus(context); base_observer_->OnFocus(context);
} }
...@@ -320,13 +325,14 @@ void NativeInputMethodEngine::ImeObserver::FlushForTesting() { ...@@ -320,13 +325,14 @@ void NativeInputMethodEngine::ImeObserver::FlushForTesting() {
} }
void NativeInputMethodEngine::ImeObserver::OnConnected(base::Time start, void NativeInputMethodEngine::ImeObserver::OnConnected(base::Time start,
std::string engine_id,
bool bound) { bool bound) {
LogLatency("InputMethod.Mojo.Extension.ActivateIMELatency", LogLatency("InputMethod.Mojo.Extension.ActivateIMELatency",
base::Time::Now() - start); base::Time::Now() - start);
LogEvent(bound ? ImeServiceEvent::kActivateImeSuccess LogEvent(bound ? ImeServiceEvent::kActivateImeSuccess
: ImeServiceEvent::kActivateImeSuccess); : ImeServiceEvent::kActivateImeSuccess);
connected_to_engine_ = bound; active_engine_id_ = engine_id;
} }
void NativeInputMethodEngine::ImeObserver::OnError(base::Time start) { void NativeInputMethodEngine::ImeObserver::OnError(base::Time start) {
...@@ -340,6 +346,8 @@ void NativeInputMethodEngine::ImeObserver::OnError(base::Time start) { ...@@ -340,6 +346,8 @@ void NativeInputMethodEngine::ImeObserver::OnError(base::Time start) {
} else { } else {
LogEvent(ImeServiceEvent::kServiceDisconnected); LogEvent(ImeServiceEvent::kServiceDisconnected);
} }
active_engine_id_.reset();
} }
void NativeInputMethodEngine::ImeObserver::OnKeyEventResponse( void NativeInputMethodEngine::ImeObserver::OnKeyEventResponse(
......
...@@ -92,6 +92,7 @@ class NativeInputMethodEngine : public InputMethodEngine { ...@@ -92,6 +92,7 @@ class NativeInputMethodEngine : public InputMethodEngine {
// mojom::InputChannel: // mojom::InputChannel:
void ProcessMessage(const std::vector<uint8_t>& message, void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override {} ProcessMessageCallback callback) override {}
void OnFocus() override {}
void ProcessKeypressForRulebased( void ProcessKeypressForRulebased(
ime::mojom::PhysicalKeyEventPtr event, ime::mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback callback) override {} ProcessKeypressForRulebasedCallback callback) override {}
...@@ -103,12 +104,12 @@ class NativeInputMethodEngine : public InputMethodEngine { ...@@ -103,12 +104,12 @@ class NativeInputMethodEngine : public InputMethodEngine {
void FlushForTesting(); void FlushForTesting();
// Returns whether this is connected to the input engine. // Returns whether this is connected to the input engine.
bool IsConnectedForTesting() const { return connected_to_engine_; } bool IsConnectedForTesting() const { return active_engine_id_.has_value(); }
private: private:
// Called when this is connected to the input engine. |bound| indicates // Called when this is connected to the input engine. |bound| indicates
// the success of the connection. // the success of the connection.
void OnConnected(base::Time start, bool bound); void OnConnected(base::Time start, std::string engine_id, bool bound);
// Called when there's a connection error. // Called when there's a connection error.
void OnError(base::Time start); void OnError(base::Time start);
...@@ -123,7 +124,7 @@ class NativeInputMethodEngine : public InputMethodEngine { ...@@ -123,7 +124,7 @@ class NativeInputMethodEngine : public InputMethodEngine {
mojo::Remote<ime::mojom::InputEngineManager> remote_manager_; mojo::Remote<ime::mojom::InputEngineManager> remote_manager_;
mojo::Receiver<ime::mojom::InputChannel> receiver_from_engine_; mojo::Receiver<ime::mojom::InputChannel> receiver_from_engine_;
mojo::Remote<ime::mojom::InputChannel> remote_to_engine_; mojo::Remote<ime::mojom::InputChannel> remote_to_engine_;
bool connected_to_engine_ = false; base::Optional<std::string> active_engine_id_;
std::unique_ptr<AssistiveSuggester> assistive_suggester_; std::unique_ptr<AssistiveSuggester> assistive_suggester_;
}; };
......
...@@ -37,6 +37,7 @@ source_set("lib") { ...@@ -37,6 +37,7 @@ source_set("lib") {
"//chromeos/services/ime/public/cpp:rulebased", "//chromeos/services/ime/public/cpp:rulebased",
"//chromeos/services/ime/public/cpp/shared_lib:interfaces", "//chromeos/services/ime/public/cpp/shared_lib:interfaces",
"//chromeos/services/ime/public/mojom", "//chromeos/services/ime/public/mojom",
"//chromeos/services/ime/public/proto:messages_proto",
] ]
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "build/buildflag.h" #include "build/buildflag.h"
#include "chromeos/services/ime/constants.h" #include "chromeos/services/ime/constants.h"
#include "chromeos/services/ime/public/cpp/buildflags.h" #include "chromeos/services/ime/public/cpp/buildflags.h"
#include "chromeos/services/ime/public/proto/messages.pb.h"
namespace chromeos { namespace chromeos {
namespace ime { namespace ime {
...@@ -62,6 +63,14 @@ class ClientDelegate : public ImeClientDelegate { ...@@ -62,6 +63,14 @@ class ClientDelegate : public ImeClientDelegate {
mojo::Remote<mojom::InputChannel> client_remote_; mojo::Remote<mojom::InputChannel> client_remote_;
}; };
std::vector<uint8_t> SerializeRequest(const ime::Request& request) {
ime::Wrapper wrapper;
*wrapper.mutable_request() = request;
std::vector<uint8_t> output;
wrapper.SerializeToArray(output.data(), output.size());
return output;
}
} // namespace } // namespace
void FakeEngineMainEntryForTesting() { void FakeEngineMainEntryForTesting() {
...@@ -134,6 +143,14 @@ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) { ...@@ -134,6 +143,14 @@ bool DecoderEngine::IsImeSupportedByDecoder(const std::string& ime_spec) {
engine_main_entry_->IsImeSupported(ime_spec.c_str()); engine_main_entry_->IsImeSupported(ime_spec.c_str());
} }
void DecoderEngine::OnFocus() {
ime::Request request;
request.set_seq_id(current_seq_id_++);
*request.mutable_on_focus() = ime::OnFocus();
ProcessMessage(SerializeRequest(request), base::DoNothing());
}
void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message, void DecoderEngine::ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) { ProcessMessageCallback callback) {
// TODO(https://crbug.com/837156): Set a default protobuf message. // TODO(https://crbug.com/837156): Set a default protobuf message.
......
...@@ -32,6 +32,7 @@ class DecoderEngine : public InputEngine { ...@@ -32,6 +32,7 @@ class DecoderEngine : public InputEngine {
void ProcessMessage(const std::vector<uint8_t>& message, void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override; ProcessMessageCallback callback) override;
void OnFocus() override;
private: private:
// Try to load the decoding functions from some decoder shared library. // Try to load the decoding functions from some decoder shared library.
...@@ -50,6 +51,9 @@ class DecoderEngine : public InputEngine { ...@@ -50,6 +51,9 @@ class DecoderEngine : public InputEngine {
mojo::ReceiverSet<mojom::InputChannel> decoder_channel_receivers_; mojo::ReceiverSet<mojom::InputChannel> decoder_channel_receivers_;
// Sequence ID for protobuf messages sent from the engine.
int current_seq_id_ = 0;
DISALLOW_COPY_AND_ASSIGN(DecoderEngine); DISALLOW_COPY_AND_ASSIGN(DecoderEngine);
}; };
......
...@@ -55,6 +55,7 @@ class TestClientChannel : mojom::InputChannel { ...@@ -55,6 +55,7 @@ class TestClientChannel : mojom::InputChannel {
MOCK_METHOD2(ProcessMessage, MOCK_METHOD2(ProcessMessage,
void(const std::vector<uint8_t>& message, void(const std::vector<uint8_t>& message,
ProcessMessageCallback)); ProcessMessageCallback));
MOCK_METHOD0(OnFocus, void());
MOCK_METHOD2(ProcessKeypressForRulebased, MOCK_METHOD2(ProcessKeypressForRulebased,
void(const mojom::PhysicalKeyEventPtr event, void(const mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback)); ProcessKeypressForRulebasedCallback));
......
...@@ -107,6 +107,10 @@ void InputEngine::ProcessMessage(const std::vector<uint8_t>& message, ...@@ -107,6 +107,10 @@ void InputEngine::ProcessMessage(const std::vector<uint8_t>& message,
NOTIMPLEMENTED(); // Protobuf message is not used in the rulebased engine. NOTIMPLEMENTED(); // Protobuf message is not used in the rulebased engine.
} }
void InputEngine::OnFocus() {
NOTIMPLEMENTED(); // Not used in the rulebased engine.
}
void InputEngine::ProcessKeypressForRulebased( void InputEngine::ProcessKeypressForRulebased(
mojom::PhysicalKeyEventPtr event, mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback callback) { ProcessKeypressForRulebasedCallback callback) {
......
...@@ -45,6 +45,7 @@ class InputEngine : public mojom::InputChannel { ...@@ -45,6 +45,7 @@ class InputEngine : public mojom::InputChannel {
// mojom::InputChannel overrides: // mojom::InputChannel overrides:
void ProcessMessage(const std::vector<uint8_t>& message, void ProcessMessage(const std::vector<uint8_t>& message,
ProcessMessageCallback callback) override; ProcessMessageCallback callback) override;
void OnFocus() override;
void ProcessKeypressForRulebased( void ProcessKeypressForRulebased(
mojom::PhysicalKeyEventPtr event, mojom::PhysicalKeyEventPtr event,
ProcessKeypressForRulebasedCallback callback) override; ProcessKeypressForRulebasedCallback callback) override;
......
...@@ -112,6 +112,9 @@ interface InputChannel { ...@@ -112,6 +112,9 @@ interface InputChannel {
// protobuf message. // protobuf message.
ProcessMessage(array<uint8> message) => (array<uint8> result); ProcessMessage(array<uint8> message) => (array<uint8> result);
// Called when there's a new focused input field.
OnFocus();
// Process a PhysicalKeyEvent using the rule-based engine and return a // Process a PhysicalKeyEvent using the rule-based engine and return a
// KeypressResponseForRulebased object with a list of operations to be handled // KeypressResponseForRulebased object with a list of operations to be handled
// by the caller. // by the caller.
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/protobuf/proto_library.gni")
proto_library("messages_proto") {
sources = [ "messages.proto" ]
}
syntax = "proto2";
option optimize_for = LITE_RUNTIME;
package chromeos.ime;
// Wrapper message to contain either internal messages or public messages.
message Wrapper {
oneof param {
string internal_request = 1;
string internal_reply = 2;
Request request = 3;
Reply reply = 4;
}
}
// Message from Chrome to the shared library.
message Request {
// The sequence id of the request.
optional int32 seq_id = 1;
oneof param { OnFocus on_focus = 2; }
}
// Message from the shared library to Chrome.
message Reply {
// The sequence id of the reply.
optional int32 seq_id = 1;
}
// Protobuf version of InputEngine::OnFocus in
// chromeos/services/ime/public/mojom/input_engine.mojom
message OnFocus {
// TODO(crbug/1019541): Add information about the input field.
}
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