| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MOJO_UI_VIEW_PROVIDER_APP_H_ | 5 #ifndef MOJO_UI_VIEW_PROVIDER_APP_H_ |
| 6 #define MOJO_UI_VIEW_PROVIDER_APP_H_ | 6 #define MOJO_UI_VIEW_PROVIDER_APP_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "mojo/common/strong_binding_set.h" | 10 #include "mojo/common/strong_binding_set.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_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
| 14 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 15 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" | 15 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 // Abstract implementation of a simple application that offers a ViewProvider. | 20 // Abstract implementation of a simple application that offers a ViewProvider. |
| 21 // Subclasses must provide a function to create the necessary Views. | 21 // Subclasses must provide a function to create the necessary Views. |
| 22 // | 22 // |
| 23 // It is not necessary to use this class to implement all ViewProviders. | 23 // It is not necessary to use this class to implement all ViewProviders. |
| 24 // This class is merely intended to make the simple apps easier to write. | 24 // This class is merely intended to make the simple apps easier to write. |
| 25 class ViewProviderApp : public mojo::ApplicationDelegate, | 25 class ViewProviderApp : public ApplicationDelegate, |
| 26 public mojo::InterfaceFactory<mojo::ui::ViewProvider> { | 26 public InterfaceFactory<ui::ViewProvider> { |
| 27 public: | 27 public: |
| 28 ViewProviderApp(); | 28 ViewProviderApp(); |
| 29 ~ViewProviderApp() override; | 29 ~ViewProviderApp() override; |
| 30 | 30 |
| 31 mojo::ApplicationImpl* app_impl() { return app_impl_; } | 31 ApplicationImpl* app_impl() { return app_impl_; } |
| 32 | 32 |
| 33 // |ApplicationDelegate|: | 33 // |ApplicationDelegate|: |
| 34 void Initialize(mojo::ApplicationImpl* app) override; | 34 void Initialize(ApplicationImpl* app) override; |
| 35 bool ConfigureIncomingConnection( | 35 bool ConfigureIncomingConnection(ApplicationConnection* connection) override; |
| 36 mojo::ApplicationConnection* connection) override; | |
| 37 | 36 |
| 38 // Called by the ViewProvider to create a view. | 37 // Called by the ViewProvider to create a view. |
| 39 // This method may be called multiple times in the case where the | 38 // This method may be called multiple times in the case where the |
| 40 // view provider is asked to create multiple view instances. | 39 // view provider is asked to create multiple view instances. |
| 41 // | 40 // |
| 42 // The |view_provider_url| is the connection URL of the view provider request. | 41 // The |view_provider_url| is the connection URL of the view provider request. |
| 43 // | 42 // |
| 44 // The |view_owner_request| should be attached to the newly created view | 43 // The |view_owner_request| should be attached to the newly created view |
| 45 // and closed or left pending if the view could not be created. | 44 // and closed or left pending if the view could not be created. |
| 46 // | 45 // |
| 47 // The |services| parameter is used to receive services from the view | 46 // The |services| parameter is used to receive services from the view |
| 48 // on behalf of the caller. | 47 // on behalf of the caller. |
| 49 // | 48 // |
| 50 // The |exposed_services| parameters is used to provide services to | 49 // The |exposed_services| parameters is used to provide services to |
| 51 // the view from the caller. | 50 // the view from the caller. |
| 52 virtual void CreateView( | 51 virtual void CreateView( |
| 53 const std::string& view_provider_url, | 52 const std::string& view_provider_url, |
| 54 mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request, | 53 InterfaceRequest<ViewOwner> view_owner_request, |
| 55 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 54 InterfaceRequest<ServiceProvider> services, |
| 56 mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services) = 0; | 55 InterfaceHandle<ServiceProvider> exposed_services) = 0; |
| 57 | 56 |
| 58 private: | 57 private: |
| 59 class DelegatingViewProvider; | 58 class DelegatingViewProvider; |
| 60 | 59 |
| 61 // |InterfaceFactory<mojo::ui::ViewProvider>|: | 60 // |InterfaceFactory<ViewProvider>|: |
| 62 void Create(mojo::ApplicationConnection* connection, | 61 void Create(const ConnectionContext& connection_context, |
| 63 mojo::InterfaceRequest<mojo::ui::ViewProvider> request) override; | 62 InterfaceRequest<ViewProvider> request) override; |
| 64 | 63 |
| 65 void CreateView( | 64 void CreateView(DelegatingViewProvider* provider, |
| 66 DelegatingViewProvider* provider, | 65 const std::string& view_provider_url, |
| 67 const std::string& view_provider_url, | 66 InterfaceRequest<ViewOwner> view_owner_request, |
| 68 mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request, | 67 InterfaceRequest<ServiceProvider> services, |
| 69 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 68 InterfaceHandle<ServiceProvider> exposed_services); |
| 70 mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services); | |
| 71 | 69 |
| 72 mojo::ApplicationImpl* app_impl_ = nullptr; | 70 ApplicationImpl* app_impl_ = nullptr; |
| 73 mojo::StrongBindingSet<mojo::ui::ViewProvider> bindings_; | 71 StrongBindingSet<ViewProvider> bindings_; |
| 74 | 72 |
| 75 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewProviderApp); | 73 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewProviderApp); |
| 76 }; | 74 }; |
| 77 | 75 |
| 78 } // namespace ui | 76 } // namespace ui |
| 79 } // namespace mojo | 77 } // namespace mojo |
| 80 | 78 |
| 81 #endif // MOJO_UI_VIEW_PROVIDER_APP_H_ | 79 #endif // MOJO_UI_VIEW_PROVIDER_APP_H_ |
| OLD | NEW |