summaryrefslogtreecommitdiff
path: root/chromium/content/child/webmessageportchannel_impl.h
blob: 70a04b1766171f0fbba35cce72e53a9257011904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_
#define CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_

#include <memory>
#include <vector>

#include "base/macros.h"
#include "content/common/message_port.h"
#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"

namespace content {

// This is thread safe.
class WebMessagePortChannelImpl : public blink::WebMessagePortChannel {
 public:
  ~WebMessagePortChannelImpl() override;
  explicit WebMessagePortChannelImpl(MessagePort message_port);

  static void CreatePair(blink::WebMessagePortChannel** channel1,
                         blink::WebMessagePortChannel** channel2);

  // Extracts MessagePorts for passing on to other processes.
  static std::vector<MessagePort> ExtractMessagePorts(
      blink::WebMessagePortChannelArray channels);

  // Creates WebMessagePortChannelImpl instances for MessagePorts passed in from
  // other processes.
  static blink::WebMessagePortChannelArray CreateFromMessagePorts(
      const std::vector<MessagePort>& message_ports);
  static blink::WebMessagePortChannelArray CreateFromMessagePipeHandles(
      std::vector<mojo::ScopedMessagePipeHandle> handles);

  MessagePort ReleaseMessagePort();

 private:
  explicit WebMessagePortChannelImpl(mojo::ScopedMessagePipeHandle handle);

  // WebMessagePortChannel implementation.
  void setClient(blink::WebMessagePortChannelClient* client) override;
  void postMessage(const blink::WebString& encoded_message,
                   blink::WebMessagePortChannelArray channels) override;
  bool tryGetMessage(blink::WebString* encoded_message,
                     blink::WebMessagePortChannelArray& channels) override;

  MessagePort port_;

  DISALLOW_COPY_AND_ASSIGN(WebMessagePortChannelImpl);
};

}  // namespace content

#endif  // CONTENT_CHILD_WEBMESSAGEPORTCHANNEL_IMPL_H_