diff --git a/ArkwebSchemeHandler/.gitignore b/ArkwebSchemeHandler/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkwebSchemeHandler/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkwebSchemeHandler/AppScope/app.json5 b/ArkwebSchemeHandler/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6c6d6b856fcc951ff4d5db5ed8479774532b78c2 --- /dev/null +++ b/ArkwebSchemeHandler/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.arkwebschemehandler", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkwebSchemeHandler/AppScope/resources/base/element/string.json b/ArkwebSchemeHandler/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4473b35b3f46248b60f681be27eba9821898cd3d --- /dev/null +++ b/ArkwebSchemeHandler/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ArkwebSchemeHandler" + } + ] +} diff --git a/ArkwebSchemeHandler/AppScope/resources/base/media/background.png b/ArkwebSchemeHandler/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkwebSchemeHandler/AppScope/resources/base/media/background.png differ diff --git a/ArkwebSchemeHandler/AppScope/resources/base/media/foreground.png b/ArkwebSchemeHandler/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkwebSchemeHandler/AppScope/resources/base/media/foreground.png differ diff --git a/ArkwebSchemeHandler/AppScope/resources/base/media/layered_image.json b/ArkwebSchemeHandler/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkwebSchemeHandler/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/README.md b/ArkwebSchemeHandler/README.md new file mode 100644 index 0000000000000000000000000000000000000000..aeae1ea7a82212e0c340875002a6e6728dc56144 --- /dev/null +++ b/ArkwebSchemeHandler/README.md @@ -0,0 +1,63 @@ +# 拦截Web组件发起的网络请求 + +### 介绍 +本示例通过使用arkweb_scheme_handler.h相关API实现对Web组件发出的请求进行拦截,并为被拦截的请求提供自定义的响应头以及响应体。 + +### 效果预览 + +| 主页 | 拦截视频资源 | +|:--------------------------------------:|:-----------------------------------------:| +| ![home](screenshots/home.png) | ![home](screenshots/mp4.png) | +| 忽略csp检查并拦截 | 拦截ISOLATED属性 | +| ![home](screenshots/csp.png) | ![home](screenshots/ISOLATED.png) | +| 拦截LOCAL属性 | 拦截service worker +| ![home](screenshots/LOCAL.png) | ![home](screenshots/service_worker.png) +| 测试读取blob类型 | 测试读取chunked类型 | +| ![home](screenshots/blob.png) | ![home](screenshots/chunked.png) | + +### 使用说明 +1. 打开DEMO进入首页,展示html。 +2. 点击各链接进入不同属性的拦截结果页面或读取结果页面。 + +### 工程目录 + + +``` +├── entry +│ └── src +│ └── main +│ ├── cpp // C++代码区 +│ │ ├── CMakeLists.txt // CMAKE配置文件 +│ │ ├── hello.cpp // Native业务代码实现 +│ │ ├── rawfile_request.cpp // RawfileRequest实现 +│ │ ├── rawfile_request.h // RawfileRequest类 +│ │ └── types +│ │ └── libentry // C++接口导出 +│ │ ├── Index.d.ts +│ │ └── oh-package.json5 +│ ├── ets // ArkTS代码区 +│ │ ├── entryability +│ │ │ └── EntryAbility.ets // 入口类 +│ │ ├── entrybackupability +│ │ │ └── EntryBackupAbility.ets // 备份恢复框架 +│ │ └── pages +│ │ └── Index.ets // 主页 +│ └── resources // 应用资源文件 +``` +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.1 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.1 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.1 Release及以上。 \ No newline at end of file diff --git a/ArkwebSchemeHandler/build-profile.json5 b/ArkwebSchemeHandler/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..537a8ef6fd113674c68f085dae75fbbb95880efb --- /dev/null +++ b/ArkwebSchemeHandler/build-profile.json5 @@ -0,0 +1,41 @@ +{ + "app": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.0.1(13)", + "compatibleSdkVersion": "5.0.1(13)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/code-linter.json5 b/ArkwebSchemeHandler/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/ArkwebSchemeHandler/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/build-profile.json5 b/ArkwebSchemeHandler/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9b5904523a7e5027acf6469ed9bb91003daf0237 --- /dev/null +++ b/ArkwebSchemeHandler/entry/build-profile.json5 @@ -0,0 +1,40 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a", "x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/hvigorfile.ts b/ArkwebSchemeHandler/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/ArkwebSchemeHandler/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkwebSchemeHandler/entry/obfuscation-rules.txt b/ArkwebSchemeHandler/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkwebSchemeHandler/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/oh-package.json5 b/ArkwebSchemeHandler/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..54cb066266f9993f5a023f2ac5a8dfc5d2574643 --- /dev/null +++ b/ArkwebSchemeHandler/entry/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/cpp/CMakeLists.txt b/ArkwebSchemeHandler/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..27bc12820c74e082ddcb3dbdb80db75951d72222 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,19 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(schemehandler) + + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + + +if(DEFINED PACKAGE_INFO_FILE) + include(${PACKAGE_INFO_FILE}) +endif() + + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + + +add_library(entry SHARED rawfile_request.cpp hello.cpp) +target_link_libraries(entry PUBLIC librawfile.z.so libace_napi.z.so libohweb.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/cpp/hello.cpp b/ArkwebSchemeHandler/entry/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5ec9335a06ff09c025923a959cc8cb7e1c24ff2 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/cpp/hello.cpp @@ -0,0 +1,137 @@ +#include "hilog/log.h" +#include "napi/native_api.h" +#include "rawfile_request.h" +#include "rawfile/raw_file_manager.h" +#include "web/arkweb_scheme_handler.h" +#include "web/arkweb_net_error_list.h" + +#undef LOG_TAG +#define LOG_TAG "ss-handler" + +ArkWeb_SchemeHandler *g_schemeHandler; +ArkWeb_SchemeHandler *g_schemeHandlerForSW; +NativeResourceManager *g_resourceManager; + +// 注册三方协议的配置,需要在Web内核初始化之前调用,否则会注册失败。 +static napi_value RegisterCustomSchemes(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "register custom schemes"); + OH_ArkWeb_RegisterCustomSchemes("custom", ARKWEB_SCHEME_OPTION_STANDARD | ARKWEB_SCHEME_OPTION_CORS_ENABLED); + OH_ArkWeb_RegisterCustomSchemes("custom-local", ARKWEB_SCHEME_OPTION_LOCAL); + OH_ArkWeb_RegisterCustomSchemes("custom-csp-bypassing", ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD); + OH_ArkWeb_RegisterCustomSchemes("custom-isolated", ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED); + return nullptr; +} + +// 请求开始的回调,在该函数中我们创建一个RawfileRequest来实现对Web内核请求的拦截。 +void OnURLRequestStart(const ArkWeb_SchemeHandler *schemeHandler, + ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + bool *intercept) +{ + *intercept = true; + RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); + OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); + request->Start(); +} + +// 请求结束的回调,在该函数中我们需要标记RawfileRequest已经结束了,内部不应该再使用ResourceHandler。 +void OnURLRequestStop(const ArkWeb_SchemeHandler *schemeHandler, + const ArkWeb_ResourceRequest *request) +{ + if (!request) { + OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); + return; + } + + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); + if (rawfileRequest) { + rawfileRequest->Stop(); + } +} + +void OnURLRequestStartForSW(const ArkWeb_SchemeHandler *schemeHandler, + ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + bool *intercept) +{ + *intercept = true; + RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); + OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); + request->Start(); +} + +void OnURLRequestStopForSW(const ArkWeb_SchemeHandler *schemeHandler, + const ArkWeb_ResourceRequest *request) +{ + if (!request) { + OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); + return; + } + + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); + if (rawfileRequest) { + rawfileRequest->Stop(); + } +} + +// 设置SchemeHandler。 +static napi_value SetSchemeHandler(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "set scheme handler"); + OH_ArkWeb_CreateSchemeHandler(&g_schemeHandler); + OH_ArkWeb_CreateSchemeHandler(&g_schemeHandlerForSW); + + OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandler, OnURLRequestStart); + OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandler, OnURLRequestStop); + + OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandlerForSW, OnURLRequestStart); + OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandlerForSW, OnURLRequestStop); + + OH_ArkWeb_SetSchemeHandler("custom", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-csp-bypassing", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-isolated", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-local", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("https", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("http", "scheme-handler", g_schemeHandler); + + OH_ArkWebServiceWorker_SetSchemeHandler("https", g_schemeHandlerForSW); + return nullptr; +} + +static napi_value InitResourceManager(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + g_resourceManager = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"setSchemeHandler", nullptr, SetSchemeHandler, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"initResourceManager", nullptr, InitResourceManager, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"registerCustomSchemes", nullptr, RegisterCustomSchemes, nullptr, nullptr, nullptr, napi_default, nullptr} + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/cpp/rawfile_request.cpp b/ArkwebSchemeHandler/entry/src/main/cpp/rawfile_request.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a35e9066b403cac1b56ba0d0960a0a25fe21329a --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/cpp/rawfile_request.cpp @@ -0,0 +1,257 @@ +#include "rawfile_request.h" + + +#include "threads.h" + + +#include "hilog/log.h" +#include "rawfile/raw_file.h" +#include "rawfile/raw_file_manager.h" + + +#undef LOG_TAG +#define LOG_TAG "ss-handler" + + +namespace { + + +uint8_t buffer[1024]; +cnd_t http_body_cnd; +mtx_t http_body_mtx; + + +// HttpBodyStream的读回调。 +void ReadCallback(const ArkWeb_HttpBodyStream *httpBodyStream, uint8_t* buffer, int bytesRead) +{ + OH_LOG_INFO(LOG_APP, "read http body back."); + bool isEof = OH_ArkWebHttpBodyStream_IsEof(httpBodyStream); + if (!isEof && bytesRead != 0) { + memset(buffer, 0, 1000); + OH_ArkWebHttpBodyStream_Read(httpBodyStream, buffer, 1000); + } else { + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebHttpBodyStream_GetUserData(httpBodyStream); + if (rawfileRequest) { + rawfileRequest->ReadRawfileDataOnWorkerThread(); + cnd_signal(&http_body_cnd); + } + } +} + + +int ReadHttpBodyOnWorkerThread(void* userData) +{ + memset(buffer, 0, 1000); + ArkWeb_HttpBodyStream *httpBodyStream = (ArkWeb_HttpBodyStream *)userData; + OH_ArkWebHttpBodyStream_Read(httpBodyStream, buffer, 1000); + cnd_init(&http_body_cnd); + mtx_init(&http_body_mtx, mtx_plain); + cnd_wait(&http_body_cnd, &http_body_mtx); + return 0; +} + + +int ReadRawfileOnWorkerThread(void* userData) +{ + RawfileRequest * rawfileRequest = (RawfileRequest *)userData; + if (rawfileRequest) { + rawfileRequest->ReadRawfileDataOnWorkerThread(); + } + return 0; +} + + +// ArkWeb_HttpBodyStream的初始化回调。 +void InitCallback(const ArkWeb_HttpBodyStream *httpBodyStream, ArkWeb_NetError result) +{ + OH_LOG_INFO(LOG_APP, "init http body stream done %{public}d.", result); + bool isChunked = OH_ArkWebHttpBodyStream_IsChunked(httpBodyStream); + OH_LOG_INFO(LOG_APP, "http body stream is chunked %{public}d.", isChunked); + thrd_t th; + if (thrd_create(&th, ReadHttpBodyOnWorkerThread, (void *)httpBodyStream) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "create thread failed."); + return; + } + + + if (thrd_detach(th) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "detach thread failed."); + } +} + + +const int blockSize = 1024 * 8; + + +} // namespace + + +RawfileRequest::RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + const NativeResourceManager* resourceManager) + : resourceRequest_(resourceRequest), + resourceHandler_(resourceHandler), + resourceManager_(resourceManager) {} + + +RawfileRequest::~RawfileRequest() {} + + +void RawfileRequest::Start() +{ + OH_LOG_INFO(LOG_APP, "start a rawfile request."); + char* url; + OH_ArkWebResourceRequest_GetUrl(resourceRequest_, &url); + std::string urlStr(url); + std::size_t position = urlStr.rfind('/'); + if (position != std::string::npos) { + rawfilePath_ = urlStr.substr(position + 1); + } + OH_ArkWeb_ReleaseString(url); + + + OH_ArkWeb_CreateResponse(&response_); + OH_ArkWebResourceRequest_GetHttpBodyStream(resourceRequest(), &stream_); + if (stream_) { + OH_LOG_ERROR(LOG_APP, "have http body stream"); + OH_ArkWebHttpBodyStream_SetUserData(stream_, this); + OH_ArkWebHttpBodyStream_SetReadCallback(stream_, ReadCallback); + OH_ArkWebHttpBodyStream_Init(stream_, InitCallback); + } else { + thrd_t th; + if (thrd_create(&th, ReadRawfileOnWorkerThread, (void *)this) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "create thread failed."); + return; + } + + + if (thrd_detach(th) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "detach thread failed."); + } + } +} + + +// 在worker线程中读取rawfile,并通过ResourceHandler返回给Web内核。 +void RawfileRequest::ReadRawfileDataOnWorkerThread() +{ + OH_LOG_INFO(LOG_APP, "read rawfile in worker thread."); + const struct UrlInfo { + std::string resource; + std::string mimeType; + } urlInfos[] = { + {"test.html", "text/html"}, + {"video.html", "text/html"}, + {"isolated.html", "text/html"}, + {"csp_bypassing.html", "text/html"}, + {"post_data.html", "text/html"}, + {"chunked_post_stream.html", "text/html"}, + {"local.html", "text/html"}, + {"service_worker.html", "text/html"}, + {"csp_script.js", "text/javascript"}, + {"sw.js", "text/javascript"}, + {"isolated_script.js", "text/javascript"}, + {"local_script.js", "text/javascript"}, + {"test.mp4", "video/mp4"}, + {"xhr", "application/json"} + }; + + + if (!resourceManager()) { + OH_LOG_ERROR(LOG_APP, "read rawfile error, resource manager is nullptr."); + return; + } + + + RawFile *rawfile = OH_ResourceManager_OpenRawFile(resourceManager(), rawfilePath().c_str()); + if (!rawfile) { + OH_ArkWebResponse_SetStatus(response(), 404); + } else { + OH_ArkWebResponse_SetStatus(response(), 200); + } + + + for (auto &urlInfo : urlInfos) { + if (urlInfo.resource == rawfilePath()) { + OH_ArkWebResponse_SetMimeType(response(), urlInfo.mimeType.c_str()); + break; + } + } + OH_ArkWebResponse_SetCharset(response(), "UTF-8"); + + + long len = OH_ResourceManager_GetRawFileSize(rawfile); + OH_ArkWebResponse_SetHeaderByName(response(), "content-length", std::to_string(len).c_str(), false); + DidReceiveResponse(); + + + long consumed = 0; + uint8_t buffer[blockSize]; + while (true) { + int ret = OH_ResourceManager_ReadRawFile(rawfile, buffer, blockSize); + OH_LOG_INFO(LOG_APP, "read rawfile %{public}d bytes.", ret); + if (ret == 0) { + break; + } + consumed += ret; + OH_ResourceManager_SeekRawFile(rawfile, consumed, 0); + DidReceiveData(buffer, ret); + memset(buffer, 0, blockSize); + } + + + OH_ResourceManager_CloseRawFile(rawfile); + DidFinish(); +} + + +void RawfileRequest::Stop() +{ + OH_LOG_INFO(LOG_APP, "stop the rawfile request."); + std::lock_guard guard(mutex_); + stopped_ = true; + if (response_) { + OH_ArkWeb_DestroyResponse(response_); + } + OH_ArkWebResourceRequest_Destroy(resourceRequest_); + OH_ArkWebResourceHandler_Destroy(resourceHandler_); +} + + +void RawfileRequest::DidReceiveResponse() +{ + OH_LOG_INFO(LOG_APP, "did receive response."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidReceiveResponse(resourceHandler_, response_); + } +} + + +void RawfileRequest::DidReceiveData(const uint8_t *buffer, int64_t bufLen) +{ + OH_LOG_INFO(LOG_APP, "did receive data."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidReceiveData(resourceHandler_, buffer, bufLen); + } +} + + +void RawfileRequest::DidFinish() +{ + OH_LOG_INFO(LOG_APP, "did finish."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidFinish(resourceHandler_); + } +} + + +void RawfileRequest::DidFailWithError(ArkWeb_NetError errorCode) +{ + OH_LOG_INFO(LOG_APP, "did finish with error %{public}d.", errorCode); + if (!stopped_) { + OH_ArkWebResourceHandler_DidFailWithError(resourceHandler_, errorCode); + } +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/cpp/rawfile_request.h b/ArkwebSchemeHandler/entry/src/main/cpp/rawfile_request.h new file mode 100644 index 0000000000000000000000000000000000000000..ce72bce77ab7fea89a360b6ab025c88c9b240b38 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/cpp/rawfile_request.h @@ -0,0 +1,53 @@ +#ifndef RAWFILE_REQUEST_H +#define RAWFILE_REQUEST_H + + +#include +#include + + +#include +#include "web/arkweb_scheme_handler.h" +#include "web/arkweb_net_error_list.h" + + +class RawfileRequest { +public: + RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + const NativeResourceManager* resourceManager); + ~RawfileRequest(); + + + void Start(); + void Stop(); + void ReadRawfileDataOnWorkerThread(); + + + const ArkWeb_ResourceHandler *resourceHandler() { return resourceHandler_; } + const ArkWeb_ResourceRequest *resourceRequest() { return resourceRequest_; } + const NativeResourceManager *resourceManager() { return resourceManager_; } + ArkWeb_Response *response() { return response_; } + ArkWeb_HttpBodyStream *stream() { return stream_; } + const std::string rawfilePath() { return rawfilePath_; } + + + void DidReceiveResponse(); + void DidReceiveData(const uint8_t *buffer, int64_t bufLen); + void DidFinish(); + void DidFailWithError(ArkWeb_NetError errorCode); + + +private: + const ArkWeb_ResourceRequest *resourceRequest_{nullptr}; + const ArkWeb_ResourceHandler *resourceHandler_{nullptr}; + const NativeResourceManager *resourceManager_{nullptr}; + ArkWeb_Response *response_; + bool stopped_{false}; + std::string rawfilePath_; + ArkWeb_HttpBodyStream *stream_{nullptr}; + std::mutex mutex_; +}; + + +#endif // RAWFILE_REQUEST_H \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkwebSchemeHandler/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f34c7c5744d67baf13ba4e26d3cd786025f08b90 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,3 @@ +export const registerCustomSchemes: () => void; +export const setSchemeHandler: () => void; +export const initResourceManager: (resmgr: resourceManager.ResourceManager) => void; \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/cpp/types/libentry/oh-package.json5 b/ArkwebSchemeHandler/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ea410725a8826704d061021d98cf02aa76cd8016 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/ets/entryability/EntryAbility.ets b/ArkwebSchemeHandler/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..2969788642fbedf6f36fd9941f76719783ae6f19 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,40 @@ +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 注册三方协议的配置。 + testNapi.registerCustomSchemes(); + // 初始化Web组件内核,该操作会初始化Browser进程以及创建BrowserContext。 + webview.WebviewController.initializeWebEngine(); + // 设置SchemeHandler。 + testNapi.setSchemeHandler(); + } + + onDestroy(): void { + + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } + + onWindowStageDestroy(): void { + + } + + onForeground(): void { + + } + + onBackground(): void { + + } +}; \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkwebSchemeHandler/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e4de99282050bad799ac892eb85ac5449364a51 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,16 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/ets/pages/Index.ets b/ArkwebSchemeHandler/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba2e14ecd149aadd9a5687eb47a1b0f792f3b33c --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,36 @@ +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; +import { resourceManager } from '@kit.LocalizationKit'; + + +@Entry +@Component +struct Index { + mycontroller: webview.WebviewController = new webview.WebviewController("scheme-handler"); + + + build() { + Row() { + Column() { + Button("goback").onClick( event => { + this.mycontroller.backward(); + }) + + + Web({ src: $rawfile("test.html"), controller: this.mycontroller}) + .javaScriptAccess(true) + .width('100%') + .height('100%') + .databaseAccess(true) + .fileAccess(false) + .domStorageAccess(true) + .cacheMode(CacheMode.Default) + .onPageBegin( event => { + testNapi.initResourceManager(getContext().resourceManager); + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/module.json5 b/ArkwebSchemeHandler/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6547f5ccaaad79b157a9539a06b87d8caaea9e1b --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/module.json5 @@ -0,0 +1,57 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ], + "requestPermissions":[ + { + "name" : "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/element/color.json b/ArkwebSchemeHandler/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/element/float.json b/ArkwebSchemeHandler/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/element/string.json b/ArkwebSchemeHandler/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/media/background.png b/ArkwebSchemeHandler/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkwebSchemeHandler/entry/src/main/resources/base/media/background.png differ diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/media/foreground.png b/ArkwebSchemeHandler/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkwebSchemeHandler/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/media/layered_image.json b/ArkwebSchemeHandler/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/media/startIcon.png b/ArkwebSchemeHandler/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkwebSchemeHandler/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/profile/backup_config.json b/ArkwebSchemeHandler/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/base/profile/main_pages.json b/ArkwebSchemeHandler/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkwebSchemeHandler/entry/src/main/resources/dark/element/color.json b/ArkwebSchemeHandler/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/cat.svg b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/cat.svg new file mode 100644 index 0000000000000000000000000000000000000000..e2abac4d22da57f6217cda27e2087d3863bb3fe2 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/cat.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/chunked_post_stream.html b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/chunked_post_stream.html new file mode 100644 index 0000000000000000000000000000000000000000..a1d905f01967aa6be6c024a6dcd19a7b7f15e752 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/chunked_post_stream.html @@ -0,0 +1,28 @@ + + + + + + + + + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/csp_bypassing.html b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/csp_bypassing.html new file mode 100644 index 0000000000000000000000000000000000000000..29880a7e0a63d35e3a4bc2c574e621f43244be3b --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/csp_bypassing.html @@ -0,0 +1,11 @@ + + + + + + +

