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

Side by Side Diff: blimp/engine/session/blimp_engine_session.cc

Issue 1779673003: Added network components for blimp text input feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed initial values for tab id in ImeFeature 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/engine/session/blimp_engine_session.h" 5 #include "blimp/engine/session/blimp_engine_session.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 14 matching lines...) Expand all
25 #include "blimp/net/engine_connection_manager.h" 25 #include "blimp/net/engine_connection_manager.h"
26 #include "blimp/net/null_blimp_message_processor.h" 26 #include "blimp/net/null_blimp_message_processor.h"
27 #include "blimp/net/tcp_engine_transport.h" 27 #include "blimp/net/tcp_engine_transport.h"
28 #include "blimp/net/thread_pipe_manager.h" 28 #include "blimp/net/thread_pipe_manager.h"
29 #include "content/public/browser/browser_context.h" 29 #include "content/public/browser/browser_context.h"
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/navigation_controller.h" 31 #include "content/public/browser/navigation_controller.h"
32 #include "content/public/browser/navigation_entry.h" 32 #include "content/public/browser/navigation_entry.h"
33 #include "content/public/browser/render_view_host.h" 33 #include "content/public/browser/render_view_host.h"
34 #include "content/public/browser/render_widget_host.h" 34 #include "content/public/browser/render_widget_host.h"
35 #include "content/public/browser/render_widget_host_view.h"
35 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
36 #include "net/base/ip_address.h" 37 #include "net/base/ip_address.h"
37 #include "net/base/net_errors.h" 38 #include "net/base/net_errors.h"
38 #include "ui/aura/client/default_capture_client.h" 39 #include "ui/aura/client/default_capture_client.h"
39 #include "ui/aura/env.h" 40 #include "ui/aura/env.h"
40 #include "ui/aura/window.h" 41 #include "ui/aura/window.h"
41 #include "ui/aura/window_tree_host.h" 42 #include "ui/aura/window_tree_host.h"
43 #include "ui/base/ime/input_method.h"
44 #include "ui/base/ime/text_input_client.h"
42 #include "ui/gfx/geometry/size.h" 45 #include "ui/gfx/geometry/size.h"
43 #include "ui/wm/core/base_focus_rules.h" 46 #include "ui/wm/core/base_focus_rules.h"
44 #include "ui/wm/core/default_activation_client.h" 47 #include "ui/wm/core/default_activation_client.h"
45 #include "ui/wm/core/focus_controller.h" 48 #include "ui/wm/core/focus_controller.h"
46 49
47 50
48 namespace blimp { 51 namespace blimp {
49 namespace engine { 52 namespace engine {
50 namespace { 53 namespace {
51 54
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 DCHECK(engine_config_); 190 DCHECK(engine_config_);
188 screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, 191 screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor,
189 gfx::Size(kDefaultDisplayWidth, 192 gfx::Size(kDefaultDisplayWidth,
190 kDefaultDisplayHeight)); 193 kDefaultDisplayHeight));
191 render_widget_feature_.SetDelegate(kDummyTabId, this); 194 render_widget_feature_.SetDelegate(kDummyTabId, this);
192 } 195 }
193 196
194 BlimpEngineSession::~BlimpEngineSession() { 197 BlimpEngineSession::~BlimpEngineSession() {
195 render_widget_feature_.RemoveDelegate(kDummyTabId); 198 render_widget_feature_.RemoveDelegate(kDummyTabId);
196 199
200 window_tree_host_->GetInputMethod()->RemoveObserver(this);
201
197 // Ensure that all WebContents are torn down first, since teardown will 202 // Ensure that all WebContents are torn down first, since teardown will
198 // trigger RenderViewDeleted callbacks to their observers. 203 // trigger RenderViewDeleted callbacks to their observers.
199 web_contents_.reset(); 204 web_contents_.reset();
200 205
201 // Safely delete network components on the IO thread. 206 // Safely delete network components on the IO thread.
202 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, 207 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
203 net_components_.release()); 208 net_components_.release());
204 } 209 }
205 210
206 void BlimpEngineSession::Initialize() { 211 void BlimpEngineSession::Initialize() {
207 DCHECK(!gfx::Screen::GetScreen()); 212 DCHECK(!gfx::Screen::GetScreen());
208 gfx::Screen::SetScreenInstance(screen_.get()); 213 gfx::Screen::SetScreenInstance(screen_.get());
209 214
210 context_factory_.reset(new BlimpUiContextFactory()); 215 context_factory_.reset(new BlimpUiContextFactory());
211 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); 216 aura::Env::GetInstance()->set_context_factory(context_factory_.get());
212 window_tree_host_.reset(new BlimpWindowTreeHost()); 217 window_tree_host_.reset(new BlimpWindowTreeHost());
213 218
214 screen_->set_window_tree_host(window_tree_host_.get()); 219 screen_->set_window_tree_host(window_tree_host_.get());
215 window_tree_host_->InitHost(); 220 window_tree_host_->InitHost();
216 window_tree_host_->window()->SetLayoutManager( 221 window_tree_host_->window()->SetLayoutManager(
217 new BlimpLayoutManager(window_tree_host_->window())); 222 new BlimpLayoutManager(window_tree_host_->window()));
218 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); 223 focus_client_.reset(new wm::FocusController(new FocusRulesImpl));
219 aura::client::SetFocusClient(window_tree_host_->window(), 224 aura::client::SetFocusClient(window_tree_host_->window(),
220 focus_client_.get()); 225 focus_client_.get());
221 aura::client::SetActivationClient(window_tree_host_->window(), 226 aura::client::SetActivationClient(window_tree_host_->window(),
222 focus_client_.get()); 227 focus_client_.get());
223 capture_client_.reset( 228 capture_client_.reset(
224 new aura::client::DefaultCaptureClient(window_tree_host_->window())); 229 new aura::client::DefaultCaptureClient(window_tree_host_->window()));
225 230
231 window_tree_host_->GetInputMethod()->AddObserver(this);
232
226 window_tree_host_->SetBounds(gfx::Rect(screen_->GetPrimaryDisplay().size())); 233 window_tree_host_->SetBounds(gfx::Rect(screen_->GetPrimaryDisplay().size()));
227 234
228 RegisterFeatures(); 235 RegisterFeatures();
229 236
230 // Initialize must only be posted after the RegisterFeature calls have 237 // Initialize must only be posted after the RegisterFeature calls have
231 // completed. 238 // completed.
232 content::BrowserThread::PostTask( 239 content::BrowserThread::PostTask(
233 content::BrowserThread::IO, FROM_HERE, 240 content::BrowserThread::IO, FROM_HERE,
234 base::Bind(&EngineNetworkComponents::Initialize, 241 base::Bind(&EngineNetworkComponents::Initialize,
235 base::Unretained(net_components_.get()), 242 base::Unretained(net_components_.get()),
(...skipping 15 matching lines...) Expand all
251 thread_pipe_manager_->RegisterFeature(BlimpMessage::NAVIGATION, this); 258 thread_pipe_manager_->RegisterFeature(BlimpMessage::NAVIGATION, this);
252 render_widget_feature_.set_render_widget_message_sender( 259 render_widget_feature_.set_render_widget_message_sender(
253 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, 260 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET,
254 &render_widget_feature_)); 261 &render_widget_feature_));
255 render_widget_feature_.set_input_message_sender( 262 render_widget_feature_.set_input_message_sender(
256 thread_pipe_manager_->RegisterFeature(BlimpMessage::INPUT, 263 thread_pipe_manager_->RegisterFeature(BlimpMessage::INPUT,
257 &render_widget_feature_)); 264 &render_widget_feature_));
258 render_widget_feature_.set_compositor_message_sender( 265 render_widget_feature_.set_compositor_message_sender(
259 thread_pipe_manager_->RegisterFeature(BlimpMessage::COMPOSITOR, 266 thread_pipe_manager_->RegisterFeature(BlimpMessage::COMPOSITOR,
260 &render_widget_feature_)); 267 &render_widget_feature_));
268 render_widget_feature_.set_ime_message_sender(
269 thread_pipe_manager_->RegisterFeature(BlimpMessage::IME,
270 &render_widget_feature_));
261 } 271 }
262 272
263 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { 273 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) {
264 DVLOG(1) << "Create tab " << target_tab_id; 274 DVLOG(1) << "Create tab " << target_tab_id;
265 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). 275 // TODO(haibinlu): Support more than one active WebContents (crbug/547231).
266 if (web_contents_) { 276 if (web_contents_) {
267 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; 277 DLOG(WARNING) << "Tab " << target_tab_id << " already existed";
268 return false; 278 return false;
269 } 279 }
270 280
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 render_widget_host->ForwardGestureEvent(*event); 345 render_widget_host->ForwardGestureEvent(*event);
336 } 346 }
337 347
338 void BlimpEngineSession::OnCompositorMessageReceived( 348 void BlimpEngineSession::OnCompositorMessageReceived(
339 content::RenderWidgetHost* render_widget_host, 349 content::RenderWidgetHost* render_widget_host,
340 const std::vector<uint8_t>& message) { 350 const std::vector<uint8_t>& message) {
341 351
342 render_widget_host->HandleCompositorProto(message); 352 render_widget_host->HandleCompositorProto(message);
343 } 353 }
344 354
355 void BlimpEngineSession::OnTextInputTypeChanged(
356 const ui::TextInputClient* client) {}
357
358 void BlimpEngineSession::OnFocus() {}
359
360 void BlimpEngineSession::OnBlur() {}
361
362 void BlimpEngineSession::OnCaretBoundsChanged(
363 const ui::TextInputClient* client) {}
364
365 // Called when either:
366 // - the TextInputClient is changed (e.g. by a change of focus)
367 // - the TextInputType of the TextInputClient changes
368 void BlimpEngineSession::OnTextInputStateChanged(
369 const ui::TextInputClient* client) {
370 if (!web_contents_->GetRenderWidgetHostView())
371 return;
372
373 ui::TextInputType type =
374 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
375
376 // TODO(shaktisahu): Propagate the new type to the client.
377 // Hide IME, when text input is out of focus, i.e. if the text input type
378 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types,
379 // OnShowImeIfNeeded is used instead to send show IME request to client.
380 if (type == ui::TEXT_INPUT_TYPE_NONE)
381 render_widget_feature_.SendHideImeRequest(
382 kDummyTabId,
383 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost());
384 }
385
386 void BlimpEngineSession::OnInputMethodDestroyed(
387 const ui::InputMethod* input_method) {}
388
389 // Called when a user input should trigger showing the IME.
390 void BlimpEngineSession::OnShowImeIfNeeded() {
391 if (!web_contents_->GetRenderWidgetHostView() ||
392 !window_tree_host_->GetInputMethod()->GetTextInputClient())
393 return;
394
395 render_widget_feature_.SendShowImeRequest(
396 kDummyTabId,
397 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(),
398 window_tree_host_->GetInputMethod()->GetTextInputClient());
399 }
400
345 void BlimpEngineSession::ProcessMessage( 401 void BlimpEngineSession::ProcessMessage(
346 scoped_ptr<BlimpMessage> message, 402 scoped_ptr<BlimpMessage> message,
347 const net::CompletionCallback& callback) { 403 const net::CompletionCallback& callback) {
348 DCHECK(!callback.is_null()); 404 DCHECK(!callback.is_null());
349 DCHECK(message->type() == BlimpMessage::TAB_CONTROL || 405 DCHECK(message->type() == BlimpMessage::TAB_CONTROL ||
350 message->type() == BlimpMessage::NAVIGATION); 406 message->type() == BlimpMessage::NAVIGATION);
351 407
352 net::Error result = net::OK; 408 net::Error result = net::OK;
353 if (message->type() == BlimpMessage::TAB_CONTROL) { 409 if (message->type() == BlimpMessage::TAB_CONTROL) {
354 switch (message->tab_control().type()) { 410 switch (message->tab_control().type()) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 536
481 navigation_message_sender_->ProcessMessage(std::move(message), 537 navigation_message_sender_->ProcessMessage(std::move(message),
482 net::CompletionCallback()); 538 net::CompletionCallback());
483 } 539 }
484 540
485 void BlimpEngineSession::LoadProgressChanged( 541 void BlimpEngineSession::LoadProgressChanged(
486 content::WebContents* source, double progress) { 542 content::WebContents* source, double progress) {
487 if (source != web_contents_.get()) 543 if (source != web_contents_.get())
488 return; 544 return;
489 545
490 bool page_load_completed = progress == 1.0 ? true : false; 546 bool page_load_completed = progress == 1.0 ? true : false;
Wez 2016/03/22 21:43:38 nit: Why not just completed = (progress == 1.0)
shaktisahu 2016/03/22 23:45:43 Not from my CL.
Wez 2016/03/23 00:10:53 Acknowledged.
491 547
492 // If the client has been notified of a page load completed change, avoid 548 // If the client has been notified of a page load completed change, avoid
493 // sending another message. For the first navigation, the initial value used 549 // sending another message. For the first navigation, the initial value used
494 // by the client is already false. 550 // by the client is already false.
495 if (last_page_load_completed_value_ == page_load_completed) 551 if (last_page_load_completed_value_ == page_load_completed)
496 return; 552 return;
497 553
498 NavigationMessage* navigation_message; 554 NavigationMessage* navigation_message;
Wez 2016/03/22 21:43:38 nit: Initialize this, even though it's about to be
Wez 2016/03/23 00:10:53 Ping
shaktisahu 2016/03/23 01:44:13 Done.
499 scoped_ptr<BlimpMessage> message = 555 scoped_ptr<BlimpMessage> message =
500 CreateBlimpMessage(&navigation_message, kDummyTabId); 556 CreateBlimpMessage(&navigation_message, kDummyTabId);
501 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); 557 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED);
502 NavigationStateChangeMessage* details = 558 NavigationStateChangeMessage* details =
Wez 2016/03/22 21:43:38 Indentation looks wrong here.
shaktisahu 2016/03/23 01:44:13 Done.
503 navigation_message->mutable_navigation_state_changed(); 559 navigation_message->mutable_navigation_state_changed();
504 details->set_page_load_completed(page_load_completed); 560 details->set_page_load_completed(page_load_completed);
505 561
506 navigation_message_sender_->ProcessMessage(std::move(message), 562 navigation_message_sender_->ProcessMessage(std::move(message),
507 net::CompletionCallback()); 563 net::CompletionCallback());
508 564
509 last_page_load_completed_value_ = page_load_completed; 565 last_page_load_completed_value_ = page_load_completed;
510 } 566 }
511 567
512 void BlimpEngineSession::RenderViewCreated( 568 void BlimpEngineSession::RenderViewCreated(
(...skipping 25 matching lines...) Expand all
538 594
539 aura::Window* parent = window_tree_host_->window(); 595 aura::Window* parent = window_tree_host_->window();
540 aura::Window* content = web_contents_->GetNativeView(); 596 aura::Window* content = web_contents_->GetNativeView();
541 if (!parent->Contains(content)) 597 if (!parent->Contains(content))
542 parent->AddChild(content); 598 parent->AddChild(content);
543 content->Show(); 599 content->Show();
544 } 600 }
545 601
546 } // namespace engine 602 } // namespace engine
547 } // namespace blimp 603 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698