2018-12-24 22:21:12 +01:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-01-17 17:25:34 +01:00
|
|
|
#include <array>
|
|
|
|
#include <cstring>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_funcs.h"
|
2018-12-24 22:21:12 +01:00
|
|
|
#include "common/common_paths.h"
|
2019-01-17 17:25:34 +01:00
|
|
|
#include "common/file_util.h"
|
2018-12-24 22:21:12 +01:00
|
|
|
#include "common/hex_util.h"
|
2019-01-17 17:25:34 +01:00
|
|
|
#include "common/logging/log.h"
|
2018-12-24 22:21:12 +01:00
|
|
|
#include "common/string_util.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/file_sys/content_archive.h"
|
|
|
|
#include "core/file_sys/mode.h"
|
|
|
|
#include "core/file_sys/nca_metadata.h"
|
|
|
|
#include "core/file_sys/registered_cache.h"
|
|
|
|
#include "core/file_sys/romfs.h"
|
2019-06-05 18:16:02 +02:00
|
|
|
#include "core/file_sys/system_archive/system_archive.h"
|
2018-12-24 22:21:12 +01:00
|
|
|
#include "core/file_sys/vfs_types.h"
|
2019-06-05 18:16:02 +02:00
|
|
|
#include "core/frontend/applets/general_frontend.h"
|
2018-12-24 22:21:12 +01:00
|
|
|
#include "core/frontend/applets/web_browser.h"
|
|
|
|
#include "core/hle/kernel/process.h"
|
|
|
|
#include "core/hle/service/am/applets/web_browser.h"
|
|
|
|
#include "core/hle/service/filesystem/filesystem.h"
|
|
|
|
#include "core/loader/loader.h"
|
|
|
|
|
|
|
|
namespace Service::AM::Applets {
|
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
enum class WebArgTLVType : u16 {
|
|
|
|
InitialURL = 0x1,
|
|
|
|
ShopArgumentsURL = 0x2, ///< TODO(DarkLordZach): This is not the official name.
|
|
|
|
CallbackURL = 0x3,
|
|
|
|
CallbackableURL = 0x4,
|
|
|
|
ApplicationID = 0x5,
|
|
|
|
DocumentPath = 0x6,
|
|
|
|
DocumentKind = 0x7,
|
|
|
|
SystemDataID = 0x8,
|
|
|
|
ShareStartPage = 0x9,
|
|
|
|
Whitelist = 0xA,
|
|
|
|
News = 0xB,
|
|
|
|
UserID = 0xE,
|
|
|
|
AlbumEntry0 = 0xF,
|
|
|
|
ScreenShotEnabled = 0x10,
|
|
|
|
EcClientCertEnabled = 0x11,
|
|
|
|
Unk12 = 0x12,
|
|
|
|
PlayReportEnabled = 0x13,
|
|
|
|
Unk14 = 0x14,
|
|
|
|
Unk15 = 0x15,
|
|
|
|
BootDisplayKind = 0x17,
|
|
|
|
BackgroundKind = 0x18,
|
|
|
|
FooterEnabled = 0x19,
|
|
|
|
PointerEnabled = 0x1A,
|
|
|
|
LeftStickMode = 0x1B,
|
|
|
|
KeyRepeatFrame1 = 0x1C,
|
|
|
|
KeyRepeatFrame2 = 0x1D,
|
|
|
|
BootAsMediaPlayerInv = 0x1E,
|
|
|
|
DisplayUrlKind = 0x1F,
|
|
|
|
BootAsMediaPlayer = 0x21,
|
|
|
|
ShopJumpEnabled = 0x22,
|
|
|
|
MediaAutoPlayEnabled = 0x23,
|
|
|
|
LobbyParameter = 0x24,
|
|
|
|
ApplicationAlbumEntry = 0x26,
|
|
|
|
JsExtensionEnabled = 0x27,
|
|
|
|
AdditionalCommentText = 0x28,
|
|
|
|
TouchEnabledOnContents = 0x29,
|
|
|
|
UserAgentAdditionalString = 0x2A,
|
|
|
|
AdditionalMediaData0 = 0x2B,
|
|
|
|
MediaPlayerAutoCloseEnabled = 0x2C,
|
|
|
|
PageCacheEnabled = 0x2D,
|
|
|
|
WebAudioEnabled = 0x2E,
|
|
|
|
Unk2F = 0x2F,
|
|
|
|
YouTubeVideoWhitelist = 0x31,
|
|
|
|
FooterFixedKind = 0x32,
|
|
|
|
PageFadeEnabled = 0x33,
|
|
|
|
MediaCreatorApplicationRatingAge = 0x34,
|
|
|
|
BootLoadingIconEnabled = 0x35,
|
|
|
|
PageScrollIndicationEnabled = 0x36,
|
|
|
|
MediaPlayerSpeedControlEnabled = 0x37,
|
|
|
|
AlbumEntry1 = 0x38,
|
|
|
|
AlbumEntry2 = 0x39,
|
|
|
|
AlbumEntry3 = 0x3A,
|
|
|
|
AdditionalMediaData1 = 0x3B,
|
|
|
|
AdditionalMediaData2 = 0x3C,
|
|
|
|
AdditionalMediaData3 = 0x3D,
|
|
|
|
BootFooterButton = 0x3E,
|
|
|
|
OverrideWebAudioVolume = 0x3F,
|
|
|
|
OverrideMediaAudioVolume = 0x40,
|
|
|
|
BootMode = 0x41,
|
|
|
|
WebSessionEnabled = 0x42,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class ShimKind : u32 {
|
|
|
|
Shop = 1,
|
|
|
|
Login = 2,
|
|
|
|
Offline = 3,
|
|
|
|
Share = 4,
|
|
|
|
Web = 5,
|
|
|
|
Wifi = 6,
|
|
|
|
Lobby = 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr std::size_t SHIM_KIND_COUNT = 0x8;
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
struct WebArgHeader {
|
2018-12-24 22:21:12 +01:00
|
|
|
u16 count;
|
2019-06-05 18:16:02 +02:00
|
|
|
INSERT_PADDING_BYTES(2);
|
|
|
|
ShimKind kind;
|
2018-12-24 22:21:12 +01:00
|
|
|
};
|
2019-06-05 18:16:02 +02:00
|
|
|
static_assert(sizeof(WebArgHeader) == 0x8, "WebArgHeader has incorrect size.");
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
struct WebArgTLV {
|
|
|
|
WebArgTLVType type;
|
2018-12-24 22:21:12 +01:00
|
|
|
u16 size;
|
|
|
|
u32 offset;
|
|
|
|
};
|
2019-06-05 18:16:02 +02:00
|
|
|
static_assert(sizeof(WebArgTLV) == 0x8, "WebArgTLV has incorrect size.");
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
struct WebCommonReturnValue {
|
2018-12-24 22:21:12 +01:00
|
|
|
u32 result_code;
|
2019-06-05 18:16:02 +02:00
|
|
|
INSERT_PADDING_BYTES(0x4);
|
2018-12-24 22:21:12 +01:00
|
|
|
std::array<char, 0x1000> last_url;
|
|
|
|
u64 last_url_size;
|
|
|
|
};
|
2019-06-05 18:16:02 +02:00
|
|
|
static_assert(sizeof(WebCommonReturnValue) == 0x1010, "WebCommonReturnValue has incorrect size.");
|
|
|
|
|
|
|
|
struct WebWifiPageArg {
|
|
|
|
INSERT_PADDING_BYTES(4);
|
|
|
|
std::array<char, 0x100> connection_test_url;
|
|
|
|
std::array<char, 0x400> initial_url;
|
|
|
|
std::array<u8, 0x10> nifm_network_uuid;
|
|
|
|
u32 nifm_requirement;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(WebWifiPageArg) == 0x518, "WebWifiPageArg has incorrect size.");
|
|
|
|
|
|
|
|
struct WebWifiReturnValue {
|
|
|
|
INSERT_PADDING_BYTES(4);
|
|
|
|
u32 result;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(WebWifiReturnValue) == 0x8, "WebWifiReturnValue has incorrect size.");
|
|
|
|
|
|
|
|
enum class OfflineWebSource : u32 {
|
|
|
|
OfflineHtmlPage = 0x1,
|
|
|
|
ApplicationLegalInformation = 0x2,
|
|
|
|
SystemDataPage = 0x3,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class ShopWebTarget {
|
|
|
|
ApplicationInfo,
|
|
|
|
AddOnContentList,
|
|
|
|
SubscriptionList,
|
|
|
|
ConsumableItemList,
|
|
|
|
Home,
|
|
|
|
Settings,
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
std::map<WebArgTLVType, std::vector<u8>> GetWebArguments(const std::vector<u8>& arg) {
|
|
|
|
WebArgHeader header{};
|
|
|
|
if (arg.size() < sizeof(WebArgHeader))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
std::memcpy(&header, arg.data(), sizeof(WebArgHeader));
|
|
|
|
|
|
|
|
std::map<WebArgTLVType, std::vector<u8>> out;
|
|
|
|
u64 offset = sizeof(WebArgHeader);
|
|
|
|
for (std::size_t i = 0; i < header.count; ++i) {
|
|
|
|
WebArgTLV tlv{};
|
|
|
|
if (arg.size() < (offset + sizeof(WebArgTLV)))
|
2018-12-24 22:21:12 +01:00
|
|
|
return out;
|
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
std::memcpy(&tlv, arg.data() + offset, sizeof(WebArgTLV));
|
|
|
|
offset += sizeof(WebArgTLV);
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
offset += tlv.offset;
|
|
|
|
if (arg.size() < (offset + tlv.size))
|
|
|
|
return out;
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
std::vector<u8> data(tlv.size);
|
|
|
|
std::memcpy(data.data(), arg.data() + offset, tlv.size);
|
|
|
|
offset += tlv.size;
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
out.insert_or_assign(tlv.type, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
FileSys::VirtualFile GetApplicationRomFS(u64 title_id, FileSys::ContentRecordType type) {
|
2019-03-04 18:40:53 +01:00
|
|
|
const auto& installed{Core::System::GetInstance().GetContentProvider()};
|
2019-06-05 18:16:02 +02:00
|
|
|
const auto res = installed.GetEntry(title_id, type);
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
if (res != nullptr) {
|
2018-12-24 22:21:12 +01:00
|
|
|
return res->GetRomFS();
|
2019-06-05 18:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type == FileSys::ContentRecordType::Data) {
|
|
|
|
return FileSys::SystemArchive::SynthesizeSystemArchive(title_id);
|
|
|
|
}
|
|
|
|
|
2018-12-24 22:21:12 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
|
WebBrowser::WebBrowser(Core::Frontend::WebBrowserApplet& frontend,
|
|
|
|
Core::Frontend::ECommerceApplet* frontend_e_commerce)
|
|
|
|
: frontend(frontend), frontend_e_commerce(frontend_e_commerce) {}
|
2018-12-24 22:21:12 +01:00
|
|
|
|
|
|
|
WebBrowser::~WebBrowser() = default;
|
|
|
|
|
|
|
|
void WebBrowser::Initialize() {
|
2018-12-29 00:20:29 +01:00
|
|
|
Applet::Initialize();
|
|
|
|
|
2018-12-24 22:21:12 +01:00
|
|
|
complete = false;
|
|
|
|
temporary_dir.clear();
|
|
|
|
filename.clear();
|
|
|
|
status = RESULT_SUCCESS;
|
|
|
|
|
|
|
|
const auto web_arg_storage = broker.PopNormalDataToApplet();
|
|
|
|
ASSERT(web_arg_storage != nullptr);
|
|
|
|
const auto& web_arg = web_arg_storage->GetData();
|
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
ASSERT(web_arg.size() >= 0x8);
|
|
|
|
std::memcpy(&kind, web_arg.data() + 0x4, sizeof(ShimKind));
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
args = GetWebArguments(web_arg);
|
2018-12-24 22:21:12 +01:00
|
|
|
|
2019-06-05 18:16:02 +02:00
|
|
|
InitializeInternal();
|
2018-12-24 22:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebBrowser::TransactionComplete() const {
|
|
|
|
return complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode WebBrowser::GetStatus() const {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebBrowser::ExecuteInteractive() {
|
2018-12-29 00:20:29 +01:00
|
|
|
UNIMPLEMENTED_MSG("Unexpected interactive data recieved!");
|
2018-12-24 22:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebBrowser::Execute() {
|
|
|
|
if (complete)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (status != RESULT_SUCCESS) {
|
|
|
|
complete = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-28 01:08:56 +01:00
|
|
|
frontend.OpenPage(filename, [this] { UnpackRomFS(); }, [this] { Finalize(); });
|
2018-12-24 22:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebBrowser::UnpackRomFS() {
|
|
|
|
if (unpacked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ASSERT(manual_romfs != nullptr);
|
|
|
|
const auto dir =
|
|
|
|
FileSys::ExtractRomFS(manual_romfs, FileSys::RomFSExtractionType::SingleDiscard);
|
|
|
|
const auto& vfs{Core::System::GetInstance().GetFilesystem()};
|
|
|
|
const auto temp_dir = vfs->CreateDirectory(temporary_dir, FileSys::Mode::ReadWrite);
|
|
|
|
FileSys::VfsRawCopyD(dir, temp_dir);
|
|
|
|
|
|
|
|
unpacked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebBrowser::Finalize() {
|
|
|
|
complete = true;
|
|
|
|
|
|
|
|
WebArgumentResult out{};
|
|
|
|
out.result_code = 0;
|
|
|
|
out.last_url_size = 0;
|
|
|
|
|
|
|
|
std::vector<u8> data(sizeof(WebArgumentResult));
|
|
|
|
std::memcpy(data.data(), &out, sizeof(WebArgumentResult));
|
|
|
|
|
|
|
|
broker.PushNormalDataFromApplet(IStorage{data});
|
|
|
|
broker.SignalStateChanged();
|
|
|
|
|
|
|
|
FileUtil::DeleteDirRecursively(temporary_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::AM::Applets
|