Browse Source
Merge pull request #5042 from Morph1984/project-aether
Merge pull request #5042 from Morph1984/project-aether
Project Aether: Reimplementation of the Web Browser Appletnce_cpp
committed by
GitHub
27 changed files with 1788 additions and 861 deletions
-
2src/core/CMakeLists.txt
-
68src/core/frontend/applets/general_frontend.cpp
-
51src/core/frontend/applets/general_frontend.h
-
24src/core/frontend/applets/web_browser.cpp
-
20src/core/frontend/applets/web_browser.h
-
45src/core/frontend/input_interpreter.cpp
-
120src/core/frontend/input_interpreter.h
-
35src/core/hle/service/am/applets/applets.cpp
-
20src/core/hle/service/am/applets/applets.h
-
752src/core/hle/service/am/applets/web_browser.cpp
-
80src/core/hle/service/am/applets/web_browser.h
-
178src/core/hle/service/am/applets/web_types.h
-
2src/core/hle/service/hid/controllers/npad.cpp
-
3src/core/hle/service/hid/controllers/npad.h
-
11src/core/hle/service/ns/ns.cpp
-
30src/core/hle/service/ns/pl_u.cpp
-
19src/core/hle/service/ns/pl_u.h
-
2src/yuzu/CMakeLists.txt
-
435src/yuzu/applets/web_browser.cpp
-
191src/yuzu/applets/web_browser.h
-
193src/yuzu/applets/web_browser_scripts.h
-
4src/yuzu/bootmanager.cpp
-
2src/yuzu/bootmanager.h
-
228src/yuzu/main.cpp
-
14src/yuzu/main.h
-
32src/yuzu/util/url_request_interceptor.cpp
-
30src/yuzu/util/url_request_interceptor.h
@ -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<Service::HID::Hid>("hid") |
||||
|
->GetAppletResource() |
||||
|
->GetController<Service::HID::Controller_NPad>(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<u8>(button))) != 0; |
||||
|
const bool previous_press = |
||||
|
(button_states[previous_index] & (1U << static_cast<u8>(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<u8>(button))) != 0; |
||||
|
} |
||||
@ -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 <array> |
||||
|
|
||||
|
#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 <HIDButton... T> |
||||
|
[[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 <HIDButton... T> |
||||
|
[[nodiscard]] bool IsAnyButtonHeld() { |
||||
|
return (IsButtonHeld(T) || ...); |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
Service::HID::Controller_NPad& npad; |
||||
|
|
||||
|
/// Stores 9 consecutive button states polled from HID. |
||||
|
std::array<u32, 9> button_states{}; |
||||
|
|
||||
|
std::size_t previous_index{}; |
||||
|
std::size_t current_index{}; |
||||
|
}; |
||||
@ -1,558 +1,478 @@ |
|||||
// Copyright 2018 yuzu emulator team
|
|
||||
|
// Copyright 2020 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||
|
|
||||
#include <array>
|
|
||||
#include <cstring>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||
#include "common/common_funcs.h"
|
|
||||
#include "common/common_paths.h"
|
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||
#include "common/hex_util.h"
|
|
||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||
#include "core/core.h"
|
#include "core/core.h"
|
||||
#include "core/file_sys/content_archive.h"
|
#include "core/file_sys/content_archive.h"
|
||||
#include "core/file_sys/mode.h"
|
#include "core/file_sys/mode.h"
|
||||
#include "core/file_sys/nca_metadata.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/registered_cache.h"
|
||||
#include "core/file_sys/romfs.h"
|
#include "core/file_sys/romfs.h"
|
||||
#include "core/file_sys/system_archive/system_archive.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/file_sys/vfs_vector.h"
|
||||
#include "core/frontend/applets/web_browser.h"
|
#include "core/frontend/applets/web_browser.h"
|
||||
#include "core/hle/kernel/process.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/am/applets/web_browser.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/loader/loader.h"
|
|
||||
|
#include "core/hle/service/ns/pl_u.h"
|
||||
|
|
||||
namespace Service::AM::Applets { |
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 { |
namespace { |
||||
|
|
||||
constexpr std::size_t SHIM_KIND_COUNT = 0x8; |
|
||||
|
template <typename T> |
||||
|
void ParseRawValue(T& value, const std::vector<u8>& data) { |
||||
|
static_assert(std::is_trivially_copyable_v<T>, |
||||
|
"It's undefined behavior to use memcpy with non-trivially copyable objects"); |
||||
|
std::memcpy(&value, data.data(), data.size()); |
||||
|
} |
||||
|
|
||||
struct WebArgHeader { |
|
||||
u16 count; |
|
||||
INSERT_PADDING_BYTES(2); |
|
||||
ShimKind kind; |
|
||||
}; |
|
||||
static_assert(sizeof(WebArgHeader) == 0x8, "WebArgHeader has incorrect size."); |
|
||||
|
template <typename T> |
||||
|
T ParseRawValue(const std::vector<u8>& data) { |
||||
|
T value; |
||||
|
ParseRawValue(value, data); |
||||
|
return value; |
||||
|
} |
||||
|
|
||||
struct WebArgTLV { |
|
||||
WebArgTLVType type; |
|
||||
u16 size; |
|
||||
u32 offset; |
|
||||
}; |
|
||||
static_assert(sizeof(WebArgTLV) == 0x8, "WebArgTLV has incorrect size."); |
|
||||
|
std::string ParseStringValue(const std::vector<u8>& data) { |
||||
|
return Common::StringFromFixedZeroTerminatedBuffer(reinterpret_cast<const char*>(data.data()), |
||||
|
data.size()); |
||||
|
} |
||||
|
|
||||
struct WebCommonReturnValue { |
|
||||
u32 result_code; |
|
||||
INSERT_PADDING_BYTES(0x4); |
|
||||
std::array<char, 0x1000> last_url; |
|
||||
u64 last_url_size; |
|
||||
}; |
|
||||
static_assert(sizeof(WebCommonReturnValue) == 0x1010, "WebCommonReturnValue has incorrect size."); |
|
||||
|
|
||||
struct WebWifiPageArg { |
|
||||
INSERT_PADDING_BYTES(4); |
|
||||
std::array<char, 0x100> connection_test_url; |
|
||||
std::array<char, 0x400> initial_url; |
|
||||
std::array<u8, 0x10> nifm_network_uuid; |
|
||||
u32 nifm_requirement; |
|
||||
}; |
|
||||
static_assert(sizeof(WebWifiPageArg) == 0x518, "WebWifiPageArg has incorrect size."); |
|
||||
|
std::string GetMainURL(const std::string& url) { |
||||
|
const auto index = url.find('?'); |
||||
|
|
||||
struct WebWifiReturnValue { |
|
||||
INSERT_PADDING_BYTES(4); |
|
||||
u32 result; |
|
||||
}; |
|
||||
static_assert(sizeof(WebWifiReturnValue) == 0x8, "WebWifiReturnValue has incorrect size."); |
|
||||
|
if (index == std::string::npos) { |
||||
|
return url; |
||||
|
} |
||||
|
|
||||
enum class OfflineWebSource : u32 { |
|
||||
OfflineHtmlPage = 0x1, |
|
||||
ApplicationLegalInformation = 0x2, |
|
||||
SystemDataPage = 0x3, |
|
||||
}; |
|
||||
|
return url.substr(0, index); |
||||
|
} |
||||
|
|
||||
|
WebArgInputTLVMap ReadWebArgs(const std::vector<u8>& web_arg, WebArgHeader& web_arg_header) { |
||||
|
std::memcpy(&web_arg_header, web_arg.data(), sizeof(WebArgHeader)); |
||||
|
|
||||
std::map<WebArgTLVType, std::vector<u8>> GetWebArguments(const std::vector<u8>& arg) { |
|
||||
if (arg.size() < sizeof(WebArgHeader)) |
|
||||
|
if (web_arg.size() == sizeof(WebArgHeader)) { |
||||
return {}; |
return {}; |
||||
|
} |
||||
|
|
||||
WebArgHeader header{}; |
|
||||
std::memcpy(&header, arg.data(), sizeof(WebArgHeader)); |
|
||||
|
WebArgInputTLVMap input_tlv_map; |
||||
|
|
||||
std::map<WebArgTLVType, std::vector<u8>> out; |
|
||||
u64 offset = sizeof(WebArgHeader); |
|
||||
for (std::size_t i = 0; i < header.count; ++i) { |
|
||||
if (arg.size() < (offset + sizeof(WebArgTLV))) |
|
||||
return out; |
|
||||
|
u64 current_offset = sizeof(WebArgHeader); |
||||
|
|
||||
WebArgTLV tlv{}; |
|
||||
std::memcpy(&tlv, arg.data() + offset, sizeof(WebArgTLV)); |
|
||||
offset += sizeof(WebArgTLV); |
|
||||
|
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; |
||||
|
} |
||||
|
|
||||
offset += tlv.offset; |
|
||||
if (arg.size() < (offset + tlv.size)) |
|
||||
return out; |
|
||||
|
WebArgInputTLV input_tlv; |
||||
|
std::memcpy(&input_tlv, web_arg.data() + current_offset, sizeof(WebArgInputTLV)); |
||||
|
|
||||
std::vector<u8> data(tlv.size); |
|
||||
std::memcpy(data.data(), arg.data() + offset, tlv.size); |
|
||||
offset += tlv.size; |
|
||||
|
current_offset += sizeof(WebArgInputTLV); |
||||
|
|
||||
out.insert_or_assign(tlv.type, data); |
|
||||
|
if (web_arg.size() < current_offset + input_tlv.arg_data_size) { |
||||
|
return input_tlv_map; |
||||
} |
} |
||||
|
|
||||
return out; |
|
||||
} |
|
||||
|
std::vector<u8> 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; |
||||
|
|
||||
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); |
|
||||
|
input_tlv_map.insert_or_assign(input_tlv.input_tlv_type, std::move(data)); |
||||
|
} |
||||
|
|
||||
if (res != nullptr) { |
|
||||
return res->GetRomFS(); |
|
||||
|
return input_tlv_map; |
||||
} |
} |
||||
|
|
||||
if (type == FileSys::ContentRecordType::Data) { |
|
||||
|
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 (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 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; |
return nullptr; |
||||
} |
} |
||||
|
|
||||
} // Anonymous namespace
|
|
||||
|
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(), |
||||
|
system.GetContentProvider()}; |
||||
|
|
||||
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_} {} |
|
||||
|
return pm.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(), nca_type); |
||||
|
} |
||||
|
} |
||||
|
|
||||
WebBrowser::~WebBrowser() = default; |
|
||||
|
void ExtractSharedFonts(Core::System& system) { |
||||
|
static constexpr std::array<const char*, 7> DECRYPTED_SHARED_FONTS{ |
||||
|
"FontStandard.ttf", |
||||
|
"FontChineseSimplified.ttf", |
||||
|
"FontExtendedChineseSimplified.ttf", |
||||
|
"FontChineseTraditional.ttf", |
||||
|
"FontKorean.ttf", |
||||
|
"FontNintendoExtended.ttf", |
||||
|
"FontNintendoExtended2.ttf", |
||||
|
}; |
||||
|
|
||||
void WebBrowser::Initialize() { |
|
||||
Applet::Initialize(); |
|
||||
|
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); |
||||
|
|
||||
complete = false; |
|
||||
temporary_dir.clear(); |
|
||||
filename.clear(); |
|
||||
status = RESULT_SUCCESS; |
|
||||
|
const auto font_file_path = |
||||
|
Common::FS::SanitizePath(fmt::format("{}/{}", fonts_dir, DECRYPTED_SHARED_FONTS[i]), |
||||
|
Common::FS::DirectorySeparator::PlatformDefault); |
||||
|
|
||||
const auto web_arg_storage = broker.PopNormalDataToApplet(); |
|
||||
ASSERT(web_arg_storage != nullptr); |
|
||||
const auto& web_arg = web_arg_storage->GetData(); |
|
||||
|
if (Common::FS::Exists(font_file_path)) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
ASSERT(web_arg.size() >= 0x8); |
|
||||
std::memcpy(&kind, web_arg.data() + 0x4, sizeof(ShimKind)); |
|
||||
|
const auto font = NS::SHARED_FONTS[i]; |
||||
|
const auto font_title_id = static_cast<u64>(font.first); |
||||
|
|
||||
args = GetWebArguments(web_arg); |
|
||||
|
const auto nca = system.GetFileSystemController().GetSystemNANDContents()->GetEntry( |
||||
|
font_title_id, FileSys::ContentRecordType::Data); |
||||
|
|
||||
InitializeInternal(); |
|
||||
} |
|
||||
|
FileSys::VirtualFile romfs; |
||||
|
|
||||
bool WebBrowser::TransactionComplete() const { |
|
||||
return complete; |
|
||||
|
if (!nca) { |
||||
|
romfs = FileSys::SystemArchive::SynthesizeSystemArchive(font_title_id); |
||||
|
} else { |
||||
|
romfs = nca->GetRomFS(); |
||||
} |
} |
||||
|
|
||||
ResultCode WebBrowser::GetStatus() const { |
|
||||
return status; |
|
||||
|
if (!romfs) { |
||||
|
LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} cannot be extracted!", |
||||
|
font_title_id); |
||||
|
continue; |
||||
} |
} |
||||
|
|
||||
void WebBrowser::ExecuteInteractive() { |
|
||||
UNIMPLEMENTED_MSG("Unexpected interactive data recieved!"); |
|
||||
} |
|
||||
|
const auto extracted_romfs = FileSys::ExtractRomFS(romfs); |
||||
|
|
||||
void WebBrowser::Execute() { |
|
||||
if (complete) { |
|
||||
return; |
|
||||
|
if (!extracted_romfs) { |
||||
|
LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} failed to extract!", |
||||
|
font_title_id); |
||||
|
continue; |
||||
} |
} |
||||
|
|
||||
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; |
|
||||
|
const auto font_file = extracted_romfs->GetFile(font.second); |
||||
|
|
||||
return; |
|
||||
|
if (!font_file) { |
||||
|
LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} has no font file \"{}\"!", |
||||
|
font_title_id, font.second); |
||||
|
continue; |
||||
} |
} |
||||
|
|
||||
ExecuteInternal(); |
|
||||
} |
|
||||
|
std::vector<u32> font_data_u32(font_file->GetSize() / sizeof(u32)); |
||||
|
font_file->ReadBytes<u32>(font_data_u32.data(), font_file->GetSize()); |
||||
|
|
||||
void WebBrowser::UnpackRomFS() { |
|
||||
if (unpacked) |
|
||||
return; |
|
||||
|
std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(), |
||||
|
Common::swap32); |
||||
|
|
||||
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); |
|
||||
|
std::vector<u8> decrypted_data(font_file->GetSize() - 8); |
||||
|
|
||||
unpacked = true; |
|
||||
} |
|
||||
|
NS::DecryptSharedFontToTTF(font_data_u32, decrypted_data); |
||||
|
|
||||
void WebBrowser::Finalize() { |
|
||||
complete = true; |
|
||||
|
FileSys::VirtualFile decrypted_font = std::make_shared<FileSys::VectorVfsFile>( |
||||
|
std::move(decrypted_data), DECRYPTED_SHARED_FONTS[i]); |
||||
|
|
||||
WebCommonReturnValue out{}; |
|
||||
out.result_code = 0; |
|
||||
out.last_url_size = 0; |
|
||||
|
const auto temp_dir = |
||||
|
system.GetFilesystem()->CreateDirectory(fonts_dir, FileSys::Mode::ReadWrite); |
||||
|
|
||||
std::vector<u8> data(sizeof(WebCommonReturnValue)); |
|
||||
std::memcpy(data.data(), &out, sizeof(WebCommonReturnValue)); |
|
||||
|
|
||||
broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(data))); |
|
||||
broker.SignalStateChanged(); |
|
||||
|
const auto out_file = temp_dir->CreateFile(DECRYPTED_SHARED_FONTS[i]); |
||||
|
|
||||
if (!temporary_dir.empty() && Common::FS::IsDirectory(temporary_dir)) { |
|
||||
Common::FS::DeleteDirRecursively(temporary_dir); |
|
||||
|
FileSys::VfsRawCopy(decrypted_font, out_file); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
void WebBrowser::InitializeInternal() { |
|
||||
using WebAppletInitializer = void (WebBrowser::*)(); |
|
||||
|
} // namespace
|
||||
|
|
||||
constexpr std::array<WebAppletInitializer, SHIM_KIND_COUNT> functions{ |
|
||||
nullptr, &WebBrowser::InitializeShop, |
|
||||
nullptr, &WebBrowser::InitializeOffline, |
|
||||
nullptr, nullptr, |
|
||||
nullptr, nullptr, |
|
||||
}; |
|
||||
|
WebBrowser::WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_) |
||||
|
: Applet{system_.Kernel()}, frontend(frontend_), system{system_} {} |
||||
|
|
||||
const auto index = static_cast<u32>(kind); |
|
||||
|
WebBrowser::~WebBrowser() = default; |
||||
|
|
||||
if (index > functions.size() || functions[index] == nullptr) { |
|
||||
LOG_ERROR(Service_AM, "Invalid shim_kind={:08X}", index); |
|
||||
return; |
|
||||
} |
|
||||
|
void WebBrowser::Initialize() { |
||||
|
Applet::Initialize(); |
||||
|
|
||||
const auto function = functions[index]; |
|
||||
(this->*function)(); |
|
||||
} |
|
||||
|
LOG_INFO(Service_AM, "Initializing Web Browser Applet."); |
||||
|
|
||||
void WebBrowser::ExecuteInternal() { |
|
||||
using WebAppletExecutor = void (WebBrowser::*)(); |
|
||||
|
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); |
||||
|
|
||||
constexpr std::array<WebAppletExecutor, SHIM_KIND_COUNT> functions{ |
|
||||
nullptr, &WebBrowser::ExecuteShop, |
|
||||
nullptr, &WebBrowser::ExecuteOffline, |
|
||||
nullptr, nullptr, |
|
||||
nullptr, nullptr, |
|
||||
}; |
|
||||
|
web_applet_version = WebAppletVersion{common_args.library_version}; |
||||
|
|
||||
|
const auto web_arg_storage = broker.PopNormalDataToApplet(); |
||||
|
ASSERT(web_arg_storage != nullptr); |
||||
|
|
||||
const auto index = static_cast<u32>(kind); |
|
||||
|
const auto& web_arg = web_arg_storage->GetData(); |
||||
|
ASSERT_OR_EXECUTE(web_arg.size() >= sizeof(WebArgHeader), { return; }); |
||||
|
|
||||
if (index > functions.size() || functions[index] == nullptr) { |
|
||||
LOG_ERROR(Service_AM, "Invalid shim_kind={:08X}", index); |
|
||||
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); |
||||
|
|
||||
|
ExtractSharedFonts(system); |
||||
|
|
||||
|
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; |
||||
|
} |
||||
} |
} |
||||
|
|
||||
const auto function = functions[index]; |
|
||||
(this->*function)(); |
|
||||
|
bool WebBrowser::TransactionComplete() const { |
||||
|
return complete; |
||||
} |
} |
||||
|
|
||||
void WebBrowser::InitializeShop() { |
|
||||
if (frontend_e_commerce == nullptr) { |
|
||||
LOG_ERROR(Service_AM, "Missing ECommerce Applet frontend!"); |
|
||||
status = RESULT_UNKNOWN; |
|
||||
return; |
|
||||
|
ResultCode WebBrowser::GetStatus() const { |
||||
|
return status; |
||||
} |
} |
||||
|
|
||||
const auto user_id_data = args.find(WebArgTLVType::UserID); |
|
||||
|
void WebBrowser::ExecuteInteractive() { |
||||
|
UNIMPLEMENTED_MSG("WebSession is not implemented"); |
||||
|
} |
||||
|
|
||||
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)); |
|
||||
|
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; |
||||
|
} |
||||
} |
} |
||||
|
|
||||
const auto url = args.find(WebArgTLVType::ShopArgumentsURL); |
|
||||
|
void WebBrowser::ExtractOfflineRomFS() { |
||||
|
LOG_DEBUG(Service_AM, "Extracting RomFS to {}", offline_cache_dir); |
||||
|
|
||||
if (url == args.end()) { |
|
||||
LOG_ERROR(Service_AM, "Missing EShop Arguments URL for initialization!"); |
|
||||
status = RESULT_UNKNOWN; |
|
||||
return; |
|
||||
} |
|
||||
|
const auto extracted_romfs_dir = |
||||
|
FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard); |
||||
|
|
||||
std::vector<std::string> split_query; |
|
||||
Common::SplitString(Common::StringFromFixedZeroTerminatedBuffer( |
|
||||
reinterpret_cast<const char*>(url->second.data()), url->second.size()), |
|
||||
'?', split_query); |
|
||||
|
const auto temp_dir = |
||||
|
system.GetFilesystem()->CreateDirectory(offline_cache_dir, FileSys::Mode::ReadWrite); |
||||
|
|
||||
// 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; |
|
||||
|
FileSys::VfsRawCopyD(extracted_romfs_dir, temp_dir); |
||||
} |
} |
||||
|
|
||||
std::vector<std::string> queries; |
|
||||
Common::SplitString(split_query[1], '&', queries); |
|
||||
|
|
||||
const auto split_single_query = |
|
||||
[](const std::string& in) -> std::pair<std::string, std::string> { |
|
||||
const auto index = in.find('='); |
|
||||
if (index == std::string::npos || index == in.size() - 1) { |
|
||||
return {in, ""}; |
|
||||
|
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
|
||||
} |
} |
||||
|
|
||||
return {in.substr(0, index), in.substr(index + 1)}; |
|
||||
}; |
|
||||
|
WebCommonReturnValue web_common_return_value; |
||||
|
|
||||
std::transform(queries.begin(), queries.end(), |
|
||||
std::inserter(shop_query, std::next(shop_query.begin())), split_single_query); |
|
||||
|
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(); |
||||
|
|
||||
const auto scene = shop_query.find("scene"); |
|
||||
|
LOG_DEBUG(Service_AM, "WebCommonReturnValue: exit_reason={}, last_url={}, last_url_size={}", |
||||
|
exit_reason, last_url, last_url.size()); |
||||
|
|
||||
if (scene == shop_query.end()) { |
|
||||
LOG_ERROR(Service_AM, "No scene parameter was passed via shop query!"); |
|
||||
status = RESULT_UNKNOWN; |
|
||||
return; |
|
||||
|
complete = true; |
||||
|
std::vector<u8> out_data(sizeof(WebCommonReturnValue)); |
||||
|
std::memcpy(out_data.data(), &web_common_return_value, out_data.size()); |
||||
|
broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(out_data))); |
||||
|
broker.SignalStateChanged(); |
||||
} |
} |
||||
|
|
||||
const std::map<std::string, ShopWebTarget, std::less<>> target_map{ |
|
||||
{"product_detail", ShopWebTarget::ApplicationInfo}, |
|
||||
{"aocs", ShopWebTarget::AddOnContentList}, |
|
||||
{"subscriptions", ShopWebTarget::SubscriptionList}, |
|
||||
{"consumption", ShopWebTarget::ConsumableItemList}, |
|
||||
{"settings", ShopWebTarget::Settings}, |
|
||||
{"top", ShopWebTarget::Home}, |
|
||||
}; |
|
||||
|
|
||||
const auto target = target_map.find(scene->second); |
|
||||
if (target == target_map.end()) { |
|
||||
LOG_ERROR(Service_AM, "Scene for shop query is invalid! (scene={})", scene->second); |
|
||||
status = RESULT_UNKNOWN; |
|
||||
return; |
|
||||
|
bool WebBrowser::InputTLVExistsInMap(WebArgInputTLVType input_tlv_type) const { |
||||
|
return web_arg_input_tlv_map.find(input_tlv_type) != web_arg_input_tlv_map.end(); |
||||
} |
} |
||||
|
|
||||
shop_web_target = target->second; |
|
||||
|
std::optional<std::vector<u8>> WebBrowser::GetInputTLVData(WebArgInputTLVType input_tlv_type) { |
||||
|
const auto map_it = web_arg_input_tlv_map.find(input_tlv_type); |
||||
|
|
||||
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); |
|
||||
|
if (map_it == web_arg_input_tlv_map.end()) { |
||||
|
return std::nullopt; |
||||
} |
} |
||||
|
|
||||
const auto mode_data = shop_query.find("mode"); |
|
||||
if (mode_data != shop_query.end()) { |
|
||||
shop_full_display = mode_data->second == "full"; |
|
||||
} |
|
||||
|
return map_it->second; |
||||
} |
} |
||||
|
|
||||
|
void WebBrowser::InitializeShop() {} |
||||
|
|
||||
|
void WebBrowser::InitializeLogin() {} |
||||
|
|
||||
void WebBrowser::InitializeOffline() { |
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 document_path = |
||||
|
ParseStringValue(GetInputTLVData(WebArgInputTLVType::DocumentPath).value()); |
||||
|
|
||||
const auto url_data = args[WebArgTLVType::DocumentPath]; |
|
||||
filename = Common::StringFromFixedZeroTerminatedBuffer( |
|
||||
reinterpret_cast<const char*>(url_data.data()), url_data.size()); |
|
||||
|
const auto document_kind = |
||||
|
ParseRawValue<DocumentKind>(GetInputTLVData(WebArgInputTLVType::DocumentKind).value()); |
||||
|
|
||||
OfflineWebSource source; |
|
||||
ASSERT(args[WebArgTLVType::DocumentKind].size() >= 4); |
|
||||
std::memcpy(&source, args[WebArgTLVType::DocumentKind].data(), sizeof(OfflineWebSource)); |
|
||||
|
std::string additional_paths; |
||||
|
|
||||
constexpr std::array<const char*, 3> WEB_SOURCE_NAMES{ |
|
||||
|
switch (document_kind) { |
||||
|
case DocumentKind::OfflineHtmlPage: |
||||
|
default: |
||||
|
title_id = system.CurrentProcess()->GetTitleID(); |
||||
|
nca_type = FileSys::ContentRecordType::HtmlDocument; |
||||
|
additional_paths = "html-document"; |
||||
|
break; |
||||
|
case DocumentKind::ApplicationLegalInformation: |
||||
|
title_id = ParseRawValue<u64>(GetInputTLVData(WebArgInputTLVType::ApplicationID).value()); |
||||
|
nca_type = FileSys::ContentRecordType::LegalInformation; |
||||
|
break; |
||||
|
case DocumentKind::SystemDataPage: |
||||
|
title_id = ParseRawValue<u64>(GetInputTLVData(WebArgInputTLVType::SystemDataID).value()); |
||||
|
nca_type = FileSys::ContentRecordType::Data; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
static constexpr std::array<const char*, 3> RESOURCE_TYPES{ |
||||
"manual", |
"manual", |
||||
"legal", |
|
||||
"system", |
|
||||
|
"legal_information", |
||||
|
"system_data", |
||||
}; |
}; |
||||
|
|
||||
temporary_dir = |
|
||||
Common::FS::SanitizePath(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + |
|
||||
"web_applet_" + WEB_SOURCE_NAMES[static_cast<u32>(source) - 1], |
|
||||
|
offline_cache_dir = Common::FS::SanitizePath( |
||||
|
fmt::format("{}/offline_web_applet_{}/{:016X}", |
||||
|
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir), |
||||
|
RESOURCE_TYPES[static_cast<u32>(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); |
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(); |
|
||||
|
void WebBrowser::InitializeShare() {} |
||||
|
|
||||
|
void WebBrowser::InitializeWeb() { |
||||
|
external_url = ParseStringValue(GetInputTLVData(WebArgInputTLVType::InitialURL).value()); |
||||
} |
} |
||||
|
|
||||
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!"); |
|
||||
|
void WebBrowser::InitializeWifi() {} |
||||
|
|
||||
|
void WebBrowser::InitializeLobby() {} |
||||
|
|
||||
|
void WebBrowser::ExecuteShop() { |
||||
|
LOG_WARNING(Service_AM, "(STUBBED) called, Shop Applet is not implemented"); |
||||
|
WebBrowserExit(WebExitReason::EndButtonPressed); |
||||
} |
} |
||||
|
|
||||
std::string path_additional_directory; |
|
||||
if (source == OfflineWebSource::OfflineHtmlPage) { |
|
||||
path_additional_directory = std::string(DIR_SEP).append("html-document"); |
|
||||
|
void WebBrowser::ExecuteLogin() { |
||||
|
LOG_WARNING(Service_AM, "(STUBBED) called, Login Applet is not implemented"); |
||||
|
WebBrowserExit(WebExitReason::EndButtonPressed); |
||||
} |
} |
||||
|
|
||||
filename = |
|
||||
Common::FS::SanitizePath(temporary_dir + path_additional_directory + DIR_SEP + filename, |
|
||||
|
void WebBrowser::ExecuteOffline() { |
||||
|
const auto main_url = Common::FS::SanitizePath(GetMainURL(offline_document), |
||||
Common::FS::DirectorySeparator::PlatformDefault); |
Common::FS::DirectorySeparator::PlatformDefault); |
||||
} |
|
||||
|
|
||||
void WebBrowser::ExecuteShop() { |
|
||||
const auto callback = [this]() { Finalize(); }; |
|
||||
|
if (!Common::FS::Exists(main_url)) { |
||||
|
offline_romfs = GetOfflineRomFS(system, title_id, nca_type); |
||||
|
|
||||
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; |
|
||||
|
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; |
||||
|
} |
||||
} |
} |
||||
|
|
||||
return true; |
|
||||
}; |
|
||||
|
LOG_INFO(Service_AM, "Opening offline document at {}", offline_document); |
||||
|
|
||||
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(); |
|
||||
|
frontend.OpenLocalWebPage( |
||||
|
offline_document, [this] { ExtractOfflineRomFS(); }, |
||||
|
[this](WebExitReason exit_reason, std::string last_url) { |
||||
|
WebBrowserExit(exit_reason, last_url); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
void WebBrowser::ExecuteShare() { |
||||
|
LOG_WARNING(Service_AM, "(STUBBED) called, Share Applet is not implemented"); |
||||
|
WebBrowserExit(WebExitReason::EndButtonPressed); |
||||
} |
} |
||||
|
|
||||
|
void WebBrowser::ExecuteWeb() { |
||||
|
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::ExecuteOffline() { |
|
||||
frontend.OpenPageLocal( |
|
||||
filename, [this] { UnpackRomFS(); }, [this] { Finalize(); }); |
|
||||
|
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
|
} // namespace Service::AM::Applets
|
||||
@ -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 <array> |
||||
|
#include <unordered_map> |
||||
|
#include <vector> |
||||
|
|
||||
|
#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<char, 0x1000> last_url{}; |
||||
|
u64 last_url_size{}; |
||||
|
}; |
||||
|
static_assert(sizeof(WebCommonReturnValue) == 0x1010, "WebCommonReturnValue has incorrect size."); |
||||
|
|
||||
|
using WebArgInputTLVMap = std::unordered_map<WebArgInputTLVType, std::vector<u8>>; |
||||
|
|
||||
|
} // namespace Service::AM::Applets |
||||
@ -1,115 +1,414 @@ |
|||||
// Copyright 2018 yuzu Emulator Project
|
|
||||
|
// Copyright 2020 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||
|
|
||||
#include <mutex>
|
|
||||
|
|
||||
|
#ifdef YUZU_USE_QT_WEB_ENGINE
|
||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||
|
|
||||
#include "core/hle/lock.h"
|
|
||||
|
#include <QWebEngineProfile>
|
||||
|
#include <QWebEngineScript>
|
||||
|
#include <QWebEngineScriptCollection>
|
||||
|
#include <QWebEngineSettings>
|
||||
|
#include <QWebEngineUrlScheme>
|
||||
|
#endif
|
||||
|
|
||||
|
#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.h"
|
||||
|
#include "yuzu/applets/web_browser_scripts.h"
|
||||
#include "yuzu/main.h"
|
#include "yuzu/main.h"
|
||||
|
#include "yuzu/util/url_request_interceptor.h"
|
||||
|
|
||||
#ifdef YUZU_USE_QT_WEB_ENGINE
|
#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"); |
|
||||
}; |
|
||||
|
namespace { |
||||
|
|
||||
window.nx.playReport.incrementCounter = function () { |
|
||||
console.log("nx.playReport.incrementCounter called - unimplemented"); |
|
||||
}; |
|
||||
|
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; |
||||
|
} |
||||
|
} |
||||
|
|
||||
window.nx.footer = {}; |
|
||||
window.nx.footer.unsetAssign = function () { |
|
||||
console.log("nx.footer.unsetAssign called - unimplemented"); |
|
||||
}; |
|
||||
|
} // Anonymous namespace
|
||||
|
|
||||
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; |
|
||||
|
QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system, |
||||
|
InputCommon::InputSubsystem* input_subsystem_) |
||||
|
: QWebEngineView(parent), input_subsystem{input_subsystem_}, |
||||
|
url_interceptor(std::make_unique<UrlRequestInterceptor>()), |
||||
|
input_interpreter(std::make_unique<InputInterpreter>(system)), |
||||
|
default_profile{QWebEngineProfile::defaultProfile()}, |
||||
|
global_settings{QWebEngineSettings::globalSettings()} { |
||||
|
QWebEngineScript gamepad; |
||||
|
QWebEngineScript window_nx; |
||||
|
|
||||
|
gamepad.setName(QStringLiteral("gamepad_script.js")); |
||||
|
window_nx.setName(QStringLiteral("window_nx_script.js")); |
||||
|
|
||||
|
gamepad.setSourceCode(QString::fromStdString(GAMEPAD_SCRIPT)); |
||||
|
window_nx.setSourceCode(QString::fromStdString(WINDOW_NX_SCRIPT)); |
||||
|
|
||||
|
gamepad.setInjectionPoint(QWebEngineScript::DocumentCreation); |
||||
|
window_nx.setInjectionPoint(QWebEngineScript::DocumentCreation); |
||||
|
|
||||
|
gamepad.setWorldId(QWebEngineScript::MainWorld); |
||||
|
window_nx.setWorldId(QWebEngineScript::MainWorld); |
||||
|
|
||||
|
gamepad.setRunsOnSubFrames(true); |
||||
|
window_nx.setRunsOnSubFrames(true); |
||||
|
|
||||
|
default_profile->scripts()->insert(gamepad); |
||||
|
default_profile->scripts()->insert(window_nx); |
||||
|
|
||||
|
default_profile->setRequestInterceptor(url_interceptor.get()); |
||||
|
|
||||
|
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); |
||||
|
|
||||
|
global_settings->setFontFamily(QWebEngineSettings::StandardFont, QStringLiteral("Roboto")); |
||||
|
|
||||
|
connect( |
||||
|
page(), &QWebEnginePage::windowCloseRequested, page(), |
||||
|
[this] { |
||||
|
if (page()->url() == url_interceptor->GetRequestedURL()) { |
||||
|
SetFinished(true); |
||||
|
SetExitReason(Service::AM::Applets::WebExitReason::WindowClosed); |
||||
|
} |
||||
|
}, |
||||
|
Qt::QueuedConnection); |
||||
|
} |
||||
|
|
||||
|
QtNXWebEngineView::~QtNXWebEngineView() { |
||||
|
SetFinished(true); |
||||
|
StopInputThread(); |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
SetLastURL("http://localhost/"); |
||||
|
StartInputThread(); |
||||
|
|
||||
|
load(QUrl(QUrl::fromLocalFile(QString::fromStdString(std::string(main_url))).toString() + |
||||
|
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) { |
||||
|
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_; |
||||
|
} |
||||
|
|
||||
|
Service::AM::Applets::WebExitReason QtNXWebEngineView::GetExitReason() const { |
||||
|
return exit_reason; |
||||
|
} |
||||
|
|
||||
|
void QtNXWebEngineView::SetExitReason(Service::AM::Applets::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(); |
||||
|
} |
||||
|
|
||||
|
void QtNXWebEngineView::keyPressEvent(QKeyEvent* event) { |
||||
|
if (is_local) { |
||||
|
input_subsystem->GetKeyboard()->PressKey(event->key()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void QtNXWebEngineView::keyReleaseEvent(QKeyEvent* event) { |
||||
|
if (is_local) { |
||||
|
input_subsystem->GetKeyboard()->ReleaseKey(event->key()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
template <HIDButton... T> |
||||
|
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<u8>(button)), |
||||
|
[&](const QVariant& variant) { |
||||
|
if (variant.toBool()) { |
||||
|
switch (button) { |
||||
|
case HIDButton::A: |
||||
|
SendMultipleKeyPressEvents<Qt::Key_A, Qt::Key_Space, Qt::Key_Return>(); |
||||
break; |
break; |
||||
case 'X': |
|
||||
yuzu_key_callbacks[2] = func; |
|
||||
|
case HIDButton::B: |
||||
|
SendKeyPressEvent(Qt::Key_B); |
||||
break; |
break; |
||||
case 'Y': |
|
||||
yuzu_key_callbacks[3] = func; |
|
||||
|
case HIDButton::X: |
||||
|
SendKeyPressEvent(Qt::Key_X); |
||||
break; |
break; |
||||
case 'L': |
|
||||
yuzu_key_callbacks[6] = func; |
|
||||
|
case HIDButton::Y: |
||||
|
SendKeyPressEvent(Qt::Key_Y); |
||||
break; |
break; |
||||
case 'R': |
|
||||
yuzu_key_callbacks[7] = func; |
|
||||
|
default: |
||||
break; |
break; |
||||
} |
} |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
page()->runJavaScript( |
||||
|
QStringLiteral("if (yuzu_key_callbacks[%1] != null) { yuzu_key_callbacks[%1](); }") |
||||
|
.arg(static_cast<u8>(button))); |
||||
|
} |
||||
}; |
}; |
||||
|
|
||||
var applet_done = false; |
|
||||
window.nx.endApplet = function() { |
|
||||
applet_done = true; |
|
||||
|
(f(T), ...); |
||||
|
} |
||||
|
|
||||
|
template <HIDButton... T> |
||||
|
void QtNXWebEngineView::HandleWindowKeyButtonPressedOnce() { |
||||
|
const auto f = [this](HIDButton button) { |
||||
|
if (input_interpreter->IsButtonPressedOnce(button)) { |
||||
|
SendKeyPressEvent(HIDButtonToKey(button)); |
||||
|
} |
||||
}; |
}; |
||||
|
|
||||
window.onkeypress = function(e) { if (e.keyCode === 13) { applet_done = true; } }; |
|
||||
)"; |
|
||||
|
(f(T), ...); |
||||
|
} |
||||
|
|
||||
|
template <HIDButton... T> |
||||
|
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() { |
||||
|
if (is_local) { |
||||
|
QWidget::releaseKeyboard(); |
||||
|
} |
||||
|
|
||||
QString GetNXShimInjectionScript() { |
|
||||
return QString::fromStdString(NX_SHIM_INJECT_SCRIPT); |
|
||||
|
input_thread_running = false; |
||||
|
if (input_thread.joinable()) { |
||||
|
input_thread.join(); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
NXInputWebEngineView::NXInputWebEngineView(QWidget* parent) : QWebEngineView(parent) {} |
|
||||
|
void QtNXWebEngineView::InputThread() { |
||||
|
// Wait for 1 second before allowing any inputs to be processed.
|
||||
|
std::this_thread::sleep_for(std::chrono::seconds(1)); |
||||
|
|
||||
void NXInputWebEngineView::keyPressEvent(QKeyEvent* event) { |
|
||||
parent()->event(event); |
|
||||
|
if (is_local) { |
||||
|
QWidget::grabKeyboard(); |
||||
} |
} |
||||
|
|
||||
void NXInputWebEngineView::keyReleaseEvent(QKeyEvent* event) { |
|
||||
parent()->event(event); |
|
||||
|
while (input_thread_running) { |
||||
|
input_interpreter->PollInput(); |
||||
|
|
||||
|
HandleWindowFooterButtonPressedOnce<HIDButton::A, HIDButton::B, HIDButton::X, HIDButton::Y, |
||||
|
HIDButton::L, HIDButton::R>(); |
||||
|
|
||||
|
HandleWindowKeyButtonPressedOnce<HIDButton::DLeft, HIDButton::DUp, HIDButton::DRight, |
||||
|
HIDButton::DDown, HIDButton::LStickLeft, |
||||
|
HIDButton::LStickUp, HIDButton::LStickRight, |
||||
|
HIDButton::LStickDown>(); |
||||
|
|
||||
|
HandleWindowKeyButtonHold<HIDButton::DLeft, HIDButton::DUp, HIDButton::DRight, |
||||
|
HIDButton::DDown, HIDButton::LStickLeft, HIDButton::LStickUp, |
||||
|
HIDButton::LStickRight, HIDButton::LStickDown>(); |
||||
|
|
||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(50)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
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
|
#endif
|
||||
|
|
||||
QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { |
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); |
|
||||
|
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, |
||||
|
&QtWebBrowser::MainWindowWebBrowserClosed, Qt::QueuedConnection); |
||||
} |
} |
||||
|
|
||||
QtWebBrowser::~QtWebBrowser() = default; |
QtWebBrowser::~QtWebBrowser() = default; |
||||
|
|
||||
void QtWebBrowser::OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback_, |
|
||||
std::function<void()> finished_callback_) { |
|
||||
unpack_romfs_callback = std::move(unpack_romfs_callback_); |
|
||||
finished_callback = std::move(finished_callback_); |
|
||||
|
void QtWebBrowser::OpenLocalWebPage( |
||||
|
std::string_view local_url, std::function<void()> extract_romfs_callback_, |
||||
|
std::function<void(Service::AM::Applets::WebExitReason, std::string)> 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 MainWindowOpenWebPage(local_url, "", true); |
||||
|
} else { |
||||
|
emit MainWindowOpenWebPage(local_url.substr(0, index), local_url.substr(index), true); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void QtWebBrowser::OpenExternalWebPage( |
||||
|
std::string_view external_url, |
||||
|
std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback_) const { |
||||
|
callback = std::move(callback_); |
||||
|
|
||||
|
const auto index = external_url.find('?'); |
||||
|
|
||||
const auto index = url.find('?'); |
|
||||
if (index == std::string::npos) { |
if (index == std::string::npos) { |
||||
emit MainWindowOpenPage(url, ""); |
|
||||
|
emit MainWindowOpenWebPage(external_url, "", false); |
||||
} else { |
} else { |
||||
const auto front = url.substr(0, index); |
|
||||
const auto back = url.substr(index); |
|
||||
emit MainWindowOpenPage(front, back); |
|
||||
|
emit MainWindowOpenWebPage(external_url.substr(0, index), external_url.substr(index), |
||||
|
false); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
void QtWebBrowser::MainWindowUnpackRomFS() { |
|
||||
// Acquire the HLE mutex
|
|
||||
std::lock_guard lock{HLE::g_hle_lock}; |
|
||||
unpack_romfs_callback(); |
|
||||
|
void QtWebBrowser::MainWindowExtractOfflineRomFS() { |
||||
|
extract_romfs_callback(); |
||||
} |
} |
||||
|
|
||||
void QtWebBrowser::MainWindowFinishedBrowsing() { |
|
||||
// Acquire the HLE mutex
|
|
||||
std::lock_guard lock{HLE::g_hle_lock}; |
|
||||
finished_callback(); |
|
||||
|
void QtWebBrowser::MainWindowWebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, |
||||
|
std::string last_url) { |
||||
|
callback(exit_reason, last_url); |
||||
} |
} |
||||
@ -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(); |
||||
|
})(); |
||||
|
)"; |
||||
@ -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
|
||||
@ -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 <QObject> |
||||
|
#include <QWebEngineUrlRequestInterceptor> |
||||
|
|
||||
|
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 |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue