1
0
Fork 0
forked from suyu/suyu

applets: Remove the previous web browser applet implementation

This commit is contained in:
Morph 2020-11-08 07:17:12 -05:00
parent 0b47f7a46b
commit ccb439efb0
12 changed files with 40 additions and 1039 deletions

View file

@ -53,72 +53,4 @@ void DefaultPhotoViewerApplet::ShowAllPhotos(std::function<void()> finished) con
finished();
}
ECommerceApplet::~ECommerceApplet() = default;
DefaultECommerceApplet::~DefaultECommerceApplet() = default;
void DefaultECommerceApplet::ShowApplicationInformation(
std::function<void()> finished, u64 title_id, std::optional<u128> user_id,
std::optional<bool> full_display, std::optional<std::string> extra_parameter) {
const auto value = user_id.value_or(u128{});
LOG_INFO(Service_AM,
"Application requested frontend show application information for EShop, "
"title_id={:016X}, user_id={:016X}{:016X}, full_display={}, extra_parameter={}",
title_id, value[1], value[0],
full_display.has_value() ? fmt::format("{}", *full_display) : "null",
extra_parameter.value_or("null"));
finished();
}
void DefaultECommerceApplet::ShowAddOnContentList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id,
std::optional<bool> full_display) {
const auto value = user_id.value_or(u128{});
LOG_INFO(Service_AM,
"Application requested frontend show add on content list for EShop, "
"title_id={:016X}, user_id={:016X}{:016X}, full_display={}",
title_id, value[1], value[0],
full_display.has_value() ? fmt::format("{}", *full_display) : "null");
finished();
}
void DefaultECommerceApplet::ShowSubscriptionList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id) {
const auto value = user_id.value_or(u128{});
LOG_INFO(Service_AM,
"Application requested frontend show subscription list for EShop, title_id={:016X}, "
"user_id={:016X}{:016X}",
title_id, value[1], value[0]);
finished();
}
void DefaultECommerceApplet::ShowConsumableItemList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id) {
const auto value = user_id.value_or(u128{});
LOG_INFO(
Service_AM,
"Application requested frontend show consumable item list for EShop, title_id={:016X}, "
"user_id={:016X}{:016X}",
title_id, value[1], value[0]);
finished();
}
void DefaultECommerceApplet::ShowShopHome(std::function<void()> finished, u128 user_id,
bool full_display) {
LOG_INFO(Service_AM,
"Application requested frontend show home menu for EShop, user_id={:016X}{:016X}, "
"full_display={}",
user_id[1], user_id[0], full_display);
finished();
}
void DefaultECommerceApplet::ShowSettings(std::function<void()> finished, u128 user_id,
bool full_display) {
LOG_INFO(Service_AM,
"Application requested frontend show settings menu for EShop, user_id={:016X}{:016X}, "
"full_display={}",
user_id[1], user_id[0], full_display);
finished();
}
} // namespace Core::Frontend

View file

@ -58,55 +58,4 @@ public:
void ShowAllPhotos(std::function<void()> finished) const override;
};
class ECommerceApplet {
public:
virtual ~ECommerceApplet();
// Shows a page with application icons, description, name, and price.
virtual void ShowApplicationInformation(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id = {},
std::optional<bool> full_display = {},
std::optional<std::string> extra_parameter = {}) = 0;
// Shows a page with all of the add on content available for a game, with name, description, and
// price.
virtual void ShowAddOnContentList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id = {},
std::optional<bool> full_display = {}) = 0;
// Shows a page with all of the subscriptions (recurring payments) for a game, with name,
// description, price, and renewal period.
virtual void ShowSubscriptionList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id = {}) = 0;
// Shows a page with a list of any additional game related purchasable items (DLC,
// subscriptions, etc) for a particular game, with name, description, type, and price.
virtual void ShowConsumableItemList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id = {}) = 0;
// Shows the home page of the shop.
virtual void ShowShopHome(std::function<void()> finished, u128 user_id, bool full_display) = 0;
// Shows the user settings page of the shop.
virtual void ShowSettings(std::function<void()> finished, u128 user_id, bool full_display) = 0;
};
class DefaultECommerceApplet : public ECommerceApplet {
public:
~DefaultECommerceApplet() override;
void ShowApplicationInformation(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id, std::optional<bool> full_display,
std::optional<std::string> extra_parameter) override;
void ShowAddOnContentList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id,
std::optional<bool> full_display) override;
void ShowSubscriptionList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id) override;
void ShowConsumableItemList(std::function<void()> finished, u64 title_id,
std::optional<u128> user_id) override;
void ShowShopHome(std::function<void()> finished, u128 user_id, bool full_display) override;
void ShowSettings(std::function<void()> finished, u128 user_id, bool full_display) override;
};
} // namespace Core::Frontend

View file

