| // Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |
| #define CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |
| |
| #include <memory> |
| #include <string> |
| |
| #include "content/common/content_export.h" |
| #include "mojo/public/cpp/bindings/interface_ptr.h" |
| #include "mojo/public/cpp/bindings/interface_request.h" |
| #include "mojo/public/cpp/system/message_pipe.h" |
| |
| namespace content { |
| |
| // A virtual app URL identifying the browser itself. This should be used for |
| // a connection's |requestor_url| when connecting from browser code to apps that |
| // don't require a more specific request context. |
| CONTENT_EXPORT extern const char kBrowserMojoAppUrl[]; |
| |
| // This provides a way for arbitrary browser code to connect to Mojo apps. These |
| // objects are not thread-safe but may be constructed and used on any single |
| // thread. |
| class CONTENT_EXPORT MojoAppConnection { |
| public: |
| virtual ~MojoAppConnection() {} |
| |
| // Creates a new connection to the application at |name| using |
| // |requestor_name| to identify the requestor and |context|'s mojo userid to |
| // specify a profile specific application instantiation. This may be called |
| // from any thread. |
| static std::unique_ptr<MojoAppConnection> Create( |
| const std::string& user_id, |
| const std::string& name, |
| const std::string& requestor_name); |
| |
| // Connects to a service within the application. |
| template <typename Interface> |
| void GetInterface(mojo::InterfacePtr<Interface>* proxy) { |
| GetInterface(Interface::Name_, mojo::GetProxy(proxy).PassMessagePipe()); |
| } |
| |
| virtual void GetInterface(const std::string& interface_name, |
| mojo::ScopedMessagePipeHandle handle) = 0; |
| }; |
| |
| } // namespace content |
| |
| #endif // CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |