| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
| 6 #include "sky/engine/core/script/dart_loader.h" | 6 #include "sky/engine/core/script/dart_loader.h" |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "mojo/common/data_pipe_drainer.h" | 9 #include "mojo/common/data_pipe_drainer.h" |
| 10 #include "sky/engine/core/script/dart_dependency_catcher.h" | 10 #include "sky/engine/core/script/dart_dependency_catcher.h" |
| 11 #include "sky/engine/core/script/dom_dart_state.h" | 11 #include "sky/engine/core/script/dom_dart_state.h" |
| 12 #include "sky/engine/platform/fetcher/MojoFetcher.h" | 12 #include "sky/engine/platform/fetcher/MojoFetcher.h" |
| 13 #include "sky/engine/platform/weborigin/KURL.h" | 13 #include "sky/engine/platform/weborigin/KURL.h" |
| 14 #include "sky/engine/tonic/dart_api_scope.h" | 14 #include "sky/engine/tonic/dart_api_scope.h" |
| 15 #include "sky/engine/tonic/dart_converter.h" | 15 #include "sky/engine/tonic/dart_converter.h" |
| 16 #include "sky/engine/tonic/dart_error.h" | 16 #include "sky/engine/tonic/dart_error.h" |
| 17 #include "sky/engine/tonic/dart_isolate_scope.h" | 17 #include "sky/engine/tonic/dart_isolate_scope.h" |
| 18 #include "sky/engine/wtf/MainThread.h" | 18 #include "sky/engine/wtf/MainThread.h" |
| 19 | 19 |
| 20 using mojo::common::DataPipeDrainer; | 20 using mojo::common::DataPipeDrainer; |
| 21 | 21 |
| 22 namespace blink { | 22 namespace blink { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 Dart_Handle CanonicalizeURL(DartState* state, | 25 Dart_Handle CanonicalizeURL(DartState* state, |
| 26 Dart_Handle library, | 26 Dart_Handle library, |
| 27 Dart_Handle url) { | 27 Dart_Handle url) { |
| 28 String string = StringFromDart(url); | 28 String string = StringFromDart(url); |
| 29 if (string.startsWith("dart:")) | 29 if (string.startsWith("dart:") || string.startsWith("mojo:")) |
| 30 return url; | 30 return url; |
| 31 // TODO(dart): Figure out how 'package:' should work in sky. | 31 // TODO(dart): Figure out how 'package:' should work in sky. |
| 32 if (string.startsWith("package:")) { | 32 if (string.startsWith("package:")) { |
| 33 string.replace("package:", "/gen/"); | 33 string.replace("package:", "/gen/"); |
| 34 } | 34 } |
| 35 String library_url_string = StringFromDart(Dart_LibraryUrl(library)); | 35 String library_url_string = StringFromDart(Dart_LibraryUrl(library)); |
| 36 KURL library_url = KURL(ParsedURLString, library_url_string); | 36 KURL library_url = KURL(ParsedURLString, library_url_string); |
| 37 KURL resolved_url = KURL(library_url, string); | 37 KURL resolved_url = KURL(library_url, string); |
| 38 return StringToDart(state, resolved_url.string()); | 38 return StringToDart(state, resolved_url.string()); |
| 39 } | 39 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 Dart_Handle DartLoader::HandleLibraryTag(Dart_LibraryTag tag, | 188 Dart_Handle DartLoader::HandleLibraryTag(Dart_LibraryTag tag, |
| 189 Dart_Handle library, | 189 Dart_Handle library, |
| 190 Dart_Handle url) { | 190 Dart_Handle url) { |
| 191 DCHECK(Dart_IsLibrary(library)); | 191 DCHECK(Dart_IsLibrary(library)); |
| 192 DCHECK(Dart_IsString(url)); | 192 DCHECK(Dart_IsString(url)); |
| 193 if (tag == Dart_kCanonicalizeUrl) | 193 if (tag == Dart_kCanonicalizeUrl) |
| 194 return CanonicalizeURL(DartState::Current(), library, url); | 194 return CanonicalizeURL(DartState::Current(), library, url); |
| 195 if (tag == Dart_kImportTag) { | 195 if (tag == Dart_kImportTag) { |
| 196 CHECK(WTF::isMainThread()); | 196 CHECK(WTF::isMainThread()); |
| 197 |
| 198 String string = StringFromDart(url); |
| 199 if (string.startsWith("mojo:")) { |
| 200 Dart_Handle mojo_library = Dart_LookupLibrary(url); |
| 201 LogIfError(mojo_library); |
| 202 return mojo_library; |
| 203 } |
| 204 |
| 197 return DOMDartState::Current()->loader().Import(library, url); | 205 return DOMDartState::Current()->loader().Import(library, url); |
| 198 } | 206 } |
| 199 if (tag == Dart_kSourceTag) { | 207 if (tag == Dart_kSourceTag) { |
| 200 CHECK(WTF::isMainThread()); | 208 CHECK(WTF::isMainThread()); |
| 201 return DOMDartState::Current()->loader().Source(library, url); | 209 return DOMDartState::Current()->loader().Source(library, url); |
| 202 } | 210 } |
| 203 DCHECK(false); | 211 DCHECK(false); |
| 204 return Dart_NewApiError("Unknown library tag."); | 212 return Dart_NewApiError("Unknown library tag."); |
| 205 } | 213 } |
| 206 | 214 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 283 |
| 276 WatcherSignaler watcher_signaler(*this, job); | 284 WatcherSignaler watcher_signaler(*this, job); |
| 277 | 285 |
| 278 LOG(ERROR) << "Library Load failed: " << job->url().string().utf8().data(); | 286 LOG(ERROR) << "Library Load failed: " << job->url().string().utf8().data(); |
| 279 // TODO(eseidel): Call Dart_LibraryHandleError in the SourceJob case? | 287 // TODO(eseidel): Call Dart_LibraryHandleError in the SourceJob case? |
| 280 | 288 |
| 281 jobs_.remove(job); | 289 jobs_.remove(job); |
| 282 } | 290 } |
| 283 | 291 |
| 284 } // namespace blink | 292 } // namespace blink |
| OLD | NEW |