@ -11,14 +11,4 @@ WebBrowserApplet::~WebBrowserApplet() = default;
DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default;
void DefaultWebBrowserApplet::OpenPageLocal(std::string_view filename,
std::function<void()> unpack_romfs_callback,
std::function<void()> finished_callback) {
LOG_INFO(Service_AM,
"(STUBBED) called - No suitable web browser implementation found to open website page "
"at '{}'!",
filename);
finished_callback();
}
} // namespace Core::Frontend

View file

@ -5,24 +5,17 @@
#pragma once
#include <functional>
#include <string_view>
namespace Core::Frontend {
class WebBrowserApplet {
public:
virtual ~WebBrowserApplet();
virtual void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback,
std::function<void()> finished_callback) = 0;
};
class DefaultWebBrowserApplet final : public WebBrowserApplet {
public:
~DefaultWebBrowserApplet() override;
void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback,
std::function<void()> finished_callback) override;
};
} // namespace Core::Frontend

View file

@ -142,14 +142,14 @@ void Applet::Initialize() {
AppletFrontendSet::AppletFrontendSet() = default;
AppletFrontendSet::AppletFrontendSet(ControllerApplet controller, ECommerceApplet e_commerce,
ErrorApplet error, ParentalControlsApplet parental_controls,
PhotoViewer photo_viewer, ProfileSelect profile_select,
SoftwareKeyboard software_keyboard, WebBrowser web_browser)
: controller{std::move(controller)}, e_commerce{std::move(e_commerce)}, error{std::move(error)},
parental_controls{std::move(parental_controls)}, photo_viewer{std::move(photo_viewer)},
profile_select{std::move(profile_select)}, software_keyboard{std::move(software_keyboard)},
web_browser{std::move(web_browser)} {}
AppletFrontendSet::AppletFrontendSet(ControllerApplet controller_applet, ErrorApplet error_applet,
ParentalControlsApplet parental_controls_applet,
PhotoViewer photo_viewer_, ProfileSelect profile_select_,
SoftwareKeyboard software_keyboard_, WebBrowser web_browser_)
: controller{std::move(controller_applet)}, error{std::move(error_applet)},
parental_controls{std::move(parental_controls_applet)},
photo_viewer{std::move(photo_viewer_)}, profile_select{std::move(profile_select_)},
software_keyboard{std::move(software_keyboard_)}, web_browser{std::move(web_browser_)} {}
AppletFrontendSet::~AppletFrontendSet() = default;
@ -170,10 +170,6 @@ void AppletManager::SetAppletFrontendSet(AppletFrontendSet set) {
frontend.controller = std::move(set.controller);
}
if (set.e_commerce != nullptr) {
frontend.e_commerce = std::move(set.e_commerce);
}
if (set.error != nullptr) {
frontend.error = std::move(set.error);
}
@ -210,10 +206,6 @@ void AppletManager::SetDefaultAppletsIfMissing() {
std::make_unique<Core::Frontend::DefaultControllerApplet>(system.ServiceManager());
}
if (frontend.e_commerce == nullptr) {
frontend.e_commerce = std::make_unique<Core::Frontend::DefaultECommerceApplet>();
}
if (frontend.error == nullptr) {
frontend.error = std::make_unique<Core::Frontend::DefaultErrorApplet>();
}
@ -257,13 +249,14 @@ std::shared_ptr<Applet> AppletManager::GetApplet(AppletId id) const {
return std::make_shared<ProfileSelect>(system, *frontend.profile_select);
case AppletId::SoftwareKeyboard:
return std::make_shared<SoftwareKeyboard>(system, *frontend.software_keyboard);
case AppletId::Web:
case AppletId::Shop:
case AppletId::OfflineWeb:
case AppletId::LoginShare:
case AppletId::WebAuth:
return std::make_shared<WebBrowser>(system, *frontend.web_browser);
case AppletId::PhotoViewer:
return std::make_shared<PhotoViewer>(system, *frontend.photo_viewer);
case AppletId::LibAppletShop:
return std::make_shared<WebBrowser>(system, *frontend.web_browser,
frontend.e_commerce.get());
case AppletId::LibAppletOff:
return std::make_shared<WebBrowser>(system, *frontend.web_browser);
default:
UNIMPLEMENTED_MSG(
"No backend implementation exists for applet_id={:02X}! Falling back to stub applet.",

View file

@ -50,13 +50,13 @@ enum class AppletId : u32 {
ProfileSelect = 0x10,
SoftwareKeyboard = 0x11,
MiiEdit = 0x12,
LibAppletWeb = 0x13,
LibAppletShop = 0x14,
Web = 0x13,
Shop = 0x14,
PhotoViewer = 0x15,
Settings = 0x16,
LibAppletOff = 0x17,
LibAppletWhitelisted = 0x18,
LibAppletAuth = 0x19,
OfflineWeb = 0x17,
LoginShare = 0x18,
WebAuth = 0x19,
MyPage = 0x1A,
};
@ -157,7 +157,6 @@ protected:
struct AppletFrontendSet {
using ControllerApplet = std::unique_ptr<Core::Frontend::ControllerApplet>;
using ECommerceApplet = std::unique_ptr<Core::Frontend::ECommerceApplet>;
using ErrorApplet = std::unique_ptr<Core::Frontend::ErrorApplet>;
using ParentalControlsApplet = std::unique_ptr<Core::Frontend::ParentalControlsApplet>;
using PhotoViewer = std::unique_ptr<Core::Frontend::PhotoViewerApplet>;
@ -166,10 +165,10 @@ struct AppletFrontendSet {
using WebBrowser = std::unique_ptr<Core::Frontend::WebBrowserApplet>;
AppletFrontendSet();
AppletFrontendSet(ControllerApplet controller, ECommerceApplet e_commerce, ErrorApplet error,
ParentalControlsApplet parental_controls, PhotoViewer photo_viewer,
ProfileSelect profile_select, SoftwareKeyboard software_keyboard,
WebBrowser web_browser);
AppletFrontendSet(ControllerApplet controller_applet, ErrorApplet error_applet,
ParentalControlsApplet parental_controls_applet, PhotoViewer photo_viewer_,
ProfileSelect profile_select_, SoftwareKeyboard software_keyboard_,
WebBrowser web_browser_);
~AppletFrontendSet();
AppletFrontendSet(const AppletFrontendSet&) = delete;
@ -179,7 +178,6 @@ struct AppletFrontendSet {
AppletFrontendSet& operator=(AppletFrontendSet&&) noexcept;
ControllerApplet controller;
ECommerceApplet e_commerce;
ErrorApplet error;
ParentalControlsApplet parental_controls;
PhotoViewer photo_viewer;

View file

@ -1,238 +1,24 @@
// Copyright 2018 yuzu emulator team
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <array>
#include <cstring>
#include <vector>
#include "common/assert.h"
#include "common/common_funcs.h"
#include "common/common_paths.h"
#include "common/file_util.h"
#include "common/hex_util.h"
#include "common/logging/log.h"
#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"
#include "core/file_sys/system_archive/system_archive.h"
#include "core/file_sys/vfs_types.h"
#include "core/frontend/applets/general_frontend.h"
#include "core/frontend/applets/web_browser.h"
#include "core/hle/kernel/process.h"
#include "core/hle/result.h"
#include "core/hle/service/am/am.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 {
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,
};
enum class ShopWebTarget {
ApplicationInfo,
AddOnContentList,
SubscriptionList,
ConsumableItemList,
Home,
Settings,
};
namespace {
constexpr std::size_t SHIM_KIND_COUNT = 0x8;
struct WebArgHeader {
u16 count;
INSERT_PADDING_BYTES(2);
ShimKind kind;
};
static_assert(sizeof(WebArgHeader) == 0x8, "WebArgHeader has incorrect size.");
struct WebArgTLV {
WebArgTLVType type;
u16 size;
u32 offset;
};
static_assert(sizeof(WebArgTLV) == 0x8, "WebArgTLV has incorrect size.");
struct WebCommonReturnValue {
u32 result_code;
INSERT_PADDING_BYTES(0x4);
std::array<char, 0x1000> last_url;
u64 last_url_size;
};
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,
};
std::map<WebArgTLVType, std::vector<u8>> GetWebArguments(const std::vector<u8>& arg) {
if (arg.size() < sizeof(WebArgHeader))
return {};
WebArgHeader header{};
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) {
if (arg.size() < (offset + sizeof(WebArgTLV)))
return out;
WebArgTLV tlv{};
std::memcpy(&tlv, arg.data() + offset, sizeof(WebArgTLV));
offset += sizeof(WebArgTLV);
offset += tlv.offset;
if (arg.size() < (offset + tlv.size))
return out;
std::vector<u8> data(tlv.size);
std::memcpy(data.data(), arg.data() + offset, tlv.size);
offset += tlv.size;
out.insert_or_assign(tlv.type, data);
}
return out;
}
FileSys::VirtualFile GetApplicationRomFS(const Core::System& system, u64 title_id,
FileSys::ContentRecordType type) {
const auto& installed{system.GetContentProvider()};
const auto res = installed.GetEntry(title_id, type);
if (res != nullptr) {
return res->GetRomFS();
}
if (type == FileSys::ContentRecordType::Data) {
return FileSys::SystemArchive::SynthesizeSystemArchive(title_id);
}
return nullptr;
}
} // Anonymous namespace
WebBrowser::WebBrowser(Core::System& system_, Core::Frontend::WebBrowserApplet& frontend_,
Core::Frontend::ECommerceApplet* frontend_e_commerce_)
: Applet{system_.Kernel()}, frontend(frontend_),
frontend_e_commerce(frontend_e_commerce_), system{system_} {}
WebBrowser::WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_)
: Applet{system_.Kernel()}, frontend(frontend_), system{system_} {}
WebBrowser::~WebBrowser() = default;
void WebBrowser::Initialize() {
Applet::Initialize();
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();
ASSERT(web_arg.size() >= 0x8);
std::memcpy(&kind, web_arg.data() + 0x4, sizeof(ShimKind));
args = GetWebArguments(web_arg);
InitializeInternal();
}
bool WebBrowser::TransactionComplete() const {
@ -247,312 +33,6 @@ void WebBrowser::ExecuteInteractive() {
UNIMPLEMENTED_MSG("Unexpected interactive data recieved!");
}
void WebBrowser::Execute() {
if (complete) {
return;
}
if (status != RESULT_SUCCESS) {
complete = true;
// This is a workaround in order not to softlock yuzu when an error happens during the
// webapplet init. In order to avoid an svcBreak, the status is set to RESULT_SUCCESS
Finalize();
status = RESULT_SUCCESS;
return;
}
ExecuteInternal();
}
void WebBrowser::UnpackRomFS() {
if (unpacked)
return;
ASSERT(offline_romfs != nullptr);
const auto dir =
FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard);
const auto& vfs{system.GetFilesystem()};
const auto temp_dir = vfs->CreateDirectory(temporary_dir, FileSys::Mode::ReadWrite);
FileSys::VfsRawCopyD(dir, temp_dir);
unpacked = true;
}
void WebBrowser::Finalize() {
complete = true;
WebCommonReturnValue out{};
out.result_code = 0;
out.last_url_size = 0;
std::vector<u8> data(sizeof(WebCommonReturnValue));
std::memcpy(data.data(), &out, sizeof(WebCommonReturnValue));
broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(data)));
broker.SignalStateChanged();
if (!temporary_dir.empty() && Common::FS::IsDirectory(temporary_dir)) {
Common::FS::DeleteDirRecursively(temporary_dir);
}
}
void WebBrowser::InitializeInternal() {
using WebAppletInitializer = void (WebBrowser::*)();
constexpr std::array<WebAppletInitializer, SHIM_KIND_COUNT> functions{
nullptr, &WebBrowser::InitializeShop,
nullptr, &WebBrowser::InitializeOffline,
nullptr, nullptr,
nullptr, nullptr,
};
const auto index = static_cast<u32>(kind);
if (index > functions.size() || functions[index] == nullptr) {
LOG_ERROR(Service_AM, "Invalid shim_kind={:08X}", index);
return;
}
const auto function = functions[index];
(this->*function)();
}
void WebBrowser::ExecuteInternal() {
using WebAppletExecutor = void (WebBrowser::*)();
constexpr std::array<WebAppletExecutor, SHIM_KIND_COUNT> functions{
nullptr, &WebBrowser::ExecuteShop,
nullptr, &WebBrowser::ExecuteOffline,
nullptr, nullptr,
nullptr, nullptr,
};
const auto index = static_cast<u32>(kind);
if (index > functions.size() || functions[index] == nullptr) {
LOG_ERROR(Service_AM, "Invalid shim_kind={:08X}", index);
return;
}
const auto function = functions[index];
(this->*function)();
}
void WebBrowser::InitializeShop() {
if (frontend_e_commerce == nullptr) {
LOG_ERROR(Service_AM, "Missing ECommerce Applet frontend!");
status = RESULT_UNKNOWN;
return;
}
const auto user_id_data = args.find(WebArgTLVType::UserID);
user_id = std::nullopt;
if (user_id_data != args.end()) {
user_id = u128{};
std::memcpy(user_id->data(), user_id_data->second.data(), sizeof(u128));
}
const auto url = args.find(WebArgTLVType::ShopArgumentsURL);
if (url == args.end()) {
LOG_ERROR(Service_AM, "Missing EShop Arguments URL for initialization!");
status = RESULT_UNKNOWN;
return;
}
std::vector<std::string> split_query;
Common::SplitString(Common::StringFromFixedZeroTerminatedBuffer(
reinterpret_cast<const char*>(url->second.data()), url->second.size()),
'?', split_query);
// 2 -> Main URL '?' Query Parameters
// Less is missing info, More is malformed
if (split_query.size() != 2) {
LOG_ERROR(Service_AM, "EShop Arguments has more than one question mark, malformed");
status = RESULT_UNKNOWN;
return;
}
std::vector<std::string> queries;
Common::SplitString(split_query[1], '&', queries);
const auto split_single_query =
[](const std::string& in) -> std::pair<std::string, std::string> {
const auto index = in.find('=');
if (index == std::string::npos || index == in.size() - 1) {
return {in, ""};
}
return {in.substr(0, index), in.substr(index + 1)};
};
std::transform(queries.begin(), queries.end(),
std::inserter(shop_query, std::next(shop_query.begin())), split_single_query);
const auto scene = shop_query.find("scene");
if (scene == shop_query.end()) {
LOG_ERROR(Service_AM, "No scene parameter was passed via shop query!");
status = RESULT_UNKNOWN;
return;
}
const std::map<std::string, ShopWebTarget, std::less<>> target_map{
{"product_detail", ShopWebTarget::ApplicationInfo},
{"aocs", ShopWebTarget::AddOnContentList},
{"subscriptions", ShopWebTarget::SubscriptionList},
{"consumption", ShopWebTarget::ConsumableItemList},
{"settings", ShopWebTarget::Settings},
{"top", ShopWebTarget::Home},
};
const auto target = target_map.find(scene->second);
if (target == target_map.end()) {
LOG_ERROR(Service_AM, "Scene for shop query is invalid! (scene={})", scene->second);
status = RESULT_UNKNOWN;
return;
}
shop_web_target = target->second;
const auto title_id_data = shop_query.find("dst_app_id");
if (title_id_data != shop_query.end()) {
title_id = std::stoull(title_id_data->second, nullptr, 0x10);
}
const auto mode_data = shop_query.find("mode");
if (mode_data != shop_query.end()) {
shop_full_display = mode_data->second == "full";
}
}
void WebBrowser::InitializeOffline() {
if (args.find(WebArgTLVType::DocumentPath) == args.end() ||
args.find(WebArgTLVType::DocumentKind) == args.end() ||
args.find(WebArgTLVType::ApplicationID) == args.end()) {
status = RESULT_UNKNOWN;
LOG_ERROR(Service_AM, "Missing necessary parameters for initialization!");
}
const auto url_data = args[WebArgTLVType::DocumentPath];
filename = Common::StringFromFixedZeroTerminatedBuffer(
reinterpret_cast<const char*>(url_data.data()), url_data.size());
OfflineWebSource source;
ASSERT(args[WebArgTLVType::DocumentKind].size() >= 4);
std::memcpy(&source, args[WebArgTLVType::DocumentKind].data(), sizeof(OfflineWebSource));
constexpr std::array<const char*, 3> WEB_SOURCE_NAMES{
"manual",
"legal",
"system",
};
temporary_dir =
Common::FS::SanitizePath(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) +
"web_applet_" + WEB_SOURCE_NAMES[static_cast<u32>(source) - 1],
Common::FS::DirectorySeparator::PlatformDefault);
Common::FS::DeleteDirRecursively(temporary_dir);
u64 title_id = 0; // 0 corresponds to current process
ASSERT(args[WebArgTLVType::ApplicationID].size() >= 0x8);
std::memcpy(&title_id, args[WebArgTLVType::ApplicationID].data(), sizeof(u64));
FileSys::ContentRecordType type = FileSys::ContentRecordType::Data;
switch (source) {
case OfflineWebSource::OfflineHtmlPage:
// While there is an AppID TLV field, in official SW this is always ignored.
title_id = 0;
type = FileSys::ContentRecordType::HtmlDocument;
break;
case OfflineWebSource::ApplicationLegalInformation:
type = FileSys::ContentRecordType::LegalInformation;
break;
case OfflineWebSource::SystemDataPage:
type = FileSys::ContentRecordType::Data;
break;
}
if (title_id == 0) {
title_id = system.CurrentProcess()->GetTitleID();
}
offline_romfs = GetApplicationRomFS(system, title_id, type);
if (offline_romfs == nullptr) {
status = RESULT_UNKNOWN;
LOG_ERROR(Service_AM, "Failed to find offline data for request!");
}
std::string path_additional_directory;
if (source == OfflineWebSource::OfflineHtmlPage) {
path_additional_directory = std::string(DIR_SEP).append("html-document");
}
filename =
Common::FS::SanitizePath(temporary_dir + path_additional_directory + DIR_SEP + filename,
Common::FS::DirectorySeparator::PlatformDefault);
}
void WebBrowser::ExecuteShop() {
const auto callback = [this]() { Finalize(); };
const auto check_optional_parameter = [this](const auto& p) {
if (!p.has_value()) {
LOG_ERROR(Service_AM, "Missing one or more necessary parameters for execution!");
status = RESULT_UNKNOWN;
return false;
}
return true;
};
switch (shop_web_target) {
case ShopWebTarget::ApplicationInfo:
if (!check_optional_parameter(title_id))
return;
frontend_e_commerce->ShowApplicationInformation(callback, *title_id, user_id,
shop_full_display, shop_extra_parameter);
break;
case ShopWebTarget::AddOnContentList:
if (!check_optional_parameter(title_id))
return;
frontend_e_commerce->ShowAddOnContentList(callback, *title_id, user_id, shop_full_display);
break;
case ShopWebTarget::ConsumableItemList:
if (!check_optional_parameter(title_id))
return;
frontend_e_commerce->ShowConsumableItemList(callback, *title_id, user_id);
break;
case ShopWebTarget::Home:
if (!check_optional_parameter(user_id))
return;
if (!check_optional_parameter(shop_full_display))
return;
frontend_e_commerce->ShowShopHome(callback, *user_id, *shop_full_display);
break;
case ShopWebTarget::Settings:
if (!check_optional_parameter(user_id))
return;
if (!check_optional_parameter(shop_full_display))
return;
frontend_e_commerce->ShowSettings(callback, *user_id, *shop_full_display);
break;
case ShopWebTarget::SubscriptionList:
if (!check_optional_parameter(title_id))
return;
frontend_e_commerce->ShowSubscriptionList(callback, *title_id, user_id);
break;
default:
UNREACHABLE();
}
}
void WebBrowser::ExecuteOffline() {
frontend.OpenPageLocal(
filename, [this] { UnpackRomFS(); }, [this] { Finalize(); });
}
void WebBrowser::Execute() {}
} // namespace Service::AM::Applets

