| 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" |
| 11 #include "mojo/public/c/system/main.h" | 11 #include "mojo/public/c/system/main.h" |
| 12 #include "mojo/public/cpp/application/application_connection.h" | 12 #include "mojo/public/cpp/application/application_connection.h" |
| 13 #include "mojo/public/cpp/application/application_delegate.h" | 13 #include "mojo/public/cpp/application/application_delegate.h" |
| 14 #include "mojo/public/cpp/application/application_impl.h" | 14 #include "mojo/public/cpp/application/application_impl.h" |
| 15 #include "mojo/public/cpp/application/connect.h" | 15 #include "mojo/public/cpp/application/connect.h" |
| 16 #include "mojo/public/cpp/application/interface_factory_impl.h" | |
| 17 #include "mojo/public/cpp/application/service_provider_impl.h" | 16 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 17 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 18 #include "mojo/services/view_manager/public/cpp/view.h" | 18 #include "mojo/services/view_manager/public/cpp/view.h" |
| 19 #include "mojo/services/view_manager/public/cpp/view_manager.h" | 19 #include "mojo/services/view_manager/public/cpp/view_manager.h" |
| 20 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h" | 20 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h" |
| 21 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h" | 21 #include "mojo/services/view_manager/public/cpp/view_manager_delegate.h" |
| 22 #include "third_party/skia/include/core/SkColor.h" | 22 #include "third_party/skia/include/core/SkColor.h" |
| 23 | 23 |
| 24 namespace examples { | 24 namespace examples { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class EmbeddeeImpl : public mojo::InterfaceImpl<Embeddee> { | 28 class EmbeddeeImpl : public Embeddee { |
| 29 public: | 29 public: |
| 30 EmbeddeeImpl() {} | 30 explicit EmbeddeeImpl(mojo::InterfaceRequest<Embeddee> request) |
| 31 virtual ~EmbeddeeImpl() {} | 31 : binding_(this, request.Pass()) {} |
| 32 ~EmbeddeeImpl() override {} |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 // Overridden from Embeddee: | 35 // Overridden from Embeddee: |
| 35 virtual void HelloBack(const mojo::Callback<void()>& callback) override { | 36 void HelloBack(const mojo::Callback<void()>& callback) override { |
| 36 callback.Run(); | 37 callback.Run(); |
| 37 } | 38 } |
| 38 | 39 |
| 40 mojo::StrongBinding<Embeddee> binding_; |
| 39 DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl); | 41 DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl); |
| 40 }; | 42 }; |
| 41 | 43 |
| 42 } // namespace | 44 } // namespace |
| 43 | 45 |
| 44 class WMFlowEmbedded : public mojo::ApplicationDelegate, | 46 class WMFlowEmbedded : public mojo::ApplicationDelegate, |
| 45 public mojo::ViewManagerDelegate { | 47 public mojo::ViewManagerDelegate, |
| 48 public mojo::InterfaceFactory<Embeddee> { |
| 46 public: | 49 public: |
| 47 WMFlowEmbedded() : shell_(nullptr) { | 50 WMFlowEmbedded() : shell_(nullptr) { |
| 48 embeddee_provider_impl_.AddService(&embeddee_factory_); | 51 embeddee_provider_impl_.AddService(this); |
| 49 } | 52 } |
| 50 virtual ~WMFlowEmbedded() {} | 53 virtual ~WMFlowEmbedded() {} |
| 51 | 54 |
| 52 private: | 55 private: |
| 53 // Overridden from Application: | 56 // Overridden from Application: |
| 54 virtual void Initialize(mojo::ApplicationImpl* app) override { | 57 void Initialize(mojo::ApplicationImpl* app) override { |
| 55 shell_ = app->shell(); | 58 shell_ = app->shell(); |
| 56 view_manager_client_factory_.reset( | 59 view_manager_client_factory_.reset( |
| 57 new mojo::ViewManagerClientFactory(app->shell(), this)); | 60 new mojo::ViewManagerClientFactory(app->shell(), this)); |
| 58 } | 61 } |
| 59 virtual bool ConfigureIncomingConnection( | 62 bool ConfigureIncomingConnection( |
| 60 mojo::ApplicationConnection* connection) override { | 63 mojo::ApplicationConnection* connection) override { |
| 61 connection->AddService(view_manager_client_factory_.get()); | 64 connection->AddService(view_manager_client_factory_.get()); |
| 62 return true; | 65 return true; |
| 63 } | 66 } |
| 64 | 67 |
| 65 // Overridden from mojo::ViewManagerDelegate: | 68 // Overridden from mojo::ViewManagerDelegate: |
| 66 virtual void OnEmbed(mojo::View* root, | 69 void OnEmbed(mojo::View* root, |
| 67 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 70 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 68 mojo::ServiceProviderPtr exposed_services) override { | 71 mojo::ServiceProviderPtr exposed_services) override { |
| 69 bitmap_uploader_.reset(new mojo::BitmapUploader(root)); | 72 bitmap_uploader_.reset(new mojo::BitmapUploader(root)); |
| 70 bitmap_uploader_->Init(shell_); | 73 bitmap_uploader_->Init(shell_); |
| 71 // BitmapUploader does not track view size changes, we would | 74 // BitmapUploader does not track view size changes, we would |
| 72 // need to subscribe to OnViewBoundsChanged and tell the bitmap uploader | 75 // need to subscribe to OnViewBoundsChanged and tell the bitmap uploader |
| 73 // to invalidate itself. This is better done once if had a per-view | 76 // to invalidate itself. This is better done once if had a per-view |
| 74 // object instead of holding per-view state on the ApplicationDelegate. | 77 // object instead of holding per-view state on the ApplicationDelegate. |
| 75 bitmap_uploader_->SetColor(SK_ColorMAGENTA); | 78 bitmap_uploader_->SetColor(SK_ColorMAGENTA); |
| 76 | 79 |
| 77 embeddee_provider_impl_.Bind(services.Pass()); | 80 embeddee_provider_impl_.Bind(services.Pass()); |
| 78 // FIXME: embedder_ is wrong for the same reason the embedee_ storage is | 81 // FIXME: embedder_ is wrong for the same reason the embedee_ storage is |
| 79 // wrong in app.cc. We need separate per-instance storage not on the | 82 // wrong in app.cc. We need separate per-instance storage not on the |
| 80 // application delegate. | 83 // application delegate. |
| 81 mojo::ConnectToService(exposed_services.get(), &embedder_); | 84 mojo::ConnectToService(exposed_services.get(), &embedder_); |
| 82 embedder_->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck, | 85 embedder_->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck, |
| 83 base::Unretained(this))); | 86 base::Unretained(this))); |
| 84 } | 87 } |
| 85 virtual void OnViewManagerDisconnected( | 88 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override {} |
| 86 mojo::ViewManager* view_manager) override {} | 89 |
| 90 // Overridden from mojo::InterfaceFactory<Embeddee>: |
| 91 void Create(mojo::ApplicationConnection* app, |
| 92 mojo::InterfaceRequest<Embeddee> request) override { |
| 93 new EmbeddeeImpl(request.Pass()); |
| 94 } |
| 87 | 95 |
| 88 void HelloWorldAck() { | 96 void HelloWorldAck() { |
| 89 printf("HelloWorld() ack'ed\n"); | 97 printf("HelloWorld() ack'ed\n"); |
| 90 } | 98 } |
| 91 | 99 |
| 92 mojo::Shell* shell_; | 100 mojo::Shell* shell_; |
| 93 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; | 101 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; |
| 94 EmbedderPtr embedder_; | 102 EmbedderPtr embedder_; |
| 95 mojo::ServiceProviderImpl embeddee_provider_impl_; | 103 mojo::ServiceProviderImpl embeddee_provider_impl_; |
| 96 mojo::InterfaceFactoryImpl<EmbeddeeImpl> embeddee_factory_; | |
| 97 scoped_ptr<mojo::BitmapUploader> bitmap_uploader_; | 104 scoped_ptr<mojo::BitmapUploader> bitmap_uploader_; |
| 98 | 105 |
| 99 DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded); | 106 DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded); |
| 100 }; | 107 }; |
| 101 | 108 |
| 102 } // namespace examples | 109 } // namespace examples |
| 103 | 110 |
| 104 MojoResult MojoMain(MojoHandle shell_handle) { | 111 MojoResult MojoMain(MojoHandle shell_handle) { |
| 105 mojo::ApplicationRunnerChromium runner(new examples::WMFlowEmbedded); | 112 mojo::ApplicationRunnerChromium runner(new examples::WMFlowEmbedded); |
| 106 return runner.Run(shell_handle); | 113 return runner.Run(shell_handle); |
| 107 } | 114 } |
| 108 | 115 |
| OLD | NEW |