OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_H_ |
| 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_H_ |
| 7 |
| 8 #include "mojo/shell/public/cpp/app_lifetime_helper.h" |
| 9 #include "mojo/shell/public/cpp/application_connection.h" |
| 10 #include "mojo/shell/public/interfaces/application.mojom.h" |
| 11 #include "mojo/shell/public/interfaces/shell.mojom.h" |
| 12 |
| 13 namespace mojo { |
| 14 |
| 15 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter(); |
| 16 |
| 17 using ApplicationRequest = InterfaceRequest<shell::mojom::Application>; |
| 18 |
| 19 class Shell { |
| 20 public: |
| 21 class ConnectParams { |
| 22 public: |
| 23 explicit ConnectParams(const std::string& url); |
| 24 explicit ConnectParams(URLRequestPtr request); |
| 25 ~ConnectParams(); |
| 26 |
| 27 URLRequestPtr TakeRequest() { return std::move(request_); } |
| 28 shell::mojom::CapabilityFilterPtr TakeFilter() { |
| 29 return std::move(filter_); |
| 30 } |
| 31 void set_filter(shell::mojom::CapabilityFilterPtr filter) { |
| 32 filter_ = std::move(filter); |
| 33 } |
| 34 |
| 35 private: |
| 36 URLRequestPtr request_; |
| 37 shell::mojom::CapabilityFilterPtr filter_; |
| 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(ConnectParams); |
| 40 }; |
| 41 |
| 42 // Requests a new connection to an application. Returns a pointer to the |
| 43 // connection if the connection is permitted by this application's delegate, |
| 44 // or nullptr otherwise. Caller takes ownership. |
| 45 virtual scoped_ptr<ApplicationConnection> ConnectToApplication( |
| 46 const std::string& url) = 0; |
| 47 virtual scoped_ptr<ApplicationConnection> ConnectToApplication( |
| 48 ConnectParams* params) = 0; |
| 49 |
| 50 // Connect to application identified by |request->url| and connect to the |
| 51 // service implementation of the interface identified by |Interface|. |
| 52 template <typename Interface> |
| 53 void ConnectToService(ConnectParams* params, InterfacePtr<Interface>* ptr) { |
| 54 scoped_ptr<ApplicationConnection> connection = ConnectToApplication(params); |
| 55 if (!connection.get()) |
| 56 return; |
| 57 connection->ConnectToService(ptr); |
| 58 } |
| 59 template <typename Interface> |
| 60 void ConnectToService(const std::string& url, InterfacePtr<Interface>* ptr) { |
| 61 ConnectParams params(url); |
| 62 params.set_filter(CreatePermissiveCapabilityFilter()); |
| 63 return ConnectToService(¶ms, ptr); |
| 64 } |
| 65 |
| 66 // Initiate shutdown of this application. This may involve a round trip to the |
| 67 // Shell to ensure there are no inbound service requests. |
| 68 virtual void Quit() = 0; |
| 69 |
| 70 // Create an object that can be used to refcount the lifetime of the |
| 71 // application. The returned object may be cloned, and when the refcount falls |
| 72 // to zero Quit() is called. |
| 73 virtual scoped_ptr<AppRefCount> CreateAppRefCount() = 0; |
| 74 }; |
| 75 |
| 76 } // namespace mojo |
| 77 |
| 78 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_H_ |
OLD | NEW |