OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MESSAGE_PORT_PROVIDER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ |
6 #define CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
| 17 class MessagePortDelegate; |
17 class WebContents; | 18 class WebContents; |
18 | 19 |
19 // An interface consisting of methods that can be called to use Message ports. | 20 // An interface consisting of methods that can be called to use Message ports. |
20 class CONTENT_EXPORT MessagePortProvider { | 21 class CONTENT_EXPORT MessagePortProvider { |
21 public: | 22 public: |
22 // Posts a MessageEvent to the main frame using the given source and target | 23 // Posts a MessageEvent to the main frame using the given source and target |
23 // origins and data. The caller may also provide any message port ids as | 24 // origins and data. The caller may also provide any message port ids as |
24 // part of the message. | 25 // part of the message. |
25 // See https://html.spec.whatwg.org/multipage/comms.html#messageevent for | 26 // See https://html.spec.whatwg.org/multipage/comms.html#messageevent for |
26 // further information on message events. | 27 // further information on message events. |
27 // Should be called on IO thread. | 28 // Should be called on UI thread. |
28 static void PostMessageToFrame(WebContents* web_contents, | 29 static void PostMessageToFrame(WebContents* web_contents, |
29 const base::string16& source_origin, | 30 const base::string16& source_origin, |
30 const base::string16& target_origin, | 31 const base::string16& target_origin, |
31 const base::string16& data, | 32 const base::string16& data, |
32 const std::vector<int>& ports); | 33 const std::vector<int>& ports); |
33 | 34 |
34 // Creates a message channel and provide the ids of the message ports that are | 35 // Creates a message channel and provide the ids of the message ports that are |
35 // associated with this message channel. | 36 // associated with this message channel. |
36 // See https://html.spec.whatwg.org/multipage/comms.html#messagechannel | 37 // See https://html.spec.whatwg.org/multipage/comms.html#messagechannel |
37 // Should be called on IO thread. | 38 // Should be called on IO thread. |
38 static void CreateMessageChannel(WebContents* web_contents, | 39 // The message ports that are created will have their routing id numbers equal |
| 40 // to the message port numbers. |
| 41 static void CreateMessageChannel(MessagePortDelegate* delegate, |
39 int* port1, | 42 int* port1, |
40 int* port2); | 43 int* port2); |
41 | 44 |
| 45 // Cleanup the message ports that belong to the closing delegate. |
| 46 static void OnMessagePortDelegateClosing(MessagePortDelegate * delegate); |
| 47 |
42 private: | 48 private: |
43 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortProvider); | 49 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortProvider); |
44 }; | 50 }; |
45 | 51 |
46 } // namespace content | 52 } // namespace content |
47 | 53 |
48 #endif // CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ | 54 #endif // CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ |
OLD | NEW |