Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: pkg/web_components/lib/interop_support.js

Issue 644163002: Splitting interop support so `dart_support.js` is no longer required. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/web_components/lib/interop_support.html ('k') | pkg/web_components/test/interop_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/web_components/lib/interop_support.js
diff --git a/runtime/bin/vmservice/observatory/deployed/web/packages/web_components/dart_support.js b/pkg/web_components/lib/interop_support.js
similarity index 61%
copy from runtime/bin/vmservice/observatory/deployed/web/packages/web_components/dart_support.js
copy to pkg/web_components/lib/interop_support.js
index 7ce882cef9a107d18d5fc8ec23de4d7df69673d8..790f8284bdbe5158035eb755bc2911eebca40770 100644
--- a/runtime/bin/vmservice/observatory/deployed/web/packages/web_components/dart_support.js
+++ b/pkg/web_components/lib/interop_support.js
@@ -2,74 +2,12 @@
// 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.
-// Teaches dart2js about the wrapping that is done by the Shadow DOM polyfill.
-(function() {
- var ShadowDOMPolyfill = window.ShadowDOMPolyfill;
- if (!ShadowDOMPolyfill) return;
-
- // TODO(sigmund): remove the userAgent check once 1.6 rolls as stable.
- // See: dartbug.com/18463
- if (navigator.dartEnabled || (navigator.userAgent.indexOf('(Dart)') !== -1)) {
- console.error("ShadowDOMPolyfill polyfill was loaded in Dartium. This " +
- "will not work. This indicates that Dartium's Chrome version is " +
- "not compatible with this version of web_components.");
- }
-
- var needsConstructorFix = window.constructor === window.Window;
-
- // TODO(jmesserly): we need to wrap document somehow (a dart:html hook?)
-
- // dartNativeDispatchHooksTransformer is described on initHooks() in
- // sdk/lib/_internal/lib/native_helper.dart.
- if (typeof window.dartNativeDispatchHooksTransformer == 'undefined')
- window.dartNativeDispatchHooksTransformer = [];
-
- window.dartNativeDispatchHooksTransformer.push(function(hooks) {
- var NodeList = ShadowDOMPolyfill.wrappers.NodeList;
- var ShadowRoot = ShadowDOMPolyfill.wrappers.ShadowRoot;
- var unwrapIfNeeded = ShadowDOMPolyfill.unwrapIfNeeded;
- var originalGetTag = hooks.getTag;
- hooks.getTag = function getTag(obj) {
- // TODO(jmesserly): do we still need these?
- if (obj instanceof NodeList) return 'NodeList';
- if (obj instanceof ShadowRoot) return 'ShadowRoot';
- if (MutationRecord && (obj instanceof MutationRecord))
- return 'MutationRecord';
- if (MutationObserver && (obj instanceof MutationObserver))
- return 'MutationObserver';
-
- // TODO(jmesserly): this prevents incorrect interaction between ShadowDOM
- // and dart:html's <template> polyfill. Essentially, ShadowDOM is
- // polyfilling native template, but our Dart polyfill fails to detect this
- // because the unwrapped node is an HTMLUnknownElement, leading it to
- // think the node has no content.
- if (obj instanceof HTMLTemplateElement) return 'HTMLTemplateElement';
-
- var unwrapped = unwrapIfNeeded(obj);
- if (unwrapped && (needsConstructorFix || obj !== unwrapped)) {
- // Fix up class names for Firefox, or if using the minified polyfill.
- // dart2js prefers .constructor.name, but there are all kinds of cases
- // where this will give the wrong answer.
- var ctor = obj.constructor
- if (ctor === unwrapped.constructor) {
- var name = ctor._ShadowDOMPolyfill$cacheTag_;
- if (!name) {
- name = originalGetTag(unwrapped);
- ctor._ShadowDOMPolyfill$cacheTag_ = name;
- }
- return name;
- }
-
- obj = unwrapped;
- }
- return originalGetTag(obj);
- }
- });
-})();
-
// Updates document.registerElement so Dart can see when Javascript custom
// elements are created, and wrap them to provide a Dart friendly API.
(function (doc) {
+ if (window._dart_register_element_interop_support) return;
+ window._dart_register_element_interop_support = true;
+
var upgraders = {}; // upgrader associated with a custom-tag.
var unpatchableTags = {}; // set of custom-tags that can't be patched.
var pendingElements = {}; // will upgrade when/if an upgrader is installed.
@@ -159,7 +97,7 @@
// Native custom elements outside the app in Chrome have constructor
// names like "x-tag", which need to be translated to the DOM
// element they extend. When using the shadow dom polyfill this is
- // take care of above.
+ // taken care of in dart_support.js.
var ShadowDOMPolyfill = window.ShadowDOMPolyfill;
if (!ShadowDOMPolyfill) {
// dartNativeDispatchHooksTransformer is described on initHooks() in
@@ -175,7 +113,7 @@
var match = s.match(/^\[object ([A-Za-z]*Element)\]$/);
if (match) {
return match[1];
- }
+ }
return originalGetUnknownTag(o, tag);
}
};
« no previous file with comments | « pkg/web_components/lib/interop_support.html ('k') | pkg/web_components/test/interop_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698