| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of polymer; | 5 part of polymer; |
| 6 | 6 |
| 7 /** Annotation used to automatically register polymer elements. */ | 7 /** Annotation used to automatically register polymer elements. */ |
| 8 class CustomTag { | 8 class CustomTag { |
| 9 final String tagName; | 9 final String tagName; |
| 10 const CustomTag(this.tagName); | 10 const CustomTag(this.tagName); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return scripts; | 131 return scripts; |
| 132 } | 132 } |
| 133 | 133 |
| 134 /** All libraries in the current isolate. */ | 134 /** All libraries in the current isolate. */ |
| 135 final _libs = currentMirrorSystem().libraries; | 135 final _libs = currentMirrorSystem().libraries; |
| 136 | 136 |
| 137 // TODO(sigmund): explore other (cheaper) ways to resolve URIs relative to the | 137 // TODO(sigmund): explore other (cheaper) ways to resolve URIs relative to the |
| 138 // root library (see dartbug.com/12612) | 138 // root library (see dartbug.com/12612) |
| 139 final _rootUri = currentMirrorSystem().isolate.rootLibrary.uri; | 139 final _rootUri = currentMirrorSystem().isolate.rootLibrary.uri; |
| 140 | 140 |
| 141 final String _packageRoot = | 141 final Logger _loaderLog = new Logger('polymer.loader'); |
| 142 path.url.join(path.url.dirname(Uri.parse(window.location.href).path), | |
| 143 'packages') + '/'; | |
| 144 | 142 |
| 145 final Logger _loaderLog = new Logger('polymer.loader'); | 143 bool _isHttpStylePackageUrl(Uri uri) { |
| 144 var uriPath = uri.path; |
| 145 return uri.scheme == _rootUri.scheme && |
| 146 // Don't process cross-domain uris. |
| 147 uri.authority == _rootUri.authority && |
| 148 uriPath.endsWith('.dart') && |
| 149 (uriPath.contains('/packages/') || uriPath.startsWith('packages/')); |
| 150 } |
| 146 | 151 |
| 147 /** | 152 /** |
| 148 * Reads the library at [uriString] (which can be an absolute URI or a relative | 153 * Reads the library at [uriString] (which can be an absolute URI or a relative |
| 149 * URI from the root library), and: | 154 * URI from the root library), and: |
| 150 * | 155 * |
| 151 * * If present, invokes any top-level and static functions marked | 156 * * If present, invokes any top-level and static functions marked |
| 152 * with the [initMethod] annotation (in the order they appear). | 157 * with the [initMethod] annotation (in the order they appear). |
| 153 * | 158 * |
| 154 * * Registers any [PolymerElement] that is marked with the [CustomTag] | 159 * * Registers any [PolymerElement] that is marked with the [CustomTag] |
| 155 * annotation. | 160 * annotation. |
| 156 */ | 161 */ |
| 157 void _loadLibrary(String uriString) { | 162 void _loadLibrary(String uriString) { |
| 158 var uri = _rootUri.resolve(uriString); | 163 var uri = _rootUri.resolve(uriString); |
| 159 var lib = _libs[uri]; | 164 var lib = _libs[uri]; |
| 160 if (uri.path.startsWith(_packageRoot) && uri.path.endsWith('.dart')) { | 165 if (_isHttpStylePackageUrl(uri)) { |
| 161 var packageUri = | 166 // Use package: urls if available. This rule here is more permissive than |
| 162 Uri.parse('package:${uri.path.substring(_packageRoot.length)}'); | 167 // how we translate urls in polymer-build, but we expect Dartium to limit |
| 163 var canonicalLib = _libs[packageUri]; | 168 // the cases where there are differences. The polymer-build issues an error |
| 169 // when using packages/ inside lib without properly stepping out all the way |
| 170 // to the packages folder. If users don't create symlinks in the source |
| 171 // tree, then Dartium will also complain because it won't find the file seen |
| 172 // in an HTML import. |
| 173 var packagePath = uri.path.substring( |
| 174 uri.path.lastIndexOf('packages/') + 'packages/'.length); |
| 175 var canonicalLib = _libs[Uri.parse('package:$packagePath')]; |
| 164 if (canonicalLib != null) { | 176 if (canonicalLib != null) { |
| 165 lib = canonicalLib; | 177 lib = canonicalLib; |
| 166 } | 178 } |
| 167 } | 179 } |
| 168 | 180 |
| 169 if (lib == null) { | 181 if (lib == null) { |
| 170 _loaderLog.info('$uri library not found'); | 182 _loaderLog.info('$uri library not found'); |
| 171 return; | 183 return; |
| 172 } | 184 } |
| 173 | 185 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 print("warning: methods marked with @initMethod should take no " | 224 print("warning: methods marked with @initMethod should take no " |
| 213 "arguments, ${method.simpleName} expects some."); | 225 "arguments, ${method.simpleName} expects some."); |
| 214 return; | 226 return; |
| 215 } | 227 } |
| 216 obj.invoke(method.simpleName, const []); | 228 obj.invoke(method.simpleName, const []); |
| 217 } | 229 } |
| 218 | 230 |
| 219 class _InitMethodAnnotation { | 231 class _InitMethodAnnotation { |
| 220 const _InitMethodAnnotation(); | 232 const _InitMethodAnnotation(); |
| 221 } | 233 } |
| OLD | NEW |