Popular sites on the NTP: Try to keep the ordering constant
[chromium-blink-merge.git] / content / public / browser / message_port_provider.h
blobcf82ec746731ccc2c5fb3b534ac8fb5391328ffa
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_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/macros.h"
12 #include "base/strings/string16.h"
13 #include "content/common/content_export.h"
15 namespace content {
17 class MessagePortDelegate;
18 class WebContents;
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 {
24 public:
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,
45 int* port1,
46 int* port2);
48 // Posts a MessageEvent to a message port associated with a message channel.
49 // Should be called on IO thread.
50 static void PostMessageToPort(
51 int sender_port_id,
52 const MessagePortMessage& message,
53 const std::vector<TransferredMessagePort>& sent_ports);
55 // Close the message port. Should be called on IO thread.
56 static void ClosePort(int message_port_id);
58 // Queue up all the messages for this message port until ReleaseMessages
59 // is called. Should be called on IO thread.
60 static void HoldMessages(int message_port_id);
62 // Release any queued messages as a result of HoldMessages. Should be
63 // called on IO thread.
64 static void ReleaseMessages(int message_port_id);
66 // Cleanup the message ports that belong to the closing delegate.
67 // Should be called on IO thread.
68 static void OnMessagePortDelegateClosing(MessagePortDelegate * delegate);
70 // Update message port information when the message port is transferred
71 // from a different process. The updated message ports will have their
72 // routing numbers equal to the message port numbers.
73 // Should be called on IO thread.
74 static void UpdateMessagePort(int message_port_id,
75 MessagePortDelegate* delegate);
77 private:
78 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortProvider);
81 } // namespace content
83 #endif // CONTENT_PUBLIC_BROWSER_MESSAGE_PORT_PROVIDER_H_