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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_
6 #define CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_
10 #include "base/basictypes.h"
11 #include "base/macros.h"
12 #include "base/strings/string16.h"
13 #include "content/common/content_export.h"
17 class MessagePortDelegate
;
19 struct MessagePortMessage
;
20 struct TransferredMessagePort
;
22 // An interface consisting of methods that can be called to use Message ports.
23 class CONTENT_EXPORT MessagePortProvider
{
25 // Posts a MessageEvent to the main frame using the given source and target
26 // origins and data. The caller may also provide any message port ids as
27 // part of the message.
28 // See https://html.spec.whatwg.org/multipage/comms.html#messageevent for
29 // further information on message events.
30 // Should be called on UI thread.
31 static void PostMessageToFrame(
32 WebContents
* web_contents
,
33 const base::string16
& source_origin
,
34 const base::string16
& target_origin
,
35 const base::string16
& data
,
36 const std::vector
<TransferredMessagePort
>& ports
);
38 // Creates a message channel and provide the ids of the message ports that are
39 // associated with this message channel.
40 // See https://html.spec.whatwg.org/multipage/comms.html#messagechannel
41 // Should be called on IO thread.
42 // The message ports that are created will have their routing id numbers equal
43 // to the message port numbers.
44 static void CreateMessageChannel(MessagePortDelegate
* delegate
,
48 // Posts a MessageEvent to a message port associated with a message channel.
49 static void PostMessageToPort(
51 const MessagePortMessage
& message
,
52 const std::vector
<TransferredMessagePort
>& sent_ports
);
54 // Close the message port. Should be called on IO thread.
55 static void ClosePort(int message_port_id
);
57 // Cleanup the message ports that belong to the closing delegate.
58 static void OnMessagePortDelegateClosing(MessagePortDelegate
* delegate
);
61 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortProvider
);
64 } // namespace content
66 #endif // CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_