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> | 8 #include <set> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "mojo/application/public/interfaces/application.mojom.h" | 11 #include "mojo/application/public/interfaces/application.mojom.h" |
12 #include "mojo/application/public/interfaces/shell.mojom.h" | 12 #include "mojo/application/public/interfaces/shell.mojom.h" |
13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
14 #include "mojo/shell/capability_filter.h" | 14 #include "mojo/shell/capability_filter.h" |
15 #include "mojo/shell/identity.h" | 15 #include "mojo/shell/identity.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace mojo { | 18 namespace mojo { |
19 namespace shell { | 19 namespace shell { |
20 | 20 |
21 class ApplicationManager; | 21 class ApplicationManager; |
22 | 22 |
23 // Encapsulates a connection to an instance of an application, tracked by the | 23 // Encapsulates a connection to an instance of an application, tracked by the |
24 // shell's ApplicationManager. | 24 // shell's ApplicationManager. |
25 class ApplicationInstance : public Shell { | 25 class ApplicationInstance : public Shell { |
26 public: | 26 public: |
| 27 // |requesting_content_handler_id| is the id of the content handler that |
| 28 // loaded this app. If the app was not loaded by a content handler the id |
| 29 // is kInvalidContentHandlerID. |
27 ApplicationInstance(ApplicationPtr application, | 30 ApplicationInstance(ApplicationPtr application, |
28 ApplicationManager* manager, | 31 ApplicationManager* manager, |
29 const Identity& originator_identity, | 32 const Identity& originator_identity, |
30 const Identity& resolved_identity, | 33 const Identity& resolved_identity, |
31 const CapabilityFilter& filter, | 34 const CapabilityFilter& filter, |
| 35 uint32_t requesting_content_handler_id, |
32 const base::Closure& on_application_end); | 36 const base::Closure& on_application_end); |
33 | 37 |
34 ~ApplicationInstance() override; | 38 ~ApplicationInstance() override; |
35 | 39 |
36 void InitializeApplication(); | 40 void InitializeApplication(); |
37 | 41 |
38 void ConnectToClient(ApplicationInstance* originator, | 42 void ConnectToClient(ApplicationInstance* originator, |
39 const GURL& requested_url, | 43 const GURL& requested_url, |
40 const GURL& requestor_url, | 44 const GURL& requestor_url, |
41 InterfaceRequest<ServiceProvider> services, | 45 InterfaceRequest<ServiceProvider> services, |
42 ServiceProviderPtr exposed_services, | 46 ServiceProviderPtr exposed_services, |
43 const CapabilityFilter& filter); | 47 const CapabilityFilter& filter, |
| 48 const ConnectToApplicationCallback& callback); |
44 | 49 |
45 // Returns the set of interfaces this application instance is allowed to see | 50 // Returns the set of interfaces this application instance is allowed to see |
46 // from an instance with |identity|. | 51 // from an instance with |identity|. |
47 AllowedInterfaces GetAllowedInterfaces(const Identity& identity) const; | 52 AllowedInterfaces GetAllowedInterfaces(const Identity& identity) const; |
48 | 53 |
49 Application* application() { return application_.get(); } | 54 Application* application() { return application_.get(); } |
50 const Identity& identity() const { return identity_; } | 55 const Identity& identity() const { return identity_; } |
51 base::Closure on_application_end() const { return on_application_end_; } | 56 base::Closure on_application_end() const { return on_application_end_; } |
| 57 void set_requesting_content_handler_id(uint32_t id) { |
| 58 requesting_content_handler_id_ = id; |
| 59 } |
| 60 uint32_t requesting_content_handler_id() const { |
| 61 return requesting_content_handler_id_; |
| 62 } |
52 | 63 |
53 private: | 64 private: |
54 // Shell implementation: | 65 // Shell implementation: |
55 void ConnectToApplication(URLRequestPtr app_request, | 66 void ConnectToApplication( |
56 InterfaceRequest<ServiceProvider> services, | 67 URLRequestPtr app_request, |
57 ServiceProviderPtr exposed_services, | 68 InterfaceRequest<ServiceProvider> services, |
58 CapabilityFilterPtr filter) override; | 69 ServiceProviderPtr exposed_services, |
| 70 CapabilityFilterPtr filter, |
| 71 const ConnectToApplicationCallback& callback) override; |
59 void QuitApplication() override; | 72 void QuitApplication() override; |
60 | 73 |
61 void CallAcceptConnection(ApplicationInstance* originator, | 74 void CallAcceptConnection(ApplicationInstance* originator, |
62 const GURL& url, | 75 const GURL& url, |
63 InterfaceRequest<ServiceProvider> services, | 76 InterfaceRequest<ServiceProvider> services, |
64 ServiceProviderPtr exposed_services, | 77 ServiceProviderPtr exposed_services, |
65 const GURL& requested_url); | 78 const GURL& requested_url); |
66 | 79 |
67 void OnConnectionError(); | 80 void OnConnectionError(); |
68 | 81 |
69 void OnQuitRequestedResult(bool can_quit); | 82 void OnQuitRequestedResult(bool can_quit); |
70 | 83 |
71 struct QueuedClientRequest { | 84 struct QueuedClientRequest { |
72 QueuedClientRequest(); | 85 QueuedClientRequest(); |
73 ~QueuedClientRequest(); | 86 ~QueuedClientRequest(); |
74 ApplicationInstance* originator; | 87 ApplicationInstance* originator; |
75 GURL requested_url; | 88 GURL requested_url; |
76 GURL requestor_url; | 89 GURL requestor_url; |
77 InterfaceRequest<ServiceProvider> services; | 90 InterfaceRequest<ServiceProvider> services; |
78 ServiceProviderPtr exposed_services; | 91 ServiceProviderPtr exposed_services; |
79 CapabilityFilter filter; | 92 CapabilityFilter filter; |
| 93 ConnectToApplicationCallback connect_callback; |
80 }; | 94 }; |
81 | 95 |
82 ApplicationManager* const manager_; | 96 ApplicationManager* const manager_; |
83 const Identity originator_identity_; | 97 const Identity originator_identity_; |
84 const Identity identity_; | 98 const Identity identity_; |
85 const CapabilityFilter filter_; | 99 const CapabilityFilter filter_; |
86 const bool allow_any_application_; | 100 const bool allow_any_application_; |
| 101 uint32_t requesting_content_handler_id_; |
87 base::Closure on_application_end_; | 102 base::Closure on_application_end_; |
88 ApplicationPtr application_; | 103 ApplicationPtr application_; |
89 Binding<Shell> binding_; | 104 Binding<Shell> binding_; |
90 bool queue_requests_; | 105 bool queue_requests_; |
91 std::vector<QueuedClientRequest*> queued_client_requests_; | 106 std::vector<QueuedClientRequest*> queued_client_requests_; |
92 | 107 |
93 DISALLOW_COPY_AND_ASSIGN(ApplicationInstance); | 108 DISALLOW_COPY_AND_ASSIGN(ApplicationInstance); |
94 }; | 109 }; |
95 | 110 |
96 } // namespace shell | 111 } // namespace shell |
97 } // namespace mojo | 112 } // namespace mojo |
98 | 113 |
99 #endif // MOJO_SHELL_APPLICATION_INSTANCE_H_ | 114 #endif // MOJO_SHELL_APPLICATION_INSTANCE_H_ |
OLD | NEW |