Chromium Code Reviews| 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_controller.h" | 6 #include "sky/engine/core/script/dart_controller.h" |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "dart/runtime/bin/embedded_dart_io.h" | 12 #include "dart/runtime/bin/embedded_dart_io.h" |
| 13 #include "dart/runtime/include/dart_mirrors_api.h" | 13 #include "dart/runtime/include/dart_mirrors_api.h" |
| 14 #include "gen/sky/platform/RuntimeEnabledFeatures.h" | 14 #include "gen/sky/platform/RuntimeEnabledFeatures.h" |
| 15 #include "sky/engine/bindings/builtin.h" | 15 #include "sky/engine/bindings/builtin.h" |
| 16 #include "sky/engine/bindings/builtin_natives.h" | 16 #include "sky/engine/bindings/builtin_natives.h" |
| 17 #include "sky/engine/bindings/builtin_sky.h" | 17 #include "sky/engine/bindings/builtin_sky.h" |
| 18 #include "sky/engine/core/app/AbstractModule.h" | 18 #include "sky/engine/core/app/AbstractModule.h" |
| 19 #include "sky/engine/core/app/Module.h" | 19 #include "sky/engine/core/app/Module.h" |
| 20 #include "sky/engine/core/dom/Element.h" | 20 #include "sky/engine/core/dom/Element.h" |
| 21 #include "sky/engine/core/frame/LocalFrame.h" | 21 #include "sky/engine/core/frame/LocalFrame.h" |
| 22 #include "sky/engine/core/html/HTMLScriptElement.h" | 22 #include "sky/engine/core/html/HTMLScriptElement.h" |
| 23 #include "sky/engine/core/html/imports/HTMLImport.h" | 23 #include "sky/engine/core/html/imports/HTMLImport.h" |
| 24 #include "sky/engine/core/html/imports/HTMLImportChild.h" | 24 #include "sky/engine/core/html/imports/HTMLImportChild.h" |
| 25 #include "sky/engine/core/loader/FrameLoaderClient.h" | 25 #include "sky/engine/core/loader/FrameLoaderClient.h" |
| 26 #include "sky/engine/core/script/dart_debugger.h" | 26 #include "sky/engine/core/script/dart_debugger.h" |
| 27 #include "sky/engine/core/script/dart_dependency_catcher.h" | 27 #include "sky/engine/core/script/dart_dependency_catcher.h" |
| 28 #include "sky/engine/core/script/dart_loader.h" | 28 #include "sky/engine/core/script/dart_loader.h" |
| 29 #include "sky/engine/core/script/dart_service_isolate.h" | 29 #include "sky/engine/core/script/dart_service_isolate.h" |
| 30 #include "sky/engine/core/script/dart_snapshot_loader.h" | |
| 30 #include "sky/engine/core/script/dom_dart_state.h" | 31 #include "sky/engine/core/script/dom_dart_state.h" |
| 31 #include "sky/engine/public/platform/Platform.h" | 32 #include "sky/engine/public/platform/Platform.h" |
| 32 #include "sky/engine/tonic/dart_api_scope.h" | 33 #include "sky/engine/tonic/dart_api_scope.h" |
| 33 #include "sky/engine/tonic/dart_class_library.h" | 34 #include "sky/engine/tonic/dart_class_library.h" |
| 34 #include "sky/engine/tonic/dart_error.h" | 35 #include "sky/engine/tonic/dart_error.h" |
| 35 #include "sky/engine/tonic/dart_gc_controller.h" | 36 #include "sky/engine/tonic/dart_gc_controller.h" |
| 36 #include "sky/engine/tonic/dart_invoke.h" | 37 #include "sky/engine/tonic/dart_invoke.h" |
| 37 #include "sky/engine/tonic/dart_isolate_scope.h" | 38 #include "sky/engine/tonic/dart_isolate_scope.h" |
| 38 #include "sky/engine/tonic/dart_state.h" | 39 #include "sky/engine/tonic/dart_state.h" |
| 39 #include "sky/engine/tonic/dart_wrappable.h" | 40 #include "sky/engine/tonic/dart_wrappable.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 } | 127 } |
| 127 | 128 |
| 128 void DartController::LoadMainLibrary(const KURL& url, mojo::URLResponsePtr respo nse) { | 129 void DartController::LoadMainLibrary(const KURL& url, mojo::URLResponsePtr respo nse) { |
| 129 DartLoader& loader = dart_state()->loader(); | 130 DartLoader& loader = dart_state()->loader(); |
| 130 DartDependencyCatcher dependency_catcher(loader); | 131 DartDependencyCatcher dependency_catcher(loader); |
| 131 loader.LoadLibrary(url, response.Pass()); | 132 loader.LoadLibrary(url, response.Pass()); |
| 132 loader.WaitForDependencies(dependency_catcher.dependencies(), | 133 loader.WaitForDependencies(dependency_catcher.dependencies(), |
| 133 base::Bind(&DartController::DidLoadMainLibrary, wea k_factory_.GetWeakPtr(), url)); | 134 base::Bind(&DartController::DidLoadMainLibrary, wea k_factory_.GetWeakPtr(), url)); |
| 134 } | 135 } |
| 135 | 136 |
| 137 void DartController::DidLoadSnapshot() { | |
| 138 DCHECK(Dart_CurrentIsolate() == nullptr); | |
| 139 snapshot_loader_ = nullptr; | |
| 140 | |
| 141 Dart_Isolate isolate = dart_state()->isolate(); | |
| 142 DartIsolateScope isolate_scope(isolate); | |
| 143 DartApiScope dart_api_scope; | |
| 144 | |
| 145 Dart_Handle library = Dart_RootLibrary(); | |
| 146 if (LogIfError(library)) | |
| 147 return; | |
| 148 DartInvokeAppField(library, ToDart("main"), 0, nullptr); | |
| 149 } | |
| 150 | |
| 151 void DartController::LoadSnapshot(const KURL& url, mojo::URLResponsePtr response ) { | |
| 152 snapshot_loader_ = adoptPtr(new DartSnapshotLoader(dart_state())); | |
| 153 snapshot_loader_->LoadSnapshot(url, response.Pass(), | |
| 154 base::Bind(&DartController::DidLoadSnapshot, weak_factory_.GetWeakPtr())); | |
| 155 } | |
| 156 | |
| 136 void DartController::LoadScriptInModule( | 157 void DartController::LoadScriptInModule( |
| 137 AbstractModule* module, | 158 AbstractModule* module, |
| 138 const String& source, | 159 const String& source, |
| 139 const TextPosition& position, | 160 const TextPosition& position, |
| 140 const LoadFinishedCallback& finished_callback) { | 161 const LoadFinishedCallback& finished_callback) { |
| 141 DartIsolateScope isolate_scope(dart_state()->isolate()); | 162 DartIsolateScope isolate_scope(dart_state()->isolate()); |
| 142 DartApiScope dart_api_scope; | 163 DartApiScope dart_api_scope; |
| 143 | 164 |
| 144 DartDependencyCatcher dependency_catcher(dart_state()->loader()); | 165 DartDependencyCatcher dependency_catcher(dart_state()->loader()); |
| 145 Dart_Handle library_handle = CreateLibrary(module, source, position); | 166 Dart_Handle library_handle = CreateLibrary(module, source, position); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 dart_state->SetIsolate(isolate); | 303 dart_state->SetIsolate(isolate); |
| 283 | 304 |
| 284 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); | 305 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); |
| 285 | 306 |
| 286 { | 307 { |
| 287 DartApiScope apiScope; | 308 DartApiScope apiScope; |
| 288 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 309 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 289 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); | 310 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); |
| 290 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 311 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 291 | 312 |
| 292 // Ensure the isolate has a root library. | 313 if (!script_uri) { |
| 293 Dart_LoadScript(Dart_NewStringFromCString("dart:empty"), | 314 // Ensure the isolate has a root library. |
|
eseidel
2015/06/23 06:21:39
I don't think this is necessary anymore This was
abarth-chromium
2015/06/23 14:50:42
Yeah, I was close to removing it entirely. I thin
eseidel
2015/06/23 16:02:03
My recollection was it was needed because of the w
| |
| 294 Dart_NewStringFromCString(""), 0, 0); | 315 Dart_LoadScript(Dart_NewStringFromCString("dart:empty"), |
| 316 Dart_EmptyString(), 0, 0); | |
| 317 } | |
| 295 } | 318 } |
| 296 | 319 |
| 297 Dart_ExitIsolate(); | 320 Dart_ExitIsolate(); |
| 298 | 321 |
| 299 CHECK(Dart_IsolateMakeRunnable(isolate)); | 322 CHECK(Dart_IsolateMakeRunnable(isolate)); |
| 300 return isolate; | 323 return isolate; |
| 301 } | 324 } |
| 302 | 325 |
| 303 static void CallHandleMessage(base::WeakPtr<DartState> dart_state) { | 326 static void CallHandleMessage(base::WeakPtr<DartState> dart_state) { |
| 304 TRACE_EVENT0("sky", "CallHandleMessage"); | 327 TRACE_EVENT0("sky", "CallHandleMessage"); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 327 static_cast<DartState*>(dom_dart_state_.get()), &error); | 350 static_cast<DartState*>(dom_dart_state_.get()), &error); |
| 328 Dart_SetMessageNotifyCallback(MessageNotifyCallback); | 351 Dart_SetMessageNotifyCallback(MessageNotifyCallback); |
| 329 CHECK(isolate) << error; | 352 CHECK(isolate) << error; |
| 330 dom_dart_state_->SetIsolate(isolate); | 353 dom_dart_state_->SetIsolate(isolate); |
| 331 Dart_SetGcCallbacks(DartGCPrologue, DartGCEpilogue); | 354 Dart_SetGcCallbacks(DartGCPrologue, DartGCEpilogue); |
| 332 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); | 355 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); |
| 333 | 356 |
| 334 { | 357 { |
| 335 DartApiScope apiScope; | 358 DartApiScope apiScope; |
| 336 | 359 |
| 337 // Ensure the isolate has a root library. | |
| 338 Dart_LoadScript(Dart_NewStringFromCString("dart:empty"), | |
| 339 Dart_NewStringFromCString(""), 0, 0); | |
| 340 | |
| 341 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 360 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 342 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); | 361 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); |
| 343 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 362 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 344 BuiltinNatives::Init(BuiltinNatives::MainIsolate); | 363 BuiltinNatives::Init(BuiltinNatives::MainIsolate); |
| 345 | 364 |
| 346 builtin_sky_ = adoptPtr(new BuiltinSky(dart_state())); | 365 builtin_sky_ = adoptPtr(new BuiltinSky(dart_state())); |
| 347 dart_state()->class_library().set_provider(builtin_sky_.get()); | 366 dart_state()->class_library().set_provider(builtin_sky_.get()); |
| 348 | 367 |
| 349 if (dart_state()->document()) | 368 if (dart_state()->document()) |
| 350 builtin_sky_->InstallWindow(dart_state()); | 369 builtin_sky_->InstallWindow(dart_state()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 nullptr, // Isolate interrupt callback. | 407 nullptr, // Isolate interrupt callback. |
| 389 UnhandledExceptionCallback, IsolateShutdownCallback, | 408 UnhandledExceptionCallback, IsolateShutdownCallback, |
| 390 // File IO callbacks. | 409 // File IO callbacks. |
| 391 nullptr, nullptr, nullptr, nullptr, nullptr)); | 410 nullptr, nullptr, nullptr, nullptr, nullptr)); |
| 392 // Wait for load port- ensures handle watcher and service isolates are | 411 // Wait for load port- ensures handle watcher and service isolates are |
| 393 // running. | 412 // running. |
| 394 Dart_ServiceWaitForLoadPort(); | 413 Dart_ServiceWaitForLoadPort(); |
| 395 } | 414 } |
| 396 | 415 |
| 397 } // namespace blink | 416 } // namespace blink |
| OLD | NEW |