Chromium Code Reviews| Index: mojo/shell/application_instance.h |
| diff --git a/mojo/shell/application_instance.h b/mojo/shell/application_instance.h |
| index 5340298dc05f355640b4989f622c3b070e02028c..6b78006d9e99b26ce151d0cdb17c449623512ee5 100644 |
| --- a/mojo/shell/application_instance.h |
| +++ b/mojo/shell/application_instance.h |
| @@ -5,6 +5,8 @@ |
| #ifndef MOJO_SHELL_APPLICATION_INSTANCE_H_ |
| #define MOJO_SHELL_APPLICATION_INSTANCE_H_ |
| +#include <set> |
| + |
| #include "base/callback.h" |
| #include "mojo/application/public/interfaces/application.mojom.h" |
| #include "mojo/application/public/interfaces/shell.mojom.h" |
| @@ -17,27 +19,58 @@ namespace shell { |
| class ApplicationManager; |
| +// A |TypeConverter| that will create an |std::set<E>| containing a copy of |
| +// the contents of an |Array<T>|, using |TypeConverter<E, T>| to copy each |
| +// element. If the input array is null, the output set will be empty. |
| +template <typename E, typename T> |
| +struct TypeConverter <std::set<E>, Array<T>> { |
|
yzshen1
2015/07/22 22:26:47
Please consider share this code with application_i
|
| + static std::set<E> Convert(const Array<T>& input) { |
| + std::set<E> result; |
| + if (!input.is_null()) { |
| + for (size_t i = 0; i < input.size(); ++i) |
| + result.insert(TypeConverter<E, T>::Convert(input[i])); |
| + } |
| + return result; |
| + } |
| +}; |
| + |
| +template <typename T, typename E> |
| +struct TypeConverter <Array<T>, std::set<E>> { |
| + static Array<T> Convert(const std::set<E>& input) { |
| + Array<T> result(0u); |
| + for (auto i : input) |
| + result.push_back(TypeConverter<T, E>::Convert(i)); |
| + return result.Pass(); |
| + } |
| +}; |
| + |
| // Encapsulates a connection to an instance of an application, tracked by the |
| // shell's ApplicationManager. |
| -// TODO(beng): Currently this provides a default implementation of the Shell |
| -// interface. This should be moved into a separate class RootShell |
| -// which is instantiated when no other Shell implementation is |
| -// provided via ConnectToApplication(). |
| class ApplicationInstance : public Shell { |
| public: |
| + using AllowedInterfaces = std::set <std::string> ; |
|
jam
2015/07/22 19:47:40
nit: here and below extra spaces before and after
|
| + using CapabilityFilter = std::map <std::string, AllowedInterfaces> ; |
| + |
| ApplicationInstance(ApplicationPtr application, |
| ApplicationManager* manager, |
| const Identity& resolved_identity, |
| + const CapabilityFilter& filter, |
| const base::Closure& on_application_end); |
| ~ApplicationInstance() override; |
| void InitializeApplication(); |
| - void ConnectToClient(const GURL& requested_url, |
| + void ConnectToClient(ApplicationInstance* originator, |
| + const GURL& requested_url, |
| const GURL& requestor_url, |
| InterfaceRequest<ServiceProvider> services, |
| - ServiceProviderPtr exposed_services); |
| + ServiceProviderPtr exposed_services, |
| + CapabilityFilterPtr filter); |
| + |
| + // Returns the set of interfaces this application instance is allowed to see |
| + // from an instance with |identity|. |
| + AllowedInterfaces GetAllowedInterfaces(const Identity& identity) const; |
| Application* application() { return application_.get(); } |
| const Identity& identity() const { return identity_; } |
| @@ -45,11 +78,18 @@ class ApplicationInstance : public Shell { |
| private: |
| // Shell implementation: |
| - void ConnectToApplication(mojo::URLRequestPtr app_request, |
| + void ConnectToApplication(URLRequestPtr app_request, |
| InterfaceRequest<ServiceProvider> services, |
| - ServiceProviderPtr exposed_services) override; |
| + ServiceProviderPtr exposed_services, |
| + CapabilityFilterPtr filter) override; |
| void QuitApplication() override; |
| + void CallAcceptConnection(ApplicationInstance* originator, |
| + const GURL& url, |
| + InterfaceRequest<ServiceProvider> services, |
| + ServiceProviderPtr exposed_services, |
| + const GURL& requested_url); |
| + |
| void OnConnectionError(); |
| void OnQuitRequestedResult(bool can_quit); |
| @@ -57,14 +97,17 @@ class ApplicationInstance : public Shell { |
| struct QueuedClientRequest { |
| QueuedClientRequest(); |
| ~QueuedClientRequest(); |
| + ApplicationInstance* originator; |
| GURL requested_url; |
| GURL requestor_url; |
| InterfaceRequest<ServiceProvider> services; |
| ServiceProviderPtr exposed_services; |
| + CapabilityFilterPtr filter; |
| }; |
| ApplicationManager* const manager_; |
| const Identity identity_; |
| + CapabilityFilter filter_; |
| base::Closure on_application_end_; |
| ApplicationPtr application_; |
| Binding<Shell> binding_; |