diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/frontend/applets/web_browser.cpp | 5 | ||||
-rw-r--r-- | src/core/frontend/applets/web_browser.h | 11 | ||||
-rw-r--r-- | src/core/hle/service/am/applets/web_browser.cpp | 66 | ||||
-rw-r--r-- | src/core/hle/service/am/applets/web_browser.h | 10 |
4 files changed, 52 insertions, 40 deletions
diff --git a/src/core/frontend/applets/web_browser.cpp b/src/core/frontend/applets/web_browser.cpp index 0e1612e27..a5d8f82ac 100644 --- a/src/core/frontend/applets/web_browser.cpp +++ b/src/core/frontend/applets/web_browser.cpp @@ -12,11 +12,12 @@ WebBrowserApplet::~WebBrowserApplet() = default; DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default; void DefaultWebBrowserApplet::OpenLocalWebPage( - std::string_view local_url, std::function<void(WebExitReason, std::string)> callback) const { + std::string_view local_url, std::function<void()> extract_romfs_callback, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const { LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open local web page at {}", local_url); - callback(WebExitReason::WindowClosed, "http://localhost/"); + callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/"); } } // namespace Core::Frontend diff --git a/src/core/frontend/applets/web_browser.h b/src/core/frontend/applets/web_browser.h index 2ccefc68f..5b0629cfb 100644 --- a/src/core/frontend/applets/web_browser.h +++ b/src/core/frontend/applets/web_browser.h @@ -9,8 +9,6 @@ #include "core/hle/service/am/applets/web_types.h" -using namespace Service::AM::Applets; - namespace Core::Frontend { class WebBrowserApplet { @@ -18,16 +16,17 @@ public: virtual ~WebBrowserApplet(); virtual void OpenLocalWebPage( - std::string_view local_url, - std::function<void(WebExitReason, std::string)> callback) const = 0; + std::string_view local_url, std::function<void()> extract_romfs_callback, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0; }; class DefaultWebBrowserApplet final : public WebBrowserApplet { public: ~DefaultWebBrowserApplet() override; - void OpenLocalWebPage(std::string_view local_url, - std::function<void(WebExitReason, std::string)> callback) const override; + void OpenLocalWebPage(std::string_view local_url, std::function<void()> extract_romfs_callback, + std::function<void(Service::AM::Applets::WebExitReason, std::string)> + callback) const override; }; } // namespace Core::Frontend diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp index 02ce9f387..9c8be156f 100644 --- a/src/core/hle/service/am/applets/web_browser.cpp +++ b/src/core/hle/service/am/applets/web_browser.cpp @@ -15,7 +15,6 @@ #include "core/file_sys/registered_cache.h" #include "core/file_sys/romfs.h" #include "core/file_sys/system_archive/system_archive.h" -#include "core/file_sys/vfs_types.h" #include "core/file_sys/vfs_vector.h" #include "core/frontend/applets/web_browser.h" #include "core/hle/kernel/process.h" @@ -311,6 +310,18 @@ void WebBrowser::Execute() { } } +void WebBrowser::ExtractOfflineRomFS() { + LOG_DEBUG(Service_AM, "Extracting RomFS to {}", offline_cache_dir); + + const auto extracted_romfs_dir = + FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard); + + const auto temp_dir = + system.GetFilesystem()->CreateDirectory(offline_cache_dir, FileSys::Mode::ReadWrite); + + FileSys::VfsRawCopyD(extracted_romfs_dir, temp_dir); +} + void WebBrowser::WebBrowserExit(WebExitReason exit_reason, std::string last_url) { if ((web_arg_header.shim_kind == ShimKind::Share && web_applet_version >= WebAppletVersion::Version196608) || @@ -360,12 +371,11 @@ void WebBrowser::InitializeOffline() { const auto document_kind = ParseRawValue<DocumentKind>(GetInputTLVData(WebArgInputTLVType::DocumentKind).value()); - u64 title_id{}; - FileSys::ContentRecordType nca_type{FileSys::ContentRecordType::HtmlDocument}; std::string additional_paths; switch (document_kind) { case DocumentKind::OfflineHtmlPage: + default: title_id = system.CurrentProcess()->GetTitleID(); nca_type = FileSys::ContentRecordType::HtmlDocument; additional_paths = "html-document"; @@ -395,31 +405,6 @@ void WebBrowser::InitializeOffline() { offline_document = Common::FS::SanitizePath( fmt::format("{}/{}/{}", offline_cache_dir, additional_paths, document_path), Common::FS::DirectorySeparator::PlatformDefault); - - const auto main_url = Common::FS::SanitizePath(GetMainURL(offline_document), - Common::FS::DirectorySeparator::PlatformDefault); - - if (Common::FS::Exists(main_url)) { - return; - } - - auto offline_romfs = GetOfflineRomFS(system, title_id, nca_type); - - if (offline_romfs == nullptr) { - LOG_ERROR(Service_AM, "RomFS with title_id={:016X} and nca_type={} cannot be extracted!", - title_id, nca_type); - return; - } - - LOG_DEBUG(Service_AM, "Extracting RomFS to {}", offline_cache_dir); - - const auto extracted_romfs_dir = - FileSys::ExtractRomFS(offline_romfs, FileSys::RomFSExtractionType::SingleDiscard); - - const auto temp_dir = - system.GetFilesystem()->CreateDirectory(offline_cache_dir, FileSys::Mode::ReadWrite); - - FileSys::VfsRawCopyD(extracted_romfs_dir, temp_dir); } void WebBrowser::InitializeShare() {} @@ -441,11 +426,28 @@ void WebBrowser::ExecuteLogin() { } void WebBrowser::ExecuteOffline() { + const auto main_url = Common::FS::SanitizePath(GetMainURL(offline_document), + Common::FS::DirectorySeparator::PlatformDefault); + + if (!Common::FS::Exists(main_url)) { + offline_romfs = GetOfflineRomFS(system, title_id, nca_type); + + if (offline_romfs == nullptr) { + LOG_ERROR(Service_AM, + "RomFS with title_id={:016X} and nca_type={} cannot be extracted!", title_id, + nca_type); + WebBrowserExit(WebExitReason::WindowClosed); + return; + } + } + LOG_INFO(Service_AM, "Opening offline document at {}", offline_document); - frontend.OpenLocalWebPage(offline_document, - [this](WebExitReason exit_reason, std::string last_url) { - WebBrowserExit(exit_reason, last_url); - }); + + frontend.OpenLocalWebPage( + offline_document, [this] { ExtractOfflineRomFS(); }, + [this](WebExitReason exit_reason, std::string last_url) { + WebBrowserExit(exit_reason, last_url); + }); } void WebBrowser::ExecuteShare() { diff --git a/src/core/hle/service/am/applets/web_browser.h b/src/core/hle/service/am/applets/web_browser.h index c36c717f1..936a49a86 100644 --- a/src/core/hle/service/am/applets/web_browser.h +++ b/src/core/hle/service/am/applets/web_browser.h @@ -8,6 +8,7 @@ #include "common/common_funcs.h" #include "common/common_types.h" +#include "core/file_sys/vfs_types.h" #include "core/hle/result.h" #include "core/hle/service/am/applets/applets.h" #include "core/hle/service/am/applets/web_types.h" @@ -16,6 +17,10 @@ namespace Core { class System; } +namespace FileSys { +enum class ContentRecordType : u8; +} + namespace Service::AM::Applets { class WebBrowser final : public Applet { @@ -31,6 +36,8 @@ public: void ExecuteInteractive() override; void Execute() override; + void ExtractOfflineRomFS(); + void WebBrowserExit(WebExitReason exit_reason, std::string last_url = ""); private: @@ -66,8 +73,11 @@ private: WebArgHeader web_arg_header; WebArgInputTLVMap web_arg_input_tlv_map; + u64 title_id; + FileSys::ContentRecordType nca_type; std::string offline_cache_dir; std::string offline_document; + FileSys::VirtualFile offline_romfs; Core::System& system; }; |