const char* const TIZEN_GET_WINDOW_HANDLE = "tizen://getWindowHandle";
const char* const TIZEN_CLEAR_ALL_COOKIES = "tizen://clearAllCookies";
-static std::string toString(WKStringRef str)
+std::string toString(WKStringRef str)
{
if (WKStringIsEmpty(str)) {
return std::string();
return buffer;
}
-static std::string sendSyncMessage(const char* name, const char* body)
+std::string sendSyncMessage(const char* name, const char* body)
{
WKStringRef nameWKString = WKStringCreateWithUTF8CString(name);
WKStringRef bodyWKString = NULL;
}
}
-static void sendPostMessage(const char* name, const char* body)
+void sendAsyncMessage(const char* name, const char* body)
{
WKStringRef nameWKString = WKStringCreateWithUTF8CString(name);
WKStringRef bodyWKString = NULL;
WKRelease(bodyWKString);
}
}
-
-static int sendAsyncMessage(const char* name, const char* body, AsyncReplyCallback replyCallback, void* data)
-{
- using namespace IPCMessageSupport;
-
- int handle = AsyncConnectionManager::instance().addConnection(AsyncConnectionPtr(new AsyncConnection(replyCallback, data)));
-
- std::string strBody = body;
- std::stringstream ss;
-
- ss << handle;
- strBody = ss.str() + "_" + strBody;
-
- sendPostMessage(name, strBody.c_str());
-
- return handle;
-}
-
-} // namespace
-
-
-namespace IPCMessageSupport {
-
-AsyncConnectionManager::~AsyncConnectionManager()
-{
- m_connectionMap.clear();
-}
-
-AsyncConnectionManager &AsyncConnectionManager::instance()
-{
- static AsyncConnectionManager instance;
-
- return instance;
-}
-
-int AsyncConnectionManager::addConnection(AsyncConnectionPtr connection)
-{
- static int latestHandle = -1;
- int newHandle;
-
- latestHandle++;
- if (latestHandle < 0) latestHandle = 0;
-
- newHandle = latestHandle;
-
- m_connectionMap.insert(AsyncConnectionMap::value_type(newHandle, connection));
-
- return newHandle;
-}
-
-bool AsyncConnectionManager::removeConnection(int handle)
-{
- bool ret = (m_connectionMap.erase(handle) == 1);
-
- return ret;
-}
-
-AsyncConnectionPtr AsyncConnectionManager::getConnection(int handle)
-{
- AsyncConnectionMap::iterator iter = m_connectionMap.find(handle);
-
- if (iter != m_connectionMap.end())
- {
- return iter->second;
- }
-
- return AsyncConnectionPtr();
}
-
-} // namespace IPCMessageSupport
-
-
void IPCMessageSupport::setWKBundleRef(WKBundleRef bundleRef)
{
LogDebug("setWKBundleRef called");
// tizen://clearAllCookies
if (!strcmp(name, TIZEN_CLEAR_ALL_COOKIES)) {
- sendPostMessage(name, body);
+ sendAsyncMessage(name, body);
return NULL;
}
return NULL;
}
-
-int IPCMessageSupport::sendAsyncMessageToUiProcess(const char* name, const char* body, AsyncReplyCallback replyCallback, void* data)
-{
- LogDebug("sendAsyncMessageToUiProcess called");
-
- if (s_injectedBundleRef == NULL)
- {
- LogError("UI Process information isn't set");
- return -1;
- }
-
- if (name == NULL)
- {
- LogError("msg name is null!");
- return -1;
- }
-
- if (body == NULL)
- {
- body = "";
- }
-
- LogDebug("name = [" << name << "]");
- LogDebug("body = [" << body << "]");
-
- return sendAsyncMessage(name, body, replyCallback, data);
-}
-
-void* IPCMessageSupport::ignoreAsyncMessageReply(int handle)
-{
- LogDebug("ignoreAsyncMessageReply called");
-
- AsyncConnectionPtr connection = AsyncConnectionManager::instance().getConnection(handle);
-
- if (!connection)
- {
- return NULL;
- }
-
- AsyncConnectionManager::instance().removeConnection(handle);
-
- return connection->data;
-}
-
-void IPCMessageSupport::replyAsyncMessageToWebProcess(Ewk_Context* ewkContext, int handle, const char* body)
-{
- LogDebug("replyAsyncMessageToWebProcess called");
-
- if (ewkContext == NULL)
- {
- return;
- }
-
- std::string strBody = (body) ? (body) : "";
- std::stringstream ss;
- ss << handle;
-
- strBody = ss.str() + "_" + strBody;
-
- ewk_context_message_post_to_injected_bundle(ewkContext, REPLY_ASYNC, strBody.c_str());
-}
#ifndef WRT_SRC_IPC_MESSAGE_SUPPORT
#define WRT_SRC_IPC_MESSAGE_SUPPORT
-#include <memory>
-#include <map>
#include <string>
#include <WKBundle.h>
-#include <EWebKit2.h>
-
-typedef void (*AsyncReplyCallback)(unsigned int, void*, const char*);
namespace IPCMessageSupport {
-
-static const char * const REPLY_ASYNC = "ToInjectedBundle::REPLY_ASYNC";
-static const char * const TIZEN_CHANGE_USERAGENT = "tizen://changeUA";
-static const char * const TIZEN_DELETE_ALL_COOKIES = "tizen://deleteAllCookies";
-
-class AsyncConnection
-{
- public:
- AsyncReplyCallback replyCallback;
- void* data;
-
- AsyncConnection(AsyncReplyCallback r, void* d) :
- replyCallback(r),
- data(d)
- {
- }
-};
-
-typedef std::shared_ptr<AsyncConnection> AsyncConnectionPtr;
-typedef std::map<unsigned int, AsyncConnectionPtr> AsyncConnectionMap;
-
-class AsyncConnectionManager
-{
- private:
- AsyncConnectionMap m_connectionMap;
-
- public:
- ~AsyncConnectionManager();
-
- // Singleton
- static AsyncConnectionManager &instance();
-
- int addConnection(AsyncConnectionPtr connection);
- bool removeConnection(int handle);
- AsyncConnectionPtr getConnection(int handle);
-
-};
-
void setWKBundleRef(WKBundleRef bundleRef);
void setXwindowHandle(unsigned int handle);
const char* sendMessageToUiProcess(const char* name, const char* body);
-int sendAsyncMessageToUiProcess(const char* name, const char* body, AsyncReplyCallback replyCallback, void* data);
-void* ignoreAsyncMessageReply(int handle);
-void replyAsyncMessageToWebProcess(Ewk_Context* ewkContext, int handle, const char* body);
}
#endif // WRT_SRC_IPC_MESSAGE_SUPPORT
\ No newline at end of file