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/browser/blimp_engine_session.h" | 5 #include "blimp/engine/browser/blimp_engine_session.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "blimp/common/create_blimp_message.h" | 9 #include "blimp/common/create_blimp_message.h" |
| 10 #include "blimp/common/proto/blimp_message.pb.h" | 10 #include "blimp/common/proto/blimp_message.pb.h" |
| 11 #include "blimp/common/proto/tab_control.pb.h" | 11 #include "blimp/common/proto/tab_control.pb.h" |
| 12 #include "blimp/engine/browser/blimp_browser_context.h" | 12 #include "blimp/engine/browser/blimp_browser_context.h" |
| 13 #include "blimp/engine/ui/blimp_layout_manager.h" | 13 #include "blimp/engine/ui/blimp_layout_manager.h" |
| 14 #include "blimp/engine/ui/blimp_screen.h" | 14 #include "blimp/engine/ui/blimp_screen.h" |
| 15 #include "blimp/engine/ui/blimp_ui_context_factory.h" | 15 #include "blimp/engine/ui/blimp_ui_context_factory.h" |
| 16 #include "blimp/net/blimp_connection.h" | 16 #include "blimp/net/blimp_connection.h" |
| 17 #include "blimp/net/blimp_message_multiplexer.h" | 17 #include "blimp/net/blimp_message_multiplexer.h" |
| 18 #include "blimp/net/browser_connection_handler.h" | 18 #include "blimp/net/browser_connection_handler.h" |
| 19 #include "blimp/net/common.h" | |
| 19 #include "blimp/net/engine_authentication_handler.h" | 20 #include "blimp/net/engine_authentication_handler.h" |
| 20 #include "blimp/net/engine_connection_manager.h" | 21 #include "blimp/net/engine_connection_manager.h" |
| 21 #include "blimp/net/null_blimp_message_processor.h" | 22 #include "blimp/net/null_blimp_message_processor.h" |
| 22 #include "blimp/net/tcp_engine_transport.h" | 23 #include "blimp/net/tcp_engine_transport.h" |
| 23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/navigation_controller.h" | 26 #include "content/public/browser/navigation_controller.h" |
| 26 #include "content/public/browser/navigation_entry.h" | 27 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/browser/render_widget_host.h" | 29 #include "content/public/browser/render_widget_host.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 namespace blimp { | 45 namespace blimp { |
| 45 namespace engine { | 46 namespace engine { |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 const int kDummyTabId = 0; | 49 const int kDummyTabId = 0; |
| 49 const float kDefaultScaleFactor = 1.f; | 50 const float kDefaultScaleFactor = 1.f; |
| 50 const int kDefaultDisplayWidth = 800; | 51 const int kDefaultDisplayWidth = 800; |
| 51 const int kDefaultDisplayHeight = 600; | 52 const int kDefaultDisplayHeight = 600; |
| 52 const uint16 kDefaultPortNumber = 25467; | |
| 53 | 53 |
| 54 base::LazyInstance<blimp::NullBlimpMessageProcessor> g_blimp_message_processor = | 54 base::LazyInstance<blimp::NullBlimpMessageProcessor> g_blimp_message_processor = |
| 55 LAZY_INSTANCE_INITIALIZER; | 55 LAZY_INSTANCE_INITIALIZER; |
| 56 | 56 |
| 57 // Focus rules that support activating an child window. | 57 // Focus rules that support activating an child window. |
| 58 class FocusRulesImpl : public wm::BaseFocusRules { | 58 class FocusRulesImpl : public wm::BaseFocusRules { |
| 59 public: | 59 public: |
| 60 FocusRulesImpl() {} | 60 FocusRulesImpl() {} |
| 61 ~FocusRulesImpl() override {} | 61 ~FocusRulesImpl() override {} |
| 62 | 62 |
| 63 bool SupportsChildActivation(aura::Window* window) const override { | 63 bool SupportsChildActivation(aura::Window* window) const override { |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); | 68 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 // This class's functions and destruction are all invoked on the IO thread by | |
| 74 // the BlimpEngineSession. | |
| 75 class BlimpNetworkComponents { | |
|
haibinlu
2015/12/29 00:51:45
per offline discussion, keep BlimpNetworkComponent
Kevin M
2015/12/30 23:08:49
Done.
| |
| 76 public: | |
| 77 explicit BlimpNetworkComponents(net::NetLog* net_log); | |
| 78 ~BlimpNetworkComponents(); | |
| 79 | |
| 80 void Initialize(); | |
| 81 | |
| 82 private: | |
| 83 net::NetLog* net_log_; | |
| 84 scoped_ptr<BrowserConnectionHandler> connection_handler_; | |
| 85 scoped_ptr<EngineAuthenticationHandler> authentication_handler_; | |
| 86 scoped_ptr<EngineConnectionManager> connection_manager_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(BlimpNetworkComponents); | |
| 89 }; | |
| 90 | |
| 91 BlimpNetworkComponents::BlimpNetworkComponents(net::NetLog* net_log) | |
| 92 : net_log_(net_log) {} | |
| 93 | |
| 94 BlimpNetworkComponents::~BlimpNetworkComponents() { | |
| 95 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 96 } | |
| 97 | |
| 98 void BlimpNetworkComponents::Initialize() { | |
| 99 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 100 DCHECK(!connection_handler_); | |
| 101 | |
| 102 // Creates and connects net components. | |
| 103 // A BlimpConnection flows from | |
| 104 // connection_manager_ --> authentication_handler_ --> connection_handler_ | |
| 105 connection_handler_.reset(new BrowserConnectionHandler); | |
| 106 authentication_handler_.reset( | |
| 107 new EngineAuthenticationHandler(connection_handler_.get())); | |
| 108 connection_manager_.reset( | |
| 109 new EngineConnectionManager(authentication_handler_.get())); | |
| 110 | |
| 111 // Adds BlimpTransports to connection_manager_. | |
| 112 net::IPAddressNumber local_ip_any; | |
| 113 bool success = net::ParseIPLiteralToNumber("0.0.0.0", &local_ip_any); | |
| 114 DCHECK(success); | |
| 115 net::IPEndPoint address(local_ip_any, kDefaultPortNumber); | |
| 116 connection_manager_->AddTransport( | |
| 117 make_scoped_ptr(new TCPEngineTransport(address, net_log_))); | |
| 118 } | |
| 119 | |
| 120 BlimpEngineSession::BlimpEngineSession( | 73 BlimpEngineSession::BlimpEngineSession( |
| 121 scoped_ptr<BlimpBrowserContext> browser_context, | 74 scoped_ptr<BlimpBrowserContext> browser_context, |
| 122 net::NetLog* net_log) | 75 net::NetLog* net_log) |
| 123 : browser_context_(std::move(browser_context)), | 76 : browser_context_(std::move(browser_context)), |
| 124 screen_(new BlimpScreen), | 77 screen_(new BlimpScreen), |
| 125 // TODO(dtrainor, haibinlu): Properly pull these from the BlimpMessageMux. | 78 // TODO(dtrainor, haibinlu): Properly pull these from the BlimpMessageMux. |
| 126 render_widget_processor_(g_blimp_message_processor.Pointer(), | 79 render_widget_processor_(g_blimp_message_processor.Pointer(), |
| 127 g_blimp_message_processor.Pointer()), | 80 g_blimp_message_processor.Pointer()), |
| 128 net_components_(new BlimpNetworkComponents(net_log)) { | 81 net_log_(net_log) { |
| 129 screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, | 82 screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, |
| 130 gfx::Size(kDefaultDisplayWidth, | 83 gfx::Size(kDefaultDisplayWidth, |
| 131 kDefaultDisplayHeight)); | 84 kDefaultDisplayHeight)); |
| 132 render_widget_processor_.SetDelegate(kDummyTabId, this); | 85 render_widget_processor_.SetDelegate(kDummyTabId, this); |
| 133 } | 86 } |
| 134 | 87 |
| 135 BlimpEngineSession::~BlimpEngineSession() { | 88 BlimpEngineSession::~BlimpEngineSession() { |
| 136 render_widget_processor_.RemoveDelegate(kDummyTabId); | 89 render_widget_processor_.RemoveDelegate(kDummyTabId); |
| 137 | 90 |
| 138 // Safely delete network components on the IO thread. | 91 // Safely delete network components on the IO thread. |
| 139 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 92 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
| 140 net_components_.release()); | 93 connection_handler_.release()); |
| 94 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | |
| 95 authentication_handler_.release()); | |
| 96 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | |
| 97 connection_manager_.release()); | |
| 141 } | 98 } |
| 142 | 99 |
| 143 void BlimpEngineSession::Initialize() { | 100 void BlimpEngineSession::Initialize() { |
| 144 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); | 101 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); |
| 145 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 102 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
| 146 | 103 |
| 147 #if defined(USE_X11) | 104 #if defined(USE_X11) |
| 148 window_tree_host_.reset(aura::WindowTreeHost::Create( | 105 window_tree_host_.reset(aura::WindowTreeHost::Create( |
| 149 gfx::Rect(screen_->GetPrimaryDisplay().size()))); | 106 gfx::Rect(screen_->GetPrimaryDisplay().size()))); |
| 150 #else | 107 #else |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 165 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 122 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
| 166 | 123 |
| 167 #if defined(USE_X11) | 124 #if defined(USE_X11) |
| 168 window_tree_host_->Show(); | 125 window_tree_host_->Show(); |
| 169 #endif | 126 #endif |
| 170 | 127 |
| 171 window_tree_host_->SetBounds(gfx::Rect(screen_->GetPrimaryDisplay().size())); | 128 window_tree_host_->SetBounds(gfx::Rect(screen_->GetPrimaryDisplay().size())); |
| 172 | 129 |
| 173 content::BrowserThread::PostTask( | 130 content::BrowserThread::PostTask( |
| 174 content::BrowserThread::IO, FROM_HERE, | 131 content::BrowserThread::IO, FROM_HERE, |
| 175 base::Bind(&BlimpNetworkComponents::Initialize, | 132 base::Bind(&BlimpEngineSession::InitializeNetwork, |
| 176 base::Unretained(net_components_.get()))); | 133 base::Unretained(this))); |
| 177 } | 134 } |
| 178 | 135 |
| 179 void BlimpEngineSession::CreateWebContents(const int target_tab_id) { | 136 void BlimpEngineSession::CreateWebContents(const int target_tab_id) { |
| 180 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). | 137 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). |
| 181 DCHECK(!web_contents_); | 138 DCHECK(!web_contents_); |
| 182 content::WebContents::CreateParams create_params(browser_context_.get(), | 139 content::WebContents::CreateParams create_params(browser_context_.get(), |
| 183 nullptr); | 140 nullptr); |
| 184 scoped_ptr<content::WebContents> new_contents = | 141 scoped_ptr<content::WebContents> new_contents = |
| 185 make_scoped_ptr(content::WebContents::Create(create_params)); | 142 make_scoped_ptr(content::WebContents::Create(create_params)); |
| 186 PlatformSetContents(std::move(new_contents)); | 143 PlatformSetContents(std::move(new_contents)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 // Make sure we actually have a valid RenderWidgetHost. | 211 // Make sure we actually have a valid RenderWidgetHost. |
| 255 if (!host) | 212 if (!host) |
| 256 return; | 213 return; |
| 257 | 214 |
| 258 host->HandleCompositorProto(message); | 215 host->HandleCompositorProto(message); |
| 259 } | 216 } |
| 260 | 217 |
| 261 void BlimpEngineSession::ProcessMessage( | 218 void BlimpEngineSession::ProcessMessage( |
| 262 scoped_ptr<BlimpMessage> message, | 219 scoped_ptr<BlimpMessage> message, |
| 263 const net::CompletionCallback& callback) { | 220 const net::CompletionCallback& callback) { |
| 221 DVLOG(2) << "BlimpEngineSession: ProcessMessage"; | |
| 264 DCHECK(message->type() == BlimpMessage::TAB_CONTROL || | 222 DCHECK(message->type() == BlimpMessage::TAB_CONTROL || |
| 265 message->type() == BlimpMessage::NAVIGATION); | 223 message->type() == BlimpMessage::NAVIGATION); |
| 266 | 224 |
| 267 if (message->type() == BlimpMessage::TAB_CONTROL) { | 225 if (message->type() == BlimpMessage::TAB_CONTROL) { |
| 268 switch (message->tab_control().type()) { | 226 switch (message->tab_control().type()) { |
| 269 case TabControlMessage::CREATE_TAB: | 227 case TabControlMessage::CREATE_TAB: |
| 270 CreateWebContents(message->target_tab_id()); | 228 CreateWebContents(message->target_tab_id()); |
| 271 break; | 229 break; |
| 272 case TabControlMessage::CLOSE_TAB: | 230 case TabControlMessage::CLOSE_TAB: |
| 273 CloseWebContents(message->target_tab_id()); | 231 CloseWebContents(message->target_tab_id()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 297 default: | 255 default: |
| 298 NOTIMPLEMENTED(); | 256 NOTIMPLEMENTED(); |
| 299 } | 257 } |
| 300 } | 258 } |
| 301 | 259 |
| 302 if (!callback.is_null()) { | 260 if (!callback.is_null()) { |
| 303 callback.Run(net::OK); | 261 callback.Run(net::OK); |
| 304 } | 262 } |
| 305 } | 263 } |
| 306 | 264 |
| 265 void BlimpEngineSession::InitializeNetwork() { | |
| 266 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 267 DCHECK(!connection_handler_); | |
| 268 | |
| 269 // Create a handler chain for BlimpConnections. | |
| 270 // Newly connected BlimpConnections are passed from | |
| 271 // connection_manager_ --> authentication_handler_ --> connection_handler_. | |
| 272 connection_handler_.reset(new BrowserConnectionHandler); | |
| 273 authentication_handler_.reset( | |
| 274 new EngineAuthenticationHandler(connection_handler_.get())); | |
| 275 connection_manager_.reset( | |
| 276 new EngineConnectionManager(authentication_handler_.get())); | |
| 277 | |
| 278 // Adds BlimpTransports to connection_manager_. | |
| 279 // TODO(kmarshall): Take transport configuration from parameters. | |
| 280 net::IPAddressNumber local_ip_any; | |
| 281 bool success = net::ParseIPLiteralToNumber("0.0.0.0", &local_ip_any); | |
| 282 CHECK(success); | |
| 283 net::IPEndPoint address(local_ip_any, kDefaultTcpPort); | |
| 284 connection_manager_->AddTransport( | |
| 285 make_scoped_ptr(new TCPEngineTransport(address, net_log_))); | |
| 286 } | |
| 287 | |
| 307 void BlimpEngineSession::AddNewContents(content::WebContents* source, | 288 void BlimpEngineSession::AddNewContents(content::WebContents* source, |
| 308 content::WebContents* new_contents, | 289 content::WebContents* new_contents, |
| 309 WindowOpenDisposition disposition, | 290 WindowOpenDisposition disposition, |
| 310 const gfx::Rect& initial_rect, | 291 const gfx::Rect& initial_rect, |
| 311 bool user_gesture, | 292 bool user_gesture, |
| 312 bool* was_blocked) { | 293 bool* was_blocked) { |
| 313 NOTIMPLEMENTED(); | 294 NOTIMPLEMENTED(); |
| 314 } | 295 } |
| 315 | 296 |
| 316 content::WebContents* BlimpEngineSession::OpenURLFromTab( | 297 content::WebContents* BlimpEngineSession::OpenURLFromTab( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 | 397 |
| 417 aura::Window* parent = window_tree_host_->window(); | 398 aura::Window* parent = window_tree_host_->window(); |
| 418 aura::Window* content = web_contents_->GetNativeView(); | 399 aura::Window* content = web_contents_->GetNativeView(); |
| 419 if (!parent->Contains(content)) | 400 if (!parent->Contains(content)) |
| 420 parent->AddChild(content); | 401 parent->AddChild(content); |
| 421 content->Show(); | 402 content->Show(); |
| 422 } | 403 } |
| 423 | 404 |
| 424 } // namespace engine | 405 } // namespace engine |
| 425 } // namespace blimp | 406 } // namespace blimp |
| OLD | NEW |