Version 1.16.0-dev.5.5

Cherry-pick e8fd9f5c1f9f3e5df1265cf762ceac5170c40621 to dev
Cherry-pick 8f7b8a9d87d63ff164cdeee1be64104b648d8056 to dev
Cherry-pick cf59fdfabd77924e542954d6cb0ecd6d88272f99 to dev
diff --git a/sdk/lib/_blink/dartium/_blink_dartium.dart b/sdk/lib/_blink/dartium/_blink_dartium.dart
index 479b231..c0674f6 100644
--- a/sdk/lib/_blink/dartium/_blink_dartium.dart
+++ b/sdk/lib/_blink/dartium/_blink_dartium.dart
@@ -23303,6 +23303,7 @@
   static defineInterceptorCustomElement(jsObject, Type type) native "Utils_defineInterceptorCustomElement";
   static defineInterceptor(jsObject, Type type) native "Utils_defineInterceptor";
   static setInstanceInterceptor(o, Type type, {bool customElement: false}) native "Utils_setInstanceInterceptor";
+  static setInstanceInterceptorCustomUpgrade(o) native "Utils_setInstanceInterceptorCustomUpgrade";
 
   // This method will throw if the element isn't actually a real Element.
   static initializeCustomElement(element) native "Utils_initializeCustomElement";
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index 369bb28..30f39f7 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -20194,6 +20194,10 @@
       js.JsNative.setProperty(elemProto, 'createdCallback', js.allowInteropCaptureThis(($this) {
         // The created callback has already been called by the very act of passing a JS
         // custom element from JS to Dart.
+
+        //  Make element's interceptor a CustomElementClass.
+        _blink.Blink_Utils.setInstanceInterceptorCustomUpgrade($this);
+
         if (oldCreatedCallback != null)
           oldCreatedCallback.apply([], thisArg: $this);
       }));
diff --git a/sdk/lib/js/dartium/cached_patches.dart b/sdk/lib/js/dartium/cached_patches.dart
index 847abd5..f6bb4ab 100644
--- a/sdk/lib/js/dartium/cached_patches.dart
+++ b/sdk/lib/js/dartium/cached_patches.dart
@@ -7,7 +7,8 @@
 
 library cached_patches;
 
