diff options
| author | 2018-12-24 16:22:49 -0500 | |
|---|---|---|
| committer | 2018-12-28 15:32:39 -0500 | |
| commit | e00e1fc755501018c4106e8453045037d5b9e3ee (patch) | |
| tree | e2d19db87e63e2e873a492f5b35f0b6db15933e6 /src | |
| parent | core: Add getter and setter for WebBrowserApplet frontend (diff) | |
| download | yuzu-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.cpp | 109 | ||||
| -rw-r--r-- | src/yuzu/applets/web_browser.h | 45 |
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 | |||
| 13 | constexpr 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 | |||
| 59 | void NXInputWebEngineView::keyPressEvent(QKeyEvent* event) { | ||
| 60 | parent()->event(event); | ||
| 61 | } | ||
| 62 | |||
| 63 | void NXInputWebEngineView::keyReleaseEvent(QKeyEvent* event) { | ||
| 64 | parent()->event(event); | ||
| 65 | } | ||
| 66 | |||
| 67 | QString GetNXShimInjectionScript() { | ||
| 68 | return QString::fromStdString(NX_SHIM_INJECT_SCRIPT); | ||
| 69 | } | ||
| 70 | |||
| 71 | NXInputWebEngineView::NXInputWebEngineView(QWidget* parent) : QWebEngineView(parent) {} | ||
| 72 | |||
| 73 | QtWebBrowser::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 | |||
| 82 | QtWebBrowser::~QtWebBrowser() = default; | ||
| 83 | |||
| 84 | void 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 | |||
| 99 | void 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 | |||
| 105 | void 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 | |||
| 12 | class GMainWindow; | ||
| 13 | |||
| 14 | QString GetNXShimInjectionScript(); | ||
| 15 | |||
| 16 | class NXInputWebEngineView : public QWebEngineView { | ||
| 17 | public: | ||
| 18 | NXInputWebEngineView(QWidget* parent = nullptr); | ||
| 19 | |||
| 20 | protected: | ||
| 21 | void keyPressEvent(QKeyEvent* event) override; | ||
| 22 | void keyReleaseEvent(QKeyEvent* event) override; | ||
| 23 | }; | ||
| 24 | |||
| 25 | class QtWebBrowser final : public QObject, public Core::Frontend::WebBrowserApplet { | ||
| 26 | Q_OBJECT | ||
| 27 | |||
| 28 | public: | ||
| 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 | |||
| 35 | signals: | ||
| 36 | void MainWindowOpenPage(std::string_view filename, std::string_view additional_args) const; | ||
| 37 | |||
| 38 | public slots: | ||
| 39 | void MainWindowUnpackRomFS(); | ||
| 40 | void MainWindowFinishedBrowsing(); | ||
| 41 | |||
| 42 | private: | ||
| 43 | mutable std::function<void()> unpack_romfs_callback; | ||
| 44 | mutable std::function<void()> finished_callback; | ||
| 45 | }; | ||