Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): dynamic loading support custom protocols #2827

Merged
merged 2 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/sdk/src/main/jni/include/loader/adr_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class ADRLoader : public hippy::base::UriLoader {
bool LoadByAsset(const unicode_string_view& file_path,
const std::function<void(u8string)>& cb,
bool is_auto_fill = false);
bool LoadByHttp(const unicode_string_view& uri,
const std::function<void(u8string)>& cb);
bool LoadByJni(const unicode_string_view& uri,
const std::function<void(u8string)>& cb);

std::shared_ptr<JavaRef> bridge_;
AAssetManager* aasset_manager_;
Expand Down
13 changes: 4 additions & 9 deletions android/sdk/src/main/jni/src/loader/adr_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ bool ADRLoader::RequestUntrustedContent(const unicode_string_view& uri,
std::u16string schema_str = schema.utf16_value();
if (schema_str == u"file") {
return LoadByFile(path, cb);
} else if (schema_str == u"http" || schema_str == u"https" ||
schema_str == u"debug") {
return LoadByHttp(uri, cb);
} else if (schema_str == u"asset") {
if (aasset_manager_) {
return LoadByAsset(path, cb, false);
Expand All @@ -75,9 +72,7 @@ bool ADRLoader::RequestUntrustedContent(const unicode_string_view& uri,
cb(u8string());
return false;
} else {
TDF_BASE_DLOG(ERROR) << "schema error, schema = " << schema;
cb(u8string());
return false;
return LoadByJni(uri, cb);
}
}

Expand Down Expand Up @@ -110,7 +105,7 @@ bool ADRLoader::RequestUntrustedContent(const unicode_string_view& uri,
[p = std::move(promise)](u8string bytes) mutable {
p.set_value(std::move(bytes));
});
bool ret = LoadByHttp(uri, cb);
bool ret = LoadByJni(uri, cb);
content = read_file_future.get();
return ret;
} else if (schema_str == u"asset") {
Expand Down Expand Up @@ -162,8 +157,8 @@ bool ADRLoader::LoadByAsset(const unicode_string_view& path,
return true;
}

bool ADRLoader::LoadByHttp(const unicode_string_view& uri,
const std::function<void(u8string)>& cb) {
bool ADRLoader::LoadByJni(const unicode_string_view& uri,
const std::function<void(u8string)>& cb) {
std::shared_ptr<JNIEnvironment> instance = JNIEnvironment::GetInstance();
JNIEnv* j_env = instance->AttachCurrentThread();

Expand Down