From 41ebe1d64ade0cf18fb1b30a62be0a49d8811c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 9 Jun 2021 18:06:56 +0800 Subject: [PATCH] add js loader manager --- doric-Qt/example/doric/doric.pro | 3 ++ .../doric/loader/DoricInterfaceLoader.h | 15 +++++++++ .../doric/loader/DoricJSLoaderManager.cpp | 29 ++++++++++++++++ .../doric/loader/DoricJSLoaderManager.h | 33 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 doric-Qt/example/doric/loader/DoricInterfaceLoader.h create mode 100644 doric-Qt/example/doric/loader/DoricJSLoaderManager.cpp create mode 100644 doric-Qt/example/doric/loader/DoricJSLoaderManager.h diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro index 371bcf9a..e5571d0c 100644 --- a/doric-Qt/example/doric/doric.pro +++ b/doric-Qt/example/doric/doric.pro @@ -36,6 +36,7 @@ SOURCES += \ engine/native/NativeExecutor.cpp \ engine/v8/JSValueHelper.cpp \ engine/v8/V8Executor.cpp \ + loader/DoricJSLoaderManager.cpp \ plugin/DoricModalPlugin.cpp \ plugin/DoricNavigatorPlugin.cpp \ plugin/DoricNetworkPlugin.cpp \ @@ -124,6 +125,8 @@ HEADERS += \ engine/native/NativeExecutor.h \ engine/v8/JSValueHelper.h \ engine/v8/V8Executor.h \ + loader/DoricInterfaceLoader.h \ + loader/DoricJSLoaderManager.h \ plugin/DoricModalPlugin.h \ plugin/DoricNativePlugin.h \ plugin/DoricNavigatorPlugin.h \ diff --git a/doric-Qt/example/doric/loader/DoricInterfaceLoader.h b/doric-Qt/example/doric/loader/DoricInterfaceLoader.h new file mode 100644 index 00000000..d48c1dde --- /dev/null +++ b/doric-Qt/example/doric/loader/DoricInterfaceLoader.h @@ -0,0 +1,15 @@ +#ifndef DORICINTERFACELOADER_H +#define DORICINTERFACELOADER_H + +#include "async/DoricAsyncResult.h" + +#include + +class DoricInterfaceLoader { +public: + virtual bool filter(QString source) = 0; + + virtual std::shared_ptr request(QString source) = 0; +}; + +#endif // DORICINTERFACELOADER_H diff --git a/doric-Qt/example/doric/loader/DoricJSLoaderManager.cpp b/doric-Qt/example/doric/loader/DoricJSLoaderManager.cpp new file mode 100644 index 00000000..c4c4ebb4 --- /dev/null +++ b/doric-Qt/example/doric/loader/DoricJSLoaderManager.cpp @@ -0,0 +1,29 @@ +#include "DoricJSLoaderManager.h" + +DoricJSLoaderManager::DoricJSLoaderManager() { + qDebug() << "DoricJSLoaderManager constructor"; +} + +void DoricJSLoaderManager::addJSLoader(DoricInterfaceLoader *jsLoader) { + jsLoaders.insert(jsLoader); +} + +QSet *DoricJSLoaderManager::getJSLoaders() { + return &jsLoaders; +} + +std::shared_ptr +DoricJSLoaderManager::request(QString source) { + if (!source.isEmpty()) { + if (source.startsWith("_internal_://")) { + } + foreach (DoricInterfaceLoader *jsLoader, jsLoaders) { + if (jsLoader->filter(source)) { + return jsLoader->request(source); + } + } + } + std::shared_ptr asyncResult = + std::make_shared(); + return asyncResult; +} diff --git a/doric-Qt/example/doric/loader/DoricJSLoaderManager.h b/doric-Qt/example/doric/loader/DoricJSLoaderManager.h new file mode 100644 index 00000000..2d6e0823 --- /dev/null +++ b/doric-Qt/example/doric/loader/DoricJSLoaderManager.h @@ -0,0 +1,33 @@ +#ifndef DORICJSLOADERMANAGER_H +#define DORICJSLOADERMANAGER_H + +#include + +#include "DoricInterfaceLoader.h" + +class DoricJSLoaderManager { +private: + static DoricJSLoaderManager *local_instance; + + DoricJSLoaderManager(); + + ~DoricJSLoaderManager() { qDebug() << "DoricJSLoaderManager destructor"; } + +public: + static DoricJSLoaderManager *getInstance() { + static DoricJSLoaderManager instance; + return &instance; + } + +private: + QSet jsLoaders; + +public: + void addJSLoader(DoricInterfaceLoader *jsLoader); + + QSet *getJSLoaders(); + + std::shared_ptr request(QString source); +}; + +#endif // DORICJSLOADERMANAGER_H