Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
file_loader.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef LIB_TONIC_FILE_LOADER_FILE_LOADER_H_
6#define LIB_TONIC_FILE_LOADER_FILE_LOADER_H_
7
8#include <memory>
9#include <set>
10#include <string>
11#include <vector>
12
13#include "third_party/dart/runtime/include/dart_api.h"
14#include "tonic/common/macros.h"
16
17namespace tonic {
18
20 public:
21 explicit FileLoader(int dirfd = -1);
23
24 bool LoadPackagesMap(const std::string& packages);
25
26 // The path to the `.packages` file the packages map was loaded from.
27 const std::string& packages() const { return packages_; }
28
30 Dart_Handle library,
31 Dart_Handle url);
32
37
38 Dart_Handle FetchBytes(const std::string& url,
39 uint8_t*& buffer,
40 intptr_t& buffer_size);
41
42 static const char kFileURLPrefix[];
43 static const size_t kFileURLPrefixLength;
44 static const std::string kPathSeparator;
45
46 private:
47 static std::string SanitizeURIEscapedCharacters(const std::string& str);
48 static std::string SanitizePath(const std::string& path);
49
50 std::string GetFilePathForURL(std::string url);
51 std::string GetFilePathForPackageURL(std::string url);
52 std::string GetFilePathForFileURL(std::string url);
53
54 std::string GetFileURLForPath(const std::string& path);
55
56 bool ReadFileToString(const std::string& path, std::string* result);
57 std::pair<uint8_t*, intptr_t> ReadFileToBytes(const std::string& path);
58
59 int dirfd_;
60 std::string packages_;
61 std::unique_ptr<PackagesMap> packages_map_;
62 std::vector<uint8_t*> kernel_buffers_;
63
65};
66
67} // namespace tonic
68
69#endif // LIB_TONIC_FILE_LOADER_FILE_LOADER_H_
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
const std::string & packages() const
Definition file_loader.h:27
Dart_Handle Import(Dart_Handle url)
void SetPackagesUrl(Dart_Handle url)
static const char kFileURLPrefix[]
Definition file_loader.h:42
bool LoadPackagesMap(const std::string &packages)
Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
static const size_t kFileURLPrefixLength
Definition file_loader.h:43
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
Definition file_loader.h:44
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
Dart_LibraryTag
Definition dart_api.h:3339
static const uint8_t buffer[]
GAsyncResult * result
#define TONIC_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:19