summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/copynpaste.cpp18
-rw-r--r--src/utils/process.cpp74
-rw-r--r--src/utils/process.h12
3 files changed, 99 insertions, 5 deletions
diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp
index 1f88d8abf..45729021e 100644
--- a/src/utils/copynpaste.cpp
+++ b/src/utils/copynpaste.cpp
@@ -470,6 +470,24 @@ static bool runxsel(std::string& text, const char *p1, const char *p2)
return true;
}
+#elif defined __native_client__
+
+#include "utils/process.h"
+
+bool retrieveBuffer(std::string& text, size_t& pos)
+{
+ NaclMessageHandle *handle = naclRegisterMessageHandler("clipboard-paste");
+ naclPostMessage("clipboard-paste", "");
+ std::string response = naclWaitForMessage(handle);
+ text.insert(pos, response);
+ return true;
+}
+
+bool sendBuffer(std::string& text)
+{
+ naclPostMessage("clipboard-copy", text);
+ return true;
+}
#else
bool retrieveBuffer(std::string&, size_t&)
{
diff --git a/src/utils/process.cpp b/src/utils/process.cpp
index 74ac20b53..d3d154270 100644
--- a/src/utils/process.cpp
+++ b/src/utils/process.cpp
@@ -269,13 +269,9 @@ bool openBrowser(std::string url)
return execFile("/usr/bin/xdg-open", "/usr/bin/xdg-open", url, "");
}
#elif defined __native_client__
-#include <ppapi_simple/ps.h>
-#include <ppapi/cpp/instance.h>
-#include <ppapi/cpp/var.h>
bool openBrowser(std::string url)
{
- pp::Var msgVar = pp::Var(std::string("open-browser: ").append(url));
- pp::Instance(PSGetInstanceId()).PostMessage(msgVar);
+ naclPostMessage("open-browser", url);
return true;
}
#else
@@ -300,3 +296,71 @@ void setPriority(const bool big A_UNUSED)
{
}
#endif
+
+#ifdef __native_client__
+#include <ppapi_simple/ps.h>
+#include <ppapi_simple/ps_event.h>
+#include <ppapi/cpp/instance.h>
+#include <ppapi/cpp/var.h>
+
+#include <mutex>
+#include <condition_variable>
+
+struct _NaclMessageHandle {
+ bool handled;
+ std::string type;
+ std::string message;
+ std::condition_variable condv;
+};
+
+void naclPostMessage(const std::string &type, const std::string &message)
+{
+ pp::Var msgVar = pp::Var(std::string(type).append(":").append(message));
+ pp::Instance(PSGetInstanceId()).PostMessage(msgVar);
+}
+
+void naclMessageHandlerFunc(struct PP_Var key,
+ struct PP_Var value,
+ void* user_data)
+{
+ NaclMessageHandle *handle = (NaclMessageHandle *)user_data;
+
+ if (key.type != PP_VARTYPE_STRING || value.type != PP_VARTYPE_STRING)
+ return;
+ if (pp::Var(key).AsString() != handle->type)
+ return;
+
+ handle->handled = true;
+ handle->message = pp::Var(value).AsString();
+
+ handle->condv.notify_one();
+}
+
+NaclMessageHandle *naclRegisterMessageHandler(const std::string &type)
+{
+ NaclMessageHandle *handle = new NaclMessageHandle;
+ handle->handled = false;
+ handle->type = type;
+
+ PSEventRegisterMessageHandler(type.c_str(), naclMessageHandlerFunc, (void *)handle);
+ return handle;
+}
+
+void naclUnregisterMessageHandler(NaclMessageHandle *handle)
+{
+ PSEventRegisterMessageHandler(handle->type.c_str(), NULL, NULL);
+ delete handle;
+}
+
+std::string naclWaitForMessage(NaclMessageHandle *handle)
+{
+ std::mutex mtx;
+ std::unique_lock <std::mutex> lck(mtx);
+
+ while (!handle->handled)
+ handle->condv.wait(lck);
+
+ handle->handled = false;
+ return handle->message;
+}
+#endif
diff --git a/src/utils/process.h b/src/utils/process.h
index 5ceddd032..44c1d2286 100644
--- a/src/utils/process.h
+++ b/src/utils/process.h
@@ -34,4 +34,16 @@ bool openBrowser(std::string url);
void setPriority(const bool big);
+#ifdef __native_client__
+
+typedef struct _NaclMessageHandle NaclMessageHandle;
+
+void naclPostMessage(const std::string &type, const std::string &message);
+
+NaclMessageHandle *naclRegisterMessageHandler(const std::string &type);
+void naclUnregisterMessageHandler(NaclMessageHandle *handle);
+std::string naclWaitForMessage(NaclMessageHandle *handle);
+
+#endif
+
#endif // UTILS_PROCESS_H