Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1976)

Unified Diff: blimp/client/feature/ime_feature.cc

Issue 1779673003: Added network components for blimp text input feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review comments from Wez Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4210e7da3315b234c228e186e395f7d368973d8b
--- /dev/null
+++ b/blimp/client/feature/ime_feature.cc
@@ -0,0 +1,77 @@
+// 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()
+ : delegate_(nullptr), tab_id_(-1), render_widget_id_(0) {}
Wez 2016/03/23 00:10:53 No need to initialize these here if you're doing i
shaktisahu 2016/03/23 01:44:13 Done.
+
+ImeFeature::~ImeFeature() {}
+
+void ImeFeature::OnImeTextEntered(const std::string& text) {
+ DCHECK_LE(0, tab_id_);
+ DCHECK_LT(0, render_widget_id_);
+
+ 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_EQ(message->type(), BlimpMessage::IME);
Wez 2016/03/23 00:10:53 nit: DCHECK_EQ(BlimpMessage::IME, message-type())
shaktisahu 2016/03/23 01:44:13 Done.
+
+ DCHECK(delegate_);
+
+ const ImeMessage& ime_message = message->ime();
+
+ switch (ime_message.type()) {
+ case ImeMessage::SHOW_IME:
+ if (!message->has_target_tab_id() || message->target_tab_id() < 0 ||
+ ime_message.render_widget_id() <= 0) {
+ callback.Run(net::ERR_INVALID_ARGUMENT);
+ return;
+ }
+
+ tab_id_ = message->target_tab_id();
+ render_widget_id_ = ime_message.render_widget_id();
+
+ delegate_->OnShowImeRequested(
+ InputMessageConverter::TextInputTypeFromProto(
+ ime_message.text_input_type()),
+ ime_message.ime_text());
+ break;
+ case ImeMessage::HIDE_IME:
+ tab_id_ = -1;
+ render_widget_id_ = 0;
+ delegate_->OnHideImeRequested();
+ break;
+ case ImeMessage::SET_TEXT:
+ case ImeMessage::UNKNOWN:
+ NOTREACHED();
+ callback.Run(net::ERR_UNEXPECTED);
+ return;
+ }
+
+ callback.Run(net::OK);
+}
+
+} // namespace client
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698