[scenic] Prepare for ChildView migration to SDK

Some of the components in vendor/google are entangled with these classes
in topaz.  We need to expose both ChildViewConnection types temporarily
for migration purposes.

TEST: Ran sysUI; started a story
SCN-898 #comment
SCN-1033 #comment
SCN-1214 #comment

Change-Id: I3eb3829ad409a0a53898c403e6063af1aacf840e
diff --git a/lib/base_shell/BUILD.gn b/lib/base_shell/BUILD.gn
index a57f655..574bd51 100644
--- a/lib/base_shell/BUILD.gn
+++ b/lib/base_shell/BUILD.gn
@@ -23,8 +23,10 @@
     "$peridot_sdk_fidl/fuchsia.modular.auth",
     "//third_party/dart-pkg/git/flutter/packages/flutter",
     "//topaz/public/dart/fidl",
+    "//topaz/public/dart/fuchsia_scenic_flutter",
     "//topaz/public/dart/widgets:lib.widgets",
     "//topaz/public/lib/app/dart",
+    "//topaz/public/lib/ui/flutter",
     "//topaz/shell/widgets",
     "//zircon/public/fidl/fuchsia-net:fuchsia-net",
   ]
diff --git a/lib/base_shell/lib/base_model.dart b/lib/base_shell/lib/base_model.dart
index 958e179..d0b881b 100644
--- a/lib/base_shell/lib/base_model.dart
+++ b/lib/base_shell/lib/base_model.dart
@@ -14,11 +14,14 @@
 import 'package:fidl_fuchsia_ui_gfx/fidl.dart';
 import 'package:fidl_fuchsia_ui_input/fidl.dart' as input;
 import 'package:fidl_fuchsia_ui_policy/fidl.dart';
+import 'package:fuchsia_scenic_flutter/child_view_connection.dart'
+    show ChildViewConnection;
 import 'package:lib.app.dart/app.dart' as app;
 import 'package:lib.app.dart/logging.dart';
-import 'package:lib.ui.flutter/child_view.dart';
+import 'package:lib.ui.flutter/child_view.dart' as deprecated
+    show ChildViewConnection;
 import 'package:meta/meta.dart';
-import 'package:zircon/zircon.dart' show Channel;
+import 'package:zircon/zircon.dart' show Channel, EventPair;
 
 import 'base_shell_model.dart';
 import 'netstack_model.dart';
@@ -60,6 +63,8 @@
   List<Account> _accounts;
 
   /// Childview connection that contains the session shell.
+  bool _shouldCreateNewChildView = false;
+  deprecated.ChildViewConnection _deprecatedChildViewConnection;
   ChildViewConnection _childViewConnection;
 
   final List<KeyboardCaptureListenerHackBinding> _keyBindings = [];
@@ -82,7 +87,13 @@
   List<Account> get accounts => _accounts;
 
   /// Returns the authenticated child view connection
-  ChildViewConnection get childViewConnection => _childViewConnection;
+  deprecated.ChildViewConnection get childViewConnection =>
+      _deprecatedChildViewConnection;
+  ChildViewConnection get childViewConnectionNew => _childViewConnection;
+
+  set shouldCreateNewChildView(bool should) {
+    _shouldCreateNewChildView = should;
+  }
 
   @override
   void captureKeyboardEventHack(input.KeyboardEvent eventToCapture,
@@ -200,21 +211,40 @@
     final viewOwnerHandle =
         _userManager.login(accountId, serviceProvider.passHandle());
 
-    _childViewConnection = ChildViewConnection(
-      viewOwnerHandle,
-      onAvailable: (ChildViewConnection connection) {
-        trace('session shell available');
-        log.info('BaseShell: Child view connection available!');
-        connection.requestFocus();
-        notifyListeners();
-      },
-      onUnavailable: (ChildViewConnection connection) {
-        trace('BaseShell: Child view connection now unavailable!');
-        log.info('BaseShell: Child view connection now unavailable!');
-        onLogout();
-        notifyListeners();
-      },
-    );
+    if (_shouldCreateNewChildView) {
+      _childViewConnection = ChildViewConnection.fromViewHolderToken(
+        EventPair(viewOwnerHandle.passChannel().passHandle()),
+        onAvailable: (ChildViewConnection connection) {
+          trace('session shell available');
+          log.info('BaseShell: Child view connection available!');
+          connection.requestFocus();
+          notifyListeners();
+        },
+        onUnavailable: (ChildViewConnection connection) {
+          trace('BaseShell: Child view connection now unavailable!');
+          log.info('BaseShell: Child view connection now unavailable!');
+          onLogout();
+          notifyListeners();
+        },
+      );
+    } else {
+      _deprecatedChildViewConnection =
+          deprecated.ChildViewConnection.fromViewHolderToken(
+        EventPair(viewOwnerHandle.passChannel().passHandle()),
+        onAvailable: (deprecated.ChildViewConnection connection) {
+          trace('session shell available');
+          log.info('BaseShell: Child view connection available!');
+          connection.requestFocus();
+          notifyListeners();
+        },
+        onUnavailable: (deprecated.ChildViewConnection connection) {
+          trace('BaseShell: Child view connection now unavailable!');
+          log.info('BaseShell: Child view connection now unavailable!');
+          onLogout();
+          notifyListeners();
+        },
+      );
+    }
     notifyListeners();
   }
 
