Repository: incubator-weex Updated Branches: refs/heads/master 78e1000fc -> 19a242971
* [core] mv ipc to android dir Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/19a24297 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/19a24297 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/19a24297 Branch: refs/heads/master Commit: 19a242971cac8ec22e14452e149bc44d23e58b3f Parents: 78e1000 Author: zhongcang <[email protected]> Authored: Fri Jun 1 14:15:18 2018 +0800 Committer: YorkShen <[email protected]> Committed: Mon Jun 4 16:10:31 2018 +0800 ---------------------------------------------------------------------- weex_core/Source/CMakeLists.txt | 6 +- .../android/jsengine/api/WeexJSCoreApi.cpp | 239 +++++++++++++++ .../Source/android/jsengine/api/WeexJSCoreApi.h | 86 ++++++ .../jsengine/multiprocess/ExtendJSApi.cpp | 2 +- .../android/jsengine/multiprocess/WeexProxy.cpp | 3 +- weex_core/Source/core/api/WeexJSCoreApi.cpp | 303 ------------------- weex_core/Source/core/api/WeexJSCoreApi.h | 86 ------ weex_core/Source/core/bridge/bridge.h | 2 +- weex_core/Source/core/bridge/js_bridge.cpp | 201 ++++++++++++ weex_core/Source/core/bridge/js_bridge.h | 82 +++++ .../Source/core/manager/weex_core_manager.cpp | 11 +- .../Source/core/manager/weex_core_manager.h | 13 +- 12 files changed, 638 insertions(+), 396 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/weex_core/Source/CMakeLists.txt b/weex_core/Source/CMakeLists.txt index 4ae9e10..ce49a55 100644 --- a/weex_core/Source/CMakeLists.txt +++ b/weex_core/Source/CMakeLists.txt @@ -15,7 +15,6 @@ add_definitions(-DJSAPI_LOG=0) add_definitions(-DDOM_PARSER_LOG=0) set(COMMON_SRCS - ./core/api/WeexJSCoreApi.cpp ./core/render/manager/render_manager.cpp ./core/render/page/render_page.cpp @@ -41,7 +40,9 @@ set(COMMON_SRCS ./core/config/core_environment.cpp ./core/moniter/render_performance.cpp - ./core/manager/weex_core_manager.cpp ) + ./core/manager/weex_core_manager.cpp + ./core/bridge/js_bridge.cpp + ) SET(FINAL_ADD_LIBRARY ${COMMON_SRCS} @@ -79,6 +80,7 @@ if (ANDROID) ./core/parser/dom_wson.cpp + ./android/jsengine/api/WeexJSCoreApi.cpp ) http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/android/jsengine/api/WeexJSCoreApi.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/jsengine/api/WeexJSCoreApi.cpp b/weex_core/Source/android/jsengine/api/WeexJSCoreApi.cpp new file mode 100644 index 0000000..6573050 --- /dev/null +++ b/weex_core/Source/android/jsengine/api/WeexJSCoreApi.cpp @@ -0,0 +1,239 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// +// Created by Darin on 13/02/2018. +// + +#include "WeexJSCoreApi.h" +#include <android/bridge/impl/bridge_impl_android.h> +#include <android/jsengine/multiprocess/ExtendJSApi.h> +#include <android/base/string/string_utils.h> +#include <wson/wson_parser.h> +#include <core/manager/weex_core_manager.h> + +using namespace WeexCore; + +extern WeexCore::FunType gCanvasFunc; +extern WeexCore::FunTypeT3d t3dFunc; + +void _setJSVersion(const char *jsVersion) { + LOGA("init JSFrm version %s", jsVersion); + WeexCoreManager::getInstance()->getJSBridge()->onSetJSVersion(jsVersion); +} + +void _reportException(const char *pageId, const char *func, const char *exception_string) { + WeexCoreManager::getInstance()->getJSBridge()->onReportException( + pageId, + func, + exception_string + ); +} + +void _callNative(const char *pageId, const char *task, const char *callback) { + WeexCoreManager::getInstance()->getJSBridge()->onCallNative( + pageId, + task, + callback + ); + + +}; + +std::unique_ptr<IPCResult> +_callNativeModule(const char *pageId, const char *module, const char *method, + const char *arguments, int argumentsLength, const char *options, int optionsLength) { + std::unique_ptr<IPCResult> ret = createInt32Result(-1); + if (pageId != nullptr && module != nullptr && method != nullptr) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] handleCallNativeModule >>>> pageId: %s, module: %s, method: %s, arg: %s, opt: %s", + pageId, module, method, argString, optString); +#endif + + // add for android support + jobject result; + result = static_cast<jobject>( + WeexCoreManager::getInstance()->getJSBridge()->onCallNativeModule( + pageId, module, method, arguments, + argumentsLength, options, + optionsLength) + ); + + if (result == nullptr) { + return ret; + } + + JNIEnv *env = getJNIEnv(); + jfieldID jTypeId = env->GetFieldID(jWXJSObject, "type", "I"); + jint jTypeInt = env->GetIntField(result, jTypeId); + jfieldID jDataId = env->GetFieldID(jWXJSObject, "data", "Ljava/lang/Object;"); + jobject jDataObj = env->GetObjectField(result, jDataId); + if (jTypeInt == 1) { + if (jDoubleValueMethodId == NULL) { + jclass jDoubleClazz = env->FindClass("java/lang/Double"); + jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue", "()D"); + env->DeleteLocalRef(jDoubleClazz); + } + jdouble jDoubleObj = env->CallDoubleMethod(jDataObj, jDoubleValueMethodId); + ret = std::move(createDoubleResult(jDoubleObj)); + + } else if (jTypeInt == 2) { + jstring jDataStr = (jstring) jDataObj; + ret = std::move(createStringResult(env, jDataStr)); + } else if (jTypeInt == 3) { + jstring jDataStr = (jstring) jDataObj; + ret = std::move(createJSONStringResult(env, jDataStr)); + } else if (jTypeInt == 4) { + jbyteArray array = (jbyteArray) jDataObj; + if (array != nullptr) { + int length = env->GetArrayLength(array); + void *data = env->GetByteArrayElements(array, 0); + ret = std::move(createByteArrayResult((const char *) data, length)); + env->ReleaseByteArrayElements(array, (jbyte *) data, 0); + } + } + env->DeleteLocalRef(jDataObj); + if (result != nullptr) { + env->DeleteLocalRef(result); + } + } + + return ret; +} + +void _callNativeComponent(const char *pageId, const char *ref, const char *method, + const char *arguments, int argumentsLength, const char *options, int optionsLength) { + WeexCoreManager::getInstance()->getJSBridge()->onCallNativeComponent( + pageId, ref, method, arguments, argumentsLength, options, optionsLength + ); +} + +void _callAddElement(const char *pageId, const char *parentRef, const char *domStr, + const char *index_cstr) { + + WeexCoreManager::getInstance()->getJSBridge()->onCallAddElement(pageId,parentRef,domStr,index_cstr); +} + +void _setTimeout(const char *callbackId, const char *time) { + WeexCoreManager::getInstance()->getJSBridge()->onSetTimeout(callbackId,time); +} + +void _callNativeLog(const char *str_array) { + WeexCoreManager::getInstance()->getJSBridge()->onCallNativeLog(str_array); +} + +void _callCreateBody(const char *pageId, const char *domStr) { + WeexCoreManager::getInstance()->getJSBridge()->onCallCreateBody(pageId,domStr); +} + +int _callUpdateFinish(const char *pageId, const char *task, const char *callback) { + return WeexCoreManager::getInstance()->getJSBridge()->onCallUpdateFinish(pageId,task,callback); +} + +void _callCreateFinish(const char *pageId) { + WeexCoreManager::getInstance()->getJSBridge()->onCallCreateFinish(pageId); +} + +int _callRefreshFinish(const char *pageId, const char *task, const char *callback) { + return WeexCoreManager::getInstance()->getJSBridge()->onCallRefreshFinish( + pageId,task,callback); +} + +void _callUpdateAttrs(const char *pageId, const char *ref, const char *data) { + WeexCoreManager::getInstance()->getJSBridge()->onCallUpdateAttrs(pageId,ref,data); +} + +void _callUpdateStyle(const char *pageId, const char *ref, const char *data) { + WeexCoreManager::getInstance()->getJSBridge()->onCallUpdateStyle( + pageId, ref, data + ); +} + +void _callRemoveElement(const char *pageId, const char *ref) { + WeexCoreManager::getInstance()->getJSBridge()->onCallRemoveElement(pageId,ref); +} + +void _callMoveElement(const char *pageId, const char *ref, const char *parentRef, int index) { + WeexCoreManager::getInstance()->getJSBridge()->onCallMoveElement( + pageId,ref,parentRef,index + ); +} + +void _callAddEvent(const char *pageId, const char *ref, const char *event) { + WeexCoreManager::getInstance()->getJSBridge()->onCallAddEvent( + pageId,ref,event + ); +} + +void _callRemoveEvent(const char *pageId, const char *ref, const char *event) { + WeexCoreManager::getInstance()->getJSBridge()->onCallRemoveEvent( + pageId,ref,event + ); +} + +int _setInterval(const char *pageId, const char *callbackId, const char *_time) { + return WeexCoreManager::getInstance()->getJSBridge()->onSetInterval(pageId,callbackId,_time); +} + +void _clearInterval(const char *pageId, const char *callbackId) { + WeexCoreManager::getInstance()->getJSBridge()->onClearInterval(pageId,callbackId); +} + +const char *_callGCanvasLinkNative(const char *pageId, int type, const char *args) { + const char *retVal = NULL; + if (gCanvasFunc) { + retVal = callGCanvasFun(gCanvasFunc, pageId, type, args); + } + + return retVal; +} + +const char *_t3dLinkNative(int type, const char *args) { + const char *retVal = NULL; + if (t3dFunc) { + retVal = WeexCore::weexCallT3dFunc(t3dFunc, type, args); + } + + return retVal; +} + +void callHandlePostMessage(const char *vimId, const char *data) { + JNIEnv *pEnv = getJNIEnv(); + jstring pJstring = pEnv->NewStringUTF(vimId); + jbyteArray pArray = newJByteArray(pEnv, data); + Bridge_Impl_Android::getInstance()->handlePostMessage(pJstring, pArray); + pEnv->DeleteLocalRef(pJstring); + pEnv->DeleteLocalRef(pArray); +} + +void +callDIspatchMessage(const char *clientId, const char *data, const char *callback, + const char *vmId) { + JNIEnv *pEnv = getJNIEnv(); + jstring pClientId = newJString(pEnv, clientId); + jbyteArray pArray = newJByteArray(pEnv, data); + jstring pCallback = newJString(pEnv, callback); + jstring pVmId = newJString(pEnv, vmId); + Bridge_Impl_Android::getInstance()->handleDispatchMessage(pClientId, pVmId, pArray, pCallback); + pEnv->DeleteLocalRef(pClientId); + pEnv->DeleteLocalRef(pArray); + pEnv->DeleteLocalRef(pCallback); + pEnv->DeleteLocalRef(pVmId); +} + + http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/android/jsengine/api/WeexJSCoreApi.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/jsengine/api/WeexJSCoreApi.h b/weex_core/Source/android/jsengine/api/WeexJSCoreApi.h new file mode 100644 index 0000000..cf0b81e --- /dev/null +++ b/weex_core/Source/android/jsengine/api/WeexJSCoreApi.h @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// +// Created by Darin on 13/02/2018. +// + +#ifndef WEEXV8_WEEXJSCOREAPI_H +#define WEEXV8_WEEXJSCOREAPI_H + +#include "jni.h" +#include "IPCResult.h" +#include "WeexJSCoreApi.h" + +extern "C" { + +void _setJSVersion(const char *jsVersion); + +void _reportException(const char *pageId, const char *func, const char *exception_string); + +void _callNative(const char *pageId, const char *task, const char *callback); + + +std::unique_ptr<IPCResult> _callNativeModule(const char *pageId, const char *module, const char *method, + const char *arguments, int argumentsLength, const char *options, int optionsLength); + +void _callNativeComponent(const char *pageId, const char *ref, + const char *method, + const char *arguments, int argumentsLength, const char *options, int optionsLength); + +void _callAddElement(const char *pageId, const char *parentRef, const char *domStr, + const char *index_cstr); + +void _setTimeout(const char *callbackId, const char *time); + +void _callNativeLog(const char *str_array); + +void _callCreateBody(const char *pageId, const char *domStr); + +int _callUpdateFinish(const char *pageId, const char *task, const char *callback); + +void _callCreateFinish(const char *pageId); + +int _callRefreshFinish(const char *pageId, const char *task, const char *callback); + +void _callUpdateAttrs(const char *pageId, const char *ref, const char *data); + +void _callUpdateStyle(const char *pageId, const char *ref, const char *data); + +void _callRemoveElement(const char *pageId, const char *ref); + +void _callMoveElement(const char *pageId, const char *ref, const char *parentRef, int index); + +void _callAddEvent(const char *pageId, const char *ref, const char *event); + +void _callRemoveEvent(const char *pageId, const char *ref, const char *event); + +int _setInterval(const char *pageId, const char *callbackId, const char *_time); + +void _clearInterval(const char *pageId, const char *callbackId); + +const char *_callGCanvasLinkNative(const char *pageId, int type, const char *args); + +const char *_t3dLinkNative(int type, const char *args); + +void callHandlePostMessage(const char *vimId, const char *data); + +void +callDIspatchMessage(const char *clientId, const char *data, const char *callback, const char *vmId); +}; +#endif //WEEXV8_WEEXJSCOREAPI_H http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/android/jsengine/multiprocess/ExtendJSApi.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/jsengine/multiprocess/ExtendJSApi.cpp b/weex_core/Source/android/jsengine/multiprocess/ExtendJSApi.cpp index 36eeabd..80b60d5 100644 --- a/weex_core/Source/android/jsengine/multiprocess/ExtendJSApi.cpp +++ b/weex_core/Source/android/jsengine/multiprocess/ExtendJSApi.cpp @@ -18,7 +18,7 @@ */ #include <android/base/string/string_utils.h> #include <base/ViewUtils.h> -#include <core/api/WeexJSCoreApi.h> +#include <android/jsengine/api/WeexJSCoreApi.h> #include "ExtendJSApi.h" using namespace WeexCore; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/android/jsengine/multiprocess/WeexProxy.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/android/jsengine/multiprocess/WeexProxy.cpp b/weex_core/Source/android/jsengine/multiprocess/WeexProxy.cpp index c9bd3b0..dbb7d58 100644 --- a/weex_core/Source/android/jsengine/multiprocess/WeexProxy.cpp +++ b/weex_core/Source/android/jsengine/multiprocess/WeexProxy.cpp @@ -23,7 +23,7 @@ #include <android/base/string/string_utils.h> #include <core/config/core_environment.h> #include <android/jsengine/multiprocess/ExtendJSApi.h> -#include <core/api/WeexJSCoreApi.h> +#include <android/jsengine/api/WeexJSCoreApi.h> #include <dlfcn.h> #include <errno.h> @@ -267,6 +267,7 @@ namespace WeexCore { Bridge_Impl_Android::getInstance()->setGlobalRef(jThis); WeexCoreManager::getInstance()->setPlatformBridge(Bridge_Impl_Android::getInstance()); + WeexCoreManager::getInstance()->setJSBridge(new JSBridge()); RenderManager::GetInstance()->SetMeasureFunctionAdapter(new MeasureFunctionAdapterImplAndroid()); std::unique_ptr<IPCSerializer> serializer(createIPCSerializer()); const std::vector<INIT_FRAMEWORK_PARAMS *> &initFrameworkParams = initFromParam(env, http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/core/api/WeexJSCoreApi.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/core/api/WeexJSCoreApi.cpp b/weex_core/Source/core/api/WeexJSCoreApi.cpp deleted file mode 100644 index a1bd22c..0000000 --- a/weex_core/Source/core/api/WeexJSCoreApi.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -// -// Created by Darin on 13/02/2018. -// - -#include "WeexJSCoreApi.h" -#include <android/bridge/impl/bridge_impl_android.h> -#include <core/render/manager/render_manager.h> -#include <android/jsengine/multiprocess/ExtendJSApi.h> -#include <android/base/string/string_utils.h> -#include <wson/wson_parser.h> - -using namespace WeexCore; - -extern WeexCore::FunType gCanvasFunc; -extern WeexCore::FunTypeT3d t3dFunc; - -void _setJSVersion(const char *jsVersion) { - LOGA("init JSFrm version %s", jsVersion); - Bridge_Impl_Android::getInstance()->setJSVersion(jsVersion); -} - -void _reportException(const char *pageId, const char *func, const char *exception_string) { - Bridge_Impl_Android::getInstance()->reportException(pageId, func, exception_string); -} - -void _callNative(const char *pageId, const char *task, const char *callback) { - if (pageId == nullptr || task == nullptr) - return; -#if JSAPI_LOG - LOGD("[ExtendJSApi] handleCallNative >>>> pageId: %s, task: %s", pageId, task); -#endif - if (strcmp(task, "[{\"module\":\"dom\",\"method\":\"createFinish\",\"args\":[]}]") == 0) { - RenderManager::GetInstance()->CreateFinish(pageId) ? 0 : -1; - } else { - Bridge_Impl_Android::getInstance()->callNative(pageId, task, callback); - } - -}; - -std::unique_ptr<IPCResult> -_callNativeModule(const char *pageId, const char *module, const char *method, - const char *arguments, int argumentsLength, const char *options, int optionsLength) { - std::unique_ptr<IPCResult> ret = createInt32Result(-1); - if (pageId != nullptr && module != nullptr && method != nullptr) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] handleCallNativeModule >>>> pageId: %s, module: %s, method: %s, arg: %s, opt: %s", - pageId, module, method, argString, optString); -#endif - - // add for android support - jobject result; - result = static_cast<jobject>(Bridge_Impl_Android::getInstance()->callNativeModule(pageId, module, method, - arguments, argumentsLength, options, optionsLength)); - if (result == nullptr){ - return ret; - } - - JNIEnv *env = getJNIEnv(); - jfieldID jTypeId = env->GetFieldID(jWXJSObject, "type", "I"); - jint jTypeInt = env->GetIntField(result, jTypeId); - jfieldID jDataId = env->GetFieldID(jWXJSObject, "data", "Ljava/lang/Object;"); - jobject jDataObj = env->GetObjectField(result, jDataId); - if (jTypeInt == 1) { - if (jDoubleValueMethodId == NULL) { - jclass jDoubleClazz = env->FindClass("java/lang/Double"); - jDoubleValueMethodId = env->GetMethodID(jDoubleClazz, "doubleValue", "()D"); - env->DeleteLocalRef(jDoubleClazz); - } - jdouble jDoubleObj = env->CallDoubleMethod(jDataObj, jDoubleValueMethodId); - ret = std::move(createDoubleResult(jDoubleObj)); - - } else if (jTypeInt == 2) { - jstring jDataStr = (jstring) jDataObj; - ret = std::move(createStringResult(env, jDataStr)); - } else if (jTypeInt == 3) { - jstring jDataStr = (jstring) jDataObj; - ret = std::move(createJSONStringResult(env, jDataStr)); - } else if (jTypeInt == 4) { - jbyteArray array = (jbyteArray)jDataObj; - if(array != nullptr){ - int length = env->GetArrayLength(array); - void* data = env->GetByteArrayElements(array, 0); - ret = std::move(createByteArrayResult((const char*)data, length)); - env->ReleaseByteArrayElements(array, (jbyte*)data, 0); - } - } - env->DeleteLocalRef(jDataObj); - if(result != nullptr){ - env->DeleteLocalRef(result); - } - } - - return ret; -} - -void _callNativeComponent(const char *pageId, const char *ref, const char *method, - const char *arguments, int argumentsLength, const char *options, int optionsLength) { - if (pageId != nullptr && ref != nullptr && method != nullptr) { - -#if JSAPI_LOG - LOGD("[ExtendJSApi] handleCallNativeComponent >>>> pageId: %s, ref: %s, method: %s, arg: %s, opt: %s", - pageId, ref, method, argString, optString); -#endif - - Bridge_Impl_Android::getInstance()->callNativeComponent(pageId, ref, method, - arguments, argumentsLength, options, optionsLength); - } -} - -void _callAddElement(const char *pageId, const char *parentRef, const char *domStr, - const char *index_cstr) { - - - const char *indexChar = index_cstr == nullptr ? "\0" : index_cstr; - - int index = atoi(indexChar); - if (pageId == nullptr || parentRef == nullptr || domStr == nullptr || index < -1) - return; - -#if JSAPI_LOG - - std::string log = ""; - log.append("pageId: ").append(pageId).append(", parentRef: ").append(parentRef).append(", domStr: ").append(domStr); - int log_index = 0; - int maxLength = 800; - std::string sub; - while (log_index < log.length()) { - if (log.length() <= log_index + maxLength) { - sub = log.substr(log_index); - } else { - sub = log.substr(log_index, maxLength); - } - - - if (log_index == 0) - LOGD("[ExtendJSApi] functionCallAddElement >>>> %s", sub.c_str()); - else - LOGD(" [ExtendJSApi] functionCallAddElement >>>> %s", sub.c_str()); - - log_index += maxLength; - } -#endif - - RenderManager::GetInstance()->AddRenderObject(pageId, parentRef, index, domStr); -} - -void _setTimeout(const char *callbackId, const char *time) { - Bridge_Impl_Android::getInstance()->setTimeout(callbackId, time); -} - -void _callNativeLog(const char *str_array) { - Bridge_Impl_Android::getInstance()->callNativeLog(str_array); -} - -void _callCreateBody(const char *pageId, const char *domStr) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] functionCallCreateBody >>>> pageId: %s, domStr: %s", pageId, domStr); -#endif - - RenderManager::GetInstance()->CreatePage(pageId, domStr) ? 0 : -1; -} - -int _callUpdateFinish(const char *pageId, const char *task, const char *callback) { - return Bridge_Impl_Android::getInstance()->callUpdateFinish(pageId, task, callback); -} - -void _callCreateFinish(const char *pageId) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] functionCallCreateFinish >>>> pageId: %s", pageId); -#endif - - RenderManager::GetInstance()->CreateFinish(pageId); -} - -int _callRefreshFinish(const char *pageId, const char *task, const char *callback) { - if (pageId == nullptr) - return -1; - return Bridge_Impl_Android::getInstance()->callRefreshFinish(pageId, task, callback); -} - -void _callUpdateAttrs(const char *pageId, const char *ref, const char *data) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] functionCallUpdateAttrs >>>> pageId: %s, ref: %s, data: %s", pageId, - ref, data); -#endif - - RenderManager::GetInstance()->UpdateAttr(pageId, ref, data); -} - -void _callUpdateStyle(const char *pageId, const char *ref, const char *data) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] functionCallUpdateStyle >>>> pageId: %s, ref: %s, data: %s", pageId, - ref, data); -#endif - - RenderManager::GetInstance()->UpdateStyle(pageId, ref, data); -} - -void _callRemoveElement(const char *pageId, const char *ref) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] functionCallRemoveElement >>>> pageId: %s, ref: %s", pageId, - ref); -#endif - - RenderManager::GetInstance()->RemoveRenderObject(pageId, ref); -} - -void _callMoveElement(const char *pageId, const char *ref, const char *parentRef, int index) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] functionCallRemoveElement >>>> pageId: %s, ref: %s, parentRef: %s, index: %d", - pageId, ref, parentRef, index); -#endif - - RenderManager::GetInstance()->MoveRenderObject(pageId, ref, parentRef, index); -} - -void _callAddEvent(const char *pageId, const char *ref, const char *event) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] functionCallAddEvent >>>> pageId: %s, ref: %s, event: %s", pageId, - ref, event); -#endif - - RenderManager::GetInstance()->AddEvent(pageId, ref, event); -} - -void _callRemoveEvent(const char *pageId, const char *ref, const char *event) { -#if JSAPI_LOG - LOGD("[ExtendJSApi] functionCallRemoveEvent >>>> pageId: %s, ref: %s, event: %s", pageId, - ref, event); -#endif - - RenderManager::GetInstance()->RemoveEvent(pageId, ref, event); -} - -int _setInterval(const char *pageId, const char *callbackId, const char *_time) { - return (atoi(pageId) << 16) | (atoi(callbackId)); -} - -void _clearInterval(const char *pageId, const char *callbackId) { - return; -} - -const char *_callGCanvasLinkNative(const char *pageId, int type, const char *args) { - const char *retVal = NULL; - if (gCanvasFunc) { - retVal = callGCanvasFun(gCanvasFunc, pageId, type, args); - } - - return retVal; -} - -const char *_t3dLinkNative(int type, const char *args) { - const char *retVal = NULL; - if (t3dFunc) { - retVal = WeexCore::weexCallT3dFunc(t3dFunc, type, args); - } - - return retVal; -} - -void callHandlePostMessage(const char *vimId, const char *data) { - JNIEnv *pEnv = getJNIEnv(); - jstring pJstring = pEnv->NewStringUTF(vimId); - jbyteArray pArray = newJByteArray(pEnv, data); - Bridge_Impl_Android::getInstance()->handlePostMessage(pJstring, pArray); - pEnv->DeleteLocalRef(pJstring); - pEnv->DeleteLocalRef(pArray); -} - -void -callDIspatchMessage(const char *clientId, const char *data, const char *callback, - const char *vmId) { - JNIEnv *pEnv = getJNIEnv(); - jstring pClientId = newJString(pEnv, clientId); - jbyteArray pArray = newJByteArray(pEnv, data); - jstring pCallback = newJString(pEnv, callback); - jstring pVmId = newJString(pEnv, vmId); - Bridge_Impl_Android::getInstance()->handleDispatchMessage(pClientId, pVmId, pArray, pCallback); - pEnv->DeleteLocalRef(pClientId); - pEnv->DeleteLocalRef(pArray); - pEnv->DeleteLocalRef(pCallback); - pEnv->DeleteLocalRef(pVmId); -} - - http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/core/api/WeexJSCoreApi.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/core/api/WeexJSCoreApi.h b/weex_core/Source/core/api/WeexJSCoreApi.h deleted file mode 100644 index cf0b81e..0000000 --- a/weex_core/Source/core/api/WeexJSCoreApi.h +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -// -// Created by Darin on 13/02/2018. -// - -#ifndef WEEXV8_WEEXJSCOREAPI_H -#define WEEXV8_WEEXJSCOREAPI_H - -#include "jni.h" -#include "IPCResult.h" -#include "WeexJSCoreApi.h" - -extern "C" { - -void _setJSVersion(const char *jsVersion); - -void _reportException(const char *pageId, const char *func, const char *exception_string); - -void _callNative(const char *pageId, const char *task, const char *callback); - - -std::unique_ptr<IPCResult> _callNativeModule(const char *pageId, const char *module, const char *method, - const char *arguments, int argumentsLength, const char *options, int optionsLength); - -void _callNativeComponent(const char *pageId, const char *ref, - const char *method, - const char *arguments, int argumentsLength, const char *options, int optionsLength); - -void _callAddElement(const char *pageId, const char *parentRef, const char *domStr, - const char *index_cstr); - -void _setTimeout(const char *callbackId, const char *time); - -void _callNativeLog(const char *str_array); - -void _callCreateBody(const char *pageId, const char *domStr); - -int _callUpdateFinish(const char *pageId, const char *task, const char *callback); - -void _callCreateFinish(const char *pageId); - -int _callRefreshFinish(const char *pageId, const char *task, const char *callback); - -void _callUpdateAttrs(const char *pageId, const char *ref, const char *data); - -void _callUpdateStyle(const char *pageId, const char *ref, const char *data); - -void _callRemoveElement(const char *pageId, const char *ref); - -void _callMoveElement(const char *pageId, const char *ref, const char *parentRef, int index); - -void _callAddEvent(const char *pageId, const char *ref, const char *event); - -void _callRemoveEvent(const char *pageId, const char *ref, const char *event); - -int _setInterval(const char *pageId, const char *callbackId, const char *_time); - -void _clearInterval(const char *pageId, const char *callbackId); - -const char *_callGCanvasLinkNative(const char *pageId, int type, const char *args); - -const char *_t3dLinkNative(int type, const char *args); - -void callHandlePostMessage(const char *vimId, const char *data); - -void -callDIspatchMessage(const char *clientId, const char *data, const char *callback, const char *vmId); -}; -#endif //WEEXV8_WEEXJSCOREAPI_H http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/core/bridge/bridge.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/core/bridge/bridge.h b/weex_core/Source/core/bridge/bridge.h index 823e06c..5660e4c 100644 --- a/weex_core/Source/core/bridge/bridge.h +++ b/weex_core/Source/core/bridge/bridge.h @@ -19,7 +19,7 @@ #ifndef Bridge_h #define Bridge_h -#include <jni.h> +//#include <jni.h> #include <string> #include <map> #include <set> http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/core/bridge/js_bridge.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/core/bridge/js_bridge.cpp b/weex_core/Source/core/bridge/js_bridge.cpp new file mode 100644 index 0000000..17608d8 --- /dev/null +++ b/weex_core/Source/core/bridge/js_bridge.cpp @@ -0,0 +1,201 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "js_bridge.h" +#include <core/manager/weex_core_manager.h> +#include <core/render/manager/render_manager.h> + +namespace WeexCore { + void JSBridge::onSetJSVersion(const char *jsVersion) { + WeexCoreManager::getInstance()->getPlatformBridge()->setJSVersion(jsVersion); + } + + void JSBridge::onReportException(const char *pageId, const char *func, const char *exception_string) { + WeexCoreManager::getInstance()->getPlatformBridge()->reportException(pageId, func, exception_string); + } + + void JSBridge::onCallNative(const char *pageId, const char *task, const char *callback) { + if (pageId == nullptr || task == nullptr) + return; +#if JSAPI_LOG + LOGD("[ExtendJSApi] handleCallNative >>>> pageId: %s, task: %s", pageId, task); +#endif + if (strcmp(task, "[{\"module\":\"dom\",\"method\":\"createFinish\",\"args\":[]}]") == 0) { + RenderManager::GetInstance()->CreateFinish(pageId) ? 0 : -1; + } else { + WeexCoreManager::getInstance()->getPlatformBridge()->callNative(pageId, task, callback); + } + } + + + void *JSBridge::onCallNativeModule(const char *pageId, const char *module, const char *method, + const char *arguments, int argumentsLength, const char *options, + int optionsLength) { + return WeexCoreManager::getInstance()->getPlatformBridge()->callNativeModule( + pageId, module, method, arguments, + argumentsLength, options, + optionsLength + ); + } + + void JSBridge::onCallNativeComponent(const char *pageId, const char *ref, + const char *method, + const char *arguments, int argumentsLength, const char *options, + int optionsLength) { + if (pageId != nullptr && ref != nullptr && method != nullptr) { + +#if JSAPI_LOG + LOGD("[ExtendJSApi] handleCallNativeComponent >>>> pageId: %s, ref: %s, method: %s, arg: %s, opt: %s", + pageId, ref, method, argString, optString); +#endif + WeexCoreManager::getInstance()->getPlatformBridge()->callNativeComponent( + pageId, ref, method, arguments, argumentsLength, options, optionsLength + ); + } + } + + + void JSBridge::onCallAddElement(const char *pageId, const char *parentRef, const char *domStr, + const char *index_cstr) { + const char *indexChar = index_cstr == nullptr ? "\0" : index_cstr; + + int index = atoi(indexChar); + if (pageId == nullptr || parentRef == nullptr || domStr == nullptr || index < -1) + return; + +#if JSAPI_LOG + + std::string log = ""; + log.append("pageId: ").append(pageId).append(", parentRef: ").append(parentRef).append(", domStr: ").append(domStr); + int log_index = 0; + int maxLength = 800; + std::string sub; + while (log_index < log.length()) { + if (log.length() <= log_index + maxLength) { + sub = log.substr(log_index); + } else { + sub = log.substr(log_index, maxLength); + } + + + if (log_index == 0) + LOGD("[ExtendJSApi] functionCallAddElement >>>> %s", sub.c_str()); + else + LOGD(" [ExtendJSApi] functionCallAddElement >>>> %s", sub.c_str()); + + log_index += maxLength; + } +#endif + + RenderManager::GetInstance()->AddRenderObject(pageId, parentRef, index, domStr); + } + + void JSBridge::onSetTimeout(const char *callbackId, const char *time) { + WeexCoreManager::getInstance()->getPlatformBridge()->setTimeout(callbackId, time); + } + + void JSBridge::onCallNativeLog(const char *str_array) { + WeexCoreManager::getInstance()->getPlatformBridge()->callNativeLog(str_array); + } + + + void JSBridge::onCallCreateBody(const char *pageId, const char *domStr) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] functionCallCreateBody >>>> pageId: %s, domStr: %s", pageId, domStr); +#endif + + RenderManager::GetInstance()->CreatePage(pageId, domStr) ? 0 : -1; + } + + int JSBridge::onCallUpdateFinish(const char *pageId, const char *task, const char *callback) { + WeexCoreManager::getInstance()->getPlatformBridge()->callUpdateFinish(pageId, task, callback); + } + + void JSBridge::onCallCreateFinish(const char *pageId) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] functionCallCreateFinish >>>> pageId: %s", pageId); +#endif + + RenderManager::GetInstance()->CreateFinish(pageId); + } + + int JSBridge::onCallRefreshFinish(const char *pageId, const char *task, const char *callback) { + if (pageId == nullptr) + return -1; + return WeexCoreManager::getInstance()->getPlatformBridge()->callRefreshFinish(pageId, task, callback); + } + + void JSBridge::onCallUpdateAttrs(const char *pageId, const char *ref, const char *data) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] functionCallUpdateAttrs >>>> pageId: %s, ref: %s, data: %s", pageId, + ref, data); +#endif + + RenderManager::GetInstance()->UpdateAttr(pageId, ref, data); + } + + void JSBridge::onCallUpdateStyle(const char *pageId, const char *ref, const char *data) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] functionCallUpdateStyle >>>> pageId: %s, ref: %s, data: %s", pageId, + ref, data); +#endif + RenderManager::GetInstance()->UpdateStyle(pageId, ref, data); + } + + + void JSBridge::onCallRemoveElement(const char *pageId, const char *ref) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] functionCallRemoveElement >>>> pageId: %s, ref: %s", pageId, + ref); +#endif + RenderManager::GetInstance()->RemoveRenderObject(pageId, ref); + } + + void JSBridge::onCallMoveElement(const char *pageId, const char *ref, const char *parentRef, int index) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] functionCallRemoveElement >>>> pageId: %s, ref: %s, parentRef: %s, index: %d", + pageId, ref, parentRef, index); +#endif + RenderManager::GetInstance()->MoveRenderObject(pageId, ref, parentRef, index); + } + + void JSBridge::onCallAddEvent(const char *pageId, const char *ref, const char *event) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] functionCallAddEvent >>>> pageId: %s, ref: %s, event: %s", pageId, + ref, event); +#endif + RenderManager::GetInstance()->AddEvent(pageId, ref, event); + } + + void JSBridge::onCallRemoveEvent(const char *pageId, const char *ref, const char *event) { +#if JSAPI_LOG + LOGD("[ExtendJSApi] functionCallRemoveEvent >>>> pageId: %s, ref: %s, event: %s", pageId, + ref, event); +#endif + RenderManager::GetInstance()->RemoveEvent(pageId, ref, event); + } + + int JSBridge::onSetInterval(const char *pageId, const char *callbackId, const char *_time) { + return (atoi(pageId) << 16) | (atoi(callbackId)); + } + + void JSBridge::onClearInterval(const char *pageId, const char *callbackId) { + return; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/core/bridge/js_bridge.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/core/bridge/js_bridge.h b/weex_core/Source/core/bridge/js_bridge.h new file mode 100644 index 0000000..ee9a771 --- /dev/null +++ b/weex_core/Source/core/bridge/js_bridge.h @@ -0,0 +1,82 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// +// Created by é佩翰 on 2018/6/1. +// + +#ifndef WEEXCORE_JS_BRIDGE_H +#define WEEXCORE_JS_BRIDGE_H + +namespace WeexCore { + class JSBridge { + public: + JSBridge(){}; + + ~JSBridge(){}; + + public: + + void onSetJSVersion(const char *jsVersion); + + void onReportException(const char *pageId, const char *func, const char *exception_string); + + void onCallNative(const char *pageId, const char *task, const char *callback); + + + void *onCallNativeModule(const char *pageId, const char *module, const char *method, + const char *arguments, int argumentsLength, const char *options, int optionsLength); + + void onCallNativeComponent(const char *pageId, const char *ref, + const char *method, + const char *arguments, int argumentsLength, const char *options, int optionsLength); + + void onCallAddElement(const char *pageId, const char *parentRef, const char *domStr, + const char *index_cstr); + + void onSetTimeout(const char *callbackId, const char *time); + + void onCallNativeLog(const char *str_array); + + void onCallCreateBody(const char *pageId, const char *domStr); + + int onCallUpdateFinish(const char *pageId, const char *task, const char *callback); + + void onCallCreateFinish(const char *pageId); + + int onCallRefreshFinish(const char *pageId, const char *task, const char *callback); + + void onCallUpdateAttrs(const char *pageId, const char *ref, const char *data); + + void onCallUpdateStyle(const char *pageId, const char *ref, const char *data); + + void onCallRemoveElement(const char *pageId, const char *ref); + + void onCallMoveElement(const char *pageId, const char *ref, const char *parentRef, int index); + + void onCallAddEvent(const char *pageId, const char *ref, const char *event); + + void onCallRemoveEvent(const char *pageId, const char *ref, const char *event); + + int onSetInterval(const char *pageId, const char *callbackId, const char *_time); + + void onClearInterval(const char *pageId, const char *callbackId); + }; +} + +#endif //WEEXCORE_JS_BRIDGE_H \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/core/manager/weex_core_manager.cpp ---------------------------------------------------------------------- diff --git a/weex_core/Source/core/manager/weex_core_manager.cpp b/weex_core/Source/core/manager/weex_core_manager.cpp index 067c399..2b49367 100644 --- a/weex_core/Source/core/manager/weex_core_manager.cpp +++ b/weex_core/Source/core/manager/weex_core_manager.cpp @@ -30,7 +30,16 @@ namespace WeexCore { this->platformBridge = pBridge; } - Bridge *WeexCoreManager::getPlatformBridge() { + Bridge* WeexCoreManager::getPlatformBridge() { return this->platformBridge; } + + WeexCoreManager *WeexCoreManager::setJSBridge(JSBridge *jsBridge) { + this->jsBridge = jsBridge; + } + + JSBridge* WeexCoreManager::getJSBridge() { + return this->jsBridge; + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/19a24297/weex_core/Source/core/manager/weex_core_manager.h ---------------------------------------------------------------------- diff --git a/weex_core/Source/core/manager/weex_core_manager.h b/weex_core/Source/core/manager/weex_core_manager.h index 0757ba8..3d1fd6d 100644 --- a/weex_core/Source/core/manager/weex_core_manager.h +++ b/weex_core/Source/core/manager/weex_core_manager.h @@ -21,17 +21,24 @@ #define WEEXCORE_WEEX_CORE_MANAGER_H #include <core/bridge/bridge.h> +#include <core/bridge/js_bridge.h> namespace WeexCore { class WeexCoreManager { private: Bridge *platformBridge = nullptr; static WeexCoreManager *m_pInstance; + JSBridge* jsBridge = nullptr; private: WeexCoreManager() {}; - ~WeexCoreManager() {}; + ~WeexCoreManager() { + delete platformBridge; + platformBridge = nullptr; + delete jsBridge; + jsBridge = nullptr; + }; //just to release singleton object class Garbo { @@ -56,6 +63,10 @@ namespace WeexCore { Bridge *getPlatformBridge(); WeexCoreManager *setPlatformBridge(Bridge *pBridge); + + JSBridge* getJSBridge(); + WeexCoreManager *setJSBridge(JSBridge *jsBridge); + }; }
