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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <blimp/client/feature/ime_feature.h>
6 #include <string>
7
8 #include "blimp/common/create_blimp_message.h"
9 #include "blimp/common/proto/blimp_message.pb.h"
10 #include "blimp/net/input_message_converter.h"
11 #include "net/base/net_errors.h"
12
13 namespace blimp {
14 namespace client {
15
16 ImeFeature::ImeFeature()
17 : 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.
18
19 ImeFeature::~ImeFeature() {}
20
21 void ImeFeature::OnImeTextEntered(const std::string& text) {
22 DCHECK_LE(0, tab_id_);
23 DCHECK_LT(0, render_widget_id_);
24
25 ImeMessage* ime_message;
26 scoped_ptr<BlimpMessage> blimp_message =
27 CreateBlimpMessage(&ime_message, tab_id_);
28 ime_message->set_render_widget_id(render_widget_id_);
29 ime_message->set_type(ImeMessage::SET_TEXT);
30 ime_message->set_ime_text(text);
31
32 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
33 net::CompletionCallback());
34 }
35
36 void ImeFeature::ProcessMessage(scoped_ptr<BlimpMessage> message,
37 const net::CompletionCallback& callback) {
38 DCHECK(!callback.is_null());
39 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.
40
41 DCHECK(delegate_);
42
43 const ImeMessage& ime_message = message->ime();
44
45 switch (ime_message.type()) {
46 case ImeMessage::SHOW_IME:
47 if (!message->has_target_tab_id() || message->target_tab_id() < 0 ||
48 ime_message.render_widget_id() <= 0) {
49 callback.Run(net::ERR_INVALID_ARGUMENT);
50 return;
51 }
52
53 tab_id_ = message->target_tab_id();
54 render_widget_id_ = ime_message.render_widget_id();
55
56 delegate_->OnShowImeRequested(
57 InputMessageConverter::TextInputTypeFromProto(
58 ime_message.text_input_type()),
59 ime_message.ime_text());
60 break;
61 case ImeMessage::HIDE_IME:
62 tab_id_ = -1;
63 render_widget_id_ = 0;
64 delegate_->OnHideImeRequested();
65 break;
66 case ImeMessage::SET_TEXT:
67 case ImeMessage::UNKNOWN:
68 NOTREACHED();
69 callback.Run(net::ERR_UNEXPECTED);
70 return;
71 }
72
73 callback.Run(net::OK);
74 }
75
76 } // namespace client
77 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698