blob: ae3fe329d0b6c6fee8cf5632c39892648d3cdff6 [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
James Robinson1581cd62014-12-02 10:52:00 -08005#include "services/window_manager/window_manager_app.h"
James Robinson646469d2014-10-03 15:33:28 -07006
7#include "base/message_loop/message_loop.h"
8#include "base/stl_util.h"
John Abd-El-Maleked8d84d2014-10-23 14:27:08 -07009#include "mojo/converters/geometry/geometry_type_converters.h"
James Robinsone2ac7e82014-10-15 13:21:59 -070010#include "mojo/converters/input_events/input_events_type_converters.h"
James Robinson646469d2014-10-03 15:33:28 -070011#include "mojo/public/cpp/application/application_connection.h"
12#include "mojo/public/cpp/application/application_impl.h"
James Robinsonbaf71d32014-10-08 13:00:20 -070013#include "mojo/public/interfaces/application/shell.mojom.h"
Colin Blundellc4edbc72014-12-10 14:16:27 +010014#include "mojo/services/view_manager/public/cpp/view.h"
15#include "mojo/services/view_manager/public/cpp/view_manager.h"
Elliot Glaysherf88a2fb2014-12-16 11:09:36 -080016#include "services/window_manager/capture_controller.h"
James Robinson1581cd62014-12-02 10:52:00 -080017#include "services/window_manager/focus_controller.h"
18#include "services/window_manager/focus_rules.h"
Elliot Glaysherad08bd02015-01-20 12:18:28 -080019#include "services/window_manager/hit_test.h"
James Robinson1581cd62014-12-02 10:52:00 -080020#include "services/window_manager/view_event_dispatcher.h"
21#include "services/window_manager/view_target.h"
22#include "services/window_manager/view_targeter.h"
23#include "services/window_manager/window_manager_delegate.h"
James Robinson646469d2014-10-03 15:33:28 -070024
James Robinson489c8f12014-12-08 12:08:55 -080025using mojo::ApplicationConnection;
26using mojo::Id;
27using mojo::ServiceProvider;
28using mojo::View;
29using mojo::WindowManager;
30
31namespace window_manager {
James Robinson646469d2014-10-03 15:33:28 -070032
James Robinson646469d2014-10-03 15:33:28 -070033namespace {
34
Elliot Glaysher28b50b92014-11-10 17:06:49 -080035Id GetIdForView(View* view) {
36 return view ? view->id() : 0;
James Robinson646469d2014-10-03 15:33:28 -070037}
38
39} // namespace
40
Scott Violet5d674ef2014-10-22 15:52:54 -070041// Used for calls to Embed() that occur before we've connected to the
42// ViewManager.
43struct WindowManagerApp::PendingEmbed {
James Robinson489c8f12014-12-08 12:08:55 -080044 mojo::String url;
James Robinson3b679672015-01-21 18:36:01 -080045 mojo::InterfaceRequest<ServiceProvider> services;
46 mojo::ServiceProviderPtr exposed_services;
Scott Violet5d674ef2014-10-22 15:52:54 -070047};
48
James Robinson646469d2014-10-03 15:33:28 -070049////////////////////////////////////////////////////////////////////////////////
50// WindowManagerApp, public:
51
52WindowManagerApp::WindowManagerApp(
53 ViewManagerDelegate* view_manager_delegate,
54 WindowManagerDelegate* window_manager_delegate)
James Robinsonbaf71d32014-10-08 13:00:20 -070055 : shell_(nullptr),
James Robinson646469d2014-10-03 15:33:28 -070056 wrapped_view_manager_delegate_(view_manager_delegate),
James Robinsone2ac7e82014-10-15 13:21:59 -070057 window_manager_delegate_(window_manager_delegate),
Michael Wassermanbae17942015-01-14 20:33:10 -080058 root_(nullptr) {
James Robinson646469d2014-10-03 15:33:28 -070059}
60
Eric Seidel3f1157b2014-11-05 13:09:08 -080061WindowManagerApp::~WindowManagerApp() {
Michael Wasserman93d013c2015-01-14 20:22:36 -080062 // TODO(msw|sky): Should this destructor explicitly delete the ViewManager?
63 mojo::ViewManager* cached_view_manager = view_manager();
64 for (RegisteredViewIdSet::const_iterator it = registered_view_id_set_.begin();
65 cached_view_manager && it != registered_view_id_set_.end(); ++it) {
66 View* view = cached_view_manager->GetViewById(*it);
67 if (view && view == root_)
68 root_ = nullptr;
69 if (view)
70 view->RemoveObserver(this);
71 }
72 registered_view_id_set_.clear();
73 DCHECK(!root_);
74
Eric Seidel3f1157b2014-11-05 13:09:08 -080075 STLDeleteElements(&connections_);
76}
James Robinson646469d2014-10-03 15:33:28 -070077
Scott Violet37e9aea2014-10-31 15:06:04 -070078void WindowManagerApp::AddConnection(WindowManagerImpl* connection) {
James Robinson646469d2014-10-03 15:33:28 -070079 DCHECK(connections_.find(connection) == connections_.end());
80 connections_.insert(connection);
81}
82
Scott Violet37e9aea2014-10-31 15:06:04 -070083void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) {
James Robinson646469d2014-10-03 15:33:28 -070084 DCHECK(connections_.find(connection) != connections_.end());
85 connections_.erase(connection);
86}
87
Scott Violet695598e2015-02-07 08:36:14 -080088bool WindowManagerApp::SetCapture(Id view_id) {
Scott Violet92643b52014-12-18 14:35:42 -080089 View* view = view_manager()->GetViewById(view_id);
Scott Violet6edabbf2015-02-25 16:02:50 -080090 return view && SetCaptureImpl(view);
James Robinson646469d2014-10-03 15:33:28 -070091}
92
Scott Violet695598e2015-02-07 08:36:14 -080093bool WindowManagerApp::FocusWindow(Id view_id) {
Scott Violet92643b52014-12-18 14:35:42 -080094 View* view = view_manager()->GetViewById(view_id);
Scott Violet6edabbf2015-02-25 16:02:50 -080095 return view && FocusWindowImpl(view);
James Robinson646469d2014-10-03 15:33:28 -070096}
97
Scott Violet695598e2015-02-07 08:36:14 -080098bool WindowManagerApp::ActivateWindow(Id view_id) {
Scott Violet92643b52014-12-18 14:35:42 -080099 View* view = view_manager()->GetViewById(view_id);
Scott Violet6edabbf2015-02-25 16:02:50 -0800100 return view && ActivateWindowImpl(view);
James Robinson646469d2014-10-03 15:33:28 -0700101}
102
103bool WindowManagerApp::IsReady() const {
Scott Violet92643b52014-12-18 14:35:42 -0800104 return root_;
James Robinson646469d2014-10-03 15:33:28 -0700105}
106
James Robinson489c8f12014-12-08 12:08:55 -0800107void WindowManagerApp::InitFocus(scoped_ptr<FocusRules> rules) {
Elliot Glaysherf88a2fb2014-12-16 11:09:36 -0800108 DCHECK(root_);
109
James Robinson489c8f12014-12-08 12:08:55 -0800110 focus_controller_.reset(new FocusController(rules.Pass()));
Elliot Glaysher28b50b92014-11-10 17:06:49 -0800111 focus_controller_->AddObserver(this);
Elliot Glayshere28eebf2014-11-19 10:39:24 -0800112 SetFocusController(root_, focus_controller_.get());
Elliot Glaysherf88a2fb2014-12-16 11:09:36 -0800113
114 capture_controller_.reset(new CaptureController);
115 capture_controller_->AddObserver(this);
116 SetCaptureController(root_, capture_controller_.get());
James Robinson646469d2014-10-03 15:33:28 -0700117}
118
Scott Violet5d674ef2014-10-22 15:52:54 -0700119void WindowManagerApp::Embed(
James Robinson489c8f12014-12-08 12:08:55 -0800120 const mojo::String& url,
James Robinson3b679672015-01-21 18:36:01 -0800121 mojo::InterfaceRequest<mojo::ServiceProvider> services,
122 mojo::ServiceProviderPtr exposed_services) {
Scott Violet92643b52014-12-18 14:35:42 -0800123 if (view_manager()) {
James Robinson3b679672015-01-21 18:36:01 -0800124 window_manager_delegate_->Embed(url, services.Pass(),
125 exposed_services.Pass());
Scott Violet5d674ef2014-10-22 15:52:54 -0700126 return;
127 }
128 scoped_ptr<PendingEmbed> pending_embed(new PendingEmbed);
129 pending_embed->url = url;
James Robinson3b679672015-01-21 18:36:01 -0800130 pending_embed->services = services.Pass();
131 pending_embed->exposed_services = exposed_services.Pass();
Scott Violet5d674ef2014-10-22 15:52:54 -0700132 pending_embeds_.push_back(pending_embed.release());
133}
134
James Robinson646469d2014-10-03 15:33:28 -0700135////////////////////////////////////////////////////////////////////////////////
136// WindowManagerApp, ApplicationDelegate implementation:
137
James Robinson489c8f12014-12-08 12:08:55 -0800138void WindowManagerApp::Initialize(mojo::ApplicationImpl* impl) {
James Robinsonbaf71d32014-10-08 13:00:20 -0700139 shell_ = impl->shell();
Scott Violet5d674ef2014-10-22 15:52:54 -0700140 LaunchViewManager(impl);
James Robinson646469d2014-10-03 15:33:28 -0700141}
142
143bool WindowManagerApp::ConfigureIncomingConnection(
144 ApplicationConnection* connection) {
James Robinson05d56292015-02-18 17:35:49 -0800145 connection->AddService<WindowManager>(this);
James Robinson646469d2014-10-03 15:33:28 -0700146 return true;
147}
148
149////////////////////////////////////////////////////////////////////////////////
150// WindowManagerApp, ViewManagerDelegate implementation:
151
James Robinson3b679672015-01-21 18:36:01 -0800152void WindowManagerApp::OnEmbed(
153 View* root,
154 mojo::InterfaceRequest<mojo::ServiceProvider> services,
155 mojo::ServiceProviderPtr exposed_services) {
Scott Violet92643b52014-12-18 14:35:42 -0800156 DCHECK(!root_);
James Robinson646469d2014-10-03 15:33:28 -0700157 root_ = root;
158
James Robinson489c8f12014-12-08 12:08:55 -0800159 view_event_dispatcher_.reset(new ViewEventDispatcher);
James Robinson646469d2014-10-03 15:33:28 -0700160
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800161 RegisterSubtree(root_);
James Robinson646469d2014-10-03 15:33:28 -0700162
James Robinson646469d2014-10-03 15:33:28 -0700163 if (wrapped_view_manager_delegate_) {
James Robinson3b679672015-01-21 18:36:01 -0800164 wrapped_view_manager_delegate_->OnEmbed(root, services.Pass(),
165 exposed_services.Pass());
James Robinson646469d2014-10-03 15:33:28 -0700166 }
167
James Robinson3b679672015-01-21 18:36:01 -0800168 for (PendingEmbed* pending_embed : pending_embeds_) {
169 Embed(pending_embed->url, pending_embed->services.Pass(),
170 pending_embed->exposed_services.Pass());
171 }
Scott Violet5d674ef2014-10-22 15:52:54 -0700172 pending_embeds_.clear();
James Robinson646469d2014-10-03 15:33:28 -0700173}
174
175void WindowManagerApp::OnViewManagerDisconnected(
James Robinson489c8f12014-12-08 12:08:55 -0800176 mojo::ViewManager* view_manager) {
James Robinson646469d2014-10-03 15:33:28 -0700177 if (wrapped_view_manager_delegate_)
178 wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager);
Michael Wasserman93d013c2015-01-14 20:22:36 -0800179
180 base::MessageLoop* message_loop = base::MessageLoop::current();
181 if (message_loop && message_loop->is_running())
182 message_loop->Quit();
James Robinson646469d2014-10-03 15:33:28 -0700183}
184
Scott Violet6edabbf2015-02-25 16:02:50 -0800185bool WindowManagerApp::OnPerformAction(mojo::View* view,
186 const std::string& action) {
187 if (!view)
188 return false;
189 if (action == "capture")
190 return SetCaptureImpl(view);
191 if (action == "focus")
192 return FocusWindowImpl(view);
193 else if (action == "activate")
194 return ActivateWindowImpl(view);
195 return false;
196}
197
James Robinson646469d2014-10-03 15:33:28 -0700198////////////////////////////////////////////////////////////////////////////////
James Robinson646469d2014-10-03 15:33:28 -0700199// WindowManagerApp, ViewObserver implementation:
200
201void WindowManagerApp::OnTreeChanged(
202 const ViewObserver::TreeChangeParams& params) {
203 if (params.receiver != root_)
204 return;
205 DCHECK(params.old_parent || params.new_parent);
206 if (!params.target)
207 return;
208
209 if (params.new_parent) {
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800210 if (registered_view_id_set_.find(params.target->id()) ==
211 registered_view_id_set_.end()) {
212 RegisteredViewIdSet::const_iterator it =
213 registered_view_id_set_.find(params.new_parent->id());
214 DCHECK(it != registered_view_id_set_.end());
215 RegisterSubtree(params.target);
James Robinson646469d2014-10-03 15:33:28 -0700216 }
217 } else if (params.old_parent) {
218 UnregisterSubtree(params.target);
219 }
220}
221
James Robinsone2ac7e82014-10-15 13:21:59 -0700222void WindowManagerApp::OnViewDestroying(View* view) {
Michael Wasserman93d013c2015-01-14 20:22:36 -0800223 Unregister(view);
224 if (view == root_) {
225 root_ = nullptr;
226 if (focus_controller_)
227 focus_controller_->RemoveObserver(this);
228 if (capture_controller_)
229 capture_controller_->RemoveObserver(this);
James Robinsone2ac7e82014-10-15 13:21:59 -0700230 }
James Robinson646469d2014-10-03 15:33:28 -0700231}
232
James Robinson646469d2014-10-03 15:33:28 -0700233////////////////////////////////////////////////////////////////////////////////
James Robinson646469d2014-10-03 15:33:28 -0700234// WindowManagerApp, ui::EventHandler implementation:
235
236void WindowManagerApp::OnEvent(ui::Event* event) {
James Robinsone2ac7e82014-10-15 13:21:59 -0700237 if (!window_manager_client_)
238 return;
239
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800240 View* view = static_cast<ViewTarget*>(event->target())->view();
James Robinsone2ac7e82014-10-15 13:21:59 -0700241 if (!view)
242 return;
243
Benjamin Lerman63fc2782015-02-26 10:33:42 +0100244 if (event->IsKeyEvent()) {
245 const ui::KeyEvent* key_event = static_cast<const ui::KeyEvent*>(event);
246 if (key_event->type() == ui::ET_KEY_PRESSED) {
247 ui::Accelerator accelerator = ConvertEventToAccelerator(key_event);
Scott Violet0dbc7212015-04-13 13:31:43 -0700248 if (accelerator_manager_.Process(accelerator, view))
Benjamin Lerman63fc2782015-02-26 10:33:42 +0100249 return;
250 }
251 }
252
Elliot Glaysher28b50b92014-11-10 17:06:49 -0800253 if (focus_controller_)
254 focus_controller_->OnEvent(event);
255
James Robinsone2ac7e82014-10-15 13:21:59 -0700256 window_manager_client_->DispatchInputEventToView(view->id(),
James Robinson489c8f12014-12-08 12:08:55 -0800257 mojo::Event::From(*event));
Adam Barth29fd00a2015-01-13 17:01:10 -0800258}
259
260////////////////////////////////////////////////////////////////////////////////
Elliot Glaysher28b50b92014-11-10 17:06:49 -0800261// WindowManagerApp, mojo::FocusControllerObserver implementation:
James Robinson646469d2014-10-03 15:33:28 -0700262
James Robinson8c33cd92015-01-29 12:33:50 -0800263void WindowManagerApp::OnFocused(View* gained_focus) {
James Robinson646469d2014-10-03 15:33:28 -0700264 for (Connections::const_iterator it = connections_.begin();
265 it != connections_.end(); ++it) {
James Robinson8c33cd92015-01-29 12:33:50 -0800266 (*it)->NotifyViewFocused(GetIdForView(gained_focus));
James Robinson646469d2014-10-03 15:33:28 -0700267 }
268}
269
James Robinson8c33cd92015-01-29 12:33:50 -0800270void WindowManagerApp::OnActivated(View* gained_active) {
James Robinson646469d2014-10-03 15:33:28 -0700271 for (Connections::const_iterator it = connections_.begin();
272 it != connections_.end(); ++it) {
James Robinson8c33cd92015-01-29 12:33:50 -0800273 (*it)->NotifyWindowActivated(GetIdForView(gained_active));
James Robinson646469d2014-10-03 15:33:28 -0700274 }
Elliot Glaysher28b50b92014-11-10 17:06:49 -0800275 if (gained_active)
276 gained_active->MoveToFront();
James Robinson646469d2014-10-03 15:33:28 -0700277}
278
279////////////////////////////////////////////////////////////////////////////////
Elliot Glaysherf88a2fb2014-12-16 11:09:36 -0800280// WindowManagerApp, mojo::CaptureControllerObserver implementation:
281
James Robinson8c33cd92015-01-29 12:33:50 -0800282void WindowManagerApp::OnCaptureChanged(View* gained_capture) {
Elliot Glaysherf88a2fb2014-12-16 11:09:36 -0800283 for (Connections::const_iterator it = connections_.begin();
284 it != connections_.end(); ++it) {
James Robinson8c33cd92015-01-29 12:33:50 -0800285 (*it)->NotifyCaptureChanged(GetIdForView(gained_capture));
Elliot Glaysherf88a2fb2014-12-16 11:09:36 -0800286 }
287 if (gained_capture)
288 gained_capture->MoveToFront();
289}
290
291////////////////////////////////////////////////////////////////////////////////
James Robinson646469d2014-10-03 15:33:28 -0700292// WindowManagerApp, private:
293
Scott Violet6edabbf2015-02-25 16:02:50 -0800294bool WindowManagerApp::SetCaptureImpl(View* view) {
295 CHECK(view);
296 capture_controller_->SetCapture(view);
297 return capture_controller_->GetCapture() == view;
298}
299
300bool WindowManagerApp::FocusWindowImpl(View* view) {
301 CHECK(view);
302 focus_controller_->FocusView(view);
303 return focus_controller_->GetFocusedView() == view;
304}
305
306bool WindowManagerApp::ActivateWindowImpl(View* view) {
307 CHECK(view);
308 focus_controller_->ActivateView(view);
309 return focus_controller_->GetActiveView() == view;
310}
311
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800312void WindowManagerApp::RegisterSubtree(View* view) {
James Robinson646469d2014-10-03 15:33:28 -0700313 view->AddObserver(this);
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800314 DCHECK(registered_view_id_set_.find(view->id()) ==
315 registered_view_id_set_.end());
James Robinson646469d2014-10-03 15:33:28 -0700316 // All events pass through the root during dispatch, so we only need a handler
317 // installed there.
Elliot Glaysher28b50b92014-11-10 17:06:49 -0800318 if (view == root_) {
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800319 ViewTarget* target = ViewTarget::TargetFromView(view);
Elliot Glaysher28b50b92014-11-10 17:06:49 -0800320 target->SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter()));
321 target->AddPreTargetHandler(this);
322 view_event_dispatcher_->SetRootViewTarget(target);
323 }
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800324 registered_view_id_set_.insert(view->id());
James Robinson646469d2014-10-03 15:33:28 -0700325 View::Children::const_iterator it = view->children().begin();
326 for (; it != view->children().end(); ++it)
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800327 RegisterSubtree(*it);
James Robinson646469d2014-10-03 15:33:28 -0700328}
329
330void WindowManagerApp::UnregisterSubtree(View* view) {
James Robinsone2ac7e82014-10-15 13:21:59 -0700331 for (View* child : view->children())
332 UnregisterSubtree(child);
333 Unregister(view);
334}
335
336void WindowManagerApp::Unregister(View* view) {
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800337 RegisteredViewIdSet::iterator it = registered_view_id_set_.find(view->id());
338 if (it == registered_view_id_set_.end()) {
James Robinsone2ac7e82014-10-15 13:21:59 -0700339 // Because we unregister in OnViewDestroying() we can still get a subsequent
340 // OnTreeChanged for the same view. Ignore this one.
341 return;
342 }
343 view->RemoveObserver(this);
Elliot Glaysherc89cc3b2014-11-17 16:45:06 -0800344 DCHECK(it != registered_view_id_set_.end());
345 registered_view_id_set_.erase(it);
James Robinson646469d2014-10-03 15:33:28 -0700346}
347
James Robinson489c8f12014-12-08 12:08:55 -0800348void WindowManagerApp::DispatchInputEventToView(View* view,
349 mojo::EventPtr event) {
Adam Barth4c9c2c52014-11-12 10:32:54 -0800350 window_manager_client_->DispatchInputEventToView(view->id(), event.Pass());
351}
352
Eric Seidel6a7fabe2014-10-30 14:20:45 -0700353void WindowManagerApp::SetViewportSize(const gfx::Size& size) {
James Robinson489c8f12014-12-08 12:08:55 -0800354 window_manager_client_->SetViewportSize(mojo::Size::From(size));
Eric Seidel6a7fabe2014-10-30 14:20:45 -0700355}
356
James Robinson489c8f12014-12-08 12:08:55 -0800357void WindowManagerApp::LaunchViewManager(mojo::ApplicationImpl* app) {
Scott Violet5d674ef2014-10-22 15:52:54 -0700358 // TODO(sky): figure out logic if this connection goes away.
359 view_manager_client_factory_.reset(
James Robinson489c8f12014-12-08 12:08:55 -0800360 new mojo::ViewManagerClientFactory(shell_, this));
Scott Violet5d674ef2014-10-22 15:52:54 -0700361
Scott Violet5d674ef2014-10-22 15:52:54 -0700362 ApplicationConnection* view_manager_app =
363 app->ConnectToApplication("mojo:view_manager");
James Robinson2297c632015-02-06 11:06:34 -0800364 view_manager_app->ConnectToService(&view_manager_service_);
Scott Violet5d674ef2014-10-22 15:52:54 -0700365
James Robinson2297c632015-02-06 11:06:34 -0800366 view_manager_app->AddService<WindowManagerInternal>(this);
James Robinson05d56292015-02-18 17:35:49 -0800367 view_manager_app->AddService<mojo::NativeViewportEventDispatcher>(this);
Scott Violetc947ecc2014-10-28 16:49:51 -0700368
369 view_manager_app->ConnectToService(&window_manager_client_);
Scott Violet5d674ef2014-10-22 15:52:54 -0700370}
371
James Robinson489c8f12014-12-08 12:08:55 -0800372void WindowManagerApp::Create(
373 ApplicationConnection* connection,
374 mojo::InterfaceRequest<WindowManagerInternal> request) {
Scott Violet945fd422014-11-19 15:56:54 -0800375 if (wm_internal_binding_.get()) {
376 VLOG(1) <<
377 "WindowManager allows only one WindowManagerInternal connection.";
378 return;
379 }
380 wm_internal_binding_.reset(
James Robinson489c8f12014-12-08 12:08:55 -0800381 new mojo::Binding<WindowManagerInternal>(this, request.Pass()));
Scott Violet945fd422014-11-19 15:56:54 -0800382}
383
384void WindowManagerApp::Create(ApplicationConnection* connection,
James Robinson489c8f12014-12-08 12:08:55 -0800385 mojo::InterfaceRequest<WindowManager> request) {
Scott Violet945fd422014-11-19 15:56:54 -0800386 WindowManagerImpl* wm = new WindowManagerImpl(this, false);
387 wm->Bind(request.PassMessagePipe());
388 // WindowManagerImpl is deleted when the connection has an error, or from our
389 // destructor.
390}
391
James Robinson05d56292015-02-18 17:35:49 -0800392void WindowManagerApp::Create(
393 mojo::ApplicationConnection* connection,
394 mojo::InterfaceRequest<mojo::NativeViewportEventDispatcher> request) {
395 new NativeViewportEventDispatcherImpl(this, request.Pass());
396}
397
Scott Violet945fd422014-11-19 15:56:54 -0800398void WindowManagerApp::CreateWindowManagerForViewManagerClient(
399 uint16_t connection_id,
James Robinson489c8f12014-12-08 12:08:55 -0800400 mojo::ScopedMessagePipeHandle window_manager_pipe) {
Scott Violet29f7dbf2014-12-10 14:26:52 -0800401 // TODO(sky): pass in |connection_id| for validation.
Scott Violet945fd422014-11-19 15:56:54 -0800402 WindowManagerImpl* wm = new WindowManagerImpl(this, true);
403 wm->Bind(window_manager_pipe.Pass());
404 // WindowManagerImpl is deleted when the connection has an error, or from our
405 // destructor.
Scott Violet37e9aea2014-10-31 15:06:04 -0700406}
407
James Robinson2297c632015-02-06 11:06:34 -0800408void WindowManagerApp::SetViewManagerClient(
409 mojo::ScopedMessagePipeHandle view_manager_client_request) {
James Robinson3aefd1b2015-02-10 17:11:46 -0800410 view_manager_client_.reset(
James Robinson2297c632015-02-06 11:06:34 -0800411 mojo::ViewManagerClientFactory::WeakBindViewManagerToPipe(
412 mojo::MakeRequest<mojo::ViewManagerClient>(
413 view_manager_client_request.Pass()),
James Robinson3aefd1b2015-02-10 17:11:46 -0800414 view_manager_service_.Pass(), shell_, this));
James Robinson2297c632015-02-06 11:06:34 -0800415}
416
James Robinson489c8f12014-12-08 12:08:55 -0800417} // namespace window_manager