| 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" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 CHECK(!LogIfError(Dart_RunLoop())); | 231 CHECK(!LogIfError(Dart_RunLoop())); |
| 232 handle_watcher_started = true; | 232 handle_watcher_started = true; |
| 233 } | 233 } |
| 234 | 234 |
| 235 // TODO(rafaelw): Right now this only supports the creation of the handle | 235 // TODO(rafaelw): Right now this only supports the creation of the handle |
| 236 // watcher isolate and the service isolate. Presumably, we'll want application | 236 // watcher isolate and the service isolate. Presumably, we'll want application |
| 237 // isolates to spawn their own isolates. | 237 // isolates to spawn their own isolates. |
| 238 static Dart_Isolate IsolateCreateCallback(const char* script_uri, | 238 static Dart_Isolate IsolateCreateCallback(const char* script_uri, |
| 239 const char* main, | 239 const char* main, |
| 240 const char* package_root, | 240 const char* package_root, |
| 241 Dart_IsolateFlags* flags, |
| 241 void* callback_data, | 242 void* callback_data, |
| 242 char** error) { | 243 char** error) { |
| 243 | |
| 244 if (IsServiceIsolateURL(script_uri)) { | 244 if (IsServiceIsolateURL(script_uri)) { |
| 245 CHECK(kDartIsolateSnapshotBuffer); | 245 CHECK(kDartIsolateSnapshotBuffer); |
| 246 DartState* dart_state = new DartState(); | 246 DartState* dart_state = new DartState(); |
| 247 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, | 247 Dart_Isolate isolate = |
| 248 "main", | 248 Dart_CreateIsolate(script_uri, "main", kDartIsolateSnapshotBuffer, |
| 249 kDartIsolateSnapshotBuffer, | 249 nullptr, nullptr, error); |
| 250 nullptr, | |
| 251 error); | |
| 252 CHECK(isolate) << error; | 250 CHECK(isolate) << error; |
| 253 dart_state->SetIsolate(isolate); | 251 dart_state->SetIsolate(isolate); |
| 254 CHECK(Dart_IsServiceIsolate(isolate)); | 252 CHECK(Dart_IsServiceIsolate(isolate)); |
| 255 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); | 253 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); |
| 256 { | 254 { |
| 257 DartApiScope apiScope; | 255 DartApiScope apiScope; |
| 258 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 256 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 259 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); | 257 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); |
| 260 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 258 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 261 BuiltinNatives::Init(BuiltinNatives::DartIOIsolate); | 259 BuiltinNatives::Init(BuiltinNatives::DartIOIsolate); |
| 262 // Start the handle watcher from the service isolate so it isn't available | 260 // Start the handle watcher from the service isolate so it isn't available |
| 263 // for debugging or general Observatory interaction. | 261 // for debugging or general Observatory interaction. |
| 264 EnsureHandleWatcherStarted(); | 262 EnsureHandleWatcherStarted(); |
| 265 if (RuntimeEnabledFeatures::observatoryEnabled()) { | 263 if (RuntimeEnabledFeatures::observatoryEnabled()) { |
| 266 std::string ip = "127.0.0.1"; | 264 std::string ip = "127.0.0.1"; |
| 267 const intptr_t port = 8181; | 265 const intptr_t port = 8181; |
| 268 const bool service_isolate_booted = | 266 const bool service_isolate_booted = |
| 269 DartServiceIsolate::Startup(ip, port, LibraryTagHandler, error); | 267 DartServiceIsolate::Startup(ip, port, LibraryTagHandler, error); |
| 270 CHECK(service_isolate_booted) << error; | 268 CHECK(service_isolate_booted) << error; |
| 271 } | 269 } |
| 272 } | 270 } |
| 273 Dart_ExitIsolate(); | 271 Dart_ExitIsolate(); |
| 274 return isolate; | 272 return isolate; |
| 275 } | 273 } |
| 276 | 274 |
| 277 // Create & start the handle watcher isolate | 275 // Create & start the handle watcher isolate |
| 278 CHECK(kDartIsolateSnapshotBuffer); | 276 CHECK(kDartIsolateSnapshotBuffer); |
| 279 DartState* dart_state = new DartState(); | 277 DartState* dart_state = new DartState(); |
| 280 Dart_Isolate isolate = Dart_CreateIsolate("sky:handle_watcher", "", | 278 Dart_Isolate isolate = |
| 281 kDartIsolateSnapshotBuffer, dart_state, error); | 279 Dart_CreateIsolate("sky:handle_watcher", "", kDartIsolateSnapshotBuffer, |
| 280 nullptr, dart_state, error); |
| 282 CHECK(isolate) << error; | 281 CHECK(isolate) << error; |
| 283 dart_state->SetIsolate(isolate); | 282 dart_state->SetIsolate(isolate); |
| 284 | 283 |
| 285 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); | 284 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); |
| 286 | 285 |
| 287 { | 286 { |
| 288 DartApiScope apiScope; | 287 DartApiScope apiScope; |
| 289 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 288 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 290 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); | 289 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); |
| 291 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 290 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 317 Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE, | 316 Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE, |
| 318 base::Bind(&CallHandleMessage, DartState::From(dest_isolate)->GetWeakPtr()
)); | 317 base::Bind(&CallHandleMessage, DartState::From(dest_isolate)->GetWeakPtr()
)); |
| 319 } | 318 } |
| 320 | 319 |
| 321 void DartController::CreateIsolateFor(PassOwnPtr<DOMDartState> state) { | 320 void DartController::CreateIsolateFor(PassOwnPtr<DOMDartState> state) { |
| 322 CHECK(kDartIsolateSnapshotBuffer); | 321 CHECK(kDartIsolateSnapshotBuffer); |
| 323 char* error = nullptr; | 322 char* error = nullptr; |
| 324 dom_dart_state_ = state; | 323 dom_dart_state_ = state; |
| 325 Dart_Isolate isolate = Dart_CreateIsolate( | 324 Dart_Isolate isolate = Dart_CreateIsolate( |
| 326 dom_dart_state_->url().string().utf8().data(), "main", | 325 dom_dart_state_->url().string().utf8().data(), "main", |
| 327 kDartIsolateSnapshotBuffer, | 326 kDartIsolateSnapshotBuffer, nullptr, |
| 328 static_cast<DartState*>(dom_dart_state_.get()), &error); | 327 static_cast<DartState*>(dom_dart_state_.get()), &error); |
| 329 Dart_SetMessageNotifyCallback(MessageNotifyCallback); | 328 Dart_SetMessageNotifyCallback(MessageNotifyCallback); |
| 330 CHECK(isolate) << error; | 329 CHECK(isolate) << error; |
| 331 dom_dart_state_->SetIsolate(isolate); | 330 dom_dart_state_->SetIsolate(isolate); |
| 332 Dart_SetGcCallbacks(DartGCPrologue, DartGCEpilogue); | 331 Dart_SetGcCallbacks(DartGCPrologue, DartGCEpilogue); |
| 333 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); | 332 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); |
| 334 | 333 |
| 335 { | 334 { |
| 336 DartApiScope apiScope; | 335 DartApiScope apiScope; |
| 337 | 336 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 nullptr, // Isolate interrupt callback. | 388 nullptr, // Isolate interrupt callback. |
| 390 UnhandledExceptionCallback, IsolateShutdownCallback, | 389 UnhandledExceptionCallback, IsolateShutdownCallback, |
| 391 // File IO callbacks. | 390 // File IO callbacks. |
| 392 nullptr, nullptr, nullptr, nullptr, nullptr)); | 391 nullptr, nullptr, nullptr, nullptr, nullptr)); |
| 393 // Wait for load port- ensures handle watcher and service isolates are | 392 // Wait for load port- ensures handle watcher and service isolates are |
| 394 // running. | 393 // running. |
| 395 Dart_ServiceWaitForLoadPort(); | 394 Dart_ServiceWaitForLoadPort(); |
| 396 } | 395 } |
| 397 | 396 |
| 398 } // namespace blink | 397 } // namespace blink |
| OLD | NEW |