This is an automated email from the ASF dual-hosted git repository. jianhan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-weex.git
The following commit(s) were added to refs/heads/master by this push: new 497e82e Fix eagle js content issue (#2575) 497e82e is described below commit 497e82e81128571a5d119ae051571fdb28f31304 Author: YorkShen <shenyua...@gmail.com> AuthorDate: Wed Jun 19 11:24:00 2019 +0800 Fix eagle js content issue (#2575) --- .../com/taobao/weex/bridge/RequestHandler.java | 21 +++++++++++++++++ .../jniprebuild/jniheader/RequestHandler_jni.h | 26 ++++++++++++++++++++++ weex_core/Source/core/bridge/eagle_bridge.cpp | 5 +++++ weex_core/Source/core/bridge/eagle_bridge.h | 1 + .../core/bridge/platform/core_side_in_platform.cpp | 1 - .../network/android/default_request_handler.cc | 12 ++++++++++ .../core/network/android/default_request_handler.h | 1 + weex_core/Source/core/network/http_module.cc | 4 ++++ weex_core/Source/core/network/http_module.h | 5 +++-- weex_core/Source/core/network/request_handler.h | 5 +++++ 10 files changed, 78 insertions(+), 3 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/RequestHandler.java b/android/sdk/src/main/java/com/taobao/weex/bridge/RequestHandler.java index 9e4b99a..a3eba20 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/RequestHandler.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/RequestHandler.java @@ -37,7 +37,9 @@ import com.taobao.weex.common.WXResponse; import com.taobao.weex.http.WXHttpUtil; import com.taobao.weex.utils.WXExceptionUtils; +import com.taobao.weex.utils.WXLogUtils; import java.util.HashMap; +import java.util.Locale; public class RequestHandler { @@ -78,9 +80,28 @@ public class RequestHandler { KEY_USER_AGENT, WXHttpUtil.assembleUserAgent( instance.getContext(), WXEnvironment.getConfig())); wxRequest.paramMap.put("isBundleRequest", "true"); + WXLogUtils.i("Eagle", String.format(Locale.ENGLISH, "Weex eagle is going to download script from %s", url)); adapter.sendRequest(wxRequest, new OnHttpListenerInner(instance, nativeCallback, url)); } + @Keep + @CalledByNative + public void getBundleType(String instanceId, String content, long nativeCallback){ + BundType bundleType = WXBridgeManager.getInstance().getBundleType("", content); + String bundleTypeStr = bundleType == null ? "Others" : bundleType.toString(); + WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId); + if ("Others".equalsIgnoreCase(bundleTypeStr) && null != instance){ + WXExceptionUtils.commitCriticalExceptionRT( + instanceId, + WXErrorCode.WX_KEY_EXCEPTION_NO_BUNDLE_TYPE, + "RequestHandler.onSuccess", + "eagle ->" +WXErrorCode.WX_KEY_EXCEPTION_NO_BUNDLE_TYPE.getErrorMsg(), + null + ); + } + nativeInvokeOnSuccess(nativeCallback, content, bundleTypeStr); + } + class OnHttpListenerInner extends WXHttpListener { private long sNativeCallback; diff --git a/weex_core/Source/base/android/jniprebuild/jniheader/RequestHandler_jni.h b/weex_core/Source/base/android/jniprebuild/jniheader/RequestHandler_jni.h index 5934737..e4ffd3c 100644 --- a/weex_core/Source/base/android/jniprebuild/jniheader/RequestHandler_jni.h +++ b/weex_core/Source/base/android/jniprebuild/jniheader/RequestHandler_jni.h @@ -100,6 +100,32 @@ static void Java_RequestHandler_send(JNIEnv* env, jobject obj, jstring } +static intptr_t g_RequestHandler_getBundleType = 0; +static void Java_RequestHandler_getBundleType (JNIEnv* env, jobject obj, + jstring instanceId,jstring content,jlong nativeCallback) { + /* Must call RegisterNativesImpl() */ + //CHECK_CLAZZ(env, obj, + // RequestHandler_clazz(env)); + jmethodID method_id = + base::android::GetMethod( + env, RequestHandler_clazz(env), + base::android::INSTANCE_METHOD, + "getBundleType", + + "(" + "Ljava/lang/String;" + "Ljava/lang/String;" + "J" + ")" + "V", + &g_RequestHandler_getBundleType); + + env->CallVoidMethod(obj, + method_id, instanceId, content, nativeCallback); + base::android::CheckException(env); + +} + // Step 3: RegisterNatives. static const JNINativeMethod kMethodsRequestHandler[] = { diff --git a/weex_core/Source/core/bridge/eagle_bridge.cpp b/weex_core/Source/core/bridge/eagle_bridge.cpp index 3b07c0d..cc2e672 100644 --- a/weex_core/Source/core/bridge/eagle_bridge.cpp +++ b/weex_core/Source/core/bridge/eagle_bridge.cpp @@ -137,6 +137,11 @@ namespace WeexCore { weex::core::network::HttpModule http_module; http_module.Send(instance_id, url, callback); } + + void EagleBridge::WeexCoreHandler::GetBundleType(const char* instance_id, const char* content, std::function<void(const std::string&, const std::string&)> callback) { + weex::core::network::HttpModule http_module; + http_module.GetBundleType(instance_id, content, callback); + } int EagleBridge::WeexCoreHandler::RefreshFinish(const char* page_id, const char* task, const char* callback) { return WeexCore::WeexCoreManager::Instance() diff --git a/weex_core/Source/core/bridge/eagle_bridge.h b/weex_core/Source/core/bridge/eagle_bridge.h index 5ff489e..f7b0478 100644 --- a/weex_core/Source/core/bridge/eagle_bridge.h +++ b/weex_core/Source/core/bridge/eagle_bridge.h @@ -78,6 +78,7 @@ namespace WeexCore { bool ClosePage(const std::string &page_id); void ReportException(const char* page_id, const char* func, const char* exception_string); void Send(const char* instance_id, const char* url, std::function<void(const std::string&, const std::string&)> callback); + void GetBundleType(const char* instance_id, const char* url, std::function<void(const std::string&, const std::string&)> callback); int RefreshFinish(const char* page_id, const char* task, const char* callback); std::unique_ptr<ValueWithType> CallNativeModule (const char* page_id, const char* module, const char* method,const char* arguments, int arguments_length, const char* options, int options_length); void CallNativeComponent (const char* page_id, const char* module, const char* method,const char* arguments, int arguments_length, const char* options, int options_length); diff --git a/weex_core/Source/core/bridge/platform/core_side_in_platform.cpp b/weex_core/Source/core/bridge/platform/core_side_in_platform.cpp index 85c531c..93a8e3f 100644 --- a/weex_core/Source/core/bridge/platform/core_side_in_platform.cpp +++ b/weex_core/Source/core/bridge/platform/core_side_in_platform.cpp @@ -504,7 +504,6 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func, [instanceId = std::string(instanceId), func = std::string(func), opts = std::string(opts), initData = std::string(initData), extendsApi = std::string(extendsApi)](const char *result, const char *bundleType) { - // FIXME Now only support vue, this should be fixed std::string error; auto opts_json = json11::Json::parse(opts, error); std::map<std::string, json11::Json> &opts_map = diff --git a/weex_core/Source/core/network/android/default_request_handler.cc b/weex_core/Source/core/network/android/default_request_handler.cc index be45cc4..ab218bd 100644 --- a/weex_core/Source/core/network/android/default_request_handler.cc +++ b/weex_core/Source/core/network/android/default_request_handler.cc @@ -18,6 +18,7 @@ */ #if OS_ANDROID +#include "base/log_defines.h" #include "core/network/android/default_request_handler.h" #include "android/base/string/scoped_jstring_utf8.h" #include "base/android/jniprebuild/jniheader/RequestHandler_jni.h" @@ -39,6 +40,7 @@ static void InvokeOnSuccess(JNIEnv* env, jobject jcaller, jlong callback, } static void InvokeOnFailed(JNIEnv* env, jobject jcaller, jlong callback) { + LOGE_TAG("Eagle", "Download js file using src failed."); CallbackWrapper* callback_wrapper = reinterpret_cast<CallbackWrapper*>(callback); delete callback_wrapper; @@ -72,6 +74,16 @@ void DefaultRequestHandler::Send(const char* instance_id, const char* url, reinterpret_cast<jlong>(callback_wrapper)); } +void DefaultRequestHandler::GetBundleType(const char *instance_id, const char *content, Callback callback){ + JNIEnv* env = base::android::AttachCurrentThread(); + if (!env) return; + CallbackWrapper* callback_wrapper = new CallbackWrapper(callback); + base::android::ScopedLocalJavaRef<jstring> jni_id(env, env->NewStringUTF(instance_id)); + base::android::ScopedLocalJavaRef<jstring> jni_content(env,env->NewStringUTF(content)); + Java_RequestHandler_getBundleType(env, jni_object(), jni_id.Get(), jni_content.Get(), + reinterpret_cast<jlong>(callback_wrapper)); +} + RequestHandler* RequestHandler::CreateDefaultHandler() { return new DefaultRequestHandler(); } diff --git a/weex_core/Source/core/network/android/default_request_handler.h b/weex_core/Source/core/network/android/default_request_handler.h index cd4eb00..d514fb3 100644 --- a/weex_core/Source/core/network/android/default_request_handler.h +++ b/weex_core/Source/core/network/android/default_request_handler.h @@ -37,6 +37,7 @@ class DefaultRequestHandler : public RequestHandler, ~DefaultRequestHandler() override; void Send(const char* instance_id, const char* url, Callback callback) override; + void GetBundleType(const char *instance_id, const char *content, Callback callback) override; }; class CallbackWrapper { diff --git a/weex_core/Source/core/network/http_module.cc b/weex_core/Source/core/network/http_module.cc index 200952f..2768263 100644 --- a/weex_core/Source/core/network/http_module.cc +++ b/weex_core/Source/core/network/http_module.cc @@ -34,6 +34,10 @@ void HttpModule::Send(const char* instance_id, const char* url, request_handler_->Send(instance_id, url, callback); } +void HttpModule::GetBundleType(const char *instance_id, const char *content, Callback callback){ + request_handler_->GetBundleType(instance_id, content, callback); +} + } // namespace network } // namespace core } // namespace weex diff --git a/weex_core/Source/core/network/http_module.h b/weex_core/Source/core/network/http_module.h index 4c4b579..edb9894 100644 --- a/weex_core/Source/core/network/http_module.h +++ b/weex_core/Source/core/network/http_module.h @@ -28,8 +28,9 @@ namespace network { class HttpModule { public: HttpModule(); - HttpModule(RequestHandler* request_handler); - void Send(const char* instance_id, const char* url, Callback callback); + HttpModule(RequestHandler *request_handler); + void Send(const char *instance_id, const char *url, Callback callback); + void GetBundleType(const char *instance_id, const char *content, Callback callback); private: std::unique_ptr<RequestHandler> request_handler_; diff --git a/weex_core/Source/core/network/request_handler.h b/weex_core/Source/core/network/request_handler.h index 4e68243..ba21e9c 100644 --- a/weex_core/Source/core/network/request_handler.h +++ b/weex_core/Source/core/network/request_handler.h @@ -20,6 +20,7 @@ #ifndef CORE_NETWORK_REQUEST_HANDLER_H #define CORE_NETWORK_REQUEST_HANDLER_H #include <functional> +#include <string> #include <memory> namespace weex { @@ -33,6 +34,10 @@ class RequestHandler { virtual ~RequestHandler() {} virtual void Send(const char* instance_id, const char* url, Callback callback) = 0; + virtual void GetBundleType(const char *instance_id, const char *content, Callback callback){ + std::string result; + callback(result, result); + } static RequestHandler* CreateDefaultHandler(); };