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