@@ -222,6 +252,7 @@
   @mustCallSuper
   Future<void> onLogout() async {
     trace('logout');
+    _deprecatedChildViewConnection = null;
     _childViewConnection = null;
     _serviceProviderBinding.close();
     for (PresentationBinding presentationBinding in _presentationBindings) {
diff --git a/public/lib/mediaplayer/flutter/BUILD.gn b/public/lib/mediaplayer/flutter/BUILD.gn
index 0a2ba03..6098842 100644
--- a/public/lib/mediaplayer/flutter/BUILD.gn
+++ b/public/lib/mediaplayer/flutter/BUILD.gn
@@ -19,7 +19,7 @@
     "$garnet_sdk_fidl/fuchsia.media",
     "$garnet_sdk_fidl/fuchsia.ui.viewsv1",
     "//third_party/dart-pkg/git/flutter/packages/flutter",
-    "//topaz/public/dart/fidl",
+    "//topaz/public/dart/fuchsia_scenic_flutter",
     "//topaz/public/lib/app/dart",
     "//topaz/public/lib/mediaplayer/dart",
     "//topaz/public/lib/ui/flutter",
diff --git a/public/lib/mediaplayer/flutter/media_player_controller.dart b/public/lib/mediaplayer/flutter/media_player_controller.dart
index 74a2290..671eb8a 100644
--- a/public/lib/mediaplayer/flutter/media_player_controller.dart
+++ b/public/lib/mediaplayer/flutter/media_player_controller.dart
@@ -8,24 +8,24 @@
 import 'package:fidl_fuchsia_math/fidl.dart' as geom;
 import 'package:fidl_fuchsia_mediaplayer/fidl.dart';
 import 'package:fidl_fuchsia_sys/fidl.dart';
-import 'package:fidl_fuchsia_ui_viewsv1/fidl.dart';
-import 'package:fidl/fidl.dart';
-import 'package:lib.app.dart/app.dart';
-import 'package:lib.mediaplayer.dart/audio_player_controller.dart';
-import 'package:lib.ui.flutter/child_view.dart';
-
 import 'package:flutter/foundation.dart';
 import 'package:flutter/widgets.dart';
+import 'package:fuchsia_scenic_flutter/child_view_connection.dart'
+    show ChildViewConnection;
+import 'package:lib.mediaplayer.dart/audio_player_controller.dart';
+import 'package:lib.ui.flutter/child_view.dart' as deprecated
+    show ChildViewConnection;
+import 'package:zircon/zircon.dart';
 
 /// Controller for MediaPlayer widgets.
 class MediaPlayerController extends AudioPlayerController
     implements Listenable {
   final List<VoidCallback> _listeners = <VoidCallback>[];
 
-  ServiceProvider _services;
-
   Timer _hideTimer;
 
+  bool _shouldCreateNewChildView = false;
+  deprecated.ChildViewConnection _deprecatedVideoViewConnection;
   ChildViewConnection _videoViewConnection;
 
   Size _videoSize = Size.zero;
@@ -36,10 +36,13 @@
   /// Constructs a MediaPlayerController.
   MediaPlayerController(ServiceProvider services) : super(services) {
     updateCallback = _notifyListeners;
-    _services = services;
     _close(); // Initialize stuff.
   }
 
+  set shouldCreateNewChildView(bool should) {
+    _shouldCreateNewChildView = should;
+  }
+
   @override
   void open(Uri uri, {HttpHeaders headers}) {
     _wasActive = openOrConnected;
@@ -50,14 +53,18 @@
   @override
   void onMediaPlayerCreated(PlayerProxy player) {
     if (!_wasActive) {
-      ViewManagerProxy viewManager = new ViewManagerProxy();
-      connectToService(_services, viewManager.ctrl);
+      final EventPairPair viewTokens = new EventPairPair();
+      assert(viewTokens.status == ZX.OK);
+      player.createView2(viewTokens.first);
 
-      InterfacePair<ViewOwner> viewOwnerPair = new InterfacePair<ViewOwner>();
-      player.createView(viewManager.ctrl.unbind(), viewOwnerPair.passRequest());
-
-      _videoViewConnection =
-          new ChildViewConnection(viewOwnerPair.passHandle());
+      if (_shouldCreateNewChildView) {
+        _videoViewConnection =
+            ChildViewConnection.fromViewHolderToken(viewTokens.second);
+      } else {
+        _deprecatedVideoViewConnection =
+            deprecated.ChildViewConnection.fromViewHolderToken(
+                viewTokens.second);
+      }
     }
   }
 
@@ -69,6 +76,7 @@
   }
 
   void _close() {
+    _deprecatedVideoViewConnection = null;
     _videoViewConnection = null;
   }
 
@@ -138,7 +146,9 @@
   Size get videoPhysicalSize => hasVideo ? _videoSize : Size.zero;
 
   /// Gets the video view connection.
-  ChildViewConnection get videoViewConnection => _videoViewConnection;
+  deprecated.ChildViewConnection get videoViewConnection =>
+      _deprecatedVideoViewConnection;
+  ChildViewConnection get videoViewConnectionNew => _videoViewConnection;
 
   @override
   void onVideoGeometryUpdated(geom.Size videoSize, geom.Size pixelAspectRatio) {