| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "crypto/random.h" | 10 #include "crypto/random.h" |
| 11 #include "dart/runtime/include/dart_api.h" | 11 #include "dart/runtime/include/dart_api.h" |
| 12 #include "dart/runtime/include/dart_native_api.h" | 12 #include "dart/runtime/include/dart_native_api.h" |
| 13 #include "mojo/dart/embedder/builtin.h" | 13 #include "mojo/dart/embedder/builtin.h" |
| 14 #include "mojo/dart/embedder/dart_controller.h" | 14 #include "mojo/dart/embedder/dart_controller.h" |
| 15 #include "mojo/dart/embedder/isolate_data.h" | 15 #include "mojo/dart/embedder/isolate_data.h" |
| 16 #include "mojo/public/c/system/core.h" | 16 #include "mojo/public/c/system/core.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 namespace dart { | 19 namespace dart { |
| 20 | 20 |
| 21 extern const uint8_t* snapshot_buffer; | 21 extern const uint8_t* vm_isolate_snapshot_buffer; |
| 22 extern const uint8_t* isolate_snapshot_buffer; |
| 22 | 23 |
| 23 const char* kDartScheme = "dart:"; | 24 const char* kDartScheme = "dart:"; |
| 24 const char* kAsyncLibURL = "dart:async"; | 25 const char* kAsyncLibURL = "dart:async"; |
| 25 const char* kInternalLibURL = "dart:_internal"; | 26 const char* kInternalLibURL = "dart:_internal"; |
| 26 const char* kIsolateLibURL = "dart:isolate"; | 27 const char* kIsolateLibURL = "dart:isolate"; |
| 27 const char* kIOLibURL = "dart:io"; | 28 const char* kIOLibURL = "dart:io"; |
| 28 const char* kCoreLibURL = "dart:core"; | 29 const char* kCoreLibURL = "dart:core"; |
| 29 | 30 |
| 30 static bool IsDartSchemeURL(const char* url_name) { | 31 static bool IsDartSchemeURL(const char* url_name) { |
| 31 static const intptr_t kDartSchemeLen = strlen(kDartScheme); | 32 static const intptr_t kDartSchemeLen = strlen(kDartScheme); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 Dart_NewStringFromCString("_getPrintClosure"), | 193 Dart_NewStringFromCString("_getPrintClosure"), |
| 193 0, | 194 0, |
| 194 nullptr); | 195 nullptr); |
| 195 DART_CHECK_VALID(print); | 196 DART_CHECK_VALID(print); |
| 196 result = Dart_SetField(internal_lib, | 197 result = Dart_SetField(internal_lib, |
| 197 Dart_NewStringFromCString("_printClosure"), | 198 Dart_NewStringFromCString("_printClosure"), |
| 198 print); | 199 print); |
| 199 DART_CHECK_VALID(result); | 200 DART_CHECK_VALID(result); |
| 200 | 201 |
| 201 DART_CHECK_VALID(Dart_Invoke( | 202 DART_CHECK_VALID(Dart_Invoke( |
| 202 builtin_lib, Dart_NewStringFromCString("_setupHooks"), 0, NULL)); | 203 builtin_lib, Dart_NewStringFromCString("_setupHooks"), 0, nullptr)); |
| 203 DART_CHECK_VALID(Dart_Invoke( | 204 DART_CHECK_VALID(Dart_Invoke( |
| 204 isolate_lib, Dart_NewStringFromCString("_setupHooks"), 0, NULL)); | 205 isolate_lib, Dart_NewStringFromCString("_setupHooks"), 0, nullptr)); |
| 205 | 206 |
| 206 // Setup the 'scheduleImmediate' closure. | 207 // Setup the 'scheduleImmediate' closure. |
| 207 Dart_Handle schedule_immediate_closure = Dart_Invoke( | 208 Dart_Handle schedule_immediate_closure = Dart_Invoke( |
| 208 isolate_lib, | 209 isolate_lib, |
| 209 Dart_NewStringFromCString("_getIsolateScheduleImmediateClosure"), | 210 Dart_NewStringFromCString("_getIsolateScheduleImmediateClosure"), |
| 210 0, | 211 0, |
| 211 nullptr); | 212 nullptr); |
| 212 Dart_Handle schedule_args[1]; | 213 Dart_Handle schedule_args[1]; |
| 213 schedule_args[0] = schedule_immediate_closure; | 214 schedule_args[0] = schedule_immediate_closure; |
| 214 result = Dart_Invoke( | 215 result = Dart_Invoke( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 237 Dart_NewStringFromCString("_setPackageRoot"), | 238 Dart_NewStringFromCString("_setPackageRoot"), |
| 238 kNumArgs, | 239 kNumArgs, |
| 239 dart_args); | 240 dart_args); |
| 240 DART_CHECK_VALID(result); | 241 DART_CHECK_VALID(result); |
| 241 | 242 |
| 242 // Setup the uriBase with the base uri of the mojo app. | 243 // Setup the uriBase with the base uri of the mojo app. |
| 243 Dart_Handle uri_base = Dart_Invoke( | 244 Dart_Handle uri_base = Dart_Invoke( |
| 244 builtin_lib, | 245 builtin_lib, |
| 245 Dart_NewStringFromCString("_getUriBaseClosure"), | 246 Dart_NewStringFromCString("_getUriBaseClosure"), |
| 246 0, | 247 0, |
| 247 NULL); | 248 nullptr); |
| 248 DART_CHECK_VALID(uri_base); | 249 DART_CHECK_VALID(uri_base); |
| 249 result = Dart_SetField(core_lib, | 250 result = Dart_SetField(core_lib, |
| 250 Dart_NewStringFromCString("_uriBaseClosure"), | 251 Dart_NewStringFromCString("_uriBaseClosure"), |
| 251 uri_base); | 252 uri_base); |
| 252 DART_CHECK_VALID(result); | 253 DART_CHECK_VALID(result); |
| 253 | 254 |
| 254 return result; | 255 return result; |
| 255 } | 256 } |
| 256 | 257 |
| 257 static Dart_Isolate CreateServiceIsolateHelper(const char* script_uri, | 258 static Dart_Isolate CreateServiceIsolateHelper(const char* script_uri, |
| 258 char** error) { | 259 char** error) { |
| 259 // TODO(johnmccutchan): Add support the service isolate. | 260 // TODO(johnmccutchan): Add support the service isolate. |
| 260 // No callbacks for service isolate. | 261 // No callbacks for service isolate. |
| 261 IsolateCallbacks callbacks; | 262 IsolateCallbacks callbacks; |
| 262 IsolateData* isolate_data = | 263 IsolateData* isolate_data = |
| 263 new IsolateData(NULL, false, callbacks, "", "", ""); | 264 new IsolateData(nullptr, false, callbacks, "", "", ""); |
| 264 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, | 265 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, |
| 265 "main", | 266 "main", |
| 266 snapshot_buffer, | 267 isolate_snapshot_buffer, |
| 267 isolate_data, | 268 isolate_data, |
| 268 error); | 269 error); |
| 269 if (isolate == nullptr) { | 270 if (isolate == nullptr) { |
| 270 delete isolate_data; | 271 delete isolate_data; |
| 271 return nullptr; | 272 return nullptr; |
| 272 } | 273 } |
| 273 return isolate; | 274 return isolate; |
| 274 } | 275 } |
| 275 | 276 |
| 276 static Dart_Isolate CreateIsolateHelper(void* dart_app, | 277 static Dart_Isolate CreateIsolateHelper(void* dart_app, |
| 277 bool strict_compilation, | 278 bool strict_compilation, |
| 278 IsolateCallbacks callbacks, | 279 IsolateCallbacks callbacks, |
| 279 const std::string& script, | 280 const std::string& script, |
| 280 const std::string& script_uri, | 281 const std::string& script_uri, |
| 281 const std::string& package_root, | 282 const std::string& package_root, |
| 282 char** error) { | 283 char** error) { |
| 283 IsolateData* isolate_data = new IsolateData( | 284 IsolateData* isolate_data = new IsolateData( |
| 284 dart_app, | 285 dart_app, |
| 285 strict_compilation, | 286 strict_compilation, |
| 286 callbacks, | 287 callbacks, |
| 287 script, | 288 script, |
| 288 script_uri, | 289 script_uri, |
| 289 package_root); | 290 package_root); |
| 290 Dart_Isolate isolate = Dart_CreateIsolate( | 291 Dart_Isolate isolate = Dart_CreateIsolate( |
| 291 script_uri.c_str(), "main", snapshot_buffer, isolate_data, error); | 292 script_uri.c_str(), "main", isolate_snapshot_buffer, isolate_data, error); |
| 292 if (isolate == nullptr) { | 293 if (isolate == nullptr) { |
| 293 delete isolate_data; | 294 delete isolate_data; |
| 294 return nullptr; | 295 return nullptr; |
| 295 } | 296 } |
| 296 | 297 |
| 297 DPCHECK(!Dart_IsServiceIsolate(isolate)); | 298 DPCHECK(!Dart_IsServiceIsolate(isolate)); |
| 298 Dart_EnterScope(); | 299 Dart_EnterScope(); |
| 299 | 300 |
| 300 Dart_IsolateSetStrictCompilation(strict_compilation); | 301 Dart_IsolateSetStrictCompilation(strict_compilation); |
| 301 | 302 |
| 302 // Setup the native resolvers for the builtin libraries as they are not set | 303 // Setup the native resolvers for the builtin libraries as they are not set |
| 303 // up when the snapshot is read. | 304 // up when the snapshot is read. |
| 304 CHECK(snapshot_buffer != nullptr); | 305 CHECK(isolate_snapshot_buffer != nullptr); |
| 305 Builtin::PrepareLibrary(Builtin::kBuiltinLibrary); | 306 Builtin::PrepareLibrary(Builtin::kBuiltinLibrary); |
| 306 Builtin::PrepareLibrary(Builtin::kMojoInternalLibrary); | 307 Builtin::PrepareLibrary(Builtin::kMojoInternalLibrary); |
| 307 | 308 |
| 308 if (!callbacks.create.is_null()) { | 309 if (!callbacks.create.is_null()) { |
| 309 callbacks.create.Run(script_uri.c_str(), | 310 callbacks.create.Run(script_uri.c_str(), |
| 310 "main", | 311 "main", |
| 311 package_root.c_str(), | 312 package_root.c_str(), |
| 312 isolate_data, | 313 isolate_data, |
| 313 error); | 314 error); |
| 314 } | 315 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // that isn't there anymore. | 449 // that isn't there anymore. |
| 449 args[0] = "--worker-timeout-millis=0"; | 450 args[0] = "--worker-timeout-millis=0"; |
| 450 | 451 |
| 451 for (int i = 0; i < arguments_count; ++i) { | 452 for (int i = 0; i < arguments_count; ++i) { |
| 452 args[i + 1] = arguments[i]; | 453 args[i + 1] = arguments[i]; |
| 453 } | 454 } |
| 454 | 455 |
| 455 bool result = Dart_SetVMFlags(kNumArgs, args); | 456 bool result = Dart_SetVMFlags(kNumArgs, args); |
| 456 CHECK(result); | 457 CHECK(result); |
| 457 | 458 |
| 458 result = Dart_Initialize(IsolateCreateCallback, | 459 result = Dart_Initialize(vm_isolate_snapshot_buffer, |
| 460 IsolateCreateCallback, |
| 459 nullptr, // Isolate interrupt callback. | 461 nullptr, // Isolate interrupt callback. |
| 460 UnhandledExceptionCallback, | 462 UnhandledExceptionCallback, |
| 461 IsolateShutdownCallback, | 463 IsolateShutdownCallback, |
| 462 // File IO callbacks. | 464 // File IO callbacks. |
| 463 nullptr, nullptr, nullptr, nullptr, | 465 nullptr, nullptr, nullptr, nullptr, |
| 464 entropy); | 466 entropy); |
| 465 CHECK(result); | 467 CHECK(result); |
| 466 initialized_ = true; | 468 initialized_ = true; |
| 467 } | 469 } |
| 468 | 470 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 | 714 |
| 713 Dart_ExitScope(); | 715 Dart_ExitScope(); |
| 714 Dart_ShutdownIsolate(); | 716 Dart_ShutdownIsolate(); |
| 715 Dart_Cleanup(); | 717 Dart_Cleanup(); |
| 716 root_isolate_ = nullptr; | 718 root_isolate_ = nullptr; |
| 717 initialized_ = false; | 719 initialized_ = false; |
| 718 } | 720 } |
| 719 | 721 |
| 720 } // namespace apps | 722 } // namespace apps |
| 721 } // namespace mojo | 723 } // namespace mojo |
| OLD | NEW |