scheme: custom-csp-bypassing

+

options: ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD

+ + + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/csp_script.js b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/csp_script.js new file mode 100644 index 0000000000000000000000000000000000000000..690e53ae751bde9c8754fccea4c79de618fe88e8 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/csp_script.js @@ -0,0 +1,4 @@ +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'csp_script.js bypass the csp rules'; +body.appendChild(element); \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/isolated.html b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/isolated.html new file mode 100644 index 0000000000000000000000000000000000000000..2afa59bd1af02febe1486f8a1300f1bf8e2ab28f --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/isolated.html @@ -0,0 +1,11 @@ + + + + + +

scheme: custom-isolated

+

options: ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED

+
isolated_script.js 被拦截
+ + + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/isolated_script.js b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/isolated_script.js new file mode 100644 index 0000000000000000000000000000000000000000..055dc32e85df564ff62df1d2612a77a26e337374 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/isolated_script.js @@ -0,0 +1,2 @@ +const element = document.getElementById('isolated_test'); +element.textContent = 'isolated_script.js not blocked'; \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/local.html b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/local.html new file mode 100644 index 0000000000000000000000000000000000000000..0eac2f0841f7dd680c248a5d72cc19f0d6d24327 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/local.html @@ -0,0 +1,11 @@ + + + + + +

