OLD | NEW |
1 // Copyright 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/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 class MessagePortDelegate; | 16 class MessagePortDelegate; |
17 class WebContents; | 17 class WebContents; |
18 struct MessagePortMessage; | |
19 struct TransferredMessagePort; | |
20 | 18 |
21 // An interface consisting of methods that can be called to use Message ports. | 19 // An interface consisting of methods that can be called to use Message ports. |
22 class CONTENT_EXPORT MessagePortProvider { | 20 class CONTENT_EXPORT MessagePortProvider { |
23 public: | 21 public: |
24 // Posts a MessageEvent to the main frame using the given source and target | 22 // Posts a MessageEvent to the main frame using the given source and target |
25 // origins and data. The caller may also provide any message port ids as | 23 // origins and data. The caller may also provide any message port ids as |
26 // part of the message. | 24 // part of the message. |
27 // See https://html.spec.whatwg.org/multipage/comms.html#messageevent for | 25 // See https://html.spec.whatwg.org/multipage/comms.html#messageevent for |
28 // further information on message events. | 26 // further information on message events. |
29 // Should be called on UI thread. | 27 // Should be called on UI thread. |
30 static void PostMessageToFrame( | 28 static void PostMessageToFrame( |
31 WebContents* web_contents, | 29 WebContents* web_contents, |
32 const base::string16& source_origin, | 30 const base::string16& source_origin, |
33 const base::string16& target_origin, | 31 const base::string16& target_origin, |
34 const base::string16& data, | 32 const base::string16& data, |
35 const std::vector<TransferredMessagePort>& ports); | 33 const std::vector<int>& ports); |
36 | 34 |
37 // 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 |
38 // associated with this message channel. | 36 // associated with this message channel. |
39 // See https://html.spec.whatwg.org/multipage/comms.html#messagechannel | 37 // See https://html.spec.whatwg.org/multipage/comms.html#messagechannel |
40 // Should be called on IO thread. | 38 // Should be called on IO thread. |
41 // The message ports that are created will have their routing id numbers equal | 39 // The message ports that are created will have their routing id numbers equal |
42 // to the message port numbers. | 40 // to the message port numbers. |
43 static void CreateMessageChannel(MessagePortDelegate* delegate, | 41 static void CreateMessageChannel(MessagePortDelegate* delegate, |
44 int* port1, | 42 int* port1, |
45 int* port2); | 43 int* port2); |
46 | 44 |
47 // Posts a MessageEvent to a message port associated with a message channel. | 45 // Posts a MessageEvent to a message port associated with a message channel. |
48 // Should be called on IO thread. | 46 // Should be called on IO thread. |
49 static void PostMessageToPort( | 47 static void PostMessageToPort( |
50 int sender_port_id, | 48 int sender_port_id, |
51 const MessagePortMessage& message, | 49 const base::string16& message, |
52 const std::vector<TransferredMessagePort>& sent_ports); | 50 const std::vector<int>& sent_ports); |
53 | 51 |
54 // Close the message port. Should be called on IO thread. | 52 // Close the message port. Should be called on IO thread. |
55 static void ClosePort(int message_port_id); | 53 static void ClosePort(int message_port_id); |
56 | 54 |
57 // Queue up all the messages for this message port until ReleaseMessages | 55 // Queue up all the messages for this message port until ReleaseMessages |
58 // is called. Should be called on IO thread. | 56 // is called. Should be called on IO thread. |
59 static void HoldMessages(int message_port_id); | 57 static void HoldMessages(int message_port_id); |
60 | 58 |
61 // Release any queued messages as a result of HoldMessages. Should be | 59 // Release any queued messages as a result of HoldMessages. Should be |
62 // called on IO thread. | 60 // called on IO thread. |
(...skipping 10 matching lines...) Expand all Loading... |
73 static void UpdateMessagePort(int message_port_id, | 71 static void UpdateMessagePort(int message_port_id, |
74 MessagePortDelegate* delegate); | 72 MessagePortDelegate* delegate); |
75 | 73 |
76 private: | 74 private: |
77 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortProvider); | 75 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortProvider); |
78 }; | 76 }; |
79 | 77 |
80 } // namespace content | 78 } // namespace content |
81 | 79 |
82 #endif // CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ | 80 #endif // CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ |
OLD | NEW |