Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / public / browser / mojo_app_connection.h
blobae92b1014cd29563f87750771203a26c15fd90b7
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_
6 #define CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "content/common/content_export.h"
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h"
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
14 #include "third_party/mojo/src/mojo/public/cpp/system/message_pipe.h"
16 class GURL;
18 namespace content {
20 // 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
22 // don't require a more specific request context.
23 CONTENT_EXPORT extern const char kBrowserMojoAppUrl[];
25 // 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
27 // thread.
28 class CONTENT_EXPORT MojoAppConnection {
29 public:
30 virtual ~MojoAppConnection() {}
32 // Creates a new connection to the application at |url| using |requestor_url|
33 // to identify the requestor upon connection. This may be called from any
34 // thread.
35 static scoped_ptr<MojoAppConnection> Create(const GURL& url,
36 const GURL& requestor_url);
38 // Connects to a service within the application.
39 template <typename Interface>
40 void ConnectToService(mojo::InterfacePtr<Interface>* proxy) {
41 ConnectToService(Interface::Name_, mojo::GetProxy(proxy).PassMessagePipe());
44 virtual void ConnectToService(const std::string& service_name,
45 mojo::ScopedMessagePipeHandle handle) = 0;
48 } // namespace content
50 #endif // CONTENT_PUBLIC_BROWSER_MOJO_APP_CONNECTION_H_