Commit 29fe082f authored by Chris Hamilton's avatar Chris Hamilton Committed by Commit Bot

Rename SimpleMessagePort to WebMessagePort.

This parallels the naming scheme for other parts of Blink's
public interface.

BUG=803242

Change-Id: Ib92a31fa379c184258e1ef41a9397d707220f3bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2025991
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Auto-Submit: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736147}
parent 77586436
...@@ -74,10 +74,10 @@ jumbo_source_set("common") { ...@@ -74,10 +74,10 @@ jumbo_source_set("common") {
"messaging/message_port_channel.cc", "messaging/message_port_channel.cc",
"messaging/message_port_descriptor.cc", "messaging/message_port_descriptor.cc",
"messaging/message_port_descriptor_mojom_traits.cc", "messaging/message_port_descriptor_mojom_traits.cc",
"messaging/simple_message_port.cc",
"messaging/string_message_codec.cc", "messaging/string_message_codec.cc",
"messaging/transferable_message.cc", "messaging/transferable_message.cc",
"messaging/transferable_message_mojom_traits.cc", "messaging/transferable_message_mojom_traits.cc",
"messaging/web_message_port.cc",
"mime_util/mime_util.cc", "mime_util/mime_util.cc",
"notifications/notification_mojom_traits.cc", "notifications/notification_mojom_traits.cc",
"notifications/notification_resources.cc", "notifications/notification_resources.cc",
...@@ -201,8 +201,8 @@ jumbo_source_set("common_unittests_sources") { ...@@ -201,8 +201,8 @@ jumbo_source_set("common_unittests_sources") {
# they are excluded as they require V8 environment but V8 snapshot is # they are excluded as they require V8 environment but V8 snapshot is
# not available in the current minimum test setting. # not available in the current minimum test setting.
sources += [ sources += [
"messaging/simple_message_port_unittest.cc",
"messaging/string_message_codec_unittest.cc", "messaging/string_message_codec_unittest.cc",
"messaging/web_message_port_unittest.cc",
] ]
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "third_party/blink/public/common/messaging/simple_message_port.h" #include "third_party/blink/public/common/messaging/web_message_port.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "third_party/blink/public/common/messaging/message_port_channel.h" #include "third_party/blink/public/common/messaging/message_port_channel.h"
...@@ -13,63 +13,67 @@ ...@@ -13,63 +13,67 @@
namespace blink { namespace blink {
SimpleMessagePort::Message::Message() = default; WebMessagePort::Message::Message() = default;
SimpleMessagePort::Message::Message(Message&&) = default; WebMessagePort::Message::Message(Message&&) = default;
SimpleMessagePort::Message& SimpleMessagePort::Message::operator=(Message&&) = WebMessagePort::Message& WebMessagePort::Message::operator=(Message&&) =
default; default;
SimpleMessagePort::Message::~Message() = default; WebMessagePort::Message::~Message() = default;
SimpleMessagePort::Message::Message(const base::string16& data) : data(data) {} WebMessagePort::Message::Message(const base::string16& data) : data(data) {}
SimpleMessagePort::Message::Message(std::vector<SimpleMessagePort> ports) WebMessagePort::Message::Message(std::vector<WebMessagePort> ports)
: ports(std::move(ports)) {} : ports(std::move(ports)) {}
SimpleMessagePort::Message::Message(SimpleMessagePort&& port) { WebMessagePort::Message::Message(WebMessagePort&& port) {
ports.emplace_back(std::move(port)); ports.emplace_back(std::move(port));
} }
SimpleMessagePort::Message::Message(const base::string16& data, WebMessagePort::Message::Message(const base::string16& data,
std::vector<SimpleMessagePort> ports) std::vector<WebMessagePort> ports)
: data(data), ports(std::move(ports)) {} : data(data), ports(std::move(ports)) {}
SimpleMessagePort::Message::Message(const base::string16& data, WebMessagePort::Message::Message(const base::string16& data,
SimpleMessagePort port) WebMessagePort port)
: data(data) { : data(data) {
ports.emplace_back(std::move(port)); ports.emplace_back(std::move(port));
} }
SimpleMessagePort::MessageReceiver::MessageReceiver() = default; WebMessagePort::MessageReceiver::MessageReceiver() = default;
SimpleMessagePort::MessageReceiver::~MessageReceiver() = default; WebMessagePort::MessageReceiver::~MessageReceiver() = default;
bool SimpleMessagePort::MessageReceiver::OnMessage(Message) { bool WebMessagePort::MessageReceiver::OnMessage(Message) {
return true; return true;
} }
SimpleMessagePort::SimpleMessagePort() = default; WebMessagePort::WebMessagePort() = default;
SimpleMessagePort::SimpleMessagePort(SimpleMessagePort&& other) { WebMessagePort::WebMessagePort(WebMessagePort&& other) {
Take(std::move(other)); Take(std::move(other));
} }
SimpleMessagePort& SimpleMessagePort::operator=(SimpleMessagePort&& other) { WebMessagePort& WebMessagePort::operator=(WebMessagePort&& other) {
Take(std::move(other)); Take(std::move(other));
return *this; return *this;
} }
SimpleMessagePort::~SimpleMessagePort() { WebMessagePort::~WebMessagePort() {
CloseIfNecessary(); CloseIfNecessary();
} }
// static // static
std::pair<SimpleMessagePort, SimpleMessagePort> std::pair<WebMessagePort, WebMessagePort> WebMessagePort::CreatePair() {
SimpleMessagePort::CreatePair() {
mojo::ScopedMessagePipeHandle handle0, handle1; mojo::ScopedMessagePipeHandle handle0, handle1;
CHECK_EQ(MOJO_RESULT_OK, CHECK_EQ(MOJO_RESULT_OK,
mojo::CreateMessagePipe(nullptr, &handle0, &handle1)); mojo::CreateMessagePipe(nullptr, &handle0, &handle1));
return std::make_pair(SimpleMessagePort(std::move(handle0)), return std::make_pair(WebMessagePort(std::move(handle0)),
SimpleMessagePort(std::move(handle1))); WebMessagePort(std::move(handle1)));
} }
void SimpleMessagePort::SetReceiver( // static
WebMessagePort WebMessagePort::Create(mojo::ScopedMessagePipeHandle port) {
return WebMessagePort(std::move(port));
}
void WebMessagePort::SetReceiver(
MessageReceiver* receiver, MessageReceiver* receiver,
scoped_refptr<base::SequencedTaskRunner> runner) { scoped_refptr<base::SequencedTaskRunner> runner) {
DCHECK(receiver); DCHECK(receiver);
...@@ -88,10 +92,10 @@ void SimpleMessagePort::SetReceiver( ...@@ -88,10 +92,10 @@ void SimpleMessagePort::SetReceiver(
std::move(runner)); std::move(runner));
connector_->set_incoming_receiver(this); connector_->set_incoming_receiver(this);
connector_->set_connection_error_handler( connector_->set_connection_error_handler(
base::BindOnce(&SimpleMessagePort::OnPipeError, base::Unretained(this))); base::BindOnce(&WebMessagePort::OnPipeError, base::Unretained(this)));
} }
void SimpleMessagePort::ClearReceiver() { void WebMessagePort::ClearReceiver() {
if (!connector_) if (!connector_)
return; return;
port_ = connector_->PassMessagePipe(); port_ = connector_->PassMessagePipe();
...@@ -99,13 +103,13 @@ void SimpleMessagePort::ClearReceiver() { ...@@ -99,13 +103,13 @@ void SimpleMessagePort::ClearReceiver() {
receiver_ = nullptr; receiver_ = nullptr;
} }
base::SequencedTaskRunner* SimpleMessagePort::GetTaskRunner() const { base::SequencedTaskRunner* WebMessagePort::GetTaskRunner() const {
if (!connector_) if (!connector_)
return nullptr; return nullptr;
return connector_->task_runner(); return connector_->task_runner();
} }
mojo::ScopedMessagePipeHandle SimpleMessagePort::PassHandle() { mojo::ScopedMessagePipeHandle WebMessagePort::PassHandle() {
DCHECK(is_transferable_); DCHECK(is_transferable_);
// Clear the receiver, which takes the handle out of the connector if it // Clear the receiver, which takes the handle out of the connector if it
...@@ -116,17 +120,17 @@ mojo::ScopedMessagePipeHandle SimpleMessagePort::PassHandle() { ...@@ -116,17 +120,17 @@ mojo::ScopedMessagePipeHandle SimpleMessagePort::PassHandle() {
return handle; return handle;
} }
SimpleMessagePort::SimpleMessagePort(mojo::ScopedMessagePipeHandle&& port) WebMessagePort::WebMessagePort(mojo::ScopedMessagePipeHandle&& port)
: port_(std::move(port)), is_closed_(false), is_transferable_(true) { : port_(std::move(port)), is_closed_(false), is_transferable_(true) {
DCHECK(port_.is_valid()); DCHECK(port_.is_valid());
} }
bool SimpleMessagePort::CanPostMessage() const { bool WebMessagePort::CanPostMessage() const {
return connector_ && connector_->is_valid() && !is_closed_ && !is_errored_ && return connector_ && connector_->is_valid() && !is_closed_ && !is_errored_ &&
receiver_; receiver_;
} }
bool SimpleMessagePort::PostMessage(Message&& message) { bool WebMessagePort::PostMessage(Message&& message) {
if (!CanPostMessage()) if (!CanPostMessage())
return false; return false;
...@@ -164,24 +168,24 @@ bool SimpleMessagePort::PostMessage(Message&& message) { ...@@ -164,24 +168,24 @@ bool SimpleMessagePort::PostMessage(Message&& message) {
return true; return true;
} }
bool SimpleMessagePort::IsValid() const { bool WebMessagePort::IsValid() const {
if (connector_) if (connector_)
return connector_->is_valid(); return connector_->is_valid();
return port_.is_valid(); return port_.is_valid();
} }
void SimpleMessagePort::Close() { void WebMessagePort::Close() {
CloseIfNecessary(); CloseIfNecessary();
} }
void SimpleMessagePort::Reset() { void WebMessagePort::Reset() {
CloseIfNecessary(); CloseIfNecessary();
is_closed_ = true; is_closed_ = true;
is_errored_ = false; is_errored_ = false;
is_transferable_ = false; is_transferable_ = false;
} }
void SimpleMessagePort::Take(SimpleMessagePort&& other) { void WebMessagePort::Take(WebMessagePort&& other) {
port_ = std::move(other.port_); port_ = std::move(other.port_);
connector_ = std::move(other.connector_); connector_ = std::move(other.connector_);
is_closed_ = std::exchange(other.is_closed_, true); is_closed_ = std::exchange(other.is_closed_, true);
...@@ -190,7 +194,7 @@ void SimpleMessagePort::Take(SimpleMessagePort&& other) { ...@@ -190,7 +194,7 @@ void SimpleMessagePort::Take(SimpleMessagePort&& other) {
receiver_ = std::exchange(other.receiver_, nullptr); receiver_ = std::exchange(other.receiver_, nullptr);
} }
void SimpleMessagePort::OnPipeError() { void WebMessagePort::OnPipeError() {
DCHECK(!is_transferable_); DCHECK(!is_transferable_);
if (is_errored_) if (is_errored_)
return; return;
...@@ -199,7 +203,7 @@ void SimpleMessagePort::OnPipeError() { ...@@ -199,7 +203,7 @@ void SimpleMessagePort::OnPipeError() {
receiver_->OnPipeError(); receiver_->OnPipeError();
} }
void SimpleMessagePort::CloseIfNecessary() { void WebMessagePort::CloseIfNecessary() {
if (is_closed_) if (is_closed_)
return; return;
is_closed_ = true; is_closed_ = true;
...@@ -207,7 +211,7 @@ void SimpleMessagePort::CloseIfNecessary() { ...@@ -207,7 +211,7 @@ void SimpleMessagePort::CloseIfNecessary() {
port_.reset(); port_.reset();
} }
bool SimpleMessagePort::Accept(mojo::Message* mojo_message) { bool WebMessagePort::Accept(mojo::Message* mojo_message) {
DCHECK(receiver_); DCHECK(receiver_);
DCHECK(!is_transferable_); DCHECK(!is_transferable_);
...@@ -230,7 +234,7 @@ bool SimpleMessagePort::Accept(mojo::Message* mojo_message) { ...@@ -230,7 +234,7 @@ bool SimpleMessagePort::Accept(mojo::Message* mojo_message) {
auto handles = auto handles =
blink::MessagePortChannel::ReleaseHandles(transferable_message.ports); blink::MessagePortChannel::ReleaseHandles(transferable_message.ports);
for (auto& handle : handles) { for (auto& handle : handles) {
message.ports.emplace_back(SimpleMessagePort(std::move(handle))); message.ports.emplace_back(WebMessagePort(std::move(handle)));
} }
// Pass the message on to the receiver. // Pass the message on to the receiver.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "third_party/blink/public/common/messaging/simple_message_port.h" #include "third_party/blink/public/common/messaging/web_message_port.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
...@@ -15,14 +15,14 @@ namespace blink { ...@@ -15,14 +15,14 @@ namespace blink {
namespace { namespace {
using Message = SimpleMessagePort::Message; using Message = WebMessagePort::Message;
class LenientMockReceiver : public SimpleMessagePort::MessageReceiver { class LenientMockReceiver : public WebMessagePort::MessageReceiver {
public: public:
LenientMockReceiver() = default; LenientMockReceiver() = default;
~LenientMockReceiver() override = default; ~LenientMockReceiver() override = default;
// SimpleMessagePort::MessageReceiver implementation: // WebMessagePort::MessageReceiver implementation:
MOCK_METHOD1(OnMessage, bool(Message)); MOCK_METHOD1(OnMessage, bool(Message));
MOCK_METHOD0(OnPipeError, void()); MOCK_METHOD0(OnPipeError, void());
}; };
...@@ -34,11 +34,11 @@ using testing::Invoke; ...@@ -34,11 +34,11 @@ using testing::Invoke;
} // namespace } // namespace
TEST(SimpleMessagePortTest, EndToEnd) { TEST(WebMessagePortTest, EndToEnd) {
base::test::SingleThreadTaskEnvironment task_env; base::test::SingleThreadTaskEnvironment task_env;
// Create a dummy pipe and ensure it behaves as expected. // Create a dummy pipe and ensure it behaves as expected.
SimpleMessagePort port0; WebMessagePort port0;
EXPECT_FALSE(port0.IsValid()); EXPECT_FALSE(port0.IsValid());
EXPECT_FALSE(port0.is_errored()); EXPECT_FALSE(port0.is_errored());
EXPECT_TRUE(port0.is_closed()); EXPECT_TRUE(port0.is_closed());
...@@ -47,9 +47,9 @@ TEST(SimpleMessagePortTest, EndToEnd) { ...@@ -47,9 +47,9 @@ TEST(SimpleMessagePortTest, EndToEnd) {
EXPECT_FALSE(port0.CanPostMessage()); EXPECT_FALSE(port0.CanPostMessage());
// Create a pipe. // Create a pipe.
auto pipe = SimpleMessagePort::CreatePair(); auto pipe = WebMessagePort::CreatePair();
port0 = std::move(pipe.first); port0 = std::move(pipe.first);
SimpleMessagePort port1 = std::move(pipe.second); WebMessagePort port1 = std::move(pipe.second);
EXPECT_TRUE(port0.IsValid()); EXPECT_TRUE(port0.IsValid());
EXPECT_FALSE(port0.is_errored()); EXPECT_FALSE(port0.is_errored());
...@@ -103,7 +103,7 @@ TEST(SimpleMessagePortTest, EndToEnd) { ...@@ -103,7 +103,7 @@ TEST(SimpleMessagePortTest, EndToEnd) {
} }
// Send a message the other way (from 1 to 0) with a port. // Send a message the other way (from 1 to 0) with a port.
auto pipe2 = SimpleMessagePort::CreatePair(); auto pipe2 = WebMessagePort::CreatePair();
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_CALL(receiver0, OnMessage(_)) EXPECT_CALL(receiver0, OnMessage(_))
......
...@@ -113,10 +113,10 @@ source_set("headers") { ...@@ -113,10 +113,10 @@ source_set("headers") {
"messaging/message_port_channel.h", "messaging/message_port_channel.h",
"messaging/message_port_descriptor.h", "messaging/message_port_descriptor.h",
"messaging/message_port_descriptor_mojom_traits.h", "messaging/message_port_descriptor_mojom_traits.h",
"messaging/simple_message_port.h",
"messaging/string_message_codec.h", "messaging/string_message_codec.h",
"messaging/transferable_message.h", "messaging/transferable_message.h",
"messaging/transferable_message_mojom_traits.h", "messaging/transferable_message_mojom_traits.h",
"messaging/web_message_port.h",
"mime_util/mime_util.h", "mime_util/mime_util.h",
"navigation/triggering_event_info.h", "navigation/triggering_event_info.h",
"notifications/notification_constants.h", "notifications/notification_constants.h",
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_MESSAGING_SIMPLE_MESSAGE_PORT_H_ #ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_MESSAGING_WEB_MESSAGE_PORT_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_MESSAGING_SIMPLE_MESSAGE_PORT_H_ #define THIRD_PARTY_BLINK_PUBLIC_COMMON_MESSAGING_WEB_MESSAGE_PORT_H_
#include <utility> #include <utility>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace blink { namespace blink {
// Defines a SimpleMessagePort, which is used by embedders to send and receive // Defines a WebMessagePort, which is used by embedders to send and receive
// messages to and from Javascript content. This is a simplified version of the // messages to and from Javascript content. This is a simplified version of the
// full MessagePort concept implemented by renderer/core/messaging/message_port. // full MessagePort concept implemented by renderer/core/messaging/message_port.
// It is a lightweight wrapper of a Mojo message pipe, and provides // It is a lightweight wrapper of a Mojo message pipe, and provides
...@@ -29,8 +29,8 @@ namespace blink { ...@@ -29,8 +29,8 @@ namespace blink {
// //
// // Create a pair of ports. The two ends of the pipe are conjugates of each // // Create a pair of ports. The two ends of the pipe are conjugates of each
// // other. // // other.
// std::pair<SimpleMessagePort, SimpleMessagePort> ports = // std::pair<WebMessagePort, WebMessagePort> ports =
// SimpleMessagePort::CreatePair(); // WebMessagePort::CreatePair();
// //
// // Keep one end for ourselves. // // Keep one end for ourselves.
// MessageReceiverImpl receiver; // Implements MessageReceiver. // MessageReceiverImpl receiver; // Implements MessageReceiver.
...@@ -63,25 +63,31 @@ namespace blink { ...@@ -63,25 +63,31 @@ namespace blink {
// sequence. The sequence from which it is used does not have to be the same // sequence. The sequence from which it is used does not have to be the same
// sequence that the bound receiver uses. // sequence that the bound receiver uses.
// //
// Further note that a SimpleMessagePort is not "reusable". That is, once it has // Further note that a WebMessagePort is not "reusable". That is, once it has
// been bound via SetReceiver, it is no longer transmittable (can't be passed as // been bound via SetReceiver, it is no longer transmittable (can't be passed as
// a port in part of a Message). This is enforced via runtime CHECKs. // a port in part of a Message). This is enforced via runtime CHECKs.
class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver { class BLINK_COMMON_EXPORT WebMessagePort : public mojo::MessageReceiver {
public: public:
// See below for definitions. // See below for definitions.
struct Message; struct Message;
class MessageReceiver; class MessageReceiver;
SimpleMessagePort(); WebMessagePort();
SimpleMessagePort(const SimpleMessagePort&) = delete; WebMessagePort(const WebMessagePort&) = delete;
SimpleMessagePort(SimpleMessagePort&&); WebMessagePort(WebMessagePort&&);
SimpleMessagePort& operator=(const SimpleMessagePort&) = delete; WebMessagePort& operator=(const WebMessagePort&) = delete;
SimpleMessagePort& operator=(SimpleMessagePort&&); WebMessagePort& operator=(WebMessagePort&&);
~SimpleMessagePort() override; ~WebMessagePort() override;
// Factory function for creating two ends of a message channel. The two ports // Factory function for creating two ends of a message channel. The two ports
// are conjugates of each other. // are conjugates of each other.
static std::pair<SimpleMessagePort, SimpleMessagePort> CreatePair(); static std::pair<WebMessagePort, WebMessagePort> CreatePair();
// Factory function that creates a MessagePort from a raw Mojo pipe. This is
// deprecated, as clients should prefer to use CreatePair above.
// TODO(chrisha): Remove this once all downstream clients have been migrated
// away from using raw Mojo pipes.
static WebMessagePort Create(mojo::ScopedMessagePipeHandle port);
// Sets a message receiver for this message port. Once bound any incoming // Sets a message receiver for this message port. Once bound any incoming
// messages to this port will be routed to the provided |receiver| with // messages to this port will be routed to the provided |receiver| with
...@@ -89,7 +95,7 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver { ...@@ -89,7 +95,7 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver {
// *after* a pipe has already transitioned to being in error, you will not // *after* a pipe has already transitioned to being in error, you will not
// receive an "OnPipeError" callback; you should instead manually check // receive an "OnPipeError" callback; you should instead manually check
// "is_errored" before setting the receiver. Once a receiver has been set a // "is_errored" before setting the receiver. Once a receiver has been set a
// SimpleMessagePort is no longer transferable. // WebMessagePort is no longer transferable.
void SetReceiver(MessageReceiver* receiver, void SetReceiver(MessageReceiver* receiver,
scoped_refptr<base::SequencedTaskRunner> runner); scoped_refptr<base::SequencedTaskRunner> runner);
...@@ -100,14 +106,14 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver { ...@@ -100,14 +106,14 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver {
// continue to be invoked after calling this. // continue to be invoked after calling this.
void ClearReceiver(); void ClearReceiver();
// Returns true if this SimpleMessagePort currently has a receiver. // Returns true if this WebMessagePort currently has a receiver.
bool HasReceiver() const { return receiver_; } bool HasReceiver() const { return receiver_; }
// Returns the receiver to which this SimpleMessagePort is bound. This can // Returns the receiver to which this WebMessagePort is bound. This can
// return nullptr if it has not been bound to a receiver. // return nullptr if it has not been bound to a receiver.
MessageReceiver* receiver() const { return receiver_; } MessageReceiver* receiver() const { return receiver_; }
// Returns the task runner to which this SimpleMessagePort is bound. This can // Returns the task runner to which this WebMessagePort is bound. This can
// return nullptr if the port is not bound to a receiver. // return nullptr if the port is not bound to a receiver.
base::SequencedTaskRunner* GetTaskRunner() const; base::SequencedTaskRunner* GetTaskRunner() const;
...@@ -125,14 +131,14 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver { ...@@ -125,14 +131,14 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver {
// Returns true if this port is bound to a valid message pipe. // Returns true if this port is bound to a valid message pipe.
bool IsValid() const; bool IsValid() const;
// Returns true if this SimpleMessagePort has been closed. // Returns true if this WebMessagePort has been closed.
bool is_closed() const { return is_closed_; } bool is_closed() const { return is_closed_; }
// Returns true if this SimpleMessagePort has experienced an error. // Returns true if this WebMessagePort has experienced an error.
bool is_errored() const { return is_errored_; } bool is_errored() const { return is_errored_; }
// Returns true if this SimpleMessagePort is transferable as part of a // Returns true if this WebMessagePort is transferable as part of a
// Message. This is true for a brand new SimpleMessagePort, but becomes false // Message. This is true for a brand new WebMessagePort, but becomes false
// if SetReceiver is ever called. // if SetReceiver is ever called.
bool is_transferable() const { return is_transferable_; } bool is_transferable() const { return is_transferable_; }
...@@ -142,7 +148,7 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver { ...@@ -142,7 +148,7 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver {
// was closed. This function can be called at any time, and repeatedly. // was closed. This function can be called at any time, and repeatedly.
void Close(); void Close();
// Reset this SimpleMessagePort to a completely default state. Similar to // Reset this WebMessagePort to a completely default state. Similar to
// close, but also resets the "is_closed", "is_errored" and "is_transferable" // close, but also resets the "is_closed", "is_errored" and "is_transferable"
// states. Can be called at any time, and repeatedly. // states. Can be called at any time, and repeatedly.
void Reset(); void Reset();
...@@ -156,9 +162,9 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver { ...@@ -156,9 +162,9 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver {
// Creates a message port that wraps the provided |port|. This provided |port| // Creates a message port that wraps the provided |port|. This provided |port|
// must be valid. This is private as it should only be called by message // must be valid. This is private as it should only be called by message
// deserialization code, or the CreatePair factory. // deserialization code, or the CreatePair factory.
explicit SimpleMessagePort(mojo::ScopedMessagePipeHandle&& port); explicit WebMessagePort(mojo::ScopedMessagePipeHandle&& port);
void Take(SimpleMessagePort&& other); void Take(WebMessagePort&& other);
void OnPipeError(); void OnPipeError();
void CloseIfNecessary(); void CloseIfNecessary();
...@@ -176,7 +182,7 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver { ...@@ -176,7 +182,7 @@ class BLINK_COMMON_EXPORT SimpleMessagePort : public mojo::MessageReceiver {
// A very simple message format. This is a subset of a TransferableMessage, as // A very simple message format. This is a subset of a TransferableMessage, as
// many of the fields in the full message type aren't appropriate for messages // many of the fields in the full message type aren't appropriate for messages
// originating from the embedder. // originating from the embedder.
struct BLINK_COMMON_EXPORT SimpleMessagePort::Message { struct BLINK_COMMON_EXPORT WebMessagePort::Message {
Message(); Message();
Message(const Message&) = delete; Message(const Message&) = delete;
Message(Message&&); Message(Message&&);
...@@ -188,27 +194,27 @@ struct BLINK_COMMON_EXPORT SimpleMessagePort::Message { ...@@ -188,27 +194,27 @@ struct BLINK_COMMON_EXPORT SimpleMessagePort::Message {
explicit Message(const base::string16& data); explicit Message(const base::string16& data);
// Creates a message with the given collection of |ports| to be transferred. // Creates a message with the given collection of |ports| to be transferred.
explicit Message(std::vector<SimpleMessagePort> ports); explicit Message(std::vector<WebMessagePort> ports);
// Creates a message with a single |port| to be transferred. // Creates a message with a single |port| to be transferred.
explicit Message(SimpleMessagePort&& port); explicit Message(WebMessagePort&& port);
// Creates a message with |data| and a collection of |ports| to be // Creates a message with |data| and a collection of |ports| to be
// transferred. // transferred.
Message(const base::string16& data, std::vector<SimpleMessagePort> ports); Message(const base::string16& data, std::vector<WebMessagePort> ports);
// Creates a message with |data| and a single |port| to be transferred. // Creates a message with |data| and a single |port| to be transferred.
Message(const base::string16& data, SimpleMessagePort port); Message(const base::string16& data, WebMessagePort port);
// A UTF-16 message. // A UTF-16 message.
base::string16 data; base::string16 data;
// Other message ports that are to be transmitted as part of this message. // Other message ports that are to be transmitted as part of this message.
std::vector<SimpleMessagePort> ports; std::vector<WebMessagePort> ports;
}; };
// Interface to be implemented by receivers. // Interface to be implemented by receivers.
class BLINK_COMMON_EXPORT SimpleMessagePort::MessageReceiver { class BLINK_COMMON_EXPORT WebMessagePort::MessageReceiver {
public: public:
MessageReceiver(); MessageReceiver();
MessageReceiver(const MessageReceiver&) = delete; MessageReceiver(const MessageReceiver&) = delete;
...@@ -228,4 +234,4 @@ class BLINK_COMMON_EXPORT SimpleMessagePort::MessageReceiver { ...@@ -228,4 +234,4 @@ class BLINK_COMMON_EXPORT SimpleMessagePort::MessageReceiver {
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_MESSAGING_SIMPLE_MESSAGE_PORT_H_ #endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_MESSAGING_WEB_MESSAGE_PORT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment