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 "blimp/common/proto/blimp_message.pb.h" | 8 #include "blimp/common/proto/blimp_message.pb.h" |
8 #include "blimp/common/proto/control.pb.h" | 9 #include "blimp/common/proto/control.pb.h" |
9 #include "blimp/engine/browser/blimp_browser_context.h" | 10 #include "blimp/engine/browser/blimp_browser_context.h" |
10 #include "blimp/engine/ui/blimp_layout_manager.h" | 11 #include "blimp/engine/ui/blimp_layout_manager.h" |
11 #include "blimp/engine/ui/blimp_screen.h" | 12 #include "blimp/engine/ui/blimp_screen.h" |
12 #include "blimp/engine/ui/blimp_ui_context_factory.h" | 13 #include "blimp/engine/ui/blimp_ui_context_factory.h" |
14 #include "blimp/net/black_hole_blimp_message_processor.h" | |
13 #include "blimp/net/blimp_connection.h" | 15 #include "blimp/net/blimp_connection.h" |
14 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
15 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/render_widget_host.h" | 20 #include "content/public/browser/render_widget_host.h" |
19 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
20 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
21 #include "ui/aura/client/default_capture_client.h" | 23 #include "ui/aura/client/default_capture_client.h" |
22 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
23 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
24 #include "ui/aura/window_tree_host.h" | 26 #include "ui/aura/window_tree_host.h" |
27 #include "ui/gfx/geometry/size.h" | |
25 #include "ui/wm/core/base_focus_rules.h" | 28 #include "ui/wm/core/base_focus_rules.h" |
26 #include "ui/wm/core/default_activation_client.h" | 29 #include "ui/wm/core/default_activation_client.h" |
27 #include "ui/wm/core/focus_controller.h" | 30 #include "ui/wm/core/focus_controller.h" |
28 | 31 |
29 #if !defined(USE_X11) | 32 #if !defined(USE_X11) |
30 #include "blimp/engine/ui/blimp_window_tree_host.h" | 33 #include "blimp/engine/ui/blimp_window_tree_host.h" |
31 #endif | 34 #endif |
32 | 35 |
33 namespace blimp { | 36 namespace blimp { |
34 namespace engine { | 37 namespace engine { |
35 namespace { | 38 namespace { |
36 | 39 |
40 const int kDummyTabId = 0; | |
41 | |
42 base::LazyInstance<blimp::BlackHoleBlimpMessageProcessor> | |
43 g_black_hole_message_processor = LAZY_INSTANCE_INITIALIZER; | |
44 | |
37 // Focus rules that support activating an child window. | 45 // Focus rules that support activating an child window. |
38 class FocusRulesImpl : public wm::BaseFocusRules { | 46 class FocusRulesImpl : public wm::BaseFocusRules { |
39 public: | 47 public: |
40 FocusRulesImpl() {} | 48 FocusRulesImpl() {} |
41 ~FocusRulesImpl() override {} | 49 ~FocusRulesImpl() override {} |
42 | 50 |
43 bool SupportsChildActivation(aura::Window* window) const override { | 51 bool SupportsChildActivation(aura::Window* window) const override { |
44 return true; | 52 return true; |
45 } | 53 } |
46 | 54 |
47 private: | 55 private: |
48 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); | 56 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); |
49 }; | 57 }; |
50 | 58 |
51 } // namespace | 59 } // namespace |
52 | 60 |
53 BlimpEngineSession::BlimpEngineSession( | 61 BlimpEngineSession::BlimpEngineSession( |
54 scoped_ptr<BlimpBrowserContext> browser_context) | 62 scoped_ptr<BlimpBrowserContext> browser_context) |
55 : browser_context_(browser_context.Pass()), screen_(new BlimpScreen) {} | 63 : browser_context_(browser_context.Pass()), |
64 screen_(new BlimpScreen), | |
65 render_widget_processor_(g_black_hole_message_processor.Pointer()) { | |
Kevin M
2015/11/24 18:39:59
What's the purpose of this? Why not attach to a Mu
David Trainor- moved to gerrit
2015/11/25 17:56:42
Once we have a valid BlimpMessageMultiplexer I can
| |
66 render_widget_processor_.SetDelegate(kDummyTabId, this); | |
67 } | |
56 | 68 |
57 BlimpEngineSession::~BlimpEngineSession() {} | 69 BlimpEngineSession::~BlimpEngineSession() { |
70 render_widget_processor_.RemoveDelegate(kDummyTabId); | |
71 } | |
58 | 72 |
59 void BlimpEngineSession::Initialize() { | 73 void BlimpEngineSession::Initialize() { |
60 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); | 74 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); |
61 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 75 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
62 | 76 |
63 #if defined(USE_X11) | 77 #if defined(USE_X11) |
64 window_tree_host_.reset(aura::WindowTreeHost::Create( | 78 window_tree_host_.reset(aura::WindowTreeHost::Create( |
65 gfx::Rect(screen_->GetPrimaryDisplay().size()))); | 79 gfx::Rect(screen_->GetPrimaryDisplay().size()))); |
66 #else | 80 #else |
67 context_factory_.reset(new BlimpUiContextFactory()); | 81 context_factory_.reset(new BlimpUiContextFactory()); |
(...skipping 27 matching lines...) Expand all Loading... | |
95 scoped_ptr<content::WebContents> new_contents = | 109 scoped_ptr<content::WebContents> new_contents = |
96 make_scoped_ptr(content::WebContents::Create(create_params)); | 110 make_scoped_ptr(content::WebContents::Create(create_params)); |
97 PlatformSetContents(new_contents.Pass()); | 111 PlatformSetContents(new_contents.Pass()); |
98 } | 112 } |
99 | 113 |
100 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { | 114 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { |
101 DCHECK(web_contents_); | 115 DCHECK(web_contents_); |
102 web_contents_->Close(); | 116 web_contents_->Close(); |
103 } | 117 } |
104 | 118 |
119 void BlimpEngineSession::HandleResize(const gfx::Size& size) { | |
120 // TODO(dtrainor, haibinlu): Set the proper size on the WebContents/save for | |
121 // future WebContents objects. | |
122 } | |
123 | |
105 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { | 124 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { |
106 if (url.is_empty() || !web_contents_) | 125 if (url.is_empty() || !web_contents_) |
107 return; | 126 return; |
108 | 127 |
109 content::NavigationController::LoadURLParams params(url); | 128 content::NavigationController::LoadURLParams params(url); |
110 params.transition_type = ui::PageTransitionFromInt( | 129 params.transition_type = ui::PageTransitionFromInt( |
111 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 130 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
112 web_contents_->GetController().LoadURLWithParams(params); | 131 web_contents_->GetController().LoadURLWithParams(params); |
113 web_contents_->Focus(); | 132 web_contents_->Focus(); |
114 } | 133 } |
(...skipping 12 matching lines...) Expand all Loading... | |
127 web_contents_->GetController().GoForward(); | 146 web_contents_->GetController().GoForward(); |
128 } | 147 } |
129 | 148 |
130 void BlimpEngineSession::Reload(const int target_tab_id) { | 149 void BlimpEngineSession::Reload(const int target_tab_id) { |
131 if (!web_contents_) | 150 if (!web_contents_) |
132 return; | 151 return; |
133 | 152 |
134 web_contents_->GetController().Reload(true); | 153 web_contents_->GetController().Reload(true); |
135 } | 154 } |
136 | 155 |
156 void BlimpEngineSession::OnWebInputEvent( | |
157 scoped_ptr<blink::WebInputEvent> event) { | |
158 if (!web_contents_ || !web_contents_->GetRenderViewHost()) | |
159 return; | |
160 | |
161 // TODO(dtrainor): Send the input event directly to the render process? | |
162 } | |
163 | |
164 void BlimpEngineSession::OnCompositorMessageReceived( | |
165 const std::vector<uint8_t>& message) { | |
166 // Make sure that We actually have a valid WebContents and RenderViewHost. | |
167 if (!web_contents_ || !web_contents_->GetRenderViewHost()) | |
168 return; | |
169 | |
170 content::RenderWidgetHost* host = | |
171 web_contents_->GetRenderViewHost()->GetWidget(); | |
172 | |
173 // Make sure we actually have a valid RenderWidgetHost. | |
174 if (!host) | |
175 return; | |
176 | |
177 host->HandleCompositorProto(message); | |
178 } | |
179 | |
137 void BlimpEngineSession::ProcessMessage( | 180 void BlimpEngineSession::ProcessMessage( |
138 scoped_ptr<BlimpMessage> message, | 181 scoped_ptr<BlimpMessage> message, |
139 const net::CompletionCallback& callback) { | 182 const net::CompletionCallback& callback) { |
140 DCHECK(message->type() == BlimpMessage::CONTROL || | 183 DCHECK(message->type() == BlimpMessage::CONTROL || |
141 message->type() == BlimpMessage::NAVIGATION || | 184 message->type() == BlimpMessage::NAVIGATION); |
142 message->type() == BlimpMessage::COMPOSITOR); | |
143 | 185 |
144 if (message->type() == BlimpMessage::CONTROL) { | 186 if (message->type() == BlimpMessage::CONTROL) { |
145 switch (message->control().type()) { | 187 switch (message->control().type()) { |
146 case ControlMessage::CREATE_TAB: | 188 case ControlMessage::CREATE_TAB: |
147 CreateWebContents(message->target_tab_id()); | 189 CreateWebContents(message->target_tab_id()); |
148 break; | 190 break; |
149 case ControlMessage::CLOSE_TAB: | 191 case ControlMessage::CLOSE_TAB: |
150 CloseWebContents(message->target_tab_id()); | 192 CloseWebContents(message->target_tab_id()); |
193 case ControlMessage::SIZE: | |
194 HandleResize(gfx::Size(message->control().resize().width(), | |
195 message->control().resize().height())); | |
196 break; | |
151 default: | 197 default: |
152 NOTIMPLEMENTED(); | 198 NOTIMPLEMENTED(); |
153 } | 199 } |
154 } else if (message->type() == BlimpMessage::NAVIGATION && web_contents_) { | 200 } else if (message->type() == BlimpMessage::NAVIGATION && web_contents_) { |
155 switch (message->navigation().type()) { | 201 switch (message->navigation().type()) { |
156 case NavigationMessage::LOAD_URL: | 202 case NavigationMessage::LOAD_URL: |
157 LoadUrl(message->target_tab_id(), | 203 LoadUrl(message->target_tab_id(), |
158 GURL(message->navigation().load_url().url())); | 204 GURL(message->navigation().load_url().url())); |
159 break; | 205 break; |
160 case NavigationMessage::GO_BACK: | 206 case NavigationMessage::GO_BACK: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 return source; | 265 return source; |
220 } | 266 } |
221 | 267 |
222 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, | 268 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, |
223 bool user_gesture, | 269 bool user_gesture, |
224 bool last_unlocked_by_target) { | 270 bool last_unlocked_by_target) { |
225 web_contents->GotResponseToLockMouseRequest(true); | 271 web_contents->GotResponseToLockMouseRequest(true); |
226 } | 272 } |
227 | 273 |
228 void BlimpEngineSession::CloseContents(content::WebContents* source) { | 274 void BlimpEngineSession::CloseContents(content::WebContents* source) { |
229 if (source == web_contents_.get()) | 275 if (source == web_contents_.get()) { |
276 Observe(nullptr); | |
230 web_contents_.reset(); | 277 web_contents_.reset(); |
278 } | |
231 } | 279 } |
232 | 280 |
233 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { | 281 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { |
234 contents->GetRenderViewHost()->GetWidget()->Focus(); | 282 contents->GetRenderViewHost()->GetWidget()->Focus(); |
235 } | 283 } |
236 | 284 |
237 void BlimpEngineSession::ForwardCompositorProto( | 285 void BlimpEngineSession::ForwardCompositorProto( |
238 const std::vector<uint8_t>& proto) { | 286 const std::vector<uint8_t>& proto) { |
239 // Send the compositor proto over the network layer to the client, which will | 287 render_widget_processor_.SendCompositorMessage(kDummyTabId, proto); |
240 // apply the proto to their local compositor instance. | 288 } |
241 // TODO(dtrainor): Send the compositor proto. | 289 |
290 void BlimpEngineSession::RenderViewHostChanged( | |
291 content::RenderViewHost* old_host, | |
292 content::RenderViewHost* new_host) { | |
293 render_widget_processor_.OnRenderWidgetInitialized(kDummyTabId); | |
242 } | 294 } |
243 | 295 |
244 void BlimpEngineSession::PlatformSetContents( | 296 void BlimpEngineSession::PlatformSetContents( |
245 scoped_ptr<content::WebContents> new_contents) { | 297 scoped_ptr<content::WebContents> new_contents) { |
246 new_contents->SetDelegate(this); | 298 new_contents->SetDelegate(this); |
299 Observe(new_contents.get()); | |
247 web_contents_ = new_contents.Pass(); | 300 web_contents_ = new_contents.Pass(); |
248 | 301 |
249 aura::Window* parent = window_tree_host_->window(); | 302 aura::Window* parent = window_tree_host_->window(); |
250 aura::Window* content = web_contents_->GetNativeView(); | 303 aura::Window* content = web_contents_->GetNativeView(); |
251 if (!parent->Contains(content)) | 304 if (!parent->Contains(content)) |
252 parent->AddChild(content); | 305 parent->AddChild(content); |
253 content->Show(); | 306 content->Show(); |
254 } | 307 } |
255 | 308 |
256 } // namespace engine | 309 } // namespace engine |
257 } // namespace blimp | 310 } // namespace blimp |
OLD | NEW |