View file

@ -1,12 +1,12 @@
// Copyright 2018 yuzu emulator team
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <map>
#include "core/file_sys/vfs_types.h"
#include "core/hle/service/am/am.h"
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "core/hle/result.h"
#include "core/hle/service/am/applets/applets.h"
namespace Core {
@ -15,14 +15,9 @@ class System;
namespace Service::AM::Applets {
enum class ShimKind : u32;
enum class ShopWebTarget;
enum class WebArgTLVType : u16;
class WebBrowser final : public Applet {
public:
WebBrowser(Core::System& system_, Core::Frontend::WebBrowserApplet& frontend_,
Core::Frontend::ECommerceApplet* frontend_e_commerce_ = nullptr);
WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_);
~WebBrowser() override;
@ -33,49 +28,11 @@ public:
void ExecuteInteractive() override;
void Execute() override;
// Callback to be fired when the frontend needs the manual RomFS unpacked to temporary
// directory. This is a blocking call and may take a while as some manuals can be up to 100MB in
// size. Attempting to access files at filename before invocation is likely to not work.
void UnpackRomFS();
// Callback to be fired when the frontend is finished browsing. This will delete the temporary
// manual RomFS extracted files, so ensure this is only called at actual finalization.
void Finalize();
private:
void InitializeInternal();
void ExecuteInternal();
const Core::Frontend::WebBrowserApplet& frontend;
// Specific initializers for the types of web applets
void InitializeShop();
void InitializeOffline();
// Specific executors for the types of web applets
void ExecuteShop();
void ExecuteOffline();
Core::Frontend::WebBrowserApplet& frontend;
// Extra frontends for specialized functions
Core::Frontend::ECommerceApplet* frontend_e_commerce;
bool complete = false;
bool unpacked = false;
ResultCode status = RESULT_SUCCESS;
ShimKind kind;
std::map<WebArgTLVType, std::vector<u8>> args;
FileSys::VirtualFile offline_romfs;
std::string temporary_dir;
std::string filename;
ShopWebTarget shop_web_target;
std::map<std::string, std::string, std::less<>> shop_query;
std::optional<u64> title_id = 0;
std::optional<u128> user_id;
std::optional<bool> shop_full_display;
std::string shop_extra_parameter;
bool complete{false};
ResultCode status{RESULT_SUCCESS};
Core::System& system;
};

View file

@ -1,115 +1,11 @@
// Copyright 2018 yuzu Emulator Project
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <mutex>
#include <QKeyEvent>
#include "core/hle/lock.h"
#include "yuzu/applets/web_browser.h"
#include "yuzu/main.h"
#ifdef YUZU_USE_QT_WEB_ENGINE
constexpr char NX_SHIM_INJECT_SCRIPT[] = R"(
window.nx = {};
window.nx.playReport = {};
window.nx.playReport.setCounterSetIdentifier = function () {
console.log("nx.playReport.setCounterSetIdentifier called - unimplemented");
};
window.nx.playReport.incrementCounter = function () {
console.log("nx.playReport.incrementCounter called - unimplemented");
};
window.nx.footer = {};
window.nx.footer.unsetAssign = function () {
console.log("nx.footer.unsetAssign called - unimplemented");
};
var yuzu_key_callbacks = [];
window.nx.footer.setAssign = function(key, discard1, func, discard2) {
switch (key) {
case 'A':
yuzu_key_callbacks[0] = func;
break;
case 'B':
yuzu_key_callbacks[1] = func;
break;
case 'X':
yuzu_key_callbacks[2] = func;
break;
case 'Y':
yuzu_key_callbacks[3] = func;
break;
case 'L':
yuzu_key_callbacks[6] = func;
break;
case 'R':
yuzu_key_callbacks[7] = func;
break;
}
};
var applet_done = false;
window.nx.endApplet = function() {
applet_done = true;
};
window.onkeypress = function(e) { if (e.keyCode === 13) { applet_done = true; } };
)";
QString GetNXShimInjectionScript() {
return QString::fromStdString(NX_SHIM_INJECT_SCRIPT);
}
NXInputWebEngineView::NXInputWebEngineView(QWidget* parent) : QWebEngineView(parent) {}
void NXInputWebEngineView::keyPressEvent(QKeyEvent* event) {
parent()->event(event);
}
void NXInputWebEngineView::keyReleaseEvent(QKeyEvent* event) {
parent()->event(event);
}
#endif
QtWebBrowser::QtWebBrowser(GMainWindow& main_window) {
connect(this, &QtWebBrowser::MainWindowOpenPage, &main_window, &GMainWindow::WebBrowserOpenPage,
Qt::QueuedConnection);
connect(&main_window, &GMainWindow::WebBrowserUnpackRomFS, this,
&QtWebBrowser::MainWindowUnpackRomFS, Qt::QueuedConnection);
connect(&main_window, &GMainWindow::WebBrowserFinishedBrowsing, this,
&QtWebBrowser::MainWindowFinishedBrowsing, Qt::QueuedConnection);
}
QtWebBrowser::QtWebBrowser(GMainWindow& main_window) {}
QtWebBrowser::~QtWebBrowser() = default;
void QtWebBrowser::OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback_,
std::function<void()> finished_callback_) {
unpack_romfs_callback = std::move(unpack_romfs_callback_);
finished_callback = std::move(finished_callback_);
const auto index = url.find('?');
if (index == std::string::npos) {
emit MainWindowOpenPage(url, "");
} else {
const auto front = url.substr(0, index);
const auto back = url.substr(index);
emit MainWindowOpenPage(front, back);
}
}
void QtWebBrowser::MainWindowUnpackRomFS() {
// Acquire the HLE mutex
std::lock_guard lock{HLE::g_hle_lock};
unpack_romfs_callback();
}
void QtWebBrowser::MainWindowFinishedBrowsing() {
// Acquire the HLE mutex
std::lock_guard lock{HLE::g_hle_lock};
finished_callback();
}

