@cordova-ohos/cordova-plugin-themeablebrowser 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +204 -0
- package/OAT.xml +79 -0
- package/README.md +105 -0
- package/package.json +29 -0
- package/plugin.xml +51 -0
- package/src/main/cpp/inappbrowser/ThemeableBrowser.cpp +444 -0
- package/src/main/cpp/inappbrowser/ThemeableBrowser.h +46 -0
- package/src/main/ets/components/InAppBrowser/BrowserAction.ets +383 -0
- package/www/themeablebrowser.js +119 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include "ThemeableBrowser.h"
|
|
18
|
+
#include "CordovaArgs.h"
|
|
19
|
+
#include "CordovaViewController.h"
|
|
20
|
+
#include "HttpUrl.h"
|
|
21
|
+
#include "cJSON.h"
|
|
22
|
+
#include "FileCache.h"
|
|
23
|
+
|
|
24
|
+
REGISTER_PLUGIN_CLASS(ThemeableBrowser)
|
|
25
|
+
bool ThemeableBrowser::execute(const std::string& action, cJSON* args, CallbackContext cbc)
|
|
26
|
+
{
|
|
27
|
+
if (action == "onArKTsResult") {
|
|
28
|
+
return onArKTsResult(args);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (action == "open") {
|
|
32
|
+
std::string strWebTag = cbc.getWebTag();
|
|
33
|
+
m_mapWebTagToChanel[strWebTag] = cbc;
|
|
34
|
+
CordovaArgs cordovaArgs(args);
|
|
35
|
+
int nArraySize = cordovaArgs.getSize();
|
|
36
|
+
if (nArraySize > 0)
|
|
37
|
+
m_strUrl = cordovaArgs.getString(0);
|
|
38
|
+
if (nArraySize > 1)
|
|
39
|
+
m_strType = cordovaArgs.optString(1);
|
|
40
|
+
|
|
41
|
+
if (nArraySize > 2)
|
|
42
|
+
m_strArg = cordovaArgs.optString(2);
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
cJSON* pTemp = cJSON_CreateObject();
|
|
46
|
+
cJSON_AddStringToObject(pTemp, "url", m_strUrl.c_str());
|
|
47
|
+
cJSON_AddStringToObject(pTemp, "title", m_strTitle.c_str());
|
|
48
|
+
cJSON_AddStringToObject(pTemp, "target", m_strType.c_str());
|
|
49
|
+
cJSON_AddStringToObject(pTemp, "args", m_strArg.c_str());
|
|
50
|
+
|
|
51
|
+
char* pStr = cJSON_Print(pTemp);
|
|
52
|
+
std::string strArgs = pStr;
|
|
53
|
+
std::string result = showWebPage(strArgs, cbc);
|
|
54
|
+
PluginResult pluginResult(PluginResult::Status::OK, result);
|
|
55
|
+
pluginResult.setKeepCallback(true);
|
|
56
|
+
cbc.sendPluginResult(pluginResult);
|
|
57
|
+
free(pStr);
|
|
58
|
+
cJSON_Delete(pTemp);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (action == "show") {
|
|
62
|
+
if (cJSON_GetArraySize(args) > 0) {
|
|
63
|
+
cJSON* pJson = cJSON_GetArrayItem(args, 0);
|
|
64
|
+
if (pJson->type == cJSON_String) {
|
|
65
|
+
m_strTitle = pJson->valuestring;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
cJSON* pTemp = cJSON_CreateObject();
|
|
70
|
+
cJSON_AddStringToObject(pTemp, "url", m_strUrl.c_str());
|
|
71
|
+
cJSON_AddStringToObject(pTemp, "title", m_strTitle.c_str());
|
|
72
|
+
cJSON_AddStringToObject(pTemp, "target", m_strType.c_str());
|
|
73
|
+
cJSON_AddStringToObject(pTemp, "args", m_strArg.c_str());
|
|
74
|
+
|
|
75
|
+
char* pStr = cJSON_Print(pTemp);
|
|
76
|
+
std::string strArgs = pStr;
|
|
77
|
+
std::string result = showWebPage(strArgs, cbc);
|
|
78
|
+
PluginResult pluginResult(PluginResult::Status::OK, result);
|
|
79
|
+
pluginResult.setKeepCallback(true);
|
|
80
|
+
cbc.sendPluginResult(pluginResult);
|
|
81
|
+
free(pStr);
|
|
82
|
+
cJSON_Delete(pTemp);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (action == "close" || action == "hide") {
|
|
86
|
+
closeDialog(cbc);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (action == "loadAfterBeforeload") {
|
|
90
|
+
CordovaArgs cordovaArgs(args);
|
|
91
|
+
int nArraySize = cordovaArgs.getSize();
|
|
92
|
+
if (nArraySize > 0) {
|
|
93
|
+
m_strUrl = cordovaArgs.getString(0);
|
|
94
|
+
}
|
|
95
|
+
cJSON* pTemp = cJSON_CreateObject();
|
|
96
|
+
cJSON_AddStringToObject(pTemp, "url", m_strUrl.c_str());
|
|
97
|
+
cJSON_AddStringToObject(pTemp, "title", m_strTitle.c_str());
|
|
98
|
+
cJSON_AddStringToObject(pTemp, "target", m_strType.c_str());
|
|
99
|
+
cJSON_AddStringToObject(pTemp, "args", m_strArg.c_str());
|
|
100
|
+
|
|
101
|
+
char* pStr = cJSON_Print(pTemp);
|
|
102
|
+
std::string strArgs = pStr;
|
|
103
|
+
std::string result = showWebPage(strArgs, cbc);
|
|
104
|
+
PluginResult pluginResult(PluginResult::Status::OK, result);
|
|
105
|
+
pluginResult.setKeepCallback(true);
|
|
106
|
+
cbc.sendPluginResult(pluginResult);
|
|
107
|
+
free(pStr);
|
|
108
|
+
cJSON_Delete(pTemp);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (action == "injectScriptCode") {
|
|
112
|
+
std::string strCbId = cbc.getCallbackId();
|
|
113
|
+
m_mapCallBackIdToCbc[strCbId] = cbc;
|
|
114
|
+
|
|
115
|
+
CordovaArgs cordovaArgs(args);
|
|
116
|
+
int nArraySize = cordovaArgs.getSize();
|
|
117
|
+
std::string strCode = "";
|
|
118
|
+
bool isCallBack = false;
|
|
119
|
+
if (nArraySize > 0) {
|
|
120
|
+
strCode = cordovaArgs.getString(0);
|
|
121
|
+
}
|
|
122
|
+
if (nArraySize > 1) {
|
|
123
|
+
isCallBack = cordovaArgs.getBoolean(1);
|
|
124
|
+
}
|
|
125
|
+
if (strCode.empty()) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
cJSON* pTemp = cJSON_CreateObject();
|
|
129
|
+
cJSON_AddStringToObject(pTemp, "code", strCode.c_str());
|
|
130
|
+
cJSON_AddStringToObject(pTemp, "callbackId", strCbId.c_str());
|
|
131
|
+
if (isCallBack) {
|
|
132
|
+
cJSON_AddTrueToObject(pTemp, "cb");
|
|
133
|
+
} else {
|
|
134
|
+
cJSON_AddFalseToObject(pTemp, "cb");
|
|
135
|
+
}
|
|
136
|
+
char* pStr = cJSON_Print(pTemp);
|
|
137
|
+
std::string strArgs = pStr;
|
|
138
|
+
injectScriptCode(strArgs, cbc);
|
|
139
|
+
free(pStr);
|
|
140
|
+
cJSON_Delete(pTemp);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (action == "injectStyleCode") {
|
|
144
|
+
std::string strCbId = cbc.getCallbackId();
|
|
145
|
+
m_mapCallBackIdToCbc[strCbId] = cbc;
|
|
146
|
+
|
|
147
|
+
CordovaArgs cordovaArgs(args);
|
|
148
|
+
int nArraySize = cordovaArgs.getSize();
|
|
149
|
+
std::string strCode = "";
|
|
150
|
+
bool isCallBack = false;
|
|
151
|
+
if (nArraySize > 0) {
|
|
152
|
+
strCode = cordovaArgs.getString(0);
|
|
153
|
+
}
|
|
154
|
+
if (nArraySize > 1) {
|
|
155
|
+
isCallBack = cordovaArgs.getBoolean(1);
|
|
156
|
+
}
|
|
157
|
+
if (strCode.empty()) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
cJSON* pTemp = cJSON_CreateObject();
|
|
161
|
+
cJSON_AddStringToObject(pTemp, "code", strCode.c_str());
|
|
162
|
+
cJSON_AddStringToObject(pTemp, "callbackId", strCbId.c_str());
|
|
163
|
+
if (isCallBack) {
|
|
164
|
+
cJSON_AddTrueToObject(pTemp, "cb");
|
|
165
|
+
} else {
|
|
166
|
+
cJSON_AddFalseToObject(pTemp, "cb");
|
|
167
|
+
}
|
|
168
|
+
char* pStr = cJSON_Print(pTemp);
|
|
169
|
+
std::string strArgs = pStr;
|
|
170
|
+
injectStyleCode(strArgs, cbc);
|
|
171
|
+
free((void*)pStr);
|
|
172
|
+
cJSON_Delete(pTemp);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (action == "injectScriptFile") {
|
|
176
|
+
std::string strCbId = cbc.getCallbackId();
|
|
177
|
+
m_mapCallBackIdToCbc[strCbId] = cbc;
|
|
178
|
+
|
|
179
|
+
CordovaArgs cordovaArgs(args);
|
|
180
|
+
int nArraySize = cordovaArgs.getSize();
|
|
181
|
+
std::string strCode = "";
|
|
182
|
+
bool isCallBack = false;
|
|
183
|
+
if (nArraySize > 0) {
|
|
184
|
+
strCode = cordovaArgs.getString(0);
|
|
185
|
+
}
|
|
186
|
+
if (nArraySize > 1) {
|
|
187
|
+
isCallBack = cordovaArgs.getBoolean(1);
|
|
188
|
+
}
|
|
189
|
+
if (strCode.empty()) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
cJSON* pTemp = cJSON_CreateObject();
|
|
193
|
+
cJSON_AddStringToObject(pTemp, "file", strCode.c_str());
|
|
194
|
+
cJSON_AddStringToObject(pTemp, "callbackId", strCbId.c_str());
|
|
195
|
+
if (isCallBack) {
|
|
196
|
+
cJSON_AddTrueToObject(pTemp, "cb");
|
|
197
|
+
} else {
|
|
198
|
+
cJSON_AddFalseToObject(pTemp, "cb");
|
|
199
|
+
}
|
|
200
|
+
char* pStr = cJSON_Print(pTemp);
|
|
201
|
+
std::string strArgs = pStr;
|
|
202
|
+
injectScriptFile(strArgs, cbc);
|
|
203
|
+
free((void*)pStr);
|
|
204
|
+
cJSON_Delete(pTemp);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (action == "injectStyleFile") {
|
|
208
|
+
std::string strCbId = cbc.getCallbackId();
|
|
209
|
+
m_mapCallBackIdToCbc[strCbId] = cbc;
|
|
210
|
+
|
|
211
|
+
CordovaArgs cordovaArgs(args);
|
|
212
|
+
int nArraySize = cordovaArgs.getSize();
|
|
213
|
+
std::string strCode = "";
|
|
214
|
+
bool isCallBack = false;
|
|
215
|
+
if (nArraySize > 0) {
|
|
216
|
+
strCode = cordovaArgs.getString(0);
|
|
217
|
+
}
|
|
218
|
+
if (nArraySize > 1) {
|
|
219
|
+
isCallBack = cordovaArgs.getBoolean(1);
|
|
220
|
+
}
|
|
221
|
+
if (strCode.empty()) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
cJSON* pTemp = cJSON_CreateObject();
|
|
225
|
+
cJSON_AddStringToObject(pTemp, "file", strCode.c_str());
|
|
226
|
+
cJSON_AddStringToObject(pTemp, "callbackId", strCbId.c_str());
|
|
227
|
+
if (isCallBack) {
|
|
228
|
+
cJSON_AddTrueToObject(pTemp, "cb");
|
|
229
|
+
} else {
|
|
230
|
+
cJSON_AddFalseToObject(pTemp, "cb");
|
|
231
|
+
}
|
|
232
|
+
char* pStr = cJSON_Print(pTemp);
|
|
233
|
+
std::string strArgs = pStr;
|
|
234
|
+
injectStyleFile(strArgs, cbc);
|
|
235
|
+
free((void*)pStr);
|
|
236
|
+
cJSON_Delete(pTemp);
|
|
237
|
+
}
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
std::string ThemeableBrowser::showWebPage(const std::string strArgs, CallbackContext cbc)
|
|
242
|
+
{
|
|
243
|
+
executeArkTs("./InAppBrowser/BrowserAction/openInAppBrowser", 0, strArgs.c_str(), "ThemeableBrowser", cbc);
|
|
244
|
+
return "OK";
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
void ThemeableBrowser::closeDialog(CallbackContext cbc)
|
|
248
|
+
{
|
|
249
|
+
executeArkTs("./InAppBrowser/BrowserAction/closeInAppBrowser", 0, "close", "ThemeableBrowser", cbc);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
void ThemeableBrowser::injectScriptCode(const std::string strArgs, CallbackContext cbc)
|
|
254
|
+
{
|
|
255
|
+
executeArkTs("./InAppBrowser/BrowserAction/injectScriptCodeInAppBrowser", 0, strArgs.c_str(), "ThemeableBrowser", cbc);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
void ThemeableBrowser::injectScriptFile(const std::string strArgs, CallbackContext cbc)
|
|
260
|
+
{
|
|
261
|
+
executeArkTs("./InAppBrowser/BrowserAction/injectScriptFileInAppBrowser", 0, strArgs.c_str(), "ThemeableBrowser", cbc);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
void ThemeableBrowser::injectStyleCode(const std::string strArgs, CallbackContext cbc)
|
|
266
|
+
{
|
|
267
|
+
executeArkTs("./InAppBrowser/BrowserAction/injectStyleCodeInAppBrowser", 0, strArgs.c_str(), "ThemeableBrowser", cbc);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
void ThemeableBrowser::injectStyleFile(const std::string strArgs, CallbackContext cbc)
|
|
272
|
+
{
|
|
273
|
+
executeArkTs("./InAppBrowser/BrowserAction/injectStyleFileInAppBrowser", 0, strArgs.c_str(), "ThemeableBrowser", cbc);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
bool ThemeableBrowser::onArKTsResult(cJSON* args)
|
|
278
|
+
{
|
|
279
|
+
cJSON* content = cJSON_GetObjectItem(args, "content");
|
|
280
|
+
std::string action = "";
|
|
281
|
+
if (content != NULL) {
|
|
282
|
+
action = content->valuestring;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (action == "beforeload") {
|
|
286
|
+
cJSON* json = cJSON_GetObjectItem(args, "result");
|
|
287
|
+
std::string webTag = "";
|
|
288
|
+
std::string strUrl;
|
|
289
|
+
if (json != NULL && json->type == cJSON_Array) {
|
|
290
|
+
int count = cJSON_GetArraySize(json);
|
|
291
|
+
if (count > 0) {
|
|
292
|
+
webTag = cJSON_GetArrayItem(json, 0)->valuestring;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (count > 1) {
|
|
296
|
+
strUrl = cJSON_GetArrayItem(json, 1)->valuestring;
|
|
297
|
+
}
|
|
298
|
+
PluginResult pluginResult(PluginResult::Status::OK, strUrl);
|
|
299
|
+
pluginResult.setKeepCallback(true);
|
|
300
|
+
if (m_mapWebTagToChanel.find(webTag) != m_mapWebTagToChanel.end()) {
|
|
301
|
+
CallbackContext cbc = m_mapWebTagToChanel[webTag];
|
|
302
|
+
cbc.sendPluginResult(pluginResult);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} else if (action == "customscheme") {
|
|
306
|
+
cJSON* json = cJSON_GetObjectItem(args, "result");
|
|
307
|
+
std::string webTag = "";
|
|
308
|
+
std::string strUrl;
|
|
309
|
+
if (json != NULL && json->type == cJSON_Array) {
|
|
310
|
+
int count = cJSON_GetArraySize(json);
|
|
311
|
+
if (count > 0) {
|
|
312
|
+
webTag = cJSON_GetArrayItem(json, 0)->valuestring;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (count > 1) {
|
|
316
|
+
strUrl = cJSON_GetArrayItem(json, 1)->valuestring;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
cJSON * pObj = cJSON_CreateObject();
|
|
320
|
+
cJSON_AddStringToObject(pObj, "type", action.c_str());
|
|
321
|
+
cJSON_AddStringToObject(pObj, "url", strUrl.c_str());
|
|
322
|
+
PluginResult pluginResult(PluginResult::Status::OK, pObj);
|
|
323
|
+
pluginResult.setKeepCallback(true);
|
|
324
|
+
if (m_mapWebTagToChanel.find(webTag) != m_mapWebTagToChanel.end()) {
|
|
325
|
+
CallbackContext cbc = m_mapWebTagToChanel[webTag];
|
|
326
|
+
cbc.sendPluginResult(pluginResult);
|
|
327
|
+
}
|
|
328
|
+
cJSON_Delete(pObj);
|
|
329
|
+
}
|
|
330
|
+
} else if (action == "download") {
|
|
331
|
+
cJSON* json = cJSON_GetObjectItem(args, "result");
|
|
332
|
+
std::string webTag = "";
|
|
333
|
+
std::string strUrl;
|
|
334
|
+
std::string strUserAgent;
|
|
335
|
+
std::string strContentDisposition;
|
|
336
|
+
std::string strMimetype;
|
|
337
|
+
std::string strContentLength;
|
|
338
|
+
long lngContentLength = 0;
|
|
339
|
+
if (json != NULL && json->type == cJSON_Array) {
|
|
340
|
+
int count = cJSON_GetArraySize(json);
|
|
341
|
+
if (count > 0) {
|
|
342
|
+
webTag = cJSON_GetArrayItem(json, 0)->valuestring;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (count > 1) {
|
|
346
|
+
strUrl = cJSON_GetArrayItem(json, 1)->valuestring;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (count > 2) {
|
|
350
|
+
strUserAgent = cJSON_GetArrayItem(json, 2)->valuestring;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (count > 3) {
|
|
354
|
+
strContentDisposition = cJSON_GetArrayItem(json, 3)->valuestring;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (count > 4) {
|
|
358
|
+
strMimetype = cJSON_GetArrayItem(json, 4)->valuestring;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (count > 5) {
|
|
362
|
+
strContentLength = cJSON_GetArrayItem(json, 5)->valuestring;
|
|
363
|
+
lngContentLength = atoi(strContentLength.c_str());
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
cJSON * pObj = cJSON_CreateObject();
|
|
367
|
+
cJSON_AddStringToObject(pObj, "type", action.c_str());
|
|
368
|
+
cJSON_AddStringToObject(pObj, "url", strUrl.c_str());
|
|
369
|
+
cJSON_AddStringToObject(pObj, "userAgent", strUserAgent.c_str());
|
|
370
|
+
cJSON_AddStringToObject(pObj, "contentDisposition", strContentDisposition.c_str());
|
|
371
|
+
cJSON_AddStringToObject(pObj, "mimetype", strMimetype.c_str());
|
|
372
|
+
cJSON_AddNumberToObject(pObj, "contentLength", lngContentLength);
|
|
373
|
+
PluginResult pluginResult(PluginResult::Status::OK, pObj);
|
|
374
|
+
pluginResult.setKeepCallback(true);
|
|
375
|
+
|
|
376
|
+
if (m_mapWebTagToChanel.find(webTag) != m_mapWebTagToChanel.end()) {
|
|
377
|
+
CallbackContext cbc = m_mapWebTagToChanel[webTag];
|
|
378
|
+
cbc.sendPluginResult(pluginResult);
|
|
379
|
+
}
|
|
380
|
+
cJSON_Delete(pObj);
|
|
381
|
+
}
|
|
382
|
+
} else if (action == "callback") {
|
|
383
|
+
cJSON* json = cJSON_GetObjectItem(args, "result");
|
|
384
|
+
std::string callbackId = "";
|
|
385
|
+
std::string message = "";
|
|
386
|
+
if (json != NULL && json->type == cJSON_Array) {
|
|
387
|
+
int count = cJSON_GetArraySize(json);
|
|
388
|
+
if (count > 0) {
|
|
389
|
+
callbackId = cJSON_GetArrayItem(json, 0)->valuestring;
|
|
390
|
+
}
|
|
391
|
+
if (count > 1) {
|
|
392
|
+
message = cJSON_GetArrayItem(json, 1)->valuestring;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (m_mapCallBackIdToCbc.find(callbackId) != m_mapCallBackIdToCbc.end()) {
|
|
396
|
+
CallbackContext cbc = m_mapCallBackIdToCbc[callbackId];
|
|
397
|
+
if (message.empty()) {
|
|
398
|
+
PluginResult pluginResult(PluginResult::Status::OK);
|
|
399
|
+
pluginResult.setKeepCallback(true);
|
|
400
|
+
cbc.sendPluginResult(pluginResult);
|
|
401
|
+
} else {
|
|
402
|
+
PluginResult pluginResult(PluginResult::Status::OK, message);
|
|
403
|
+
pluginResult.setKeepCallback(true);
|
|
404
|
+
cbc.sendPluginResult(pluginResult);
|
|
405
|
+
}
|
|
406
|
+
m_mapCallBackIdToCbc.erase(callbackId);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
} else {
|
|
410
|
+
cJSON* json = cJSON_GetObjectItem(args, "result");
|
|
411
|
+
std::string webTag = "";
|
|
412
|
+
std::string data = "";
|
|
413
|
+
if (json != NULL && json->type == cJSON_Array) {
|
|
414
|
+
int count = cJSON_GetArraySize(json);
|
|
415
|
+
if (count > 0) {
|
|
416
|
+
webTag = cJSON_GetArrayItem(json, 0)->valuestring;
|
|
417
|
+
}
|
|
418
|
+
if (count > 1) {
|
|
419
|
+
data = cJSON_GetArrayItem(json, 1)->valuestring;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (m_mapWebTagToChanel.find(webTag) == m_mapWebTagToChanel.end()) {
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
cJSON * pObj = cJSON_CreateObject();
|
|
428
|
+
cJSON_AddStringToObject(pObj, "type", action.c_str());
|
|
429
|
+
if (!data.empty()) {
|
|
430
|
+
cJSON * pData = cJSON_Parse(data.c_str());
|
|
431
|
+
if (pData != NULL) {
|
|
432
|
+
cJSON_AddItemToObject(pObj, "data", pData);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
PluginResult pluginResult(PluginResult::Status::OK, pObj);
|
|
436
|
+
pluginResult.setKeepCallback(true);
|
|
437
|
+
if (m_mapWebTagToChanel.find(webTag) != m_mapWebTagToChanel.end()) {
|
|
438
|
+
CallbackContext cbc = m_mapWebTagToChanel[webTag];
|
|
439
|
+
cbc.sendPluginResult(pluginResult);
|
|
440
|
+
}
|
|
441
|
+
cJSON_Delete(pObj);
|
|
442
|
+
}
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
#ifndef MYAPPLICATION_THEMEABLEBROWSER_H
|
|
17
|
+
#define MYAPPLICATION_THEMEABLEBROWSER_H
|
|
18
|
+
|
|
19
|
+
#include "CordovaPlugin.h"
|
|
20
|
+
class ThemeableBrowser : public CordovaPlugin {
|
|
21
|
+
// 存在多个webview打开不同的浏览器
|
|
22
|
+
std::map<std::string, CallbackContext> m_mapWebTagToChanel; // 针对于webview的
|
|
23
|
+
std::map<std::string, CallbackContext> m_mapCallBackIdToCbc; // 针对于每次调用js的
|
|
24
|
+
std::string m_strUrl;
|
|
25
|
+
std::string m_strType;
|
|
26
|
+
std::string m_strArg;
|
|
27
|
+
std::string m_strTitle;
|
|
28
|
+
public:
|
|
29
|
+
ThemeableBrowser()
|
|
30
|
+
{
|
|
31
|
+
m_strType = "_blank";
|
|
32
|
+
}
|
|
33
|
+
~ThemeableBrowser()
|
|
34
|
+
{
|
|
35
|
+
}
|
|
36
|
+
bool execute(const std::string& action, cJSON* args, CallbackContext cbc) override;
|
|
37
|
+
std::string showWebPage(const std::string strArgs, CallbackContext cbc);
|
|
38
|
+
void injectScriptCode(const std::string strArgs, CallbackContext cbc);
|
|
39
|
+
void injectScriptFile(const std::string strArgs, CallbackContext cbc);
|
|
40
|
+
void injectStyleCode(const std::string strArgs, CallbackContext cbc);
|
|
41
|
+
void injectStyleFile(const std::string strArgs, CallbackContext cbc);
|
|
42
|
+
void closeDialog(CallbackContext cbc);
|
|
43
|
+
bool onArKTsResult(cJSON* args);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
#endif //MYAPPLICATION_THEMEABLEBROWSER_H
|