Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: blimp/engine/browser/blimp_engine_session.cc

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

Powered by Google App Engine
This is Rietveld 408576698