summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-12-24 16:22:49 -0500
committerGravatar Zach Hilman2018-12-28 15:32:39 -0500
commite00e1fc755501018c4106e8453045037d5b9e3ee (patch)
treee2d19db87e63e2e873a492f5b35f0b6db15933e6 /src
parentcore: Add getter and setter for WebBrowserApplet frontend (diff)
downloadyuzu-e00e1fc755501018c4106e8453045037d5b9e3ee.tar.gz
yuzu-e00e1fc755501018c4106e8453045037d5b9e3ee.tar.xz
yuzu-e00e1fc755501018c4106e8453045037d5b9e3ee.zip
qt: Implement Qt frontend to web browser
Using a custom reimplementation of QWebEngineView and an injector script.
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/applets/web_browser.cpp109
-rw-r--r--src/yuzu/applets/web_browser.h45
2 files changed, 154 insertions, 0 deletions
diff --git a/src/yuzu/applets/web_browser.cpp b/src/yuzu/applets/web_browser.cpp
new file mode 100644
index 000000000..e1a34bb5f
--- /dev/null
+++ b/src/yuzu/applets/web_browser.cpp
@@ -0,0 +1,109 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <mutex>
6
7#include <QKeyEvent>
8
9#include "core/hle/lock.h"
10#include "yuzu/applets/web_browser.h"
11#include "yuzu/main.h"
12
13constexpr char NX_SHIM_INJECT_SCRIPT[] = R"(
14 window.nx = {};
15 window.nx.playReport = {};
16 window.nx.playReport.setCounterSetIdentifier = function () {
17 console.log("nx.footer.setCounterSetIdentifier called - unimplemented");
18 };
19
20 window.nx.playReport.incrementCounter = function () {
21 console.log("nx.footer.incrementCounter called - unimplemented");
22 };
23
24 window.nx.footer = {};
25 window.nx.footer.unsetAssign = function () {
26 console.log("nx.footer.unsetAssign called - unimplemented");
27 };
28
29 var yuzu_key_callbacks = [];
30 window.nx.footer.setAssign = function(key, discard1, func, discard2) {
31 switch (key) {
32 case 'A':
33 yuzu_key_callbacks[0] = func;
34 break;
35 case 'B':
36 yuzu_key_callbacks[1] = func;
37 break;
38 case 'X':
39 yuzu_key_callbacks[2] = func;
40 break;
41 case 'Y':
42 yuzu_key_callbacks[3] = func;
43 break;
44 case 'L':
45 yuzu_key_callbacks[6] = func;
46 break;
47 case 'R':
48 yuzu_key_callbacks[7] = func;
49 break;
50 }
51 };
52
53 var applet_done = false;
54 window.nx.endApplet = function() {
55 applet_done = true;
56 };
57)";
58
59void NXInputWebEngineView::keyPressEvent(QKeyEvent* event) {
60 parent()->event(event);
61}
62
63void NXInputWebEngineView::keyReleaseEvent(QKeyEvent* event) {
64 parent()->event(event);
65}
66
67QString GetNXShimInjectionScript() {
68 return QString::fromStdString(NX_SHIM_INJECT_SCRIPT);
69}
70
71NXInputWebEngineView::NXInputWebEngineView(QWidget* parent) : QWebEngineView(parent) {}
72
73QtWebBrowser::QtWebBrowser(GMainWindow& main_window) {
74 connect(this, &QtWebBrowser::MainWindowOpenPage, &main_window, &GMainWindow::WebBrowserOpenPage,
75 Qt::QueuedConnection);
76 connect(&main_window, &GMainWindow::WebBrowserUnpackRomFS, this,
77 &QtWebBrowser::MainWindowUnpackRomFS, Qt::QueuedConnection);
78 connect(&main_window, &GMainWindow::WebBrowserFinishedBrowsing, this,
79 &QtWebBrowser::MainWindowFinishedBrowsing, Qt::QueuedConnection);
80}
81
82QtWebBrowser::~QtWebBrowser() = default;
83
84void QtWebBrowser::OpenPage(std::string_view url, std::function<void()> unpack_romfs_callback,
85 std::function<void()> finished_callback) const {
86 this->unpack_romfs_callback = unpack_romfs_callback;
87 this->finished_callback = finished_callback;
88
89 const auto index = url.find('?');
90 if (index == std::string::npos) {
91 emit MainWindowOpenPage(url, "");
92 } else {
93 const auto front = url.substr(0, index);
94 const auto back = url.substr(index);
95 emit MainWindowOpenPage(front, back);
96 }
97}
98
99void QtWebBrowser::MainWindowUnpackRomFS() {
100 // Acquire the HLE mutex
101 std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
102 unpack_romfs_callback();
103}
104
105void QtWebBrowser::MainWindowFinishedBrowsing() {
106 // Acquire the HLE mutex
107 std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
108 finished_callback();
109}
diff --git a/src/yuzu/applets/web_browser.h b/src/yuzu/applets/web_browser.h
new file mode 100644
index 000000000..74f6698be
--- /dev/null
+++ b/src/yuzu/applets/web_browser.h
@@ -0,0 +1,45 @@
1// Copyright 2018 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 <functional>
8#include <QObject>
9#include <QWebEngineView>
10#include "core/frontend/applets/web_browser.h"
11
12class GMainWindow;
13
14QString GetNXShimInjectionScript();
15
16class NXInputWebEngineView : public QWebEngineView {
17public:
18 NXInputWebEngineView(QWidget* parent = nullptr);
19
20protected:
21 void keyPressEvent(QKeyEvent* event) override;
22 void keyReleaseEvent(QKeyEvent* event) override;
23};
24
25class QtWebBrowser final : public QObject, public Core::Frontend::WebBrowserApplet {
26 Q_OBJECT
27
28public:
29 explicit QtWebBrowser(GMainWindow& main_window);
30 ~QtWebBrowser() override;
31
32 void OpenPage(std::string_view url, std::function<void()> unpack_romfs_callback,
33 std::function<void()> finished_callback) const override;
34
35signals:
36 void MainWindowOpenPage(std::string_view filename, std::string_view additional_args) const;
37
38public slots:
39 void MainWindowUnpackRomFS();
40 void MainWindowFinishedBrowsing();
41
42private:
43 mutable std::function<void()> unpack_romfs_callback;
44 mutable std::function<void()> finished_callback;
45};