21constexpr char kDartScheme[] =
"dart:";
23constexpr char kFileScheme[] =
"file:";
24constexpr size_t kFileSchemeLength =
sizeof(kFileScheme) - 1;
26constexpr char kPackageScheme[] =
"package:";
27constexpr size_t kPackageSchemeLength =
sizeof(kPackageScheme) - 1;
30std::string ExtractSchemePrefix(std::string url) {
31 if (url.find(kPackageScheme) == 0u)
32 return kPackageScheme;
33 if (url.find(kFileScheme) == 0u)
39std::string ExtractPath(std::string url) {
40 if (url.find(kPackageScheme) == 0u)
41 return url.substr(kPackageSchemeLength);
42 if (url.find(kFileScheme) == 0u)
43 return url.substr(kFileSchemeLength);
52 for (
auto kernel_buffer : kernel_buffers_)
59std::string FileLoader::SanitizeURIEscapedCharacters(
const std::string& str) {
61 result.reserve(str.size());
62 for (std::string::size_type
i = 0;
i < str.size(); ++
i) {
64 if (
i > str.size() - 3 || !isxdigit(str[
i + 1]) || !isxdigit(str[
i + 2]))
66 const std::string hex = str.substr(
i + 1, 2);
67 const unsigned char c = strtoul(hex.c_str(),
nullptr, 16);
81 std::string packages_source;
82 if (!ReadFileToString(packages_, &packages_source)) {
83 tonic::Log(
"error: Unable to load .packages file '%s'.", packages_.c_str());
88 if (!packages_map_->Parse(packages_source, &
error)) {
89 tonic::Log(
"error: Unable to parse .packages file '%s'. %s",
90 packages_.c_str(),
error.c_str());
96std::string FileLoader::GetFilePathForPackageURL(std::string url) {
100 url = url.substr(kPackageSchemeLength);
103 if (slash == std::string::npos)
104 return std::string();
105 std::string
package = url.substr(0, slash);
106 std::string library_path = url.substr(slash + 1);
107 std::string package_path = packages_map_->Resolve(package);
108 if (package_path.empty())
109 return std::string();
135 if (
string.
find(kDartScheme) == 0u)
137 if (
string.
find(kPackageScheme) == 0u)
140 if (
string.
find(kFileScheme) == 0u) {
145 std::string
prefix = ExtractSchemePrefix(library_url);
146 std::string base_path = ExtractPath(library_url);
147 std::string simplified_path =
153std::string FileLoader::GetFilePathForURL(std::string url) {
154 if (url.find(kPackageScheme) == 0u)
155 return GetFilePathForPackageURL(std::move(url));
156 if (url.find(kFileScheme) == 0u)
157 return GetFilePathForFileURL(std::move(url));
169 std::string error_message =
"error: Unable to read '" + url +
"'.";
175 if (
result.first ==
nullptr) {
176 std::string error_message =
177 "error: Unable to read '" + absolute_path +
"'.";
188 uint8_t*
buffer =
nullptr;
195 kernel_buffers_.push_back(
buffer);
207 uint8_t*
buffer =
nullptr;
230std::string FileLoader::GetFilePathForFileURL(std::string url) {
235std::string FileLoader::GetFileURLForPath(
const std::string&
path) {
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
int find(T *array, int N, T item)
const std::string & packages() const
Dart_Handle Import(Dart_Handle url)
void SetPackagesUrl(Dart_Handle url)
static const char kFileURLPrefix[]
bool LoadPackagesMap(const std::string &packages)
Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
static const size_t kFileURLPrefixLength
Dart_Handle CanonicalizeURL(Dart_Handle library, Dart_Handle url)
Dart_Handle Kernel(Dart_Handle url)
Dart_Handle FetchBytes(const std::string &url, uint8_t *&buffer, intptr_t &buffer_size)
static const std::string kPathSeparator
DART_EXPORT Dart_FinalizableHandle Dart_NewFinalizableHandle(Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, void *data, intptr_t length)
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_Handle Dart_True(void)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_LoadLibraryFromKernel(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
DART_EXPORT Dart_Handle Dart_NewApiError(const char *error)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT bool Dart_IsString(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception)
DART_EXPORT bool Dart_IsLibrary(Dart_Handle object)
const uint8_t uint32_t uint32_t GError ** error
static void MallocFinalizer(void *isolate_callback_data, void *peer)
std::string AbsolutePath(const std::string &path)
std::string GetAbsoluteFilePath(const std::string &path)
std::string GetDirectoryName(const std::string &path)
std::string SimplifyPath(std::string path)
std::pair< uint8_t *, intptr_t > ReadFileToBytes(const std::string &path)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Dart_Handle StdStringToDart(const std::string &val)
void Log(const char *format,...)
std::string StdStringFromDart(Dart_Handle handle)