1 // 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.
5 #include "base/memory/scoped_ptr.h"
6 #include "mojo/public/c/system/main.h"
7 #include "mojo/public/cpp/application/application_delegate.h"
8 #include "mojo/public/cpp/application/application_runner_chromium.h"
9 #include "mojo/public/cpp/application/service_provider_impl.h"
10 #include "mojo/services/public/cpp/view_manager/view_manager.h"
11 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
12 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
13 #include "mojo/services/window_manager/window_manager_app.h"
15 // ApplicationDelegate implementation file for WindowManager users (e.g.
16 // core window manager tests) that do not want to provide their own
17 // ApplicationDelegate::Create().
21 class DefaultWindowManager
: public ApplicationDelegate
,
22 public ViewManagerDelegate
,
23 public WindowManagerDelegate
{
25 DefaultWindowManager()
26 : window_manager_app_(new WindowManagerApp(this, this)),
29 virtual ~DefaultWindowManager() {}
32 // Overridden from ApplicationDelegate:
33 virtual void Initialize(ApplicationImpl
* impl
) MOJO_OVERRIDE
{
34 window_manager_app_
->Initialize(impl
);
36 virtual bool ConfigureIncomingConnection(
37 ApplicationConnection
* connection
) MOJO_OVERRIDE
{
38 window_manager_app_
->ConfigureIncomingConnection(connection
);
42 // Overridden from ViewManagerDelegate:
44 ViewManager
* view_manager
,
46 ServiceProviderImpl
* exported_services
,
47 scoped_ptr
<ServiceProvider
> imported_services
) MOJO_OVERRIDE
{
48 view_manager_
= view_manager
;
50 view_manager_
->SetWindowManagerDelegate(this);
52 virtual void OnViewManagerDisconnected(
53 ViewManager
* view_manager
) MOJO_OVERRIDE
{}
55 // Overridden from WindowManagerDelegate:
58 InterfaceRequest
<ServiceProvider
> service_provider
) MOJO_OVERRIDE
{
59 View
* view
= View::Create(view_manager_
);
60 root_
->AddChild(view
);
61 view
->Embed(url
, scoped_ptr
<mojo::ServiceProviderImpl
>(
62 new mojo::ServiceProviderImpl
).Pass());
64 virtual void DispatchEvent(EventPtr event
) MOJO_OVERRIDE
{}
66 scoped_ptr
<WindowManagerApp
> window_manager_app_
;
68 ViewManager
* view_manager_
;
71 MOJO_DISALLOW_COPY_AND_ASSIGN(DefaultWindowManager
);
76 MojoResult
MojoMain(MojoHandle shell_handle
) {
77 mojo::ApplicationRunnerChromium
runner(new mojo::DefaultWindowManager
);
78 return runner
.Run(shell_handle
);