| 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/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 MessagePortDelegate; |
| 18 struct MessagePortMessage; |
| 18 class WebContents; | 19 class WebContents; |
| 19 | 20 |
| 20 // An interface consisting of methods that can be called to use Message ports. | 21 // An interface consisting of methods that can be called to use Message ports. |
| 21 class CONTENT_EXPORT MessagePortProvider { | 22 class CONTENT_EXPORT MessagePortProvider { |
| 22 public: | 23 public: |
| 23 // Posts a MessageEvent to the main frame using the given source and target | 24 // Posts a MessageEvent to the main frame using the given source and target |
| 24 // origins and data. The caller may also provide any message port ids as | 25 // origins and data. The caller may also provide any message port ids as |
| 25 // part of the message. | 26 // part of the message. |
| 26 // See https://html.spec.whatwg.org/multipage/comms.html#messageevent for | 27 // See https://html.spec.whatwg.org/multipage/comms.html#messageevent for |
| 27 // further information on message events. | 28 // further information on message events. |
| 28 // Should be called on UI thread. | 29 // Should be called on UI thread. |
| 29 static void PostMessageToFrame(WebContents* web_contents, | 30 static void PostMessageToFrame(WebContents* web_contents, |
| 30 const base::string16& source_origin, | 31 const base::string16& source_origin, |
| 31 const base::string16& target_origin, | 32 const base::string16& target_origin, |
| 32 const base::string16& data, | 33 const base::string16& data, |
| 33 const std::vector<int>& ports); | 34 const std::vector<int>& ports); |
| 34 | 35 |
| 35 // Creates a message channel and provide the ids of the message ports that are | 36 // Creates a message channel and provide the ids of the message ports that are |
| 36 // associated with this message channel. | 37 // associated with this message channel. |
| 37 // See https://html.spec.whatwg.org/multipage/comms.html#messagechannel | 38 // See https://html.spec.whatwg.org/multipage/comms.html#messagechannel |
| 38 // Should be called on IO thread. | 39 // Should be called on IO thread. |
| 39 // The message ports that are created will have their routing id numbers equal | 40 // The message ports that are created will have their routing id numbers equal |
| 40 // to the message port numbers. | 41 // to the message port numbers. |
| 41 static void CreateMessageChannel(MessagePortDelegate* delegate, | 42 static void CreateMessageChannel(MessagePortDelegate* delegate, |
| 42 int* port1, | 43 int* port1, |
| 43 int* port2); | 44 int* port2); |
| 44 | 45 |
| 45 // Posts a MessageEvent to a message port associated with a message channel. | 46 // Posts a MessageEvent to a message port associated with a message channel. |
| 46 static void PostMessageToPort(int sender_port_id, | 47 static void PostMessageToPort(int sender_port_id, |
| 47 const base::string16& data, | 48 const MessagePortMessage& message, |
| 48 const std::vector<int>& sent_ports); | 49 const std::vector<int>& sent_ports); |
| 49 | 50 |
| 50 // Close the message port. Should be called on IO thread. | 51 // Close the message port. Should be called on IO thread. |
| 51 static void ClosePort(int message_port_id); | 52 static void ClosePort(int message_port_id); |
| 52 | 53 |
| 53 // Cleanup the message ports that belong to the closing delegate. | 54 // Cleanup the message ports that belong to the closing delegate. |
| 54 static void OnMessagePortDelegateClosing(MessagePortDelegate * delegate); | 55 static void OnMessagePortDelegateClosing(MessagePortDelegate * delegate); |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortProvider); | 58 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortProvider); |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 } // namespace content | 61 } // namespace content |
| 61 | 62 |
| 62 #endif // CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ | 63 #endif // CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_ |
| OLD | NEW |