View file

@ -1,10 +1,9 @@
// Copyright 2018 yuzu Emulator Project
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <functional>
#include <QObject>
#ifdef YUZU_USE_QT_WEB_ENGINE
@ -15,38 +14,10 @@
class GMainWindow;
#ifdef YUZU_USE_QT_WEB_ENGINE
QString GetNXShimInjectionScript();
class NXInputWebEngineView : public QWebEngineView {
public:
explicit NXInputWebEngineView(QWidget* parent = nullptr);
protected:
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
};
#endif
class QtWebBrowser final : public QObject, public Core::Frontend::WebBrowserApplet {
Q_OBJECT
public:
explicit QtWebBrowser(GMainWindow& main_window);
~QtWebBrowser() override;
void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback_,
std::function<void()> finished_callback_) override;
signals:
void MainWindowOpenPage(std::string_view filename, std::string_view additional_args) const;
private:
void MainWindowUnpackRomFS();
void MainWindowFinishedBrowsing();
std::function<void()> unpack_romfs_callback;
std::function<void()> finished_callback;
};

View file

@ -125,14 +125,6 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
#include "yuzu/discord_impl.h"
#endif
#ifdef YUZU_USE_QT_WEB_ENGINE
#include <QWebEngineProfile>
#include <QWebEngineScript>
#include <QWebEngineScriptCollection>
#include <QWebEngineSettings>
#include <QWebEngineView>
#endif
#ifdef QT_STATICPLUGIN
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
#endif
@ -349,151 +341,6 @@ void GMainWindow::SoftwareKeyboardInvokeCheckDialog(std::u16string error_message
emit SoftwareKeyboardFinishedCheckDialog();
}
#ifdef YUZU_USE_QT_WEB_ENGINE
void GMainWindow::WebBrowserOpenPage(std::string_view filename, std::string_view additional_args) {
NXInputWebEngineView web_browser_view(this);
// Scope to contain the QProgressDialog for initialization
{
QProgressDialog progress(this);
progress.setMinimumDuration(200);
progress.setLabelText(tr("Loading Web Applet..."));
progress.setRange(0, 4);
progress.setValue(0);
progress.show();
auto future = QtConcurrent::run([this] { emit WebBrowserUnpackRomFS(); });
while (!future.isFinished())
QApplication::processEvents();
progress.setValue(1);
// Load the special shim script to handle input and exit.
QWebEngineScript nx_shim;
nx_shim.setSourceCode(GetNXShimInjectionScript());
nx_shim.setWorldId(QWebEngineScript::MainWorld);
nx_shim.setName(QStringLiteral("nx_inject.js"));
nx_shim.setInjectionPoint(QWebEngineScript::DocumentCreation);
nx_shim.setRunsOnSubFrames(true);
web_browser_view.page()->profile()->scripts()->insert(nx_shim);
web_browser_view.load(
QUrl(QUrl::fromLocalFile(QString::fromStdString(std::string(filename))).toString() +
QString::fromStdString(std::string(additional_args))));
progress.setValue(2);
render_window->hide();
web_browser_view.setFocus();
const auto& layout = render_window->GetFramebufferLayout();
web_browser_view.resize(layout.screen.GetWidth(), layout.screen.GetHeight());
web_browser_view.move(layout.screen.left, layout.screen.top + menuBar()->height());
web_browser_view.setZoomFactor(static_cast<qreal>(layout.screen.GetWidth()) /
Layout::ScreenUndocked::Width);
web_browser_view.settings()->setAttribute(
QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
web_browser_view.show();
progress.setValue(3);
QApplication::processEvents();
progress.setValue(4);
}
bool finished = false;
QAction* exit_action = new QAction(tr("Exit Web Applet"), this);
connect(exit_action, &QAction::triggered, this, [&finished] { finished = true; });
ui.menubar->addAction(exit_action);
auto& npad =
Core::System::GetInstance()
.ServiceManager()
.GetService<Service::HID::Hid>("hid")
->GetAppletResource()
->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad);
const auto fire_js_keypress = [&web_browser_view](u32 key_code) {
web_browser_view.page()->runJavaScript(
QStringLiteral("document.dispatchEvent(new KeyboardEvent('keydown', {'key': %1}));")
.arg(key_code));
};
QMessageBox::information(
this, tr("Exit"),
tr("To exit the web application, use the game provided controls to select exit, select the "
"'Exit Web Applet' option in the menu bar, or press the 'Enter' key."));
bool running_exit_check = false;
while (!finished) {
QApplication::processEvents();
if (!running_exit_check) {
web_browser_view.page()->runJavaScript(QStringLiteral("applet_done;"),
[&](const QVariant& res) {
running_exit_check = false;
if (res.toBool())
finished = true;
});
running_exit_check = true;
}
const auto input = npad.GetAndResetPressState();
for (std::size_t i = 0; i < Settings::NativeButton::NumButtons; ++i) {
if ((input & (1 << i)) != 0) {
LOG_DEBUG(Frontend, "firing input for button id={:02X}", i);
web_browser_view.page()->runJavaScript(
QStringLiteral("yuzu_key_callbacks[%1]();").arg(i));
}
}
if (input & 0x00888000) // RStick Down | LStick Down | DPad Down
fire_js_keypress(40); // Down Arrow Key
else if (input & 0x00444000) // RStick Right | LStick Right | DPad Right
fire_js_keypress(39); // Right Arrow Key
else if (input & 0x00222000) // RStick Up | LStick Up | DPad Up
fire_js_keypress(38); // Up Arrow Key
else if (input & 0x00111000) // RStick Left | LStick Left | DPad Left
fire_js_keypress(37); // Left Arrow Key
else if (input & 0x00000001) // A Button
fire_js_keypress(13); // Enter Key
}
web_browser_view.hide();
render_window->show();
render_window->setFocus();
ui.menubar->removeAction(exit_action);
// Needed to update render window focus/show and remove menubar action
QApplication::processEvents();
emit WebBrowserFinishedBrowsing();
}
#else
void GMainWindow::WebBrowserOpenPage(std::string_view filename, std::string_view additional_args) {
#ifndef __linux__
QMessageBox::warning(
this, tr("Web Applet"),
tr("This version of yuzu was built without QtWebEngine support, meaning that yuzu cannot "
"properly display the game manual or web page requested."),
QMessageBox::Ok, QMessageBox::Ok);
#endif
LOG_INFO(Frontend,
"(STUBBED) called - Missing QtWebEngine dependency needed to open website page at "
"'{}' with arguments '{}'!",
filename, additional_args);
emit WebBrowserFinishedBrowsing();
}
#endif
void GMainWindow::InitializeWidgets() {
#ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING
ui.action_Report_Compatibility->setVisible(true);
@ -993,7 +840,6 @@ bool GMainWindow::LoadROM(const QString& filename, std::size_t program_index) {
system.SetAppletFrontendSet({
std::make_unique<QtControllerSelector>(*this), // Controller Selector
nullptr, // E-Commerce
std::make_unique<QtErrorDisplay>(*this), // Error Display
nullptr, // Parental Controls
nullptr, // Photo Viewer

View file

@ -126,9 +126,6 @@ signals:
void SoftwareKeyboardFinishedText(std::optional<std::u16string> text);
void SoftwareKeyboardFinishedCheckDialog();
void WebBrowserUnpackRomFS();
void WebBrowserFinishedBrowsing();
public slots:
void OnLoadComplete();
void OnExecuteProgram(std::size_t program_index);
@ -138,7 +135,6 @@ public slots:
void ProfileSelectorSelectProfile();
void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters);
void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message);
void WebBrowserOpenPage(std::string_view filename, std::string_view arguments);
void OnAppFocusStateChanged(Qt::ApplicationState state);
private: