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

[Android] Pass bundleType to eagle #2412

Merged
merged 2 commits into from
May 8, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@
*/
package com.taobao.weex.bridge;

import static com.taobao.weex.http.WXHttpUtil.KEY_USER_AGENT;

import android.net.Uri;
import android.support.annotation.Keep;
import android.text.TextUtils;

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXHttpListener;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.adapter.URIAdapter;
import com.taobao.weex.base.CalledByNative;
import com.taobao.weex.bridge.WXBridgeManager.BundType;
import com.taobao.weex.common.WXRequest;
import com.taobao.weex.common.WXResponse;
import com.taobao.weex.http.WXHttpUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.taobao.weex.http.WXHttpUtil.KEY_USER_AGENT;

public class RequestHandler {

native void nativeInvokeOnSuccess(long callback, String result);
@Keep
native void nativeInvokeOnSuccess(long callback, String script, String bundleType);
native void nativeInvokeOnFailed(long callback);

@CalledByNative
Expand Down Expand Up @@ -90,7 +89,9 @@ class OnHttpListenerInner extends WXHttpListener {
@Override
public void onSuccess(WXResponse response) {
String script = new String(response.originalData);
nativeInvokeOnSuccess(sNativeCallback, script);
BundType bundleType = WXBridgeManager.getInstance().getBundleType("", script);
String bundleTypeStr = bundleType == null ? "Others" : bundleType.toString();
nativeInvokeOnSuccess(sNativeCallback, script, bundleTypeStr);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jclass g_RequestHandler_clazz = NULL;

static void InvokeOnSuccess(JNIEnv* env, jobject jcaller,
jlong callback,
jstring result);
jstring script,
jstring bundleType);

static void InvokeOnFailed(JNIEnv* env, jobject jcaller,
jlong callback);
Expand Down Expand Up @@ -109,6 +110,7 @@ static const JNINativeMethod kMethodsRequestHandler[] = {
"("
"J"
"Ljava/lang/String;"
"Ljava/lang/String;"
")"
"V", reinterpret_cast<void*>(InvokeOnSuccess) },
{ "nativeInvokeOnFailed",
Expand Down
2 changes: 1 addition & 1 deletion weex_core/Source/core/bridge/eagle_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace WeexCore {
WeexCore::WeexCoreManager::Instance()->getPlatformBridge()->platform_side()->ReportException(page_id, func, exception_string);
}

void EagleBridge::WeexCoreHandler::Send(const char* instance_id, const char* url, std::function<void(const std::string&)> callback) {
void EagleBridge::WeexCoreHandler::Send(const char* instance_id, const char* url, std::function<void(const std::string&, const std::string&)> callback) {
weex::core::network::HttpModule http_module;
http_module.Send(instance_id, url, callback);
}
Expand Down
6 changes: 3 additions & 3 deletions weex_core/Source/core/bridge/eagle_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace WeexCore {
bool CreateFinish(const std::string &page_id);
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&)> callback);
void Send(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 Expand Up @@ -115,9 +115,9 @@ namespace WeexCore {
class DataRenderHandler {
public:
virtual int DestroyInstance(const char *instanceId);
virtual void CreatePage(const std::string &input, const std::string &page_id, const std::string &options, const std::string &init_data, std::function<void(const char*)> exec_js) {}
virtual void CreatePage(const std::string &input, const std::string &page_id, const std::string &options, const std::string &init_data, std::function<void(const char*, const char*)> exec_js) {}

virtual void CreatePage(const char *contents, size_t length, const std::string& page_id, const std::string& options, const std::string& env, const std::string& init_data, std::function<void(const char*)> exec_js) {}
virtual void CreatePage(const char *contents, size_t length, const std::string& page_id, const std::string& options, const std::string& env, const std::string& init_data, std::function<void(const char*,const char*)> exec_js) {}
virtual bool RefreshPage(const std::string &page_id, const std::string &init_data) {return false;}
virtual void UpdateComponentData(const std::string& page_id, const char* cid, const std::string& json_data) {}
virtual void FireEvent(const std::string &page_id, const std::string &ref, const std::string &event,const std::string &args,const std::string &dom_changes) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,17 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func,
const char *render_strategy) {
// First check about DATA_RENDER mode
if (render_strategy != nullptr) {
std::function<void(const char *)> exec_js =
std::function<void(const char *, const char *)> exec_js =
[instanceId = std::string(instanceId), func = std::string(func),
opts = std::string(opts), initData = std::string(initData),
extendsApi = std::string(extendsApi)](const char *result) {
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 =
const_cast<std::map<std::string, json11::Json> &>(
opts_json.object_items());
opts_map["bundleType"] = "Vue";
opts_map["bundleType"] = bundleType;
std::vector<INIT_FRAMEWORK_PARAMS*> params;
WeexCoreManager::Instance()
->script_bridge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
using namespace weex::core::network;

static void InvokeOnSuccess(JNIEnv* env, jobject jcaller, jlong callback,
jstring result) {
jstring script,
jstring bundleType) {
CallbackWrapper* callback_wrapper =
reinterpret_cast<CallbackWrapper*>(callback);
WeexCore::ScopedJStringUTF8 jni_result(env, result);
callback_wrapper->Invoke(jni_result.getChars() ? jni_result.getChars() : "");
WeexCore::ScopedJStringUTF8 jni_result(env, script);
WeexCore::ScopedJStringUTF8 bundleTypeStr(env, bundleType);
callback_wrapper->Invoke(
jni_result.getChars() ? jni_result.getChars() : "",
bundleTypeStr.getChars());
delete callback_wrapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CallbackWrapper {
public:
CallbackWrapper(Callback callback) : callback_(callback) {}
~CallbackWrapper() {}
void Invoke(const std::string& result) { callback_(result); }
void Invoke(const std::string& result, const std::string& bundleType) { callback_(result, bundleType); }

private:
Callback callback_;
Expand Down
2 changes: 1 addition & 1 deletion weex_core/Source/core/network/request_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace weex {
namespace core {
namespace network {
typedef std::function<void(const std::string&)> Callback;
typedef std::function<void(const std::string&, const std::string&)> Callback;

class RequestHandler {
public:
Expand Down