| 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 "blimp/common/proto/blimp_message.pb.h" | 7 #include "blimp/common/proto/blimp_message.pb.h" |
| 8 #include "blimp/common/proto/control.pb.h" | 8 #include "blimp/common/proto/control.pb.h" |
| 9 #include "blimp/engine/browser/blimp_browser_context.h" | 9 #include "blimp/engine/browser/blimp_browser_context.h" |
| 10 #include "blimp/engine/ui/blimp_layout_manager.h" | 10 #include "blimp/engine/ui/blimp_layout_manager.h" |
| 11 #include "blimp/engine/ui/blimp_screen.h" | 11 #include "blimp/engine/ui/blimp_screen.h" |
| 12 #include "blimp/engine/ui/blimp_ui_context_factory.h" | 12 #include "blimp/engine/ui/blimp_ui_context_factory.h" |
| 13 #include "blimp/net/blimp_connection.h" | 13 #include "blimp/net/blimp_connection.h" |
| 14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/browser/render_widget_host.h" | 18 #include "content/public/browser/render_widget_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "net/base/net_errors.h" |
| 20 #include "ui/aura/client/default_capture_client.h" | 21 #include "ui/aura/client/default_capture_client.h" |
| 21 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
| 22 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 23 #include "ui/aura/window_tree_host.h" | 24 #include "ui/aura/window_tree_host.h" |
| 24 #include "ui/wm/core/base_focus_rules.h" | 25 #include "ui/wm/core/base_focus_rules.h" |
| 25 #include "ui/wm/core/default_activation_client.h" | 26 #include "ui/wm/core/default_activation_client.h" |
| 26 #include "ui/wm/core/focus_controller.h" | 27 #include "ui/wm/core/focus_controller.h" |
| 27 | 28 |
| 28 #if !defined(USE_X11) | 29 #if !defined(USE_X11) |
| 29 #include "blimp/engine/ui/blimp_window_tree_host.h" | 30 #include "blimp/engine/ui/blimp_window_tree_host.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 void BlimpEngineSession::AttachClientConnection( | 90 void BlimpEngineSession::AttachClientConnection( |
| 90 scoped_ptr<BlimpConnection> client_connection) { | 91 scoped_ptr<BlimpConnection> client_connection) { |
| 91 DCHECK(client_connection); | 92 DCHECK(client_connection); |
| 92 client_connection_ = client_connection.Pass(); | 93 client_connection_ = client_connection.Pass(); |
| 93 | 94 |
| 94 // TODO(haibinlu): Remove this once we can use client connection to send in | 95 // TODO(haibinlu): Remove this once we can use client connection to send in |
| 95 // a navigation message. | 96 // a navigation message. |
| 96 BlimpMessage message; | 97 BlimpMessage message; |
| 97 message.set_type(BlimpMessage::CONTROL); | 98 message.set_type(BlimpMessage::CONTROL); |
| 98 message.mutable_control()->set_type(ControlMessage::CREATE_TAB); | 99 message.mutable_control()->set_type(ControlMessage::CREATE_TAB); |
| 99 OnBlimpMessage(message); | 100 ProcessMessage(message, net::CompletionCallback()); |
| 100 message.mutable_control()->set_type(ControlMessage::LOAD_URL); | 101 message.mutable_control()->set_type(ControlMessage::LOAD_URL); |
| 101 message.mutable_control()->mutable_load_url()->set_url( | 102 message.mutable_control()->mutable_load_url()->set_url( |
| 102 "https://www.google.com/"); | 103 "https://www.google.com/"); |
| 103 OnBlimpMessage(message); | 104 ProcessMessage(message, net::CompletionCallback()); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void BlimpEngineSession::CreateWebContents(const int target_tab_id) { | 107 void BlimpEngineSession::CreateWebContents(const int target_tab_id) { |
| 107 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). | 108 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). |
| 108 DCHECK(!web_contents_); | 109 DCHECK(!web_contents_); |
| 109 content::WebContents::CreateParams create_params(browser_context_.get(), | 110 content::WebContents::CreateParams create_params(browser_context_.get(), |
| 110 nullptr); | 111 nullptr); |
| 111 scoped_ptr<content::WebContents> new_contents = | 112 scoped_ptr<content::WebContents> new_contents = |
| 112 make_scoped_ptr(content::WebContents::Create(create_params)); | 113 make_scoped_ptr(content::WebContents::Create(create_params)); |
| 113 PlatformSetContents(new_contents.Pass()); | 114 PlatformSetContents(new_contents.Pass()); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { | 117 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { |
| 117 if (url.is_empty() || !web_contents_) | 118 if (url.is_empty() || !web_contents_) |
| 118 return; | 119 return; |
| 119 | 120 |
| 120 content::NavigationController::LoadURLParams params(url); | 121 content::NavigationController::LoadURLParams params(url); |
| 121 params.transition_type = ui::PageTransitionFromInt( | 122 params.transition_type = ui::PageTransitionFromInt( |
| 122 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 123 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 123 web_contents_->GetController().LoadURLWithParams(params); | 124 web_contents_->GetController().LoadURLWithParams(params); |
| 124 web_contents_->Focus(); | 125 web_contents_->Focus(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 net::Error BlimpEngineSession::OnBlimpMessage(const BlimpMessage& message) { | 128 void BlimpEngineSession::ProcessMessage( |
| 129 const BlimpMessage& message, |
| 130 const net::CompletionCallback& callback) { |
| 128 DCHECK(message.type() == BlimpMessage::CONTROL); | 131 DCHECK(message.type() == BlimpMessage::CONTROL); |
| 129 | 132 |
| 130 switch (message.control().type()) { | 133 switch (message.control().type()) { |
| 131 case ControlMessage::CREATE_TAB: | 134 case ControlMessage::CREATE_TAB: |
| 132 CreateWebContents(message.target_tab_id()); | 135 CreateWebContents(message.target_tab_id()); |
| 133 break; | 136 break; |
| 134 case ControlMessage::LOAD_URL: | 137 case ControlMessage::LOAD_URL: |
| 135 LoadUrl(message.target_tab_id(), | 138 LoadUrl(message.target_tab_id(), |
| 136 GURL(message.control().load_url().url())); | 139 GURL(message.control().load_url().url())); |
| 137 break; | 140 break; |
| 138 default: | 141 default: |
| 139 NOTIMPLEMENTED(); | 142 NOTIMPLEMENTED(); |
| 140 } | 143 } |
| 141 | 144 |
| 142 return net::OK; | 145 callback.Run(net::OK); |
| 143 } | 146 } |
| 144 | 147 |
| 145 void BlimpEngineSession::AddNewContents(content::WebContents* source, | 148 void BlimpEngineSession::AddNewContents(content::WebContents* source, |
| 146 content::WebContents* new_contents, | 149 content::WebContents* new_contents, |
| 147 WindowOpenDisposition disposition, | 150 WindowOpenDisposition disposition, |
| 148 const gfx::Rect& initial_rect, | 151 const gfx::Rect& initial_rect, |
| 149 bool user_gesture, | 152 bool user_gesture, |
| 150 bool* was_blocked) { | 153 bool* was_blocked) { |
| 151 NOTIMPLEMENTED(); | 154 NOTIMPLEMENTED(); |
| 152 } | 155 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 210 |
| 208 aura::Window* parent = window_tree_host_->window(); | 211 aura::Window* parent = window_tree_host_->window(); |
| 209 aura::Window* content = web_contents_->GetNativeView(); | 212 aura::Window* content = web_contents_->GetNativeView(); |
| 210 if (!parent->Contains(content)) | 213 if (!parent->Contains(content)) |
| 211 parent->AddChild(content); | 214 parent->AddChild(content); |
| 212 content->Show(); | 215 content->Show(); |
| 213 } | 216 } |
| 214 | 217 |
| 215 } // namespace engine | 218 } // namespace engine |
| 216 } // namespace blimp | 219 } // namespace blimp |
| OLD | NEW |