-var cached_patches = {"dart:html": ["dart:html", "dart:html_js_interop_patch.dart", """import 'dart:js' as js_library;
+var cached_patches = {
+"dart:html": ["dart:html", "dart:html_js_interop_patch.dart", """import 'dart:js' as js_library;
 
 /**
  * Placeholder object for cases where we need to determine exactly how many
@@ -4057,7 +4058,8 @@
   toString() => super.toString();
 }
 
-"""],"dart:indexed_db": ["dart:indexed_db", "dart:indexed_db_js_interop_patch.dart", """import 'dart:js' as js_library;
+"""],
+"dart:indexed_db": ["dart:indexed_db", "dart:indexed_db_js_interop_patch.dart", """import 'dart:js' as js_library;
 
 /**
  * Placeholder object for cases where we need to determine exactly how many
@@ -4165,7 +4167,8 @@
   toString() => super.toString();
 }
 
-"""],"dart:web_gl": ["dart:web_gl", "dart:web_gl_js_interop_patch.dart", """import 'dart:js' as js_library;
+"""],
+"dart:web_gl": ["dart:web_gl", "dart:web_gl_js_interop_patch.dart", """import 'dart:js' as js_library;
 
 /**
  * Placeholder object for cases where we need to determine exactly how many
@@ -4561,7 +4564,8 @@
   toString() => super.toString();
 }
 
-"""],"dart:web_sql": ["dart:web_sql", "dart:web_sql_js_interop_patch.dart", """import 'dart:js' as js_library;
+"""],
+"dart:web_sql": ["dart:web_sql", "dart:web_sql_js_interop_patch.dart", """import 'dart:js' as js_library;
 
 /**
  * Placeholder object for cases where we need to determine exactly how many
@@ -4615,7 +4619,8 @@
   toString() => super.toString();
 }
 
-"""],"dart:svg": ["dart:svg", "dart:svg_js_interop_patch.dart", """import 'dart:js' as js_library;
+"""],
+"dart:svg": ["dart:svg", "dart:svg_js_interop_patch.dart", """import 'dart:js' as js_library;
 
 /**
  * Placeholder object for cases where we need to determine exactly how many
@@ -5767,7 +5772,8 @@
   toString() => super.toString();
 }
 
-"""],"dart:web_audio": ["dart:web_audio", "dart:web_audio_js_interop_patch.dart", """import 'dart:js' as js_library;
+"""],
+"dart:web_audio": ["dart:web_audio", "dart:web_audio_js_interop_patch.dart", """import 'dart:js' as js_library;
 
 /**
  * Placeholder object for cases where we need to determine exactly how many
@@ -6028,5 +6034,7 @@
   toString() => super.toString();
 }
 
-"""],};
+"""],
+
+};
 // END_OF_CACHED_PATCHES
diff --git a/sdk/lib/js/dartium/js_dartium.dart b/sdk/lib/js/dartium/js_dartium.dart
index 0d96425..97e927e 100644
--- a/sdk/lib/js/dartium/js_dartium.dart
+++ b/sdk/lib/js/dartium/js_dartium.dart
@@ -282,48 +282,6 @@
 
 _finalizeJsInterfaces() native "Js_finalizeJsInterfaces";
 
-// Create the files for the generated Dart files from IDLs.  These only change
-// when browser's Dart files change (dart:*).
-@Deprecated("Internal Use Only")
-String createCachedPatchesFile() {
-  var patches = _generateInteropPatchFiles(['dart:html',
-                                            'dart:indexed_db',
-                                            'dart:web_gl',
-                                            'dart:web_sql',
-                                            'dart:svg',
-                                            'dart:web_audio']);
-  var sb = new StringBuffer();
-
-  sb.write("""
-
-// START_OF_CACHED_PATCHES
-// Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-// DO NOT EDIT GENERATED FILE.
-
-library cached_patches;
-
-var cached_patches = {""");
-
-  for (var baseIndex = 0; baseIndex < patches.length; baseIndex += 3) {
-    var uri = patches[baseIndex + 0];
-    var uri_js_interop = patches[baseIndex + 1];
-    var source = patches[baseIndex + 2];
-
-    if (uri != 'dart:js') {
-      sb.write('"$uri": ["$uri", "$uri_js_interop", """$source"""],');
-    }
-  }
-
-  sb.write("""};
-// END_OF_CACHED_PATCHES
-  """);
-
-  return "$sb";
-}
-
 String _getJsName(mirrors.DeclarationMirror mirror) {
   if (_atJsType != null) {
     for (var annotation in mirror.metadata) {
@@ -499,19 +457,23 @@
   return false;
 }
 
-List<String> _generateExternalMethods(List<String> libraryPaths) {
+List<String> _generateExternalMethods(List<String> libraryPaths, bool useCachedPatches) {
   var staticCodegen = <String>[];
 
   if (libraryPaths.length == 0) {
     mirrors.currentMirrorSystem().libraries.forEach((uri, library) {
       var library_name = "${uri.scheme}:${uri.path}";
-      if (cached_patches.containsKey(library_name)) {
+      if (useCachedPatches && cached_patches.containsKey(library_name)) {
         // Use the pre-generated patch files for DOM dart:nnnn libraries.
         var patch = cached_patches[library_name];
         staticCodegen.addAll(patch);
       } else if (_hasJsName(library)) {
         // Library marked with @JS
         _generateLibraryCodegen(uri, library, staticCodegen);
+      } else if (!useCachedPatches) {
+        // Can't use the cached patches file, instead this is a signal to generate
+        // the patches for this file.
+        _generateLibraryCodegen(uri, library, staticCodegen);
       }
     });    // End of library foreach
   } else {
@@ -676,8 +638,11 @@
  * Generates part files defining source code for JSObjectImpl, all DOM classes
  * classes. This codegen  is needed so that type checks for all registered
  * JavaScript interop classes pass.
+ * If genCachedPatches is true then the patch files don't exist this is a special
+ * signal to generate and emit the patches to stdout to be captured and put into
+ * the file sdk/lib/js/dartium/cached_patches.dart
  */
-List<String> _generateInteropPatchFiles(List<String> libraryPaths) {
+List<String> _generateInteropPatchFiles(List<String> libraryPaths, genCachedPatches) {
   // Cache the @JS Type.
   if (_atJsType == -1) {
     var uri = new Uri(scheme: "package", path: "js/js.dart");
@@ -692,7 +657,7 @@
     }
   }
 
-  var ret = _generateExternalMethods(libraryPaths);
+  var ret = _generateExternalMethods(libraryPaths, genCachedPatches ? false : true);
   var libraryPrefixes = new Map<mirrors.LibraryMirror, String>();
   var prefixNames = new Set<String>();
   var sb = new StringBuffer();
diff --git a/tests/co19/co19-dartium.status b/tests/co19/co19-dartium.status
index 8144d86..b788b84 100644
--- a/tests/co19/co19-dartium.status
+++ b/tests/co19/co19-dartium.status
@@ -1365,8 +1365,6 @@
 LayoutTests/fast/dom/HTMLTemplateElement/cycles-in-shadow_t01: RuntimeError # Issue 26134
 LayoutTests/fast/dom/HTMLTemplateElement/cycles_t01: RuntimeError # Issue 26134
 LayoutTests/fast/dom/computed-style-set-property_t01: RuntimeError # Issue 26134
-LayoutTests/fast/dom/custom/element-type_t01: RuntimeError # Issue 26134
-LayoutTests/fast/dom/custom/element-upgrade_t01: RuntimeError # Issue 26134
 LayoutTests/fast/dom/custom/document-register-type-extensions_t01: RuntimeError # Issue 26134
 LayoutTests/fast/dom/custom/document-register-namespace_t01: RuntimeError # Issue 26134
 LayoutTests/fast/dom/DOMException/prototype-object_t01: RuntimeError # Issue 26134
diff --git a/tools/VERSION b/tools/VERSION
index c549298..da869b8 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -28,4 +28,4 @@
 MINOR 16
 PATCH 0
 PRERELEASE 5
-PRERELEASE_PATCH 4
+PRERELEASE_PATCH 5
diff --git a/tools/dartium/generate_app/generate_cached_patches.dart b/tools/dartium/generate_app/generate_cached_patches.dart
index 21ca4fb..af34b27 100644
--- a/tools/dartium/generate_app/generate_cached_patches.dart
+++ b/tools/dartium/generate_app/generate_cached_patches.dart
@@ -2,12 +2,9 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import "dart:js" as js;
-
 void main() {
   try {
-    var cached_files = js.createCachedPatchesFile();
-    print("$cached_files");
+    print("Generated Patches");
   } catch (e) {
     var workedElem = document.querySelector("#worked");
     var failedElem = document.querySelector("#failed");
diff --git a/tools/dartium/generate_app/generate_cached_patches.html b/tools/dartium/generate_app/generate_cached_patches.html
index e6c24b6..cee01ac 100644
--- a/tools/dartium/generate_app/generate_cached_patches.html
+++ b/tools/dartium/generate_app/generate_cached_patches.html
@@ -5,14 +5,14 @@
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1">
 
-	<style>
-	    div {
+    <style>
+    div {
       background: #ffffff;
       text-align: center;
       width: 50%;
       margin: 10% 10% 25% 25%;
     }
-	
+
     div#worked {
       border: 5px solid green;
       color: green;
@@ -23,7 +23,7 @@
       color: red;
     }
 
-	.cached_file_done {
+    .cached_file_done {
       font-family: arial;
       font-size: 24pt;
      }
@@ -33,12 +33,12 @@
       font-size: 16pt;
       vertical-align: text-bottom;
     }
-	</style>
+    </style>
 
     <script async type="application/dart" src="generate_cached_patches.dart"></script>
     <script async src="packages/browser/dart.js"></script>
   </head> 
-	<body>
+    <body>
       <div id=worked>
         <span class=cached_file_done>Close Dartium</span><br/><br/>
         <span class=cached_file_done>File: </span>
diff --git a/tools/dartium/generate_patches.sh b/tools/dartium/generate_patches.sh
index ec2011a..40dc895 100755
--- a/tools/dartium/generate_patches.sh
+++ b/tools/dartium/generate_patches.sh
@@ -13,25 +13,31 @@
 # other systems.  My habit is to run:
 #
 #   ./go.sh
-
+#
 # 1. After running go.sh libraries in sdk/lib may change.
 # 2. Build Dartium.
 # 3. Run this script and sdk/lib/js/dartium/cached_patches will be created.
 # 4. Rebuild Dartium.
 # 5. Commit files in sdk/lib
+#
+# NOTE: If the Dart files generated from the IDLs may cause major changes which
+#       could cause the patch files to fail (missing classes, etc).  If this
+#       happens delete the contents of the sdk/lib/js/dartium/cached_patches.dart
+#       build Dartium, run this script and build Dartium again with the newly
+#       generated patches. 
 
 LOCATION_DARTIUM="../../../out/Release"
 DARTIUM="$LOCATION_DARTIUM"
 
 DART_APP_LOCATION="file://"$PWD"/generate_app/generate_cached_patches.html"
-DARTIUM_ARGS=" --user-data-dir=out --disable-web-security --no-sandbox --enable-logging=stderr"
+DARTIUM_ARGS=" --user-data-dir=out --disable-web-security --no-sandbox --enable-blink-features=dartGenCachedPatches"
 CACHED_PATCHES_FILE=""$PWD"/../../sdk/lib/js/dartium/cached_patches.dart"
 
 if [[ "$1" != "" ]] ; then
   DARTIM="$1"
 fi
 
-cmd=""$DARTIUM"/chrome "$DARTIUM_ARGS" "$DART_APP_LOCATION" 3>&1 1>&2- 2>&3 | \
+cmd=""$DARTIUM"/chrome "$DARTIUM_ARGS" "$DART_APP_LOCATION" |
   (sed -n '/START_OF_CACHED_PATCHES/,/END_OF_CACHED_PATCHES/p') > "$CACHED_PATCHES_FILE""
 
 reset && eval "${cmd}"
diff --git a/tools/deps/dartium.deps/DEPS b/tools/deps/dartium.deps/DEPS
index 26151f2..2eb609e 100644
--- a/tools/deps/dartium.deps/DEPS
+++ b/tools/deps/dartium.deps/DEPS
@@ -9,7 +9,7 @@
 
 vars.update({
   "dartium_chromium_commit": "c2d1ddba7a86ce11a8dcb77a4ac101872d6110bd",
-  "dartium_webkit_commit": "b4483b1ace5b28b4678cf132087db9cd9e18deb6",
+  "dartium_webkit_commit": "1ebe477439d73297f0e6090b474fd9b761407434",
   "chromium_base_revision": "338390",
 
   # We use mirrors of all github repos to guarantee reproducibility and
diff --git a/tools/dom/scripts/generate_blink_file.py b/tools/dom/scripts/generate_blink_file.py
index 8cea946..dee266c 100644
--- a/tools/dom/scripts/generate_blink_file.py
+++ b/tools/dom/scripts/generate_blink_file.py
@@ -133,6 +133,7 @@
   static defineInterceptorCustomElement(jsObject, Type type) native "Utils_defineInterceptorCustomElement";
   static defineInterceptor(jsObject, Type type) native "Utils_defineInterceptor";
   static setInstanceInterceptor(o, Type type, {bool customElement: false}) native "Utils_setInstanceInterceptor";
+  static setInstanceInterceptorCustomUpgrade(o) native "Utils_setInstanceInterceptorCustomUpgrade";
 
   // This method will throw if the element isn't actually a real Element.
   static initializeCustomElement(element) native "Utils_initializeCustomElement";
diff --git a/tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate b/tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate
index a52e369..1264edc 100644
--- a/tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate
+++ b/tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate
@@ -439,6 +439,10 @@
       js.JsNative.setProperty(elemProto, 'createdCallback', js.allowInteropCaptureThis(($this) {
         // The created callback has already been called by the very act of passing a JS
         // custom element from JS to Dart.
+
+        //  Make element's interceptor a CustomElementClass.
+        _blink.Blink_Utils.setInstanceInterceptorCustomUpgrade($this);
+
         if (oldCreatedCallback != null)
           oldCreatedCallback.apply([], thisArg: $this);
       }));