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

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

Issue 950063002: Add patch file support to Dart embedder (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return result; 118 return result;
119 } 119 }
120 bool is_dart_scheme_url = IsDartSchemeURL(url_string); 120 bool is_dart_scheme_url = IsDartSchemeURL(url_string);
121 // If this is a Dart Scheme URL then it is not modified as it will be 121 // If this is a Dart Scheme URL then it is not modified as it will be
122 // handled internally. 122 // handled internally.
123 if (is_dart_scheme_url) { 123 if (is_dart_scheme_url) {
124 return url; 124 return url;
125 } 125 }
126 // Resolve the url within the context of the library's URL. 126 // Resolve the url within the context of the library's URL.
127 Dart_Handle builtin_lib = 127 Dart_Handle builtin_lib =
128 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 128 Builtin::GetLibrary(Builtin::kBuiltinLibrary);
129 return ResolveUri(library_url, url, builtin_lib); 129 return ResolveUri(library_url, url, builtin_lib);
130 } 130 }
131 131
132 Dart_Handle builtin_lib = 132 Dart_Handle builtin_lib =
133 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 133 Builtin::GetLibrary(Builtin::kBuiltinLibrary);
134 // Handle 'import' or 'part' requests for all other URIs. Call dart code to 134 // Handle 'import' or 'part' requests for all other URIs. Call dart code to
135 // read the source code asynchronously. 135 // read the source code asynchronously.
136 return LoadDataAsync_Invoke( 136 return LoadDataAsync_Invoke(
137 Dart_NewInteger(tag), url, library_url, builtin_lib, Dart_Null()); 137 Dart_NewInteger(tag), url, library_url, builtin_lib, Dart_Null());
138 } 138 }
139 139
140 static Dart_Handle SetWorkingDirectory(Dart_Handle builtin_lib) { 140 static Dart_Handle SetWorkingDirectory(Dart_Handle builtin_lib) {
141 base::FilePath current_dir; 141 base::FilePath current_dir;
142 PathService::Get(base::DIR_CURRENT, &current_dir); 142 PathService::Get(base::DIR_CURRENT, &current_dir);
143 143
(...skipping 14 matching lines...) Expand all
158 // First ensure all required libraries are available. 158 // First ensure all required libraries are available.
159 Dart_Handle url = Dart_NewStringFromCString(kAsyncLibURL); 159 Dart_Handle url = Dart_NewStringFromCString(kAsyncLibURL);
160 DART_CHECK_VALID(url); 160 DART_CHECK_VALID(url);
161 Dart_Handle async_lib = Dart_LookupLibrary(url); 161 Dart_Handle async_lib = Dart_LookupLibrary(url);
162 DART_CHECK_VALID(async_lib); 162 DART_CHECK_VALID(async_lib);
163 url = Dart_NewStringFromCString(kIsolateLibURL); 163 url = Dart_NewStringFromCString(kIsolateLibURL);
164 DART_CHECK_VALID(url); 164 DART_CHECK_VALID(url);
165 Dart_Handle isolate_lib = Dart_LookupLibrary(url); 165 Dart_Handle isolate_lib = Dart_LookupLibrary(url);
166 DART_CHECK_VALID(isolate_lib); 166 DART_CHECK_VALID(isolate_lib);
167 Dart_Handle mojo_core_lib = 167 Dart_Handle mojo_core_lib =
168 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); 168 Builtin::GetLibrary(Builtin::kMojoCoreLibrary);
169 DART_CHECK_VALID(mojo_core_lib); 169 DART_CHECK_VALID(mojo_core_lib);
170 170
171 // We need to ensure that all the scripts loaded so far are finalized 171 // We need to ensure that all the scripts loaded so far are finalized
172 // as we are about to invoke some Dart code below to setup closures. 172 // as we are about to invoke some Dart code below to setup closures.
173 Dart_Handle result = Dart_FinalizeLoading(false); 173 Dart_Handle result = Dart_FinalizeLoading(false);
174 DART_CHECK_VALID(result); 174 DART_CHECK_VALID(result);
175 175
176 // Setup the internal library's 'internalPrint' function. 176 // Setup the internal library's 'internalPrint' function.
177 Dart_Handle print = Dart_Invoke(builtin_lib, 177 Dart_Handle print = Dart_Invoke(builtin_lib,
178 Dart_NewStringFromCString("_getPrintClosure"), 178 Dart_NewStringFromCString("_getPrintClosure"),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 // Set up package root. 219 // Set up package root.
220 result = Dart_NewStringFromUTF8( 220 result = Dart_NewStringFromUTF8(
221 reinterpret_cast<const uint8_t*>(package_root.c_str()), 221 reinterpret_cast<const uint8_t*>(package_root.c_str()),
222 package_root.length()); 222 package_root.length());
223 DART_CHECK_VALID(result); 223 DART_CHECK_VALID(result);
224 224
225 const int kNumArgs = 1; 225 const int kNumArgs = 1;
226 Dart_Handle dart_args[kNumArgs]; 226 Dart_Handle dart_args[kNumArgs];
227 dart_args[0] = result; 227 dart_args[0] = result;
228 return Dart_Invoke(builtin_lib, 228 result = Dart_Invoke(builtin_lib,
229 Dart_NewStringFromCString("_setPackageRoot"), 229 Dart_NewStringFromCString("_setPackageRoot"),
230 kNumArgs, 230 kNumArgs,
231 dart_args); 231 dart_args);
232 232 DART_CHECK_VALID(result);
233 return result; 233 return result;
234 } 234 }
235 235
236 static Dart_Isolate CreateServiceIsolateHelper(const char* script_uri, 236 static Dart_Isolate CreateServiceIsolateHelper(const char* script_uri,
237 char** error) { 237 char** error) {
238 // TODO(johnmccutchan): Add support the service isolate. 238 // TODO(johnmccutchan): Add support the service isolate.
239 // No callbacks for service isolate. 239 // No callbacks for service isolate.
240 IsolateCallbacks callbacks; 240 IsolateCallbacks callbacks;
241 IsolateData* isolate_data = 241 IsolateData* isolate_data =
242 new IsolateData(NULL, false, callbacks, "", "", ""); 242 new IsolateData(NULL, false, callbacks, "", "", "");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 274 }
275 275
276 DPCHECK(!Dart_IsServiceIsolate(isolate)); 276 DPCHECK(!Dart_IsServiceIsolate(isolate));
277 Dart_EnterScope(); 277 Dart_EnterScope();
278 278
279 Dart_IsolateSetStrictCompilation(strict_compilation); 279 Dart_IsolateSetStrictCompilation(strict_compilation);
280 280
281 // Setup the native resolvers for the builtin libraries as they are not set 281 // Setup the native resolvers for the builtin libraries as they are not set
282 // up when the snapshot is read. 282 // up when the snapshot is read.
283 CHECK(snapshot_buffer != nullptr); 283 CHECK(snapshot_buffer != nullptr);
284 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 284 Builtin::PrepareLibrary(Builtin::kBuiltinLibrary);
285 Builtin::SetNativeResolver(Builtin::kMojoCoreLibrary); 285 Builtin::PrepareLibrary(Builtin::kMojoCoreLibrary);
286 286
287 if (!callbacks.create.is_null()) { 287 if (!callbacks.create.is_null()) {
288 callbacks.create.Run(script_uri.c_str(), 288 callbacks.create.Run(script_uri.c_str(),
289 "main", 289 "main",
290 package_root.c_str(), 290 package_root.c_str(),
291 isolate_data, 291 isolate_data,
292 error); 292 error);
293 } 293 }
294 294
295 // Set up the library tag handler for this isolate. 295 // Set up the library tag handler for this isolate.
296 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); 296 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler);
297 DART_CHECK_VALID(result); 297 DART_CHECK_VALID(result);
298 298
299 // Prepare builtin and its dependent libraries for use to resolve URIs. 299 // Prepare builtin and its dependent libraries for use to resolve URIs.
300 // The builtin library is part of the snapshot and is already available. 300 // The builtin library is part of the snapshot and is already available.
301 Dart_Handle builtin_lib = 301 Dart_Handle builtin_lib =
302 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 302 Builtin::GetLibrary(Builtin::kBuiltinLibrary);
303 DART_CHECK_VALID(builtin_lib); 303 DART_CHECK_VALID(builtin_lib);
304 304
305 result = PrepareScriptForLoading(package_root, builtin_lib); 305 result = PrepareScriptForLoading(package_root, builtin_lib);
306 DART_CHECK_VALID(result); 306 DART_CHECK_VALID(result);
307 307
308 Dart_Handle uri = Dart_NewStringFromUTF8( 308 Dart_Handle uri = Dart_NewStringFromUTF8(
309 reinterpret_cast<const uint8_t*>(script_uri.c_str()), 309 reinterpret_cast<const uint8_t*>(script_uri.c_str()),
310 script_uri.length()); 310 script_uri.length());
311 DART_CHECK_VALID(uri); 311 DART_CHECK_VALID(uri);
312 312
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 if (isolate == nullptr) { 452 if (isolate == nullptr) {
453 return false; 453 return false;
454 } 454 }
455 455
456 Dart_EnterIsolate(isolate); 456 Dart_EnterIsolate(isolate);
457 Dart_Handle result; 457 Dart_Handle result;
458 Dart_EnterScope(); 458 Dart_EnterScope();
459 459
460 // Start the MojoHandleWatcher. 460 // Start the MojoHandleWatcher.
461 Dart_Handle mojo_core_lib = 461 Dart_Handle mojo_core_lib =
462 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); 462 Builtin::GetLibrary(Builtin::kMojoCoreLibrary);
463 DART_CHECK_VALID(mojo_core_lib); 463 DART_CHECK_VALID(mojo_core_lib);
464 Dart_Handle handle_watcher_type = Dart_GetType( 464 Dart_Handle handle_watcher_type = Dart_GetType(
465 mojo_core_lib, 465 mojo_core_lib,
466 Dart_NewStringFromCString("MojoHandleWatcher"), 466 Dart_NewStringFromCString("MojoHandleWatcher"),
467 0, 467 0,
468 nullptr); 468 nullptr);
469 DART_CHECK_VALID(handle_watcher_type); 469 DART_CHECK_VALID(handle_watcher_type);
470 result = Dart_Invoke( 470 result = Dart_Invoke(
471 handle_watcher_type, 471 handle_watcher_type,
472 Dart_NewStringFromCString("_start"), 472 Dart_NewStringFromCString("_start"),
473 0, 473 0,
474 nullptr); 474 nullptr);
475 DART_CHECK_VALID(result); 475 DART_CHECK_VALID(result);
476 476
477 // RunLoop until the handle watcher isolate is spun-up. 477 // RunLoop until the handle watcher isolate is spun-up.
478 result = Dart_RunLoop(); 478 result = Dart_RunLoop();
479 DART_CHECK_VALID(result); 479 DART_CHECK_VALID(result);
480 480
481 // Load the root library into the builtin library so that main can be found. 481 // Load the root library into the builtin library so that main can be found.
482 Dart_Handle builtin_lib = 482 Dart_Handle builtin_lib =
483 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 483 Builtin::GetLibrary(Builtin::kBuiltinLibrary);
484 DART_CHECK_VALID(builtin_lib); 484 DART_CHECK_VALID(builtin_lib);
485 Dart_Handle root_lib = Dart_RootLibrary(); 485 Dart_Handle root_lib = Dart_RootLibrary();
486 DART_CHECK_VALID(root_lib); 486 DART_CHECK_VALID(root_lib);
487 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); 487 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null());
488 DART_CHECK_VALID(result); 488 DART_CHECK_VALID(result);
489 489
490 if (config.compile_all) { 490 if (config.compile_all) {
491 result = Dart_CompileAll(); 491 result = Dart_CompileAll();
492 DART_CHECK_VALID(result); 492 DART_CHECK_VALID(result);
493 } 493 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 initialized_ = false; 563 initialized_ = false;
564 return false; 564 return false;
565 } 565 }
566 566
567 Dart_EnterIsolate(root_isolate_); 567 Dart_EnterIsolate(root_isolate_);
568 Dart_Handle result; 568 Dart_Handle result;
569 Dart_EnterScope(); 569 Dart_EnterScope();
570 570
571 // Start the MojoHandleWatcher. 571 // Start the MojoHandleWatcher.
572 Dart_Handle mojo_core_lib = 572 Dart_Handle mojo_core_lib =
573 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); 573 Builtin::GetLibrary(Builtin::kMojoCoreLibrary);
574 DART_CHECK_VALID(mojo_core_lib); 574 DART_CHECK_VALID(mojo_core_lib);
575 Dart_Handle handle_watcher_type = Dart_GetType( 575 Dart_Handle handle_watcher_type = Dart_GetType(
576 mojo_core_lib, 576 mojo_core_lib,
577 Dart_NewStringFromCString("MojoHandleWatcher"), 577 Dart_NewStringFromCString("MojoHandleWatcher"),
578 0, 578 0,
579 nullptr); 579 nullptr);
580 DART_CHECK_VALID(handle_watcher_type); 580 DART_CHECK_VALID(handle_watcher_type);
581 result = Dart_Invoke( 581 result = Dart_Invoke(
582 handle_watcher_type, 582 handle_watcher_type,
583 Dart_NewStringFromCString("_start"), 583 Dart_NewStringFromCString("_start"),
(...skipping 22 matching lines...) Expand all
606 if (isolate == nullptr) { 606 if (isolate == nullptr) {
607 return false; 607 return false;
608 } 608 }
609 609
610 Dart_EnterIsolate(isolate); 610 Dart_EnterIsolate(isolate);
611 Dart_Handle result; 611 Dart_Handle result;
612 Dart_EnterScope(); 612 Dart_EnterScope();
613 613
614 // Load the root library into the builtin library so that main can be found. 614 // Load the root library into the builtin library so that main can be found.
615 Dart_Handle builtin_lib = 615 Dart_Handle builtin_lib =
616 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 616 Builtin::GetLibrary(Builtin::kBuiltinLibrary);
617 DART_CHECK_VALID(builtin_lib); 617 DART_CHECK_VALID(builtin_lib);
618 Dart_Handle root_lib = Dart_RootLibrary(); 618 Dart_Handle root_lib = Dart_RootLibrary();
619 DART_CHECK_VALID(root_lib); 619 DART_CHECK_VALID(root_lib);
620 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null()); 620 result = Dart_LibraryImportLibrary(builtin_lib, root_lib, Dart_Null());
621 DART_CHECK_VALID(result); 621 DART_CHECK_VALID(result);
622 622
623 if (config.compile_all) { 623 if (config.compile_all) {
624 result = Dart_CompileAll(); 624 result = Dart_CompileAll();
625 DART_CHECK_VALID(result); 625 DART_CHECK_VALID(result);
626 } 626 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 } 666 }
667 667
668 void DartController::Shutdown() { 668 void DartController::Shutdown() {
669 CHECK(root_isolate_ != nullptr); 669 CHECK(root_isolate_ != nullptr);
670 Dart_EnterIsolate(root_isolate_); 670 Dart_EnterIsolate(root_isolate_);
671 Dart_Handle result; 671 Dart_Handle result;
672 Dart_EnterScope(); 672 Dart_EnterScope();
673 673
674 // Stop the MojoHandleWatcher. 674 // Stop the MojoHandleWatcher.
675 Dart_Handle mojo_core_lib = 675 Dart_Handle mojo_core_lib =
676 Builtin::LoadAndCheckLibrary(Builtin::kMojoCoreLibrary); 676 Builtin::GetLibrary(Builtin::kMojoCoreLibrary);
677 DART_CHECK_VALID(mojo_core_lib); 677 DART_CHECK_VALID(mojo_core_lib);
678 Dart_Handle handle_watcher_type = Dart_GetType( 678 Dart_Handle handle_watcher_type = Dart_GetType(
679 mojo_core_lib, 679 mojo_core_lib,
680 Dart_NewStringFromCString("MojoHandleWatcher"), 680 Dart_NewStringFromCString("MojoHandleWatcher"),
681 0, 681 0,
682 nullptr); 682 nullptr);
683 DART_CHECK_VALID(handle_watcher_type); 683 DART_CHECK_VALID(handle_watcher_type);
684 result = Dart_Invoke( 684 result = Dart_Invoke(
685 handle_watcher_type, 685 handle_watcher_type,
686 Dart_NewStringFromCString("_stop"), 686 Dart_NewStringFromCString("_stop"),
687 0, 687 0,
688 nullptr); 688 nullptr);
689 DART_CHECK_VALID(result); 689 DART_CHECK_VALID(result);
690 690
691 result = Dart_RunLoop(); 691 result = Dart_RunLoop();
692 DART_CHECK_VALID(result); 692 DART_CHECK_VALID(result);
693 693
694 Dart_ExitScope(); 694 Dart_ExitScope();
695 Dart_ShutdownIsolate(); 695 Dart_ShutdownIsolate();
696 Dart_Cleanup(); 696 Dart_Cleanup();
697 root_isolate_ = nullptr; 697 root_isolate_ = nullptr;
698 initialized_ = false; 698 initialized_ = false;
699 } 699 }
700 700
701 } // namespace apps 701 } // namespace apps
702 } // namespace mojo 702 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698