[fuchsia] Migrate chromium.cast to the fuchsia.web API.

This changes chromium.cast.Channel to use the Open() method rather
than the legacy OnOpened() method.

Bug: 964732
Change-Id: I55e899dce0b3ef813c36a09740c8e73822b6b8b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1580479
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653679}
diff --git a/fuchsia/fidl/cast/cast_channel.fidl b/fuchsia/fidl/cast/cast_channel.fidl
index 8fb702e..1d72753 100644
--- a/fuchsia/fidl/cast/cast_channel.fidl
+++ b/fuchsia/fidl/cast/cast_channel.fidl
@@ -11,10 +11,10 @@
 protocol CastChannel {
   /// Receives an opened Cast |channel| from the Cast application.
   /// Open() must not be called again until the preceding call has returned.
-  [Transitional="Transitional method to migrate the fuchsia.web API."]
   Open(fuchsia.web.MessagePort channel) -> ();
 
   // TODO(crbug.com/946732): Remove this once callers have migrated to Open().
+  [Transitional="Deprecated method to migrate the fuchsia.web API."]
   OnOpened(chromium.web.MessagePort channel) -> ();
 };
 
diff --git a/fuchsia/runners/BUILD.gn b/fuchsia/runners/BUILD.gn
index 82bbe3b..7595902 100644
--- a/fuchsia/runners/BUILD.gn
+++ b/fuchsia/runners/BUILD.gn
@@ -54,7 +54,6 @@
     "//base",
     "//fuchsia/base",
     "//fuchsia/base:modular",
-    "//fuchsia/engine:legacy_message_port_bridge",
     "//third_party/fuchsia-sdk/sdk:modular",
     "//url",
   ]
diff --git a/fuchsia/runners/cast/cast_channel_bindings.cc b/fuchsia/runners/cast/cast_channel_bindings.cc
index 26a2caf..e05d362 100644
--- a/fuchsia/runners/cast/cast_channel_bindings.cc
+++ b/fuchsia/runners/cast/cast_channel_bindings.cc
@@ -16,7 +16,6 @@
 #include "base/path_service.h"
 #include "base/threading/thread_task_runner_handle.h"
 #include "fuchsia/base/mem_buffer_util.h"
-#include "fuchsia/engine/legacy_message_port_bridge.h"
 #include "fuchsia/runners/cast/cast_platform_bindings_ids.h"
 #include "fuchsia/runners/cast/named_message_port_connector.h"
 
