2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-12-24 21:22:49 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-11-30 13:31:26 +00:00
|
|
|
#include <atomic>
|
2022-03-23 20:18:48 +00:00
|
|
|
#include <thread>
|
2020-11-30 13:31:26 +00:00
|
|
|
|
2018-12-24 21:22:49 +00:00
|
|
|
#include <QObject>
|
2018-12-28 23:20:29 +00:00
|
|
|
|
|
|
|
#ifdef YUZU_USE_QT_WEB_ENGINE
|
2018-12-24 21:22:49 +00:00
|
|
|
#include <QWebEngineView>
|
2018-12-28 23:20:29 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-24 21:22:49 +00:00
|
|
|
#include "core/frontend/applets/web_browser.h"
|
|
|
|
|
|
|
|
class GMainWindow;
|
2020-12-08 11:20:45 +00:00
|
|
|
class InputInterpreter;
|
2020-11-30 13:31:26 +00:00
|
|
|
class UrlRequestInterceptor;
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2021-10-24 06:02:56 +00:00
|
|
|
namespace Core::HID {
|
|
|
|
enum class NpadButton : u64;
|
|
|
|
}
|
|
|
|
|
2020-12-01 03:25:01 +00:00
|
|
|
namespace InputCommon {
|
|
|
|
class InputSubsystem;
|
|
|
|
}
|
|
|
|
|
2020-11-30 13:31:26 +00:00
|
|
|
#ifdef YUZU_USE_QT_WEB_ENGINE
|
|
|
|
|
|
|
|
enum class UserAgent {
|
|
|
|
WebApplet,
|
|
|
|
ShopN,
|
|
|
|
LoginApplet,
|
|
|
|
ShareApplet,
|
|
|
|
LobbyApplet,
|
|
|
|
WifiWebAuthApplet,
|
|
|
|
};
|
|
|
|
|
2020-12-08 11:20:45 +00:00
|
|
|
class QWebEngineProfile;
|
|
|
|
class QWebEngineSettings;
|
|
|
|
|
2020-11-30 13:31:26 +00:00
|
|
|
class QtNXWebEngineView : public QWebEngineView {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-12-01 03:25:01 +00:00
|
|
|
explicit QtNXWebEngineView(QWidget* parent, Core::System& system,
|
|
|
|
InputCommon::InputSubsystem* input_subsystem_);
|
2020-11-30 13:31:26 +00:00
|
|
|
~QtNXWebEngineView() override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a HTML document that exists locally. Cannot be used to load external websites.
|
|
|
|
*
|
|
|
|
* @param main_url The url to the file.
|
|
|
|
* @param additional_args Additional arguments appended to the main url.
|
|
|
|
*/
|
2021-04-28 15:32:44 +00:00
|
|
|
void LoadLocalWebPage(const std::string& main_url, const std::string& additional_args);
|
2020-11-30 13:31:26 +00:00
|
|
|
|
2020-12-08 11:20:45 +00:00
|
|
|
/**
|
|
|
|
* Loads an external website. Cannot be used to load local urls.
|
|
|
|
*
|
|
|
|
* @param main_url The url to the website.
|
|
|
|
* @param additional_args Additional arguments appended to the main url.
|
|
|
|
*/
|
2021-04-28 15:32:44 +00:00
|
|
|
void LoadExternalWebPage(const std::string& main_url, const std::string& additional_args);
|
2020-12-08 11:20:45 +00:00
|
|
|
|
2020-11-30 13:31:26 +00:00
|
|
|
/**
|
|
|
|
* Sets the background color of the web page.
|
|
|
|
*
|
|
|
|
* @param color The color to set.
|
|
|
|
*/
|
|
|
|
void SetBackgroundColor(QColor color);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the user agent of the web browser.
|
|
|
|
*
|
|
|
|
* @param user_agent The user agent enum.
|
|
|
|
*/
|
|
|
|
void SetUserAgent(UserAgent user_agent);
|
|
|
|
|
|
|
|
[[nodiscard]] bool IsFinished() const;
|
|
|
|
void SetFinished(bool finished_);
|
|
|
|
|
2020-11-30 15:15:00 +00:00
|
|
|
[[nodiscard]] Service::AM::Applets::WebExitReason GetExitReason() const;
|
|
|
|
void SetExitReason(Service::AM::Applets::WebExitReason exit_reason_);
|
2020-11-30 13:31:26 +00:00
|
|
|
|
|
|
|
[[nodiscard]] const std::string& GetLastURL() const;
|
|
|
|
void SetLastURL(std::string last_url_);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This gets the current URL that has been requested by the webpage.
|
|
|
|
* This only applies to the main frame. Sub frames and other resources are ignored.
|
|
|
|
*
|
|
|
|
* @return Currently requested URL
|
|
|
|
*/
|
|
|
|
[[nodiscard]] QString GetCurrentURL() const;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void hide();
|
|
|
|
|
2020-12-01 03:25:01 +00:00
|
|
|
protected:
|
|
|
|
void keyPressEvent(QKeyEvent* event) override;
|
|
|
|
void keyReleaseEvent(QKeyEvent* event) override;
|
|
|
|
|
2020-11-30 13:31:26 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Handles button presses to execute functions assigned in yuzu_key_callbacks.
|
|
|
|
* yuzu_key_callbacks contains specialized functions for the buttons in the window footer
|
2023-03-12 03:10:38 +00:00
|
|
|
* that can be overridden by games to achieve desired functionality.
|
2020-11-30 13:31:26 +00:00
|
|
|
*
|
|
|
|
* @tparam HIDButton The list of buttons contained in yuzu_key_callbacks
|
|
|
|
*/
|
2021-10-24 06:02:56 +00:00
|
|
|
template <Core::HID::NpadButton... T>
|
2020-11-30 13:31:26 +00:00
|
|
|
void HandleWindowFooterButtonPressedOnce();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles button presses and converts them into keyboard input.
|
|
|
|
* This should only be used to convert D-Pad or Analog Stick input into arrow keys.
|
|
|
|
*
|
|
|
|
* @tparam HIDButton The list of buttons that can be converted into keyboard input.
|
|
|
|
*/
|
2021-10-24 06:02:56 +00:00
|
|
|
template <Core::HID::NpadButton... T>
|
2020-11-30 13:31:26 +00:00
|
|
|
void HandleWindowKeyButtonPressedOnce();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles button holds and converts them into keyboard input.
|
|
|
|
* This should only be used to convert D-Pad or Analog Stick input into arrow keys.
|
|
|
|
*
|
|
|
|
* @tparam HIDButton The list of buttons that can be converted into keyboard input.
|
|
|
|
*/
|
2021-10-24 06:02:56 +00:00
|
|
|
template <Core::HID::NpadButton... T>
|
2020-11-30 13:31:26 +00:00
|
|
|
void HandleWindowKeyButtonHold();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a key press event to QWebEngineView.
|
|
|
|
*
|
|
|
|
* @param key Qt key code.
|
|
|
|
*/
|
|
|
|
void SendKeyPressEvent(int key);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends multiple key press events to QWebEngineView.
|
|
|
|
*
|
|
|
|
* @tparam int Qt key code.
|
|
|
|
*/
|
|
|
|
template <int... T>
|
|
|
|
void SendMultipleKeyPressEvents() {
|
|
|
|
(SendKeyPressEvent(T), ...);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartInputThread();
|
|
|
|
void StopInputThread();
|
|
|
|
|
|
|
|
/// The thread where input is being polled and processed.
|
|
|
|
void InputThread();
|
|
|
|
|
2020-12-08 11:20:45 +00:00
|
|
|
/// Loads the extracted fonts using JavaScript.
|
|
|
|
void LoadExtractedFonts();
|
|
|
|
|
2021-07-17 23:10:15 +00:00
|
|
|
/// Brings focus to the first available link element.
|
|
|
|
void FocusFirstLinkElement();
|
|
|
|
|
2020-12-01 03:25:01 +00:00
|
|
|
InputCommon::InputSubsystem* input_subsystem;
|
|
|
|
|
2020-11-30 13:31:26 +00:00
|
|
|
std::unique_ptr<UrlRequestInterceptor> url_interceptor;
|
|
|
|
|
|
|
|
std::unique_ptr<InputInterpreter> input_interpreter;
|
|
|
|
|
|
|
|
std::thread input_thread;
|
|
|
|
|
|
|
|
std::atomic<bool> input_thread_running{};
|
|
|
|
|
|
|
|
std::atomic<bool> finished{};
|
|
|
|
|
2020-11-30 15:15:00 +00:00
|
|
|
Service::AM::Applets::WebExitReason exit_reason{
|
|
|
|
Service::AM::Applets::WebExitReason::EndButtonPressed};
|
2020-11-30 13:31:26 +00:00
|
|
|
|
|
|
|
std::string last_url{"http://localhost/"};
|
2020-12-08 11:20:45 +00:00
|
|
|
|
|
|
|
bool is_local{};
|
|
|
|
|
|
|
|
QWebEngineProfile* default_profile;
|
|
|
|
QWebEngineSettings* global_settings;
|
2020-11-30 13:31:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2018-12-24 21:22:49 +00:00
|
|
|
|
|
|
|
class QtWebBrowser final : public QObject, public Core::Frontend::WebBrowserApplet {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-11-30 13:31:26 +00:00
|
|
|
explicit QtWebBrowser(GMainWindow& parent);
|
2018-12-24 21:22:49 +00:00
|
|
|
~QtWebBrowser() override;
|
2020-11-30 13:31:26 +00:00
|
|
|
|
2021-04-28 15:32:44 +00:00
|
|
|
void OpenLocalWebPage(const std::string& local_url,
|
2022-12-05 23:46:57 +00:00
|
|
|
ExtractROMFSCallback extract_romfs_callback_,
|
|
|
|
OpenWebPageCallback callback_) const override;
|
2020-12-08 11:20:45 +00:00
|
|
|
|
2021-04-28 15:32:44 +00:00
|
|
|
void OpenExternalWebPage(const std::string& external_url,
|
2022-12-05 23:46:57 +00:00
|
|
|
OpenWebPageCallback callback_) const override;
|
2020-11-30 13:31:26 +00:00
|
|
|
|
|
|
|
signals:
|
2021-04-28 15:32:44 +00:00
|
|
|
void MainWindowOpenWebPage(const std::string& main_url, const std::string& additional_args,
|
2020-12-08 11:20:45 +00:00
|
|
|
bool is_local) const;
|
2020-11-30 13:31:26 +00:00
|
|
|
|
|
|
|
private:
|
2020-11-30 15:15:00 +00:00
|
|
|
void MainWindowExtractOfflineRomFS();
|
2020-11-30 13:31:26 +00:00
|
|
|
|
2020-11-30 15:15:00 +00:00
|
|
|
void MainWindowWebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason,
|
|
|
|
std::string last_url);
|
|
|
|
|
2022-12-05 23:46:57 +00:00
|
|
|
mutable ExtractROMFSCallback extract_romfs_callback;
|
|
|
|
mutable OpenWebPageCallback callback;
|
2018-12-24 21:22:49 +00:00
|
|
|
};
|