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

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

Issue 919883002: Allow sky apps to be consumers of mojo services (Closed) Base URL: https://github.com/eseidel/skydart.git@master
Patch Set: cr comments Created 5 years, 10 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_loader.h ('k') | sky/examples/dart.sky » ('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_loader.h" 6 #include "sky/engine/core/script/dart_loader.h"
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "mojo/common/data_pipe_drainer.h" 9 #include "mojo/common/data_pipe_drainer.h"
10 #include "sky/engine/core/script/dart_dependency_catcher.h" 10 #include "sky/engine/core/script/dart_dependency_catcher.h"
11 #include "sky/engine/core/script/dom_dart_state.h"
11 #include "sky/engine/platform/fetcher/MojoFetcher.h" 12 #include "sky/engine/platform/fetcher/MojoFetcher.h"
12 #include "sky/engine/platform/weborigin/KURL.h" 13 #include "sky/engine/platform/weborigin/KURL.h"
13 #include "sky/engine/tonic/dart_api_scope.h" 14 #include "sky/engine/tonic/dart_api_scope.h"
14 #include "sky/engine/tonic/dart_converter.h" 15 #include "sky/engine/tonic/dart_converter.h"
15 #include "sky/engine/tonic/dart_error.h" 16 #include "sky/engine/tonic/dart_error.h"
16 #include "sky/engine/tonic/dart_isolate_scope.h" 17 #include "sky/engine/tonic/dart_isolate_scope.h"
18 #include "sky/engine/wtf/MainThread.h"
17 19
18 using mojo::common::DataPipeDrainer; 20 using mojo::common::DataPipeDrainer;
19 21
20 namespace blink { 22 namespace blink {
21 namespace { 23 namespace {
22 24
23 Dart_Handle CanonicalizeURL(DartState* state, 25 Dart_Handle CanonicalizeURL(DartState* state,
24 Dart_Handle library, 26 Dart_Handle library,
25 Dart_Handle url) { 27 Dart_Handle url) {
26 String string = StringFromDart(url); 28 String string = StringFromDart(url);
27 if (string.startsWith("dart:")) 29 if (string.startsWith("dart:"))
28 return url; 30 return url;
31 // TODO(dart): Figure out how 'package:' should work in sky.
32 if (string.startsWith("package:")) {
33 string.replace("package:", "/gen/");
34 }
29 String library_url_string = StringFromDart(Dart_LibraryUrl(library)); 35 String library_url_string = StringFromDart(Dart_LibraryUrl(library));
30 KURL library_url = KURL(ParsedURLString, library_url_string); 36 KURL library_url = KURL(ParsedURLString, library_url_string);
31 KURL resolved_url = KURL(library_url, string); 37 KURL resolved_url = KURL(library_url, string);
32 return StringToDart(state, resolved_url.string()); 38 return StringToDart(state, resolved_url.string());
33 } 39 }
34 40
35 } // namespace 41 } // namespace
36 42
37 // A DartLoader::Job represents a network load. It fetches data from the network 43 // A DartLoader::Job represents a network load. It fetches data from the network
38 // and buffers the data in Vector. To cancel the job, delete this object. 44 // and buffers the data in Vector. To cancel the job, delete this object.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 180
175 DartLoader::~DartLoader() { 181 DartLoader::~DartLoader() {
176 } 182 }
177 183
178 Dart_Handle DartLoader::HandleLibraryTag(Dart_LibraryTag tag, 184 Dart_Handle DartLoader::HandleLibraryTag(Dart_LibraryTag tag,
179 Dart_Handle library, 185 Dart_Handle library,
180 Dart_Handle url) { 186 Dart_Handle url) {
181 DCHECK(Dart_IsLibrary(library)); 187 DCHECK(Dart_IsLibrary(library));
182 DCHECK(Dart_IsString(url)); 188 DCHECK(Dart_IsString(url));
183 if (tag == Dart_kCanonicalizeUrl) 189 if (tag == Dart_kCanonicalizeUrl)
184 return CanonicalizeURL(dart_state_.get(), library, url); 190 return CanonicalizeURL(DartState::Current(), library, url);
185 if (tag == Dart_kImportTag) 191 if (tag == Dart_kImportTag) {
186 return Import(library, url); 192 CHECK(WTF::isMainThread());
187 if (tag == Dart_kSourceTag) 193 return DOMDartState::Current()->loader().Import(library, url);
188 return Source(library, url); 194 }
195 if (tag == Dart_kSourceTag) {
196 CHECK(WTF::isMainThread());
197 return DOMDartState::Current()->loader().Source(library, url);
198 }
189 DCHECK(false); 199 DCHECK(false);
190 return Dart_NewApiError("Unknown library tag."); 200 return Dart_NewApiError("Unknown library tag.");
191 } 201 }
192 202
193 void DartLoader::WaitForDependencies( 203 void DartLoader::WaitForDependencies(
194 const HashSet<DartDependency*>& dependencies, 204 const HashSet<DartDependency*>& dependencies,
195 const base::Closure& callback) { 205 const base::Closure& callback) {
196 dependency_watchers_.add( 206 dependency_watchers_.add(
197 adoptPtr(new DependencyWatcher(dependencies, callback))); 207 adoptPtr(new DependencyWatcher(dependencies, callback)));
198 } 208 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 256
247 LogIfError(Dart_LoadSource( 257 LogIfError(Dart_LoadSource(
248 Dart_HandleFromPersistent(job->library()), 258 Dart_HandleFromPersistent(job->library()),
249 StringToDart(dart_state_.get(), job->url().string()), 259 StringToDart(dart_state_.get(), job->url().string()),
250 Dart_NewStringFromUTF8(buffer.data(), buffer.size()), 0, 0)); 260 Dart_NewStringFromUTF8(buffer.data(), buffer.size()), 0, 0));
251 261
252 jobs_.remove(job); 262 jobs_.remove(job);
253 } 263 }
254 264
255 } // namespace blink 265 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/script/dart_loader.h ('k') | sky/examples/dart.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698