Skip to content

Commit

Permalink
feat(core): dynamic loading support custom protocols (#2827)
Browse files Browse the repository at this point in the history
  • Loading branch information
churchill-zhang authored and zoomchan-cxj committed Feb 6, 2023
1 parent 7153bab commit d238aad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
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

0 comments on commit d238aad

Please sign in to comment.