scheme: custom-local

+

options: ARKWEB_SCHEME_OPTION_LOCAL

+
local_script.js 被拦截
+ + + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/local_script.js b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/local_script.js new file mode 100644 index 0000000000000000000000000000000000000000..f144ed3e745686edc5f01b797080338f52720c5e --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/local_script.js @@ -0,0 +1,2 @@ +const element = document.getElementById('local_test'); +element.textContent = 'local_script.js not blocked.'; \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/post_data.html b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/post_data.html new file mode 100644 index 0000000000000000000000000000000000000000..129191629914612c30cf49d19c9b8dedcdaf17a7 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/post_data.html @@ -0,0 +1,33 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/service_worker.html b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/service_worker.html new file mode 100644 index 0000000000000000000000000000000000000000..b61ccd83e4c2b652c12917a5687f0aa8f2524d6a --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/service_worker.html @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/sw.js b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/sw.js new file mode 100644 index 0000000000000000000000000000000000000000..6364cc4d75820652afcfe6f5eda799a7570c79c0 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/sw.js @@ -0,0 +1,11 @@ +self.addEventListener('install', event => { + console.log('v1 installing'); + event.waitUntil( + caches.open('static-v1').then(cache => cache.add('/cat.svg')) + ); +}); + + +self.addEventListener('activate', event => { + console.log("v1 now redy to handle fetches."); +}); \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/test.html b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/test.html new file mode 100644 index 0000000000000000000000000000000000000000..95a83e1166ec3f3d2f0aeac7520fc38b66b8624b --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/test.html @@ -0,0 +1,17 @@ + + + + + + + +

