Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "blimp/common/create_blimp_message.h" | 10 #include "blimp/common/create_blimp_message.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
| 32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/render_widget_host.h" | 33 #include "content/public/browser/render_widget_host.h" |
| 34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "net/base/ip_address.h" | 35 #include "net/base/ip_address.h" |
| 36 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
| 37 #include "ui/aura/client/default_capture_client.h" | 37 #include "ui/aura/client/default_capture_client.h" |
| 38 #include "ui/aura/env.h" | 38 #include "ui/aura/env.h" |
| 39 #include "ui/aura/window.h" | 39 #include "ui/aura/window.h" |
| 40 #include "ui/aura/window_tree_host.h" | 40 #include "ui/aura/window_tree_host.h" |
| 41 #include "ui/base/ime/input_method.h" | |
| 42 #include "ui/base/ime/text_input_client.h" | |
| 41 #include "ui/gfx/geometry/size.h" | 43 #include "ui/gfx/geometry/size.h" |
| 42 #include "ui/wm/core/base_focus_rules.h" | 44 #include "ui/wm/core/base_focus_rules.h" |
| 43 #include "ui/wm/core/default_activation_client.h" | 45 #include "ui/wm/core/default_activation_client.h" |
| 44 #include "ui/wm/core/focus_controller.h" | 46 #include "ui/wm/core/focus_controller.h" |
| 45 | 47 |
| 46 | 48 |
| 47 namespace blimp { | 49 namespace blimp { |
| 48 namespace engine { | 50 namespace engine { |
| 49 namespace { | 51 namespace { |
| 50 | 52 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 window_tree_host_->window()->SetLayoutManager( | 165 window_tree_host_->window()->SetLayoutManager( |
| 164 new BlimpLayoutManager(window_tree_host_->window())); | 166 new BlimpLayoutManager(window_tree_host_->window())); |
| 165 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); | 167 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); |
| 166 aura::client::SetFocusClient(window_tree_host_->window(), | 168 aura::client::SetFocusClient(window_tree_host_->window(), |
| 167 focus_client_.get()); | 169 focus_client_.get()); |
| 168 aura::client::SetActivationClient(window_tree_host_->window(), | 170 aura::client::SetActivationClient(window_tree_host_->window(), |
| 169 focus_client_.get()); | 171 focus_client_.get()); |
| 170 capture_client_.reset( | 172 capture_client_.reset( |
| 171 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 173 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
| 172 | 174 |
| 175 window_tree_host_->GetInputMethod()->AddObserver(this); | |
|
nyquist
2016/03/10 00:57:13
Does this observer need to be removed? Also, this
shaktisahu
2016/03/15 23:44:13
Done.
| |
| 176 | |
| 173 window_tree_host_->SetBounds(gfx::Rect(screen_->GetPrimaryDisplay().size())); | 177 window_tree_host_->SetBounds(gfx::Rect(screen_->GetPrimaryDisplay().size())); |
| 174 | 178 |
| 175 RegisterFeatures(); | 179 RegisterFeatures(); |
| 176 | 180 |
| 177 // Initialize must only be posted after the RegisterFeature calls have | 181 // Initialize must only be posted after the RegisterFeature calls have |
| 178 // completed. | 182 // completed. |
| 179 content::BrowserThread::PostTask( | 183 content::BrowserThread::PostTask( |
| 180 content::BrowserThread::IO, FROM_HERE, | 184 content::BrowserThread::IO, FROM_HERE, |
| 181 base::Bind(&EngineNetworkComponents::Initialize, | 185 base::Bind(&EngineNetworkComponents::Initialize, |
| 182 base::Unretained(net_components_.get()), | 186 base::Unretained(net_components_.get()), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 198 thread_pipe_manager_->RegisterFeature(BlimpMessage::NAVIGATION, this); | 202 thread_pipe_manager_->RegisterFeature(BlimpMessage::NAVIGATION, this); |
| 199 render_widget_feature_.set_render_widget_message_sender( | 203 render_widget_feature_.set_render_widget_message_sender( |
| 200 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, | 204 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, |
| 201 &render_widget_feature_)); | 205 &render_widget_feature_)); |
| 202 render_widget_feature_.set_input_message_sender( | 206 render_widget_feature_.set_input_message_sender( |
| 203 thread_pipe_manager_->RegisterFeature(BlimpMessage::INPUT, | 207 thread_pipe_manager_->RegisterFeature(BlimpMessage::INPUT, |
| 204 &render_widget_feature_)); | 208 &render_widget_feature_)); |
| 205 render_widget_feature_.set_compositor_message_sender( | 209 render_widget_feature_.set_compositor_message_sender( |
| 206 thread_pipe_manager_->RegisterFeature(BlimpMessage::COMPOSITOR, | 210 thread_pipe_manager_->RegisterFeature(BlimpMessage::COMPOSITOR, |
| 207 &render_widget_feature_)); | 211 &render_widget_feature_)); |
| 212 ime_message_sender_ = | |
| 213 thread_pipe_manager_->RegisterFeature(BlimpMessage::IME, this); | |
|
nyquist
2016/03/10 00:57:13
I was hoping we wouldn't have to pass in |this| he
shaktisahu
2016/03/15 23:44:13
Done.
| |
| 208 } | 214 } |
| 209 | 215 |
| 210 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { | 216 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { |
| 211 DVLOG(1) << "Create tab " << target_tab_id; | 217 DVLOG(1) << "Create tab " << target_tab_id; |
| 212 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). | 218 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). |
| 213 if (web_contents_) { | 219 if (web_contents_) { |
| 214 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; | 220 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; |
| 215 return false; | 221 return false; |
| 216 } | 222 } |
| 217 | 223 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 render_widget_host->ForwardGestureEvent(*event); | 288 render_widget_host->ForwardGestureEvent(*event); |
| 283 } | 289 } |
| 284 | 290 |
| 285 void BlimpEngineSession::OnCompositorMessageReceived( | 291 void BlimpEngineSession::OnCompositorMessageReceived( |
| 286 content::RenderWidgetHost* render_widget_host, | 292 content::RenderWidgetHost* render_widget_host, |
| 287 const std::vector<uint8_t>& message) { | 293 const std::vector<uint8_t>& message) { |
| 288 | 294 |
| 289 render_widget_host->HandleCompositorProto(message); | 295 render_widget_host->HandleCompositorProto(message); |
| 290 } | 296 } |
| 291 | 297 |
| 298 void BlimpEngineSession::OnTextInputTypeChanged( | |
| 299 const ui::TextInputClient* client) {} | |
| 300 | |
| 301 void BlimpEngineSession::OnFocus() {} | |
| 302 | |
| 303 void BlimpEngineSession::OnBlur() {} | |
| 304 | |
| 305 void BlimpEngineSession::OnCaretBoundsChanged( | |
| 306 const ui::TextInputClient* client) {} | |
| 307 | |
| 308 // Called when either: | |
| 309 // - the TextInputClient is changed (e.g. by a change of focus) | |
| 310 // - the TextInputType of the TextInputClient changes | |
| 311 void BlimpEngineSession::OnTextInputStateChanged( | |
|
nyquist
2016/03/10 00:58:48
And this should hoepfully be tested as well.
| |
| 312 const ui::TextInputClient* client) { | |
|
Khushal
2016/03/10 07:54:10
The RenderWidgetHostView is also a text input clie
| |
| 313 ui::TextInputType type = | |
| 314 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | |
| 315 | |
| 316 // Hide IME if text input is out of focus | |
| 317 if (type == ui::TEXT_INPUT_TYPE_NONE) { | |
|
nyquist
2016/03/10 00:57:13
Nit: Braces are optional for single-line statement
| |
| 318 ShowIme(false); | |
| 319 } | |
| 320 } | |
| 321 | |
| 322 void BlimpEngineSession::OnInputMethodDestroyed( | |
| 323 const ui::InputMethod* input_method) {} | |
| 324 | |
| 325 // Called when a user input should trigger showing the IME. | |
| 326 void BlimpEngineSession::OnShowImeIfNeeded() { | |
| 327 ShowIme(true); | |
| 328 } | |
| 329 | |
| 330 void BlimpEngineSession::ShowIme(bool show) { | |
|
nyquist
2016/03/10 00:58:48
It feels like this should be tested.
| |
| 331 ImeMessage* ime_message; | |
| 332 scoped_ptr<BlimpMessage> blimp_message = CreateBlimpMessage(&ime_message); | |
|
David Trainor- moved to gerrit
2016/03/14 17:59:42
We probably also want to attach the tab id and the
shaktisahu
2016/03/15 23:44:13
Done.
| |
| 333 | |
| 334 ime_message->set_type(show ? ImeMessage::SHOW_IME : ImeMessage::HIDE_IME); | |
| 335 | |
| 336 ui::TextInputClient* client = | |
| 337 window_tree_host_->GetInputMethod()->GetTextInputClient(); | |
| 338 | |
| 339 gfx::Range text_range; | |
| 340 base::string16 existing_text; | |
| 341 client->GetTextRange(&text_range); | |
| 342 client->GetTextFromRange(text_range, &existing_text); | |
| 343 | |
| 344 ime_message->set_text_input_type(client->GetTextInputType()); | |
|
David Trainor- moved to gerrit
2016/03/14 17:59:42
We should pull this out to some protocol format an
shaktisahu
2016/03/15 23:44:13
Done.
| |
| 345 ime_message->set_ime_text(base::UTF16ToUTF8(existing_text)); | |
| 346 ime_message_sender_->ProcessMessage(std::move(blimp_message), | |
| 347 net::CompletionCallback()); | |
| 348 } | |
| 349 | |
| 292 void BlimpEngineSession::ProcessMessage( | 350 void BlimpEngineSession::ProcessMessage( |
| 293 scoped_ptr<BlimpMessage> message, | 351 scoped_ptr<BlimpMessage> message, |
| 294 const net::CompletionCallback& callback) { | 352 const net::CompletionCallback& callback) { |
| 295 DCHECK(!callback.is_null()); | 353 DCHECK(!callback.is_null()); |
| 296 DCHECK(message->type() == BlimpMessage::TAB_CONTROL || | 354 DCHECK(message->type() == BlimpMessage::TAB_CONTROL || |
| 297 message->type() == BlimpMessage::NAVIGATION); | 355 message->type() == BlimpMessage::NAVIGATION || |
| 356 message->type() == BlimpMessage::IME); | |
| 298 | 357 |
| 299 net::Error result = net::OK; | 358 net::Error result = net::OK; |
| 300 if (message->type() == BlimpMessage::TAB_CONTROL) { | 359 if (message->type() == BlimpMessage::TAB_CONTROL) { |
| 301 switch (message->tab_control().type()) { | 360 switch (message->tab_control().type()) { |
| 302 case TabControlMessage::CREATE_TAB: | 361 case TabControlMessage::CREATE_TAB: |
| 303 if (!CreateWebContents(message->target_tab_id())) | 362 if (!CreateWebContents(message->target_tab_id())) |
| 304 result = net::ERR_FAILED; | 363 result = net::ERR_FAILED; |
| 305 break; | 364 break; |
| 306 case TabControlMessage::CLOSE_TAB: | 365 case TabControlMessage::CLOSE_TAB: |
| 307 CloseWebContents(message->target_tab_id()); | 366 CloseWebContents(message->target_tab_id()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 326 case NavigationMessage::GO_FORWARD: | 385 case NavigationMessage::GO_FORWARD: |
| 327 GoForward(message->target_tab_id()); | 386 GoForward(message->target_tab_id()); |
| 328 break; | 387 break; |
| 329 case NavigationMessage::RELOAD: | 388 case NavigationMessage::RELOAD: |
| 330 Reload(message->target_tab_id()); | 389 Reload(message->target_tab_id()); |
| 331 break; | 390 break; |
| 332 default: | 391 default: |
| 333 NOTIMPLEMENTED(); | 392 NOTIMPLEMENTED(); |
| 334 result = net::ERR_NOT_IMPLEMENTED; | 393 result = net::ERR_NOT_IMPLEMENTED; |
| 335 } | 394 } |
| 395 } else if (message->type() == BlimpMessage::IME) { | |
|
nyquist
2016/03/10 00:58:48
And this should hopefully be tested?
| |
| 396 const ImeMessage& ime = message->ime(); | |
| 397 DCHECK(ime.type() == ImeMessage::SHOW_TEXT); | |
| 398 | |
| 399 ui::TextInputClient* client = | |
| 400 window_tree_host_->GetInputMethod()->GetTextInputClient(); | |
| 401 | |
| 402 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { | |
| 403 // Clear out any existing text first and | |
| 404 // then insert new text entered through IME. | |
| 405 gfx::Range text_range; | |
| 406 client->GetTextRange(&text_range); | |
| 407 client->ExtendSelectionAndDelete(text_range.length(), | |
| 408 text_range.length()); | |
| 409 | |
| 410 client->InsertText(base::UTF8ToUTF16(ime.ime_text())); | |
| 411 } | |
| 336 } else { | 412 } else { |
| 337 DVLOG(1) << "No WebContents for navigation control"; | 413 DVLOG(1) << "No WebContents for navigation control"; |
| 338 result = net::ERR_FAILED; | 414 result = net::ERR_FAILED; |
| 339 } | 415 } |
| 340 | 416 |
| 341 callback.Run(result); | 417 callback.Run(result); |
| 342 } | 418 } |
| 343 | 419 |
| 344 void BlimpEngineSession::AddNewContents(content::WebContents* source, | 420 void BlimpEngineSession::AddNewContents(content::WebContents* source, |
| 345 content::WebContents* new_contents, | 421 content::WebContents* new_contents, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 | 534 |
| 459 aura::Window* parent = window_tree_host_->window(); | 535 aura::Window* parent = window_tree_host_->window(); |
| 460 aura::Window* content = web_contents_->GetNativeView(); | 536 aura::Window* content = web_contents_->GetNativeView(); |
| 461 if (!parent->Contains(content)) | 537 if (!parent->Contains(content)) |
| 462 parent->AddChild(content); | 538 parent->AddChild(content); |
| 463 content->Show(); | 539 content->Show(); |
| 464 } | 540 } |
| 465 | 541 |
| 466 } // namespace engine | 542 } // namespace engine |
| 467 } // namespace blimp | 543 } // namespace blimp |
| OLD | NEW |