Rationalise usage of keys in navigator.dart.

Route (named routes) no longer have a key, and have their own storage for their names.
RouseState no longer has a key, and uses an owner field pointing to a StatefulComponent instead.
As such, RouteBase no longer has a key.

HistoryEntry no longer uses a global int to ensure uniqueness.

Propagated this to stocks app.
diff --git a/packages/flutter/example/stocks/lib/stock_home.dart b/packages/flutter/example/stocks/lib/stock_home.dart
index b7a8b89..4ce3187 100644
--- a/packages/flutter/example/stocks/lib/stock_home.dart
+++ b/packages/flutter/example/stocks/lib/stock_home.dart
@@ -69,7 +69,8 @@
   }
 
   void _handleSearchEnd() {
-    assert(navigator.currentRoute.key == this);
+    assert(navigator.currentRoute is RouteState);
+    assert((navigator.currentRoute as RouteState).owner == this); // TODO(ianh): remove cast once analyzer is cleverer
     navigator.pop();
     setState(() {
       _isSearching = false;
diff --git a/packages/flutter/example/stocks/lib/stock_settings.dart b/packages/flutter/example/stocks/lib/stock_settings.dart
index a49047c..76e5c03 100644
--- a/packages/flutter/example/stocks/lib/stock_settings.dart
+++ b/packages/flutter/example/stocks/lib/stock_settings.dart
@@ -61,7 +61,7 @@
         break;
       case StockMode.pessimistic:
         showModeDialog = true;
-        navigator.pushState("/settings/confirm", (_) {
+        navigator.pushState(this, (_) {
           showModeDialog = false;
         });
         break;
diff --git a/packages/flutter/lib/widgets/drawer.dart b/packages/flutter/lib/widgets/drawer.dart
index 781970e..b45aa9f 100644
--- a/packages/flutter/lib/widgets/drawer.dart
+++ b/packages/flutter/lib/widgets/drawer.dart
@@ -143,7 +143,8 @@
     if (_lastStatus != null && status != _lastStatus) {
       if (status == DrawerStatus.inactive &&
           navigator != null &&
-          navigator.currentRoute.key == this)
+          navigator.currentRoute is RouteState &&
+          (navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer
         navigator.pop();
       if (onStatusChanged != null)
         onStatusChanged(status);
diff --git a/packages/flutter/lib/widgets/navigator.dart b/packages/flutter/lib/widgets/navigator.dart
index 8254bbe..1a20b5a 100644
--- a/packages/flutter/lib/widgets/navigator.dart
+++ b/packages/flutter/lib/widgets/navigator.dart
@@ -12,25 +12,24 @@
 typedef Widget Builder(Navigator navigator, RouteBase route);
 
 abstract class RouteBase {
-  RouteBase({ this.key });
-  final Object key;
   Widget build(Navigator navigator, RouteBase route);
   void popState() { }
 }
 
 class Route extends RouteBase {
-  Route({ String name, this.builder }) : super(key: name);
-  String get name => key;
+  Route({ this.name, this.builder });
+  final String name;
   final Builder builder;
   Widget build(Navigator navigator, RouteBase route) => builder(navigator, route);
 }
 
 class RouteState extends RouteBase {
 
-  RouteState({ this.callback, this.route, Object key }) : super(key: key);
+  RouteState({ this.callback, this.route, this.owner });
 
-  RouteBase route;
   Function callback;
+  RouteBase route;
+  StatefulComponent owner;
 
   Widget build(Navigator navigator, RouteBase route) => null;
 
@@ -144,9 +143,8 @@
 }
 
 class HistoryEntry {
-  HistoryEntry({ this.route, this.key });
+  HistoryEntry({ this.route });
   final RouteBase route;
-  final int key;
   bool transitionFinished = false;
   // TODO(jackson): Keep track of the requested transition
 }
@@ -158,12 +156,11 @@
       if (route.name != null)
         namedRoutes[route.name] = route;
     }
-    history.add(new HistoryEntry(route: routes[0], key: _lastKey++));
+    history.add(new HistoryEntry(route: routes[0]));
   }
 
   List<HistoryEntry> history = new List<HistoryEntry>();
   int historyIndex = 0;
-  int _lastKey = 0;
   Map<String, RouteBase> namedRoutes = new Map<String, RouteBase>();
 
   RouteBase get currentRoute => history[historyIndex].route;
@@ -176,7 +173,7 @@
   }
 
   void push(RouteBase route) {
-    HistoryEntry historyEntry = new HistoryEntry(route: route, key: _lastKey++);
+    HistoryEntry historyEntry = new HistoryEntry(route: route);
     history.insert(historyIndex + 1, historyEntry);
     historyIndex++;
   }
@@ -203,9 +200,9 @@
 
   RouteBase get currentRoute => state.currentRoute;
 
-  void pushState(Object key, Function callback) {
+  void pushState(StatefulComponent owner, Function callback) {
     RouteBase route = new RouteState(
-      key: key,
+      owner: owner,
       callback: callback,
       route: state.currentRoute
     );
@@ -245,7 +242,7 @@
       if (content == null)
         continue;
       Transition transition = new Transition(
-        key: historyEntry.key.toString(),
+        key: historyEntry.hashCode.toString(), // TODO(ianh): make it not collide
         content: content,
         direction: (i <= state.historyIndex) ? TransitionDirection.forward : TransitionDirection.reverse,
         interactive: (i == state.historyIndex),
diff --git a/packages/flutter/lib/widgets/popup_menu.dart b/packages/flutter/lib/widgets/popup_menu.dart
index 85e9bd7..49d6aa9 100644
--- a/packages/flutter/lib/widgets/popup_menu.dart
+++ b/packages/flutter/lib/widgets/popup_menu.dart
@@ -122,8 +122,9 @@
     PopupMenuStatus status = _status;
     if (_lastStatus != null && status != _lastStatus) {
       if (status == PopupMenuStatus.inactive &&
-          navigator != null &&
-          navigator.currentRoute.key == this)
+          navigator != null && 
+          navigator.currentRoute is RouteState &&
+          (navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer
         navigator.pop();
       if (onStatusChanged != null)
         onStatusChanged(status);