add js loader manager
This commit is contained in:
parent
23522c6416
commit
41ebe1d64a
@ -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 \
|
||||
|
15
doric-Qt/example/doric/loader/DoricInterfaceLoader.h
Normal file
15
doric-Qt/example/doric/loader/DoricInterfaceLoader.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef DORICINTERFACELOADER_H
|
||||
#define DORICINTERFACELOADER_H
|
||||
|
||||
#include "async/DoricAsyncResult.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
class DoricInterfaceLoader {
|
||||
public:
|
||||
virtual bool filter(QString source) = 0;
|
||||
|
||||
virtual std::shared_ptr<DoricAsyncResult> request(QString source) = 0;
|
||||
};
|
||||
|
||||
#endif // DORICINTERFACELOADER_H
|
29
doric-Qt/example/doric/loader/DoricJSLoaderManager.cpp
Normal file
29
doric-Qt/example/doric/loader/DoricJSLoaderManager.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "DoricJSLoaderManager.h"
|
||||
|
||||
DoricJSLoaderManager::DoricJSLoaderManager() {
|
||||
qDebug() << "DoricJSLoaderManager constructor";
|
||||
}
|
||||
|
||||
void DoricJSLoaderManager::addJSLoader(DoricInterfaceLoader *jsLoader) {
|
||||
jsLoaders.insert(jsLoader);
|
||||
}
|
||||
|
||||
QSet<DoricInterfaceLoader *> *DoricJSLoaderManager::getJSLoaders() {
|
||||
return &jsLoaders;
|
||||
}
|
||||
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
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<DoricAsyncResult> asyncResult =
|
||||
std::make_shared<DoricAsyncResult>();
|
||||
return asyncResult;
|
||||
}
|
33
doric-Qt/example/doric/loader/DoricJSLoaderManager.h
Normal file
33
doric-Qt/example/doric/loader/DoricJSLoaderManager.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef DORICJSLOADERMANAGER_H
|
||||
#define DORICJSLOADERMANAGER_H
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#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<DoricInterfaceLoader *> jsLoaders;
|
||||
|
||||
public:
|
||||
void addJSLoader(DoricInterfaceLoader *jsLoader);
|
||||
|
||||
QSet<DoricInterfaceLoader *> *getJSLoaders();
|
||||
|
||||
std::shared_ptr<DoricAsyncResult> request(QString source);
|
||||
};
|
||||
|
||||
#endif // DORICJSLOADERMANAGER_H
|
Reference in New Issue
Block a user