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 CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |
6 #define CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ | 6 #define CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 #include "mojo/public/cpp/bindings/interface_ptr.h" | 12 #include "mojo/public/cpp/bindings/interface_ptr.h" |
13 #include "mojo/public/cpp/bindings/interface_request.h" | 13 #include "mojo/public/cpp/bindings/interface_request.h" |
14 #include "mojo/public/cpp/system/message_pipe.h" | 14 #include "mojo/public/cpp/system/message_pipe.h" |
15 | 15 |
16 class GURL; | |
17 | |
18 namespace content { | 16 namespace content { |
19 | 17 |
20 // A virtual app URL identifying the browser itself. This should be used for | 18 // A virtual app URL identifying the browser itself. This should be used for |
21 // a connection's |requestor_url| when connecting from browser code to apps that | 19 // a connection's |requestor_url| when connecting from browser code to apps that |
22 // don't require a more specific request context. | 20 // don't require a more specific request context. |
23 CONTENT_EXPORT extern const char kBrowserMojoAppUrl[]; | 21 CONTENT_EXPORT extern const char kBrowserMojoAppUrl[]; |
24 | 22 |
25 // This provides a way for arbitrary browser code to connect to Mojo apps. These | 23 // This provides a way for arbitrary browser code to connect to Mojo apps. These |
26 // objects are not thread-safe but may be constructed and used on any single | 24 // objects are not thread-safe but may be constructed and used on any single |
27 // thread. | 25 // thread. |
28 class CONTENT_EXPORT MojoAppConnection { | 26 class CONTENT_EXPORT MojoAppConnection { |
29 public: | 27 public: |
30 virtual ~MojoAppConnection() {} | 28 virtual ~MojoAppConnection() {} |
31 | 29 |
32 // Creates a new connection to the application at |url| using |requestor_url| | 30 // Creates a new connection to the application at |name| using |
33 // to identify the requestor upon connection. This may be called from any | 31 // |requestor_name| to identify the requestor upon connection. This may be |
34 // thread. | 32 // called from any thread. |
35 static scoped_ptr<MojoAppConnection> Create(const GURL& url, | 33 static scoped_ptr<MojoAppConnection> Create( |
36 const GURL& requestor_url); | 34 const std::string& name, |
| 35 const std::string& requestor_name); |
37 | 36 |
38 // Connects to a service within the application. | 37 // Connects to a service within the application. |
39 template <typename Interface> | 38 template <typename Interface> |
40 void GetInterface(mojo::InterfacePtr<Interface>* proxy) { | 39 void GetInterface(mojo::InterfacePtr<Interface>* proxy) { |
41 GetInterface(Interface::Name_, mojo::GetProxy(proxy).PassMessagePipe()); | 40 GetInterface(Interface::Name_, mojo::GetProxy(proxy).PassMessagePipe()); |
42 } | 41 } |
43 | 42 |
44 virtual void GetInterface(const std::string& interface_name, | 43 virtual void GetInterface(const std::string& interface_name, |
45 mojo::ScopedMessagePipeHandle handle) = 0; | 44 mojo::ScopedMessagePipeHandle handle) = 0; |
46 }; | 45 }; |
47 | 46 |
48 } // namespace content | 47 } // namespace content |
49 | 48 |
50 #endif // CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ | 49 #endif // CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_ |
OLD | NEW |