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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "blimp/common/create_blimp_message.h" | 15 #include "blimp/common/create_blimp_message.h" |
| 16 #include "blimp/common/proto/tab_control.pb.h" | 16 #include "blimp/common/proto/tab_control.pb.h" |
| 17 #include "blimp/engine/app/blimp_engine_config.h" | 17 #include "blimp/engine/app/blimp_engine_config.h" |
| 18 #include "blimp/engine/app/settings_manager.h" | 18 #include "blimp/engine/app/settings_manager.h" |
| 19 #include "blimp/engine/app/switches.h" | 19 #include "blimp/engine/app/switches.h" |
| 20 #include "blimp/engine/app/ui/blimp_layout_manager.h" | 20 #include "blimp/engine/app/ui/blimp_layout_manager.h" |
| 21 #include "blimp/engine/app/ui/blimp_screen.h" | 21 #include "blimp/engine/app/ui/blimp_screen.h" |
| 22 #include "blimp/engine/app/ui/blimp_window_tree_client.h" | 22 #include "blimp/engine/app/ui/blimp_window_tree_client.h" |
| 23 #include "blimp/engine/app/ui/blimp_window_tree_host.h" | 23 #include "blimp/engine/app/ui/blimp_window_tree_host.h" |
| 24 #include "blimp/engine/common/blimp_browser_context.h" | 24 #include "blimp/engine/common/blimp_browser_context.h" |
| 25 #include "blimp/engine/common/blimp_user_agent.h" | 25 #include "blimp/engine/common/blimp_user_agent.h" |
| 26 #include "blimp/engine/session/tab_blimp.h" | |
| 26 #include "blimp/net/blimp_connection.h" | 27 #include "blimp/net/blimp_connection.h" |
| 27 #include "blimp/net/blimp_connection_statistics.h" | 28 #include "blimp/net/blimp_connection_statistics.h" |
| 28 #include "blimp/net/blimp_message_multiplexer.h" | 29 #include "blimp/net/blimp_message_multiplexer.h" |
| 29 #include "blimp/net/blimp_message_thread_pipe.h" | 30 #include "blimp/net/blimp_message_thread_pipe.h" |
| 30 #include "blimp/net/browser_connection_handler.h" | 31 #include "blimp/net/browser_connection_handler.h" |
| 31 #include "blimp/net/common.h" | 32 #include "blimp/net/common.h" |
| 32 #include "blimp/net/engine_authentication_handler.h" | 33 #include "blimp/net/engine_authentication_handler.h" |
| 33 #include "blimp/net/engine_connection_manager.h" | 34 #include "blimp/net/engine_connection_manager.h" |
| 34 #include "blimp/net/null_blimp_message_processor.h" | 35 #include "blimp/net/null_blimp_message_processor.h" |
| 35 #include "blimp/net/tcp_engine_transport.h" | 36 #include "blimp/net/tcp_engine_transport.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 | 209 |
| 209 BlimpEngineSession::BlimpEngineSession( | 210 BlimpEngineSession::BlimpEngineSession( |
| 210 std::unique_ptr<BlimpBrowserContext> browser_context, | 211 std::unique_ptr<BlimpBrowserContext> browser_context, |
| 211 net::NetLog* net_log, | 212 net::NetLog* net_log, |
| 212 BlimpEngineConfig* engine_config, | 213 BlimpEngineConfig* engine_config, |
| 213 SettingsManager* settings_manager) | 214 SettingsManager* settings_manager) |
| 214 : screen_(new BlimpScreen), | 215 : screen_(new BlimpScreen), |
| 215 browser_context_(std::move(browser_context)), | 216 browser_context_(std::move(browser_context)), |
| 216 engine_config_(engine_config), | 217 engine_config_(engine_config), |
| 217 settings_manager_(settings_manager), | 218 settings_manager_(settings_manager), |
| 218 settings_feature_(settings_manager_), | 219 settings_feature_(new EngineSettingsFeature(settings_manager_)), |
| 219 render_widget_feature_(settings_manager_), | 220 render_widget_feature_(new EngineRenderWidgetFeature(settings_manager_)), |
| 220 net_components_( | 221 net_components_( |
| 221 new EngineNetworkComponents(net_log, | 222 new EngineNetworkComponents(net_log, |
| 222 QuitCurrentMessageLoopClosure())) { | 223 QuitCurrentMessageLoopClosure())) { |
| 223 DCHECK(engine_config_); | 224 DCHECK(engine_config_); |
| 224 DCHECK(settings_manager_); | 225 DCHECK(settings_manager_); |
| 225 screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, | 226 screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, |
| 226 gfx::Size(kDefaultDisplayWidth, | 227 gfx::Size(kDefaultDisplayWidth, |
| 227 kDefaultDisplayHeight)); | 228 kDefaultDisplayHeight)); |
| 228 render_widget_feature_.SetDelegate(kDummyTabId, this); | 229 render_widget_feature_->SetDelegate(kDummyTabId, this); |
| 229 } | 230 } |
| 230 | 231 |
| 231 BlimpEngineSession::~BlimpEngineSession() { | 232 BlimpEngineSession::~BlimpEngineSession() { |
| 232 render_widget_feature_.RemoveDelegate(kDummyTabId); | 233 render_widget_feature_->RemoveDelegate(kDummyTabId); |
| 233 | 234 |
| 234 window_tree_host_->GetInputMethod()->RemoveObserver(this); | 235 window_tree_host_->GetInputMethod()->RemoveObserver(this); |
| 235 | 236 |
| 236 page_load_tracker_.reset(); | |
| 237 | |
| 238 // Ensure that all WebContents are torn down first, since teardown will | 237 // Ensure that all WebContents are torn down first, since teardown will |
|
Kevin M
2016/06/02 18:38:50
Revise this comment?
haibinlu
2016/06/02 20:24:36
Done.
| |
| 239 // trigger RenderViewDeleted callbacks to their observers. | 238 // trigger RenderViewDeleted callbacks to their observers. |
| 240 web_contents_.reset(); | 239 tab_.reset(); |
| 241 | 240 |
| 242 // Safely delete network components on the IO thread. | 241 // Safely delete network components on the IO thread. |
| 243 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 242 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
| 244 net_components_.release()); | 243 net_components_.release()); |
| 245 } | 244 } |
| 246 | 245 |
| 247 void BlimpEngineSession::Initialize() { | 246 void BlimpEngineSession::Initialize() { |
| 248 DCHECK(!display::Screen::GetScreen()); | 247 DCHECK(!display::Screen::GetScreen()); |
| 249 display::Screen::SetScreenInstance(screen_.get()); | 248 display::Screen::SetScreenInstance(screen_.get()); |
| 250 | 249 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 thread_pipe_manager_.reset(new ThreadPipeManager( | 292 thread_pipe_manager_.reset(new ThreadPipeManager( |
| 294 content::BrowserThread::GetMessageLoopProxyForThread( | 293 content::BrowserThread::GetMessageLoopProxyForThread( |
| 295 content::BrowserThread::IO), | 294 content::BrowserThread::IO), |
| 296 net_components_->GetBrowserConnectionHandler())); | 295 net_components_->GetBrowserConnectionHandler())); |
| 297 | 296 |
| 298 // Register features' message senders and receivers. | 297 // Register features' message senders and receivers. |
| 299 tab_control_message_sender_ = | 298 tab_control_message_sender_ = |
| 300 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, this); | 299 thread_pipe_manager_->RegisterFeature(BlimpMessage::kTabControl, this); |
| 301 navigation_message_sender_ = | 300 navigation_message_sender_ = |
| 302 thread_pipe_manager_->RegisterFeature(BlimpMessage::kNavigation, this); | 301 thread_pipe_manager_->RegisterFeature(BlimpMessage::kNavigation, this); |
| 303 render_widget_feature_.set_render_widget_message_sender( | 302 render_widget_feature_->set_render_widget_message_sender( |
| 304 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, | 303 thread_pipe_manager_->RegisterFeature(BlimpMessage::kRenderWidget, |
| 305 &render_widget_feature_)); | 304 render_widget_feature_.get())); |
| 306 render_widget_feature_.set_input_message_sender( | 305 render_widget_feature_->set_input_message_sender( |
| 307 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, | 306 thread_pipe_manager_->RegisterFeature(BlimpMessage::kInput, |
| 308 &render_widget_feature_)); | 307 render_widget_feature_.get())); |
| 309 render_widget_feature_.set_compositor_message_sender( | 308 render_widget_feature_->set_compositor_message_sender( |
| 310 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, | 309 thread_pipe_manager_->RegisterFeature(BlimpMessage::kCompositor, |
| 311 &render_widget_feature_)); | 310 render_widget_feature_.get())); |
| 312 render_widget_feature_.set_ime_message_sender( | 311 render_widget_feature_->set_ime_message_sender( |
| 313 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, | 312 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, |
| 314 &render_widget_feature_)); | 313 render_widget_feature_.get())); |
| 315 | 314 |
| 316 // The Settings feature does not need an outgoing message processor, since we | 315 // The Settings feature does not need an outgoing message processor, since we |
| 317 // don't send any messages to the client right now. | 316 // don't send any messages to the client right now. |
| 318 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, | 317 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
| 319 &settings_feature_); | 318 settings_feature_.get()); |
| 320 } | 319 } |
| 321 | 320 |
| 322 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { | 321 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { |
|
Kevin M
2016/06/02 18:38:50
Why is this called CreateWebContents, when it crea
haibinlu
2016/06/02 20:24:36
Done.
| |
| 323 DVLOG(1) << "Create tab " << target_tab_id; | 322 DVLOG(1) << "Create tab " << target_tab_id; |
| 324 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). | 323 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). |
| 325 if (web_contents_) { | 324 if (tab_) { |
| 326 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; | 325 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; |
| 327 return false; | 326 return false; |
| 328 } | 327 } |
| 329 | 328 |
| 330 content::WebContents::CreateParams create_params(browser_context_.get(), | 329 content::WebContents::CreateParams create_params(browser_context_.get(), |
| 331 nullptr); | 330 nullptr); |
| 332 std::unique_ptr<content::WebContents> new_contents = | 331 std::unique_ptr<content::WebContents> new_contents = |
| 333 base::WrapUnique(content::WebContents::Create(create_params)); | 332 base::WrapUnique(content::WebContents::Create(create_params)); |
| 334 PlatformSetContents(std::move(new_contents)); | 333 PlatformSetContents(std::move(new_contents), target_tab_id); |
| 335 | |
| 336 // Transfer over the user agent override. The default user agent does not | |
| 337 // have client IO info. | |
| 338 web_contents_->SetUserAgentOverride(GetBlimpEngineUserAgent()); | |
| 339 | 334 |
| 340 return true; | 335 return true; |
| 341 } | 336 } |
| 342 | 337 |
| 343 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { | 338 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { |
| 344 DVLOG(1) << "Close tab " << target_tab_id; | 339 DVLOG(1) << "Close tab " << target_tab_id; |
| 345 DCHECK(web_contents_); | 340 DCHECK(tab_); |
| 346 web_contents_->Close(); | 341 tab_->Close(); |
| 347 } | 342 } |
| 348 | 343 |
| 349 void BlimpEngineSession::HandleResize(float device_pixel_ratio, | 344 void BlimpEngineSession::HandleResize(float device_pixel_ratio, |
| 350 const gfx::Size& size) { | 345 const gfx::Size& size) { |
| 351 DVLOG(1) << "Resize to " << size.ToString() << ", " << device_pixel_ratio; | 346 DVLOG(1) << "Resize to " << size.ToString() << ", " << device_pixel_ratio; |
| 352 screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); | 347 screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); |
| 353 window_tree_host_->SetBounds(gfx::Rect(size)); | 348 window_tree_host_->SetBounds(gfx::Rect(size)); |
| 354 if (web_contents_) { | 349 if (tab_) { |
| 355 const gfx::Size size_in_dips = screen_->GetPrimaryDisplay().bounds().size(); | 350 tab_->Resize(device_pixel_ratio, |
| 356 web_contents_->GetNativeView()->SetBounds(gfx::Rect(size_in_dips)); | 351 screen_->GetPrimaryDisplay().bounds().size()); |
| 357 } | |
| 358 | |
| 359 if (web_contents_ && web_contents_->GetRenderViewHost() && | |
| 360 web_contents_->GetRenderViewHost()->GetWidget()) { | |
| 361 web_contents_->GetRenderViewHost()->GetWidget()->WasResized(); | |
| 362 } | 352 } |
| 363 } | 353 } |
| 364 | 354 |
| 365 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { | 355 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { |
| 366 TRACE_EVENT1("blimp", "BlimpEngineSession::LoadUrl", "URL", url.spec()); | 356 tab_->LoadUrl(url); |
|
Kevin M
2016/06/02 18:38:50
Won't this segfault if tab_ is closed (and nulled)
haibinlu
2016/06/02 20:24:36
added check. we have been depending on client does
| |
| 367 DVLOG(1) << "Load URL " << url << " in tab " << target_tab_id; | |
| 368 if (!url.is_valid()) { | |
| 369 VLOG(1) << "Dropping invalid URL " << url; | |
| 370 return; | |
| 371 } | |
| 372 | |
| 373 // TODO(dtrainor, haibinlu): Fix up the URL with url_fixer.h. If that doesn't | |
| 374 // produce a valid spec() then try to build a search query? | |
| 375 content::NavigationController::LoadURLParams params(url); | |
| 376 params.transition_type = ui::PageTransitionFromInt( | |
| 377 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | |
| 378 params.override_user_agent = | |
| 379 content::NavigationController::UA_OVERRIDE_TRUE; | |
| 380 web_contents_->GetController().LoadURLWithParams(params); | |
| 381 web_contents_->Focus(); | |
| 382 } | 357 } |
| 383 | 358 |
| 384 void BlimpEngineSession::GoBack(const int target_tab_id) { | 359 void BlimpEngineSession::GoBack(const int target_tab_id) { |
| 385 DVLOG(1) << "Back in tab " << target_tab_id; | 360 tab_->GoBack(); |
| 386 web_contents_->GetController().GoBack(); | |
| 387 } | 361 } |
| 388 | 362 |
| 389 void BlimpEngineSession::GoForward(const int target_tab_id) { | 363 void BlimpEngineSession::GoForward(const int target_tab_id) { |
| 390 DVLOG(1) << "Forward in tab " << target_tab_id; | 364 tab_->GoForward(); |
| 391 web_contents_->GetController().GoForward(); | |
| 392 } | 365 } |
| 393 | 366 |
| 394 void BlimpEngineSession::Reload(const int target_tab_id) { | 367 void BlimpEngineSession::Reload(const int target_tab_id) { |
| 395 DVLOG(1) << "Reload in tab " << target_tab_id; | 368 tab_->Reload(); |
| 396 web_contents_->GetController().Reload(true); | |
| 397 } | 369 } |
| 398 | 370 |
| 399 void BlimpEngineSession::OnWebGestureEvent( | 371 void BlimpEngineSession::OnWebGestureEvent( |
| 400 content::RenderWidgetHost* render_widget_host, | 372 content::RenderWidgetHost* render_widget_host, |
| 401 std::unique_ptr<blink::WebGestureEvent> event) { | 373 std::unique_ptr<blink::WebGestureEvent> event) { |
| 402 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type", | 374 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type", |
| 403 event->type); | 375 event->type); |
| 404 render_widget_host->ForwardGestureEvent(*event); | 376 render_widget_host->ForwardGestureEvent(*event); |
| 405 } | 377 } |
| 406 | 378 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 420 void BlimpEngineSession::OnBlur() {} | 392 void BlimpEngineSession::OnBlur() {} |
| 421 | 393 |
| 422 void BlimpEngineSession::OnCaretBoundsChanged( | 394 void BlimpEngineSession::OnCaretBoundsChanged( |
| 423 const ui::TextInputClient* client) {} | 395 const ui::TextInputClient* client) {} |
| 424 | 396 |
| 425 // Called when either: | 397 // Called when either: |
| 426 // - the TextInputClient is changed (e.g. by a change of focus) | 398 // - the TextInputClient is changed (e.g. by a change of focus) |
| 427 // - the TextInputType of the TextInputClient changes | 399 // - the TextInputType of the TextInputClient changes |
| 428 void BlimpEngineSession::OnTextInputStateChanged( | 400 void BlimpEngineSession::OnTextInputStateChanged( |
| 429 const ui::TextInputClient* client) { | 401 const ui::TextInputClient* client) { |
| 430 if (!web_contents_->GetRenderWidgetHostView()) | 402 if (!tab_->web_contents()->GetRenderWidgetHostView()) |
| 431 return; | 403 return; |
| 432 | 404 |
| 433 ui::TextInputType type = | 405 ui::TextInputType type = |
| 434 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 406 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
| 435 | 407 |
| 436 // TODO(shaktisahu): Propagate the new type to the client. | 408 // TODO(shaktisahu): Propagate the new type to the client. |
| 437 // Hide IME, when text input is out of focus, i.e. if the text input type | 409 // Hide IME, when text input is out of focus, i.e. if the text input type |
| 438 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types, | 410 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types, |
| 439 // OnShowImeIfNeeded is used instead to send show IME request to client. | 411 // OnShowImeIfNeeded is used instead to send show IME request to client. |
| 440 if (type == ui::TEXT_INPUT_TYPE_NONE) | 412 if (type == ui::TEXT_INPUT_TYPE_NONE) |
| 441 render_widget_feature_.SendHideImeRequest( | 413 render_widget_feature_->SendHideImeRequest( |
| 442 kDummyTabId, | 414 kDummyTabId, |
| 443 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()); | 415 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost()); |
| 444 } | 416 } |
| 445 | 417 |
| 446 void BlimpEngineSession::OnInputMethodDestroyed( | 418 void BlimpEngineSession::OnInputMethodDestroyed( |
| 447 const ui::InputMethod* input_method) {} | 419 const ui::InputMethod* input_method) {} |
| 448 | 420 |
| 449 // Called when a user input should trigger showing the IME. | 421 // Called when a user input should trigger showing the IME. |
| 450 void BlimpEngineSession::OnShowImeIfNeeded() { | 422 void BlimpEngineSession::OnShowImeIfNeeded() { |
| 451 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); | 423 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); |
| 452 if (!web_contents_->GetRenderWidgetHostView() || | 424 if (!tab_->web_contents()->GetRenderWidgetHostView() || |
| 453 !window_tree_host_->GetInputMethod()->GetTextInputClient()) | 425 !window_tree_host_->GetInputMethod()->GetTextInputClient()) |
| 454 return; | 426 return; |
| 455 | 427 |
| 456 render_widget_feature_.SendShowImeRequest( | 428 render_widget_feature_->SendShowImeRequest( |
| 457 kDummyTabId, | 429 kDummyTabId, |
| 458 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(), | 430 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(), |
| 459 window_tree_host_->GetInputMethod()->GetTextInputClient()); | 431 window_tree_host_->GetInputMethod()->GetTextInputClient()); |
| 460 } | 432 } |
| 461 | 433 |
| 462 void BlimpEngineSession::ProcessMessage( | 434 void BlimpEngineSession::ProcessMessage( |
| 463 std::unique_ptr<BlimpMessage> message, | 435 std::unique_ptr<BlimpMessage> message, |
| 464 const net::CompletionCallback& callback) { | 436 const net::CompletionCallback& callback) { |
| 465 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", | 437 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", |
| 466 message->target_tab_id()); | 438 message->target_tab_id()); |
| 467 DCHECK(!callback.is_null()); | 439 DCHECK(!callback.is_null()); |
| 468 DCHECK(BlimpMessage::kTabControl == message->feature_case() || | 440 DCHECK(BlimpMessage::kTabControl == message->feature_case() || |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 479 CloseWebContents(message->target_tab_id()); | 451 CloseWebContents(message->target_tab_id()); |
| 480 case TabControlMessage::kSize: | 452 case TabControlMessage::kSize: |
| 481 HandleResize(message->tab_control().size().device_pixel_ratio(), | 453 HandleResize(message->tab_control().size().device_pixel_ratio(), |
| 482 gfx::Size(message->tab_control().size().width(), | 454 gfx::Size(message->tab_control().size().width(), |
| 483 message->tab_control().size().height())); | 455 message->tab_control().size().height())); |
| 484 break; | 456 break; |
| 485 default: | 457 default: |
| 486 NOTIMPLEMENTED(); | 458 NOTIMPLEMENTED(); |
| 487 result = net::ERR_NOT_IMPLEMENTED; | 459 result = net::ERR_NOT_IMPLEMENTED; |
| 488 } | 460 } |
| 489 } else if (message->has_navigation() && web_contents_) { | 461 } else if (message->has_navigation() && tab_) { |
| 490 switch (message->navigation().type()) { | 462 switch (message->navigation().type()) { |
| 491 case NavigationMessage::LOAD_URL: | 463 case NavigationMessage::LOAD_URL: |
| 492 LoadUrl(message->target_tab_id(), | 464 LoadUrl(message->target_tab_id(), |
| 493 GURL(message->navigation().load_url().url())); | 465 GURL(message->navigation().load_url().url())); |
| 494 break; | 466 break; |
| 495 case NavigationMessage::GO_BACK: | 467 case NavigationMessage::GO_BACK: |
| 496 GoBack(message->target_tab_id()); | 468 GoBack(message->target_tab_id()); |
| 497 break; | 469 break; |
| 498 case NavigationMessage::GO_FORWARD: | 470 case NavigationMessage::GO_FORWARD: |
| 499 GoForward(message->target_tab_id()); | 471 GoForward(message->target_tab_id()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 return source; | 520 return source; |
| 549 } | 521 } |
| 550 | 522 |
| 551 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, | 523 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, |
| 552 bool user_gesture, | 524 bool user_gesture, |
| 553 bool last_unlocked_by_target) { | 525 bool last_unlocked_by_target) { |
| 554 web_contents->GotResponseToLockMouseRequest(true); | 526 web_contents->GotResponseToLockMouseRequest(true); |
| 555 } | 527 } |
| 556 | 528 |
| 557 void BlimpEngineSession::CloseContents(content::WebContents* source) { | 529 void BlimpEngineSession::CloseContents(content::WebContents* source) { |
| 558 if (source == web_contents_.get()) { | 530 if (source == tab_->web_contents()) { |
| 559 Observe(nullptr); | 531 tab_.reset(); |
| 560 web_contents_.reset(); | |
| 561 } | 532 } |
| 562 } | 533 } |
| 563 | 534 |
| 564 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { | 535 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { |
| 565 contents->GetRenderViewHost()->GetWidget()->Focus(); | 536 contents->GetRenderViewHost()->GetWidget()->Focus(); |
| 566 } | 537 } |
| 567 | 538 |
| 568 void BlimpEngineSession::ForwardCompositorProto( | 539 void BlimpEngineSession::ForwardCompositorProto( |
| 569 content::RenderWidgetHost* render_widget_host, | 540 content::RenderWidgetHost* render_widget_host, |
| 570 const std::vector<uint8_t>& proto) { | 541 const std::vector<uint8_t>& proto) { |
| 571 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); | 542 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); |
| 572 render_widget_feature_.SendCompositorMessage(kDummyTabId, render_widget_host, | 543 render_widget_feature_->SendCompositorMessage(kDummyTabId, render_widget_host, |
| 573 proto); | 544 proto); |
| 574 } | 545 } |
| 575 | 546 |
| 576 void BlimpEngineSession::NavigationStateChanged( | 547 void BlimpEngineSession::NavigationStateChanged( |
| 577 content::WebContents* source, | 548 content::WebContents* source, |
| 578 content::InvalidateTypes changed_flags) { | 549 content::InvalidateTypes changed_flags) { |
| 579 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); | 550 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); |
| 580 if (source != web_contents_.get() || !changed_flags) | 551 if (source != tab_->web_contents() || !changed_flags) |
| 581 return; | 552 return; |
| 582 | 553 |
| 583 NavigationMessage* navigation_message; | 554 NavigationMessage* navigation_message; |
| 584 std::unique_ptr<BlimpMessage> message = | 555 std::unique_ptr<BlimpMessage> message = |
| 585 CreateBlimpMessage(&navigation_message, kDummyTabId); | 556 CreateBlimpMessage(&navigation_message, kDummyTabId); |
| 586 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | 557 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); |
| 587 NavigationStateChangeMessage* details = | 558 NavigationStateChangeMessage* details = |
| 588 navigation_message->mutable_navigation_state_changed(); | 559 navigation_message->mutable_navigation_state_changed(); |
| 589 | 560 |
| 590 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_URL) | 561 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_URL) |
| 591 details->set_url(source->GetURL().spec()); | 562 details->set_url(source->GetURL().spec()); |
| 592 | 563 |
| 593 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TAB) { | 564 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TAB) { |
| 594 // TODO(dtrainor): Serialize the favicon? crbug.com/597094. | 565 // TODO(dtrainor): Serialize the favicon? crbug.com/597094. |
| 595 DVLOG(3) << "Tab favicon changed"; | 566 DVLOG(3) << "Tab favicon changed"; |
| 596 } | 567 } |
| 597 | 568 |
| 598 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TITLE) | 569 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TITLE) |
| 599 details->set_title(base::UTF16ToUTF8(source->GetTitle())); | 570 details->set_title(base::UTF16ToUTF8(source->GetTitle())); |
| 600 | 571 |
| 601 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_LOAD) | 572 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_LOAD) |
| 602 details->set_loading(source->IsLoading()); | 573 details->set_loading(source->IsLoading()); |
| 603 | 574 |
| 604 navigation_message_sender_->ProcessMessage(std::move(message), | 575 navigation_message_sender_->ProcessMessage(std::move(message), |
| 605 net::CompletionCallback()); | 576 net::CompletionCallback()); |
| 606 } | 577 } |
| 607 | 578 |
| 608 void BlimpEngineSession::RenderViewCreated( | |
| 609 content::RenderViewHost* render_view_host) { | |
| 610 render_widget_feature_.OnRenderWidgetCreated(kDummyTabId, | |
| 611 render_view_host->GetWidget()); | |
| 612 } | |
| 613 | |
| 614 void BlimpEngineSession::RenderViewHostChanged( | |
| 615 content::RenderViewHost* old_host, | |
| 616 content::RenderViewHost* new_host) { | |
| 617 // Informs client that WebContents swaps its visible RenderViewHost with | |
| 618 // another one. | |
| 619 render_widget_feature_.OnRenderWidgetInitialized(kDummyTabId, | |
| 620 new_host->GetWidget()); | |
| 621 } | |
| 622 | |
| 623 void BlimpEngineSession::RenderViewDeleted( | |
| 624 content::RenderViewHost* render_view_host) { | |
| 625 render_widget_feature_.OnRenderWidgetDeleted(kDummyTabId, | |
| 626 render_view_host->GetWidget()); | |
| 627 } | |
| 628 | |
| 629 void BlimpEngineSession::SendPageLoadStatusUpdate(PageLoadStatus load_status) { | |
| 630 bool page_load_completed = false; | |
| 631 | |
| 632 switch (load_status) { | |
| 633 case PageLoadStatus::LOADING: | |
| 634 page_load_completed = false; | |
| 635 break; | |
| 636 case PageLoadStatus::LOADED: | |
| 637 page_load_completed = true; | |
| 638 break; | |
| 639 } | |
| 640 | |
| 641 NavigationMessage* navigation_message = nullptr; | |
| 642 std::unique_ptr<BlimpMessage> message = | |
| 643 CreateBlimpMessage(&navigation_message, kDummyTabId); | |
| 644 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | |
| 645 NavigationStateChangeMessage* details = | |
| 646 navigation_message->mutable_navigation_state_changed(); | |
| 647 details->set_page_load_completed(page_load_completed); | |
| 648 | |
| 649 navigation_message_sender_->ProcessMessage(std::move(message), | |
| 650 net::CompletionCallback()); | |
| 651 } | |
| 652 | |
| 653 void BlimpEngineSession::PlatformSetContents( | 579 void BlimpEngineSession::PlatformSetContents( |
|
Kevin M
2016/06/02 18:38:50
I don't see any other callers of this besides Crea
haibinlu
2016/06/02 20:24:37
AddNewContents will use it. But we have not implem
| |
| 654 std::unique_ptr<content::WebContents> new_contents) { | 580 std::unique_ptr<content::WebContents> new_contents, |
| 581 const int target_tab_id) { | |
| 655 new_contents->SetDelegate(this); | 582 new_contents->SetDelegate(this); |
| 656 Observe(new_contents.get()); | |
| 657 web_contents_ = std::move(new_contents); | |
| 658 | 583 |
| 659 page_load_tracker_.reset(new PageLoadTracker(web_contents_.get(), this)); | |
| 660 aura::Window* parent = window_tree_host_->window(); | 584 aura::Window* parent = window_tree_host_->window(); |
| 661 aura::Window* content = web_contents_->GetNativeView(); | 585 aura::Window* content = new_contents->GetNativeView(); |
| 662 if (!parent->Contains(content)) | 586 if (!parent->Contains(content)) |
|
Kevin M
2016/06/02 18:38:50
The WebContents and its view are brand new, is it
haibinlu
2016/06/02 20:24:36
that is the view hierarchy. WindowTreeHost is the
| |
| 663 parent->AddChild(content); | 587 parent->AddChild(content); |
| 664 content->Show(); | 588 content->Show(); |
| 589 | |
| 590 tab_ = base::WrapUnique(new TabBlimp(std::move(new_contents), target_tab_id, | |
| 591 render_widget_feature_.get(), | |
| 592 navigation_message_sender_.get())); | |
| 665 } | 593 } |
| 666 | 594 |
| 667 } // namespace engine | 595 } // namespace engine |
| 668 } // namespace blimp | 596 } // namespace blimp |
| OLD | NEW |