Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
Fix eagle js content issue (#2575)
Browse files Browse the repository at this point in the history
  • Loading branch information
YorkShen authored and jianhan-he committed Jun 19, 2019
1 parent c6fa982 commit 497e82e
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
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 {

Expand Down Expand Up @@ -78,9 +80,28 @@ public void send(String instanceId, String url, long nativeCallback) {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down
5 changes: 5 additions & 0 deletions weex_core/Source/core/bridge/eagle_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions weex_core/Source/core/bridge/eagle_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 12 additions & 0 deletions weex_core/Source/core/network/android/default_request_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions weex_core/Source/core/network/http_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions weex_core/Source/core/network/http_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
5 changes: 5 additions & 0 deletions weex_core/Source/core/network/request_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef CORE_NETWORK_REQUEST_HANDLER_H
#define CORE_NETWORK_REQUEST_HANDLER_H
#include <functional>
#include <string>
#include <memory>

namespace weex {
Expand All @@ -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();
};

Expand Down

0 comments on commit 497e82e

Please sign in to comment.