Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / mojo / shell / application_instance.h
blobf50ab82113bb354afb54f2e45c4fb3a4864a6e8a
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_
8 #include <set>
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"
16 #include "url/gurl.h"
18 namespace mojo {
19 namespace shell {
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 {
26 public:
27 ApplicationInstance(ApplicationPtr application,
28 ApplicationManager* manager,
29 const Identity& originator_identity,
30 const Identity& resolved_identity,
31 const CapabilityFilter& filter,
32 const base::Closure& on_application_end);
34 ~ApplicationInstance() override;
36 void InitializeApplication();
38 void ConnectToClient(ApplicationInstance* originator,
39 const GURL& requested_url,
40 const GURL& requestor_url,
41 InterfaceRequest<ServiceProvider> services,
42 ServiceProviderPtr exposed_services,
43 const CapabilityFilter& filter);
45 // Returns the set of interfaces this application instance is allowed to see
46 // from an instance with |identity|.
47 AllowedInterfaces GetAllowedInterfaces(const Identity& identity) const;
49 Application* application() { return application_.get(); }
50 const Identity& identity() const { return identity_; }
51 base::Closure on_application_end() const { return on_application_end_; }
53 private:
54 // Shell implementation:
55 void ConnectToApplication(URLRequestPtr app_request,
56 InterfaceRequest<ServiceProvider> services,
57 ServiceProviderPtr exposed_services,
58 CapabilityFilterPtr filter) override;
59 void QuitApplication() override;
61 void CallAcceptConnection(ApplicationInstance* originator,
62 const GURL& url,
63 InterfaceRequest<ServiceProvider> services,
64 ServiceProviderPtr exposed_services,
65 const GURL& requested_url);
67 void OnConnectionError();
69 void OnQuitRequestedResult(bool can_quit);
71 struct QueuedClientRequest {
72 QueuedClientRequest();
73 ~QueuedClientRequest();
74 ApplicationInstance* originator;
75 GURL requested_url;
76 GURL requestor_url;
77 InterfaceRequest<ServiceProvider> services;
78 ServiceProviderPtr exposed_services;
79 CapabilityFilter filter;
82 ApplicationManager* const manager_;
83 const Identity originator_identity_;
84 const Identity identity_;
85 const CapabilityFilter filter_;
86 const bool allow_any_application_;
87 base::Closure on_application_end_;
88 ApplicationPtr application_;
89 Binding<Shell> binding_;
90 bool queue_requests_;
91 std::vector<QueuedClientRequest*> queued_client_requests_;
93 DISALLOW_COPY_AND_ASSIGN(ApplicationInstance);
96 } // namespace shell
97 } // namespace mojo
99 #endif // MOJO_SHELL_APPLICATION_INSTANCE_H_