Renamed WebPageConfig to WebCommonConfig with more fields. Renamed webPageShow to webShow. Various web improvements including version handling.

This commit is contained in:
yellows8 2019-02-25 19:08:49 -05:00
parent 9f45bb4d7e
commit ec5f1dc17f
2 changed files with 26 additions and 14 deletions

View File

@ -62,7 +62,9 @@ typedef struct {
typedef struct { typedef struct {
WebCommonTLVStorage arg; WebCommonTLVStorage arg;
} WebPageConfig; AppletId appletid;
u32 version;
} WebCommonConfig;
/** /**
* @brief Creates the config for WifiWebAuthApplet. * @brief Creates the config for WifiWebAuthApplet.
@ -83,15 +85,15 @@ Result webWifiShow(WebWifiConfig* config, WebWifiReturnValue *out);
/** /**
* @brief Creates the config for WebApplet. This applet uses an URL whitelist loaded from the user-process host title. * @brief Creates the config for WebApplet. This applet uses an URL whitelist loaded from the user-process host title.
* @param config WebPageConfig object. * @param config WebCommonConfig object.
* @param url Initial URL navigated to by the applet. * @param url Initial URL navigated to by the applet.
*/ */
void webPageCreate(WebPageConfig* config, const char* url); void webPageCreate(WebCommonConfig* config, const char* url);
/** /**
* @brief Launches WebApplet with the specified config and waits for it to exit. * @brief Launches the {web applet} with the specified config and waits for it to exit.
* @param config WebPageConfig object. * @param config WebCommonConfig object.
* @param out Optional output applet reply data, can be NULL. * @param out Optional output applet reply data, can be NULL.
*/ */
Result webPageShow(WebPageConfig* config, WebCommonReturnValue *out); Result webShow(WebCommonConfig* config, WebCommonReturnValue *out);

View File

@ -5,6 +5,7 @@
#include "services/applet.h" #include "services/applet.h"
#include "applets/libapplet.h" #include "applets/libapplet.h"
#include "applets/web.h" #include "applets/web.h"
#include "runtime/hosversion.h"
static Result _webLaunch(AppletHolder* holder, AppletId id, u32 version, void* arg, size_t arg_size) { static Result _webLaunch(AppletHolder* holder, AppletId id, u32 version, void* arg, size_t arg_size) {
Result rc=0; Result rc=0;
@ -55,11 +56,20 @@ static Result _webShow(AppletId id, u32 version, void* arg, size_t arg_size, voi
return rc; return rc;
} }
static void _webArgInitialize(WebCommonTLVStorage *storage, WebShimKind shimKind) { static void _webArgInitialize(WebCommonConfig* config, AppletId appletid, WebShimKind shimKind) {
WebArgHeader *hdr = (WebArgHeader*)storage->data; memset(config, 0, sizeof(*config));
memset(storage, 0, sizeof(*storage)); WebArgHeader *hdr = (WebArgHeader*)config->arg.data;
hdr->shimKind = shimKind; hdr->shimKind = shimKind;
config->appletid = appletid;
u32 hosver = hosversionGet();
if (hosver >= MAKEHOSVERSION(5,0,0))
config->version = 0x50000;
else if (hosver >= MAKEHOSVERSION(3,0,0))
config->version = 0x30000;
else
config->version = 0x20000; // [1.0.0+] version
} }
static void _webTLVWrite(WebCommonTLVStorage *storage, u16 type, const void* argdata, u16 argdata_size) { static void _webTLVWrite(WebCommonTLVStorage *storage, u16 type, const void* argdata, u16 argdata_size) {
@ -121,21 +131,21 @@ Result webWifiShow(WebWifiConfig* config, WebWifiReturnValue *out) {
return _webShow(AppletId_wifiWebAuth, 0, &config->arg, sizeof(config->arg), out, sizeof(*out)); return _webShow(AppletId_wifiWebAuth, 0, &config->arg, sizeof(config->arg), out, sizeof(*out));
} }
void webPageCreate(WebPageConfig* config, const char* url) { void webPageCreate(WebCommonConfig* config, const char* url) {
char tmpurl[0xc00]; char tmpurl[0xc00];
_webArgInitialize(&config->arg, WebShimKind_Web); _webArgInitialize(config, AppletId_web, WebShimKind_Web);
u8 tmpval=1; u8 tmpval=1;
_webTLVWrite(&config->arg, 0xD, &tmpval, sizeof(tmpval)); _webTLVWrite(&config->arg, 0xD, &tmpval, sizeof(tmpval));
_webTLVWrite(&config->arg, 0x12, &tmpval, sizeof(tmpval)); // Removed from user-process init with [3.0.0+]. if (config->version < 0x30000) _webTLVWrite(&config->arg, 0x12, &tmpval, sizeof(tmpval)); // Removed from user-process init with [3.0.0+].
memset(tmpurl, 0, sizeof(tmpurl)); memset(tmpurl, 0, sizeof(tmpurl));
strncpy(tmpurl, url, sizeof(tmpurl)-1); strncpy(tmpurl, url, sizeof(tmpurl)-1);
_webTLVWrite(&config->arg, 0x1, tmpurl, sizeof(tmpurl)); _webTLVWrite(&config->arg, 0x1, tmpurl, sizeof(tmpurl));
} }
Result webPageShow(WebPageConfig* config, WebCommonReturnValue *out) { Result webShow(WebCommonConfig* config, WebCommonReturnValue *out) {
return _webShow(AppletId_web, 0x20000, &config->arg, sizeof(config->arg), out, sizeof(*out)); return _webShow(config->appletid, config->version, &config->arg, sizeof(config->arg), out, sizeof(*out));
} }