Chromium Code Reviews| Index: blimp/client/feature/ime_feature.cc |
| diff --git a/blimp/client/feature/ime_feature.cc b/blimp/client/feature/ime_feature.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..be39209778cc4a1e35682316814a8a57b8b841bb |
| --- /dev/null |
| +++ b/blimp/client/feature/ime_feature.cc |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2016 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. |
| + |
| +#include <blimp/client/feature/ime_feature.h> |
| +#include <string> |
| + |
| +#include "blimp/common/create_blimp_message.h" |
| +#include "blimp/common/proto/blimp_message.pb.h" |
| +#include "blimp/net/input_message_converter.h" |
| +#include "net/base/net_errors.h" |
| + |
| +namespace blimp { |
| +namespace client { |
| + |
| +ImeFeature::ImeFeature() {} |
|
Wez
2016/03/18 20:51:28
As noted in the header, there are POD members of t
shaktisahu
2016/03/22 19:44:19
Done.
|
| + |
| +ImeFeature::~ImeFeature() {} |
| + |
| +void ImeFeature::set_outgoing_message_processor( |
| + scoped_ptr<BlimpMessageProcessor> processor) { |
| + outgoing_message_processor_ = std::move(processor); |
|
Wez
2016/03/18 20:51:27
nit: Since this is a "simple" setter you could imp
shaktisahu
2016/03/22 19:44:19
Done.
|
| +} |
| + |
| +void ImeFeature::SetDelegate(ImeFeatureDelegate* delegate) { |
|
Wez
2016/03/18 20:51:28
Similarly, since this is a simple setter, it could
shaktisahu
2016/03/22 19:44:19
Done.
|
| + delegate_ = delegate; |
| +} |
| + |
| +void ImeFeature::SendImeTextToEngine(const std::string& text) { |
|
Wez
2016/03/18 20:51:28
I'd suggest DCHECK()ing that the tab & widget Ids
shaktisahu
2016/03/22 19:44:19
Done.
|
| + ImeMessage* ime_message; |
| + scoped_ptr<BlimpMessage> blimp_message = |
| + CreateBlimpMessage(&ime_message, tab_id_); |
| + ime_message->set_render_widget_id(render_widget_id_); |
| + ime_message->set_type(ImeMessage::SET_TEXT); |
| + ime_message->set_ime_text(text); |
| + |
| + outgoing_message_processor_->ProcessMessage(std::move(blimp_message), |
| + net::CompletionCallback()); |
| +} |
| + |
| +void ImeFeature::ProcessMessage(scoped_ptr<BlimpMessage> message, |
| + const net::CompletionCallback& callback) { |
| + DCHECK(!callback.is_null()); |
| + DCHECK(message->type() == BlimpMessage::IME); |
|
Wez
2016/03/18 20:51:27
As noted below, if the Engine sends bad data, call
shaktisahu
2016/03/22 19:44:19
Done.
Wez
2016/03/22 21:43:37
Ah, sorry; forgot that the demultiplexer should ne
shaktisahu
2016/03/22 23:45:42
Done.
shaktisahu
2016/03/22 23:45:42
Done.
|
| + |
| + DCHECK(delegate_) << "ImeFeatureDelegate not set"; |
|
Wez
2016/03/18 20:51:27
nit: The message following the DCHECK seems redund
shaktisahu
2016/03/22 19:44:19
Done.
|
| + |
| + const ImeMessage& ime_message = message->ime(); |
| + tab_id_ = message->target_tab_id(); |
| + render_widget_id_ = ime_message.render_widget_id(); |
|
Wez
2016/03/18 20:51:28
When you receive a hide request you're basically s
shaktisahu
2016/03/22 19:44:19
Done.
|
| + |
| + switch (ime_message.type()) { |
| + case ImeMessage::SHOW_IME: |
|
Wez
2016/03/18 20:51:28
Suggest adding a check that the tab & widget Ids a
shaktisahu
2016/03/22 19:44:19
Done.
Wez
2016/03/22 21:43:37
Looks like you've added a check for the sender spe
shaktisahu
2016/03/22 23:45:42
Actually, there might be a case where we might hav
|
| + delegate_->OnShowImeRequested( |
| + InputMessageConverter::TextInputTypeFromProto( |
| + ime_message.text_input_type()), |
| + ime_message.ime_text()); |
| + break; |
| + case ImeMessage::HIDE_IME: |
| + delegate_->OnHideImeRequested(); |
|
Wez
2016/03/18 20:51:27
Suggesting DCHECKing that the tab & widget Ids are
shaktisahu
2016/03/22 19:44:19
Actually, tab and widget ids can be invalid here.
Wez
2016/03/22 21:43:37
So if the tab_id_ and render_widget_id_ are invali
shaktisahu
2016/03/22 23:45:42
Same as above comment. I would still prefer to mak
|
| + break; |
| + case ImeMessage::SET_TEXT: |
|
Wez
2016/03/18 20:51:27
nit: No need for a separate code block for this an
shaktisahu
2016/03/22 19:44:19
Done.
|
| + NOTREACHED(); |
| + break; |
| + case ImeMessage::UNKNOWN: |
| + NOTREACHED(); |
| + } |
| + |
| + callback.Run(net::OK); |
| +} |
| + |
| +} // namespace client |
| +} // namespace blimp |