MCPcopy Create free account
hub / github.com/PenguLoader/PenguLoader / AssetsResourceHandler

Class AssetsResourceHandler

core/src/browser/assets.cc:77–387  ·  view source on GitHub ↗

Custom resource handler for local assets.

Source from the content-addressed store, hash-verified

75
76// Custom resource handler for local assets.
77class AssetsResourceHandler : public CefRefCount<cef_resource_handler_t>
78{
79public:
80 AssetsResourceHandler()
81 : CefRefCount(this)
82 , stream_(nullptr)
83 , offset_(0)
84 , length_(0)
85 , no_cache_(false)
86 {
87 cef_bind_method(AssetsResourceHandler, open);
88 cef_bind_method(AssetsResourceHandler, get_response_headers);
89 cef_bind_method(AssetsResourceHandler, skip);
90 cef_bind_method(AssetsResourceHandler, read);
91 }
92
93 ~AssetsResourceHandler()
94 {
95 if (stream_ != nullptr)
96 stream_->base.release(&stream_->base);
97 }
98
99private:
100 cef_stream_reader_t *stream_;
101 int64 offset_;
102 int64 length_;
103 std::string range_header_;
104 std::u16string mime_;
105 bool no_cache_;
106
107 int _open(cef_request_t* request, int* handle_request, cef_callback_t* callback)
108 {
109 size_t pos;
110 bool js_mime = false;
111
112 CefScopedStr url = request->get_url(request);
113 std::u16string path, query_part;
114 path.assign((char16_t *)url.str + 15, url.length - 15); // skip 'https://plugins'
115
116 // Check query part.
117 if ((pos = path.rfind('?')) != std::u16string::npos)
118 {
119 // Extract it.
120 query_part = path.substr(pos + 1);
121 // Remove it from path.
122 path = path.substr(0, pos);
123 }
124
125 // Decode URI.
126 decode_uri(path);
127
128 // Get final path.
129 path = config::plugins_dir().u16string().append(path);
130
131 // Trailing slash.
132 if (path[path.length() - 1] == '/' || path[path.length() - 1] == '\\')
133 {
134 js_mime = true;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected