| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_CONNECT_UTIL_H_ | 5 #ifndef MOJO_SHELL_CONNECT_UTIL_H_ |
| 6 #define MOJO_SHELL_CONNECT_UTIL_H_ | 6 #define MOJO_SHELL_CONNECT_UTIL_H_ |
| 7 | 7 |
| 8 #include <utility> | |
| 9 | |
| 10 #include "mojo/public/cpp/bindings/interface_ptr.h" | 8 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 11 #include "mojo/public/cpp/system/handle.h" | 9 #include "mojo/public/cpp/system/handle.h" |
| 12 #include "mojo/shell/identity.h" | 10 #include "mojo/shell/identity.h" |
| 13 #include "mojo/shell/public/interfaces/shell.mojom.h" | |
| 14 | |
| 15 class GURL; | |
| 16 | 11 |
| 17 namespace mojo { | 12 namespace mojo { |
| 18 namespace shell { | 13 namespace shell { |
| 19 | 14 |
| 20 class ApplicationManager; | 15 class ApplicationManager; |
| 21 | 16 |
| 22 ScopedMessagePipeHandle ConnectToInterfaceByName( | 17 ScopedMessagePipeHandle ConnectToInterfaceByName( |
| 23 ApplicationManager* application_manager, | 18 ApplicationManager* application_manager, |
| 24 const Identity& source, | 19 const Identity& source, |
| 25 const Identity& target, | 20 const Identity& target, |
| 26 const std::string& interface_name); | 21 const std::string& interface_name); |
| 27 | 22 |
| 28 // Must only be used by shell internals and test code as it does not forward | 23 // Must only be used by shell internals and test code as it does not forward |
| 29 // capability filters. Runs |application_url| with a permissive capability | 24 // capability filters. Runs |application_name| with a permissive capability |
| 30 // filter. | 25 // filter. |
| 31 template <typename Interface> | 26 template <typename Interface> |
| 32 inline void ConnectToInterface(ApplicationManager* application_manager, | 27 inline void ConnectToInterface(ApplicationManager* application_manager, |
| 33 const Identity& source, | 28 const Identity& source, |
| 34 const Identity& target, | 29 const Identity& target, |
| 35 InterfacePtr<Interface>* ptr) { | 30 InterfacePtr<Interface>* ptr) { |
| 36 ScopedMessagePipeHandle service_handle = ConnectToInterfaceByName( | 31 ScopedMessagePipeHandle service_handle = ConnectToInterfaceByName( |
| 37 application_manager, source, target, Interface::Name_); | 32 application_manager, source, target, Interface::Name_); |
| 38 ptr->Bind(InterfacePtrInfo<Interface>(std::move(service_handle), 0u)); | 33 ptr->Bind(InterfacePtrInfo<Interface>(std::move(service_handle), 0u)); |
| 39 } | 34 } |
| 40 | 35 |
| 41 template <typename Interface> | 36 template <typename Interface> |
| 42 inline void ConnectToInterface(ApplicationManager* application_manager, | 37 inline void ConnectToInterface(ApplicationManager* application_manager, |
| 43 const Identity& source, | 38 const Identity& source, |
| 44 const GURL& application_url, | 39 const std::string& application_name, |
| 45 InterfacePtr<Interface>* ptr) { | 40 InterfacePtr<Interface>* ptr) { |
| 46 ScopedMessagePipeHandle service_handle = ConnectToInterfaceByName( | 41 ScopedMessagePipeHandle service_handle = ConnectToInterfaceByName( |
| 47 application_manager, source, | 42 application_manager, source, |
| 48 Identity(application_url, std::string(), mojom::Connector::kUserInherit), | 43 Identity(application_name, std::string(), mojom::Connector::kUserInherit), |
| 49 Interface::Name_); | 44 Interface::Name_); |
| 50 ptr->Bind(InterfacePtrInfo<Interface>(std::move(service_handle), 0u)); | 45 ptr->Bind(InterfacePtrInfo<Interface>(std::move(service_handle), 0u)); |
| 51 } | 46 } |
| 52 | 47 |
| 53 } // namespace shell | 48 } // namespace shell |
| 54 } // namespace mojo | 49 } // namespace mojo |
| 55 | 50 |
| 56 | 51 |
| 57 #endif // MOJO_SHELL_CONNECT_UTIL_H_ | 52 #endif // MOJO_SHELL_CONNECT_UTIL_H_ |
| OLD | NEW |