summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/frontend/applets/general_frontend.cpp68
-rw-r--r--src/core/frontend/applets/general_frontend.h51
-rw-r--r--src/core/frontend/applets/web_browser.cpp24
-rw-r--r--src/core/frontend/applets/web_browser.h20
-rw-r--r--src/core/frontend/input_interpreter.cpp45
-rw-r--r--src/core/frontend/input_interpreter.h120
-rw-r--r--src/core/hle/service/am/applets/applets.cpp35
-rw-r--r--src/core/hle/service/am/applets/applets.h20
-rw-r--r--src/core/hle/service/am/applets/web_browser.cpp792
-rw-r--r--src/core/hle/service/am/applets/web_browser.h80
-rw-r--r--src/core/hle/service/am/applets/web_types.h178
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp2
-rw-r--r--src/core/hle/service/hid/controllers/npad.h3
-rw-r--r--src/core/hle/service/ns/ns.cpp11
-rw-r--r--src/core/hle/service/ns/pl_u.cpp30
-rw-r--r--src/core/hle/service/ns/pl_u.h19
-rw-r--r--src/yuzu/CMakeLists.txt2
-rw-r--r--src/yuzu/applets/web_browser.cpp443
-rw-r--r--src/yuzu/applets/web_browser.h191
-rw-r--r--src/yuzu/applets/web_browser_scripts.h193
-rw-r--r--src/yuzu/bootmanager.cpp4
-rw-r--r--src/yuzu/bootmanager.h2
-rw-r--r--src/yuzu/debugger/profiler.cpp2
-rw-r--r--src/yuzu/debugger/wait_tree.cpp2
-rw-r--r--src/yuzu/main.cpp265
-rw-r--r--src/yuzu/main.h17
-rw-r--r--src/yuzu/main.ui78
-rw-r--r--src/yuzu/util/url_request_interceptor.cpp32
-rw-r--r--src/yuzu/util/url_request_interceptor.h30
30 files changed, 1856 insertions, 905 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 2dad18e4d..59bd3d2a6 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -135,6 +135,8 @@ add_library(core STATIC
135 frontend/emu_window.h 135 frontend/emu_window.h
136 frontend/framebuffer_layout.cpp 136 frontend/framebuffer_layout.cpp
137 frontend/framebuffer_layout.h 137 frontend/framebuffer_layout.h
138 frontend/input_interpreter.cpp
139 frontend/input_interpreter.h
138 frontend/input.h 140 frontend/input.h
139 hardware_interrupt_manager.cpp 141 hardware_interrupt_manager.cpp
140 hardware_interrupt_manager.h 142 hardware_interrupt_manager.h
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<void()> finished) con
53 finished(); 53 finished();
54} 54}
55 55
56ECommerceApplet::~ECommerceApplet() = default;
57
58DefaultECommerceApplet::~DefaultECommerceApplet() = default;
59
60void DefaultECommerceApplet::ShowApplicationInformation(
61 std::function<void()> finished, u64 title_id, std::optional<u128> user_id,
62 std::optional<bool> full_display, std::optional<std::string> extra_parameter) {
63 const auto value = user_id.value_or(u128{});
64 LOG_INFO(Service_AM,
65 "Application requested frontend show application information for EShop, "
66 "title_id={:016X}, user_id={:016X}{:016X}, full_display={}, extra_parameter={}",
67 title_id, value[1], value[0],
68 full_display.has_value() ? fmt::format("{}", *full_display) : "null",
69 extra_parameter.value_or("null"));
70 finished();
71}
72
73void DefaultECommerceApplet::ShowAddOnContentList(std::function<void()> finished, u64 title_id,
74 std::optional<u128> user_id,
75 std::optional<bool> full_display) {
76 const auto value = user_id.value_or(u128{});
77 LOG_INFO(Service_AM,
78 "Application requested frontend show add on content list for EShop, "
79 "title_id={:016X}, user_id={:016X}{:016X}, full_display={}",
80 title_id, value[1], value[0],
81 full_display.has_value() ? fmt::format("{}", *full_display) : "null");
82 finished();
83}
84
85void DefaultECommerceApplet::ShowSubscriptionList(std::function<void()> finished, u64 title_id,
86 std::optional<u128> user_id) {
87 const auto value = user_id.value_or(u128{});
88 LOG_INFO(Service_AM,
89 "Application requested frontend show subscription list for EShop, title_id={:016X}, "
90 "user_id={:016X}{:016X}",
91 title_id, value[1], value[0]);
92 finished();
93}
94
95void DefaultECommerceApplet::ShowConsumableItemList(std::function<void()> finished, u64 title_id,
96 std::optional<u128> user_id) {
97 const auto value = user_id.value_or(u128{});
98 LOG_INFO(
99 Service_AM,
100 "Application requested frontend show consumable item list for EShop, title_id={:016X}, "
101 "user_id={:016X}{:016X}",
102 title_id, value[1], value[0]);
103 finished();
104}
105
106void DefaultECommerceApplet::ShowShopHome(std::function<void()> finished, u128 user_id,
107 bool full_display) {
108 LOG_INFO(Service_AM,
109 "Application requested frontend show home menu for EShop, user_id={:016X}{:016X}, "
110 "full_display={}",
111 user_id[1], user_id[0], full_display);
112 finished();
113}
114
115void DefaultECommerceApplet::ShowSettings(std::function<void()> finished, u128 user_id,
116 bool full_display) {
117 LOG_INFO(Service_AM,
118 "Application requested frontend show settings menu for EShop, user_id={:016X}{:016X}, "
119 "full_display={}",
120 user_id[1], user_id[0], full_display);
121 finished();
122}
123
124} // namespace Core::Frontend 56} // 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:
58 void ShowAllPhotos(std::function<void()> finished) const override; 58 void ShowAllPhotos(std::function<void()> finished) const override;
59}; 59};
60 60
61class ECommerceApplet {
62public:
63 virtual ~ECommerceApplet();
64
65 // Shows a page with application icons, description, name, and price.
66 virtual void ShowApplicationInformation(std::function<void()> finished, u64 title_id,
67 std::optional<u128> user_id = {},
68 std::optional<bool> full_display = {},
69 std::optional<std::string> extra_parameter = {}) = 0;
70
71 // Shows a page with all of the add on content available for a game, with name, description, and
72 // price.
73 virtual void ShowAddOnContentList(std::function<void()> finished, u64 title_id,
74 std::optional<u128> user_id = {},
75 std::optional<bool> full_display = {}) = 0;
76
77 // Shows a page with all of the subscriptions (recurring payments) for a game, with name,
78 // description, price, and renewal period.
79 virtual void ShowSubscriptionList(std::function<void()> finished, u64 title_id,
80 std::optional<u128> user_id = {}) = 0;
81
82 // Shows a page with a list of any additional game related purchasable items (DLC,
83 // subscriptions, etc) for a particular game, with name, description, type, and price.
84 virtual void ShowConsumableItemList(std::function<void()> finished, u64 title_id,
85 std::optional<u128> user_id = {}) = 0;
86
87 // Shows the home page of the shop.
88 virtual void ShowShopHome(std::function<void()> finished, u128 user_id, bool full_display) = 0;
89
90 // Shows the user settings page of the shop.
91 virtual void ShowSettings(std::function<void()> finished, u128 user_id, bool full_display) = 0;
92};
93
94class DefaultECommerceApplet : public ECommerceApplet {
95public:
96 ~DefaultECommerceApplet() override;
97
98 void ShowApplicationInformation(std::function<void()> finished, u64 title_id,
99 std::optional<u128> user_id, std::optional<bool> full_display,
100 std::optional<std::string> extra_parameter) override;
101 void ShowAddOnContentList(std::function<void()> finished, u64 title_id,
102 std::optional<u128> user_id,
103 std::optional<bool> full_display) override;
104 void ShowSubscriptionList(std::function<void()> finished, u64 title_id,
105 std::optional<u128> user_id) override;
106 void ShowConsumableItemList(std::function<void()> finished, u64 title_id,
107 std::optional<u128> user_id) override;
108 void ShowShopHome(std::function<void()> finished, u128 user_id, bool full_display) override;
109 void ShowSettings(std::function<void()> finished, u128 user_id, bool full_display) override;
110};
111
112} // namespace Core::Frontend 61} // namespace Core::Frontend
diff --git a/src/core/frontend/applets/web_browser.cpp b/src/core/frontend/applets/web_browser.cpp
index 528295ffc..50db6a654 100644
--- a/src/core/frontend/applets/web_browser.cpp
+++ b/src/core/frontend/applets/web_browser.cpp
@@ -11,14 +11,22 @@ WebBrowserApplet::~WebBrowserApplet() = default;
11 11
12DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default; 12DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default;
13 13
14void DefaultWebBrowserApplet::OpenPageLocal(std::string_view filename, 14void DefaultWebBrowserApplet::OpenLocalWebPage(
15 std::function<void()> unpack_romfs_callback, 15 std::string_view local_url, std::function<void()> extract_romfs_callback,
16 std::function<void()> finished_callback) { 16 std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const {
17 LOG_INFO(Service_AM, 17 LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open local web page at {}",
18 "(STUBBED) called - No suitable web browser implementation found to open website page " 18 local_url);
19 "at '{}'!", 19
20 filename); 20 callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/");
21 finished_callback(); 21}
22
23void DefaultWebBrowserApplet::OpenExternalWebPage(
24 std::string_view external_url,
25 std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const {
26 LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open external web page at {}",
27 external_url);
28
29 callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/");
22} 30}
23 31
24} // namespace Core::Frontend 32} // namespace Core::Frontend
diff --git a/src/core/frontend/applets/web_browser.h b/src/core/frontend/applets/web_browser.h
index 110e33bc4..1c5ef19a9 100644
--- a/src/core/frontend/applets/web_browser.h
+++ b/src/core/frontend/applets/web_browser.h
@@ -7,22 +7,34 @@
7#include <functional> 7#include <functional>
8#include <string_view> 8#include <string_view>
9 9
10#include "core/hle/service/am/applets/web_types.h"
11
10namespace Core::Frontend { 12namespace Core::Frontend {
11 13
12class WebBrowserApplet { 14class WebBrowserApplet {
13public: 15public:
14 virtual ~WebBrowserApplet(); 16 virtual ~WebBrowserApplet();
15 17
16 virtual void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback, 18 virtual void OpenLocalWebPage(
17 std::function<void()> finished_callback) = 0; 19 std::string_view local_url, std::function<void()> extract_romfs_callback,
20 std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0;
21
22 virtual void OpenExternalWebPage(
23 std::string_view external_url,
24 std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0;
18}; 25};
19 26
20class DefaultWebBrowserApplet final : public WebBrowserApplet { 27class DefaultWebBrowserApplet final : public WebBrowserApplet {
21public: 28public:
22 ~DefaultWebBrowserApplet() override; 29 ~DefaultWebBrowserApplet() override;
23 30
24 void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback, 31 void OpenLocalWebPage(std::string_view local_url, std::function<void()> extract_romfs_callback,
25 std::function<void()> finished_callback) override; 32 std::function<void(Service::AM::Applets::WebExitReason, std::string)>
33 callback) const override;
34
35 void OpenExternalWebPage(std::string_view external_url,
36 std::function<void(Service::AM::Applets::WebExitReason, std::string)>
37 callback) const override;
26}; 38};
27 39
28} // namespace Core::Frontend 40} // namespace Core::Frontend
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 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "core/core.h"
6#include "core/frontend/input_interpreter.h"
7#include "core/hle/service/hid/controllers/npad.h"
8#include "core/hle/service/hid/hid.h"
9#include "core/hle/service/sm/sm.h"
10
11InputInterpreter::InputInterpreter(Core::System& system)
12 : npad{system.ServiceManager()
13 .GetService<Service::HID::Hid>("hid")
14 ->GetAppletResource()
15 ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad)} {}
16
17InputInterpreter::~InputInterpreter() = default;
18
19void InputInterpreter::PollInput() {
20 const u32 button_state = npad.GetAndResetPressState();
21
22 previous_index = current_index;
23 current_index = (current_index + 1) % button_states.size();
24
25 button_states[current_index] = button_state;
26}
27
28bool InputInterpreter::IsButtonPressedOnce(HIDButton button) const {
29 const bool current_press =
30 (button_states[current_index] & (1U << static_cast<u8>(button))) != 0;
31 const bool previous_press =
32 (button_states[previous_index] & (1U << static_cast<u8>(button))) != 0;
33
34 return current_press && !previous_press;
35}
36
37bool InputInterpreter::IsButtonHeld(HIDButton button) const {
38 u32 held_buttons{button_states[0]};
39
40 for (std::size_t i = 1; i < button_states.size(); ++i) {
41 held_buttons &= button_states[i];
42 }
43
44 return (held_buttons & (1U << static_cast<u8>(button))) != 0;
45}
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 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8
9#include "common/common_types.h"
10
11namespace Core {
12class System;
13}
14
15namespace Service::HID {
16class Controller_NPad;
17}
18
19enum class HIDButton : u8 {
20 A,
21 B,
22 X,
23 Y,
24 LStick,
25 RStick,
26 L,
27 R,
28 ZL,
29 ZR,
30 Plus,
31 Minus,
32
33 DLeft,
34 DUp,
35 DRight,
36 DDown,
37
38 LStickLeft,
39 LStickUp,
40 LStickRight,
41 LStickDown,
42
43 RStickLeft,
44 RStickUp,
45 RStickRight,
46 RStickDown,
47
48 LeftSL,
49 LeftSR,
50
51 RightSL,
52 RightSR,
53};
54
55/**
56 * The InputInterpreter class interfaces with HID to retrieve button press states.
57 * Input is intended to be polled every 50ms so that a button is considered to be
58 * held down after 400ms has elapsed since the initial button press and subsequent
59 * repeated presses occur every 50ms.
60 */
61class InputInterpreter {
62public:
63 explicit InputInterpreter(Core::System& system);
64 virtual ~InputInterpreter();
65
66 /// Gets a button state from HID and inserts it into the array of button states.
67 void PollInput();
68
69 /**
70 * The specified button is considered to be pressed once
71 * if it is currently pressed and not pressed previously.
72 *
73 * @param button The button to check.
74 *
75 * @returns True when the button is pressed once.
76 */
77 [[nodiscard]] bool IsButtonPressedOnce(HIDButton button) const;
78
79 /**
80 * Checks whether any of the buttons in the parameter list is pressed once.
81 *
82 * @tparam HIDButton The buttons to check.
83 *
84 * @returns True when at least one of the buttons is pressed once.
85 */
86 template <HIDButton... T>
87 [[nodiscard]] bool IsAnyButtonPressedOnce() {
88 return (IsButtonPressedOnce(T) || ...);
89 }
90
91 /**
92 * The specified button is considered to be held down if it is pressed in all 9 button states.
93 *
94 * @param button The button to check.
95 *
96 * @returns True when the button is held down.
97 */
98 [[nodiscard]] bool IsButtonHeld(HIDButton button) const;
99
100 /**
101 * Checks whether any of the buttons in the parameter list is held down.
102 *
103 * @tparam HIDButton The buttons to check.
104 *
105 * @returns True when at least one of the buttons is held down.
106 */
107 template <HIDButton... T>
108 [[nodiscard]] bool IsAnyButtonHeld() {
109 return (IsButtonHeld(T) || ...);
110 }
111
112private:
113 Service::HID::Controller_NPad& npad;
114
115 /// Stores 9 consecutive button states polled from HID.
116 std::array<u32, 9> button_states{};
117
118 std::size_t previous_index{};
119 std::size_t current_index{};
120};
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() {
142 142
143AppletFrontendSet::AppletFrontendSet() = default; 143AppletFrontendSet::AppletFrontendSet() = default;
144 144
145AppletFrontendSet::AppletFrontendSet(ControllerApplet controller, ECommerceApplet e_commerce, 145AppletFrontendSet::AppletFrontendSet(ControllerApplet controller_applet, ErrorApplet error_applet,
146 ErrorApplet error, ParentalControlsApplet parental_controls, 146 ParentalControlsApplet parental_controls_applet,
147 PhotoViewer photo_viewer, ProfileSelect profile_select, 147 PhotoViewer photo_viewer_, ProfileSelect profile_select_,
148 SoftwareKeyboard software_keyboard, WebBrowser web_browser) 148 SoftwareKeyboard software_keyboard_, WebBrowser web_browser_)
149 : controller{std::move(controller)}, e_commerce{std::move(e_commerce)}, error{std::move(error)}, 149 : controller{std::move(controller_applet)}, error{std::move(error_applet)},
150 parental_controls{std::move(parental_controls)}, photo_viewer{std::move(photo_viewer)}, 150 parental_controls{std::move(parental_controls_applet)},
151 profile_select{std::move(profile_select)}, software_keyboard{std::move(software_keyboard)}, 151 photo_viewer{std::move(photo_viewer_)}, profile_select{std::move(profile_select_)},
152 web_browser{std::move(web_browser)} {} 152 software_keyboard{std::move(software_keyboard_)}, web_browser{std::move(web_browser_)} {}
153 153
154AppletFrontendSet::~AppletFrontendSet() = default; 154AppletFrontendSet::~AppletFrontendSet() = default;
155 155
@@ -170,10 +170,6 @@ void AppletManager::SetAppletFrontendSet(AppletFrontendSet set) {
170 frontend.controller = std::move(set.controller); 170 frontend.controller = std::move(set.controller);
171 } 171 }
172 172
173 if (set.e_commerce != nullptr) {
174 frontend.e_commerce = std::move(set.e_commerce);
175 }
176
177 if (set.error != nullptr) { 173 if (set.error != nullptr) {
178 frontend.error = std::move(set.error); 174 frontend.error = std::move(set.error);
179 } 175 }
@@ -210,10 +206,6 @@ void AppletManager::SetDefaultAppletsIfMissing() {
210 std::make_unique<Core::Frontend::DefaultControllerApplet>(system.ServiceManager()); 206 std::make_unique<Core::Frontend::DefaultControllerApplet>(system.ServiceManager());
211 } 207 }
212 208
213 if (frontend.e_commerce == nullptr) {
214 frontend.e_commerce = std::make_unique<Core::Frontend::DefaultECommerceApplet>();
215 }
216
217 if (frontend.error == nullptr) { 209 if (frontend.error == nullptr) {
218 frontend.error = std::make_unique<Core::Frontend::DefaultErrorApplet>(); 210 frontend.error = std::make_unique<Core::Frontend::DefaultErrorApplet>();
219 } 211 }
@@ -257,13 +249,14 @@ std::shared_ptr<Applet> AppletManager::GetApplet(AppletId id) const {
257 return std::make_shared<ProfileSelect>(system, *frontend.profile_select); 249 return std::make_shared<ProfileSelect>(system, *frontend.profile_select);
258 case AppletId::SoftwareKeyboard: 250 case AppletId::SoftwareKeyboard:
259 return std::make_shared<SoftwareKeyboard>(system, *frontend.software_keyboard); 251 return std::make_shared<SoftwareKeyboard>(system, *frontend.software_keyboard);
252 case AppletId::Web:
253 case AppletId::Shop:
254 case AppletId::OfflineWeb:
255 case AppletId::LoginShare:
256 case AppletId::WebAuth:
257 return std::make_shared<WebBrowser>(system, *frontend.web_browser);
260 case AppletId::PhotoViewer: 258 case AppletId::PhotoViewer:
261 return std::make_shared<PhotoViewer>(system, *frontend.photo_viewer); 259 return std::make_shared<PhotoViewer>(system, *frontend.photo_viewer);
262 case AppletId::LibAppletShop:
263 return std::make_shared<WebBrowser>(system, *frontend.web_browser,
264 frontend.e_commerce.get());
265 case AppletId::LibAppletOff:
266 return std::make_shared<WebBrowser>(system, *frontend.web_browser);
267 default: 260 default:
268 UNIMPLEMENTED_MSG( 261 UNIMPLEMENTED_MSG(
269 "No backend implementation exists for applet_id={:02X}! Falling back to stub applet.", 262 "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 {
50 ProfileSelect = 0x10, 50 ProfileSelect = 0x10,
51 SoftwareKeyboard = 0x11, 51 SoftwareKeyboard = 0x11,
52 MiiEdit = 0x12, 52 MiiEdit = 0x12,
53 LibAppletWeb = 0x13, 53 Web = 0x13,
54 LibAppletShop = 0x14, 54 Shop = 0x14,
55 PhotoViewer = 0x15, 55 PhotoViewer = 0x15,
56 Settings = 0x16, 56 Settings = 0x16,
57 LibAppletOff = 0x17, 57 OfflineWeb = 0x17,
58 LibAppletWhitelisted = 0x18, 58 LoginShare = 0x18,
59 LibAppletAuth = 0x19, 59 WebAuth = 0x19,
60 MyPage = 0x1A, 60 MyPage = 0x1A,
61}; 61};
62 62
@@ -157,7 +157,6 @@ protected:
157 157
158struct AppletFrontendSet { 158struct AppletFrontendSet {
159 using ControllerApplet = std::unique_ptr<Core::Frontend::ControllerApplet>; 159 using ControllerApplet = std::unique_ptr<Core::Frontend::ControllerApplet>;
160 using ECommerceApplet = std::unique_ptr<Core::Frontend::ECommerceApplet>;
161 using ErrorApplet = std::unique_ptr<Core::Frontend::ErrorApplet>; 160 using ErrorApplet = std::unique_ptr<Core::Frontend::ErrorApplet>;
162 using ParentalControlsApplet = std::unique_ptr<Core::Frontend::ParentalControlsApplet>; 161 using ParentalControlsApplet = std::unique_ptr<Core::Frontend::ParentalControlsApplet>;
163 using PhotoViewer = std::unique_ptr<Core::Frontend::PhotoViewerApplet>; 162 using PhotoViewer = std::unique_ptr<Core::Frontend::PhotoViewerApplet>;
@@ -166,10 +165,10 @@ struct AppletFrontendSet {
166 using WebBrowser = std::unique_ptr<Core::Frontend::WebBrowserApplet>; 165 using WebBrowser = std::unique_ptr<Core::Frontend::WebBrowserApplet>;
167 166
168 AppletFrontendSet(); 167 AppletFrontendSet();
169 AppletFrontendSet(ControllerApplet controller, ECommerceApplet e_commerce, ErrorApplet error, 168 AppletFrontendSet(ControllerApplet controller_applet, ErrorApplet error_applet,
170 ParentalControlsApplet parental_controls, PhotoViewer photo_viewer, 169 ParentalControlsApplet parental_controls_applet, PhotoViewer photo_viewer_,
171 ProfileSelect profile_select, SoftwareKeyboard software_keyboard, 170 ProfileSelect profile_select_, SoftwareKeyboard software_keyboard_,
172 WebBrowser web_browser); 171 WebBrowser web_browser_);
173 ~AppletFrontendSet(); 172 ~AppletFrontendSet();
174 173
175 AppletFrontendSet(const AppletFrontendSet&) = delete; 174 AppletFrontendSet(const AppletFrontendSet&) = delete;
@@ -179,7 +178,6 @@ struct AppletFrontendSet {
179 AppletFrontendSet& operator=(AppletFrontendSet&&) noexcept; 178 AppletFrontendSet& operator=(AppletFrontendSet&&) noexcept;
180 179
181 ControllerApplet controller; 180 ControllerApplet controller;
182 ECommerceApplet e_commerce;
183 ErrorApplet error; 181 ErrorApplet error;
184 ParentalControlsApplet parental_controls; 182 ParentalControlsApplet parental_controls;
185 PhotoViewer photo_viewer; 183 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..2ab420789 100644
--- a/src/core/hle/service/am/applets/web_browser.cpp
+++ b/src/core/hle/service/am/applets/web_browser.cpp
@@ -1,558 +1,478 @@
1// Copyright 2018 yuzu emulator team 1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <array>
6#include <cstring>
7#include <vector>
8
9#include "common/assert.h" 5#include "common/assert.h"
10#include "common/common_funcs.h"
11#include "common/common_paths.h" 6#include "common/common_paths.h"
12#include "common/file_util.h" 7#include "common/file_util.h"
13#include "common/hex_util.h"
14#include "common/logging/log.h" 8#include "common/logging/log.h"
15#include "common/string_util.h" 9#include "common/string_util.h"
16#include "core/core.h" 10#include "core/core.h"
17#include "core/file_sys/content_archive.h" 11#include "core/file_sys/content_archive.h"
18#include "core/file_sys/mode.h" 12#include "core/file_sys/mode.h"
19#include "core/file_sys/nca_metadata.h" 13#include "core/file_sys/nca_metadata.h"
14#include "core/file_sys/patch_manager.h"
20#include "core/file_sys/registered_cache.h" 15#include "core/file_sys/registered_cache.h"
21#include "core/file_sys/romfs.h" 16#include "core/file_sys/romfs.h"
22#include "core/file_sys/system_archive/system_archive.h" 17#include "core/file_sys/system_archive/system_archive.h"
23#include "core/file_sys/vfs_types.h" 18#include "core/file_sys/vfs_vector.h"
24#include "core/frontend/applets/general_frontend.h"
25#include "core/frontend/applets/web_browser.h" 19#include "core/frontend/applets/web_browser.h"
26#include "core/hle/kernel/process.h" 20#include "core/hle/kernel/process.h"
21#include "core/hle/result.h"
22#include "core/hle/service/am/am.h"
27#include "core/hle/service/am/applets/web_browser.h" 23#include "core/hle/service/am/applets/web_browser.h"
28#include "core/hle/service/filesystem/filesystem.h" 24#include "core/hle/service/filesystem/filesystem.h"
29#include "core/loader/loader.h" 25#include "core/hle/service/ns/pl_u.h"
30 26
31namespace Service::AM::Applets { 27namespace Service::AM::Applets {
32 28
33enum class WebArgTLVType : u16 {
34 InitialURL = 0x1,
35 ShopArgumentsURL = 0x2, ///< TODO(DarkLordZach): This is not the official name.
36 CallbackURL = 0x3,
37 CallbackableURL = 0x4,
38 ApplicationID = 0x5,
39 DocumentPath = 0x6,
40 DocumentKind = 0x7,
41 SystemDataID = 0x8,
42 ShareStartPage = 0x9,
43 Whitelist = 0xA,
44 News = 0xB,
45 UserID = 0xE,
46 AlbumEntry0 = 0xF,
47 ScreenShotEnabled = 0x10,
48 EcClientCertEnabled = 0x11,
49 Unk12 = 0x12,
50 PlayReportEnabled = 0x13,
51 Unk14 = 0x14,
52 Unk15 = 0x15,
53 BootDisplayKind = 0x17,
54 BackgroundKind = 0x18,
55 FooterEnabled = 0x19,
56 PointerEnabled = 0x1A,
57 LeftStickMode = 0x1B,
58 KeyRepeatFrame1 = 0x1C,
59 KeyRepeatFrame2 = 0x1D,
60 BootAsMediaPlayerInv = 0x1E,
61 DisplayUrlKind = 0x1F,
62 BootAsMediaPlayer = 0x21,
63 ShopJumpEnabled = 0x22,
64 MediaAutoPlayEnabled = 0x23,
65 LobbyParameter = 0x24,
66 ApplicationAlbumEntry = 0x26,
67 JsExtensionEnabled = 0x27,
68 AdditionalCommentText = 0x28,
69 TouchEnabledOnContents = 0x29,
70 UserAgentAdditionalString = 0x2A,
71 AdditionalMediaData0 = 0x2B,
72 MediaPlayerAutoCloseEnabled = 0x2C,
73 PageCacheEnabled = 0x2D,
74 WebAudioEnabled = 0x2E,
75 Unk2F = 0x2F,
76 YouTubeVideoWhitelist = 0x31,
77 FooterFixedKind = 0x32,
78 PageFadeEnabled = 0x33,
79 MediaCreatorApplicationRatingAge = 0x34,
80 BootLoadingIconEnabled = 0x35,
81 PageScrollIndicationEnabled = 0x36,
82 MediaPlayerSpeedControlEnabled = 0x37,
83 AlbumEntry1 = 0x38,
84 AlbumEntry2 = 0x39,
85 AlbumEntry3 = 0x3A,
86 AdditionalMediaData1 = 0x3B,
87 AdditionalMediaData2 = 0x3C,
88 AdditionalMediaData3 = 0x3D,
89 BootFooterButton = 0x3E,
90 OverrideWebAudioVolume = 0x3F,
91 OverrideMediaAudioVolume = 0x40,
92 BootMode = 0x41,
93 WebSessionEnabled = 0x42,
94};
95
96enum class ShimKind : u32 {
97 Shop = 1,
98 Login = 2,
99 Offline = 3,
100 Share = 4,
101 Web = 5,
102 Wifi = 6,
103 Lobby = 7,
104};
105
106enum class ShopWebTarget {
107 ApplicationInfo,
108 AddOnContentList,
109 SubscriptionList,
110 ConsumableItemList,
111 Home,
112 Settings,
113};
114
115namespace { 29namespace {
116 30
117constexpr std::size_t SHIM_KIND_COUNT = 0x8; 31template <typename T>
118 32void ParseRawValue(T& value, const std::vector<u8>& data) {
119struct WebArgHeader { 33 static_assert(std::is_trivially_copyable_v<T>,
120 u16 count; 34 "It's undefined behavior to use memcpy with non-trivially copyable objects");
121 INSERT_PADDING_BYTES(2); 35 std::memcpy(&value, data.data(), data.size());
122 ShimKind kind; 36}
123};
124static_assert(sizeof(WebArgHeader) == 0x8, "WebArgHeader has incorrect size.");
125
126struct WebArgTLV {
127 WebArgTLVType type;
128 u16 size;
129 u32 offset;
130};
131static_assert(sizeof(WebArgTLV) == 0x8, "WebArgTLV has incorrect size.");
132
133struct WebCommonReturnValue {
134 u32 result_code;
135 INSERT_PADDING_BYTES(0x4);
136 std::array<char, 0x1000> last_url;
137 u64 last_url_size;
138};
139static_assert(sizeof(WebCommonReturnValue) == 0x1010, "WebCommonReturnValue has incorrect size.");
140
141struct WebWifiPageArg {
142 INSERT_PADDING_BYTES(4);
143 std::array<char, 0x100> connection_test_url;
144 std::array<char, 0x400> initial_url;
145 std::array<u8, 0x10> nifm_network_uuid;
146 u32 nifm_requirement;
147};
148static_assert(sizeof(WebWifiPageArg) == 0x518, "WebWifiPageArg has incorrect size.");
149
150struct WebWifiReturnValue {
151 INSERT_PADDING_BYTES(4);
152 u32 result;
153};
154static_assert(sizeof(WebWifiReturnValue) == 0x8, "WebWifiReturnValue has incorrect size.");
155
156enum class OfflineWebSource : u32 {
157 OfflineHtmlPage = 0x1,
158 ApplicationLegalInformation = 0x2,
159 SystemDataPage = 0x3,
160};
161
162std::map<WebArgTLVType, std::vector<u8>> GetWebArguments(const std::vector<u8>& arg) {
163 if (arg.size() < sizeof(WebArgHeader))
164 return {};
165
166 WebArgHeader header{};
167 std::memcpy(&header, arg.data(), sizeof(WebArgHeader));
168
169 std::map<WebArgTLVType, std::vector<u8>> out;
170 u64 offset = sizeof(WebArgHeader);
171 for (std::size_t i = 0; i < header.count; ++i) {
172 if (arg.size() < (offset + sizeof(WebArgTLV)))
173 return out;
174 37
175 WebArgTLV tlv{}; 38template <typename T>
176 std::memcpy(&tlv, arg.data() + offset, sizeof(WebArgTLV)); 39T ParseRawValue(const std::vector<u8>& data) {
177 offset += sizeof(WebArgTLV); 40 T value;
41 ParseRawValue(value, data);
42 return value;
43}
178 44
179 offset += tlv.offset; 45std::string ParseStringValue(const std::vector<u8>& data) {
180 if (arg.size() < (offset + tlv.size)) 46 return Common::StringFromFixedZeroTerminatedBuffer(reinterpret_cast<const char*>(data.data()),
181 return out; 47 data.size());
48}
182 49
183 std::vector<u8> data(tlv.size); 50std::string GetMainURL(const std::string& url) {
184 std::memcpy(data.data(), arg.data() + offset, tlv.size); 51 const auto index = url.find('?');
185 offset += tlv.size;
186 52
187 out.insert_or_assign(tlv.type, data); 53 if (index == std::string::npos) {
54 return url;
188 } 55 }
189 56
190 return out; 57 return url.substr(0, index);
191} 58}
192 59
193FileSys::VirtualFile GetApplicationRomFS(const Core::System& system, u64 title_id, 60WebArgInputTLVMap ReadWebArgs(const std::vector<u8>& web_arg, WebArgHeader& web_arg_header) {
194 FileSys::ContentRecordType type) { 61 std::memcpy(&web_arg_header, web_arg.data(), sizeof(WebArgHeader));
195 const auto& installed{system.GetContentProvider()};
196 const auto res = installed.GetEntry(title_id, type);
197 62
198 if (res != nullptr) { 63 if (web_arg.size() == sizeof(WebArgHeader)) {
199 return res->GetRomFS(); 64 return {};
200 } 65 }
201 66
202 if (type == FileSys::ContentRecordType::Data) { 67 WebArgInputTLVMap input_tlv_map;
203 return FileSys::SystemArchive::SynthesizeSystemArchive(title_id); 68
69 u64 current_offset = sizeof(WebArgHeader);
70
71 for (std::size_t i = 0; i < web_arg_header.total_tlv_entries; ++i) {
72 if (web_arg.size() < current_offset + sizeof(WebArgInputTLV)) {
73 return input_tlv_map;
74 }
75
76 WebArgInputTLV input_tlv;
77 std::memcpy(&input_tlv, web_arg.data() + current_offset, sizeof(WebArgInputTLV));
78
79 current_offset += sizeof(WebArgInputTLV);
80
81 if (web_arg.size() < current_offset + input_tlv.arg_data_size) {
82 return input_tlv_map;
83 }
84
85 std::vector<u8> data(input_tlv.arg_data_size);
86 std::memcpy(data.data(), web_arg.data() + current_offset, input_tlv.arg_data_size);
87
88 current_offset += input_tlv.arg_data_size;
89
90 input_tlv_map.insert_or_assign(input_tlv.input_tlv_type, std::move(data));
204 } 91 }
205 92
206 return nullptr; 93 return input_tlv_map;
207} 94}
208 95
209} // Anonymous namespace 96FileSys::VirtualFile GetOfflineRomFS(Core::System& system, u64 title_id,
97 FileSys::ContentRecordType nca_type) {
98 if (nca_type == FileSys::ContentRecordType::Data) {
99 const auto nca =
100 system.GetFileSystemController().GetSystemNANDContents()->GetEntry(title_id, nca_type);
101
102 if (nca == nullptr) {
103 LOG_ERROR(Service_AM,
104 "NCA of type={} with title_id={:016X} is not found in the System NAND!",
105 nca_type, title_id);
106 return FileSys::SystemArchive::SynthesizeSystemArchive(title_id);
107 }
210 108
211WebBrowser::WebBrowser(Core::System& system_, Core::Frontend::WebBrowserApplet& frontend_, 109 return nca->GetRomFS();
212 Core::Frontend::ECommerceApplet* frontend_e_commerce_) 110 } else {
213 : Applet{system_.Kernel()}, frontend(frontend_), 111 const auto nca = system.GetContentProvider().GetEntry(title_id, nca_type);
214 frontend_e_commerce(frontend_e_commerce_), system{system_} {}
215 112
216WebBrowser::~WebBrowser() = default; 113 if (nca == nullptr) {
114 LOG_ERROR(Service_AM,
115 "NCA of type={} with title_id={:016X} is not found in the ContentProvider!",
116 nca_type, title_id);
117 return nullptr;
118 }
217 119
218void WebBrowser::Initialize() { 120 const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
219 Applet::Initialize(); 121 system.GetContentProvider()};
220 122
221 complete = false; 123 return pm.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(), nca_type);
222 temporary_dir.clear(); 124 }
223 filename.clear(); 125}
224 status = RESULT_SUCCESS;
225 126
226 const auto web_arg_storage = broker.PopNormalDataToApplet(); 127void ExtractSharedFonts(Core::System& system) {
227 ASSERT(web_arg_storage != nullptr); 128 static constexpr std::array<const char*, 7> DECRYPTED_SHARED_FONTS{
228 const auto& web_arg = web_arg_storage->GetData(); 129 "FontStandard.ttf",
130 "FontChineseSimplified.ttf",
131 "FontExtendedChineseSimplified.ttf",
132 "FontChineseTraditional.ttf",
133 "FontKorean.ttf",
134 "FontNintendoExtended.ttf",
135 "FontNintendoExtended2.ttf",
136 };
229 137
230 ASSERT(web_arg.size() >= 0x8); 138 for (std::size_t i = 0; i < NS::SHARED_FONTS.size(); ++i) {
231 std::memcpy(&kind, web_arg.data() + 0x4, sizeof(ShimKind)); 139 const auto fonts_dir = Common::FS::SanitizePath(
140 fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
141 Common::FS::DirectorySeparator::PlatformDefault);
232 142
233 args = GetWebArguments(web_arg); 143 const auto font_file_path =
144 Common::FS::SanitizePath(fmt::format("{}/{}", fonts_dir, DECRYPTED_SHARED_FONTS[i]),
145 Common::FS::DirectorySeparator::PlatformDefault);
234 146
235 InitializeInternal(); 147 if (Common::FS::Exists(font_file_path)) {
236} 148 continue;
149 }
237 150
238bool WebBrowser::TransactionComplete() const { 151 const auto font = NS::SHARED_FONTS[i];
239 return complete; 152 const auto font_title_id = static_cast<u64>(font.first);
240}
241 153
242ResultCode WebBrowser::GetStatus() const { 154 const auto nca = system.GetFileSystemController().GetSystemNANDContents()->GetEntry(
243 return status; 155 font_title_id, FileSys::ContentRecordType::Data);
244}
245 156
246void WebBrowser::ExecuteInteractive() { 157 FileSys::VirtualFile romfs;
247 UNIMPLEMENTED_MSG("Unexpected interactive data recieved!");
248}
249 158
250void WebBrowser::Execute() { 159 if (!nca) {
251 if (complete) { 160 romfs = FileSys::SystemArchive::SynthesizeSystemArchive(font_title_id);
252 return; 161 } else {
253 } 162 romfs = nca->GetRomFS();
163 }
254 164
255 if (status != RESULT_SUCCESS) { 165 if (!romfs) {
256 complete = true; 166 LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} cannot be extracted!",
167 font_title_id);
168 continue;
169 }
257 170
258 // This is a workaround in order not to softlock yuzu when an error happens during the 171 const auto extracted_romfs = FileSys::ExtractRomFS(romfs);
259 // webapplet init. In order to avoid an svcBreak, the status is set to RESULT_SUCCESS
260 Finalize();
261 status = RESULT_SUCCESS;
262 172
263 return; 173 if (!extracted_romfs) {
264 } 174 LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} failed to extract!",
175 font_title_id);
176 continue;
177 }
265 178
266 ExecuteInternal(); 179 const auto font_file = extracted_romfs->GetFile(font.second);
267}
268 180
269void WebBrowser::UnpackRomFS() { 181 if (!font_file) {
270 if (unpacked) 182 LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} has no font file \"{}\"!",
271 return; 183 font_title_id, font.second);
184 continue;
185 }
272 186
273 ASSERT(offline_romfs != nullptr); 187 std::vector<u32> font_data_u32(font_file->GetSize() / sizeof(u32));
274 const auto dir = 188 font_file->ReadBytes<u32>(font_data_u32.data(), font_file->GetSize());
275 FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard);
276 const auto& vfs{system.GetFilesystem()};
277 const auto temp_dir = vfs->CreateDirectory(temporary_dir, FileSys::Mode::ReadWrite);
278 FileSys::VfsRawCopyD(dir, temp_dir);
279 189
280 unpacked = true; 190 std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(),
281} 191 Common::swap32);
282 192
283void WebBrowser::Finalize() { 193 std::vector<u8> decrypted_data(font_file->GetSize() - 8);
284 complete = true;
285 194
286 WebCommonReturnValue out{}; 195 NS::DecryptSharedFontToTTF(font_data_u32, decrypted_data);
287 out.result_code = 0;
288 out.last_url_size = 0;
289 196
290 std::vector<u8> data(sizeof(WebCommonReturnValue)); 197 FileSys::VirtualFile decrypted_font = std::make_shared<FileSys::VectorVfsFile>(
291 std::memcpy(data.data(), &out, sizeof(WebCommonReturnValue)); 198 std::move(decrypted_data), DECRYPTED_SHARED_FONTS[i]);
292 199
293 broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(data))); 200 const auto temp_dir =
294 broker.SignalStateChanged(); 201 system.GetFilesystem()->CreateDirectory(fonts_dir, FileSys::Mode::ReadWrite);
202
203 const auto out_file = temp_dir->CreateFile(DECRYPTED_SHARED_FONTS[i]);
295 204
296 if (!temporary_dir.empty() && Common::FS::IsDirectory(temporary_dir)) { 205 FileSys::VfsRawCopy(decrypted_font, out_file);
297 Common::FS::DeleteDirRecursively(temporary_dir);
298 } 206 }
299} 207}
300 208
301void WebBrowser::InitializeInternal() { 209} // namespace
302 using WebAppletInitializer = void (WebBrowser::*)();
303 210
304 constexpr std::array<WebAppletInitializer, SHIM_KIND_COUNT> functions{ 211WebBrowser::WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_)
305 nullptr, &WebBrowser::InitializeShop, 212 : Applet{system_.Kernel()}, frontend(frontend_), system{system_} {}
306 nullptr, &WebBrowser::InitializeOffline,
307 nullptr, nullptr,
308 nullptr, nullptr,
309 };
310 213
311 const auto index = static_cast<u32>(kind); 214WebBrowser::~WebBrowser() = default;
312 215
313 if (index > functions.size() || functions[index] == nullptr) { 216void WebBrowser::Initialize() {
314 LOG_ERROR(Service_AM, "Invalid shim_kind={:08X}", index); 217 Applet::Initialize();
315 return;
316 }
317 218
318 const auto function = functions[index]; 219 LOG_INFO(Service_AM, "Initializing Web Browser Applet.");
319 (this->*function)();
320}
321 220
322void WebBrowser::ExecuteInternal() { 221 LOG_DEBUG(Service_AM,
323 using WebAppletExecutor = void (WebBrowser::*)(); 222 "Initializing Applet with common_args: arg_version={}, lib_version={}, "
223 "play_startup_sound={}, size={}, system_tick={}, theme_color={}",
224 common_args.arguments_version, common_args.library_version,
225 common_args.play_startup_sound, common_args.size, common_args.system_tick,
226 common_args.theme_color);
324 227
325 constexpr std::array<WebAppletExecutor, SHIM_KIND_COUNT> functions{ 228 web_applet_version = WebAppletVersion{common_args.library_version};
326 nullptr, &WebBrowser::ExecuteShop,
327 nullptr, &WebBrowser::ExecuteOffline,
328 nullptr, nullptr,
329 nullptr, nullptr,
330 };
331 229
332 const auto index = static_cast<u32>(kind); 230 const auto web_arg_storage = broker.PopNormalDataToApplet();
231 ASSERT(web_arg_storage != nullptr);
333 232
334 if (index > functions.size() || functions[index] == nullptr) { 233 const auto& web_arg = web_arg_storage->GetData();
335 LOG_ERROR(Service_AM, "Invalid shim_kind={:08X}", index); 234 ASSERT_OR_EXECUTE(web_arg.size() >= sizeof(WebArgHeader), { return; });
336 return;
337 }
338 235
339 const auto function = functions[index]; 236 web_arg_input_tlv_map = ReadWebArgs(web_arg, web_arg_header);
340 (this->*function)();
341}
342 237
343void WebBrowser::InitializeShop() { 238 LOG_DEBUG(Service_AM, "WebArgHeader: total_tlv_entries={}, shim_kind={}",
344 if (frontend_e_commerce == nullptr) { 239 web_arg_header.total_tlv_entries, web_arg_header.shim_kind);
345 LOG_ERROR(Service_AM, "Missing ECommerce Applet frontend!");
346 status = RESULT_UNKNOWN;
347 return;
348 }
349 240
350 const auto user_id_data = args.find(WebArgTLVType::UserID); 241 ExtractSharedFonts(system);
351 242
352 user_id = std::nullopt; 243 switch (web_arg_header.shim_kind) {
353 if (user_id_data != args.end()) { 244 case ShimKind::Shop:
354 user_id = u128{}; 245 InitializeShop();
355 std::memcpy(user_id->data(), user_id_data->second.data(), sizeof(u128)); 246 break;
247 case ShimKind::Login:
248 InitializeLogin();
249 break;
250 case ShimKind::Offline:
251 InitializeOffline();
252 break;
253 case ShimKind::Share:
254 InitializeShare();
255 break;
256 case ShimKind::Web:
257 InitializeWeb();
258 break;
259 case ShimKind::Wifi:
260 InitializeWifi();
261 break;
262 case ShimKind::Lobby:
263 InitializeLobby();
264 break;
265 default:
266 UNREACHABLE_MSG("Invalid ShimKind={}", web_arg_header.shim_kind);
267 break;
356 } 268 }
269}
357 270
358 const auto url = args.find(WebArgTLVType::ShopArgumentsURL); 271bool WebBrowser::TransactionComplete() const {
272 return complete;
273}
359 274
360 if (url == args.end()) { 275ResultCode WebBrowser::GetStatus() const {
361 LOG_ERROR(Service_AM, "Missing EShop Arguments URL for initialization!"); 276 return status;
362 status = RESULT_UNKNOWN; 277}
363 return;
364 }
365 278
366 std::vector<std::string> split_query; 279void WebBrowser::ExecuteInteractive() {
367 Common::SplitString(Common::StringFromFixedZeroTerminatedBuffer( 280 UNIMPLEMENTED_MSG("WebSession is not implemented");
368 reinterpret_cast<const char*>(url->second.data()), url->second.size()), 281}
369 '?', split_query);
370
371 // 2 -> Main URL '?' Query Parameters
372 // Less is missing info, More is malformed
373 if (split_query.size() != 2) {
374 LOG_ERROR(Service_AM, "EShop Arguments has more than one question mark, malformed");
375 status = RESULT_UNKNOWN;
376 return;
377 }
378 282
379 std::vector<std::string> queries; 283void WebBrowser::Execute() {
380 Common::SplitString(split_query[1], '&', queries); 284 switch (web_arg_header.shim_kind) {
285 case ShimKind::Shop:
286 ExecuteShop();
287 break;
288 case ShimKind::Login:
289 ExecuteLogin();
290 break;
291 case ShimKind::Offline:
292 ExecuteOffline();
293 break;
294 case ShimKind::Share:
295 ExecuteShare();
296 break;
297 case ShimKind::Web:
298 ExecuteWeb();
299 break;
300 case ShimKind::Wifi:
301 ExecuteWifi();
302 break;
303 case ShimKind::Lobby:
304 ExecuteLobby();
305 break;
306 default:
307 UNREACHABLE_MSG("Invalid ShimKind={}", web_arg_header.shim_kind);
308 WebBrowserExit(WebExitReason::EndButtonPressed);
309 break;
310 }
311}
381 312
382 const auto split_single_query = 313void WebBrowser::ExtractOfflineRomFS() {
383 [](const std::string& in) -> std::pair<std::string, std::string> { 314 LOG_DEBUG(Service_AM, "Extracting RomFS to {}", offline_cache_dir);
384 const auto index = in.find('=');
385 if (index == std::string::npos || index == in.size() - 1) {
386 return {in, ""};
387 }
388 315
389 return {in.substr(0, index), in.substr(index + 1)}; 316 const auto extracted_romfs_dir =
390 }; 317 FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard);
391 318
392 std::transform(queries.begin(), queries.end(), 319 const auto temp_dir =
393 std::inserter(shop_query, std::next(shop_query.begin())), split_single_query); 320 system.GetFilesystem()->CreateDirectory(offline_cache_dir, FileSys::Mode::ReadWrite);
394 321
395 const auto scene = shop_query.find("scene"); 322 FileSys::VfsRawCopyD(extracted_romfs_dir, temp_dir);
323}
396 324
397 if (scene == shop_query.end()) { 325void WebBrowser::WebBrowserExit(WebExitReason exit_reason, std::string last_url) {
398 LOG_ERROR(Service_AM, "No scene parameter was passed via shop query!"); 326 if ((web_arg_header.shim_kind == ShimKind::Share &&
399 status = RESULT_UNKNOWN; 327 web_applet_version >= WebAppletVersion::Version196608) ||
400 return; 328 (web_arg_header.shim_kind == ShimKind::Web &&
329 web_applet_version >= WebAppletVersion::Version524288)) {
330 // TODO: Push Output TLVs instead of a WebCommonReturnValue
401 } 331 }
402 332
403 const std::map<std::string, ShopWebTarget, std::less<>> target_map{ 333 WebCommonReturnValue web_common_return_value;
404 {"product_detail", ShopWebTarget::ApplicationInfo},
405 {"aocs", ShopWebTarget::AddOnContentList},
406 {"subscriptions", ShopWebTarget::SubscriptionList},
407 {"consumption", ShopWebTarget::ConsumableItemList},
408 {"settings", ShopWebTarget::Settings},
409 {"top", ShopWebTarget::Home},
410 };
411 334
412 const auto target = target_map.find(scene->second); 335 web_common_return_value.exit_reason = exit_reason;
413 if (target == target_map.end()) { 336 std::memcpy(&web_common_return_value.last_url, last_url.data(), last_url.size());
414 LOG_ERROR(Service_AM, "Scene for shop query is invalid! (scene={})", scene->second); 337 web_common_return_value.last_url_size = last_url.size();
415 status = RESULT_UNKNOWN;
416 return;
417 }
418 338
419 shop_web_target = target->second; 339 LOG_DEBUG(Service_AM, "WebCommonReturnValue: exit_reason={}, last_url={}, last_url_size={}",
340 exit_reason, last_url, last_url.size());
420 341
421 const auto title_id_data = shop_query.find("dst_app_id"); 342 complete = true;
422 if (title_id_data != shop_query.end()) { 343 std::vector<u8> out_data(sizeof(WebCommonReturnValue));
423 title_id = std::stoull(title_id_data->second, nullptr, 0x10); 344 std::memcpy(out_data.data(), &web_common_return_value, out_data.size());
424 } 345 broker.PushNormalDataFromApplet(std::make_shared<IStorage>(system, std::move(out_data)));
346 broker.SignalStateChanged();
347}
425 348
426 const auto mode_data = shop_query.find("mode"); 349bool WebBrowser::InputTLVExistsInMap(WebArgInputTLVType input_tlv_type) const {
427 if (mode_data != shop_query.end()) { 350 return web_arg_input_tlv_map.find(input_tlv_type) != web_arg_input_tlv_map.end();
428 shop_full_display = mode_data->second == "full";
429 }
430} 351}
431 352
432void WebBrowser::InitializeOffline() { 353std::optional<std::vector<u8>> WebBrowser::GetInputTLVData(WebArgInputTLVType input_tlv_type) {
433 if (args.find(WebArgTLVType::DocumentPath) == args.end() || 354 const auto map_it = web_arg_input_tlv_map.find(input_tlv_type);
434 args.find(WebArgTLVType::DocumentKind) == args.end() || 355
435 args.find(WebArgTLVType::ApplicationID) == args.end()) { 356 if (map_it == web_arg_input_tlv_map.end()) {
436 status = RESULT_UNKNOWN; 357 return std::nullopt;
437 LOG_ERROR(Service_AM, "Missing necessary parameters for initialization!");
438 } 358 }
439 359
440 const auto url_data = args[WebArgTLVType::DocumentPath]; 360 return map_it->second;
441 filename = Common::StringFromFixedZeroTerminatedBuffer( 361}
442 reinterpret_cast<const char*>(url_data.data()), url_data.size());
443 362
444 OfflineWebSource source; 363void WebBrowser::InitializeShop() {}
445 ASSERT(args[WebArgTLVType::DocumentKind].size() >= 4);
446 std::memcpy(&source, args[WebArgTLVType::DocumentKind].data(), sizeof(OfflineWebSource));
447 364
448 constexpr std::array<const char*, 3> WEB_SOURCE_NAMES{ 365void WebBrowser::InitializeLogin() {}
449 "manual", 366
450 "legal", 367void WebBrowser::InitializeOffline() {
451 "system", 368 const auto document_path =
452 }; 369 ParseStringValue(GetInputTLVData(WebArgInputTLVType::DocumentPath).value());
370
371 const auto document_kind =
372 ParseRawValue<DocumentKind>(GetInputTLVData(WebArgInputTLVType::DocumentKind).value());
373
374 std::string additional_paths;
453 375
454 temporary_dir = 376 switch (document_kind) {
455 Common::FS::SanitizePath(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + 377 case DocumentKind::OfflineHtmlPage:
456 "web_applet_" + WEB_SOURCE_NAMES[static_cast<u32>(source) - 1], 378 default:
457 Common::FS::DirectorySeparator::PlatformDefault); 379 title_id = system.CurrentProcess()->GetTitleID();
458 Common::FS::DeleteDirRecursively(temporary_dir); 380 nca_type = FileSys::ContentRecordType::HtmlDocument;
459 381 additional_paths = "html-document";
460 u64 title_id = 0; // 0 corresponds to current process
461 ASSERT(args[WebArgTLVType::ApplicationID].size() >= 0x8);
462 std::memcpy(&title_id, args[WebArgTLVType::ApplicationID].data(), sizeof(u64));
463 FileSys::ContentRecordType type = FileSys::ContentRecordType::Data;
464
465 switch (source) {
466 case OfflineWebSource::OfflineHtmlPage:
467 // While there is an AppID TLV field, in official SW this is always ignored.
468 title_id = 0;
469 type = FileSys::ContentRecordType::HtmlDocument;
470 break; 382 break;
471 case OfflineWebSource::ApplicationLegalInformation: 383 case DocumentKind::ApplicationLegalInformation:
472 type = FileSys::ContentRecordType::LegalInformation; 384 title_id = ParseRawValue<u64>(GetInputTLVData(WebArgInputTLVType::ApplicationID).value());
385 nca_type = FileSys::ContentRecordType::LegalInformation;
473 break; 386 break;
474 case OfflineWebSource::SystemDataPage: 387 case DocumentKind::SystemDataPage:
475 type = FileSys::ContentRecordType::Data; 388 title_id = ParseRawValue<u64>(GetInputTLVData(WebArgInputTLVType::SystemDataID).value());
389 nca_type = FileSys::ContentRecordType::Data;
476 break; 390 break;
477 } 391 }
478 392
479 if (title_id == 0) { 393 static constexpr std::array<const char*, 3> RESOURCE_TYPES{
480 title_id = system.CurrentProcess()->GetTitleID(); 394 "manual",
481 } 395 "legal_information",
396 "system_data",
397 };
482 398
483 offline_romfs = GetApplicationRomFS(system, title_id, type); 399 offline_cache_dir = Common::FS::SanitizePath(
484 if (offline_romfs == nullptr) { 400 fmt::format("{}/offline_web_applet_{}/{:016X}",
485 status = RESULT_UNKNOWN; 401 Common::FS::GetUserPath(Common::FS::UserPath::CacheDir),
486 LOG_ERROR(Service_AM, "Failed to find offline data for request!"); 402 RESOURCE_TYPES[static_cast<u32>(document_kind) - 1], title_id),
487 } 403 Common::FS::DirectorySeparator::PlatformDefault);
488 404
489 std::string path_additional_directory; 405 offline_document = Common::FS::SanitizePath(
490 if (source == OfflineWebSource::OfflineHtmlPage) { 406 fmt::format("{}/{}/{}", offline_cache_dir, additional_paths, document_path),
491 path_additional_directory = std::string(DIR_SEP).append("html-document"); 407 Common::FS::DirectorySeparator::PlatformDefault);
492 } 408}
409
410void WebBrowser::InitializeShare() {}
493 411
494 filename = 412void WebBrowser::InitializeWeb() {
495 Common::FS::SanitizePath(temporary_dir + path_additional_directory + DIR_SEP + filename, 413 external_url = ParseStringValue(GetInputTLVData(WebArgInputTLVType::InitialURL).value());
496 Common::FS::DirectorySeparator::PlatformDefault);
497} 414}
498 415
416void WebBrowser::InitializeWifi() {}
417
418void WebBrowser::InitializeLobby() {}
419
499void WebBrowser::ExecuteShop() { 420void WebBrowser::ExecuteShop() {
500 const auto callback = [this]() { Finalize(); }; 421 LOG_WARNING(Service_AM, "(STUBBED) called, Shop Applet is not implemented");
422 WebBrowserExit(WebExitReason::EndButtonPressed);
423}
501 424
502 const auto check_optional_parameter = [this](const auto& p) { 425void WebBrowser::ExecuteLogin() {
503 if (!p.has_value()) { 426 LOG_WARNING(Service_AM, "(STUBBED) called, Login Applet is not implemented");
504 LOG_ERROR(Service_AM, "Missing one or more necessary parameters for execution!"); 427 WebBrowserExit(WebExitReason::EndButtonPressed);
505 status = RESULT_UNKNOWN; 428}
506 return false;
507 }
508 429
509 return true; 430void WebBrowser::ExecuteOffline() {
510 }; 431 const auto main_url = Common::FS::SanitizePath(GetMainURL(offline_document),
432 Common::FS::DirectorySeparator::PlatformDefault);
511 433
512 switch (shop_web_target) { 434 if (!Common::FS::Exists(main_url)) {
513 case ShopWebTarget::ApplicationInfo: 435 offline_romfs = GetOfflineRomFS(system, title_id, nca_type);
514 if (!check_optional_parameter(title_id)) 436
515 return; 437 if (offline_romfs == nullptr) {
516 frontend_e_commerce->ShowApplicationInformation(callback, *title_id, user_id, 438 LOG_ERROR(Service_AM,
517 shop_full_display, shop_extra_parameter); 439 "RomFS with title_id={:016X} and nca_type={} cannot be extracted!", title_id,
518 break; 440 nca_type);
519 case ShopWebTarget::AddOnContentList: 441 WebBrowserExit(WebExitReason::WindowClosed);
520 if (!check_optional_parameter(title_id))
521 return;
522 frontend_e_commerce->ShowAddOnContentList(callback, *title_id, user_id, shop_full_display);
523 break;
524 case ShopWebTarget::ConsumableItemList:
525 if (!check_optional_parameter(title_id))
526 return;
527 frontend_e_commerce->ShowConsumableItemList(callback, *title_id, user_id);
528 break;
529 case ShopWebTarget::Home:
530 if (!check_optional_parameter(user_id))
531 return;
532 if (!check_optional_parameter(shop_full_display))
533 return;
534 frontend_e_commerce->ShowShopHome(callback, *user_id, *shop_full_display);
535 break;
536 case ShopWebTarget::Settings:
537 if (!check_optional_parameter(user_id))
538 return;
539 if (!check_optional_parameter(shop_full_display))
540 return;
541 frontend_e_commerce->ShowSettings(callback, *user_id, *shop_full_display);
542 break;
543 case ShopWebTarget::SubscriptionList:
544 if (!check_optional_parameter(title_id))
545 return; 442 return;
546 frontend_e_commerce->ShowSubscriptionList(callback, *title_id, user_id); 443 }
547 break;
548 default:
549 UNREACHABLE();
550 } 444 }
445
446 LOG_INFO(Service_AM, "Opening offline document at {}", offline_document);
447
448 frontend.OpenLocalWebPage(
449 offline_document, [this] { ExtractOfflineRomFS(); },
450 [this](WebExitReason exit_reason, std::string last_url) {
451 WebBrowserExit(exit_reason, last_url);
452 });
551} 453}
552 454
553void WebBrowser::ExecuteOffline() { 455void WebBrowser::ExecuteShare() {
554 frontend.OpenPageLocal( 456 LOG_WARNING(Service_AM, "(STUBBED) called, Share Applet is not implemented");
555 filename, [this] { UnpackRomFS(); }, [this] { Finalize(); }); 457 WebBrowserExit(WebExitReason::EndButtonPressed);
458}
459
460void WebBrowser::ExecuteWeb() {
461 LOG_INFO(Service_AM, "Opening external URL at {}", external_url);
462
463 frontend.OpenExternalWebPage(external_url,
464 [this](WebExitReason exit_reason, std::string last_url) {
465 WebBrowserExit(exit_reason, last_url);
466 });
556} 467}
557 468
469void WebBrowser::ExecuteWifi() {
470 LOG_WARNING(Service_AM, "(STUBBED) called, Wifi Applet is not implemented");
471 WebBrowserExit(WebExitReason::EndButtonPressed);
472}
473
474void WebBrowser::ExecuteLobby() {
475 LOG_WARNING(Service_AM, "(STUBBED) called, Lobby Applet is not implemented");
476 WebBrowserExit(WebExitReason::EndButtonPressed);
477}
558} // namespace Service::AM::Applets 478} // 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..04c274754 100644
--- a/src/core/hle/service/am/applets/web_browser.h
+++ b/src/core/hle/service/am/applets/web_browser.h
@@ -1,28 +1,31 @@
1// Copyright 2018 yuzu emulator team 1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#pragma once 5#pragma once
6 6
7#include <map> 7#include <optional>
8
9#include "common/common_funcs.h"
10#include "common/common_types.h"
8#include "core/file_sys/vfs_types.h" 11#include "core/file_sys/vfs_types.h"
9#include "core/hle/service/am/am.h" 12#include "core/hle/result.h"
10#include "core/hle/service/am/applets/applets.h" 13#include "core/hle/service/am/applets/applets.h"
14#include "core/hle/service/am/applets/web_types.h"
11 15
12namespace Core { 16namespace Core {
13class System; 17class System;
14} 18}
15 19
16namespace Service::AM::Applets { 20namespace FileSys {
21enum class ContentRecordType : u8;
22}
17 23
18enum class ShimKind : u32; 24namespace Service::AM::Applets {
19enum class ShopWebTarget;
20enum class WebArgTLVType : u16;
21 25
22class WebBrowser final : public Applet { 26class WebBrowser final : public Applet {
23public: 27public:
24 WebBrowser(Core::System& system_, Core::Frontend::WebBrowserApplet& frontend_, 28 WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_);
25 Core::Frontend::ECommerceApplet* frontend_e_commerce_ = nullptr);
26 29
27 ~WebBrowser() override; 30 ~WebBrowser() override;
28 31
@@ -33,49 +36,50 @@ public:
33 void ExecuteInteractive() override; 36 void ExecuteInteractive() override;
34 void Execute() override; 37 void Execute() override;
35 38
36 // Callback to be fired when the frontend needs the manual RomFS unpacked to temporary 39 void ExtractOfflineRomFS();
37 // directory. This is a blocking call and may take a while as some manuals can be up to 100MB in
38 // size. Attempting to access files at filename before invocation is likely to not work.
39 void UnpackRomFS();
40 40
41 // Callback to be fired when the frontend is finished browsing. This will delete the temporary 41 void WebBrowserExit(WebExitReason exit_reason, std::string last_url = "");
42 // manual RomFS extracted files, so ensure this is only called at actual finalization.
43 void Finalize();
44 42
45private: 43private:
46 void InitializeInternal(); 44 bool InputTLVExistsInMap(WebArgInputTLVType input_tlv_type) const;
47 void ExecuteInternal();
48 45
49 // Specific initializers for the types of web applets 46 std::optional<std::vector<u8>> GetInputTLVData(WebArgInputTLVType input_tlv_type);
47
48 // Initializers for the various types of browser applets
50 void InitializeShop(); 49 void InitializeShop();
50 void InitializeLogin();
51 void InitializeOffline(); 51 void InitializeOffline();
52 void InitializeShare();
53 void InitializeWeb();
54 void InitializeWifi();
55 void InitializeLobby();
52 56
53 // Specific executors for the types of web applets 57 // Executors for the various types of browser applets
54 void ExecuteShop(); 58 void ExecuteShop();
59 void ExecuteLogin();
55 void ExecuteOffline(); 60 void ExecuteOffline();
61 void ExecuteShare();
62 void ExecuteWeb();
63 void ExecuteWifi();
64 void ExecuteLobby();
56 65
57 Core::Frontend::WebBrowserApplet& frontend; 66 const Core::Frontend::WebBrowserApplet& frontend;
58
59 // Extra frontends for specialized functions
60 Core::Frontend::ECommerceApplet* frontend_e_commerce;
61 67
62 bool complete = false; 68 bool complete{false};
63 bool unpacked = false; 69 ResultCode status{RESULT_SUCCESS};
64 ResultCode status = RESULT_SUCCESS;
65 70
66 ShimKind kind; 71 WebAppletVersion web_applet_version;
67 std::map<WebArgTLVType, std::vector<u8>> args; 72 WebExitReason web_exit_reason;
73 WebArgHeader web_arg_header;
74 WebArgInputTLVMap web_arg_input_tlv_map;
68 75
76 u64 title_id;
77 FileSys::ContentRecordType nca_type;
78 std::string offline_cache_dir;
79 std::string offline_document;
69 FileSys::VirtualFile offline_romfs; 80 FileSys::VirtualFile offline_romfs;
70 std::string temporary_dir; 81
71 std::string filename; 82 std::string external_url;
72
73 ShopWebTarget shop_web_target;
74 std::map<std::string, std::string, std::less<>> shop_query;
75 std::optional<u64> title_id = 0;
76 std::optional<u128> user_id;
77 std::optional<bool> shop_full_display;
78 std::string shop_extra_parameter;
79 83
80 Core::System& system; 84 Core::System& system;
81}; 85};
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 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <unordered_map>
9#include <vector>
10
11#include "common/common_funcs.h"
12#include "common/common_types.h"
13#include "common/swap.h"
14
15namespace Service::AM::Applets {
16
17enum class WebAppletVersion : u32_le {
18 Version0 = 0x0, // Only used by WifiWebAuthApplet
19 Version131072 = 0x20000, // 1.0.0 - 2.3.0
20 Version196608 = 0x30000, // 3.0.0 - 4.1.0
21 Version327680 = 0x50000, // 5.0.0 - 5.1.0
22 Version393216 = 0x60000, // 6.0.0 - 7.0.1
23 Version524288 = 0x80000, // 8.0.0+
24};
25
26enum class ShimKind : u32 {
27 Shop = 1,
28 Login = 2,
29 Offline = 3,
30 Share = 4,
31 Web = 5,
32 Wifi = 6,
33 Lobby = 7,
34};
35
36enum class WebExitReason : u32 {
37 EndButtonPressed = 0,
38 BackButtonPressed = 1,
39 ExitRequested = 2,
40 CallbackURL = 3,
41 WindowClosed = 4,
42 ErrorDialog = 7,
43};
44
45enum class WebArgInputTLVType : u16 {
46 InitialURL = 0x1,
47 CallbackURL = 0x3,
48 CallbackableURL = 0x4,
49 ApplicationID = 0x5,
50 DocumentPath = 0x6,
51 DocumentKind = 0x7,
52 SystemDataID = 0x8,
53 ShareStartPage = 0x9,
54 Whitelist = 0xA,
55 News = 0xB,
56 UserID = 0xE,
57 AlbumEntry0 = 0xF,
58 ScreenShotEnabled = 0x10,
59 EcClientCertEnabled = 0x11,
60 PlayReportEnabled = 0x13,
61 BootDisplayKind = 0x17,
62 BackgroundKind = 0x18,
63 FooterEnabled = 0x19,
64 PointerEnabled = 0x1A,
65 LeftStickMode = 0x1B,
66 KeyRepeatFrame1 = 0x1C,
67 KeyRepeatFrame2 = 0x1D,
68 BootAsMediaPlayerInverted = 0x1E,
69 DisplayURLKind = 0x1F,
70 BootAsMediaPlayer = 0x21,
71 ShopJumpEnabled = 0x22,
72 MediaAutoPlayEnabled = 0x23,
73 LobbyParameter = 0x24,
74 ApplicationAlbumEntry = 0x26,
75 JsExtensionEnabled = 0x27,
76 AdditionalCommentText = 0x28,
77 TouchEnabledOnContents = 0x29,
78 UserAgentAdditionalString = 0x2A,
79 AdditionalMediaData0 = 0x2B,
80 MediaPlayerAutoCloseEnabled = 0x2C,
81 PageCacheEnabled = 0x2D,
82 WebAudioEnabled = 0x2E,
83 YouTubeVideoWhitelist = 0x31,
84 FooterFixedKind = 0x32,
85 PageFadeEnabled = 0x33,
86 MediaCreatorApplicationRatingAge = 0x34,
87 BootLoadingIconEnabled = 0x35,
88 PageScrollIndicatorEnabled = 0x36,
89 MediaPlayerSpeedControlEnabled = 0x37,
90 AlbumEntry1 = 0x38,
91 AlbumEntry2 = 0x39,
92 AlbumEntry3 = 0x3A,
93 AdditionalMediaData1 = 0x3B,
94 AdditionalMediaData2 = 0x3C,
95 AdditionalMediaData3 = 0x3D,
96 BootFooterButton = 0x3E,
97 OverrideWebAudioVolume = 0x3F,
98 OverrideMediaAudioVolume = 0x40,
99 BootMode = 0x41,
100 WebSessionEnabled = 0x42,
101 MediaPlayerOfflineEnabled = 0x43,
102};
103
104enum class WebArgOutputTLVType : u16 {
105 ShareExitReason = 0x1,
106 LastURL = 0x2,
107 LastURLSize = 0x3,
108 SharePostResult = 0x4,
109 PostServiceName = 0x5,
110 PostServiceNameSize = 0x6,
111 PostID = 0x7,
112 PostIDSize = 0x8,
113 MediaPlayerAutoClosedByCompletion = 0x9,
114};
115
116enum class DocumentKind : u32 {
117 OfflineHtmlPage = 1,
118 ApplicationLegalInformation = 2,
119 SystemDataPage = 3,
120};
121
122enum class ShareStartPage : u32 {
123 Default,
124 Settings,
125};
126
127enum class BootDisplayKind : u32 {
128 Default,
129 White,
130 Black,
131};
132
133enum class BackgroundKind : u32 {
134 Default,
135};
136
137enum class LeftStickMode : u32 {
138 Pointer,
139 Cursor,
140};
141
142enum class WebSessionBootMode : u32 {
143 AllForeground,
144 AllForegroundInitiallyHidden,
145};
146
147struct WebArgHeader {
148 u16 total_tlv_entries{};
149 INSERT_PADDING_BYTES(2);
150 ShimKind shim_kind{};
151};
152static_assert(sizeof(WebArgHeader) == 0x8, "WebArgHeader has incorrect size.");
153
154struct WebArgInputTLV {
155 WebArgInputTLVType input_tlv_type{};
156 u16 arg_data_size{};
157 INSERT_PADDING_WORDS(1);
158};
159static_assert(sizeof(WebArgInputTLV) == 0x8, "WebArgInputTLV has incorrect size.");
160
161struct WebArgOutputTLV {
162 WebArgOutputTLVType output_tlv_type{};
163 u16 arg_data_size{};
164 INSERT_PADDING_WORDS(1);
165};
166static_assert(sizeof(WebArgOutputTLV) == 0x8, "WebArgOutputTLV has incorrect size.");
167
168struct WebCommonReturnValue {
169 WebExitReason exit_reason{};
170 INSERT_PADDING_WORDS(1);
171 std::array<char, 0x1000> last_url{};
172 u64 last_url_size{};
173};
174static_assert(sizeof(WebCommonReturnValue) == 0x1010, "WebCommonReturnValue has incorrect size.");
175
176using WebArgInputTLVMap = std::unordered_map<WebArgInputTLVType, std::vector<u8>>;
177
178} // namespace Service::AM::Applets
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() {
1058} 1058}
1059 1059
1060u32 Controller_NPad::GetAndResetPressState() { 1060u32 Controller_NPad::GetAndResetPressState() {
1061 return std::exchange(press_state, 0); 1061 return press_state.exchange(0);
1062} 1062}
1063 1063
1064bool Controller_NPad::IsControllerSupported(NPadControllerType controller) const { 1064bool 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 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <atomic>
8#include "common/bit_field.h" 9#include "common/bit_field.h"
9#include "common/common_types.h" 10#include "common/common_types.h"
10#include "core/frontend/input.h" 11#include "core/frontend/input.h"
@@ -415,7 +416,7 @@ private:
415 bool IsControllerSupported(NPadControllerType controller) const; 416 bool IsControllerSupported(NPadControllerType controller) const;
416 void RequestPadStateUpdate(u32 npad_id); 417 void RequestPadStateUpdate(u32 npad_id);
417 418
418 u32 press_state{}; 419 std::atomic<u32> press_state{};
419 420
420 NpadStyleSet style{}; 421 NpadStyleSet style{};
421 std::array<NPadEntry, 10> shared_memory_entries{}; 422 std::array<NPadEntry, 10> shared_memory_entries{};
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:
673 explicit NS_VM(Core::System& system_) : ServiceFramework{system_, "ns:vm"} { 673 explicit NS_VM(Core::System& system_) : ServiceFramework{system_, "ns:vm"} {
674 // clang-format off 674 // clang-format off
675 static const FunctionInfo functions[] = { 675 static const FunctionInfo functions[] = {
676 {1200, nullptr, "NeedsUpdateVulnerability"}, 676 {1200, &NS_VM::NeedsUpdateVulnerability, "NeedsUpdateVulnerability"},
677 {1201, nullptr, "UpdateSafeSystemVersionForDebug"}, 677 {1201, nullptr, "UpdateSafeSystemVersionForDebug"},
678 {1202, nullptr, "GetSafeSystemVersion"}, 678 {1202, nullptr, "GetSafeSystemVersion"},
679 }; 679 };
@@ -681,6 +681,15 @@ public:
681 681
682 RegisterHandlers(functions); 682 RegisterHandlers(functions);
683 } 683 }
684
685private:
686 void NeedsUpdateVulnerability(Kernel::HLERequestContext& ctx) {
687 LOG_WARNING(Service_NS, "(STUBBED) called");
688
689 IPC::ResponseBuilder rb{ctx, 3};
690 rb.Push(RESULT_SUCCESS);
691 rb.Push(false);
692 }
684}; 693};
685 694
686void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { 695void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
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 @@
27 27
28namespace Service::NS { 28namespace Service::NS {
29 29
30enum class FontArchives : u64 {
31 Extension = 0x0100000000000810,
32 Standard = 0x0100000000000811,
33 Korean = 0x0100000000000812,
34 ChineseTraditional = 0x0100000000000813,
35 ChineseSimple = 0x0100000000000814,
36};
37
38struct FontRegion { 30struct FontRegion {
39 u32 offset; 31 u32 offset;
40 u32 size; 32 u32 size;
41}; 33};
42 34
43constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{
44 std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"),
45 std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"),
46 std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"),
47 std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"),
48 std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"),
49 std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"),
50 std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"),
51};
52
53// The below data is specific to shared font data dumped from Switch on f/w 2.2 35// The below data is specific to shared font data dumped from Switch on f/w 2.2
54// Virtual address and offsets/sizes likely will vary by dump 36// Virtual address and offsets/sizes likely will vary by dump
55[[maybe_unused]] constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; 37[[maybe_unused]] constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL};
@@ -80,6 +62,18 @@ static void DecryptSharedFont(const std::vector<u32>& input, Kernel::PhysicalMem
80 offset += transformed_font.size() * sizeof(u32); 62 offset += transformed_font.size() * sizeof(u32);
81} 63}
82 64
65void DecryptSharedFontToTTF(const std::vector<u32>& input, std::vector<u8>& output) {
66 ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number");
67
68 const u32 KEY = input[0] ^ EXPECTED_RESULT; // Derive key using an inverse xor
69 std::vector<u32> transformed_font(input.size());
70 // TODO(ogniK): Figure out a better way to do this
71 std::transform(input.begin(), input.end(), transformed_font.begin(),
72 [&KEY](u32 font_data) { return Common::swap32(font_data ^ KEY); });
73 transformed_font[1] = Common::swap32(transformed_font[1]) ^ KEY; // "re-encrypt" the size
74 std::memcpy(output.data(), transformed_font.data() + 2, transformed_font.size() * sizeof(u32));
75}
76
83void EncryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, 77void EncryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output,
84 std::size_t& offset) { 78 std::size_t& offset) {
85 ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE, 79 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;
16 16
17namespace NS { 17namespace NS {
18 18
19enum class FontArchives : u64 {
20 Extension = 0x0100000000000810,
21 Standard = 0x0100000000000811,
22 Korean = 0x0100000000000812,
23 ChineseTraditional = 0x0100000000000813,
24 ChineseSimple = 0x0100000000000814,
25};
26
27constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{
28 std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"),
29 std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"),
30 std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"),
31 std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"),
32 std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"),
33 std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"),
34 std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"),
35};
36
37void DecryptSharedFontToTTF(const std::vector<u32>& input, std::vector<u8>& output);
19void EncryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, std::size_t& offset); 38void EncryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, std::size_t& offset);
20 39
21class PL_U final : public ServiceFramework<PL_U> { 40class PL_U final : public ServiceFramework<PL_U> {
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
141 util/limitable_input_dialog.h 141 util/limitable_input_dialog.h
142 util/sequence_dialog/sequence_dialog.cpp 142 util/sequence_dialog/sequence_dialog.cpp
143 util/sequence_dialog/sequence_dialog.h 143 util/sequence_dialog/sequence_dialog.h
144 util/url_request_interceptor.cpp
145 util/url_request_interceptor.h
144 util/util.cpp 146 util/util.cpp
145 util/util.h 147 util/util.h
146 compatdb.cpp 148 compatdb.cpp
diff --git a/src/yuzu/applets/web_browser.cpp b/src/yuzu/applets/web_browser.cpp
index 9fd8d6326..e482ba029 100644
--- a/src/yuzu/applets/web_browser.cpp
+++ b/src/yuzu/applets/web_browser.cpp
@@ -1,115 +1,414 @@
1// Copyright 2018 yuzu Emulator Project 1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <mutex> 5#ifdef YUZU_USE_QT_WEB_ENGINE
6
7#include <QKeyEvent> 6#include <QKeyEvent>
8 7
9#include "core/hle/lock.h" 8#include <QWebEngineProfile>
9#include <QWebEngineScript>
10#include <QWebEngineScriptCollection>
11#include <QWebEngineSettings>
12#include <QWebEngineUrlScheme>
13#endif
14
15#include "common/file_util.h"
16#include "core/core.h"
17#include "core/frontend/input_interpreter.h"
18#include "input_common/keyboard.h"
19#include "input_common/main.h"
10#include "yuzu/applets/web_browser.h" 20#include "yuzu/applets/web_browser.h"
21#include "yuzu/applets/web_browser_scripts.h"
11#include "yuzu/main.h" 22#include "yuzu/main.h"
23#include "yuzu/util/url_request_interceptor.h"
12 24
13#ifdef YUZU_USE_QT_WEB_ENGINE 25#ifdef YUZU_USE_QT_WEB_ENGINE
14 26
15constexpr char NX_SHIM_INJECT_SCRIPT[] = R"( 27namespace {
16 window.nx = {};
17 window.nx.playReport = {};
18 window.nx.playReport.setCounterSetIdentifier = function () {
19 console.log("nx.playReport.setCounterSetIdentifier called - unimplemented");
20 };
21 28
22 window.nx.playReport.incrementCounter = function () { 29constexpr int HIDButtonToKey(HIDButton button) {
23 console.log("nx.playReport.incrementCounter called - unimplemented"); 30 switch (button) {
24 }; 31 case HIDButton::DLeft:
32 case HIDButton::LStickLeft:
33 return Qt::Key_Left;
34 case HIDButton::DUp:
35 case HIDButton::LStickUp:
36 return Qt::Key_Up;
37 case HIDButton::DRight:
38 case HIDButton::LStickRight:
39 return Qt::Key_Right;
40 case HIDButton::DDown:
41 case HIDButton::LStickDown:
42 return Qt::Key_Down;
43 default:
44 return 0;
45 }
46}
47
48} // Anonymous namespace
49
50QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system,
51 InputCommon::InputSubsystem* input_subsystem_)
52 : QWebEngineView(parent), input_subsystem{input_subsystem_},
53 url_interceptor(std::make_unique<UrlRequestInterceptor>()),
54 input_interpreter(std::make_unique<InputInterpreter>(system)),
55 default_profile{QWebEngineProfile::defaultProfile()},
56 global_settings{QWebEngineSettings::globalSettings()} {
57 QWebEngineScript gamepad;
58 QWebEngineScript window_nx;
59
60 gamepad.setName(QStringLiteral("gamepad_script.js"));
61 window_nx.setName(QStringLiteral("window_nx_script.js"));
62
63 gamepad.setSourceCode(QString::fromStdString(GAMEPAD_SCRIPT));
64 window_nx.setSourceCode(QString::fromStdString(WINDOW_NX_SCRIPT));
65
66 gamepad.setInjectionPoint(QWebEngineScript::DocumentCreation);
67 window_nx.setInjectionPoint(QWebEngineScript::DocumentCreation);
68
69 gamepad.setWorldId(QWebEngineScript::MainWorld);
70 window_nx.setWorldId(QWebEngineScript::MainWorld);
71
72 gamepad.setRunsOnSubFrames(true);
73 window_nx.setRunsOnSubFrames(true);
74
75 default_profile->scripts()->insert(gamepad);
76 default_profile->scripts()->insert(window_nx);
77
78 default_profile->setRequestInterceptor(url_interceptor.get());
79
80 global_settings->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
81 global_settings->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
82 global_settings->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, true);
83 global_settings->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, true);
84 global_settings->setAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript, true);
85 global_settings->setAttribute(QWebEngineSettings::ShowScrollBars, false);
86
87 global_settings->setFontFamily(QWebEngineSettings::StandardFont, QStringLiteral("Roboto"));
88
89 connect(
90 page(), &QWebEnginePage::windowCloseRequested, page(),
91 [this] {
92 if (page()->url() == url_interceptor->GetRequestedURL()) {
93 SetFinished(true);
94 SetExitReason(Service::AM::Applets::WebExitReason::WindowClosed);
95 }
96 },
97 Qt::QueuedConnection);
98}
99
100QtNXWebEngineView::~QtNXWebEngineView() {
101 SetFinished(true);
102 StopInputThread();
103}
104
105void QtNXWebEngineView::LoadLocalWebPage(std::string_view main_url,
106 std::string_view additional_args) {
107 is_local = true;
108
109 LoadExtractedFonts();
110 SetUserAgent(UserAgent::WebApplet);
111 SetFinished(false);
112 SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed);
113 SetLastURL("http://localhost/");
114 StartInputThread();
115
116 load(QUrl(QUrl::fromLocalFile(QString::fromStdString(std::string(main_url))).toString() +
117 QString::fromStdString(std::string(additional_args))));
118}
119
120void QtNXWebEngineView::LoadExternalWebPage(std::string_view main_url,
121 std::string_view additional_args) {
122 is_local = false;
123
124 SetUserAgent(UserAgent::WebApplet);
125 SetFinished(false);
126 SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed);
127 SetLastURL("http://localhost/");
128 StartInputThread();
129
130 load(QUrl(QString::fromStdString(std::string(main_url)) +
131 QString::fromStdString(std::string(additional_args))));
132}
133
134void QtNXWebEngineView::SetUserAgent(UserAgent user_agent) {
135 const QString user_agent_str = [user_agent] {
136 switch (user_agent) {
137 case UserAgent::WebApplet:
138 default:
139 return QStringLiteral("WebApplet");
140 case UserAgent::ShopN:
141 return QStringLiteral("ShopN");
142 case UserAgent::LoginApplet:
143 return QStringLiteral("LoginApplet");
144 case UserAgent::ShareApplet:
145 return QStringLiteral("ShareApplet");
146 case UserAgent::LobbyApplet:
147 return QStringLiteral("LobbyApplet");
148 case UserAgent::WifiWebAuthApplet:
149 return QStringLiteral("WifiWebAuthApplet");
150 }
151 }();
152
153 QWebEngineProfile::defaultProfile()->setHttpUserAgent(
154 QStringLiteral("Mozilla/5.0 (Nintendo Switch; %1) AppleWebKit/606.4 "
155 "(KHTML, like Gecko) NF/6.0.1.15.4 NintendoBrowser/5.1.0.20389")
156 .arg(user_agent_str));
157}
158
159bool QtNXWebEngineView::IsFinished() const {
160 return finished;
161}
162
163void QtNXWebEngineView::SetFinished(bool finished_) {
164 finished = finished_;
165}
166
167Service::AM::Applets::WebExitReason QtNXWebEngineView::GetExitReason() const {
168 return exit_reason;
169}
170
171void QtNXWebEngineView::SetExitReason(Service::AM::Applets::WebExitReason exit_reason_) {
172 exit_reason = exit_reason_;
173}
174
175const std::string& QtNXWebEngineView::GetLastURL() const {
176 return last_url;
177}
178
179void QtNXWebEngineView::SetLastURL(std::string last_url_) {
180 last_url = std::move(last_url_);
181}
182
183QString QtNXWebEngineView::GetCurrentURL() const {
184 return url_interceptor->GetRequestedURL().toString();
185}
186
187void QtNXWebEngineView::hide() {
188 SetFinished(true);
189 StopInputThread();
25 190
26 window.nx.footer = {}; 191 QWidget::hide();
27 window.nx.footer.unsetAssign = function () { 192}
28 console.log("nx.footer.unsetAssign called - unimplemented"); 193
194void QtNXWebEngineView::keyPressEvent(QKeyEvent* event) {
195 if (is_local) {
196 input_subsystem->GetKeyboard()->PressKey(event->key());
197 }
198}
199
200void QtNXWebEngineView::keyReleaseEvent(QKeyEvent* event) {
201 if (is_local) {
202 input_subsystem->GetKeyboard()->ReleaseKey(event->key());
203 }
204}
205
206template <HIDButton... T>
207void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() {
208 const auto f = [this](HIDButton button) {
209 if (input_interpreter->IsButtonPressedOnce(button)) {
210 page()->runJavaScript(
211 QStringLiteral("yuzu_key_callbacks[%1] == null;").arg(static_cast<u8>(button)),
212 [&](const QVariant& variant) {
213 if (variant.toBool()) {
214 switch (button) {
215 case HIDButton::A:
216 SendMultipleKeyPressEvents<Qt::Key_A, Qt::Key_Space, Qt::Key_Return>();
217 break;
218 case HIDButton::B:
219 SendKeyPressEvent(Qt::Key_B);
220 break;
221 case HIDButton::X:
222 SendKeyPressEvent(Qt::Key_X);
223 break;
224 case HIDButton::Y:
225 SendKeyPressEvent(Qt::Key_Y);
226 break;
227 default:
228 break;
229 }
230 }
231 });
232
233 page()->runJavaScript(
234 QStringLiteral("if (yuzu_key_callbacks[%1] != null) { yuzu_key_callbacks[%1](); }")
235 .arg(static_cast<u8>(button)));
236 }
29 }; 237 };
30 238
31 var yuzu_key_callbacks = []; 239 (f(T), ...);
32 window.nx.footer.setAssign = function(key, discard1, func, discard2) { 240}
33 switch (key) { 241
34 case 'A': 242template <HIDButton... T>
35 yuzu_key_callbacks[0] = func; 243void QtNXWebEngineView::HandleWindowKeyButtonPressedOnce() {
36 break; 244 const auto f = [this](HIDButton button) {
37 case 'B': 245 if (input_interpreter->IsButtonPressedOnce(button)) {
38 yuzu_key_callbacks[1] = func; 246 SendKeyPressEvent(HIDButtonToKey(button));
39 break;
40 case 'X':
41 yuzu_key_callbacks[2] = func;
42 break;
43 case 'Y':
44 yuzu_key_callbacks[3] = func;
45 break;
46 case 'L':
47 yuzu_key_callbacks[6] = func;
48 break;
49 case 'R':
50 yuzu_key_callbacks[7] = func;
51 break;
52 } 247 }
53 }; 248 };
54 249
55 var applet_done = false; 250 (f(T), ...);
56 window.nx.endApplet = function() { 251}
57 applet_done = true; 252
253template <HIDButton... T>
254void QtNXWebEngineView::HandleWindowKeyButtonHold() {
255 const auto f = [this](HIDButton button) {
256 if (input_interpreter->IsButtonHeld(button)) {
257 SendKeyPressEvent(HIDButtonToKey(button));
258 }
58 }; 259 };
59 260
60 window.onkeypress = function(e) { if (e.keyCode === 13) { applet_done = true; } }; 261 (f(T), ...);
61)"; 262}
263
264void QtNXWebEngineView::SendKeyPressEvent(int key) {
265 if (key == 0) {
266 return;
267 }
268
269 QCoreApplication::postEvent(focusProxy(),
270 new QKeyEvent(QKeyEvent::KeyPress, key, Qt::NoModifier));
271 QCoreApplication::postEvent(focusProxy(),
272 new QKeyEvent(QKeyEvent::KeyRelease, key, Qt::NoModifier));
273}
274
275void QtNXWebEngineView::StartInputThread() {
276 if (input_thread_running) {
277 return;
278 }
279
280 input_thread_running = true;
281 input_thread = std::thread(&QtNXWebEngineView::InputThread, this);
282}
283
284void QtNXWebEngineView::StopInputThread() {
285 if (is_local) {
286 QWidget::releaseKeyboard();
287 }
62 288
63QString GetNXShimInjectionScript() { 289 input_thread_running = false;
64 return QString::fromStdString(NX_SHIM_INJECT_SCRIPT); 290 if (input_thread.joinable()) {
291 input_thread.join();
292 }
65} 293}
66 294
67NXInputWebEngineView::NXInputWebEngineView(QWidget* parent) : QWebEngineView(parent) {} 295void QtNXWebEngineView::InputThread() {
296 // Wait for 1 second before allowing any inputs to be processed.
297 std::this_thread::sleep_for(std::chrono::seconds(1));
298
299 if (is_local) {
300 QWidget::grabKeyboard();
301 }
302
303 while (input_thread_running) {
304 input_interpreter->PollInput();
305
306 HandleWindowFooterButtonPressedOnce<HIDButton::A, HIDButton::B, HIDButton::X, HIDButton::Y,
307 HIDButton::L, HIDButton::R>();
308
309 HandleWindowKeyButtonPressedOnce<HIDButton::DLeft, HIDButton::DUp, HIDButton::DRight,
310 HIDButton::DDown, HIDButton::LStickLeft,
311 HIDButton::LStickUp, HIDButton::LStickRight,
312 HIDButton::LStickDown>();
68 313
69void NXInputWebEngineView::keyPressEvent(QKeyEvent* event) { 314 HandleWindowKeyButtonHold<HIDButton::DLeft, HIDButton::DUp, HIDButton::DRight,
70 parent()->event(event); 315 HIDButton::DDown, HIDButton::LStickLeft, HIDButton::LStickUp,
316 HIDButton::LStickRight, HIDButton::LStickDown>();
317
318 std::this_thread::sleep_for(std::chrono::milliseconds(50));
319 }
71} 320}
72 321
73void NXInputWebEngineView::keyReleaseEvent(QKeyEvent* event) { 322void QtNXWebEngineView::LoadExtractedFonts() {
74 parent()->event(event); 323 QWebEngineScript nx_font_css;
324 QWebEngineScript load_nx_font;
325
326 const QString fonts_dir = QString::fromStdString(Common::FS::SanitizePath(
327 fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir))));
328
329 nx_font_css.setName(QStringLiteral("nx_font_css.js"));
330 load_nx_font.setName(QStringLiteral("load_nx_font.js"));
331
332 nx_font_css.setSourceCode(
333 QString::fromStdString(NX_FONT_CSS)
334 .arg(fonts_dir + QStringLiteral("/FontStandard.ttf"))
335 .arg(fonts_dir + QStringLiteral("/FontChineseSimplified.ttf"))
336 .arg(fonts_dir + QStringLiteral("/FontExtendedChineseSimplified.ttf"))
337 .arg(fonts_dir + QStringLiteral("/FontChineseTraditional.ttf"))
338 .arg(fonts_dir + QStringLiteral("/FontKorean.ttf"))
339 .arg(fonts_dir + QStringLiteral("/FontNintendoExtended.ttf"))
340 .arg(fonts_dir + QStringLiteral("/FontNintendoExtended2.ttf")));
341 load_nx_font.setSourceCode(QString::fromStdString(LOAD_NX_FONT));
342
343 nx_font_css.setInjectionPoint(QWebEngineScript::DocumentReady);
344 load_nx_font.setInjectionPoint(QWebEngineScript::Deferred);
345
346 nx_font_css.setWorldId(QWebEngineScript::MainWorld);
347 load_nx_font.setWorldId(QWebEngineScript::MainWorld);
348
349 nx_font_css.setRunsOnSubFrames(true);
350 load_nx_font.setRunsOnSubFrames(true);
351
352 default_profile->scripts()->insert(nx_font_css);
353 default_profile->scripts()->insert(load_nx_font);
354
355 connect(
356 url_interceptor.get(), &UrlRequestInterceptor::FrameChanged, url_interceptor.get(),
357 [this] {
358 std::this_thread::sleep_for(std::chrono::milliseconds(50));
359 page()->runJavaScript(QString::fromStdString(LOAD_NX_FONT));
360 },
361 Qt::QueuedConnection);
75} 362}
76 363
77#endif 364#endif
78 365
79QtWebBrowser::QtWebBrowser(GMainWindow& main_window) { 366QtWebBrowser::QtWebBrowser(GMainWindow& main_window) {
80 connect(this, &QtWebBrowser::MainWindowOpenPage, &main_window, &GMainWindow::WebBrowserOpenPage, 367 connect(this, &QtWebBrowser::MainWindowOpenWebPage, &main_window,
81 Qt::QueuedConnection); 368 &GMainWindow::WebBrowserOpenWebPage, Qt::QueuedConnection);
82 connect(&main_window, &GMainWindow::WebBrowserUnpackRomFS, this, 369 connect(&main_window, &GMainWindow::WebBrowserExtractOfflineRomFS, this,
83 &QtWebBrowser::MainWindowUnpackRomFS, Qt::QueuedConnection); 370 &QtWebBrowser::MainWindowExtractOfflineRomFS, Qt::QueuedConnection);
84 connect(&main_window, &GMainWindow::WebBrowserFinishedBrowsing, this, 371 connect(&main_window, &GMainWindow::WebBrowserClosed, this,
85 &QtWebBrowser::MainWindowFinishedBrowsing, Qt::QueuedConnection); 372 &QtWebBrowser::MainWindowWebBrowserClosed, Qt::QueuedConnection);
86} 373}
87 374
88QtWebBrowser::~QtWebBrowser() = default; 375QtWebBrowser::~QtWebBrowser() = default;
89 376
90void QtWebBrowser::OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback_, 377void QtWebBrowser::OpenLocalWebPage(
91 std::function<void()> finished_callback_) { 378 std::string_view local_url, std::function<void()> extract_romfs_callback_,
92 unpack_romfs_callback = std::move(unpack_romfs_callback_); 379 std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback_) const {
93 finished_callback = std::move(finished_callback_); 380 extract_romfs_callback = std::move(extract_romfs_callback_);
381 callback = std::move(callback_);
382
383 const auto index = local_url.find('?');
384
385 if (index == std::string::npos) {
386 emit MainWindowOpenWebPage(local_url, "", true);
387 } else {
388 emit MainWindowOpenWebPage(local_url.substr(0, index), local_url.substr(index), true);
389 }
390}
391
392void QtWebBrowser::OpenExternalWebPage(
393 std::string_view external_url,
394 std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback_) const {
395 callback = std::move(callback_);
396
397 const auto index = external_url.find('?');
94 398
95 const auto index = url.find('?');
96 if (index == std::string::npos) { 399 if (index == std::string::npos) {
97 emit MainWindowOpenPage(url, ""); 400 emit MainWindowOpenWebPage(external_url, "", false);
98 } else { 401 } else {
99 const auto front = url.substr(0, index); 402 emit MainWindowOpenWebPage(external_url.substr(0, index), external_url.substr(index),
100 const auto back = url.substr(index); 403 false);
101 emit MainWindowOpenPage(front, back);
102 } 404 }
103} 405}
104 406
105void QtWebBrowser::MainWindowUnpackRomFS() { 407void QtWebBrowser::MainWindowExtractOfflineRomFS() {
106 // Acquire the HLE mutex 408 extract_romfs_callback();
107 std::lock_guard lock{HLE::g_hle_lock};
108 unpack_romfs_callback();
109} 409}
110 410
111void QtWebBrowser::MainWindowFinishedBrowsing() { 411void QtWebBrowser::MainWindowWebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason,
112 // Acquire the HLE mutex 412 std::string last_url) {
113 std::lock_guard lock{HLE::g_hle_lock}; 413 callback(exit_reason, last_url);
114 finished_callback();
115} 414}
diff --git a/src/yuzu/applets/web_browser.h b/src/yuzu/applets/web_browser.h
index f801846cf..47f960d69 100644
--- a/src/yuzu/applets/web_browser.h
+++ b/src/yuzu/applets/web_browser.h
@@ -1,10 +1,13 @@
1// Copyright 2018 yuzu Emulator Project 1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#pragma once 5#pragma once
6 6
7#include <functional> 7#include <atomic>
8#include <memory>
9#include <thread>
10
8#include <QObject> 11#include <QObject>
9 12
10#ifdef YUZU_USE_QT_WEB_ENGINE 13#ifdef YUZU_USE_QT_WEB_ENGINE
@@ -13,19 +16,172 @@
13 16
14#include "core/frontend/applets/web_browser.h" 17#include "core/frontend/applets/web_browser.h"
15 18
19enum class HIDButton : u8;
20
16class GMainWindow; 21class GMainWindow;
22class InputInterpreter;
23class UrlRequestInterceptor;
24
25namespace Core {
26class System;
27}
28
29namespace InputCommon {
30class InputSubsystem;
31}
17 32
18#ifdef YUZU_USE_QT_WEB_ENGINE 33#ifdef YUZU_USE_QT_WEB_ENGINE
19 34
20QString GetNXShimInjectionScript(); 35enum class UserAgent {
36 WebApplet,
37 ShopN,
38 LoginApplet,
39 ShareApplet,
40 LobbyApplet,
41 WifiWebAuthApplet,
42};
43
44class QWebEngineProfile;
45class QWebEngineSettings;
46
47class QtNXWebEngineView : public QWebEngineView {
48 Q_OBJECT
21 49
22class NXInputWebEngineView : public QWebEngineView {
23public: 50public:
24 explicit NXInputWebEngineView(QWidget* parent = nullptr); 51 explicit QtNXWebEngineView(QWidget* parent, Core::System& system,
52 InputCommon::InputSubsystem* input_subsystem_);
53 ~QtNXWebEngineView() override;
54
55 /**
56 * Loads a HTML document that exists locally. Cannot be used to load external websites.
57 *
58 * @param main_url The url to the file.
59 * @param additional_args Additional arguments appended to the main url.
60 */
61 void LoadLocalWebPage(std::string_view main_url, std::string_view additional_args);
62
63 /**
64 * Loads an external website. Cannot be used to load local urls.
65 *
66 * @param main_url The url to the website.
67 * @param additional_args Additional arguments appended to the main url.
68 */
69 void LoadExternalWebPage(std::string_view main_url, std::string_view additional_args);
70
71 /**
72 * Sets the background color of the web page.
73 *
74 * @param color The color to set.
75 */
76 void SetBackgroundColor(QColor color);
77
78 /**
79 * Sets the user agent of the web browser.
80 *
81 * @param user_agent The user agent enum.
82 */
83 void SetUserAgent(UserAgent user_agent);
84
85 [[nodiscard]] bool IsFinished() const;
86 void SetFinished(bool finished_);
87
88 [[nodiscard]] Service::AM::Applets::WebExitReason GetExitReason() const;
89 void SetExitReason(Service::AM::Applets::WebExitReason exit_reason_);
90
91 [[nodiscard]] const std::string& GetLastURL() const;
92 void SetLastURL(std::string last_url_);
93
94 /**
95 * This gets the current URL that has been requested by the webpage.
96 * This only applies to the main frame. Sub frames and other resources are ignored.
97 *
98 * @return Currently requested URL
99 */
100 [[nodiscard]] QString GetCurrentURL() const;
101
102public slots:
103 void hide();
25 104
26protected: 105protected:
27 void keyPressEvent(QKeyEvent* event) override; 106 void keyPressEvent(QKeyEvent* event) override;
28 void keyReleaseEvent(QKeyEvent* event) override; 107 void keyReleaseEvent(QKeyEvent* event) override;
108
109private:
110 /**
111 * Handles button presses to execute functions assigned in yuzu_key_callbacks.
112 * yuzu_key_callbacks contains specialized functions for the buttons in the window footer
113 * that can be overriden by games to achieve desired functionality.
114 *
115 * @tparam HIDButton The list of buttons contained in yuzu_key_callbacks
116 */
117 template <HIDButton... T>
118 void HandleWindowFooterButtonPressedOnce();
119
120 /**
121 * Handles button presses and converts them into keyboard input.
122 * This should only be used to convert D-Pad or Analog Stick input into arrow keys.
123 *
124 * @tparam HIDButton The list of buttons that can be converted into keyboard input.
125 */
126 template <HIDButton... T>
127 void HandleWindowKeyButtonPressedOnce();
128
129 /**
130 * Handles button holds and converts them into keyboard input.
131 * This should only be used to convert D-Pad or Analog Stick input into arrow keys.
132 *
133 * @tparam HIDButton The list of buttons that can be converted into keyboard input.
134 */
135 template <HIDButton... T>
136 void HandleWindowKeyButtonHold();
137
138 /**
139 * Sends a key press event to QWebEngineView.
140 *
141 * @param key Qt key code.
142 */
143 void SendKeyPressEvent(int key);
144
145 /**
146 * Sends multiple key press events to QWebEngineView.
147 *
148 * @tparam int Qt key code.
149 */
150 template <int... T>
151 void SendMultipleKeyPressEvents() {
152 (SendKeyPressEvent(T), ...);
153 }
154
155 void StartInputThread();
156 void StopInputThread();
157
158 /// The thread where input is being polled and processed.
159 void InputThread();
160
161 /// Loads the extracted fonts using JavaScript.
162 void LoadExtractedFonts();
163
164 InputCommon::InputSubsystem* input_subsystem;
165
166 std::unique_ptr<UrlRequestInterceptor> url_interceptor;
167
168 std::unique_ptr<InputInterpreter> input_interpreter;
169
170 std::thread input_thread;
171
172 std::atomic<bool> input_thread_running{};
173
174 std::atomic<bool> finished{};
175
176 Service::AM::Applets::WebExitReason exit_reason{
177 Service::AM::Applets::WebExitReason::EndButtonPressed};
178
179 std::string last_url{"http://localhost/"};
180
181 bool is_local{};
182
183 QWebEngineProfile* default_profile;
184 QWebEngineSettings* global_settings;
29}; 185};
30 186
31#endif 187#endif
@@ -34,19 +190,28 @@ class QtWebBrowser final : public QObject, public Core::Frontend::WebBrowserAppl
34 Q_OBJECT 190 Q_OBJECT
35 191
36public: 192public:
37 explicit QtWebBrowser(GMainWindow& main_window); 193 explicit QtWebBrowser(GMainWindow& parent);
38 ~QtWebBrowser() override; 194 ~QtWebBrowser() override;
39 195
40 void OpenPageLocal(std::string_view url, std::function<void()> unpack_romfs_callback_, 196 void OpenLocalWebPage(std::string_view local_url, std::function<void()> extract_romfs_callback_,
41 std::function<void()> finished_callback_) override; 197 std::function<void(Service::AM::Applets::WebExitReason, std::string)>
198 callback_) const override;
199
200 void OpenExternalWebPage(std::string_view external_url,
201 std::function<void(Service::AM::Applets::WebExitReason, std::string)>
202 callback_) const override;
42 203
43signals: 204signals:
44 void MainWindowOpenPage(std::string_view filename, std::string_view additional_args) const; 205 void MainWindowOpenWebPage(std::string_view main_url, std::string_view additional_args,
206 bool is_local) const;
45 207
46private: 208private:
47 void MainWindowUnpackRomFS(); 209 void MainWindowExtractOfflineRomFS();
48 void MainWindowFinishedBrowsing(); 210
211 void MainWindowWebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason,
212 std::string last_url);
213
214 mutable std::function<void()> extract_romfs_callback;
49 215
50 std::function<void()> unpack_romfs_callback; 216 mutable std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback;
51 std::function<void()> finished_callback;
52}; 217};
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 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7constexpr char NX_FONT_CSS[] = R"(
8(function() {
9 css = document.createElement('style');
10 css.type = 'text/css';
11 css.id = 'nx_font';
12 css.innerText = `
13/* FontStandard */
14@font-face {
15 font-family: 'FontStandard';
16 src: url('%1') format('truetype');
17}
18
19/* FontChineseSimplified */
20@font-face {
21 font-family: 'FontChineseSimplified';
22 src: url('%2') format('truetype');
23}
24
25/* FontExtendedChineseSimplified */
26@font-face {
27 font-family: 'FontExtendedChineseSimplified';
28 src: url('%3') format('truetype');
29}
30
31/* FontChineseTraditional */
32@font-face {
33 font-family: 'FontChineseTraditional';
34 src: url('%4') format('truetype');
35}
36
37/* FontKorean */
38@font-face {
39 font-family: 'FontKorean';
40 src: url('%5') format('truetype');
41}
42
43/* FontNintendoExtended */
44@font-face {
45 font-family: 'NintendoExt003';
46 src: url('%6') format('truetype');
47}
48
49/* FontNintendoExtended2 */
50@font-face {
51 font-family: 'NintendoExt003';
52 src: url('%7') format('truetype');
53}
54`;
55
56 document.head.appendChild(css);
57})();
58)";
59
60constexpr char LOAD_NX_FONT[] = R"(
61(function() {
62 var elements = document.querySelectorAll("*");
63
64 for (var i = 0; i < elements.length; i++) {
65 var style = window.getComputedStyle(elements[i], null);
66 if (style.fontFamily.includes("Arial") || style.fontFamily.includes("Calibri") ||
67 style.fontFamily.includes("Century") || style.fontFamily.includes("Times New Roman")) {
68 elements[i].style.fontFamily = "FontStandard, FontChineseSimplified, FontExtendedChineseSimplified, FontChineseTraditional, FontKorean, NintendoExt003";
69 } else {
70 elements[i].style.fontFamily = style.fontFamily + ", FontStandard, FontChineseSimplified, FontExtendedChineseSimplified, FontChineseTraditional, FontKorean, NintendoExt003";
71 }
72 }
73})();
74)";
75
76constexpr char GAMEPAD_SCRIPT[] = R"(
77window.addEventListener("gamepadconnected", function(e) {
78 console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
79 e.gamepad.index, e.gamepad.id, e.gamepad.buttons.length, e.gamepad.axes.length);
80});
81
82window.addEventListener("gamepaddisconnected", function(e) {
83 console.log("Gamepad disconnected from index %d: %s", e.gamepad.index, e.gamepad.id);
84});
85)";
86
87constexpr char WINDOW_NX_SCRIPT[] = R"(
88var end_applet = false;
89var yuzu_key_callbacks = [];
90
91(function() {
92 class WindowNX {
93 constructor() {
94 yuzu_key_callbacks[1] = function() { window.history.back(); };
95 yuzu_key_callbacks[2] = function() { window.nx.endApplet(); };
96 }
97
98 addEventListener(type, listener, options) {
99 console.log("nx.addEventListener called, type=%s", type);
100
101 window.addEventListener(type, listener, options);
102 }
103
104 endApplet() {
105 console.log("nx.endApplet called");
106
107 end_applet = true;
108 }
109
110 playSystemSe(system_se) {
111 console.log("nx.playSystemSe is not implemented, system_se=%s", system_se);
112 }
113
114 sendMessage(message) {
115 console.log("nx.sendMessage is not implemented, message=%s", message);
116 }
117
118 setCursorScrollSpeed(scroll_speed) {
119 console.log("nx.setCursorScrollSpeed is not implemented, scroll_speed=%d", scroll_speed);
120 }
121 }
122
123 class WindowNXFooter {
124 setAssign(key, label, func, option) {
125 console.log("nx.footer.setAssign called, key=%s", key);
126
127 switch (key) {
128 case "A":
129 yuzu_key_callbacks[0] = func;
130 break;
131 case "B":
132 yuzu_key_callbacks[1] = func;
133 break;
134 case "X":
135 yuzu_key_callbacks[2] = func;
136 break;
137 case "Y":
138 yuzu_key_callbacks[3] = func;
139 break;
140 case "L":
141 yuzu_key_callbacks[6] = func;
142 break;
143 case "R":
144 yuzu_key_callbacks[7] = func;
145 break;
146 }
147 }
148
149 setFixed(kind) {
150 console.log("nx.footer.setFixed is not implemented, kind=%s", kind);
151 }
152
153 unsetAssign(key) {
154 console.log("nx.footer.unsetAssign called, key=%s", key);
155
156 switch (key) {
157 case "A":
158 yuzu_key_callbacks[0] = function() {};
159 break;
160 case "B":
161 yuzu_key_callbacks[1] = function() {};
162 break;
163 case "X":
164 yuzu_key_callbacks[2] = function() {};
165 break;
166 case "Y":
167 yuzu_key_callbacks[3] = function() {};
168 break;
169 case "L":
170 yuzu_key_callbacks[6] = function() {};
171 break;
172 case "R":
173 yuzu_key_callbacks[7] = function() {};
174 break;
175 }
176 }
177 }
178
179 class WindowNXPlayReport {
180 incrementCounter(counter_id) {
181 console.log("nx.playReport.incrementCounter is not implemented, counter_id=%d", counter_id);
182 }
183
184 setCounterSetIdentifier(counter_id) {
185 console.log("nx.playReport.setCounterSetIdentifier is not implemented, counter_id=%d", counter_id);
186 }
187 }
188
189 window.nx = new WindowNX();
190 window.nx.footer = new WindowNXFooter();
191 window.nx.playReport = new WindowNXPlayReport();
192})();
193)";
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
569 layout); 569 layout);
570} 570}
571 571
572bool GRenderWindow::IsLoadingComplete() const {
573 return first_frame;
574}
575
572void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) { 576void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {
573 setMinimumSize(minimal_size.first, minimal_size.second); 577 setMinimumSize(minimal_size.first, minimal_size.second);
574} 578}
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:
162 /// Destroy the previous run's child_widget which should also destroy the child_window 162 /// Destroy the previous run's child_widget which should also destroy the child_window
163 void ReleaseRenderTarget(); 163 void ReleaseRenderTarget();
164 164
165 bool IsLoadingComplete() const;
166
165 void CaptureScreenshot(u32 res_scale, const QString& screenshot_path); 167 void CaptureScreenshot(u32 res_scale, const QString& screenshot_path);
166 168
167 std::pair<u32, u32> ScaleTouch(const QPointF& pos) const; 169 std::pair<u32, u32> ScaleTouch(const QPointF& pos) const;
diff --git a/src/yuzu/debugger/profiler.cpp b/src/yuzu/debugger/profiler.cpp
index 0e26f765b..efdc6aa50 100644
--- a/src/yuzu/debugger/profiler.cpp
+++ b/src/yuzu/debugger/profiler.cpp
@@ -48,7 +48,7 @@ private:
48 48
49MicroProfileDialog::MicroProfileDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) { 49MicroProfileDialog::MicroProfileDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) {
50 setObjectName(QStringLiteral("MicroProfile")); 50 setObjectName(QStringLiteral("MicroProfile"));
51 setWindowTitle(tr("MicroProfile")); 51 setWindowTitle(tr("&MicroProfile"));
52 resize(1000, 600); 52 resize(1000, 600);
53 // Remove the "?" button from the titlebar and enable the maximize button 53 // Remove the "?" button from the titlebar and enable the maximize button
54 setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) | 54 setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) |
diff --git a/src/yuzu/debugger/wait_tree.cpp b/src/yuzu/debugger/wait_tree.cpp
index 546a2cd4d..0925c10b4 100644
--- a/src/yuzu/debugger/wait_tree.cpp
+++ b/src/yuzu/debugger/wait_tree.cpp
@@ -457,7 +457,7 @@ void WaitTreeModel::InitItems() {
457 thread_items = WaitTreeItem::MakeThreadItemList(); 457 thread_items = WaitTreeItem::MakeThreadItemList();
458} 458}
459 459
460WaitTreeWidget::WaitTreeWidget(QWidget* parent) : QDockWidget(tr("Wait Tree"), parent) { 460WaitTreeWidget::WaitTreeWidget(QWidget* parent) : QDockWidget(tr("&Wait Tree"), parent) {
461 setObjectName(QStringLiteral("WaitTreeWidget")); 461 setObjectName(QStringLiteral("WaitTreeWidget"));
462 view = new QTreeView(this); 462 view = new QTreeView(this);
463 view->setHeaderHidden(true); 463 view->setHeaderHidden(true);
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 920789f6f..44ca3db8b 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -28,8 +28,6 @@
28#include "core/hle/service/am/applet_ae.h" 28#include "core/hle/service/am/applet_ae.h"
29#include "core/hle/service/am/applet_oe.h" 29#include "core/hle/service/am/applet_oe.h"
30#include "core/hle/service/am/applets/applets.h" 30#include "core/hle/service/am/applets/applets.h"
31#include "core/hle/service/hid/controllers/npad.h"
32#include "core/hle/service/hid/hid.h"
33 31
34// These are wrappers to avoid the calls to CreateDirectory and CreateFile because of the Windows 32// These are wrappers to avoid the calls to CreateDirectory and CreateFile because of the Windows
35// defines. 33// defines.
@@ -125,14 +123,6 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
125#include "yuzu/discord_impl.h" 123#include "yuzu/discord_impl.h"
126#endif 124#endif
127 125
128#ifdef YUZU_USE_QT_WEB_ENGINE
129#include <QWebEngineProfile>
130#include <QWebEngineScript>
131#include <QWebEngineScriptCollection>
132#include <QWebEngineSettings>
133#include <QWebEngineView>
134#endif
135
136#ifdef QT_STATICPLUGIN 126#ifdef QT_STATICPLUGIN
137Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin); 127Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
138#endif 128#endif
@@ -190,6 +180,30 @@ static void InitializeLogging() {
190#endif 180#endif
191} 181}
192 182
183static void RemoveCachedContents() {
184 const auto offline_fonts = Common::FS::SanitizePath(
185 fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
186 Common::FS::DirectorySeparator::PlatformDefault);
187
188 const auto offline_manual = Common::FS::SanitizePath(
189 fmt::format("{}/offline_web_applet_manual",
190 Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
191 Common::FS::DirectorySeparator::PlatformDefault);
192 const auto offline_legal_information = Common::FS::SanitizePath(
193 fmt::format("{}/offline_web_applet_legal_information",
194 Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
195 Common::FS::DirectorySeparator::PlatformDefault);
196 const auto offline_system_data = Common::FS::SanitizePath(
197 fmt::format("{}/offline_web_applet_system_data",
198 Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
199 Common::FS::DirectorySeparator::PlatformDefault);
200
201 Common::FS::DeleteDirRecursively(offline_fonts);
202 Common::FS::DeleteDirRecursively(offline_manual);
203 Common::FS::DeleteDirRecursively(offline_legal_information);
204 Common::FS::DeleteDirRecursively(offline_system_data);
205}
206
193GMainWindow::GMainWindow() 207GMainWindow::GMainWindow()
194 : input_subsystem{std::make_shared<InputCommon::InputSubsystem>()}, 208 : input_subsystem{std::make_shared<InputCommon::InputSubsystem>()},
195 config{std::make_unique<Config>()}, vfs{std::make_shared<FileSys::RealVfsFilesystem>()}, 209 config{std::make_unique<Config>()}, vfs{std::make_shared<FileSys::RealVfsFilesystem>()},
@@ -258,6 +272,9 @@ GMainWindow::GMainWindow()
258 FileSys::ContentProviderUnionSlot::FrontendManual, provider.get()); 272 FileSys::ContentProviderUnionSlot::FrontendManual, provider.get());
259 Core::System::GetInstance().GetFileSystemController().CreateFactories(*vfs); 273 Core::System::GetInstance().GetFileSystemController().CreateFactories(*vfs);
260 274
275 // Remove cached contents generated during the previous session
276 RemoveCachedContents();
277
261 // Gen keys if necessary 278 // Gen keys if necessary
262 OnReinitializeKeys(ReinitializeKeyBehavior::NoWarning); 279 OnReinitializeKeys(ReinitializeKeyBehavior::NoWarning);
263 280
@@ -349,150 +366,141 @@ void GMainWindow::SoftwareKeyboardInvokeCheckDialog(std::u16string error_message
349 emit SoftwareKeyboardFinishedCheckDialog(); 366 emit SoftwareKeyboardFinishedCheckDialog();
350} 367}
351 368
369void GMainWindow::WebBrowserOpenWebPage(std::string_view main_url, std::string_view additional_args,
370 bool is_local) {
352#ifdef YUZU_USE_QT_WEB_ENGINE 371#ifdef YUZU_USE_QT_WEB_ENGINE
353 372
354void GMainWindow::WebBrowserOpenPage(std::string_view filename, std::string_view additional_args) { 373 if (disable_web_applet) {
355 NXInputWebEngineView web_browser_view(this); 374 emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed,
375 "http://localhost/");
376 return;
377 }
356 378
357 // Scope to contain the QProgressDialog for initialization 379 QtNXWebEngineView web_browser_view(this, Core::System::GetInstance(), input_subsystem.get());
358 { 380
359 QProgressDialog progress(this); 381 ui.action_Pause->setEnabled(false);
360 progress.setMinimumDuration(200); 382 ui.action_Restart->setEnabled(false);
361 progress.setLabelText(tr("Loading Web Applet...")); 383 ui.action_Stop->setEnabled(false);
362 progress.setRange(0, 4);
363 progress.setValue(0);
364 progress.show();
365 384
366 auto future = QtConcurrent::run([this] { emit WebBrowserUnpackRomFS(); }); 385 {
386 QProgressDialog loading_progress(this);
387 loading_progress.setLabelText(tr("Loading Web Applet..."));
388 loading_progress.setRange(0, 3);
389 loading_progress.setValue(0);
367 390
368 while (!future.isFinished()) 391 if (is_local && !Common::FS::Exists(std::string(main_url))) {
369 QApplication::processEvents(); 392 loading_progress.show();
370 393
371 progress.setValue(1); 394 auto future = QtConcurrent::run([this] { emit WebBrowserExtractOfflineRomFS(); });
372 395
373 // Load the special shim script to handle input and exit. 396 while (!future.isFinished()) {
374 QWebEngineScript nx_shim; 397 QCoreApplication::processEvents();
375 nx_shim.setSourceCode(GetNXShimInjectionScript()); 398 }
376 nx_shim.setWorldId(QWebEngineScript::MainWorld); 399 }
377 nx_shim.setName(QStringLiteral("nx_inject.js"));
378 nx_shim.setInjectionPoint(QWebEngineScript::DocumentCreation);
379 nx_shim.setRunsOnSubFrames(true);
380 web_browser_view.page()->profile()->scripts()->insert(nx_shim);
381 400
382 web_browser_view.load( 401 loading_progress.setValue(1);
383 QUrl(QUrl::fromLocalFile(QString::fromStdString(std::string(filename))).toString() +
384 QString::fromStdString(std::string(additional_args))));
385 402
386 progress.setValue(2); 403 if (is_local) {
404 web_browser_view.LoadLocalWebPage(main_url, additional_args);
405 } else {
406 web_browser_view.LoadExternalWebPage(main_url, additional_args);
407 }
387 408
388 render_window->hide(); 409 if (render_window->IsLoadingComplete()) {
389 web_browser_view.setFocus(); 410 render_window->hide();
411 }
390 412
391 const auto& layout = render_window->GetFramebufferLayout(); 413 const auto& layout = render_window->GetFramebufferLayout();
392 web_browser_view.resize(layout.screen.GetWidth(), layout.screen.GetHeight()); 414 web_browser_view.resize(layout.screen.GetWidth(), layout.screen.GetHeight());
393 web_browser_view.move(layout.screen.left, layout.screen.top + menuBar()->height()); 415 web_browser_view.move(layout.screen.left, layout.screen.top + menuBar()->height());
394 web_browser_view.setZoomFactor(static_cast<qreal>(layout.screen.GetWidth()) / 416 web_browser_view.setZoomFactor(static_cast<qreal>(layout.screen.GetWidth()) /
395 Layout::ScreenUndocked::Width); 417 static_cast<qreal>(Layout::ScreenUndocked::Width));
396 web_browser_view.settings()->setAttribute(
397 QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
398 418
419 web_browser_view.setFocus();
399 web_browser_view.show(); 420 web_browser_view.show();
400 421
401 progress.setValue(3); 422 loading_progress.setValue(2);
402 423
403 QApplication::processEvents(); 424 QCoreApplication::processEvents();
404 425
405 progress.setValue(4); 426 loading_progress.setValue(3);
406 } 427 }
407 428
408 bool finished = false; 429 bool exit_check = false;
409 QAction* exit_action = new QAction(tr("Exit Web Applet"), this);
410 connect(exit_action, &QAction::triggered, this, [&finished] { finished = true; });
411 ui.menubar->addAction(exit_action);
412 430
413 auto& npad = 431 // TODO (Morph): Remove this
414 Core::System::GetInstance() 432 QAction* exit_action = new QAction(tr("Disable Web Applet"), this);
415 .ServiceManager() 433 connect(exit_action, &QAction::triggered, this, [this, &web_browser_view] {
416 .GetService<Service::HID::Hid>("hid") 434 const auto result = QMessageBox::warning(
417 ->GetAppletResource() 435 this, tr("Disable Web Applet"),
418 ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad); 436 tr("Disabling the web applet will cause it to not be shown again for the rest of the "
419 437 "emulated session. This can lead to undefined behavior and should only be used with "
420 const auto fire_js_keypress = [&web_browser_view](u32 key_code) { 438 "Super Mario 3D All-Stars. Are you sure you want to disable the web applet?"),
421 web_browser_view.page()->runJavaScript( 439 QMessageBox::Yes | QMessageBox::No);
422 QStringLiteral("document.dispatchEvent(new KeyboardEvent('keydown', {'key': %1}));") 440 if (result == QMessageBox::Yes) {
423 .arg(key_code)); 441 disable_web_applet = true;
424 }; 442 web_browser_view.SetFinished(true);
443 }
444 });
445 ui.menubar->addAction(exit_action);
425 446
426 QMessageBox::information( 447 while (!web_browser_view.IsFinished()) {
427 this, tr("Exit"), 448 QCoreApplication::processEvents();
428 tr("To exit the web application, use the game provided controls to select exit, select the " 449
429 "'Exit Web Applet' option in the menu bar, or press the 'Enter' key.")); 450 if (!exit_check) {
430 451 web_browser_view.page()->runJavaScript(
431 bool running_exit_check = false; 452 QStringLiteral("end_applet;"), [&](const QVariant& variant) {
432 while (!finished) { 453 exit_check = false;
433 QApplication::processEvents(); 454 if (variant.toBool()) {
434 455 web_browser_view.SetFinished(true);
435 if (!running_exit_check) { 456 web_browser_view.SetExitReason(
436 web_browser_view.page()->runJavaScript(QStringLiteral("applet_done;"), 457 Service::AM::Applets::WebExitReason::EndButtonPressed);
437 [&](const QVariant& res) { 458 }
438 running_exit_check = false; 459 });
439 if (res.toBool()) 460
440 finished = true; 461 exit_check = true;
441 });
442 running_exit_check = true;
443 } 462 }
444 463
445 const auto input = npad.GetAndResetPressState(); 464 if (web_browser_view.GetCurrentURL().contains(QStringLiteral("localhost"))) {
446 for (std::size_t i = 0; i < Settings::NativeButton::NumButtons; ++i) { 465 if (!web_browser_view.IsFinished()) {
447 if ((input & (1 << i)) != 0) { 466 web_browser_view.SetFinished(true);
448 LOG_DEBUG(Frontend, "firing input for button id={:02X}", i); 467 web_browser_view.SetExitReason(Service::AM::Applets::WebExitReason::CallbackURL);
449 web_browser_view.page()->runJavaScript(
450 QStringLiteral("yuzu_key_callbacks[%1]();").arg(i));
451 } 468 }
469
470 web_browser_view.SetLastURL(web_browser_view.GetCurrentURL().toStdString());
452 } 471 }
453 472
454 if (input & 0x00888000) // RStick Down | LStick Down | DPad Down 473 std::this_thread::sleep_for(std::chrono::milliseconds(1));
455 fire_js_keypress(40); // Down Arrow Key
456 else if (input & 0x00444000) // RStick Right | LStick Right | DPad Right
457 fire_js_keypress(39); // Right Arrow Key
458 else if (input & 0x00222000) // RStick Up | LStick Up | DPad Up
459 fire_js_keypress(38); // Up Arrow Key
460 else if (input & 0x00111000) // RStick Left | LStick Left | DPad Left
461 fire_js_keypress(37); // Left Arrow Key
462 else if (input & 0x00000001) // A Button
463 fire_js_keypress(13); // Enter Key
464 } 474 }
465 475
476 const auto exit_reason = web_browser_view.GetExitReason();
477 const auto last_url = web_browser_view.GetLastURL();
478
466 web_browser_view.hide(); 479 web_browser_view.hide();
467 render_window->show(); 480
468 render_window->setFocus(); 481 render_window->setFocus();
469 ui.menubar->removeAction(exit_action);
470 482
471 // Needed to update render window focus/show and remove menubar action 483 if (render_window->IsLoadingComplete()) {
472 QApplication::processEvents(); 484 render_window->show();
473 emit WebBrowserFinishedBrowsing(); 485 }
474}
475 486
476#else 487 ui.action_Pause->setEnabled(true);
488 ui.action_Restart->setEnabled(true);
489 ui.action_Stop->setEnabled(true);
477 490
478void GMainWindow::WebBrowserOpenPage(std::string_view filename, std::string_view additional_args) { 491 ui.menubar->removeAction(exit_action);
479#ifndef __linux__
480 QMessageBox::warning(
481 this, tr("Web Applet"),
482 tr("This version of yuzu was built without QtWebEngine support, meaning that yuzu cannot "
483 "properly display the game manual or web page requested."),
484 QMessageBox::Ok, QMessageBox::Ok);
485#endif
486 492
487 LOG_INFO(Frontend, 493 QCoreApplication::processEvents();
488 "(STUBBED) called - Missing QtWebEngine dependency needed to open website page at "
489 "'{}' with arguments '{}'!",
490 filename, additional_args);
491 494
492 emit WebBrowserFinishedBrowsing(); 495 emit WebBrowserClosed(exit_reason, last_url);
493} 496
497#else
498
499 // Utilize the same fallback as the default web browser applet.
500 emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/");
494 501
495#endif 502#endif
503}
496 504
497void GMainWindow::InitializeWidgets() { 505void GMainWindow::InitializeWidgets() {
498#ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING 506#ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING
@@ -669,7 +677,7 @@ void GMainWindow::InitializeRecentFileMenuActions() {
669 } 677 }
670 ui.menu_recent_files->addSeparator(); 678 ui.menu_recent_files->addSeparator();
671 QAction* action_clear_recent_files = new QAction(this); 679 QAction* action_clear_recent_files = new QAction(this);
672 action_clear_recent_files->setText(tr("Clear Recent Files")); 680 action_clear_recent_files->setText(tr("&Clear Recent Files"));
673 connect(action_clear_recent_files, &QAction::triggered, this, [this] { 681 connect(action_clear_recent_files, &QAction::triggered, this, [this] {
674 UISettings::values.recent_files.clear(); 682 UISettings::values.recent_files.clear();
675 UpdateRecentFiles(); 683 UpdateRecentFiles();
@@ -931,7 +939,10 @@ void GMainWindow::ConnectMenuEvents() {
931 &GMainWindow::OnDisplayTitleBars); 939 &GMainWindow::OnDisplayTitleBars);
932 connect(ui.action_Show_Filter_Bar, &QAction::triggered, this, &GMainWindow::OnToggleFilterBar); 940 connect(ui.action_Show_Filter_Bar, &QAction::triggered, this, &GMainWindow::OnToggleFilterBar);
933 connect(ui.action_Show_Status_Bar, &QAction::triggered, statusBar(), &QStatusBar::setVisible); 941 connect(ui.action_Show_Status_Bar, &QAction::triggered, statusBar(), &QStatusBar::setVisible);
934 connect(ui.action_Reset_Window_Size, &QAction::triggered, this, &GMainWindow::ResetWindowSize); 942 connect(ui.action_Reset_Window_Size_720, &QAction::triggered, this,
943 &GMainWindow::ResetWindowSize720);
944 connect(ui.action_Reset_Window_Size_1080, &QAction::triggered, this,
945 &GMainWindow::ResetWindowSize1080);
935 946
936 // Fullscreen 947 // Fullscreen
937 connect(ui.action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen); 948 connect(ui.action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen);
@@ -993,7 +1004,6 @@ bool GMainWindow::LoadROM(const QString& filename, std::size_t program_index) {
993 1004
994 system.SetAppletFrontendSet({ 1005 system.SetAppletFrontendSet({
995 std::make_unique<QtControllerSelector>(*this), // Controller Selector 1006 std::make_unique<QtControllerSelector>(*this), // Controller Selector
996 nullptr, // E-Commerce
997 std::make_unique<QtErrorDisplay>(*this), // Error Display 1007 std::make_unique<QtErrorDisplay>(*this), // Error Display
998 nullptr, // Parental Controls 1008 nullptr, // Parental Controls
999 nullptr, // Photo Viewer 1009 nullptr, // Photo Viewer
@@ -2107,11 +2117,12 @@ void GMainWindow::OnStartGame() {
2107 qRegisterMetaType<std::string>("std::string"); 2117 qRegisterMetaType<std::string>("std::string");
2108 qRegisterMetaType<std::optional<std::u16string>>("std::optional<std::u16string>"); 2118 qRegisterMetaType<std::optional<std::u16string>>("std::optional<std::u16string>");
2109 qRegisterMetaType<std::string_view>("std::string_view"); 2119 qRegisterMetaType<std::string_view>("std::string_view");
2120 qRegisterMetaType<Service::AM::Applets::WebExitReason>("Service::AM::Applets::WebExitReason");
2110 2121
2111 connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError); 2122 connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError);
2112 2123
2113 ui.action_Start->setEnabled(false); 2124 ui.action_Start->setEnabled(false);
2114 ui.action_Start->setText(tr("Continue")); 2125 ui.action_Start->setText(tr("&Continue"));
2115 2126
2116 ui.action_Pause->setEnabled(true); 2127 ui.action_Pause->setEnabled(true);
2117 ui.action_Stop->setEnabled(true); 2128 ui.action_Stop->setEnabled(true);
@@ -2255,7 +2266,7 @@ void GMainWindow::ToggleWindowMode() {
2255 } 2266 }
2256} 2267}
2257 2268
2258void GMainWindow::ResetWindowSize() { 2269void GMainWindow::ResetWindowSize720() {
2259 const auto aspect_ratio = Layout::EmulationAspectRatio( 2270 const auto aspect_ratio = Layout::EmulationAspectRatio(
2260 static_cast<Layout::AspectRatio>(Settings::values.aspect_ratio.GetValue()), 2271 static_cast<Layout::AspectRatio>(Settings::values.aspect_ratio.GetValue()),
2261 static_cast<float>(Layout::ScreenUndocked::Height) / Layout::ScreenUndocked::Width); 2272 static_cast<float>(Layout::ScreenUndocked::Height) / Layout::ScreenUndocked::Width);
@@ -2269,6 +2280,20 @@ void GMainWindow::ResetWindowSize() {
2269 } 2280 }
2270} 2281}
2271 2282
2283void GMainWindow::ResetWindowSize1080() {
2284 const auto aspect_ratio = Layout::EmulationAspectRatio(
2285 static_cast<Layout::AspectRatio>(Settings::values.aspect_ratio.GetValue()),
2286 static_cast<float>(Layout::ScreenDocked::Height) / Layout::ScreenDocked::Width);
2287 if (!ui.action_Single_Window_Mode->isChecked()) {
2288 render_window->resize(Layout::ScreenDocked::Height / aspect_ratio,
2289 Layout::ScreenDocked::Height);
2290 } else {
2291 resize(Layout::ScreenDocked::Height / aspect_ratio,
2292 Layout::ScreenDocked::Height + menuBar()->height() +
2293 (ui.action_Show_Status_Bar->isChecked() ? statusBar()->height() : 0));
2294 }
2295}
2296
2272void GMainWindow::OnConfigure() { 2297void GMainWindow::OnConfigure() {
2273 const auto old_theme = UISettings::values.theme; 2298 const auto old_theme = UISettings::values.theme;
2274 const bool old_discord_presence = UISettings::values.enable_discord_presence; 2299 const bool old_discord_presence = UISettings::values.enable_discord_presence;
@@ -2953,7 +2978,7 @@ void GMainWindow::OnLanguageChanged(const QString& locale) {
2953 UpdateWindowTitle(); 2978 UpdateWindowTitle();
2954 2979
2955 if (emulation_running) 2980 if (emulation_running)
2956 ui.action_Start->setText(tr("Continue")); 2981 ui.action_Start->setText(tr("&Continue"));
2957} 2982}
2958 2983
2959void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) { 2984void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 6aeac1925..ea6d2c30d 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -55,6 +55,10 @@ namespace InputCommon {
55class InputSubsystem; 55class InputSubsystem;
56} 56}
57 57
58namespace Service::AM::Applets {
59enum class WebExitReason : u32;
60}
61
58enum class EmulatedDirectoryTarget { 62enum class EmulatedDirectoryTarget {
59 NAND, 63 NAND,
60 SDMC, 64 SDMC,
@@ -126,8 +130,8 @@ signals:
126 void SoftwareKeyboardFinishedText(std::optional<std::u16string> text); 130 void SoftwareKeyboardFinishedText(std::optional<std::u16string> text);
127 void SoftwareKeyboardFinishedCheckDialog(); 131 void SoftwareKeyboardFinishedCheckDialog();
128 132
129 void WebBrowserUnpackRomFS(); 133 void WebBrowserExtractOfflineRomFS();
130 void WebBrowserFinishedBrowsing(); 134 void WebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, std::string last_url);
131 135
132public slots: 136public slots:
133 void OnLoadComplete(); 137 void OnLoadComplete();
@@ -138,7 +142,8 @@ public slots:
138 void ProfileSelectorSelectProfile(); 142 void ProfileSelectorSelectProfile();
139 void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters); 143 void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters);
140 void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); 144 void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message);
141 void WebBrowserOpenPage(std::string_view filename, std::string_view arguments); 145 void WebBrowserOpenWebPage(std::string_view main_url, std::string_view additional_args,
146 bool is_local);
142 void OnAppFocusStateChanged(Qt::ApplicationState state); 147 void OnAppFocusStateChanged(Qt::ApplicationState state);
143 148
144private: 149private:
@@ -237,7 +242,8 @@ private slots:
237 void ShowFullscreen(); 242 void ShowFullscreen();
238 void HideFullscreen(); 243 void HideFullscreen();
239 void ToggleWindowMode(); 244 void ToggleWindowMode();
240 void ResetWindowSize(); 245 void ResetWindowSize720();
246 void ResetWindowSize1080();
241 void OnCaptureScreenshot(); 247 void OnCaptureScreenshot();
242 void OnCoreError(Core::System::ResultStatus, std::string); 248 void OnCoreError(Core::System::ResultStatus, std::string);
243 void OnReinitializeKeys(ReinitializeKeyBehavior behavior); 249 void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
@@ -322,6 +328,9 @@ private:
322 // Last game booted, used for multi-process apps 328 // Last game booted, used for multi-process apps
323 QString last_filename_booted; 329 QString last_filename_booted;
324 330
331 // Disables the web applet for the rest of the emulated session
332 bool disable_web_applet{};
333
325protected: 334protected:
326 void dropEvent(QDropEvent* event) override; 335 void dropEvent(QDropEvent* event) override;
327 void dragEnterEvent(QDragEnterEvent* event) override; 336 void dragEnterEvent(QDragEnterEvent* event) override;
diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui
index 2f3792247..e2ad5baf6 100644
--- a/src/yuzu/main.ui
+++ b/src/yuzu/main.ui
@@ -25,16 +25,7 @@
25 </property> 25 </property>
26 <widget class="QWidget" name="centralwidget"> 26 <widget class="QWidget" name="centralwidget">
27 <layout class="QHBoxLayout" name="horizontalLayout"> 27 <layout class="QHBoxLayout" name="horizontalLayout">
28 <property name="leftMargin"> 28 <property name="margin">
29 <number>0</number>
30 </property>
31 <property name="topMargin">
32 <number>0</number>
33 </property>
34 <property name="rightMargin">
35 <number>0</number>
36 </property>
37 <property name="bottomMargin">
38 <number>0</number> 29 <number>0</number>
39 </property> 30 </property>
40 </layout> 31 </layout>
@@ -45,7 +36,7 @@
45 <x>0</x> 36 <x>0</x>
46 <y>0</y> 37 <y>0</y>
47 <width>1280</width> 38 <width>1280</width>
48 <height>21</height> 39 <height>26</height>
49 </rect> 40 </rect>
50 </property> 41 </property>
51 <widget class="QMenu" name="menu_File"> 42 <widget class="QMenu" name="menu_File">
@@ -54,7 +45,7 @@
54 </property> 45 </property>
55 <widget class="QMenu" name="menu_recent_files"> 46 <widget class="QMenu" name="menu_recent_files">
56 <property name="title"> 47 <property name="title">
57 <string>Recent Files</string> 48 <string>&amp;Recent Files</string>
58 </property> 49 </property>
59 </widget> 50 </widget>
60 <addaction name="action_Install_File_NAND"/> 51 <addaction name="action_Install_File_NAND"/>
@@ -89,7 +80,7 @@
89 </property> 80 </property>
90 <widget class="QMenu" name="menu_View_Debugging"> 81 <widget class="QMenu" name="menu_View_Debugging">
91 <property name="title"> 82 <property name="title">
92 <string>Debugging</string> 83 <string>&amp;Debugging</string>
93 </property> 84 </property>
94 </widget> 85 </widget>
95 <addaction name="action_Fullscreen"/> 86 <addaction name="action_Fullscreen"/>
@@ -97,13 +88,14 @@
97 <addaction name="action_Display_Dock_Widget_Headers"/> 88 <addaction name="action_Display_Dock_Widget_Headers"/>
98 <addaction name="action_Show_Filter_Bar"/> 89 <addaction name="action_Show_Filter_Bar"/>
99 <addaction name="action_Show_Status_Bar"/> 90 <addaction name="action_Show_Status_Bar"/>
100 <addaction name="action_Reset_Window_Size"/> 91 <addaction name="action_Reset_Window_Size_720"/>
92 <addaction name="action_Reset_Window_Size_1080"/>
101 <addaction name="separator"/> 93 <addaction name="separator"/>
102 <addaction name="menu_View_Debugging"/> 94 <addaction name="menu_View_Debugging"/>
103 </widget> 95 </widget>
104 <widget class="QMenu" name="menu_Tools"> 96 <widget class="QMenu" name="menu_Tools">
105 <property name="title"> 97 <property name="title">
106 <string>Tools</string> 98 <string>&amp;Tools</string>
107 </property> 99 </property>
108 <addaction name="action_Rederive"/> 100 <addaction name="action_Rederive"/>
109 <addaction name="separator"/> 101 <addaction name="separator"/>
@@ -131,17 +123,17 @@
131 <bool>true</bool> 123 <bool>true</bool>
132 </property> 124 </property>
133 <property name="text"> 125 <property name="text">
134 <string>Install Files to NAND...</string> 126 <string>&amp;Install Files to NAND...</string>
135 </property> 127 </property>
136 </action> 128 </action>
137 <action name="action_Load_File"> 129 <action name="action_Load_File">
138 <property name="text"> 130 <property name="text">
139 <string>Load File...</string> 131 <string>L&amp;oad File...</string>
140 </property> 132 </property>
141 </action> 133 </action>
142 <action name="action_Load_Folder"> 134 <action name="action_Load_Folder">
143 <property name="text"> 135 <property name="text">
144 <string>Load Folder...</string> 136 <string>Load &amp;Folder...</string>
145 </property> 137 </property>
146 </action> 138 </action>
147 <action name="action_Exit"> 139 <action name="action_Exit">
@@ -175,12 +167,12 @@
175 </action> 167 </action>
176 <action name="action_Rederive"> 168 <action name="action_Rederive">
177 <property name="text"> 169 <property name="text">
178 <string>Reinitialize keys...</string> 170 <string>&amp;Reinitialize keys...</string>
179 </property> 171 </property>
180 </action> 172 </action>
181 <action name="action_About"> 173 <action name="action_About">
182 <property name="text"> 174 <property name="text">
183 <string>About yuzu</string> 175 <string>&amp;About yuzu</string>
184 </property> 176 </property>
185 </action> 177 </action>
186 <action name="action_Single_Window_Mode"> 178 <action name="action_Single_Window_Mode">
@@ -188,12 +180,12 @@
188 <bool>true</bool> 180 <bool>true</bool>
189 </property> 181 </property>
190 <property name="text"> 182 <property name="text">
191 <string>Single Window Mode</string> 183 <string>Single &amp;Window Mode</string>
192 </property> 184 </property>
193 </action> 185 </action>
194 <action name="action_Configure"> 186 <action name="action_Configure">
195 <property name="text"> 187 <property name="text">
196 <string>Configure...</string> 188 <string>Con&amp;figure...</string>
197 </property> 189 </property>
198 </action> 190 </action>
199 <action name="action_Display_Dock_Widget_Headers"> 191 <action name="action_Display_Dock_Widget_Headers">
@@ -201,7 +193,7 @@
201 <bool>true</bool> 193 <bool>true</bool>
202 </property> 194 </property>
203 <property name="text"> 195 <property name="text">
204 <string>Display Dock Widget Headers</string> 196 <string>Display D&amp;ock Widget Headers</string>
205 </property> 197 </property>
206 </action> 198 </action>
207 <action name="action_Show_Filter_Bar"> 199 <action name="action_Show_Filter_Bar">
@@ -209,7 +201,7 @@
209 <bool>true</bool> 201 <bool>true</bool>
210 </property> 202 </property>
211 <property name="text"> 203 <property name="text">
212 <string>Show Filter Bar</string> 204 <string>Show &amp;Filter Bar</string>
213 </property> 205 </property>
214 </action> 206 </action>
215 <action name="action_Show_Status_Bar"> 207 <action name="action_Show_Status_Bar">
@@ -217,12 +209,26 @@
217 <bool>true</bool> 209 <bool>true</bool>
218 </property> 210 </property>
219 <property name="text"> 211 <property name="text">
212 <string>Show &amp;Status Bar</string>
213 </property>
214 <property name="iconText">
220 <string>Show Status Bar</string> 215 <string>Show Status Bar</string>
221 </property> 216 </property>
222 </action> 217 </action>
223 <action name="action_Reset_Window_Size"> 218 <action name="action_Reset_Window_Size_720">
219 <property name="text">
220 <string>Reset Window Size to &amp;720p</string>
221 </property>
222 <property name="iconText">
223 <string>Reset Window Size to 720p</string>
224 </property>
225 </action>
226 <action name="action_Reset_Window_Size_1080">
224 <property name="text"> 227 <property name="text">
225 <string>Reset Window Size</string> 228 <string>Reset Window Size to &amp;1080p</string>
229 </property>
230 <property name="iconText">
231 <string>Reset Window Size to 1080p</string>
226 </property> 232 </property>
227 </action> 233 </action>
228 <action name="action_Fullscreen"> 234 <action name="action_Fullscreen">
@@ -230,7 +236,7 @@
230 <bool>true</bool> 236 <bool>true</bool>
231 </property> 237 </property>
232 <property name="text"> 238 <property name="text">
233 <string>Fullscreen</string> 239 <string>F&amp;ullscreen</string>
234 </property> 240 </property>
235 </action> 241 </action>
236 <action name="action_Restart"> 242 <action name="action_Restart">
@@ -238,7 +244,7 @@
238 <bool>false</bool> 244 <bool>false</bool>
239 </property> 245 </property>
240 <property name="text"> 246 <property name="text">
241 <string>Restart</string> 247 <string>&amp;Restart</string>
242 </property> 248 </property>
243 </action> 249 </action>
244 <action name="action_Load_Amiibo"> 250 <action name="action_Load_Amiibo">
@@ -246,7 +252,7 @@
246 <bool>false</bool> 252 <bool>false</bool>
247 </property> 253 </property>
248 <property name="text"> 254 <property name="text">
249 <string>Load Amiibo...</string> 255 <string>Load &amp;Amiibo...</string>
250 </property> 256 </property>
251 </action> 257 </action>
252 <action name="action_Report_Compatibility"> 258 <action name="action_Report_Compatibility">
@@ -254,7 +260,7 @@
254 <bool>false</bool> 260 <bool>false</bool>
255 </property> 261 </property>
256 <property name="text"> 262 <property name="text">
257 <string>Report Compatibility</string> 263 <string>&amp;Report Compatibility</string>
258 </property> 264 </property>
259 <property name="visible"> 265 <property name="visible">
260 <bool>false</bool> 266 <bool>false</bool>
@@ -262,22 +268,22 @@
262 </action> 268 </action>
263 <action name="action_Open_Mods_Page"> 269 <action name="action_Open_Mods_Page">
264 <property name="text"> 270 <property name="text">
265 <string>Open Mods Page</string> 271 <string>Open &amp;Mods Page</string>
266 </property> 272 </property>
267 </action> 273 </action>
268 <action name="action_Open_Quickstart_Guide"> 274 <action name="action_Open_Quickstart_Guide">
269 <property name="text"> 275 <property name="text">
270 <string>Open Quickstart Guide</string> 276 <string>Open &amp;Quickstart Guide</string>
271 </property> 277 </property>
272 </action> 278 </action>
273 <action name="action_Open_FAQ"> 279 <action name="action_Open_FAQ">
274 <property name="text"> 280 <property name="text">
275 <string>FAQ</string> 281 <string>&amp;FAQ</string>
276 </property> 282 </property>
277 </action> 283 </action>
278 <action name="action_Open_yuzu_Folder"> 284 <action name="action_Open_yuzu_Folder">
279 <property name="text"> 285 <property name="text">
280 <string>Open yuzu Folder</string> 286 <string>Open &amp;yuzu Folder</string>
281 </property> 287 </property>
282 </action> 288 </action>
283 <action name="action_Capture_Screenshot"> 289 <action name="action_Capture_Screenshot">
@@ -285,7 +291,7 @@
285 <bool>false</bool> 291 <bool>false</bool>
286 </property> 292 </property>
287 <property name="text"> 293 <property name="text">
288 <string>Capture Screenshot</string> 294 <string>&amp;Capture Screenshot</string>
289 </property> 295 </property>
290 </action> 296 </action>
291 <action name="action_Configure_Current_Game"> 297 <action name="action_Configure_Current_Game">
@@ -293,7 +299,7 @@
293 <bool>false</bool> 299 <bool>false</bool>
294 </property> 300 </property>
295 <property name="text"> 301 <property name="text">
296 <string>Configure Current Game...</string> 302 <string>Configure C&amp;urrent Game...</string>
297 </property> 303 </property>
298 </action> 304 </action>
299 </widget> 305 </widget>
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 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#ifdef YUZU_USE_QT_WEB_ENGINE
6
7#include "yuzu/util/url_request_interceptor.h"
8
9UrlRequestInterceptor::UrlRequestInterceptor(QObject* p) : QWebEngineUrlRequestInterceptor(p) {}
10
11UrlRequestInterceptor::~UrlRequestInterceptor() = default;
12
13void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) {
14 const auto resource_type = info.resourceType();
15
16 switch (resource_type) {
17 case QWebEngineUrlRequestInfo::ResourceTypeMainFrame:
18 requested_url = info.requestUrl();
19 emit FrameChanged();
20 break;
21 case QWebEngineUrlRequestInfo::ResourceTypeSubFrame:
22 case QWebEngineUrlRequestInfo::ResourceTypeXhr:
23 emit FrameChanged();
24 break;
25 }
26}
27
28QUrl UrlRequestInterceptor::GetRequestedURL() const {
29 return requested_url;
30}
31
32#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 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#ifdef YUZU_USE_QT_WEB_ENGINE
8
9#include <QObject>
10#include <QWebEngineUrlRequestInterceptor>
11
12class UrlRequestInterceptor : public QWebEngineUrlRequestInterceptor {
13 Q_OBJECT
14
15public:
16 explicit UrlRequestInterceptor(QObject* p = nullptr);
17 ~UrlRequestInterceptor() override;
18
19 void interceptRequest(QWebEngineUrlRequestInfo& info) override;
20
21 QUrl GetRequestedURL() const;
22
23signals:
24 void FrameChanged();
25
26private:
27 QUrl requested_url;
28};
29
30#endif