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/tools/packager/loader.h" | 5 #include "sky/tools/packager/loader.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "sky/tools/packager/logging.h" | 12 #include "sky/tools/packager/logging.h" |
13 #include "sky/tools/packager/scope.h" | 13 #include "sky/tools/packager/scope.h" |
14 #include "sky/tools/packager/switches.h" | 14 #include "sky/tools/packager/switches.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 static const char kSkyInternalsLibraryName[] = "dart:sky.internals"; | |
19 static const char kSkyInternalsURL[] = "package:sky/internals.dart"; | |
20 | |
21 std::string Fetch(const std::string& url) { | 18 std::string Fetch(const std::string& url) { |
22 base::FilePath path(url); | 19 base::FilePath path(url); |
23 std::string source; | 20 std::string source; |
24 CHECK(base::ReadFileToString(path, &source)) << url; | 21 CHECK(base::ReadFileToString(path, &source)) << url; |
25 return source; | 22 return source; |
26 } | 23 } |
27 | 24 |
28 base::FilePath SimplifyPath(const base::FilePath& path) { | 25 base::FilePath SimplifyPath(const base::FilePath& path) { |
29 std::vector<base::FilePath::StringType> components; | 26 std::vector<base::FilePath::StringType> components; |
30 path.GetComponents(&components); | 27 path.GetComponents(&components); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 112 |
116 if (tag == Dart_kImportTag) | 113 if (tag == Dart_kImportTag) |
117 return GetLoader().Import(url); | 114 return GetLoader().Import(url); |
118 | 115 |
119 if (tag == Dart_kSourceTag) | 116 if (tag == Dart_kSourceTag) |
120 return GetLoader().Source(library, url); | 117 return GetLoader().Source(library, url); |
121 | 118 |
122 return Dart_NewApiError("Unknown library tag."); | 119 return Dart_NewApiError("Unknown library tag."); |
123 } | 120 } |
124 | 121 |
125 void LoadSkyInternals() { | |
126 DartApiScope api_scope; | |
127 | |
128 Dart_Handle library_name = StringToDart(kSkyInternalsLibraryName); | |
129 std::string url = GetLoader().CanonicalizePackageURL(kSkyInternalsURL); | |
130 LogIfError(Dart_LoadLibrary(library_name, StringToDart(Fetch(url)), 0, 0)); | |
131 } | |
132 | |
133 void LoadScript(const std::string& url) { | 122 void LoadScript(const std::string& url) { |
134 LogIfError( | 123 LogIfError( |
135 Dart_LoadScript(StringToDart(url), StringToDart(Fetch(url)), 0, 0)); | 124 Dart_LoadScript(StringToDart(url), StringToDart(Fetch(url)), 0, 0)); |
136 } | 125 } |
OLD | NEW |