From ccb439efb088c990b41a6ceb5b1b330c8c27a1aa Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 8 Nov 2020 07:17:12 -0500 Subject: [PATCH 01/16] applets: Remove the previous web browser applet implementation --- .../frontend/applets/general_frontend.cpp | 68 --- src/core/frontend/applets/general_frontend.h | 51 -- src/core/frontend/applets/web_browser.cpp | 10 - src/core/frontend/applets/web_browser.h | 7 - src/core/hle/service/am/applets/applets.cpp | 35 +- src/core/hle/service/am/applets/applets.h | 20 +- .../hle/service/am/applets/web_browser.cpp | 532 +----------------- src/core/hle/service/am/applets/web_browser.h | 59 +- src/yuzu/applets/web_browser.cpp | 108 +--- src/yuzu/applets/web_browser.h | 31 +- src/yuzu/main.cpp | 154 ----- src/yuzu/main.h | 4 - 12 files changed, 40 insertions(+), 1039 deletions(-) diff --git a/src/core/frontend/applets/general_frontend.cpp b/src/core/frontend/applets/general_frontend.cpp index c30b36de7..7483ffb76 100644 --- a/src/core/frontend/applets/general_frontend.cpp +++ b/src/core/frontend/applets/general_frontend.cpp @@ -53,72 +53,4 @@ void DefaultPhotoViewerApplet::ShowAllPhotos(std::function finished) con finished(); } -ECommerceApplet::~ECommerceApplet() = default; - -DefaultECommerceApplet::~DefaultECommerceApplet() = default; - -void DefaultECommerceApplet::ShowApplicationInformation( - std::function finished, u64 title_id, std::optional user_id, - std::optional full_display, std::optional 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 finished, u64 title_id, - std::optional user_id, - std::optional 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 finished, u64 title_id, - std::optional 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 finished, u64 title_id, - std::optional 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 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 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 diff --git a/src/core/frontend/applets/general_frontend.h b/src/core/frontend/applets/general_frontend.h index 4b63f828e..b713b14ee 100644 --- a/src/core/frontend/applets/general_frontend.h +++ b/src/core/frontend/applets/general_frontend.h @@ -58,55 +58,4 @@ public: void ShowAllPhotos(std::function finished) const override; }; -class ECommerceApplet { -public: - virtual ~ECommerceApplet(); - - // Shows a page with application icons, description, name, and price. - virtual void ShowApplicationInformation(std::function finished, u64 title_id, - std::optional user_id = {}, - std::optional full_display = {}, - std::optional 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 finished, u64 title_id, - std::optional user_id = {}, - std::optional 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 finished, u64 title_id, - std::optional 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 finished, u64 title_id, - std::optional user_id = {}) = 0; - - // Shows the home page of the shop. - virtual void ShowShopHome(std::function finished, u128 user_id, bool full_display) = 0; - - // Shows the user settings page of the shop. - virtual void ShowSettings(std::function finished, u128 user_id, bool full_display) = 0; -}; - -class DefaultECommerceApplet : public ECommerceApplet { -public: - ~DefaultECommerceApplet() override; - - void ShowApplicationInformation(std::function finished, u64 title_id, - std::optional user_id, std::optional full_display, - std::optional extra_parameter) override; - void ShowAddOnContentList(std::function finished, u64 title_id, - std::optional user_id, - std::optional full_display) override; - void ShowSubscriptionList(std::function finished, u64 title_id, - std::optional user_id) override; - void ShowConsumableItemList(std::function finished, u64 title_id, - std::optional user_id) override; - void ShowShopHome(std::function finished, u128 user_id, bool full_display) override; - void ShowSettings(std::function finished, u128 user_id, bool full_display) override; -}; - } // namespace Core::Frontend diff --git a/src/core/frontend/applets/web_browser.cpp b/src/core/frontend/applets/web_browser.cpp index 528295ffc..58861809e 100644 --- a/src/core/frontend/applets/web_browser.cpp +++ b/src/core/frontend/applets/web_browser.cpp @@ -11,14 +11,4 @@ WebBrowserApplet::~WebBrowserApplet() = default; DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default; -void DefaultWebBrowserApplet::OpenPageLocal(std::string_view filename, - std::function unpack_romfs_callback, - std::function 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 diff --git a/src/core/frontend/applets/web_browser.h b/src/core/frontend/applets/web_browser.h index 110e33bc4..6e5f4d93d 100644 --- a/src/core/frontend/applets/web_browser.h +++ b/src/core/frontend/applets/web_browser.h @@ -5,24 +5,17 @@ #pragma once #include -#include namespace Core::Frontend { class WebBrowserApplet { public: virtual ~WebBrowserApplet(); - - virtual void OpenPageLocal(std::string_view url, std::function unpack_romfs_callback, - std::function finished_callback) = 0; }; class DefaultWebBrowserApplet final : public WebBrowserApplet { public: ~DefaultWebBrowserApplet() override; - - void OpenPageLocal(std::string_view url, std::function unpack_romfs_callback, - std::function finished_callback) override; }; } // namespace Core::Frontend diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index 2b626bb40..08676c3fc 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -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(system.ServiceManager()); } - if (frontend.e_commerce == nullptr) { - frontend.e_commerce = std::make_unique(); - } - if (frontend.error == nullptr) { frontend.error = std::make_unique(); } @@ -257,13 +249,14 @@ std::shared_ptr AppletManager::GetApplet(AppletId id) const { return std::make_shared(system, *frontend.profile_select); case AppletId::SoftwareKeyboard: return std::make_shared(system, *frontend.software_keyboard); + case AppletId::Web: + case AppletId::Shop: + case AppletId::OfflineWeb: + case AppletId::LoginShare: + case AppletId::WebAuth: + return std::make_shared(system, *frontend.web_browser); case AppletId::PhotoViewer: return std::make_shared(system, *frontend.photo_viewer); - case AppletId::LibAppletShop: - return std::make_shared(system, *frontend.web_browser, - frontend.e_commerce.get()); - case AppletId::LibAppletOff: - return std::make_shared(system, *frontend.web_browser); default: UNIMPLEMENTED_MSG( "No backend implementation exists for applet_id={:02X}! Falling back to stub applet.", diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index a1f4cf897..4fd792c05 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -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; - using ECommerceApplet = std::unique_ptr; using ErrorApplet = std::unique_ptr; using ParentalControlsApplet = std::unique_ptr; using PhotoViewer = std::unique_ptr; @@ -166,10 +165,10 @@ struct AppletFrontendSet { using WebBrowser = std::unique_ptr; 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; diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index c3b6b706a..74ef037fe 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -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 -#include -#include - #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 last_url; - u64 last_url_size; -}; -static_assert(sizeof(WebCommonReturnValue) == 0x1010, "WebCommonReturnValue has incorrect size."); - -struct WebWifiPageArg { - INSERT_PADDING_BYTES(4); - std::array connection_test_url; - std::array initial_url; - std::array 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> GetWebArguments(const std::vector& arg) { - if (arg.size() < sizeof(WebArgHeader)) - return {}; - - WebArgHeader header{}; - std::memcpy(&header, arg.data(), sizeof(WebArgHeader)); - - std::map> 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 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 data(sizeof(WebCommonReturnValue)); - std::memcpy(data.data(), &out, sizeof(WebCommonReturnValue)); - - broker.PushNormalDataFromApplet(std::make_shared(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 functions{ - nullptr, &WebBrowser::InitializeShop, - nullptr, &WebBrowser::InitializeOffline, - nullptr, nullptr, - nullptr, nullptr, - }; - - const auto index = static_cast(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 functions{ - nullptr, &WebBrowser::ExecuteShop, - nullptr, &WebBrowser::ExecuteOffline, - nullptr, nullptr, - nullptr, nullptr, - }; - - const auto index = static_cast(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 split_query; - Common::SplitString(Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast(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 queries; - Common::SplitString(split_query[1], '&', queries); - - const auto split_single_query = - [](const std::string& in) -> std::pair { - 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> 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(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 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(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 diff --git a/src/core/hle/service/am/applets/web_browser.h b/src/core/hle/service/am/applets/web_browser.h index 8d4027411..0584142e5 100644 --- a/src/core/hle/service/am/applets/web_browser.h +++ b/src/core/hle/service/am/applets/web_browser.h @@ -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 -#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> args; - - FileSys::VirtualFile offline_romfs; - std::string temporary_dir; - std::string filename; - - ShopWebTarget shop_web_target; - std::map> shop_query; - std::optional title_id = 0; - std::optional user_id; - std::optional shop_full_display; - std::string shop_extra_parameter; + bool complete{false}; + ResultCode status{RESULT_SUCCESS}; Core::System& system; }; diff --git a/src/yuzu/applets/web_browser.cpp b/src/yuzu/applets/web_browser.cpp index 9fd8d6326..92b53fed0 100644 --- a/src/yuzu/applets/web_browser.cpp +++ b/src/yuzu/applets/web_browser.cpp @@ -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 - -#include - #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 unpack_romfs_callback_, - std::function 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(); -} diff --git a/src/yuzu/applets/web_browser.h b/src/yuzu/applets/web_browser.h index f801846cf..af053ace7 100644 --- a/src/yuzu/applets/web_browser.h +++ b/src/yuzu/applets/web_browser.h @@ -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 #include #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 unpack_romfs_callback_, - std::function finished_callback_) override; - -signals: - void MainWindowOpenPage(std::string_view filename, std::string_view additional_args) const; - -private: - void MainWindowUnpackRomFS(); - void MainWindowFinishedBrowsing(); - - std::function unpack_romfs_callback; - std::function finished_callback; }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 3461fa675..7d4bba854 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -125,14 +125,6 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual #include "yuzu/discord_impl.h" #endif -#ifdef YUZU_USE_QT_WEB_ENGINE -#include -#include -#include -#include -#include -#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(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("hid") - ->GetAppletResource() - ->GetController(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(*this), // Controller Selector - nullptr, // E-Commerce std::make_unique(*this), // Error Display nullptr, // Parental Controls nullptr, // Photo Viewer diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 6242341d1..f311f2b5b 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -126,9 +126,6 @@ signals: void SoftwareKeyboardFinishedText(std::optional 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: From a5750f437d58e63ed76235d171732ca25dd34be2 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 8 Nov 2020 23:27:33 -0500 Subject: [PATCH 02/16] applets/web: Initial implementation of the web browser applet --- .../hle/service/am/applets/web_browser.cpp | 227 +++++++++++++++++- src/core/hle/service/am/applets/web_browser.h | 25 ++ src/core/hle/service/am/applets/web_types.h | 178 ++++++++++++++ 3 files changed, 428 insertions(+), 2 deletions(-) create mode 100644 src/core/hle/service/am/applets/web_types.h diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index 74ef037fe..7f398254e 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -2,8 +2,11 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include + #include "common/assert.h" #include "common/logging/log.h" +#include "common/string_util.h" #include "core/core.h" #include "core/frontend/applets/web_browser.h" #include "core/hle/result.h" @@ -12,6 +15,76 @@ namespace Service::AM::Applets { +namespace { + +template +void ParseRawValue(T& value, const std::vector& data) { + static_assert(std::is_trivially_copyable_v, + "It's undefined behavior to use memcpy with non-trivially copyable objects"); + std::memcpy(&value, data.data(), data.size()); +} + +template +T ParseRawValue(const std::vector& data) { + T value; + ParseRawValue(value, data); + return value; +} + +std::string ParseStringValue(const std::vector& data) { + return Common::StringFromFixedZeroTerminatedBuffer(reinterpret_cast(data.data()), + data.size()); +} + +WebArgInputTLVMap ReadWebArgs(const std::vector& web_arg, WebArgHeader& web_arg_header) { + std::memcpy(&web_arg_header, web_arg.data(), sizeof(WebArgHeader)); + + if (web_arg.size() == sizeof(WebArgHeader)) { + return {}; + } + + WebArgInputTLVMap input_tlv_map; + + u64 current_offset = sizeof(WebArgHeader); + + for (std::size_t i = 0; i < web_arg_header.total_tlv_entries; ++i) { + if (web_arg.size() < current_offset + sizeof(WebArgInputTLV)) { + return input_tlv_map; + } + + WebArgInputTLV input_tlv; + std::memcpy(&input_tlv, web_arg.data() + current_offset, sizeof(WebArgInputTLV)); + + current_offset += sizeof(WebArgInputTLV); + + if (web_arg.size() < current_offset + input_tlv.arg_data_size) { + return input_tlv_map; + } + + std::vector data(input_tlv.arg_data_size); + std::memcpy(data.data(), web_arg.data() + current_offset, input_tlv.arg_data_size); + + current_offset += input_tlv.arg_data_size; + + input_tlv_map.insert_or_assign(input_tlv.input_tlv_type, std::move(data)); + } + + return input_tlv_map; +} + +std::optional> GetInputTLVData(const WebArgInputTLVMap& input_tlv_map, + WebArgInputTLVType input_tlv_type) { + const auto map_it = input_tlv_map.find(input_tlv_type); + + if (map_it == input_tlv_map.end()) { + return std::nullopt; + } + + return map_it->second; +} + +} // namespace + WebBrowser::WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_) : Applet{system_.Kernel()}, frontend(frontend_), system{system_} {} @@ -19,6 +92,55 @@ WebBrowser::~WebBrowser() = default; void WebBrowser::Initialize() { Applet::Initialize(); + + LOG_INFO(Service_AM, "Initializing Web Browser Applet."); + + LOG_DEBUG(Service_AM, + "Initializing Applet with common_args: arg_version={}, lib_version={}, " + "play_startup_sound={}, size={}, system_tick={}, theme_color={}", + common_args.arguments_version, common_args.library_version, + common_args.play_startup_sound, common_args.size, common_args.system_tick, + common_args.theme_color); + + web_applet_version = WebAppletVersion{common_args.library_version}; + + const auto web_arg_storage = broker.PopNormalDataToApplet(); + ASSERT(web_arg_storage != nullptr); + + const auto& web_arg = web_arg_storage->GetData(); + ASSERT_OR_EXECUTE(web_arg.size() >= sizeof(WebArgHeader), { return; }); + + web_arg_input_tlv_map = ReadWebArgs(web_arg, web_arg_header); + + LOG_DEBUG(Service_AM, "WebArgHeader: total_tlv_entries={}, shim_kind={}", + web_arg_header.total_tlv_entries, web_arg_header.shim_kind); + + switch (web_arg_header.shim_kind) { + case ShimKind::Shop: + InitializeShop(); + break; + case ShimKind::Login: + InitializeLogin(); + break; + case ShimKind::Offline: + InitializeOffline(); + break; + case ShimKind::Share: + InitializeShare(); + break; + case ShimKind::Web: + InitializeWeb(); + break; + case ShimKind::Wifi: + InitializeWifi(); + break; + case ShimKind::Lobby: + InitializeLobby(); + break; + default: + UNREACHABLE_MSG("Invalid ShimKind={}", web_arg_header.shim_kind); + break; + } } bool WebBrowser::TransactionComplete() const { @@ -30,9 +152,110 @@ ResultCode WebBrowser::GetStatus() const { } void WebBrowser::ExecuteInteractive() { - UNIMPLEMENTED_MSG("Unexpected interactive data recieved!"); + UNIMPLEMENTED_MSG("WebSession is not implemented"); } -void WebBrowser::Execute() {} +void WebBrowser::Execute() { + switch (web_arg_header.shim_kind) { + case ShimKind::Shop: + ExecuteShop(); + break; + case ShimKind::Login: + ExecuteLogin(); + break; + case ShimKind::Offline: + ExecuteOffline(); + break; + case ShimKind::Share: + ExecuteShare(); + break; + case ShimKind::Web: + ExecuteWeb(); + break; + case ShimKind::Wifi: + ExecuteWifi(); + break; + case ShimKind::Lobby: + ExecuteLobby(); + break; + default: + UNREACHABLE_MSG("Invalid ShimKind={}", web_arg_header.shim_kind); + WebBrowserExit(WebExitReason::EndButtonPressed); + break; + } +} + +void WebBrowser::WebBrowserExit(WebExitReason exit_reason, std::string last_url) { + if ((web_arg_header.shim_kind == ShimKind::Share && + web_applet_version >= WebAppletVersion::Version196608) || + (web_arg_header.shim_kind == ShimKind::Web && + web_applet_version >= WebAppletVersion::Version524288)) { + // TODO: Push Output TLVs instead of a WebCommonReturnValue + } + + WebCommonReturnValue web_common_return_value; + + web_common_return_value.exit_reason = exit_reason; + std::memcpy(&web_common_return_value.last_url, last_url.data(), last_url.size()); + web_common_return_value.last_url_size = last_url.size(); + + LOG_DEBUG(Service_AM, "WebCommonReturnValue: exit_reason={}, last_url={}, last_url_size={}", + exit_reason, last_url, last_url.size()); + + complete = true; + std::vector out_data(sizeof(WebCommonReturnValue)); + std::memcpy(out_data.data(), &web_common_return_value, out_data.size()); + broker.PushNormalDataFromApplet(std::make_shared(system, std::move(out_data))); + broker.SignalStateChanged(); +} + +void WebBrowser::InitializeShop() {} + +void WebBrowser::InitializeLogin() {} + +void WebBrowser::InitializeOffline() {} + +void WebBrowser::InitializeShare() {} + +void WebBrowser::InitializeWeb() {} + +void WebBrowser::InitializeWifi() {} + +void WebBrowser::InitializeLobby() {} + +void WebBrowser::ExecuteShop() { + LOG_WARNING(Service_AM, "(STUBBED) called, Shop Applet is not implemented"); + WebBrowserExit(WebExitReason::EndButtonPressed); +} + +void WebBrowser::ExecuteLogin() { + LOG_WARNING(Service_AM, "(STUBBED) called, Login Applet is not implemented"); + WebBrowserExit(WebExitReason::EndButtonPressed); +} + +void WebBrowser::ExecuteOffline() { + LOG_WARNING(Service_AM, "(STUBBED) called, Offline Applet is not implemented"); + WebBrowserExit(WebExitReason::EndButtonPressed); +} + +void WebBrowser::ExecuteShare() { + LOG_WARNING(Service_AM, "(STUBBED) called, Share Applet is not implemented"); + WebBrowserExit(WebExitReason::EndButtonPressed); +} + +void WebBrowser::ExecuteWeb() { + LOG_WARNING(Service_AM, "(STUBBED) called, Web Applet is not implemented"); + WebBrowserExit(WebExitReason::EndButtonPressed); +} + +void WebBrowser::ExecuteWifi() { + LOG_WARNING(Service_AM, "(STUBBED) called, Wifi Applet is not implemented"); + WebBrowserExit(WebExitReason::EndButtonPressed); +} + +void WebBrowser::ExecuteLobby() { + LOG_WARNING(Service_AM, "(STUBBED) called, Lobby Applet is not implemented"); + WebBrowserExit(WebExitReason::EndButtonPressed); +} } // namespace Service::AM::Applets diff --git a/src/core/hle/service/am/applets/web_browser.h b/src/core/hle/service/am/applets/web_browser.h index 0584142e5..a1ed5fd1d 100644 --- a/src/core/hle/service/am/applets/web_browser.h +++ b/src/core/hle/service/am/applets/web_browser.h @@ -8,6 +8,7 @@ #include "common/common_types.h" #include "core/hle/result.h" #include "core/hle/service/am/applets/applets.h" +#include "core/hle/service/am/applets/web_types.h" namespace Core { class System; @@ -28,12 +29,36 @@ public: void ExecuteInteractive() override; void Execute() override; + void WebBrowserExit(WebExitReason exit_reason, std::string last_url = ""); + private: + // Initializers for the various types of browser applets + void InitializeShop(); + void InitializeLogin(); + void InitializeOffline(); + void InitializeShare(); + void InitializeWeb(); + void InitializeWifi(); + void InitializeLobby(); + + // Executors for the various types of browser applets + void ExecuteShop(); + void ExecuteLogin(); + void ExecuteOffline(); + void ExecuteShare(); + void ExecuteWeb(); + void ExecuteWifi(); + void ExecuteLobby(); + const Core::Frontend::WebBrowserApplet& frontend; bool complete{false}; ResultCode status{RESULT_SUCCESS}; + WebAppletVersion web_applet_version; + WebArgHeader web_arg_header; + WebArgInputTLVMap web_arg_input_tlv_map; + Core::System& system; }; diff --git a/src/core/hle/service/am/applets/web_types.h b/src/core/hle/service/am/applets/web_types.h new file mode 100644 index 000000000..419c2bf79 --- /dev/null +++ b/src/core/hle/service/am/applets/web_types.h @@ -0,0 +1,178 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include "common/common_funcs.h" +#include "common/common_types.h" +#include "common/swap.h" + +namespace Service::AM::Applets { + +enum class WebAppletVersion : u32_le { + Version0 = 0x0, // Only used by WifiWebAuthApplet + Version131072 = 0x20000, // 1.0.0 - 2.3.0 + Version196608 = 0x30000, // 3.0.0 - 4.1.0 + Version327680 = 0x50000, // 5.0.0 - 5.1.0 + Version393216 = 0x60000, // 6.0.0 - 7.0.1 + Version524288 = 0x80000, // 8.0.0+ +}; + +enum class ShimKind : u32 { + Shop = 1, + Login = 2, + Offline = 3, + Share = 4, + Web = 5, + Wifi = 6, + Lobby = 7, +}; + +enum class WebExitReason : u32 { + EndButtonPressed = 0, + BackButtonPressed = 1, + ExitRequested = 2, + CallbackURL = 3, + WindowClosed = 4, + ErrorDialog = 7, +}; + +enum class WebArgInputTLVType : u16 { + InitialURL = 0x1, + 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, + PlayReportEnabled = 0x13, + BootDisplayKind = 0x17, + BackgroundKind = 0x18, + FooterEnabled = 0x19, + PointerEnabled = 0x1A, + LeftStickMode = 0x1B, + KeyRepeatFrame1 = 0x1C, + KeyRepeatFrame2 = 0x1D, + BootAsMediaPlayerInverted = 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, + YouTubeVideoWhitelist = 0x31, + FooterFixedKind = 0x32, + PageFadeEnabled = 0x33, + MediaCreatorApplicationRatingAge = 0x34, + BootLoadingIconEnabled = 0x35, + PageScrollIndicatorEnabled = 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, + MediaPlayerOfflineEnabled = 0x43, +}; + +enum class WebArgOutputTLVType : u16 { + ShareExitReason = 0x1, + LastURL = 0x2, + LastURLSize = 0x3, + SharePostResult = 0x4, + PostServiceName = 0x5, + PostServiceNameSize = 0x6, + PostID = 0x7, + PostIDSize = 0x8, + MediaPlayerAutoClosedByCompletion = 0x9, +}; + +enum class DocumentKind : u32 { + OfflineHtmlPage = 1, + ApplicationLegalInformation = 2, + SystemDataPage = 3, +}; + +enum class ShareStartPage : u32 { + Default, + Settings, +}; + +enum class BootDisplayKind : u32 { + Default, + White, + Black, +}; + +enum class BackgroundKind : u32 { + Default, +}; + +enum class LeftStickMode : u32 { + Pointer, + Cursor, +}; + +enum class WebSessionBootMode : u32 { + AllForeground, + AllForegroundInitiallyHidden, +}; + +struct WebArgHeader { + u16 total_tlv_entries{}; + INSERT_PADDING_BYTES(2); + ShimKind shim_kind{}; +}; +static_assert(sizeof(WebArgHeader) == 0x8, "WebArgHeader has incorrect size."); + +struct WebArgInputTLV { + WebArgInputTLVType input_tlv_type{}; + u16 arg_data_size{}; + INSERT_PADDING_WORDS(1); +}; +static_assert(sizeof(WebArgInputTLV) == 0x8, "WebArgInputTLV has incorrect size."); + +struct WebArgOutputTLV { + WebArgOutputTLVType output_tlv_type{}; + u16 arg_data_size{}; + INSERT_PADDING_WORDS(1); +}; +static_assert(sizeof(WebArgOutputTLV) == 0x8, "WebArgOutputTLV has incorrect size."); + +struct WebCommonReturnValue { + WebExitReason exit_reason{}; + INSERT_PADDING_WORDS(1); + std::array last_url{}; + u64 last_url_size{}; +}; +static_assert(sizeof(WebCommonReturnValue) == 0x1010, "WebCommonReturnValue has incorrect size."); + +using WebArgInputTLVMap = std::unordered_map>; + +} // namespace Service::AM::Applets From 89df4835673a2c6b1905459b2aff866a6caeec4a Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 12 Nov 2020 12:23:46 -0500 Subject: [PATCH 03/16] applets/web: Implement the offline browser applet backend --- .../hle/service/am/applets/web_browser.cpp | 146 ++++++++++++++++-- src/core/hle/service/am/applets/web_browser.h | 10 ++ 2 files changed, 143 insertions(+), 13 deletions(-) diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index 7f398254e..06fcf3e3f 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -2,16 +2,26 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include - #include "common/assert.h" +#include "common/common_paths.h" +#include "common/file_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/patch_manager.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/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" namespace Service::AM::Applets { @@ -36,6 +46,16 @@ std::string ParseStringValue(const std::vector& data) { data.size()); } +std::string GetMainURL(const std::string& url) { + const auto index = url.find('?'); + + if (index == std::string::npos) { + return url; + } + + return url.substr(0, index); +} + WebArgInputTLVMap ReadWebArgs(const std::vector& web_arg, WebArgHeader& web_arg_header) { std::memcpy(&web_arg_header, web_arg.data(), sizeof(WebArgHeader)); @@ -72,15 +92,35 @@ WebArgInputTLVMap ReadWebArgs(const std::vector& web_arg, WebArgHeader& web_ return input_tlv_map; } -std::optional> GetInputTLVData(const WebArgInputTLVMap& input_tlv_map, - WebArgInputTLVType input_tlv_type) { - const auto map_it = input_tlv_map.find(input_tlv_type); +FileSys::VirtualFile GetOfflineRomFS(Core::System& system, u64 title_id, + FileSys::ContentRecordType nca_type) { + if (nca_type == FileSys::ContentRecordType::Data) { + const auto nca = + system.GetFileSystemController().GetSystemNANDContents()->GetEntry(title_id, nca_type); - if (map_it == input_tlv_map.end()) { - return std::nullopt; + if (nca == nullptr) { + LOG_ERROR(Service_AM, + "NCA of type={} with title_id={:016X} is not found in the System NAND!", + nca_type, title_id); + return FileSys::SystemArchive::SynthesizeSystemArchive(title_id); + } + + return nca->GetRomFS(); + } else { + const auto nca = system.GetContentProvider().GetEntry(title_id, nca_type); + + if (nca == nullptr) { + LOG_ERROR(Service_AM, + "NCA of type={} with title_id={:016X} is not found in the ContentProvider!", + nca_type, title_id); + return nullptr; + } + + const FileSys::PatchManager pm{title_id, system.GetFileSystemController(), + system.GetContentProvider()}; + + return pm.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(), nca_type); } - - return map_it->second; } } // namespace @@ -209,11 +249,92 @@ void WebBrowser::WebBrowserExit(WebExitReason exit_reason, std::string last_url) broker.SignalStateChanged(); } +bool WebBrowser::InputTLVExistsInMap(WebArgInputTLVType input_tlv_type) const { + return web_arg_input_tlv_map.find(input_tlv_type) != web_arg_input_tlv_map.end(); +} + +std::optional> WebBrowser::GetInputTLVData(WebArgInputTLVType input_tlv_type) { + const auto map_it = web_arg_input_tlv_map.find(input_tlv_type); + + if (map_it == web_arg_input_tlv_map.end()) { + return std::nullopt; + } + + return map_it->second; +} + void WebBrowser::InitializeShop() {} void WebBrowser::InitializeLogin() {} -void WebBrowser::InitializeOffline() {} +void WebBrowser::InitializeOffline() { + const auto document_path = + ParseStringValue(GetInputTLVData(WebArgInputTLVType::DocumentPath).value()); + + const auto document_kind = + ParseRawValue(GetInputTLVData(WebArgInputTLVType::DocumentKind).value()); + + u64 title_id{}; + FileSys::ContentRecordType nca_type{FileSys::ContentRecordType::HtmlDocument}; + std::string additional_paths; + + switch (document_kind) { + case DocumentKind::OfflineHtmlPage: + title_id = system.CurrentProcess()->GetTitleID(); + nca_type = FileSys::ContentRecordType::HtmlDocument; + additional_paths = "html-document"; + break; + case DocumentKind::ApplicationLegalInformation: + title_id = ParseRawValue(GetInputTLVData(WebArgInputTLVType::ApplicationID).value()); + nca_type = FileSys::ContentRecordType::LegalInformation; + break; + case DocumentKind::SystemDataPage: + title_id = ParseRawValue(GetInputTLVData(WebArgInputTLVType::SystemDataID).value()); + nca_type = FileSys::ContentRecordType::Data; + break; + } + + static constexpr std::array RESOURCE_TYPES{ + "manual", + "legal_information", + "system_data", + }; + + offline_cache_dir = Common::FS::SanitizePath( + fmt::format("{}/offline_web_applet_{}/{:016X}", + Common::FS::GetUserPath(Common::FS::UserPath::CacheDir), + RESOURCE_TYPES[static_cast(document_kind) - 1], title_id), + Common::FS::DirectorySeparator::PlatformDefault); + + offline_document = Common::FS::SanitizePath( + fmt::format("{}/{}/{}", offline_cache_dir, additional_paths, document_path), + Common::FS::DirectorySeparator::PlatformDefault); + + const auto main_url = Common::FS::SanitizePath(GetMainURL(offline_document), + Common::FS::DirectorySeparator::PlatformDefault); + + if (Common::FS::Exists(main_url)) { + return; + } + + auto offline_romfs = GetOfflineRomFS(system, title_id, nca_type); + + if (offline_romfs == nullptr) { + LOG_ERROR(Service_AM, "RomFS with title_id={:016X} and nca_type={} cannot be extracted!", + title_id, nca_type); + return; + } + + LOG_DEBUG(Service_AM, "Extracting RomFS to {}", offline_cache_dir); + + const auto extracted_romfs_dir = + FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard); + + const auto temp_dir = + system.GetFilesystem()->CreateDirectory(offline_cache_dir, FileSys::Mode::ReadWrite); + + FileSys::VfsRawCopyD(extracted_romfs_dir, temp_dir); +} void WebBrowser::InitializeShare() {} @@ -234,8 +355,8 @@ void WebBrowser::ExecuteLogin() { } void WebBrowser::ExecuteOffline() { - LOG_WARNING(Service_AM, "(STUBBED) called, Offline Applet is not implemented"); - WebBrowserExit(WebExitReason::EndButtonPressed); + LOG_INFO(Service_AM, "Opening offline document at {}", offline_document); + WebBrowserExit(WebExitReason::WindowClosed); } void WebBrowser::ExecuteShare() { @@ -257,5 +378,4 @@ void WebBrowser::ExecuteLobby() { LOG_WARNING(Service_AM, "(STUBBED) called, Lobby Applet is not implemented"); WebBrowserExit(WebExitReason::EndButtonPressed); } - } // namespace Service::AM::Applets diff --git a/src/core/hle/service/am/applets/web_browser.h b/src/core/hle/service/am/applets/web_browser.h index a1ed5fd1d..c36c717f1 100644 --- a/src/core/hle/service/am/applets/web_browser.h +++ b/src/core/hle/service/am/applets/web_browser.h @@ -4,6 +4,8 @@ #pragma once +#include + #include "common/common_funcs.h" #include "common/common_types.h" #include "core/hle/result.h" @@ -32,6 +34,10 @@ public: void WebBrowserExit(WebExitReason exit_reason, std::string last_url = ""); private: + bool InputTLVExistsInMap(WebArgInputTLVType input_tlv_type) const; + + std::optional> GetInputTLVData(WebArgInputTLVType input_tlv_type); + // Initializers for the various types of browser applets void InitializeShop(); void InitializeLogin(); @@ -56,9 +62,13 @@ private: ResultCode status{RESULT_SUCCESS}; WebAppletVersion web_applet_version; + WebExitReason web_exit_reason; WebArgHeader web_arg_header; WebArgInputTLVMap web_arg_input_tlv_map; + std::string offline_cache_dir; + std::string offline_document; + Core::System& system; }; From d6d1a8e02c99b369fdbd9df2d3bdb68832f3d614 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 15 Nov 2020 09:00:19 -0500 Subject: [PATCH 04/16] applets/web: Implement the default web browser applet frontend --- src/core/frontend/applets/web_browser.cpp | 8 ++++++++ src/core/frontend/applets/web_browser.h | 12 ++++++++++++ src/core/hle/service/am/applets/web_browser.cpp | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/core/frontend/applets/web_browser.cpp b/src/core/frontend/applets/web_browser.cpp index 58861809e..0e1612e27 100644 --- a/src/core/frontend/applets/web_browser.cpp +++ b/src/core/frontend/applets/web_browser.cpp @@ -11,4 +11,12 @@ WebBrowserApplet::~WebBrowserApplet() = default; DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default; +void DefaultWebBrowserApplet::OpenLocalWebPage( + std::string_view local_url, std::function callback) const { + LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open local web page at {}", + local_url); + + callback(WebExitReason::WindowClosed, "http://localhost/"); +} + } // namespace Core::Frontend diff --git a/src/core/frontend/applets/web_browser.h b/src/core/frontend/applets/web_browser.h index 6e5f4d93d..2ccefc68f 100644 --- a/src/core/frontend/applets/web_browser.h +++ b/src/core/frontend/applets/web_browser.h @@ -5,17 +5,29 @@ #pragma once #include +#include + +#include "core/hle/service/am/applets/web_types.h" + +using namespace Service::AM::Applets; namespace Core::Frontend { class WebBrowserApplet { public: virtual ~WebBrowserApplet(); + + virtual void OpenLocalWebPage( + std::string_view local_url, + std::function callback) const = 0; }; class DefaultWebBrowserApplet final : public WebBrowserApplet { public: ~DefaultWebBrowserApplet() override; + + void OpenLocalWebPage(std::string_view local_url, + std::function callback) const override; }; } // namespace Core::Frontend diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index 06fcf3e3f..c0c98ad30 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -356,7 +356,10 @@ void WebBrowser::ExecuteLogin() { void WebBrowser::ExecuteOffline() { LOG_INFO(Service_AM, "Opening offline document at {}", offline_document); - WebBrowserExit(WebExitReason::WindowClosed); + frontend.OpenLocalWebPage(offline_document, + [this](WebExitReason exit_reason, std::string last_url) { + WebBrowserExit(exit_reason, last_url); + }); } void WebBrowser::ExecuteShare() { From 51a7681957131e0018af5122b214994dd51f93e3 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Tue, 17 Nov 2020 00:33:38 -0500 Subject: [PATCH 05/16] bootmanager: Add a check whether loading is complete --- src/yuzu/bootmanager.cpp | 4 ++++ src/yuzu/bootmanager.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 489104d5f..55c60935e 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -569,6 +569,10 @@ void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_p layout); } +bool GRenderWindow::IsLoadingComplete() const { + return first_frame; +} + void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair minimal_size) { setMinimumSize(minimal_size.first, minimal_size.second); } diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index a6d788d40..ebe5cb965 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h @@ -162,6 +162,8 @@ public: /// Destroy the previous run's child_widget which should also destroy the child_window void ReleaseRenderTarget(); + bool IsLoadingComplete() const; + void CaptureScreenshot(u32 res_scale, const QString& screenshot_path); std::pair ScaleTouch(const QPointF& pos) const; From 5836786246464a16f1d122d1c9a7c8fcb1f0e272 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Mon, 23 Nov 2020 00:06:31 -0500 Subject: [PATCH 06/16] util: Add URL Request Interceptor for QWebEngine --- src/yuzu/CMakeLists.txt | 2 ++ src/yuzu/util/url_request_interceptor.cpp | 32 +++++++++++++++++++++++ src/yuzu/util/url_request_interceptor.h | 30 +++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/yuzu/util/url_request_interceptor.cpp create mode 100644 src/yuzu/util/url_request_interceptor.h diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index b16b54032..f3e527e94 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -141,6 +141,8 @@ add_executable(yuzu util/limitable_input_dialog.h util/sequence_dialog/sequence_dialog.cpp util/sequence_dialog/sequence_dialog.h + util/url_request_interceptor.cpp + util/url_request_interceptor.h util/util.cpp util/util.h compatdb.cpp diff --git a/src/yuzu/util/url_request_interceptor.cpp b/src/yuzu/util/url_request_interceptor.cpp new file mode 100644 index 000000000..2d491d8c0 --- /dev/null +++ b/src/yuzu/util/url_request_interceptor.cpp @@ -0,0 +1,32 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#ifdef YUZU_USE_QT_WEB_ENGINE + +#include "yuzu/util/url_request_interceptor.h" + +UrlRequestInterceptor::UrlRequestInterceptor(QObject* p) : QWebEngineUrlRequestInterceptor(p) {} + +UrlRequestInterceptor::~UrlRequestInterceptor() = default; + +void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { + const auto resource_type = info.resourceType(); + + switch (resource_type) { + case QWebEngineUrlRequestInfo::ResourceTypeMainFrame: + requested_url = info.requestUrl(); + emit FrameChanged(); + break; + case QWebEngineUrlRequestInfo::ResourceTypeSubFrame: + case QWebEngineUrlRequestInfo::ResourceTypeXhr: + emit FrameChanged(); + break; + } +} + +QUrl UrlRequestInterceptor::GetRequestedURL() const { + return requested_url; +} + +#endif diff --git a/src/yuzu/util/url_request_interceptor.h b/src/yuzu/util/url_request_interceptor.h new file mode 100644 index 000000000..8a7f7499f --- /dev/null +++ b/src/yuzu/util/url_request_interceptor.h @@ -0,0 +1,30 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#ifdef YUZU_USE_QT_WEB_ENGINE + +#include +#include + +class UrlRequestInterceptor : public QWebEngineUrlRequestInterceptor { + Q_OBJECT + +public: + explicit UrlRequestInterceptor(QObject* p = nullptr); + ~UrlRequestInterceptor() override; + + void interceptRequest(QWebEngineUrlRequestInfo& info) override; + + QUrl GetRequestedURL() const; + +signals: + void FrameChanged(); + +private: + QUrl requested_url; +}; + +#endif From 54ea3c47c8ec50c62126ef7e01c21efc0c19799b Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 25 Nov 2020 07:48:00 -0500 Subject: [PATCH 07/16] controllers/npad: Make press_state atomic --- src/core/hle/service/hid/controllers/npad.cpp | 2 +- src/core/hle/service/hid/controllers/npad.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index f6a0770bf..d280e7caf 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -1058,7 +1058,7 @@ void Controller_NPad::ClearAllControllers() { } u32 Controller_NPad::GetAndResetPressState() { - return std::exchange(press_state, 0); + return press_state.exchange(0); } bool Controller_NPad::IsControllerSupported(NPadControllerType controller) const { diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 9fac00231..e2e826623 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "common/bit_field.h" #include "common/common_types.h" #include "core/frontend/input.h" @@ -415,7 +416,7 @@ private: bool IsControllerSupported(NPadControllerType controller) const; void RequestPadStateUpdate(u32 npad_id); - u32 press_state{}; + std::atomic press_state{}; NpadStyleSet style{}; std::array shared_memory_entries{}; From f9653a4417665c208d96b4ee19394ace963adc66 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 25 Nov 2020 07:01:22 -0500 Subject: [PATCH 08/16] frontend/input_interpreter: Add InputInterpreter API The InputInterpreter class interfaces with HID to retrieve button press states. Input is intended to be polled every 50ms so that a button is considered to be held down after 400ms has elapsed since the initial button press and subsequent repeated presses occur every 50ms. Co-authored-by: Chloe <25727384+ogniK5377@users.noreply.github.com> --- src/core/CMakeLists.txt | 2 + src/core/frontend/input_interpreter.cpp | 45 +++++++++ src/core/frontend/input_interpreter.h | 120 ++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 src/core/frontend/input_interpreter.cpp create mode 100644 src/core/frontend/input_interpreter.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 949748178..56c165336 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -135,6 +135,8 @@ add_library(core STATIC frontend/emu_window.h frontend/framebuffer_layout.cpp frontend/framebuffer_layout.h + frontend/input_interpreter.cpp + frontend/input_interpreter.h frontend/input.h hardware_interrupt_manager.cpp hardware_interrupt_manager.h diff --git a/src/core/frontend/input_interpreter.cpp b/src/core/frontend/input_interpreter.cpp new file mode 100644 index 000000000..66ae506cd --- /dev/null +++ b/src/core/frontend/input_interpreter.cpp @@ -0,0 +1,45 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/core.h" +#include "core/frontend/input_interpreter.h" +#include "core/hle/service/hid/controllers/npad.h" +#include "core/hle/service/hid/hid.h" +#include "core/hle/service/sm/sm.h" + +InputInterpreter::InputInterpreter(Core::System& system) + : npad{system.ServiceManager() + .GetService("hid") + ->GetAppletResource() + ->GetController(Service::HID::HidController::NPad)} {} + +InputInterpreter::~InputInterpreter() = default; + +void InputInterpreter::PollInput() { + const u32 button_state = npad.GetAndResetPressState(); + + previous_index = current_index; + current_index = (current_index + 1) % button_states.size(); + + button_states[current_index] = button_state; +} + +bool InputInterpreter::IsButtonPressedOnce(HIDButton button) const { + const bool current_press = + (button_states[current_index] & (1U << static_cast(button))) != 0; + const bool previous_press = + (button_states[previous_index] & (1U << static_cast(button))) != 0; + + return current_press && !previous_press; +} + +bool InputInterpreter::IsButtonHeld(HIDButton button) const { + u32 held_buttons{button_states[0]}; + + for (std::size_t i = 1; i < button_states.size(); ++i) { + held_buttons &= button_states[i]; + } + + return (held_buttons & (1U << static_cast(button))) != 0; +} diff --git a/src/core/frontend/input_interpreter.h b/src/core/frontend/input_interpreter.h new file mode 100644 index 000000000..fea9aebe6 --- /dev/null +++ b/src/core/frontend/input_interpreter.h @@ -0,0 +1,120 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "common/common_types.h" + +namespace Core { +class System; +} + +namespace Service::HID { +class Controller_NPad; +} + +enum class HIDButton : u8 { + A, + B, + X, + Y, + LStick, + RStick, + L, + R, + ZL, + ZR, + Plus, + Minus, + + DLeft, + DUp, + DRight, + DDown, + + LStickLeft, + LStickUp, + LStickRight, + LStickDown, + + RStickLeft, + RStickUp, + RStickRight, + RStickDown, + + LeftSL, + LeftSR, + + RightSL, + RightSR, +}; + +/** + * The InputInterpreter class interfaces with HID to retrieve button press states. + * Input is intended to be polled every 50ms so that a button is considered to be + * held down after 400ms has elapsed since the initial button press and subsequent + * repeated presses occur every 50ms. + */ +class InputInterpreter { +public: + explicit InputInterpreter(Core::System& system); + virtual ~InputInterpreter(); + + /// Gets a button state from HID and inserts it into the array of button states. + void PollInput(); + + /** + * The specified button is considered to be pressed once + * if it is currently pressed and not pressed previously. + * + * @param button The button to check. + * + * @returns True when the button is pressed once. + */ + [[nodiscard]] bool IsButtonPressedOnce(HIDButton button) const; + + /** + * Checks whether any of the buttons in the parameter list is pressed once. + * + * @tparam HIDButton The buttons to check. + * + * @returns True when at least one of the buttons is pressed once. + */ + template + [[nodiscard]] bool IsAnyButtonPressedOnce() { + return (IsButtonPressedOnce(T) || ...); + } + + /** + * The specified button is considered to be held down if it is pressed in all 9 button states. + * + * @param button The button to check. + * + * @returns True when the button is held down. + */ + [[nodiscard]] bool IsButtonHeld(HIDButton button) const; + + /** + * Checks whether any of the buttons in the parameter list is held down. + * + * @tparam HIDButton The buttons to check. + * + * @returns True when at least one of the buttons is held down. + */ + template + [[nodiscard]] bool IsAnyButtonHeld() { + return (IsButtonHeld(T) || ...); + } + +private: + Service::HID::Controller_NPad& npad; + + /// Stores 9 consecutive button states polled from HID. + std::array button_states{}; + + std::size_t previous_index{}; + std::size_t current_index{}; +}; From 46183294b2d0db8795ea8441d1942ba32c6ebb00 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 29 Nov 2020 03:47:10 -0500 Subject: [PATCH 09/16] ns_vm: Stub NeedsUpdateVulnerability This is used to force system updates on launching the web browser. We do not care about system updates so this can be set to false. --- src/core/hle/service/ns/ns.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index ef7584641..6ccf8995c 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -673,7 +673,7 @@ public: explicit NS_VM(Core::System& system_) : ServiceFramework{system_, "ns:vm"} { // clang-format off static const FunctionInfo functions[] = { - {1200, nullptr, "NeedsUpdateVulnerability"}, + {1200, &NS_VM::NeedsUpdateVulnerability, "NeedsUpdateVulnerability"}, {1201, nullptr, "UpdateSafeSystemVersionForDebug"}, {1202, nullptr, "GetSafeSystemVersion"}, }; @@ -681,6 +681,15 @@ public: RegisterHandlers(functions); } + +private: + void NeedsUpdateVulnerability(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service_NS, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(false); + } }; void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { From d46ca5a0157a5267b4c2ebf0515f1a492434071a Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 29 Nov 2020 10:54:09 -0500 Subject: [PATCH 10/16] pl_u, applets/web: Decrypt shared fonts to TTF files --- .../hle/service/am/applets/web_browser.cpp | 86 +++++++++++++++++++ src/core/hle/service/ns/pl_u.cpp | 30 +++---- src/core/hle/service/ns/pl_u.h | 19 ++++ 3 files changed, 117 insertions(+), 18 deletions(-) diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index c0c98ad30..02ce9f387 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -16,12 +16,14 @@ #include "core/file_sys/romfs.h" #include "core/file_sys/system_archive/system_archive.h" #include "core/file_sys/vfs_types.h" +#include "core/file_sys/vfs_vector.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/hle/service/ns/pl_u.h" namespace Service::AM::Applets { @@ -123,6 +125,88 @@ FileSys::VirtualFile GetOfflineRomFS(Core::System& system, u64 title_id, } } +void ExtractSharedFonts(Core::System& system) { + static constexpr std::array DECRYPTED_SHARED_FONTS{ + "FontStandard.ttf", + "FontChineseSimplified.ttf", + "FontExtendedChineseSimplified.ttf", + "FontChineseTraditional.ttf", + "FontKorean.ttf", + "FontNintendoExtended.ttf", + "FontNintendoExtended2.ttf", + }; + + for (std::size_t i = 0; i < NS::SHARED_FONTS.size(); ++i) { + const auto fonts_dir = Common::FS::SanitizePath( + fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)), + Common::FS::DirectorySeparator::PlatformDefault); + + const auto font_file_path = + Common::FS::SanitizePath(fmt::format("{}/{}", fonts_dir, DECRYPTED_SHARED_FONTS[i]), + Common::FS::DirectorySeparator::PlatformDefault); + + if (Common::FS::Exists(font_file_path)) { + continue; + } + + const auto font = NS::SHARED_FONTS[i]; + const auto font_title_id = static_cast(font.first); + + const auto nca = system.GetFileSystemController().GetSystemNANDContents()->GetEntry( + font_title_id, FileSys::ContentRecordType::Data); + + FileSys::VirtualFile romfs; + + if (!nca) { + romfs = FileSys::SystemArchive::SynthesizeSystemArchive(font_title_id); + } else { + romfs = nca->GetRomFS(); + } + + if (!romfs) { + LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} cannot be extracted!", + font_title_id); + continue; + } + + const auto extracted_romfs = FileSys::ExtractRomFS(romfs); + + if (!extracted_romfs) { + LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} failed to extract!", + font_title_id); + continue; + } + + const auto font_file = extracted_romfs->GetFile(font.second); + + if (!font_file) { + LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} has no font file \"{}\"!", + font_title_id, font.second); + continue; + } + + std::vector font_data_u32(font_file->GetSize() / sizeof(u32)); + font_file->ReadBytes(font_data_u32.data(), font_file->GetSize()); + + std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(), + Common::swap32); + + std::vector decrypted_data(font_file->GetSize() - 8); + + NS::DecryptSharedFontToTTF(font_data_u32, decrypted_data); + + FileSys::VirtualFile decrypted_font = std::make_shared( + std::move(decrypted_data), DECRYPTED_SHARED_FONTS[i]); + + const auto temp_dir = + system.GetFilesystem()->CreateDirectory(fonts_dir, FileSys::Mode::ReadWrite); + + const auto out_file = temp_dir->CreateFile(DECRYPTED_SHARED_FONTS[i]); + + FileSys::VfsRawCopy(decrypted_font, out_file); + } +} + } // namespace WebBrowser::WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_) @@ -155,6 +239,8 @@ void WebBrowser::Initialize() { LOG_DEBUG(Service_AM, "WebArgHeader: total_tlv_entries={}, shim_kind={}", web_arg_header.total_tlv_entries, web_arg_header.shim_kind); + ExtractSharedFonts(system); + switch (web_arg_header.shim_kind) { case ShimKind::Shop: InitializeShop(); diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index c8a215845..71c7587db 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp @@ -27,29 +27,11 @@ namespace Service::NS { -enum class FontArchives : u64 { - Extension = 0x0100000000000810, - Standard = 0x0100000000000811, - Korean = 0x0100000000000812, - ChineseTraditional = 0x0100000000000813, - ChineseSimple = 0x0100000000000814, -}; - struct FontRegion { u32 offset; u32 size; }; -constexpr std::array, 7> SHARED_FONTS{ - std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"), - std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"), - std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"), - std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"), - std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"), - std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"), - std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"), -}; - // The below data is specific to shared font data dumped from Switch on f/w 2.2 // Virtual address and offsets/sizes likely will vary by dump [[maybe_unused]] constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; @@ -80,6 +62,18 @@ static void DecryptSharedFont(const std::vector& input, Kernel::PhysicalMem offset += transformed_font.size() * sizeof(u32); } +void DecryptSharedFontToTTF(const std::vector& input, std::vector& output) { + ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number"); + + const u32 KEY = input[0] ^ EXPECTED_RESULT; // Derive key using an inverse xor + std::vector transformed_font(input.size()); + // TODO(ogniK): Figure out a better way to do this + std::transform(input.begin(), input.end(), transformed_font.begin(), + [&KEY](u32 font_data) { return Common::swap32(font_data ^ KEY); }); + transformed_font[1] = Common::swap32(transformed_font[1]) ^ KEY; // "re-encrypt" the size + std::memcpy(output.data(), transformed_font.data() + 2, transformed_font.size() * sizeof(u32)); +} + void EncryptSharedFont(const std::vector& input, std::vector& output, std::size_t& offset) { ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE, diff --git a/src/core/hle/service/ns/pl_u.h b/src/core/hle/service/ns/pl_u.h index 224dcb997..f920c7f69 100644 --- a/src/core/hle/service/ns/pl_u.h +++ b/src/core/hle/service/ns/pl_u.h @@ -16,6 +16,25 @@ class FileSystemController; namespace NS { +enum class FontArchives : u64 { + Extension = 0x0100000000000810, + Standard = 0x0100000000000811, + Korean = 0x0100000000000812, + ChineseTraditional = 0x0100000000000813, + ChineseSimple = 0x0100000000000814, +}; + +constexpr std::array, 7> SHARED_FONTS{ + std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"), + std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"), + std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"), + std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"), + std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"), + std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"), + std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"), +}; + +void DecryptSharedFontToTTF(const std::vector& input, std::vector& output); void EncryptSharedFont(const std::vector& input, std::vector& output, std::size_t& offset); class PL_U final : public ServiceFramework { From d5e0923e3d4152581a75b1ce0d6e06c1758b7e44 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Mon, 30 Nov 2020 08:09:00 -0500 Subject: [PATCH 11/16] web_browser_scripts: Add injection scripts for the web browser --- src/yuzu/applets/web_browser_scripts.h | 193 +++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 src/yuzu/applets/web_browser_scripts.h diff --git a/src/yuzu/applets/web_browser_scripts.h b/src/yuzu/applets/web_browser_scripts.h new file mode 100644 index 000000000..992837a85 --- /dev/null +++ b/src/yuzu/applets/web_browser_scripts.h @@ -0,0 +1,193 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +constexpr char NX_FONT_CSS[] = R"( +(function() { + css = document.createElement('style'); + css.type = 'text/css'; + css.id = 'nx_font'; + css.innerText = ` +/* FontStandard */ +@font-face { + font-family: 'FontStandard'; + src: url('%1') format('truetype'); +} + +/* FontChineseSimplified */ +@font-face { + font-family: 'FontChineseSimplified'; + src: url('%2') format('truetype'); +} + +/* FontExtendedChineseSimplified */ +@font-face { + font-family: 'FontExtendedChineseSimplified'; + src: url('%3') format('truetype'); +} + +/* FontChineseTraditional */ +@font-face { + font-family: 'FontChineseTraditional'; + src: url('%4') format('truetype'); +} + +/* FontKorean */ +@font-face { + font-family: 'FontKorean'; + src: url('%5') format('truetype'); +} + +/* FontNintendoExtended */ +@font-face { + font-family: 'NintendoExt003'; + src: url('%6') format('truetype'); +} + +/* FontNintendoExtended2 */ +@font-face { + font-family: 'NintendoExt003'; + src: url('%7') format('truetype'); +} +`; + + document.head.appendChild(css); +})(); +)"; + +constexpr char LOAD_NX_FONT[] = R"( +(function() { + var elements = document.querySelectorAll("*"); + + for (var i = 0; i < elements.length; i++) { + var style = window.getComputedStyle(elements[i], null); + if (style.fontFamily.includes("Arial") || style.fontFamily.includes("Calibri") || + style.fontFamily.includes("Century") || style.fontFamily.includes("Times New Roman")) { + elements[i].style.fontFamily = "FontStandard, FontChineseSimplified, FontExtendedChineseSimplified, FontChineseTraditional, FontKorean, NintendoExt003"; + } else { + elements[i].style.fontFamily = style.fontFamily + ", FontStandard, FontChineseSimplified, FontExtendedChineseSimplified, FontChineseTraditional, FontKorean, NintendoExt003"; + } + } +})(); +)"; + +constexpr char GAMEPAD_SCRIPT[] = R"( +window.addEventListener("gamepadconnected", function(e) { + console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.", + e.gamepad.index, e.gamepad.id, e.gamepad.buttons.length, e.gamepad.axes.length); +}); + +window.addEventListener("gamepaddisconnected", function(e) { + console.log("Gamepad disconnected from index %d: %s", e.gamepad.index, e.gamepad.id); +}); +)"; + +constexpr char WINDOW_NX_SCRIPT[] = R"( +var end_applet = false; +var yuzu_key_callbacks = []; + +(function() { + class WindowNX { + constructor() { + yuzu_key_callbacks[1] = function() { window.history.back(); }; + yuzu_key_callbacks[2] = function() { window.nx.endApplet(); }; + } + + addEventListener(type, listener, options) { + console.log("nx.addEventListener called, type=%s", type); + + window.addEventListener(type, listener, options); + } + + endApplet() { + console.log("nx.endApplet called"); + + end_applet = true; + } + + playSystemSe(system_se) { + console.log("nx.playSystemSe is not implemented, system_se=%s", system_se); + } + + sendMessage(message) { + console.log("nx.sendMessage is not implemented, message=%s", message); + } + + setCursorScrollSpeed(scroll_speed) { + console.log("nx.setCursorScrollSpeed is not implemented, scroll_speed=%d", scroll_speed); + } + } + + class WindowNXFooter { + setAssign(key, label, func, option) { + console.log("nx.footer.setAssign called, key=%s", key); + + 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; + } + } + + setFixed(kind) { + console.log("nx.footer.setFixed is not implemented, kind=%s", kind); + } + + unsetAssign(key) { + console.log("nx.footer.unsetAssign called, key=%s", key); + + switch (key) { + case "A": + yuzu_key_callbacks[0] = function() {}; + break; + case "B": + yuzu_key_callbacks[1] = function() {}; + break; + case "X": + yuzu_key_callbacks[2] = function() {}; + break; + case "Y": + yuzu_key_callbacks[3] = function() {}; + break; + case "L": + yuzu_key_callbacks[6] = function() {}; + break; + case "R": + yuzu_key_callbacks[7] = function() {}; + break; + } + } + } + + class WindowNXPlayReport { + incrementCounter(counter_id) { + console.log("nx.playReport.incrementCounter is not implemented, counter_id=%d", counter_id); + } + + setCounterSetIdentifier(counter_id) { + console.log("nx.playReport.setCounterSetIdentifier is not implemented, counter_id=%d", counter_id); + } + } + + window.nx = new WindowNX(); + window.nx.footer = new WindowNXFooter(); + window.nx.playReport = new WindowNXPlayReport(); +})(); +)"; From 93cb7838539075f0d94cb08a65a25b0c05589d7d Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Mon, 30 Nov 2020 08:31:26 -0500 Subject: [PATCH 12/16] applets/web: Implement the Qt web browser applet frontend --- src/yuzu/applets/web_browser.cpp | 337 ++++++++++++++++++++++++++++++- src/yuzu/applets/web_browser.h | 155 +++++++++++++- src/yuzu/main.cpp | 110 +++++++++- src/yuzu/main.h | 7 + 4 files changed, 602 insertions(+), 7 deletions(-) diff --git a/src/yuzu/applets/web_browser.cpp b/src/yuzu/applets/web_browser.cpp index 92b53fed0..26b9df51a 100644 --- a/src/yuzu/applets/web_browser.cpp +++ b/src/yuzu/applets/web_browser.cpp @@ -2,10 +2,339 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "core/hle/lock.h" -#include "yuzu/applets/web_browser.h" -#include "yuzu/main.h" +#ifdef YUZU_USE_QT_WEB_ENGINE +#include -QtWebBrowser::QtWebBrowser(GMainWindow& main_window) {} +#include +#include +#include +#include +#include +#endif + +#include "common/file_util.h" +#include "core/core.h" +#include "core/frontend/input_interpreter.h" +#include "yuzu/applets/web_browser.h" +#include "yuzu/applets/web_browser_scripts.h" +#include "yuzu/main.h" +#include "yuzu/util/url_request_interceptor.h" + +#ifdef YUZU_USE_QT_WEB_ENGINE + +namespace { + +constexpr int HIDButtonToKey(HIDButton button) { + switch (button) { + case HIDButton::DLeft: + case HIDButton::LStickLeft: + return Qt::Key_Left; + case HIDButton::DUp: + case HIDButton::LStickUp: + return Qt::Key_Up; + case HIDButton::DRight: + case HIDButton::LStickRight: + return Qt::Key_Right; + case HIDButton::DDown: + case HIDButton::LStickDown: + return Qt::Key_Down; + default: + return 0; + } +} + +} // Anonymous namespace + +QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system) + : QWebEngineView(parent), url_interceptor(std::make_unique()), + input_interpreter(std::make_unique(system)) { + QWebEngineScript nx_font_css; + QWebEngineScript load_nx_font; + QWebEngineScript gamepad; + QWebEngineScript window_nx; + + const QString fonts_dir = QString::fromStdString(Common::FS::SanitizePath( + fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)))); + + nx_font_css.setName(QStringLiteral("nx_font_css.js")); + load_nx_font.setName(QStringLiteral("load_nx_font.js")); + gamepad.setName(QStringLiteral("gamepad_script.js")); + window_nx.setName(QStringLiteral("window_nx_script.js")); + + nx_font_css.setSourceCode( + QString::fromStdString(NX_FONT_CSS) + .arg(fonts_dir + QStringLiteral("/FontStandard.ttf")) + .arg(fonts_dir + QStringLiteral("/FontChineseSimplified.ttf")) + .arg(fonts_dir + QStringLiteral("/FontExtendedChineseSimplified.ttf")) + .arg(fonts_dir + QStringLiteral("/FontChineseTraditional.ttf")) + .arg(fonts_dir + QStringLiteral("/FontKorean.ttf")) + .arg(fonts_dir + QStringLiteral("/FontNintendoExtended.ttf")) + .arg(fonts_dir + QStringLiteral("/FontNintendoExtended2.ttf"))); + load_nx_font.setSourceCode(QString::fromStdString(LOAD_NX_FONT)); + gamepad.setSourceCode(QString::fromStdString(GAMEPAD_SCRIPT)); + window_nx.setSourceCode(QString::fromStdString(WINDOW_NX_SCRIPT)); + + nx_font_css.setInjectionPoint(QWebEngineScript::DocumentReady); + load_nx_font.setInjectionPoint(QWebEngineScript::Deferred); + gamepad.setInjectionPoint(QWebEngineScript::DocumentCreation); + window_nx.setInjectionPoint(QWebEngineScript::DocumentCreation); + + nx_font_css.setWorldId(QWebEngineScript::MainWorld); + load_nx_font.setWorldId(QWebEngineScript::MainWorld); + gamepad.setWorldId(QWebEngineScript::MainWorld); + window_nx.setWorldId(QWebEngineScript::MainWorld); + + nx_font_css.setRunsOnSubFrames(true); + load_nx_font.setRunsOnSubFrames(true); + gamepad.setRunsOnSubFrames(true); + window_nx.setRunsOnSubFrames(true); + + auto* default_profile = QWebEngineProfile::defaultProfile(); + + default_profile->scripts()->insert(nx_font_css); + default_profile->scripts()->insert(load_nx_font); + default_profile->scripts()->insert(gamepad); + default_profile->scripts()->insert(window_nx); + + default_profile->setRequestInterceptor(url_interceptor.get()); + + auto* global_settings = QWebEngineSettings::globalSettings(); + + global_settings->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true); + global_settings->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true); + global_settings->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, true); + global_settings->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, true); + global_settings->setAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript, true); + global_settings->setAttribute(QWebEngineSettings::ShowScrollBars, false); + + connect( + url_interceptor.get(), &UrlRequestInterceptor::FrameChanged, url_interceptor.get(), + [this] { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + page()->runJavaScript(QString::fromStdString(LOAD_NX_FONT)); + }, + Qt::QueuedConnection); + + connect( + page(), &QWebEnginePage::windowCloseRequested, page(), + [this] { + if (page()->url() == url_interceptor->GetRequestedURL()) { + SetFinished(true); + SetExitReason(WebExitReason::WindowClosed); + } + }, + Qt::QueuedConnection); +} + +QtNXWebEngineView::~QtNXWebEngineView() { + SetFinished(true); + StopInputThread(); +} + +void QtNXWebEngineView::LoadLocalWebPage(std::string_view main_url, + std::string_view additional_args) { + SetUserAgent(UserAgent::WebApplet); + SetFinished(false); + SetExitReason(WebExitReason::EndButtonPressed); + SetLastURL("http://localhost/"); + StartInputThread(); + + load(QUrl(QUrl::fromLocalFile(QString::fromStdString(std::string(main_url))).toString() + + QString::fromStdString(std::string(additional_args)))); +} + +void QtNXWebEngineView::SetUserAgent(UserAgent user_agent) { + const QString user_agent_str = [user_agent] { + switch (user_agent) { + case UserAgent::WebApplet: + default: + return QStringLiteral("WebApplet"); + case UserAgent::ShopN: + return QStringLiteral("ShopN"); + case UserAgent::LoginApplet: + return QStringLiteral("LoginApplet"); + case UserAgent::ShareApplet: + return QStringLiteral("ShareApplet"); + case UserAgent::LobbyApplet: + return QStringLiteral("LobbyApplet"); + case UserAgent::WifiWebAuthApplet: + return QStringLiteral("WifiWebAuthApplet"); + } + }(); + + QWebEngineProfile::defaultProfile()->setHttpUserAgent( + QStringLiteral("Mozilla/5.0 (Nintendo Switch; %1) AppleWebKit/606.4 " + "(KHTML, like Gecko) NF/6.0.1.15.4 NintendoBrowser/5.1.0.20389") + .arg(user_agent_str)); +} + +bool QtNXWebEngineView::IsFinished() const { + return finished; +} + +void QtNXWebEngineView::SetFinished(bool finished_) { + finished = finished_; +} + +WebExitReason QtNXWebEngineView::GetExitReason() const { + return exit_reason; +} + +void QtNXWebEngineView::SetExitReason(WebExitReason exit_reason_) { + exit_reason = exit_reason_; +} + +const std::string& QtNXWebEngineView::GetLastURL() const { + return last_url; +} + +void QtNXWebEngineView::SetLastURL(std::string last_url_) { + last_url = std::move(last_url_); +} + +QString QtNXWebEngineView::GetCurrentURL() const { + return url_interceptor->GetRequestedURL().toString(); +} + +void QtNXWebEngineView::hide() { + SetFinished(true); + StopInputThread(); + + QWidget::hide(); +} + +template +void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() { + const auto f = [this](HIDButton button) { + if (input_interpreter->IsButtonPressedOnce(button)) { + page()->runJavaScript( + QStringLiteral("yuzu_key_callbacks[%1] == null;").arg(static_cast(button)), + [&](const QVariant& variant) { + if (variant.toBool()) { + switch (button) { + case HIDButton::A: + SendMultipleKeyPressEvents(); + break; + case HIDButton::B: + SendKeyPressEvent(Qt::Key_B); + break; + case HIDButton::X: + SendKeyPressEvent(Qt::Key_X); + break; + case HIDButton::Y: + SendKeyPressEvent(Qt::Key_Y); + break; + default: + break; + } + } + }); + + page()->runJavaScript( + QStringLiteral("if (yuzu_key_callbacks[%1] != null) { yuzu_key_callbacks[%1](); }") + .arg(static_cast(button))); + } + }; + + (f(T), ...); +} + +template +void QtNXWebEngineView::HandleWindowKeyButtonPressedOnce() { + const auto f = [this](HIDButton button) { + if (input_interpreter->IsButtonPressedOnce(button)) { + SendKeyPressEvent(HIDButtonToKey(button)); + } + }; + + (f(T), ...); +} + +template +void QtNXWebEngineView::HandleWindowKeyButtonHold() { + const auto f = [this](HIDButton button) { + if (input_interpreter->IsButtonHeld(button)) { + SendKeyPressEvent(HIDButtonToKey(button)); + } + }; + + (f(T), ...); +} + +void QtNXWebEngineView::SendKeyPressEvent(int key) { + if (key == 0) { + return; + } + + QCoreApplication::postEvent(focusProxy(), + new QKeyEvent(QKeyEvent::KeyPress, key, Qt::NoModifier)); + QCoreApplication::postEvent(focusProxy(), + new QKeyEvent(QKeyEvent::KeyRelease, key, Qt::NoModifier)); +} + +void QtNXWebEngineView::StartInputThread() { + if (input_thread_running) { + return; + } + + input_thread_running = true; + input_thread = std::thread(&QtNXWebEngineView::InputThread, this); +} + +void QtNXWebEngineView::StopInputThread() { + input_thread_running = false; + if (input_thread.joinable()) { + input_thread.join(); + } +} + +void QtNXWebEngineView::InputThread() { + // Wait for 1 second before allowing any inputs to be processed. + std::this_thread::sleep_for(std::chrono::seconds(1)); + + while (input_thread_running) { + input_interpreter->PollInput(); + + HandleWindowFooterButtonPressedOnce(); + + HandleWindowKeyButtonPressedOnce(); + + HandleWindowKeyButtonHold(); + + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } +} + +#endif + +QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { + connect(this, &QtWebBrowser::MainWindowOpenLocalWebPage, &main_window, + &GMainWindow::WebBrowserOpenLocalWebPage, Qt::QueuedConnection); + connect(&main_window, &GMainWindow::WebBrowserClosed, this, + &QtWebBrowser::MainWindowWebBrowserClosed, Qt::QueuedConnection); +} QtWebBrowser::~QtWebBrowser() = default; + +void QtWebBrowser::OpenLocalWebPage( + std::string_view local_url, std::function callback) const { + this->callback = std::move(callback); + + const auto index = local_url.find('?'); + + if (index == std::string::npos) { + emit MainWindowOpenLocalWebPage(local_url, ""); + } else { + emit MainWindowOpenLocalWebPage(local_url.substr(0, index), local_url.substr(index)); + } +} + +void QtWebBrowser::MainWindowWebBrowserClosed(WebExitReason exit_reason, std::string last_url) { + callback(exit_reason, last_url); +} diff --git a/src/yuzu/applets/web_browser.h b/src/yuzu/applets/web_browser.h index af053ace7..74f2b49d2 100644 --- a/src/yuzu/applets/web_browser.h +++ b/src/yuzu/applets/web_browser.h @@ -4,6 +4,10 @@ #pragma once +#include +#include +#include + #include #ifdef YUZU_USE_QT_WEB_ENGINE @@ -12,12 +16,161 @@ #include "core/frontend/applets/web_browser.h" +enum class HIDButton : u8; + +class InputInterpreter; class GMainWindow; +class UrlRequestInterceptor; + +namespace Core { +class System; +} + +#ifdef YUZU_USE_QT_WEB_ENGINE + +enum class UserAgent { + WebApplet, + ShopN, + LoginApplet, + ShareApplet, + LobbyApplet, + WifiWebAuthApplet, +}; + +class QtNXWebEngineView : public QWebEngineView { + Q_OBJECT + +public: + explicit QtNXWebEngineView(QWidget* parent, Core::System& system); + ~QtNXWebEngineView() override; + + /** + * Loads a HTML document that exists locally. Cannot be used to load external websites. + * + * @param main_url The url to the file. + * @param additional_args Additional arguments appended to the main url. + */ + void LoadLocalWebPage(std::string_view main_url, std::string_view additional_args); + + /** + * Sets the background color of the web page. + * + * @param color The color to set. + */ + void SetBackgroundColor(QColor color); + + /** + * Sets the user agent of the web browser. + * + * @param user_agent The user agent enum. + */ + void SetUserAgent(UserAgent user_agent); + + [[nodiscard]] bool IsFinished() const; + void SetFinished(bool finished_); + + [[nodiscard]] WebExitReason GetExitReason() const; + void SetExitReason(WebExitReason exit_reason_); + + [[nodiscard]] const std::string& GetLastURL() const; + void SetLastURL(std::string last_url_); + + /** + * This gets the current URL that has been requested by the webpage. + * This only applies to the main frame. Sub frames and other resources are ignored. + * + * @return Currently requested URL + */ + [[nodiscard]] QString GetCurrentURL() const; + +public slots: + void hide(); + +private: + /** + * Handles button presses to execute functions assigned in yuzu_key_callbacks. + * yuzu_key_callbacks contains specialized functions for the buttons in the window footer + * that can be overriden by games to achieve desired functionality. + * + * @tparam HIDButton The list of buttons contained in yuzu_key_callbacks + */ + template + void HandleWindowFooterButtonPressedOnce(); + + /** + * Handles button presses and converts them into keyboard input. + * This should only be used to convert D-Pad or Analog Stick input into arrow keys. + * + * @tparam HIDButton The list of buttons that can be converted into keyboard input. + */ + template + void HandleWindowKeyButtonPressedOnce(); + + /** + * Handles button holds and converts them into keyboard input. + * This should only be used to convert D-Pad or Analog Stick input into arrow keys. + * + * @tparam HIDButton The list of buttons that can be converted into keyboard input. + */ + template + void HandleWindowKeyButtonHold(); + + /** + * Sends a key press event to QWebEngineView. + * + * @param key Qt key code. + */ + void SendKeyPressEvent(int key); + + /** + * Sends multiple key press events to QWebEngineView. + * + * @tparam int Qt key code. + */ + template + void SendMultipleKeyPressEvents() { + (SendKeyPressEvent(T), ...); + } + + void StartInputThread(); + void StopInputThread(); + + /// The thread where input is being polled and processed. + void InputThread(); + + std::unique_ptr url_interceptor; + + std::unique_ptr input_interpreter; + + std::thread input_thread; + + std::atomic input_thread_running{}; + + std::atomic finished{}; + + WebExitReason exit_reason{WebExitReason::EndButtonPressed}; + + std::string last_url{"http://localhost/"}; +}; + +#endif class QtWebBrowser final : public QObject, public Core::Frontend::WebBrowserApplet { Q_OBJECT public: - explicit QtWebBrowser(GMainWindow& main_window); + explicit QtWebBrowser(GMainWindow& parent); ~QtWebBrowser() override; + + void OpenLocalWebPage(std::string_view local_url, + std::function callback) const override; + +signals: + void MainWindowOpenLocalWebPage(std::string_view main_url, + std::string_view additional_args) const; + +private: + void MainWindowWebBrowserClosed(WebExitReason exit_reason, std::string last_url); + + mutable std::function callback; }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 7d4bba854..bab76db1e 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -28,8 +28,6 @@ #include "core/hle/service/am/applet_ae.h" #include "core/hle/service/am/applet_oe.h" #include "core/hle/service/am/applets/applets.h" -#include "core/hle/service/hid/controllers/npad.h" -#include "core/hle/service/hid/hid.h" // These are wrappers to avoid the calls to CreateDirectory and CreateFile because of the Windows // defines. @@ -182,6 +180,30 @@ static void InitializeLogging() { #endif } +static void RemoveCachedContents() { + const auto offline_fonts = Common::FS::SanitizePath( + fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)), + Common::FS::DirectorySeparator::PlatformDefault); + + const auto offline_manual = Common::FS::SanitizePath( + fmt::format("{}/offline_web_applet_manual", + Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)), + Common::FS::DirectorySeparator::PlatformDefault); + const auto offline_legal_information = Common::FS::SanitizePath( + fmt::format("{}/offline_web_applet_legal_information", + Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)), + Common::FS::DirectorySeparator::PlatformDefault); + const auto offline_system_data = Common::FS::SanitizePath( + fmt::format("{}/offline_web_applet_system_data", + Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)), + Common::FS::DirectorySeparator::PlatformDefault); + + Common::FS::DeleteDirRecursively(offline_fonts); + Common::FS::DeleteDirRecursively(offline_manual); + Common::FS::DeleteDirRecursively(offline_legal_information); + Common::FS::DeleteDirRecursively(offline_system_data); +} + GMainWindow::GMainWindow() : input_subsystem{std::make_shared()}, config{std::make_unique()}, vfs{std::make_shared()}, @@ -250,6 +272,9 @@ GMainWindow::GMainWindow() FileSys::ContentProviderUnionSlot::FrontendManual, provider.get()); Core::System::GetInstance().GetFileSystemController().CreateFactories(*vfs); + // Remove cached contents generated during the previous session + RemoveCachedContents(); + // Gen keys if necessary OnReinitializeKeys(ReinitializeKeyBehavior::NoWarning); @@ -341,6 +366,86 @@ void GMainWindow::SoftwareKeyboardInvokeCheckDialog(std::u16string error_message emit SoftwareKeyboardFinishedCheckDialog(); } +void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, + std::string_view additional_args) { +#ifdef YUZU_USE_QT_WEB_ENGINE + + QtNXWebEngineView web_browser_view(this, Core::System::GetInstance()); + + web_browser_view.LoadLocalWebPage(main_url, additional_args); + + ui.action_Pause->setEnabled(false); + ui.action_Restart->setEnabled(false); + ui.action_Stop->setEnabled(false); + + if (render_window->IsLoadingComplete()) { + render_window->hide(); + } + + 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(layout.screen.GetWidth()) / + static_cast(Layout::ScreenUndocked::Width)); + + web_browser_view.setFocus(); + web_browser_view.show(); + + bool exit_check = false; + + while (!web_browser_view.IsFinished()) { + QCoreApplication::processEvents(); + + if (!exit_check) { + web_browser_view.page()->runJavaScript( + QStringLiteral("end_applet;"), [&](const QVariant& variant) { + exit_check = false; + if (variant.toBool()) { + web_browser_view.SetFinished(true); + web_browser_view.SetExitReason(WebExitReason::EndButtonPressed); + } + }); + + exit_check = true; + } + + if (web_browser_view.GetCurrentURL().contains(QStringLiteral("localhost"))) { + if (!web_browser_view.IsFinished()) { + web_browser_view.SetFinished(true); + web_browser_view.SetExitReason(WebExitReason::CallbackURL); + } + + web_browser_view.SetLastURL(web_browser_view.GetCurrentURL().toStdString()); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + + const auto exit_reason = web_browser_view.GetExitReason(); + const auto last_url = web_browser_view.GetLastURL(); + + web_browser_view.hide(); + + render_window->setFocus(); + + if (render_window->IsLoadingComplete()) { + render_window->show(); + } + + ui.action_Pause->setEnabled(true); + ui.action_Restart->setEnabled(true); + ui.action_Stop->setEnabled(true); + + emit WebBrowserClosed(exit_reason, last_url); + +#else + + // Utilize the same fallback as the default web browser applet. + emit WebBrowserClosed(WebExitReason::WindowClosed, "http://localhost"); + +#endif +} + void GMainWindow::InitializeWidgets() { #ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING ui.action_Report_Compatibility->setVisible(true); @@ -1948,6 +2053,7 @@ void GMainWindow::OnStartGame() { qRegisterMetaType("std::string"); qRegisterMetaType>("std::optional"); qRegisterMetaType("std::string_view"); + qRegisterMetaType("Service::AM::Applets::WebExitReason"); connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index f311f2b5b..22f64fc9c 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -55,6 +55,10 @@ namespace InputCommon { class InputSubsystem; } +namespace Service::AM::Applets { +enum class WebExitReason : u32; +} + enum class EmulatedDirectoryTarget { NAND, SDMC, @@ -126,6 +130,8 @@ signals: void SoftwareKeyboardFinishedText(std::optional text); void SoftwareKeyboardFinishedCheckDialog(); + void WebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, std::string last_url); + public slots: void OnLoadComplete(); void OnExecuteProgram(std::size_t program_index); @@ -135,6 +141,7 @@ public slots: void ProfileSelectorSelectProfile(); void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters); void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); + void WebBrowserOpenLocalWebPage(std::string_view main_url, std::string_view additional_args); void OnAppFocusStateChanged(Qt::ApplicationState state); private: From 8b95bf041da573459e953e27eee2dcf30208b02d Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Mon, 30 Nov 2020 10:15:00 -0500 Subject: [PATCH 13/16] main, applets/web: Re-add progress dialog for RomFS extraction --- src/core/frontend/applets/web_browser.cpp | 5 +- src/core/frontend/applets/web_browser.h | 11 ++-- .../hle/service/am/applets/web_browser.cpp | 66 ++++++++++--------- src/core/hle/service/am/applets/web_browser.h | 10 +++ src/yuzu/applets/web_browser.cpp | 21 ++++-- src/yuzu/applets/web_browser.h | 21 ++++-- src/yuzu/main.cpp | 60 ++++++++++++----- src/yuzu/main.h | 1 + 8 files changed, 126 insertions(+), 69 deletions(-) diff --git a/src/core/frontend/applets/web_browser.cpp b/src/core/frontend/applets/web_browser.cpp index 0e1612e27..a5d8f82ac 100644 --- a/src/core/frontend/applets/web_browser.cpp +++ b/src/core/frontend/applets/web_browser.cpp @@ -12,11 +12,12 @@ WebBrowserApplet::~WebBrowserApplet() = default; DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default; void DefaultWebBrowserApplet::OpenLocalWebPage( - std::string_view local_url, std::function callback) const { + std::string_view local_url, std::function extract_romfs_callback, + std::function callback) const { LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open local web page at {}", local_url); - callback(WebExitReason::WindowClosed, "http://localhost/"); + callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); } } // namespace Core::Frontend diff --git a/src/core/frontend/applets/web_browser.h b/src/core/frontend/applets/web_browser.h index 2ccefc68f..5b0629cfb 100644 --- a/src/core/frontend/applets/web_browser.h +++ b/src/core/frontend/applets/web_browser.h @@ -9,8 +9,6 @@ #include "core/hle/service/am/applets/web_types.h" -using namespace Service::AM::Applets; - namespace Core::Frontend { class WebBrowserApplet { @@ -18,16 +16,17 @@ public: virtual ~WebBrowserApplet(); virtual void OpenLocalWebPage( - std::string_view local_url, - std::function callback) const = 0; + std::string_view local_url, std::function extract_romfs_callback, + std::function callback) const = 0; }; class DefaultWebBrowserApplet final : public WebBrowserApplet { public: ~DefaultWebBrowserApplet() override; - void OpenLocalWebPage(std::string_view local_url, - std::function callback) const override; + void OpenLocalWebPage(std::string_view local_url, std::function extract_romfs_callback, + std::function + callback) const override; }; } // namespace Core::Frontend diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index 02ce9f387..9c8be156f 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -15,7 +15,6 @@ #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/file_sys/vfs_vector.h" #include "core/frontend/applets/web_browser.h" #include "core/hle/kernel/process.h" @@ -311,6 +310,18 @@ void WebBrowser::Execute() { } } +void WebBrowser::ExtractOfflineRomFS() { + LOG_DEBUG(Service_AM, "Extracting RomFS to {}", offline_cache_dir); + + const auto extracted_romfs_dir = + FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard); + + const auto temp_dir = + system.GetFilesystem()->CreateDirectory(offline_cache_dir, FileSys::Mode::ReadWrite); + + FileSys::VfsRawCopyD(extracted_romfs_dir, temp_dir); +} + void WebBrowser::WebBrowserExit(WebExitReason exit_reason, std::string last_url) { if ((web_arg_header.shim_kind == ShimKind::Share && web_applet_version >= WebAppletVersion::Version196608) || @@ -360,12 +371,11 @@ void WebBrowser::InitializeOffline() { const auto document_kind = ParseRawValue(GetInputTLVData(WebArgInputTLVType::DocumentKind).value()); - u64 title_id{}; - FileSys::ContentRecordType nca_type{FileSys::ContentRecordType::HtmlDocument}; std::string additional_paths; switch (document_kind) { case DocumentKind::OfflineHtmlPage: + default: title_id = system.CurrentProcess()->GetTitleID(); nca_type = FileSys::ContentRecordType::HtmlDocument; additional_paths = "html-document"; @@ -395,31 +405,6 @@ void WebBrowser::InitializeOffline() { offline_document = Common::FS::SanitizePath( fmt::format("{}/{}/{}", offline_cache_dir, additional_paths, document_path), Common::FS::DirectorySeparator::PlatformDefault); - - const auto main_url = Common::FS::SanitizePath(GetMainURL(offline_document), - Common::FS::DirectorySeparator::PlatformDefault); - - if (Common::FS::Exists(main_url)) { - return; - } - - auto offline_romfs = GetOfflineRomFS(system, title_id, nca_type); - - if (offline_romfs == nullptr) { - LOG_ERROR(Service_AM, "RomFS with title_id={:016X} and nca_type={} cannot be extracted!", - title_id, nca_type); - return; - } - - LOG_DEBUG(Service_AM, "Extracting RomFS to {}", offline_cache_dir); - - const auto extracted_romfs_dir = - FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard); - - const auto temp_dir = - system.GetFilesystem()->CreateDirectory(offline_cache_dir, FileSys::Mode::ReadWrite); - - FileSys::VfsRawCopyD(extracted_romfs_dir, temp_dir); } void WebBrowser::InitializeShare() {} @@ -441,11 +426,28 @@ void WebBrowser::ExecuteLogin() { } void WebBrowser::ExecuteOffline() { + const auto main_url = Common::FS::SanitizePath(GetMainURL(offline_document), + Common::FS::DirectorySeparator::PlatformDefault); + + if (!Common::FS::Exists(main_url)) { + offline_romfs = GetOfflineRomFS(system, title_id, nca_type); + + if (offline_romfs == nullptr) { + LOG_ERROR(Service_AM, + "RomFS with title_id={:016X} and nca_type={} cannot be extracted!", title_id, + nca_type); + WebBrowserExit(WebExitReason::WindowClosed); + return; + } + } + LOG_INFO(Service_AM, "Opening offline document at {}", offline_document); - frontend.OpenLocalWebPage(offline_document, - [this](WebExitReason exit_reason, std::string last_url) { - WebBrowserExit(exit_reason, last_url); - }); + + frontend.OpenLocalWebPage( + offline_document, [this] { ExtractOfflineRomFS(); }, + [this](WebExitReason exit_reason, std::string last_url) { + WebBrowserExit(exit_reason, last_url); + }); } void WebBrowser::ExecuteShare() { diff --git a/src/core/hle/service/am/applets/web_browser.h b/src/core/hle/service/am/applets/web_browser.h index c36c717f1..936a49a86 100644 --- a/src/core/hle/service/am/applets/web_browser.h +++ b/src/core/hle/service/am/applets/web_browser.h @@ -8,6 +8,7 @@ #include "common/common_funcs.h" #include "common/common_types.h" +#include "core/file_sys/vfs_types.h" #include "core/hle/result.h" #include "core/hle/service/am/applets/applets.h" #include "core/hle/service/am/applets/web_types.h" @@ -16,6 +17,10 @@ namespace Core { class System; } +namespace FileSys { +enum class ContentRecordType : u8; +} + namespace Service::AM::Applets { class WebBrowser final : public Applet { @@ -31,6 +36,8 @@ public: void ExecuteInteractive() override; void Execute() override; + void ExtractOfflineRomFS(); + void WebBrowserExit(WebExitReason exit_reason, std::string last_url = ""); private: @@ -66,8 +73,11 @@ private: WebArgHeader web_arg_header; WebArgInputTLVMap web_arg_input_tlv_map; + u64 title_id; + FileSys::ContentRecordType nca_type; std::string offline_cache_dir; std::string offline_document; + FileSys::VirtualFile offline_romfs; Core::System& system; }; diff --git a/src/yuzu/applets/web_browser.cpp b/src/yuzu/applets/web_browser.cpp index 26b9df51a..52c99d1ba 100644 --- a/src/yuzu/applets/web_browser.cpp +++ b/src/yuzu/applets/web_browser.cpp @@ -120,7 +120,7 @@ QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system) [this] { if (page()->url() == url_interceptor->GetRequestedURL()) { SetFinished(true); - SetExitReason(WebExitReason::WindowClosed); + SetExitReason(Service::AM::Applets::WebExitReason::WindowClosed); } }, Qt::QueuedConnection); @@ -135,7 +135,7 @@ void QtNXWebEngineView::LoadLocalWebPage(std::string_view main_url, std::string_view additional_args) { SetUserAgent(UserAgent::WebApplet); SetFinished(false); - SetExitReason(WebExitReason::EndButtonPressed); + SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed); SetLastURL("http://localhost/"); StartInputThread(); @@ -176,11 +176,11 @@ void QtNXWebEngineView::SetFinished(bool finished_) { finished = finished_; } -WebExitReason QtNXWebEngineView::GetExitReason() const { +Service::AM::Applets::WebExitReason QtNXWebEngineView::GetExitReason() const { return exit_reason; } -void QtNXWebEngineView::SetExitReason(WebExitReason exit_reason_) { +void QtNXWebEngineView::SetExitReason(Service::AM::Applets::WebExitReason exit_reason_) { exit_reason = exit_reason_; } @@ -316,6 +316,8 @@ void QtNXWebEngineView::InputThread() { QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { connect(this, &QtWebBrowser::MainWindowOpenLocalWebPage, &main_window, &GMainWindow::WebBrowserOpenLocalWebPage, Qt::QueuedConnection); + connect(&main_window, &GMainWindow::WebBrowserExtractOfflineRomFS, this, + &QtWebBrowser::MainWindowExtractOfflineRomFS, Qt::QueuedConnection); connect(&main_window, &GMainWindow::WebBrowserClosed, this, &QtWebBrowser::MainWindowWebBrowserClosed, Qt::QueuedConnection); } @@ -323,7 +325,9 @@ QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { QtWebBrowser::~QtWebBrowser() = default; void QtWebBrowser::OpenLocalWebPage( - std::string_view local_url, std::function callback) const { + std::string_view local_url, std::function extract_romfs_callback, + std::function callback) const { + this->extract_romfs_callback = std::move(extract_romfs_callback); this->callback = std::move(callback); const auto index = local_url.find('?'); @@ -335,6 +339,11 @@ void QtWebBrowser::OpenLocalWebPage( } } -void QtWebBrowser::MainWindowWebBrowserClosed(WebExitReason exit_reason, std::string last_url) { +void QtWebBrowser::MainWindowExtractOfflineRomFS() { + extract_romfs_callback(); +} + +void QtWebBrowser::MainWindowWebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, + std::string last_url) { callback(exit_reason, last_url); } diff --git a/src/yuzu/applets/web_browser.h b/src/yuzu/applets/web_browser.h index 74f2b49d2..18b8640a7 100644 --- a/src/yuzu/applets/web_browser.h +++ b/src/yuzu/applets/web_browser.h @@ -69,8 +69,8 @@ public: [[nodiscard]] bool IsFinished() const; void SetFinished(bool finished_); - [[nodiscard]] WebExitReason GetExitReason() const; - void SetExitReason(WebExitReason exit_reason_); + [[nodiscard]] Service::AM::Applets::WebExitReason GetExitReason() const; + void SetExitReason(Service::AM::Applets::WebExitReason exit_reason_); [[nodiscard]] const std::string& GetLastURL() const; void SetLastURL(std::string last_url_); @@ -148,7 +148,8 @@ private: std::atomic finished{}; - WebExitReason exit_reason{WebExitReason::EndButtonPressed}; + Service::AM::Applets::WebExitReason exit_reason{ + Service::AM::Applets::WebExitReason::EndButtonPressed}; std::string last_url{"http://localhost/"}; }; @@ -162,15 +163,21 @@ public: explicit QtWebBrowser(GMainWindow& parent); ~QtWebBrowser() override; - void OpenLocalWebPage(std::string_view local_url, - std::function callback) const override; + void OpenLocalWebPage(std::string_view local_url, std::function extract_romfs_callback, + std::function + callback) const override; signals: void MainWindowOpenLocalWebPage(std::string_view main_url, std::string_view additional_args) const; private: - void MainWindowWebBrowserClosed(WebExitReason exit_reason, std::string last_url); + void MainWindowExtractOfflineRomFS(); - mutable std::function callback; + void MainWindowWebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, + std::string last_url); + + mutable std::function extract_romfs_callback; + + mutable std::function callback; }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index bab76db1e..f696fc494 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -372,25 +372,50 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, QtNXWebEngineView web_browser_view(this, Core::System::GetInstance()); - web_browser_view.LoadLocalWebPage(main_url, additional_args); - ui.action_Pause->setEnabled(false); ui.action_Restart->setEnabled(false); ui.action_Stop->setEnabled(false); - if (render_window->IsLoadingComplete()) { - render_window->hide(); + { + QProgressDialog loading_progress(this); + loading_progress.setLabelText(tr("Loading Web Applet...")); + loading_progress.setRange(0, 3); + loading_progress.setValue(0); + + if (!Common::FS::Exists(std::string(main_url))) { + loading_progress.show(); + + auto future = QtConcurrent::run([this] { emit WebBrowserExtractOfflineRomFS(); }); + + while (!future.isFinished()) { + QCoreApplication::processEvents(); + } + } + + loading_progress.setValue(1); + + web_browser_view.LoadLocalWebPage(main_url, additional_args); + + if (render_window->IsLoadingComplete()) { + render_window->hide(); + } + + 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(layout.screen.GetWidth()) / + static_cast(Layout::ScreenUndocked::Width)); + + web_browser_view.setFocus(); + web_browser_view.show(); + + loading_progress.setValue(2); + + QCoreApplication::processEvents(); + + loading_progress.setValue(3); } - 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(layout.screen.GetWidth()) / - static_cast(Layout::ScreenUndocked::Width)); - - web_browser_view.setFocus(); - web_browser_view.show(); - bool exit_check = false; while (!web_browser_view.IsFinished()) { @@ -402,7 +427,8 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, exit_check = false; if (variant.toBool()) { web_browser_view.SetFinished(true); - web_browser_view.SetExitReason(WebExitReason::EndButtonPressed); + web_browser_view.SetExitReason( + Service::AM::Applets::WebExitReason::EndButtonPressed); } }); @@ -412,7 +438,7 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, if (web_browser_view.GetCurrentURL().contains(QStringLiteral("localhost"))) { if (!web_browser_view.IsFinished()) { web_browser_view.SetFinished(true); - web_browser_view.SetExitReason(WebExitReason::CallbackURL); + web_browser_view.SetExitReason(Service::AM::Applets::WebExitReason::CallbackURL); } web_browser_view.SetLastURL(web_browser_view.GetCurrentURL().toStdString()); @@ -436,12 +462,14 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, ui.action_Restart->setEnabled(true); ui.action_Stop->setEnabled(true); + QCoreApplication::processEvents(); + emit WebBrowserClosed(exit_reason, last_url); #else // Utilize the same fallback as the default web browser applet. - emit WebBrowserClosed(WebExitReason::WindowClosed, "http://localhost"); + emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost"); #endif } diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 22f64fc9c..ed02df3e2 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -130,6 +130,7 @@ signals: void SoftwareKeyboardFinishedText(std::optional text); void SoftwareKeyboardFinishedCheckDialog(); + void WebBrowserExtractOfflineRomFS(); void WebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, std::string last_url); public slots: From 2ddd83cdfe2bfb63579d2932a1ee3b26073fbeea Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Mon, 30 Nov 2020 10:34:18 -0500 Subject: [PATCH 14/16] main: Add the ability to disable the web applet This should only be used for Super Mario 3D All-Stars. This is a temporary solution until it can be implemented properly. --- src/yuzu/main.cpp | 24 ++++++++++++++++++++++++ src/yuzu/main.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index f696fc494..ccff08074 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -370,6 +370,12 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, std::string_view additional_args) { #ifdef YUZU_USE_QT_WEB_ENGINE + if (disable_web_applet) { + emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, + "http://localhost"); + return; + } + QtNXWebEngineView web_browser_view(this, Core::System::GetInstance()); ui.action_Pause->setEnabled(false); @@ -418,6 +424,22 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, bool exit_check = false; + // TODO (Morph): Remove this + QAction* exit_action = new QAction(tr("Disable Web Applet"), this); + connect(exit_action, &QAction::triggered, this, [this, &web_browser_view] { + const auto result = QMessageBox::warning( + this, tr("Disable Web Applet"), + tr("Disabling the web applet will cause it to not be shown again for the rest of the " + "emulated session. This can lead to undefined behavior and should only be used with " + "Super Mario 3D All-Stars. Are you sure you want to disable the web applet?"), + QMessageBox::Yes | QMessageBox::No); + if (result == QMessageBox::Yes) { + disable_web_applet = true; + web_browser_view.SetFinished(true); + } + }); + ui.menubar->addAction(exit_action); + while (!web_browser_view.IsFinished()) { QCoreApplication::processEvents(); @@ -462,6 +484,8 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, ui.action_Restart->setEnabled(true); ui.action_Stop->setEnabled(true); + ui.menubar->removeAction(exit_action); + QCoreApplication::processEvents(); emit WebBrowserClosed(exit_reason, last_url); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index ed02df3e2..b140995bf 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -325,6 +325,9 @@ private: // Last game booted, used for multi-process apps QString last_filename_booted; + // Disables the web applet for the rest of the emulated session + bool disable_web_applet{}; + protected: void dropEvent(QDropEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; From 51cddcb8b8d4d12715ba0517638b394244b500bb Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Mon, 30 Nov 2020 22:25:01 -0500 Subject: [PATCH 15/16] applets/web: Fix keyboard to emulated controller input --- src/yuzu/applets/web_browser.cpp | 19 +++++++++++++++++-- src/yuzu/applets/web_browser.h | 13 ++++++++++++- src/yuzu/main.cpp | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/yuzu/applets/web_browser.cpp b/src/yuzu/applets/web_browser.cpp index 52c99d1ba..7e2dc6ee9 100644 --- a/src/yuzu/applets/web_browser.cpp +++ b/src/yuzu/applets/web_browser.cpp @@ -15,6 +15,8 @@ #include "common/file_util.h" #include "core/core.h" #include "core/frontend/input_interpreter.h" +#include "input_common/keyboard.h" +#include "input_common/main.h" #include "yuzu/applets/web_browser.h" #include "yuzu/applets/web_browser_scripts.h" #include "yuzu/main.h" @@ -45,8 +47,10 @@ constexpr int HIDButtonToKey(HIDButton button) { } // Anonymous namespace -QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system) - : QWebEngineView(parent), url_interceptor(std::make_unique()), +QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system, + InputCommon::InputSubsystem* input_subsystem_) + : QWebEngineView(parent), input_subsystem{input_subsystem_}, + url_interceptor(std::make_unique()), input_interpreter(std::make_unique(system)) { QWebEngineScript nx_font_css; QWebEngineScript load_nx_font; @@ -203,6 +207,14 @@ void QtNXWebEngineView::hide() { QWidget::hide(); } +void QtNXWebEngineView::keyPressEvent(QKeyEvent* event) { + input_subsystem->GetKeyboard()->PressKey(event->key()); +} + +void QtNXWebEngineView::keyReleaseEvent(QKeyEvent* event) { + input_subsystem->GetKeyboard()->ReleaseKey(event->key()); +} + template void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() { const auto f = [this](HIDButton button) { @@ -282,6 +294,7 @@ void QtNXWebEngineView::StartInputThread() { } void QtNXWebEngineView::StopInputThread() { + QWidget::releaseKeyboard(); input_thread_running = false; if (input_thread.joinable()) { input_thread.join(); @@ -292,6 +305,8 @@ void QtNXWebEngineView::InputThread() { // Wait for 1 second before allowing any inputs to be processed. std::this_thread::sleep_for(std::chrono::seconds(1)); + QWidget::grabKeyboard(); + while (input_thread_running) { input_interpreter->PollInput(); diff --git a/src/yuzu/applets/web_browser.h b/src/yuzu/applets/web_browser.h index 18b8640a7..cfddaa6f8 100644 --- a/src/yuzu/applets/web_browser.h +++ b/src/yuzu/applets/web_browser.h @@ -26,6 +26,10 @@ namespace Core { class System; } +namespace InputCommon { +class InputSubsystem; +} + #ifdef YUZU_USE_QT_WEB_ENGINE enum class UserAgent { @@ -41,7 +45,8 @@ class QtNXWebEngineView : public QWebEngineView { Q_OBJECT public: - explicit QtNXWebEngineView(QWidget* parent, Core::System& system); + explicit QtNXWebEngineView(QWidget* parent, Core::System& system, + InputCommon::InputSubsystem* input_subsystem_); ~QtNXWebEngineView() override; /** @@ -86,6 +91,10 @@ public: public slots: void hide(); +protected: + void keyPressEvent(QKeyEvent* event) override; + void keyReleaseEvent(QKeyEvent* event) override; + private: /** * Handles button presses to execute functions assigned in yuzu_key_callbacks. @@ -138,6 +147,8 @@ private: /// The thread where input is being polled and processed. void InputThread(); + InputCommon::InputSubsystem* input_subsystem; + std::unique_ptr url_interceptor; std::unique_ptr input_interpreter; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index ccff08074..f835ee9cb 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -376,7 +376,7 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, return; } - QtNXWebEngineView web_browser_view(this, Core::System::GetInstance()); + QtNXWebEngineView web_browser_view(this, Core::System::GetInstance(), input_subsystem.get()); ui.action_Pause->setEnabled(false); ui.action_Restart->setEnabled(false); From 82fa9f8d56bc285e7bb58fc81b495a55be9ea82c Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Tue, 8 Dec 2020 06:20:45 -0500 Subject: [PATCH 16/16] applets/web: Implement the online web browser applet --- src/core/frontend/applets/web_browser.cpp | 9 ++ src/core/frontend/applets/web_browser.h | 8 + .../hle/service/am/applets/web_browser.cpp | 12 +- src/core/hle/service/am/applets/web_browser.h | 2 + src/yuzu/applets/web_browser.cpp | 148 ++++++++++++------ src/yuzu/applets/web_browser.h | 33 +++- src/yuzu/main.cpp | 16 +- src/yuzu/main.h | 3 +- 8 files changed, 167 insertions(+), 64 deletions(-) diff --git a/src/core/frontend/applets/web_browser.cpp b/src/core/frontend/applets/web_browser.cpp index a5d8f82ac..50db6a654 100644 --- a/src/core/frontend/applets/web_browser.cpp +++ b/src/core/frontend/applets/web_browser.cpp @@ -20,4 +20,13 @@ void DefaultWebBrowserApplet::OpenLocalWebPage( callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); } +void DefaultWebBrowserApplet::OpenExternalWebPage( + std::string_view external_url, + std::function callback) const { + LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open external web page at {}", + external_url); + + callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); +} + } // namespace Core::Frontend diff --git a/src/core/frontend/applets/web_browser.h b/src/core/frontend/applets/web_browser.h index 5b0629cfb..1c5ef19a9 100644 --- a/src/core/frontend/applets/web_browser.h +++ b/src/core/frontend/applets/web_browser.h @@ -18,6 +18,10 @@ public: virtual void OpenLocalWebPage( std::string_view local_url, std::function extract_romfs_callback, std::function callback) const = 0; + + virtual void OpenExternalWebPage( + std::string_view external_url, + std::function callback) const = 0; }; class DefaultWebBrowserApplet final : public WebBrowserApplet { @@ -27,6 +31,10 @@ public: void OpenLocalWebPage(std::string_view local_url, std::function extract_romfs_callback, std::function callback) const override; + + void OpenExternalWebPage(std::string_view external_url, + std::function + callback) const override; }; } // namespace Core::Frontend diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index 9c8be156f..2ab420789 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -409,7 +409,9 @@ void WebBrowser::InitializeOffline() { void WebBrowser::InitializeShare() {} -void WebBrowser::InitializeWeb() {} +void WebBrowser::InitializeWeb() { + external_url = ParseStringValue(GetInputTLVData(WebArgInputTLVType::InitialURL).value()); +} void WebBrowser::InitializeWifi() {} @@ -456,8 +458,12 @@ void WebBrowser::ExecuteShare() { } void WebBrowser::ExecuteWeb() { - LOG_WARNING(Service_AM, "(STUBBED) called, Web Applet is not implemented"); - WebBrowserExit(WebExitReason::EndButtonPressed); + LOG_INFO(Service_AM, "Opening external URL at {}", external_url); + + frontend.OpenExternalWebPage(external_url, + [this](WebExitReason exit_reason, std::string last_url) { + WebBrowserExit(exit_reason, last_url); + }); } void WebBrowser::ExecuteWifi() { diff --git a/src/core/hle/service/am/applets/web_browser.h b/src/core/hle/service/am/applets/web_browser.h index 936a49a86..04c274754 100644 --- a/src/core/hle/service/am/applets/web_browser.h +++ b/src/core/hle/service/am/applets/web_browser.h @@ -79,6 +79,8 @@ private: std::string offline_document; FileSys::VirtualFile offline_romfs; + std::string external_url; + Core::System& system; }; diff --git a/src/yuzu/applets/web_browser.cpp b/src/yuzu/applets/web_browser.cpp index 7e2dc6ee9..e482ba029 100644 --- a/src/yuzu/applets/web_browser.cpp +++ b/src/yuzu/applets/web_browser.cpp @@ -51,59 +51,32 @@ QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system, InputCommon::InputSubsystem* input_subsystem_) : QWebEngineView(parent), input_subsystem{input_subsystem_}, url_interceptor(std::make_unique()), - input_interpreter(std::make_unique(system)) { - QWebEngineScript nx_font_css; - QWebEngineScript load_nx_font; + input_interpreter(std::make_unique(system)), + default_profile{QWebEngineProfile::defaultProfile()}, + global_settings{QWebEngineSettings::globalSettings()} { QWebEngineScript gamepad; QWebEngineScript window_nx; - const QString fonts_dir = QString::fromStdString(Common::FS::SanitizePath( - fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)))); - - nx_font_css.setName(QStringLiteral("nx_font_css.js")); - load_nx_font.setName(QStringLiteral("load_nx_font.js")); gamepad.setName(QStringLiteral("gamepad_script.js")); window_nx.setName(QStringLiteral("window_nx_script.js")); - nx_font_css.setSourceCode( - QString::fromStdString(NX_FONT_CSS) - .arg(fonts_dir + QStringLiteral("/FontStandard.ttf")) - .arg(fonts_dir + QStringLiteral("/FontChineseSimplified.ttf")) - .arg(fonts_dir + QStringLiteral("/FontExtendedChineseSimplified.ttf")) - .arg(fonts_dir + QStringLiteral("/FontChineseTraditional.ttf")) - .arg(fonts_dir + QStringLiteral("/FontKorean.ttf")) - .arg(fonts_dir + QStringLiteral("/FontNintendoExtended.ttf")) - .arg(fonts_dir + QStringLiteral("/FontNintendoExtended2.ttf"))); - load_nx_font.setSourceCode(QString::fromStdString(LOAD_NX_FONT)); gamepad.setSourceCode(QString::fromStdString(GAMEPAD_SCRIPT)); window_nx.setSourceCode(QString::fromStdString(WINDOW_NX_SCRIPT)); - nx_font_css.setInjectionPoint(QWebEngineScript::DocumentReady); - load_nx_font.setInjectionPoint(QWebEngineScript::Deferred); gamepad.setInjectionPoint(QWebEngineScript::DocumentCreation); window_nx.setInjectionPoint(QWebEngineScript::DocumentCreation); - nx_font_css.setWorldId(QWebEngineScript::MainWorld); - load_nx_font.setWorldId(QWebEngineScript::MainWorld); gamepad.setWorldId(QWebEngineScript::MainWorld); window_nx.setWorldId(QWebEngineScript::MainWorld); - nx_font_css.setRunsOnSubFrames(true); - load_nx_font.setRunsOnSubFrames(true); gamepad.setRunsOnSubFrames(true); window_nx.setRunsOnSubFrames(true); - auto* default_profile = QWebEngineProfile::defaultProfile(); - - default_profile->scripts()->insert(nx_font_css); - default_profile->scripts()->insert(load_nx_font); default_profile->scripts()->insert(gamepad); default_profile->scripts()->insert(window_nx); default_profile->setRequestInterceptor(url_interceptor.get()); - auto* global_settings = QWebEngineSettings::globalSettings(); - global_settings->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true); global_settings->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true); global_settings->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, true); @@ -111,13 +84,7 @@ QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system, global_settings->setAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript, true); global_settings->setAttribute(QWebEngineSettings::ShowScrollBars, false); - connect( - url_interceptor.get(), &UrlRequestInterceptor::FrameChanged, url_interceptor.get(), - [this] { - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - page()->runJavaScript(QString::fromStdString(LOAD_NX_FONT)); - }, - Qt::QueuedConnection); + global_settings->setFontFamily(QWebEngineSettings::StandardFont, QStringLiteral("Roboto")); connect( page(), &QWebEnginePage::windowCloseRequested, page(), @@ -137,6 +104,9 @@ QtNXWebEngineView::~QtNXWebEngineView() { void QtNXWebEngineView::LoadLocalWebPage(std::string_view main_url, std::string_view additional_args) { + is_local = true; + + LoadExtractedFonts(); SetUserAgent(UserAgent::WebApplet); SetFinished(false); SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed); @@ -147,6 +117,20 @@ void QtNXWebEngineView::LoadLocalWebPage(std::string_view main_url, QString::fromStdString(std::string(additional_args)))); } +void QtNXWebEngineView::LoadExternalWebPage(std::string_view main_url, + std::string_view additional_args) { + is_local = false; + + SetUserAgent(UserAgent::WebApplet); + SetFinished(false); + SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed); + SetLastURL("http://localhost/"); + StartInputThread(); + + load(QUrl(QString::fromStdString(std::string(main_url)) + + QString::fromStdString(std::string(additional_args)))); +} + void QtNXWebEngineView::SetUserAgent(UserAgent user_agent) { const QString user_agent_str = [user_agent] { switch (user_agent) { @@ -208,11 +192,15 @@ void QtNXWebEngineView::hide() { } void QtNXWebEngineView::keyPressEvent(QKeyEvent* event) { - input_subsystem->GetKeyboard()->PressKey(event->key()); + if (is_local) { + input_subsystem->GetKeyboard()->PressKey(event->key()); + } } void QtNXWebEngineView::keyReleaseEvent(QKeyEvent* event) { - input_subsystem->GetKeyboard()->ReleaseKey(event->key()); + if (is_local) { + input_subsystem->GetKeyboard()->ReleaseKey(event->key()); + } } template @@ -294,7 +282,10 @@ void QtNXWebEngineView::StartInputThread() { } void QtNXWebEngineView::StopInputThread() { - QWidget::releaseKeyboard(); + if (is_local) { + QWidget::releaseKeyboard(); + } + input_thread_running = false; if (input_thread.joinable()) { input_thread.join(); @@ -305,7 +296,9 @@ void QtNXWebEngineView::InputThread() { // Wait for 1 second before allowing any inputs to be processed. std::this_thread::sleep_for(std::chrono::seconds(1)); - QWidget::grabKeyboard(); + if (is_local) { + QWidget::grabKeyboard(); + } while (input_thread_running) { input_interpreter->PollInput(); @@ -326,11 +319,53 @@ void QtNXWebEngineView::InputThread() { } } +void QtNXWebEngineView::LoadExtractedFonts() { + QWebEngineScript nx_font_css; + QWebEngineScript load_nx_font; + + const QString fonts_dir = QString::fromStdString(Common::FS::SanitizePath( + fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)))); + + nx_font_css.setName(QStringLiteral("nx_font_css.js")); + load_nx_font.setName(QStringLiteral("load_nx_font.js")); + + nx_font_css.setSourceCode( + QString::fromStdString(NX_FONT_CSS) + .arg(fonts_dir + QStringLiteral("/FontStandard.ttf")) + .arg(fonts_dir + QStringLiteral("/FontChineseSimplified.ttf")) + .arg(fonts_dir + QStringLiteral("/FontExtendedChineseSimplified.ttf")) + .arg(fonts_dir + QStringLiteral("/FontChineseTraditional.ttf")) + .arg(fonts_dir + QStringLiteral("/FontKorean.ttf")) + .arg(fonts_dir + QStringLiteral("/FontNintendoExtended.ttf")) + .arg(fonts_dir + QStringLiteral("/FontNintendoExtended2.ttf"))); + load_nx_font.setSourceCode(QString::fromStdString(LOAD_NX_FONT)); + + nx_font_css.setInjectionPoint(QWebEngineScript::DocumentReady); + load_nx_font.setInjectionPoint(QWebEngineScript::Deferred); + + nx_font_css.setWorldId(QWebEngineScript::MainWorld); + load_nx_font.setWorldId(QWebEngineScript::MainWorld); + + nx_font_css.setRunsOnSubFrames(true); + load_nx_font.setRunsOnSubFrames(true); + + default_profile->scripts()->insert(nx_font_css); + default_profile->scripts()->insert(load_nx_font); + + connect( + url_interceptor.get(), &UrlRequestInterceptor::FrameChanged, url_interceptor.get(), + [this] { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + page()->runJavaScript(QString::fromStdString(LOAD_NX_FONT)); + }, + Qt::QueuedConnection); +} + #endif QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { - connect(this, &QtWebBrowser::MainWindowOpenLocalWebPage, &main_window, - &GMainWindow::WebBrowserOpenLocalWebPage, Qt::QueuedConnection); + connect(this, &QtWebBrowser::MainWindowOpenWebPage, &main_window, + &GMainWindow::WebBrowserOpenWebPage, Qt::QueuedConnection); connect(&main_window, &GMainWindow::WebBrowserExtractOfflineRomFS, this, &QtWebBrowser::MainWindowExtractOfflineRomFS, Qt::QueuedConnection); connect(&main_window, &GMainWindow::WebBrowserClosed, this, @@ -340,17 +375,32 @@ QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { QtWebBrowser::~QtWebBrowser() = default; void QtWebBrowser::OpenLocalWebPage( - std::string_view local_url, std::function extract_romfs_callback, - std::function callback) const { - this->extract_romfs_callback = std::move(extract_romfs_callback); - this->callback = std::move(callback); + std::string_view local_url, std::function extract_romfs_callback_, + std::function callback_) const { + extract_romfs_callback = std::move(extract_romfs_callback_); + callback = std::move(callback_); const auto index = local_url.find('?'); if (index == std::string::npos) { - emit MainWindowOpenLocalWebPage(local_url, ""); + emit MainWindowOpenWebPage(local_url, "", true); } else { - emit MainWindowOpenLocalWebPage(local_url.substr(0, index), local_url.substr(index)); + emit MainWindowOpenWebPage(local_url.substr(0, index), local_url.substr(index), true); + } +} + +void QtWebBrowser::OpenExternalWebPage( + std::string_view external_url, + std::function callback_) const { + callback = std::move(callback_); + + const auto index = external_url.find('?'); + + if (index == std::string::npos) { + emit MainWindowOpenWebPage(external_url, "", false); + } else { + emit MainWindowOpenWebPage(external_url.substr(0, index), external_url.substr(index), + false); } } diff --git a/src/yuzu/applets/web_browser.h b/src/yuzu/applets/web_browser.h index cfddaa6f8..47f960d69 100644 --- a/src/yuzu/applets/web_browser.h +++ b/src/yuzu/applets/web_browser.h @@ -18,8 +18,8 @@ enum class HIDButton : u8; -class InputInterpreter; class GMainWindow; +class InputInterpreter; class UrlRequestInterceptor; namespace Core { @@ -41,6 +41,9 @@ enum class UserAgent { WifiWebAuthApplet, }; +class QWebEngineProfile; +class QWebEngineSettings; + class QtNXWebEngineView : public QWebEngineView { Q_OBJECT @@ -57,6 +60,14 @@ public: */ void LoadLocalWebPage(std::string_view main_url, std::string_view additional_args); + /** + * Loads an external website. Cannot be used to load local urls. + * + * @param main_url The url to the website. + * @param additional_args Additional arguments appended to the main url. + */ + void LoadExternalWebPage(std::string_view main_url, std::string_view additional_args); + /** * Sets the background color of the web page. * @@ -147,6 +158,9 @@ private: /// The thread where input is being polled and processed. void InputThread(); + /// Loads the extracted fonts using JavaScript. + void LoadExtractedFonts(); + InputCommon::InputSubsystem* input_subsystem; std::unique_ptr url_interceptor; @@ -163,6 +177,11 @@ private: Service::AM::Applets::WebExitReason::EndButtonPressed}; std::string last_url{"http://localhost/"}; + + bool is_local{}; + + QWebEngineProfile* default_profile; + QWebEngineSettings* global_settings; }; #endif @@ -174,13 +193,17 @@ public: explicit QtWebBrowser(GMainWindow& parent); ~QtWebBrowser() override; - void OpenLocalWebPage(std::string_view local_url, std::function extract_romfs_callback, + void OpenLocalWebPage(std::string_view local_url, std::function extract_romfs_callback_, std::function - callback) const override; + callback_) const override; + + void OpenExternalWebPage(std::string_view external_url, + std::function + callback_) const override; signals: - void MainWindowOpenLocalWebPage(std::string_view main_url, - std::string_view additional_args) const; + void MainWindowOpenWebPage(std::string_view main_url, std::string_view additional_args, + bool is_local) const; private: void MainWindowExtractOfflineRomFS(); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index f835ee9cb..620e80cdc 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -366,13 +366,13 @@ void GMainWindow::SoftwareKeyboardInvokeCheckDialog(std::u16string error_message emit SoftwareKeyboardFinishedCheckDialog(); } -void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, - std::string_view additional_args) { +void GMainWindow::WebBrowserOpenWebPage(std::string_view main_url, std::string_view additional_args, + bool is_local) { #ifdef YUZU_USE_QT_WEB_ENGINE if (disable_web_applet) { emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, - "http://localhost"); + "http://localhost/"); return; } @@ -388,7 +388,7 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, loading_progress.setRange(0, 3); loading_progress.setValue(0); - if (!Common::FS::Exists(std::string(main_url))) { + if (is_local && !Common::FS::Exists(std::string(main_url))) { loading_progress.show(); auto future = QtConcurrent::run([this] { emit WebBrowserExtractOfflineRomFS(); }); @@ -400,7 +400,11 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, loading_progress.setValue(1); - web_browser_view.LoadLocalWebPage(main_url, additional_args); + if (is_local) { + web_browser_view.LoadLocalWebPage(main_url, additional_args); + } else { + web_browser_view.LoadExternalWebPage(main_url, additional_args); + } if (render_window->IsLoadingComplete()) { render_window->hide(); @@ -493,7 +497,7 @@ void GMainWindow::WebBrowserOpenLocalWebPage(std::string_view main_url, #else // Utilize the same fallback as the default web browser applet. - emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost"); + emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); #endif } diff --git a/src/yuzu/main.h b/src/yuzu/main.h index b140995bf..22f82b20e 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -142,7 +142,8 @@ public slots: void ProfileSelectorSelectProfile(); void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters); void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); - void WebBrowserOpenLocalWebPage(std::string_view main_url, std::string_view additional_args); + void WebBrowserOpenWebPage(std::string_view main_url, std::string_view additional_args, + bool is_local); void OnAppFocusStateChanged(Qt::ApplicationState state); private: