OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "examples/bitmap_uploader/bitmap_uploader.h" | 7 #include "examples/bitmap_uploader/bitmap_uploader.h" |
8 #include "examples/wm_flow/app/embedder.mojom.h" | 8 #include "examples/wm_flow/app/embedder.mojom.h" |
9 #include "examples/wm_flow/embedded/embeddee.mojom.h" | 9 #include "examples/wm_flow/embedded/embeddee.mojom.h" |
10 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl); | 39 DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl); |
40 }; | 40 }; |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 class WMFlowEmbedded : public mojo::ApplicationDelegate, | 44 class WMFlowEmbedded : public mojo::ApplicationDelegate, |
45 public mojo::ViewManagerDelegate { | 45 public mojo::ViewManagerDelegate { |
46 public: | 46 public: |
47 WMFlowEmbedded() : shell_(nullptr) {} | 47 WMFlowEmbedded() : shell_(nullptr) { |
| 48 embeddee_provider_impl_.AddService(&embeddee_factory_); |
| 49 } |
48 virtual ~WMFlowEmbedded() {} | 50 virtual ~WMFlowEmbedded() {} |
49 | 51 |
50 private: | 52 private: |
51 // Overridden from Application: | 53 // Overridden from Application: |
52 virtual void Initialize(mojo::ApplicationImpl* app) override { | 54 virtual void Initialize(mojo::ApplicationImpl* app) override { |
53 shell_ = app->shell(); | 55 shell_ = app->shell(); |
54 view_manager_client_factory_.reset( | 56 view_manager_client_factory_.reset( |
55 new mojo::ViewManagerClientFactory(app->shell(), this)); | 57 new mojo::ViewManagerClientFactory(app->shell(), this)); |
56 } | 58 } |
57 virtual bool ConfigureIncomingConnection( | 59 virtual bool ConfigureIncomingConnection( |
58 mojo::ApplicationConnection* connection) override { | 60 mojo::ApplicationConnection* connection) override { |
59 connection->AddService(view_manager_client_factory_.get()); | 61 connection->AddService(view_manager_client_factory_.get()); |
60 return true; | 62 return true; |
61 } | 63 } |
62 | 64 |
63 // Overridden from mojo::ViewManagerDelegate: | 65 // Overridden from mojo::ViewManagerDelegate: |
64 virtual void OnEmbed( | 66 virtual void OnEmbed(mojo::View* root, |
65 mojo::View* root, | 67 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
66 mojo::ServiceProviderImpl* exported_services, | 68 mojo::ServiceProviderPtr exposed_services) override { |
67 scoped_ptr<mojo::ServiceProvider> imported_services) override { | |
68 bitmap_uploader_.reset(new mojo::BitmapUploader(root)); | 69 bitmap_uploader_.reset(new mojo::BitmapUploader(root)); |
69 bitmap_uploader_->Init(shell_); | 70 bitmap_uploader_->Init(shell_); |
70 // BitmapUploader does not track view size changes, we would | 71 // BitmapUploader does not track view size changes, we would |
71 // need to subscribe to OnViewBoundsChanged and tell the bitmap uploader | 72 // need to subscribe to OnViewBoundsChanged and tell the bitmap uploader |
72 // to invalidate itself. This is better done once if had a per-view | 73 // to invalidate itself. This is better done once if had a per-view |
73 // object instead of holding per-view state on the ApplicationDelegate. | 74 // object instead of holding per-view state on the ApplicationDelegate. |
74 bitmap_uploader_->SetColor(SK_ColorMAGENTA); | 75 bitmap_uploader_->SetColor(SK_ColorMAGENTA); |
75 | 76 |
76 exported_services->AddService(&embeddee_factory_); | 77 embeddee_provider_impl_.Bind(services.Pass()); |
77 // FIXME: embedder_ is wrong for the same reason the embedee_ storage is | 78 // FIXME: embedder_ is wrong for the same reason the embedee_ storage is |
78 // wrong in app.cc. We need separate per-instance storage not on the | 79 // wrong in app.cc. We need separate per-instance storage not on the |
79 // application delegate. | 80 // application delegate. |
80 mojo::ConnectToService(imported_services.get(), &embedder_); | 81 mojo::ConnectToService(exposed_services.get(), &embedder_); |
81 embedder_->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck, | 82 embedder_->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck, |
82 base::Unretained(this))); | 83 base::Unretained(this))); |
83 } | 84 } |
84 virtual void OnViewManagerDisconnected( | 85 virtual void OnViewManagerDisconnected( |
85 mojo::ViewManager* view_manager) override {} | 86 mojo::ViewManager* view_manager) override {} |
86 | 87 |
87 void HelloWorldAck() { | 88 void HelloWorldAck() { |
88 printf("HelloWorld() ack'ed\n"); | 89 printf("HelloWorld() ack'ed\n"); |
89 } | 90 } |
90 | 91 |
91 mojo::Shell* shell_; | 92 mojo::Shell* shell_; |
92 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; | 93 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; |
93 EmbedderPtr embedder_; | 94 EmbedderPtr embedder_; |
| 95 mojo::ServiceProviderImpl embeddee_provider_impl_; |
94 mojo::InterfaceFactoryImpl<EmbeddeeImpl> embeddee_factory_; | 96 mojo::InterfaceFactoryImpl<EmbeddeeImpl> embeddee_factory_; |
95 scoped_ptr<mojo::BitmapUploader> bitmap_uploader_; | 97 scoped_ptr<mojo::BitmapUploader> bitmap_uploader_; |
96 | 98 |
97 DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded); | 99 DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded); |
98 }; | 100 }; |
99 | 101 |
100 } // namespace examples | 102 } // namespace examples |
101 | 103 |
102 MojoResult MojoMain(MojoHandle shell_handle) { | 104 MojoResult MojoMain(MojoHandle shell_handle) { |
103 mojo::ApplicationRunnerChromium runner(new examples::WMFlowEmbedded); | 105 mojo::ApplicationRunnerChromium runner(new examples::WMFlowEmbedded); |
104 return runner.Run(shell_handle); | 106 return runner.Run(shell_handle); |
105 } | 107 } |
106 | 108 |
OLD | NEW |