Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: mojo/dart/embedder/dart_controller.cc

Issue 816113004: Dart: Adds a content handler and a test. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 config.package_root, 416 config.package_root,
417 config.error); 417 config.error);
418 if (isolate == nullptr) { 418 if (isolate == nullptr) {
419 return false; 419 return false;
420 } 420 }
421 421
422 Dart_EnterIsolate(isolate); 422 Dart_EnterIsolate(isolate);
423 Dart_Handle result; 423 Dart_Handle result;
424 Dart_EnterScope(); 424 Dart_EnterScope();
425 425
426 Dart_Handle root_lib = Dart_RootLibrary(); 426 // Start the MojoHandleWatcher.
427 DART_CHECK_VALID(root_lib);
428
429 Dart_Handle builtin_lib =
430 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
431 DART_CHECK_VALID(builtin_lib);
432 Dart_Handle mojo_core_lib = 427 Dart_Handle mojo_core_lib =
433 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); 428 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary);
434 DART_CHECK_VALID(mojo_core_lib); 429 DART_CHECK_VALID(mojo_core_lib);
435
436 // Start the MojoHandleWatcher.
437 Dart_Handle handle_watcher_type = Dart_GetType( 430 Dart_Handle handle_watcher_type = Dart_GetType(
438 mojo_core_lib, 431 mojo_core_lib,
439 Dart_NewStringFromCString("MojoHandleWatcher"), 432 Dart_NewStringFromCString("MojoHandleWatcher"),
440 0, 433 0,
441 nullptr); 434 nullptr);
442 DART_CHECK_VALID(handle_watcher_type); 435 DART_CHECK_VALID(handle_watcher_type);
443 result = Dart_Invoke( 436 result = Dart_Invoke(
444 handle_watcher_type, 437 handle_watcher_type,
445 Dart_NewStringFromCString("Start"), 438 Dart_NewStringFromCString("Start"),
446 0, 439 0,
447 nullptr); 440 nullptr);
448 DART_CHECK_VALID(result); 441 DART_CHECK_VALID(result);
449 442
450 // RunLoop until the handle watcher isolate is spun-up. 443 // RunLoop until the handle watcher isolate is spun-up.
451 result = Dart_RunLoop(); 444 result = Dart_RunLoop();
452 DART_CHECK_VALID(result); 445 DART_CHECK_VALID(result);
453 446
447 // Load the root library into the builtin library so that main can be found.
448 Dart_Handle builtin_lib =
449 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
450 DART_CHECK_VALID(builtin_lib);
451 Dart_Handle root_lib = Dart_RootLibrary();
452 DART_CHECK_VALID(root_lib);
454 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); 453 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null());
455 DART_CHECK_VALID(result); 454 DART_CHECK_VALID(result);
456 455
457 if (config.compile_all) { 456 if (config.compile_all) {
458 result = Dart_CompileAll(); 457 result = Dart_CompileAll();
459 DART_CHECK_VALID(result); 458 DART_CHECK_VALID(result);
460 } 459 }
461 460
462 Dart_Handle main_closure = Dart_Invoke( 461 Dart_Handle main_closure = Dart_Invoke(
463 builtin_lib, 462 builtin_lib,
464 Dart_NewStringFromCString("_getMainClosure"), 463 Dart_NewStringFromCString("_getMainClosure"),
465 0, 464 0,
466 nullptr); 465 nullptr);
467 DART_CHECK_VALID(main_closure); 466 DART_CHECK_VALID(main_closure);
468 467
469 // Call _startIsolate in the isolate library to enable dispatching the 468 // Call _startIsolate in the isolate library to enable dispatching the
470 // initial startup message. 469 // initial startup message.
471 const intptr_t kNumIsolateArgs = 2; 470 const intptr_t kNumIsolateArgs = 2;
472 Dart_Handle isolate_args[kNumIsolateArgs]; 471 Dart_Handle isolate_args[kNumIsolateArgs];
473 isolate_args[0] = main_closure; // entryPoint 472 isolate_args[0] = main_closure; // entryPoint
474 isolate_args[1] = Dart_NewList(1); // args 473 isolate_args[1] = Dart_NewList(2); // args
475 DART_CHECK_VALID(isolate_args[1]); 474 DART_CHECK_VALID(isolate_args[1]);
475
476 Dart_Handle script_uri = Dart_NewStringFromUTF8(
477 reinterpret_cast<const uint8_t*>(config.script_uri.data()),
478 config.script_uri.length());
476 Dart_ListSetAt(isolate_args[1], 0, Dart_NewInteger(config.handle)); 479 Dart_ListSetAt(isolate_args[1], 0, Dart_NewInteger(config.handle));
480 Dart_ListSetAt(isolate_args[1], 1, script_uri);
477 481
478 Dart_Handle isolate_lib = 482 Dart_Handle isolate_lib =
479 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL)); 483 Dart_LookupLibrary(Dart_NewStringFromCString(kIsolateLibURL));
480 DART_CHECK_VALID(isolate_lib); 484 DART_CHECK_VALID(isolate_lib);
481 485
482 result = Dart_Invoke(isolate_lib, 486 result = Dart_Invoke(isolate_lib,
483 Dart_NewStringFromCString("_startMainIsolate"), 487 Dart_NewStringFromCString("_startMainIsolate"),
484 kNumIsolateArgs, 488 kNumIsolateArgs,
485 isolate_args); 489 isolate_args);
486 DART_CHECK_VALID(result); 490 DART_CHECK_VALID(result);
(...skipping 13 matching lines...) Expand all
500 DART_CHECK_VALID(result); 504 DART_CHECK_VALID(result);
501 505
502 Dart_ExitScope(); 506 Dart_ExitScope();
503 Dart_ShutdownIsolate(); 507 Dart_ShutdownIsolate();
504 Dart_Cleanup(); 508 Dart_Cleanup();
505 return true; 509 return true;
506 } 510 }
507 511
508 } // namespace apps 512 } // namespace apps
509 } // namespace mojo 513 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698