| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ |
| 6 #define MOJO_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "mojo/shell/public/cpp/connection.h" | 14 #include "mojo/shell/public/cpp/connection.h" |
| 15 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" | 15 #include "mojo/shell/public/interfaces/interface_provider.mojom.h" |
| 16 #include "mojo/shell/public/interfaces/shell.mojom.h" | 16 #include "mojo/shell/public/interfaces/shell.mojom.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 namespace internal { | 19 namespace internal { |
| 20 | 20 |
| 21 // A ConnectionImpl represents each half of a connection between two | 21 // A ConnectionImpl represents each half of a connection between two |
| 22 // applications, allowing customization of which interfaces are published to the | 22 // applications, allowing customization of which interfaces are published to the |
| 23 // other. | 23 // other. |
| 24 class ConnectionImpl : public Connection, public InterfaceProvider { | 24 class ConnectionImpl : public Connection, |
| 25 public shell::mojom::InterfaceProvider { |
| 25 public: | 26 public: |
| 26 class TestApi { | 27 class TestApi { |
| 27 public: | 28 public: |
| 28 explicit TestApi(ConnectionImpl* impl) : impl_(impl) {} | 29 explicit TestApi(ConnectionImpl* impl) : impl_(impl) {} |
| 29 ~TestApi() {} | 30 ~TestApi() {} |
| 30 | 31 |
| 31 void SetInterfaceBinderForName(InterfaceBinder* binder, | 32 void SetInterfaceBinderForName(InterfaceBinder* binder, |
| 32 const std::string& interface_name) { | 33 const std::string& interface_name) { |
| 33 impl_->SetInterfaceBinderForName(binder, interface_name); | 34 impl_->SetInterfaceBinderForName(binder, interface_name); |
| 34 } | 35 } |
| 35 void RemoveInterfaceBinderForName(const std::string& interface_name) { | 36 void RemoveInterfaceBinderForName(const std::string& interface_name) { |
| 36 impl_->RemoveInterfaceBinderForName(interface_name); | 37 impl_->RemoveInterfaceBinderForName(interface_name); |
| 37 } | 38 } |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 ConnectionImpl* impl_; | 41 ConnectionImpl* impl_; |
| 41 DISALLOW_COPY_AND_ASSIGN(TestApi); | 42 DISALLOW_COPY_AND_ASSIGN(TestApi); |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 ConnectionImpl(); | 45 ConnectionImpl(); |
| 45 // |allowed_interfaces| are the set of interfaces that the shell has allowed | 46 // |allowed_interfaces| are the set of interfaces that the shell has allowed |
| 46 // an application to expose to another application. If this set contains only | 47 // an application to expose to another application. If this set contains only |
| 47 // the string value "*" all interfaces may be exposed. | 48 // the string value "*" all interfaces may be exposed. |
| 48 ConnectionImpl(const std::string& connection_url, | 49 ConnectionImpl(const std::string& connection_url, |
| 49 const std::string& remote_url, | 50 const std::string& remote_url, |
| 50 uint32_t remote_id, | 51 uint32_t remote_id, |
| 51 InterfaceProviderPtr remote_interfaces, | 52 shell::mojom::InterfaceProviderPtr remote_interfaces, |
| 52 InterfaceRequest<InterfaceProvider> local_interfaces, | 53 shell::mojom::InterfaceProviderRequest local_interfaces, |
| 53 const std::set<std::string>& allowed_interfaces); | 54 const std::set<std::string>& allowed_interfaces); |
| 54 ~ConnectionImpl() override; | 55 ~ConnectionImpl() override; |
| 55 | 56 |
| 56 shell::mojom::Shell::ConnectToApplicationCallback | 57 shell::mojom::Shell::ConnectToApplicationCallback |
| 57 GetConnectToApplicationCallback(); | 58 GetConnectToApplicationCallback(); |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 using NameToInterfaceBinderMap = std::map<std::string, InterfaceBinder*>; | 61 using NameToInterfaceBinderMap = std::map<std::string, InterfaceBinder*>; |
| 61 | 62 |
| 62 // Connection: | 63 // Connection: |
| 63 void SetDefaultInterfaceBinder(InterfaceBinder* binder) override; | 64 void SetDefaultInterfaceBinder(InterfaceBinder* binder) override; |
| 64 bool SetInterfaceBinderForName(InterfaceBinder* binder, | 65 bool SetInterfaceBinderForName(InterfaceBinder* binder, |
| 65 const std::string& interface_name) override; | 66 const std::string& interface_name) override; |
| 66 const std::string& GetConnectionURL() override; | 67 const std::string& GetConnectionURL() override; |
| 67 const std::string& GetRemoteApplicationURL() override; | 68 const std::string& GetRemoteApplicationURL() override; |
| 68 InterfaceProvider* GetRemoteInterfaces() override; | 69 shell::mojom::InterfaceProvider* GetRemoteInterfaces() override; |
| 69 InterfaceProvider* GetLocalInterfaces() override; | 70 shell::mojom::InterfaceProvider* GetLocalInterfaces() override; |
| 70 void SetRemoteInterfaceProviderConnectionErrorHandler( | 71 void SetRemoteInterfaceProviderConnectionErrorHandler( |
| 71 const Closure& handler) override; | 72 const Closure& handler) override; |
| 72 bool GetRemoteApplicationID(uint32_t* remote_id) const override; | 73 bool GetRemoteApplicationID(uint32_t* remote_id) const override; |
| 73 bool GetRemoteContentHandlerID(uint32_t* content_handler_id) const override; | 74 bool GetRemoteContentHandlerID(uint32_t* content_handler_id) const override; |
| 74 void AddRemoteIDCallback(const Closure& callback) override; | 75 void AddRemoteIDCallback(const Closure& callback) override; |
| 75 base::WeakPtr<Connection> GetWeakPtr() override; | 76 base::WeakPtr<Connection> GetWeakPtr() override; |
| 76 | 77 |
| 77 // InterfaceProvider: | 78 // InterfaceProvider: |
| 78 void GetInterface(const mojo::String& interface_name, | 79 void GetInterface(const mojo::String& interface_name, |
| 79 ScopedMessagePipeHandle handle) override; | 80 ScopedMessagePipeHandle handle) override; |
| 80 | 81 |
| 81 void RemoveInterfaceBinderForName(const std::string& interface_name); | 82 void RemoveInterfaceBinderForName(const std::string& interface_name); |
| 82 void OnGotRemoteIDs(uint32_t target_application_id, | 83 void OnGotRemoteIDs(uint32_t target_application_id, |
| 83 uint32_t content_handler_id); | 84 uint32_t content_handler_id); |
| 84 | 85 |
| 85 const std::string connection_url_; | 86 const std::string connection_url_; |
| 86 const std::string remote_url_; | 87 const std::string remote_url_; |
| 87 | 88 |
| 88 uint32_t remote_id_; | 89 uint32_t remote_id_; |
| 89 // The id of the content_handler is only available once the callback from | 90 // The id of the content_handler is only available once the callback from |
| 90 // establishing the connection is made. | 91 // establishing the connection is made. |
| 91 uint32_t content_handler_id_; | 92 uint32_t content_handler_id_; |
| 92 bool remote_ids_valid_; | 93 bool remote_ids_valid_; |
| 93 std::vector<Closure> remote_id_callbacks_; | 94 std::vector<Closure> remote_id_callbacks_; |
| 94 | 95 |
| 95 Binding<InterfaceProvider> local_binding_; | 96 Binding<shell::mojom::InterfaceProvider> local_binding_; |
| 96 InterfaceProviderPtr remote_interfaces_; | 97 shell::mojom::InterfaceProviderPtr remote_interfaces_; |
| 97 | 98 |
| 98 const std::set<std::string> allowed_interfaces_; | 99 const std::set<std::string> allowed_interfaces_; |
| 99 const bool allow_all_interfaces_; | 100 const bool allow_all_interfaces_; |
| 100 | 101 |
| 101 InterfaceBinder* default_binder_; | 102 InterfaceBinder* default_binder_; |
| 102 NameToInterfaceBinderMap name_to_binder_; | 103 NameToInterfaceBinderMap name_to_binder_; |
| 103 | 104 |
| 104 base::WeakPtrFactory<ConnectionImpl> weak_factory_; | 105 base::WeakPtrFactory<ConnectionImpl> weak_factory_; |
| 105 | 106 |
| 106 MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionImpl); | 107 MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionImpl); |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 } // namespace internal | 110 } // namespace internal |
| 110 } // namespace mojo | 111 } // namespace mojo |
| 111 | 112 |
| 112 #endif // MOJO_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ | 113 #endif // MOJO_SHELL_PUBLIC_CPP_LIB_CONNECTION_IMPL_H_ |
| OLD | NEW |