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.
6 #include "base/macros.h"
7 #include "mojo/application/application_runner_chromium.h"
8 #include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
9 #include "mojo/examples/wm_flow/app/embedder.mojom.h"
10 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
11 #include "mojo/public/cpp/application/application_connection.h"
12 #include "mojo/public/cpp/application/application_delegate.h"
13 #include "mojo/public/cpp/application/application_impl.h"
14 #include "mojo/public/cpp/application/connect.h"
15 #include "mojo/public/cpp/application/interface_factory_impl.h"
16 #include "mojo/public/cpp/application/service_provider_impl.h"
17 #include "mojo/services/public/cpp/view_manager/view.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager.h"
19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
26 class EmbeddeeImpl
: public mojo::InterfaceImpl
<Embeddee
> {
29 virtual ~EmbeddeeImpl() {}
32 // Overridden from Embeddee:
33 virtual void HelloBack(const mojo::Callback
<void()>& callback
) override
{
37 DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl
);
42 class WMFlowEmbedded
: public mojo::ApplicationDelegate
,
43 public mojo::ViewManagerDelegate
{
45 WMFlowEmbedded() : shell_(nullptr) {}
46 virtual ~WMFlowEmbedded() {}
49 // Overridden from Application:
50 virtual void Initialize(mojo::ApplicationImpl
* app
) override
{
51 shell_
= app
->shell();
52 view_manager_client_factory_
.reset(
53 new mojo::ViewManagerClientFactory(app
->shell(), this));
55 virtual bool ConfigureIncomingConnection(
56 mojo::ApplicationConnection
* connection
) override
{
57 connection
->AddService(view_manager_client_factory_
.get());
61 // Overridden from mojo::ViewManagerDelegate:
63 mojo::ViewManager
* view_manager
,
65 mojo::ServiceProviderImpl
* exported_services
,
66 scoped_ptr
<mojo::ServiceProvider
> imported_services
) override
{
67 bitmap_uploader_
.reset(new mojo::BitmapUploader(root
));
68 bitmap_uploader_
->Init(shell_
);
69 bitmap_uploader_
->SetColor(SK_ColorMAGENTA
);
71 exported_services
->AddService(&embeddee_factory_
);
72 mojo::ConnectToService(imported_services
.get(), &embedder_
);
73 embedder_
->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck
,
74 base::Unretained(this)));
76 virtual void OnViewManagerDisconnected(
77 mojo::ViewManager
* view_manager
) override
{}
79 void HelloWorldAck() {
80 printf("HelloWorld() ack'ed\n");
84 scoped_ptr
<mojo::ViewManagerClientFactory
> view_manager_client_factory_
;
85 EmbedderPtr embedder_
;
86 mojo::InterfaceFactoryImpl
<EmbeddeeImpl
> embeddee_factory_
;
87 scoped_ptr
<mojo::BitmapUploader
> bitmap_uploader_
;
89 DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded
);
92 } // namespace examples
94 MojoResult
MojoMain(MojoHandle shell_handle
) {
95 mojo::ApplicationRunnerChromium
runner(new examples::WMFlowEmbedded
);
96 return runner
.Run(shell_handle
);