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

Side by Side Diff: sky/engine/core/script/dart_controller.cc

Issue 1131673011: Teach SkyView code path to print hello, world (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: again Created 5 years, 7 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
« no previous file with comments | « sky/engine/core/script/dart_controller.h ('k') | sky/engine/core/script/dom_dart_state.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (!ImportChildLibraries(module, library)) 104 if (!ImportChildLibraries(module, library))
105 return nullptr; 105 return nullptr;
106 106
107 return library; 107 return library;
108 } 108 }
109 109
110 void DartController::DidLoadMainLibrary(KURL url) { 110 void DartController::DidLoadMainLibrary(KURL url) {
111 DCHECK(Dart_CurrentIsolate() == dart_state()->isolate()); 111 DCHECK(Dart_CurrentIsolate() == dart_state()->isolate());
112 DartApiScope dart_api_scope; 112 DartApiScope dart_api_scope;
113 113
114 if (LogIfError(Dart_FinalizeLoading(true)))
115 return;
116
114 Dart_Handle library = Dart_LookupLibrary( 117 Dart_Handle library = Dart_LookupLibrary(
115 StringToDart(dart_state(), url.string())); 118 StringToDart(dart_state(), url.string()));
116 CHECK(!LogIfError(library)); 119 CHECK(!LogIfError(library));
117 DartInvokeAppField(library, ToDart("main"), 0, nullptr); 120 DartInvokeAppField(library, ToDart("main"), 0, nullptr);
118 } 121 }
119 122
120 void DartController::LoadMainLibrary(const KURL& url) { 123 void DartController::LoadMainLibrary(const KURL& url) {
121 DartLoader& loader = dart_state()->loader(); 124 DartLoader& loader = dart_state()->loader();
122 DartDependencyCatcher dependency_catcher(loader); 125 DartDependencyCatcher dependency_catcher(loader);
123 loader.LoadLibrary(url); 126 loader.LoadLibrary(url);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 DartApiScope api_scope; 304 DartApiScope api_scope;
302 LogIfError(Dart_HandleMessage()); 305 LogIfError(Dart_HandleMessage());
303 } 306 }
304 307
305 static void MessageNotifyCallback(Dart_Isolate dest_isolate) { 308 static void MessageNotifyCallback(Dart_Isolate dest_isolate) {
306 DCHECK(Platform::current()); 309 DCHECK(Platform::current());
307 Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE, 310 Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE,
308 base::Bind(&CallHandleMessage, DartState::From(dest_isolate)->GetWeakPtr() )); 311 base::Bind(&CallHandleMessage, DartState::From(dest_isolate)->GetWeakPtr() ));
309 } 312 }
310 313
311 void DartController::CreateIsolateFor(Document* document) { 314 void DartController::CreateIsolateFor(PassOwnPtr<DOMDartState> state,
312 DCHECK(document); 315 const KURL& url) {
313 CHECK(kDartIsolateSnapshotBuffer); 316 CHECK(kDartIsolateSnapshotBuffer);
314 char* error = nullptr; 317 char* error = nullptr;
315 dom_dart_state_ = adoptPtr(new DOMDartState(document)); 318 dom_dart_state_ = state;
316 Dart_Isolate isolate = Dart_CreateIsolate( 319 Dart_Isolate isolate = Dart_CreateIsolate(
317 document->url().string().utf8().data(), "main", kDartIsolateSnapshotBuffer , 320 url.string().utf8().data(), "main", kDartIsolateSnapshotBuffer,
318 static_cast<DartState*>(dom_dart_state_.get()), &error); 321 static_cast<DartState*>(dom_dart_state_.get()), &error);
319 Dart_SetMessageNotifyCallback(MessageNotifyCallback); 322 Dart_SetMessageNotifyCallback(MessageNotifyCallback);
320 CHECK(isolate) << error; 323 CHECK(isolate) << error;
321 dom_dart_state_->set_isolate(isolate); 324 dom_dart_state_->set_isolate(isolate);
322 Dart_SetGcCallbacks(DartGCPrologue, DartGCEpilogue); 325 Dart_SetGcCallbacks(DartGCPrologue, DartGCEpilogue);
323 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler))); 326 CHECK(!LogIfError(Dart_SetLibraryTagHandler(LibraryTagHandler)));
324 327
325 { 328 {
326 DartApiScope apiScope; 329 DartApiScope apiScope;
327 330
328 // Ensure the isolate has a root library. 331 // Ensure the isolate has a root library.
329 Dart_LoadScript(Dart_NewStringFromCString("dart:empty"), 332 Dart_LoadScript(Dart_NewStringFromCString("dart:empty"),
330 Dart_NewStringFromCString(""), 0, 0); 333 Dart_NewStringFromCString(""), 0, 0);
331 334
332 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 335 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
333 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary); 336 Builtin::SetNativeResolver(Builtin::kMojoInternalLibrary);
334 Builtin::SetNativeResolver(Builtin::kIOLibrary); 337 Builtin::SetNativeResolver(Builtin::kIOLibrary);
335 BuiltinNatives::Init(BuiltinNatives::MainIsolate); 338 BuiltinNatives::Init(BuiltinNatives::MainIsolate);
336 339
337 builtin_sky_ = adoptPtr(new BuiltinSky(dart_state())); 340 builtin_sky_ = adoptPtr(new BuiltinSky(dart_state()));
338 dart_state()->class_library().set_provider(builtin_sky_.get()); 341 dart_state()->class_library().set_provider(builtin_sky_.get());
339 builtin_sky_->InstallWindow(dart_state());
340 342
341 document->frame()->loaderClient()->didCreateIsolate(isolate); 343 if (dart_state()->document())
344 builtin_sky_->InstallWindow(dart_state());
342 345
343 EnsureHandleWatcherStarted(); 346 EnsureHandleWatcherStarted();
344 } 347 }
345 Dart_ExitIsolate(); 348 Dart_ExitIsolate();
346 } 349 }
347 350
348 void DartController::ClearForClose() { 351 void DartController::ClearForClose() {
349 // Don't use a DartIsolateScope here since we never exit the isolate. 352 // Don't use a DartIsolateScope here since we never exit the isolate.
350 Dart_EnterIsolate(dom_dart_state_->isolate()); 353 Dart_EnterIsolate(dom_dart_state_->isolate());
351 Dart_ShutdownIsolate(); 354 Dart_ShutdownIsolate();
(...skipping 19 matching lines...) Expand all
371 nullptr, // Isolate interrupt callback. 374 nullptr, // Isolate interrupt callback.
372 UnhandledExceptionCallback, IsolateShutdownCallback, 375 UnhandledExceptionCallback, IsolateShutdownCallback,
373 // File IO callbacks. 376 // File IO callbacks.
374 nullptr, nullptr, nullptr, nullptr, nullptr)); 377 nullptr, nullptr, nullptr, nullptr, nullptr));
375 // Wait for load port- ensures handle watcher and service isolates are 378 // Wait for load port- ensures handle watcher and service isolates are
376 // running. 379 // running.
377 Dart_ServiceWaitForLoadPort(); 380 Dart_ServiceWaitForLoadPort();
378 } 381 }
379 382
380 } // namespace blink 383 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/script/dart_controller.h ('k') | sky/engine/core/script/dom_dart_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698