网络拦截测试demo

+拦截视频资源请求,读取本地mp4文件
+测试三方协议忽略csp检查,并成功拦截
+测试拦截设置ISOLATED属性的三方协议
+测试拦截设置LOCAL属性的三方协议
+测试拦截service worker触发的请求
+测试读取blob类型http body stream
+测试读取chunked类型http body stream + + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/test.mp4 b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/test.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9b0cc327db31d79a3fee73803deebe0762afe156 Binary files /dev/null and b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/test.mp4 differ diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/video.html b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/video.html new file mode 100644 index 0000000000000000000000000000000000000000..1fe9e79502fb96ba7d1d68d89256b2f531ad5956 --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/video.html @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/ArkwebSchemeHandler/entry/src/main/resources/rawfile/xhr b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/xhr new file mode 100644 index 0000000000000000000000000000000000000000..9e26dfeeb6e641a33dae4961196235bdb965b21b --- /dev/null +++ b/ArkwebSchemeHandler/entry/src/main/resources/rawfile/xhr @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/ArkwebSchemeHandler/hvigor/hvigor-config.json5 b/ArkwebSchemeHandler/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1e473e424320d4e68b16737b289f5c851bb19d36 --- /dev/null +++ b/ArkwebSchemeHandler/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkwebSchemeHandler/hvigorfile.ts b/ArkwebSchemeHandler/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/ArkwebSchemeHandler/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ArkwebSchemeHandler/oh-package.json5 b/ArkwebSchemeHandler/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ac964364609c9e2e4205e46a2b0f2cbccf4e3045 --- /dev/null +++ b/ArkwebSchemeHandler/oh-package.json5 @@ -0,0 +1,8 @@ +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + } +} diff --git a/ArkwebSchemeHandler/screenshots/ISOLATED.png b/ArkwebSchemeHandler/screenshots/ISOLATED.png new file mode 100644 index 0000000000000000000000000000000000000000..10d394603912fa37f1dd3ce0275522f9ca17288c Binary files /dev/null and b/ArkwebSchemeHandler/screenshots/ISOLATED.png differ diff --git a/ArkwebSchemeHandler/screenshots/LOCAL.png b/ArkwebSchemeHandler/screenshots/LOCAL.png new file mode 100644 index 0000000000000000000000000000000000000000..25fae824d4bac60d69fe8a08ee0f7ed98922a3bc Binary files /dev/null and b/ArkwebSchemeHandler/screenshots/LOCAL.png differ diff --git a/ArkwebSchemeHandler/screenshots/blob.png b/ArkwebSchemeHandler/screenshots/blob.png new file mode 100644 index 0000000000000000000000000000000000000000..ac0859746d2abfb5dfd1035f40c6524236bf13db Binary files /dev/null and b/ArkwebSchemeHandler/screenshots/blob.png differ diff --git a/ArkwebSchemeHandler/screenshots/chunked.png b/ArkwebSchemeHandler/screenshots/chunked.png new file mode 100644 index 0000000000000000000000000000000000000000..49d7fe3ddbaa43a6ca2c0669460a7c8d82470623 Binary files /dev/null and b/ArkwebSchemeHandler/screenshots/chunked.png differ diff --git a/ArkwebSchemeHandler/screenshots/csp.png b/ArkwebSchemeHandler/screenshots/csp.png new file mode 100644 index 0000000000000000000000000000000000000000..b6fb15b8f0f2f09392d9c002f514c8327ed03448 Binary files /dev/null and b/ArkwebSchemeHandler/screenshots/csp.png differ diff --git a/ArkwebSchemeHandler/screenshots/home.png b/ArkwebSchemeHandler/screenshots/home.png new file mode 100644 index 0000000000000000000000000000000000000000..4547549ea37b6a939048c312a67bb46ff5e3d082 Binary files /dev/null and b/ArkwebSchemeHandler/screenshots/home.png differ diff --git a/ArkwebSchemeHandler/screenshots/mp4.png b/ArkwebSchemeHandler/screenshots/mp4.png new file mode 100644 index 0000000000000000000000000000000000000000..f3fe7b90f038b140ab2a71e61b60d2119bab4d8b Binary files /dev/null and b/ArkwebSchemeHandler/screenshots/mp4.png differ diff --git a/ArkwebSchemeHandler/screenshots/service_worker.png b/ArkwebSchemeHandler/screenshots/service_worker.png new file mode 100644 index 0000000000000000000000000000000000000000..88d73100decc1b314f63d78680464fa9d297cbea Binary files /dev/null and b/ArkwebSchemeHandler/screenshots/service_worker.png differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..29f81d812f3e768fa89638d1f72920dbfd1413a8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/README.md b/README.md index 210df146ad1ba6d815126a77b8aa18c04a3ff3f1..a1263e2fb31efa25fa0999302597e62bc95f1f23 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,10 @@ # DocsSample_Arkweb -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +## 目录 -#### 软件架构 -软件架构说明 +* [ArkwebSchemeHandler: 拦截Web组件发起的网络请求](ArkwebSchemeHandler) +## 使用说明 -#### 安装教程 - -1. xxxx -2. xxxx -3. xxxx - -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +1. 将独立的应用示例工程导入DevEco Studio进行编译构建及运行调试。 +2. 安装运行后,即可在设备上查看应用示例运行效果,以及进行相关调试。 \ No newline at end of file