@@ -103,11 +102,8 @@
     fuchsia::web::MessagePortPtr channel) {
   if (consumer_ready_for_port_) {
     consumer_ready_for_port_ = false;
-    chromium::web::MessagePortPtr chromium_message_port;
-    new cr_fuchsia::LegacyMessagePortBridge(chromium_message_port.NewRequest(),
-                                            std::move(channel));
-    channel_consumer_->OnOpened(
-        std::move(chromium_message_port),
+    channel_consumer_->Open(
+        std::move(channel),
         fit::bind_member(this, &CastChannelBindings::OnConsumerReadyForPort));
   } else {
     connected_channel_queue_.push_front(std::move(channel));
diff --git a/fuchsia/runners/cast/cast_channel_bindings_browsertest.cc b/fuchsia/runners/cast/cast_channel_bindings_browsertest.cc
index fe00f3e..fc9f5d5 100644
--- a/fuchsia/runners/cast/cast_channel_bindings_browsertest.cc
+++ b/fuchsia/runners/cast/cast_channel_bindings_browsertest.cc
@@ -55,8 +55,8 @@
     callback();
   }
 
-  void OnOpened(fidl::InterfaceHandle<chromium::web::MessagePort> channel,
-                OnOpenedCallback receive_next_channel_cb) override {
+  void Open(fidl::InterfaceHandle<fuchsia::web::MessagePort> channel,
+            OpenCallback receive_next_channel_cb) override {
     connected_channel_ = channel.Bind();
     receive_next_channel_cb_ = std::move(receive_next_channel_cb);
 
@@ -89,14 +89,15 @@
 
   std::string ReadStringFromChannel() {
     base::RunLoop run_loop;
-    cr_fuchsia::ResultReceiver<chromium::web::WebMessage> message(
+    cr_fuchsia::ResultReceiver<fuchsia::web::WebMessage> message(
         run_loop.QuitClosure());
     connected_channel_->ReceiveMessage(
         cr_fuchsia::CallbackToFitFunction(message.GetReceiveCallback()));
     run_loop.Run();
 
     std::string data;
-    CHECK(cr_fuchsia::StringFromMemBuffer(message->data, &data));
+    CHECK(message->has_data());
+    CHECK(cr_fuchsia::StringFromMemBuffer(message->data(), &data));
     return data;
   }
 
@@ -121,7 +122,7 @@
   cr_fuchsia::TestNavigationListener navigation_listener_;
 
   // The connected Cast Channel.
-  chromium::web::MessagePortPtr connected_channel_;
+  fuchsia::web::MessagePortPtr connected_channel_;
 
   // A pending on-connect callback, to be invoked once a Cast Channel is
   // received.
@@ -129,7 +130,7 @@
 
  private:
   const base::RunLoop::ScopedRunTimeoutForTest run_timeout_;
-  OnOpenedCallback receive_next_channel_cb_;
+  OpenCallback receive_next_channel_cb_;
 
   DISALLOW_COPY_AND_ASSIGN(CastChannelBindingsTest);
 };
@@ -191,16 +192,17 @@
 
     // Send a message to the channel.
     {
-      chromium::web::WebMessage message;
-      message.data = cr_fuchsia::MemBufferFromString("hello");
+      fuchsia::web::WebMessage message;
+      message.set_data(cr_fuchsia::MemBufferFromString("hello"));
 
       base::RunLoop run_loop;
-      cr_fuchsia::ResultReceiver<bool> post_result(run_loop.QuitClosure());
+      cr_fuchsia::ResultReceiver<fuchsia::web::MessagePort_PostMessage_Result>
+          post_result(run_loop.QuitClosure());
       connected_channel_->PostMessage(
           std::move(message),
           cr_fuchsia::CallbackToFitFunction(post_result.GetReceiveCallback()));
       run_loop.Run();
-      EXPECT_EQ(true, *post_result);
+      EXPECT_TRUE(post_result->is_response());
     }
 
     EXPECT_EQ("ack hello", ReadStringFromChannel());
diff --git a/fuchsia/runners/cast/cast_runner_integration_test.cc b/fuchsia/runners/cast/cast_runner_integration_test.cc
index 59ac7da..888e50c 100644
--- a/fuchsia/runners/cast/cast_runner_integration_test.cc
+++ b/fuchsia/runners/cast/cast_runner_integration_test.cc
@@ -44,7 +44,7 @@
       : binding_(directory, this) {}
 
   // Returns null if the Cast channel is not open.
-  const chromium::web::MessagePortPtr& port() const { return port_; }
+  const fuchsia::web::MessagePortPtr& port() const { return port_; }
 
   void set_on_opened(base::OnceClosure on_opened) {
     on_opened_ = std::move(on_opened);
@@ -52,8 +52,8 @@
 
  protected:
   // chromium::cast::CastChannel implementation.
-  void OnOpened(fidl::InterfaceHandle<chromium::web::MessagePort> channel,
-                OnOpenedCallback callback_ignored) override {
+  void Open(fidl::InterfaceHandle<fuchsia::web::MessagePort> channel,
+            OpenCallback callback_ignored) override {
     port_ = channel.Bind();
 
     if (on_opened_)
@@ -66,7 +66,7 @@
       binding_;
 
   // Null until the Cast app connects to the Cast channel.
-  chromium::web::MessagePortPtr port_;
+  fuchsia::web::MessagePortPtr port_;
 
   // Invoked when the contect opens a new Cast channel, if set.
   base::OnceClosure on_opened_;
@@ -334,14 +334,15 @@
   auto expected_list = {"this", "is", "a", "test"};
   for (const std::string& expected : expected_list) {
     base::RunLoop run_loop;
-    cr_fuchsia::ResultReceiver<chromium::web::WebMessage> message(
+    cr_fuchsia::ResultReceiver<fuchsia::web::WebMessage> message(
         run_loop.QuitClosure());
     component_state_->cast_channel()->port()->ReceiveMessage(
         cr_fuchsia::CallbackToFitFunction(message.GetReceiveCallback()));
     run_loop.Run();
 
     std::string data;
-    ASSERT_TRUE(cr_fuchsia::StringFromMemBuffer(message->data, &data));
+    ASSERT_TRUE(message->has_data());
+    ASSERT_TRUE(cr_fuchsia::StringFromMemBuffer(message->data(), &data));
     EXPECT_EQ(data, expected);
   }