From c70414114cb789101dc1df33d5c80ae5566e5283 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 26 May 2019 18:02:47 +0200 Subject: [PATCH] WebExtension: Native wrapper: replace TEMPFILE with file path, MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And return it. In preparation for a “View database” feature in the WebExtension. --- .../native-wrapper/CMakeLists.txt | 1 + .../native-wrapper/remwharead_wrapper.cpp | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/browser-plugins/webextension/native-wrapper/CMakeLists.txt b/browser-plugins/webextension/native-wrapper/CMakeLists.txt index df05c11..4186b55 100644 --- a/browser-plugins/webextension/native-wrapper/CMakeLists.txt +++ b/browser-plugins/webextension/native-wrapper/CMakeLists.txt @@ -4,6 +4,7 @@ set(INSTALL_MOZILLA_NMH_DIR "${CMAKE_INSTALL_PREFIX}/${MOZILLA_NMH_DIR}") add_executable(${PROJECT_NAME}_wrapper ${PROJECT_NAME}_wrapper.cpp) +target_link_libraries(${PROJECT_NAME}_wrapper stdc++fs) install(TARGETS ${PROJECT_NAME}_wrapper DESTINATION ${MOZILLA_NMH_DIR}) add_custom_command( diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp index 4a04478..06a53fa 100644 --- a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,8 @@ using std::cout; using std::uint32_t; using std::system; +namespace fs = std::experimental::filesystem; + const string read_input() { string input; @@ -75,12 +78,36 @@ int launch(const string &args) int main() { - const string args = read_input(); + string args = read_input(); + size_t pos = args.find("TEMPFILE"); + string tmpfile; + + if (pos != string::npos) + { + try + { + tmpfile = fs::temp_directory_path() / "remwharead.html"; + args.replace(pos, 8, tmpfile); + } + catch (const fs::filesystem_error &e) + { + send_message("Could not create temporary file."); + return 3; + } + } + int ret = launch(args); if (ret == 0) { - send_message("Command successful."); + if (!tmpfile.empty()) + { + send_message("FILE:" + tmpfile); + } + else + { + send_message("Command successful."); + } } else {