Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: mojo/shell/application_instance.h

Issue 1244233002: Allow trusted brokers to restrict connections for spawned applications to whitelisted applications … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // TODO(beng): upstream this into mojo repo, array.h so it can be shared with
20 // application_impl.cc.
21 // A |TypeConverter| that will create an |std::set<E>| containing a copy of
22 // the contents of an |Array<T>|, using |TypeConverter<E, T>| to copy each
23 // element. If the input array is null, the output set will be empty.
24 template <typename E, typename T>
25 struct TypeConverter <std::set<E>, Array<T>> {
26 static std::set<E> Convert(const Array<T>& input) {
27 std::set<E> result;
28 if (!input.is_null()) {
29 for (size_t i = 0; i < input.size(); ++i)
30 result.insert(TypeConverter<E, T>::Convert(input[i]));
31 }
32 return result;
33 }
34 };
35
36 template <typename T, typename E>
37 struct TypeConverter <Array<T>, std::set<E>> {
38 static Array<T> Convert(const std::set<E>& input) {
39 Array<T> result(0u);
40 for (auto i : input)
41 result.push_back(TypeConverter<T, E>::Convert(i));
42 return result.Pass();
43 }
44 };
45
16 namespace shell { 46 namespace shell {
17 47
18 class ApplicationManager; 48 class ApplicationManager;
19 49
20 // Encapsulates a connection to an instance of an application, tracked by the 50 // Encapsulates a connection to an instance of an application, tracked by the
21 // shell's ApplicationManager. 51 // 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 { 52 class ApplicationInstance : public Shell {
27 public: 53 public:
54 using AllowedInterfaces = std::set<std::string>;
55 using CapabilityFilter = std::map<std::string, AllowedInterfaces>;
56
28 ApplicationInstance(ApplicationPtr application, 57 ApplicationInstance(ApplicationPtr application,
29 ApplicationManager* manager, 58 ApplicationManager* manager,
30 const Identity& resolved_identity, 59 const Identity& resolved_identity,
60 const CapabilityFilter& filter,
31 const base::Closure& on_application_end); 61 const base::Closure& on_application_end);
32 62
33 ~ApplicationInstance() override; 63 ~ApplicationInstance() override;
34 64
35 void InitializeApplication(); 65 void InitializeApplication();
36 66
37 void ConnectToClient(const GURL& requested_url, 67 void ConnectToClient(ApplicationInstance* originator,
68 const GURL& requested_url,
38 const GURL& requestor_url, 69 const GURL& requestor_url,
39 InterfaceRequest<ServiceProvider> services, 70 InterfaceRequest<ServiceProvider> services,
40 ServiceProviderPtr exposed_services); 71 ServiceProviderPtr exposed_services,
72 CapabilityFilterPtr filter);
73
74 // Returns the set of interfaces this application instance is allowed to see
75 // from an instance with |identity|.
76 AllowedInterfaces GetAllowedInterfaces(const Identity& identity) const;
41 77
42 Application* application() { return application_.get(); } 78 Application* application() { return application_.get(); }
43 const Identity& identity() const { return identity_; } 79 const Identity& identity() const { return identity_; }
44 base::Closure on_application_end() const { return on_application_end_; } 80 base::Closure on_application_end() const { return on_application_end_; }
45 81
46 private: 82 private:
47 // Shell implementation: 83 // Shell implementation:
48 void ConnectToApplication(mojo::URLRequestPtr app_request, 84 void ConnectToApplication(URLRequestPtr app_request,
49 InterfaceRequest<ServiceProvider> services, 85 InterfaceRequest<ServiceProvider> services,
50 ServiceProviderPtr exposed_services) override; 86 ServiceProviderPtr exposed_services,
87 CapabilityFilterPtr filter) override;
51 void QuitApplication() override; 88 void QuitApplication() override;
52 89
90 void CallAcceptConnection(ApplicationInstance* originator,
91 const GURL& url,
92 InterfaceRequest<ServiceProvider> services,
93 ServiceProviderPtr exposed_services,
94 const GURL& requested_url);
95
53 void OnConnectionError(); 96 void OnConnectionError();
54 97
55 void OnQuitRequestedResult(bool can_quit); 98 void OnQuitRequestedResult(bool can_quit);
56 99
57 struct QueuedClientRequest { 100 struct QueuedClientRequest {
58 QueuedClientRequest(); 101 QueuedClientRequest();
59 ~QueuedClientRequest(); 102 ~QueuedClientRequest();
103 ApplicationInstance* originator;
60 GURL requested_url; 104 GURL requested_url;
61 GURL requestor_url; 105 GURL requestor_url;
62 InterfaceRequest<ServiceProvider> services; 106 InterfaceRequest<ServiceProvider> services;
63 ServiceProviderPtr exposed_services; 107 ServiceProviderPtr exposed_services;
108 CapabilityFilterPtr filter;
64 }; 109 };
65 110
66 ApplicationManager* const manager_; 111 ApplicationManager* const manager_;
67 const Identity identity_; 112 const Identity identity_;
113 const CapabilityFilter filter_;
114 const bool allow_any_application_;
68 base::Closure on_application_end_; 115 base::Closure on_application_end_;
69 ApplicationPtr application_; 116 ApplicationPtr application_;
70 Binding<Shell> binding_; 117 Binding<Shell> binding_;
71 bool queue_requests_; 118 bool queue_requests_;
72 std::vector<QueuedClientRequest*> queued_client_requests_; 119 std::vector<QueuedClientRequest*> queued_client_requests_;
73 120
74 DISALLOW_COPY_AND_ASSIGN(ApplicationInstance); 121 DISALLOW_COPY_AND_ASSIGN(ApplicationInstance);
75 }; 122 };
76 123
77 } // namespace shell 124 } // namespace shell
78 } // namespace mojo 125 } // namespace mojo
79 126
80 #endif // MOJO_SHELL_APPLICATION_INSTANCE_H_ 127 #endif // MOJO_SHELL_APPLICATION_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698