diff options
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/hle/service/am/am.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/web_browser.cpp | 184 | ||||
| -rw-r--r-- | src/core/hle/service/am/applets/web_browser.h | 44 |
4 files changed, 234 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index f38271336..82c934f7e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -172,6 +172,8 @@ add_library(core STATIC | |||
| 172 | hle/service/am/applets/software_keyboard.h | 172 | hle/service/am/applets/software_keyboard.h |
| 173 | hle/service/am/applets/stub_applet.cpp | 173 | hle/service/am/applets/stub_applet.cpp |
| 174 | hle/service/am/applets/stub_applet.h | 174 | hle/service/am/applets/stub_applet.h |
| 175 | hle/service/am/applets/web_browser.cpp | ||
| 176 | hle/service/am/applets/web_browser.h | ||
| 175 | hle/service/am/idle.cpp | 177 | hle/service/am/idle.cpp |
| 176 | hle/service/am/idle.h | 178 | hle/service/am/idle.h |
| 177 | hle/service/am/omm.cpp | 179 | hle/service/am/omm.cpp |
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 512386422..c851e5420 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "core/hle/service/am/applets/profile_select.h" | 23 | #include "core/hle/service/am/applets/profile_select.h" |
| 24 | #include "core/hle/service/am/applets/software_keyboard.h" | 24 | #include "core/hle/service/am/applets/software_keyboard.h" |
| 25 | #include "core/hle/service/am/applets/stub_applet.h" | 25 | #include "core/hle/service/am/applets/stub_applet.h" |
| 26 | #include "core/hle/service/am/applets/web_browser.h" | ||
| 26 | #include "core/hle/service/am/idle.h" | 27 | #include "core/hle/service/am/idle.h" |
| 27 | #include "core/hle/service/am/omm.h" | 28 | #include "core/hle/service/am/omm.h" |
| 28 | #include "core/hle/service/am/spsm.h" | 29 | #include "core/hle/service/am/spsm.h" |
| @@ -43,6 +44,7 @@ constexpr ResultCode ERR_SIZE_OUT_OF_BOUNDS{ErrorModule::AM, 0x1F7}; | |||
| 43 | enum class AppletId : u32 { | 44 | enum class AppletId : u32 { |
| 44 | ProfileSelect = 0x10, | 45 | ProfileSelect = 0x10, |
| 45 | SoftwareKeyboard = 0x11, | 46 | SoftwareKeyboard = 0x11, |
| 47 | LibAppletOff = 0x17, | ||
| 46 | }; | 48 | }; |
| 47 | 49 | ||
| 48 | constexpr u32 POP_LAUNCH_PARAMETER_MAGIC = 0xC79497CA; | 50 | constexpr u32 POP_LAUNCH_PARAMETER_MAGIC = 0xC79497CA; |
| @@ -782,6 +784,8 @@ static std::shared_ptr<Applets::Applet> GetAppletFromId(AppletId id) { | |||
| 782 | return std::make_shared<Applets::ProfileSelect>(); | 784 | return std::make_shared<Applets::ProfileSelect>(); |
| 783 | case AppletId::SoftwareKeyboard: | 785 | case AppletId::SoftwareKeyboard: |
| 784 | return std::make_shared<Applets::SoftwareKeyboard>(); | 786 | return std::make_shared<Applets::SoftwareKeyboard>(); |
| 787 | case AppletId::LibAppletOff: | ||
| 788 | return std::make_shared<Applets::WebBrowser>(); | ||
| 785 | default: | 789 | default: |
| 786 | LOG_ERROR(Service_AM, "Unimplemented AppletId [{:08X}]! -- Falling back to stub!", | 790 | LOG_ERROR(Service_AM, "Unimplemented AppletId [{:08X}]! -- Falling back to stub!", |
| 787 | static_cast<u32>(id)); | 791 | static_cast<u32>(id)); |
diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp new file mode 100644 index 000000000..53118324b --- /dev/null +++ b/src/core/hle/service/am/applets/web_browser.cpp | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_paths.h" | ||
| 6 | #include "common/hex_util.h" | ||
| 7 | #include "common/logging/backend.h" | ||
| 8 | #include "common/string_util.h" | ||
| 9 | #include "core/core.h" | ||
| 10 | #include "core/file_sys/content_archive.h" | ||
| 11 | #include "core/file_sys/mode.h" | ||
| 12 | #include "core/file_sys/nca_metadata.h" | ||
| 13 | #include "core/file_sys/registered_cache.h" | ||
| 14 | #include "core/file_sys/romfs.h" | ||
| 15 | #include "core/file_sys/romfs_factory.h" | ||
| 16 | #include "core/file_sys/vfs_types.h" | ||
| 17 | #include "core/frontend/applets/web_browser.h" | ||
| 18 | #include "core/hle/kernel/process.h" | ||
| 19 | #include "core/hle/service/am/applets/web_browser.h" | ||
| 20 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 21 | #include "core/loader/loader.h" | ||
| 22 | |||
| 23 | namespace Service::AM::Applets { | ||
| 24 | |||
| 25 | // TODO(DarkLordZach): There are other arguments in the WebBuffer structure that are currently not | ||
| 26 | // parsed, for example footer mode and left stick mode. Some of these are not particularly relevant, | ||
| 27 | // but some may be worth an implementation. | ||
| 28 | constexpr u16 WEB_ARGUMENT_URL_TYPE = 0x6; | ||
| 29 | |||
| 30 | struct WebBufferHeader { | ||
| 31 | u16 count; | ||
| 32 | INSERT_PADDING_BYTES(6); | ||
| 33 | }; | ||
| 34 | static_assert(sizeof(WebBufferHeader) == 0x8, "WebBufferHeader has incorrect size."); | ||
| 35 | |||
| 36 | struct WebArgumentHeader { | ||
| 37 | u16 type; | ||
| 38 | u16 size; | ||
| 39 | u32 offset; | ||
| 40 | }; | ||
| 41 | static_assert(sizeof(WebArgumentHeader) == 0x8, "WebArgumentHeader has incorrect size."); | ||
| 42 | |||
| 43 | struct WebArgumentResult { | ||
| 44 | u32 result_code; | ||
| 45 | std::array<char, 0x1000> last_url; | ||
| 46 | u64 last_url_size; | ||
| 47 | }; | ||
| 48 | static_assert(sizeof(WebArgumentResult) == 0x1010, "WebArgumentResult has incorrect size."); | ||
| 49 | |||
| 50 | static std::vector<u8> GetArgumentDataForTagType(const std::vector<u8>& data, u16 type) { | ||
| 51 | WebBufferHeader header; | ||
| 52 | std::memcpy(&header, data.data(), sizeof(WebBufferHeader)); | ||
| 53 | |||
| 54 | u64 offset = sizeof(WebBufferHeader); | ||
| 55 | for (u16 i = 0; i < header.count; ++i) { | ||
| 56 | WebArgumentHeader arg; | ||
| 57 | std::memcpy(&arg, data.data() + offset, sizeof(WebArgumentHeader)); | ||
| 58 | offset += sizeof(WebArgumentHeader); | ||
| 59 | |||
| 60 | if (arg.type == type) { | ||
| 61 | std::vector<u8> out(arg.size); | ||
| 62 | offset += arg.offset; | ||
| 63 | std::memcpy(out.data(), data.data() + offset, out.size()); | ||
| 64 | return out; | ||
| 65 | } | ||
| 66 | |||
| 67 | offset += arg.offset + arg.size; | ||
| 68 | } | ||
| 69 | |||
| 70 | return {}; | ||
| 71 | } | ||
| 72 | |||
| 73 | static FileSys::VirtualFile GetManualRomFS() { | ||
| 74 | auto& loader{Core::System::GetInstance().GetAppLoader()}; | ||
| 75 | |||
| 76 | FileSys::VirtualFile out; | ||
| 77 | if (loader.ReadManualRomFS(out) == Loader::ResultStatus::Success) | ||
| 78 | return out; | ||
| 79 | |||
| 80 | const auto& installed{FileSystem::GetUnionContents()}; | ||
| 81 | const auto res = installed.GetEntry(Core::System::GetInstance().CurrentProcess()->GetTitleID(), | ||
| 82 | FileSys::ContentRecordType::Manual); | ||
| 83 | |||
| 84 | if (res != nullptr) | ||
| 85 | return res->GetRomFS(); | ||
| 86 | return nullptr; | ||
| 87 | } | ||
| 88 | |||
| 89 | WebBrowser::WebBrowser() = default; | ||
| 90 | |||
| 91 | WebBrowser::~WebBrowser() = default; | ||
| 92 | |||
| 93 | void WebBrowser::Initialize() { | ||
| 94 | complete = false; | ||
| 95 | temporary_dir.clear(); | ||
| 96 | filename.clear(); | ||
| 97 | status = RESULT_SUCCESS; | ||
| 98 | |||
| 99 | Applet::Initialize(); | ||
| 100 | |||
| 101 | const auto web_arg_storage = broker.PopNormalDataToApplet(); | ||
| 102 | ASSERT(web_arg_storage != nullptr); | ||
| 103 | const auto& web_arg = web_arg_storage->GetData(); | ||
| 104 | |||
| 105 | LOG_CRITICAL(Service_AM, "{}", Common::HexVectorToString(web_arg)); | ||
| 106 | |||
| 107 | const auto url_data = GetArgumentDataForTagType(web_arg, WEB_ARGUMENT_URL_TYPE); | ||
| 108 | filename = Common::StringFromFixedZeroTerminatedBuffer( | ||
| 109 | reinterpret_cast<const char*>(url_data.data()), url_data.size()); | ||
| 110 | |||
| 111 | temporary_dir = FileUtil::SanitizePath(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + | ||
| 112 | "web_applet_manual", | ||
| 113 | FileUtil::DirectorySeparator::PlatformDefault); | ||
| 114 | FileUtil::DeleteDirRecursively(temporary_dir); | ||
| 115 | |||
| 116 | manual_romfs = GetManualRomFS(); | ||
| 117 | if (manual_romfs == nullptr) { | ||
| 118 | status = ResultCode(-1); | ||
| 119 | LOG_ERROR(Service_AM, "Failed to find manual for current process!"); | ||
| 120 | } | ||
| 121 | |||
| 122 | filename = | ||
| 123 | FileUtil::SanitizePath(temporary_dir + DIR_SEP + "html-document" + DIR_SEP + filename, | ||
| 124 | FileUtil::DirectorySeparator::PlatformDefault); | ||
| 125 | } | ||
| 126 | |||
| 127 | bool WebBrowser::TransactionComplete() const { | ||
| 128 | return complete; | ||
| 129 | } | ||
| 130 | |||
| 131 | ResultCode WebBrowser::GetStatus() const { | ||
| 132 | return status; | ||
| 133 | } | ||
| 134 | |||
| 135 | void WebBrowser::ExecuteInteractive() { | ||
| 136 | UNIMPLEMENTED_MSG(Service_AM, "Unexpected interactive data recieved!"); | ||
| 137 | } | ||
| 138 | |||
| 139 | void WebBrowser::Execute() { | ||
| 140 | if (complete) | ||
| 141 | return; | ||
| 142 | |||
| 143 | if (status != RESULT_SUCCESS) { | ||
| 144 | complete = true; | ||
| 145 | return; | ||
| 146 | } | ||
| 147 | |||
| 148 | const auto& frontend{Core::System::GetInstance().GetWebBrowser()}; | ||
| 149 | |||
| 150 | frontend.OpenPage( | ||
| 151 | filename, [this] { UnpackRomFS(); }, [this] { Finalize(); }); | ||
| 152 | } | ||
| 153 | |||
| 154 | void WebBrowser::UnpackRomFS() { | ||
| 155 | if (unpacked) | ||
| 156 | return; | ||
| 157 | |||
| 158 | ASSERT(manual_romfs != nullptr); | ||
| 159 | const auto dir = | ||
| 160 | FileSys::ExtractRomFS(manual_romfs, FileSys::RomFSExtractionType::SingleDiscard); | ||
| 161 | const auto& vfs{Core::System::GetInstance().GetFilesystem()}; | ||
| 162 | const auto temp_dir = vfs->CreateDirectory(temporary_dir, FileSys::Mode::ReadWrite); | ||
| 163 | FileSys::VfsRawCopyD(dir, temp_dir); | ||
| 164 | |||
| 165 | unpacked = true; | ||
| 166 | } | ||
| 167 | |||
| 168 | void WebBrowser::Finalize() { | ||
| 169 | complete = true; | ||
| 170 | |||
| 171 | WebArgumentResult out{}; | ||
| 172 | out.result_code = 0; | ||
| 173 | out.last_url_size = 0; | ||
| 174 | |||
| 175 | std::vector<u8> data(sizeof(WebArgumentResult)); | ||
| 176 | std::memcpy(data.data(), &out, sizeof(WebArgumentResult)); | ||
| 177 | |||
| 178 | broker.PushNormalDataFromApplet(IStorage{data}); | ||
| 179 | broker.SignalStateChanged(); | ||
| 180 | |||
| 181 | FileUtil::DeleteDirRecursively(temporary_dir); | ||
| 182 | } | ||
| 183 | |||
| 184 | } // 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 new file mode 100644 index 000000000..b9e228fac --- /dev/null +++ b/src/core/hle/service/am/applets/web_browser.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/file_sys/vfs_types.h" | ||
| 8 | #include "core/hle/service/am/am.h" | ||
| 9 | #include "core/hle/service/am/applets/applets.h" | ||
| 10 | |||
| 11 | namespace Service::AM::Applets { | ||
| 12 | |||
| 13 | class WebBrowser final : public Applet { | ||
| 14 | public: | ||
| 15 | WebBrowser(); | ||
| 16 | ~WebBrowser() override; | ||
| 17 | |||
| 18 | void Initialize() override; | ||
| 19 | |||
| 20 | bool TransactionComplete() const override; | ||
| 21 | ResultCode GetStatus() const override; | ||
| 22 | void ExecuteInteractive() override; | ||
| 23 | void Execute() override; | ||
| 24 | |||
| 25 | // Callback to be fired when the frontend needs the manual RomFS unpacked to temporary | ||
| 26 | // directory. This is a blocking call and may take a while as some manuals can be up to 100MB in | ||
| 27 | // size. Attempting to access files at filename before invocation is likely to not work. | ||
| 28 | void UnpackRomFS(); | ||
| 29 | |||
| 30 | // Callback to be fired when the frontend is finished browsing. This will delete the temporary | ||
| 31 | // manual RomFS extracted files, so ensure this is only called at actual finalization. | ||
| 32 | void Finalize(); | ||
| 33 | |||
| 34 | private: | ||
| 35 | bool complete = false; | ||
| 36 | bool unpacked = false; | ||
| 37 | ResultCode status = RESULT_SUCCESS; | ||
| 38 | |||
| 39 | FileSys::VirtualFile manual_romfs; | ||
| 40 | std::string temporary_dir; | ||
| 41 | std::string filename; | ||
| 42 | }; | ||
| 43 | |||
| 44 | } // namespace Service::AM::Applets | ||