| 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_SHELL_APPLICATION_INSTANCE_H_ | 5 #ifndef MOJO_SHELL_APPLICATION_INSTANCE_H_ |
| 6 #define MOJO_SHELL_APPLICATION_INSTANCE_H_ | 6 #define MOJO_SHELL_APPLICATION_INSTANCE_H_ |
| 7 | 7 |
| 8 #include <set> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "mojo/application/public/interfaces/application.mojom.h" | 11 #include "mojo/application/public/interfaces/application.mojom.h" |
| 10 #include "mojo/application/public/interfaces/shell.mojom.h" | 12 #include "mojo/application/public/interfaces/shell.mojom.h" |
| 11 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 12 #include "mojo/shell/identity.h" | 14 #include "mojo/shell/identity.h" |
| 13 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 14 | 16 |
| 15 namespace mojo { | 17 namespace mojo { |
| 18 |
| 19 // A |TypeConverter| that will create an |std::set<E>| containing a copy of |
| 20 // the contents of an |Array<T>|, using |TypeConverter<E, T>| to copy each |
| 21 // element. If the input array is null, the output set will be empty. |
| 22 template <typename E, typename T> |
| 23 struct TypeConverter <std::set<E>, Array<T>> { |
| 24 static std::set<E> Convert(const Array<T>& input) { |
| 25 std::set<E> result; |
| 26 if (!input.is_null()) { |
| 27 for (size_t i = 0; i < input.size(); ++i) |
| 28 result.insert(TypeConverter<E, T>::Convert(input[i])); |
| 29 } |
| 30 return result; |
| 31 } |
| 32 }; |
| 33 |
| 34 template <typename T, typename E> |
| 35 struct TypeConverter <Array<T>, std::set<E>> { |
| 36 static Array<T> Convert(const std::set<E>& input) { |
| 37 Array<T> result(0u); |
| 38 for (auto i : input) |
| 39 result.push_back(TypeConverter<T, E>::Convert(i)); |
| 40 return result.Pass(); |
| 41 } |
| 42 }; |
| 43 |
| 16 namespace shell { | 44 namespace shell { |
| 17 | 45 |
| 18 class ApplicationManager; | 46 class ApplicationManager; |
| 19 | 47 |
| 20 // Encapsulates a connection to an instance of an application, tracked by the | 48 // Encapsulates a connection to an instance of an application, tracked by the |
| 21 // shell's ApplicationManager. | 49 // shell's ApplicationManager. |
| 22 // TODO(beng): Currently this provides a default implementation of the Shell | |
| 23 // interface. This should be moved into a separate class RootShell | |
| 24 // which is instantiated when no other Shell implementation is | |
| 25 // provided via ConnectToApplication(). | |
| 26 class ApplicationInstance : public Shell { | 50 class ApplicationInstance : public Shell { |
| 27 public: | 51 public: |
| 52 using AllowedInterfaces = std::set<std::string>; |
| 53 using CapabilityFilter = std::map<std::string, AllowedInterfaces>; |
| 54 |
| 28 ApplicationInstance(ApplicationPtr application, | 55 ApplicationInstance(ApplicationPtr application, |
| 29 ApplicationManager* manager, | 56 ApplicationManager* manager, |
| 30 const Identity& resolved_identity, | 57 const Identity& resolved_identity, |
| 58 const CapabilityFilter& filter, |
| 31 const base::Closure& on_application_end); | 59 const base::Closure& on_application_end); |
| 32 | 60 |
| 33 ~ApplicationInstance() override; | 61 ~ApplicationInstance() override; |
| 34 | 62 |
| 35 void InitializeApplication(); | 63 void InitializeApplication(); |
| 36 | 64 |
| 37 void ConnectToClient(const GURL& requested_url, | 65 void ConnectToClient(ApplicationInstance* originator, |
| 66 const GURL& requested_url, |
| 38 const GURL& requestor_url, | 67 const GURL& requestor_url, |
| 39 InterfaceRequest<ServiceProvider> services, | 68 InterfaceRequest<ServiceProvider> services, |
| 40 ServiceProviderPtr exposed_services); | 69 ServiceProviderPtr exposed_services, |
| 70 CapabilityFilterPtr filter); |
| 71 |
| 72 // Returns the set of interfaces this application instance is allowed to see |
| 73 // from an instance with |identity|. |
| 74 AllowedInterfaces GetAllowedInterfaces(const Identity& identity) const; |
| 41 | 75 |
| 42 Application* application() { return application_.get(); } | 76 Application* application() { return application_.get(); } |
| 43 const Identity& identity() const { return identity_; } | 77 const Identity& identity() const { return identity_; } |
| 44 base::Closure on_application_end() const { return on_application_end_; } | 78 base::Closure on_application_end() const { return on_application_end_; } |
| 45 | 79 |
| 46 private: | 80 private: |
| 47 // Shell implementation: | 81 // Shell implementation: |
| 48 void ConnectToApplication(mojo::URLRequestPtr app_request, | 82 void ConnectToApplication(URLRequestPtr app_request, |
| 49 InterfaceRequest<ServiceProvider> services, | 83 InterfaceRequest<ServiceProvider> services, |
| 50 ServiceProviderPtr exposed_services) override; | 84 ServiceProviderPtr exposed_services, |
| 85 CapabilityFilterPtr filter) override; |
| 51 void QuitApplication() override; | 86 void QuitApplication() override; |
| 52 | 87 |
| 88 void CallAcceptConnection(ApplicationInstance* originator, |
| 89 const GURL& url, |
| 90 InterfaceRequest<ServiceProvider> services, |
| 91 ServiceProviderPtr exposed_services, |
| 92 const GURL& requested_url); |
| 93 |
| 53 void OnConnectionError(); | 94 void OnConnectionError(); |
| 54 | 95 |
| 55 void OnQuitRequestedResult(bool can_quit); | 96 void OnQuitRequestedResult(bool can_quit); |
| 56 | 97 |
| 57 struct QueuedClientRequest { | 98 struct QueuedClientRequest { |
| 58 QueuedClientRequest(); | 99 QueuedClientRequest(); |
| 59 ~QueuedClientRequest(); | 100 ~QueuedClientRequest(); |
| 101 ApplicationInstance* originator; |
| 60 GURL requested_url; | 102 GURL requested_url; |
| 61 GURL requestor_url; | 103 GURL requestor_url; |
| 62 InterfaceRequest<ServiceProvider> services; | 104 InterfaceRequest<ServiceProvider> services; |
| 63 ServiceProviderPtr exposed_services; | 105 ServiceProviderPtr exposed_services; |
| 106 CapabilityFilterPtr filter; |
| 64 }; | 107 }; |
| 65 | 108 |
| 66 ApplicationManager* const manager_; | 109 ApplicationManager* const manager_; |
| 67 const Identity identity_; | 110 const Identity identity_; |
| 111 const CapabilityFilter filter_; |
| 112 const bool allow_any_application_; |
| 68 base::Closure on_application_end_; | 113 base::Closure on_application_end_; |
| 69 ApplicationPtr application_; | 114 ApplicationPtr application_; |
| 70 Binding<Shell> binding_; | 115 Binding<Shell> binding_; |
| 71 bool queue_requests_; | 116 bool queue_requests_; |
| 72 std::vector<QueuedClientRequest*> queued_client_requests_; | 117 std::vector<QueuedClientRequest*> queued_client_requests_; |
| 73 | 118 |
| 74 DISALLOW_COPY_AND_ASSIGN(ApplicationInstance); | 119 DISALLOW_COPY_AND_ASSIGN(ApplicationInstance); |
| 75 }; | 120 }; |
| 76 | 121 |
| 77 } // namespace shell | 122 } // namespace shell |
| 78 } // namespace mojo | 123 } // namespace mojo |
| 79 | 124 |
| 80 #endif // MOJO_SHELL_APPLICATION_INSTANCE_H_ | 125 #endif // MOJO_SHELL_APPLICATION_INSTANCE_H_ |
| OLD | NEW |