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_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_ |
6 #define CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_ | 6 #define CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 | 9 |
10 class GURL; | 10 class GURL; |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 struct NavigatorConnectClient; | 14 struct NavigatorConnectClient; |
15 class MessagePortDelegate; | 15 class MessagePortDelegate; |
16 | 16 |
17 // Implement this interface to provide a new kind of navigator.connect | 17 // Implement this interface to provide a new kind of navigator.connect |
18 // accessible service. | 18 // accessible service. |
19 // Instances of this class are owned by NavigatorConnectContext. Register new | 19 // Instances of this class are owned by NavigatorConnectContext. Register new |
20 // factories by calling NavigatorConnectContext::AddFactory. | 20 // factories by calling NavigatorConnectContext::AddFactory. |
21 class NavigatorConnectServiceFactory { | 21 class NavigatorConnectServiceFactory { |
22 public: | 22 public: |
23 // Call with nullptr to indicate connection failure. Ownership of the delegate | 23 // Call with nullptr to indicate connection failure. Ownership of the delegate |
24 // remains with the factory. It is assumed that for the passed | 24 // remains with the factory. It is assumed that for the passed |
25 // MessagePortDelegate implementation the route_id and message_port_id of a | 25 // MessagePortDelegate implementation the route_id and message_port_id of a |
26 // connection are the same. | 26 // connection are the same. |
27 using ConnectCallback = base::Callback<void(MessagePortDelegate*)>; | 27 // Pass true to |data_as_values| if the delegate expects to receive messages |
| 28 // from the client encoded as base::Value instead of the normal serialization |
| 29 // format. |
| 30 using ConnectCallback = |
| 31 base::Callback<void(MessagePortDelegate*, bool data_as_values)>; |
28 | 32 |
29 virtual ~NavigatorConnectServiceFactory() {} | 33 virtual ~NavigatorConnectServiceFactory() {} |
30 | 34 |
31 // Return true if this factory is responsible for handling connections to the | 35 // Return true if this factory is responsible for handling connections to the |
32 // |target_url|. The most recently added factory that returns true for a | 36 // |target_url|. The most recently added factory that returns true for a |
33 // particular url is picked to handle the connection attempt. | 37 // particular url is picked to handle the connection attempt. |
34 virtual bool HandlesUrl(const GURL& target_url) = 0; | 38 virtual bool HandlesUrl(const GURL& target_url) = 0; |
35 | 39 |
36 // Called to try to establish a connection. Only called if this factory was | 40 // Called to try to establish a connection. Only called if this factory was |
37 // the most recently added factory that returned true from |HandlesUrl| for | 41 // the most recently added factory that returned true from |HandlesUrl| for |
38 // the url being connected to. | 42 // the url being connected to. |
39 virtual void Connect(const NavigatorConnectClient& client, | 43 virtual void Connect(const NavigatorConnectClient& client, |
40 const ConnectCallback& callback) = 0; | 44 const ConnectCallback& callback) = 0; |
41 }; | 45 }; |
42 | 46 |
43 } // namespace content | 47 } // namespace content |
44 | 48 |
45 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_ | 49 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATOR_CONNECT_SERVICE_FACTORY_H_ |
OLD | NEW |