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
3 // found in the LICENSE file.
5 #ifndef MOJO_SHELL_APPLICATION_INSTANCE_H_
6 #define MOJO_SHELL_APPLICATION_INSTANCE_H_
10 #include "base/callback.h"
11 #include "mojo/application/public/interfaces/application.mojom.h"
12 #include "mojo/application/public/interfaces/shell.mojom.h"
13 #include "mojo/public/cpp/bindings/binding.h"
14 #include "mojo/shell/capability_filter.h"
15 #include "mojo/shell/identity.h"
21 class ApplicationManager
;
23 // Encapsulates a connection to an instance of an application, tracked by the
24 // shell's ApplicationManager.
25 class ApplicationInstance
: public Shell
{
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.
30 ApplicationInstance(ApplicationPtr application
,
31 ApplicationManager
* manager
,
32 const Identity
& originator_identity
,
33 const Identity
& resolved_identity
,
34 const CapabilityFilter
& filter
,
35 uint32_t requesting_content_handler_id
,
36 const base::Closure
& on_application_end
);
38 ~ApplicationInstance() override
;
40 void InitializeApplication();
42 void ConnectToClient(ApplicationInstance
* originator
,
43 const GURL
& requested_url
,
44 const GURL
& requestor_url
,
45 InterfaceRequest
<ServiceProvider
> services
,
46 ServiceProviderPtr exposed_services
,
47 const CapabilityFilter
& filter
,
48 const ConnectToApplicationCallback
& callback
);
50 // Returns the set of interfaces this application instance is allowed to see
51 // from an instance with |identity|.
52 AllowedInterfaces
GetAllowedInterfaces(const Identity
& identity
) const;
54 Application
* application() { return application_
.get(); }
55 const Identity
& identity() const { return identity_
; }
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
;
60 uint32_t requesting_content_handler_id() const {
61 return requesting_content_handler_id_
;
65 // Shell implementation:
66 void ConnectToApplication(
67 URLRequestPtr app_request
,
68 InterfaceRequest
<ServiceProvider
> services
,
69 ServiceProviderPtr exposed_services
,
70 CapabilityFilterPtr filter
,
71 const ConnectToApplicationCallback
& callback
) override
;
72 void QuitApplication() override
;
74 void CallAcceptConnection(ApplicationInstance
* originator
,
76 InterfaceRequest
<ServiceProvider
> services
,
77 ServiceProviderPtr exposed_services
,
78 const GURL
& requested_url
);
80 void OnConnectionError();
82 void OnQuitRequestedResult(bool can_quit
);
84 struct QueuedClientRequest
{
85 QueuedClientRequest();
86 ~QueuedClientRequest();
87 ApplicationInstance
* originator
;
90 InterfaceRequest
<ServiceProvider
> services
;
91 ServiceProviderPtr exposed_services
;
92 CapabilityFilter filter
;
93 ConnectToApplicationCallback connect_callback
;
96 ApplicationManager
* const manager_
;
97 const Identity originator_identity_
;
98 const Identity identity_
;
99 const CapabilityFilter filter_
;
100 const bool allow_any_application_
;
101 uint32_t requesting_content_handler_id_
;
102 base::Closure on_application_end_
;
103 ApplicationPtr application_
;
104 Binding
<Shell
> binding_
;
105 bool queue_requests_
;
106 std::vector
<QueuedClientRequest
*> queued_client_requests_
;
108 DISALLOW_COPY_AND_ASSIGN(ApplicationInstance
);
114 #endif // MOJO_SHELL_APPLICATION_INSTANCE_H_