Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "mojo/common/data_pipe_drainer.h" | 10 #include "mojo/common/data_pipe_drainer.h" |
| 11 #include "sky/engine/core/script/dart_dependency_catcher.h" | 11 #include "sky/engine/core/script/dart_dependency_catcher.h" |
| 12 #include "sky/engine/core/script/dom_dart_state.h" | 12 #include "sky/engine/core/script/dom_dart_state.h" |
| 13 #include "sky/engine/platform/fetcher/MojoFetcher.h" | 13 #include "sky/engine/platform/fetcher/MojoFetcher.h" |
| 14 #include "sky/engine/platform/weborigin/KURL.h" | 14 #include "sky/engine/platform/weborigin/KURL.h" |
| 15 #include "sky/engine/tonic/dart_api_scope.h" | 15 #include "sky/engine/tonic/dart_api_scope.h" |
| 16 #include "sky/engine/tonic/dart_converter.h" | 16 #include "sky/engine/tonic/dart_converter.h" |
| 17 #include "sky/engine/tonic/dart_error.h" | 17 #include "sky/engine/tonic/dart_error.h" |
| 18 #include "sky/engine/tonic/dart_isolate_scope.h" | 18 #include "sky/engine/tonic/dart_isolate_scope.h" |
| 19 #include "sky/engine/wtf/MainThread.h" | 19 #include "sky/engine/wtf/MainThread.h" |
| 20 | 20 |
| 21 using mojo::common::DataPipeDrainer; | 21 using mojo::common::DataPipeDrainer; |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 Dart_Handle CanonicalizeURL(DartState* state, | 26 Dart_Handle CanonicalizeURL(DartState* state, |
| 27 Dart_Handle library, | 27 Dart_Handle library, |
| 28 Dart_Handle url) { | 28 Dart_Handle url) { |
| 29 String string = StringFromDart(url); | 29 String string = StringFromDart(url); |
| 30 | |
| 30 if (string.startsWith("dart:") || string.startsWith("mojo:")) | 31 if (string.startsWith("dart:") || string.startsWith("mojo:")) |
| 31 return url; | 32 return url; |
| 32 // TODO(dart): Figure out how 'package:' should work in sky. | 33 // TODO(dart): Figure out how 'package:' should work in sky. |
| 33 if (string.startsWith("package:")) { | 34 if (string.startsWith("package:")) { |
| 34 string.replace("package:", "/packages/"); | 35 KURL baseUri = DOMDartState::Current()->document()->baseURI(); |
| 36 bool is_packaged_app = baseUri.string().startsWith("file://"); | |
|
eseidel
2015/04/14 17:06:31
Why aren't packaged apps just served over http loc
| |
| 37 | |
| 38 if (is_packaged_app) { | |
| 39 // In packaged apps, |package:<foo>| is specified relative to the base URL | |
| 40 // of the application. | |
| 41 string.replace("package:", ""); | |
| 42 string = KURL(baseUri, string).string(); | |
| 43 } else { | |
| 44 string.replace("package:", "/packages/"); | |
| 45 } | |
| 35 } | 46 } |
| 47 | |
| 36 String library_url_string = StringFromDart(Dart_LibraryUrl(library)); | 48 String library_url_string = StringFromDart(Dart_LibraryUrl(library)); |
| 37 KURL library_url = KURL(ParsedURLString, library_url_string); | 49 KURL library_url = KURL(ParsedURLString, library_url_string); |
| 38 KURL resolved_url = KURL(library_url, string); | 50 KURL resolved_url = KURL(library_url, string); |
| 39 return StringToDart(state, resolved_url.string()); | 51 return StringToDart(state, resolved_url.string()); |
| 40 } | 52 } |
| 41 | 53 |
| 42 } // namespace | 54 } // namespace |
| 43 | 55 |
| 44 // A DartLoader::Job represents a network load. It fetches data from the network | 56 // A DartLoader::Job represents a network load. It fetches data from the network |
| 45 // and buffers the data in Vector. To cancel the job, delete this object. | 57 // and buffers the data in Vector. To cancel the job, delete this object. |
| 46 class DartLoader::Job : public DartDependency, | 58 class DartLoader::Job : public DartDependency, |
| 47 public MojoFetcher::Client, | 59 public MojoFetcher::Client, |
| 48 public DataPipeDrainer::Client { | 60 public DataPipeDrainer::Client { |
| 49 public: | 61 public: |
| 50 Job(DartLoader* loader, const KURL& url) | 62 Job(DartLoader* loader, const KURL& url) |
| 51 : loader_(loader), url_(url), fetcher_(this, url) {} | 63 : loader_(loader), url_(url), fetcher_(this, url) {} |
| 52 | 64 |
| 53 const KURL& url() const { return url_; } | 65 const KURL& url() const { return url_; } |
| 54 | 66 |
| 55 protected: | 67 protected: |
| 56 DartLoader* loader_; | 68 DartLoader* loader_; |
| 57 // TODO(abarth): Should we be using SharedBuffer to buffer the data? | 69 // TODO(abarth): Should we be using SharedBuffer to buffer the data? |
| 58 Vector<uint8_t> buffer_; | 70 Vector<uint8_t> buffer_; |
| 59 | 71 |
| 60 private: | 72 private: |
| 61 // MojoFetcher::Client | 73 // MojoFetcher::Client |
| 62 void OnReceivedResponse(mojo::URLResponsePtr response) override { | 74 void OnReceivedResponse(mojo::URLResponsePtr response) override { |
| 63 if (response->status_code != 200) { | 75 bool failed_load = response->status_code != 200; |
| 76 | |
| 77 // TODO(blundell): Why are successful loads of file:// URLs returning a | |
| 78 // status code of 0? | |
| 79 if (response->status_code == 0) { | |
|
eseidel
2015/04/14 17:06:31
Here again, instead of teaching Sky to understand
| |
| 80 failed_load = response->error != NULL; | |
| 81 } | |
| 82 if (failed_load) { | |
| 64 loader_->DidFailJob(this); | 83 loader_->DidFailJob(this); |
| 65 return; | 84 return; |
| 66 } | 85 } |
| 67 drainer_ = adoptPtr(new DataPipeDrainer(this, response->body.Pass())); | 86 drainer_ = adoptPtr(new DataPipeDrainer(this, response->body.Pass())); |
| 68 } | 87 } |
| 69 | 88 |
| 70 // DataPipeDrainer::Client | 89 // DataPipeDrainer::Client |
| 71 void OnDataAvailable(const void* data, size_t num_bytes) override { | 90 void OnDataAvailable(const void* data, size_t num_bytes) override { |
| 72 buffer_.append(static_cast<const uint8_t*>(data), num_bytes); | 91 buffer_.append(static_cast<const uint8_t*>(data), num_bytes); |
| 73 } | 92 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 312 |
| 294 WatcherSignaler watcher_signaler(*this, job); | 313 WatcherSignaler watcher_signaler(*this, job); |
| 295 | 314 |
| 296 LOG(ERROR) << "Library Load failed: " << job->url().string().utf8().data(); | 315 LOG(ERROR) << "Library Load failed: " << job->url().string().utf8().data(); |
| 297 // TODO(eseidel): Call Dart_LibraryHandleError in the SourceJob case? | 316 // TODO(eseidel): Call Dart_LibraryHandleError in the SourceJob case? |
| 298 | 317 |
| 299 jobs_.remove(job); | 318 jobs_.remove(job); |
| 300 } | 319 } |
| 301 | 320 |
| 302 } // namespace blink | 321 } // namespace blink |
| OLD | NEW |