2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file ipc_message_support.cpp
18 * @author Jihoon Chung (jihoon.chung@samsung.com)
20 * @brief Implementation of IPC between plugins and UI Process
22 #include "ipc_message_support.h"
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
32 static WKBundleRef s_injectedBundleRef = NULL;
33 static unsigned int s_xWindowHandle = 0;
36 std::string toString(WKStringRef str)
38 if (WKStringIsEmpty(str)) {
41 size_t size = WKStringGetMaximumUTF8CStringSize(str);
42 char buffer[size + 1];
43 WKStringGetUTF8CString(str, buffer, size + 1);
48 void IPCMessageSupport::setWKBundleRef(WKBundleRef bundleRef)
50 LogDebug("setWKBundleRef called");
51 s_injectedBundleRef = bundleRef;
54 void IPCMessageSupport::setXwindowHandle(unsigned int handle)
56 LogDebug("setXwindowHandle called");
57 s_xWindowHandle = handle;
60 const char* IPCMessageSupport::sendMessageToUiProcess(
64 LogDebug("sendMessageToUiProcess called");
65 if (s_injectedBundleRef == NULL) {
66 LogError("UI Process information isn't set");
69 LogDebug("name = [" << name << "]");
71 LogDebug("body = [" << body << "]");
78 if (!strcmp(name, "tizen://getWindowHandle")) {
79 if (s_xWindowHandle == 0) {
83 ss << s_xWindowHandle;
84 std::string ret = ss.str();
85 return strdup(ret.c_str());
89 WKStringRef bodyWKString = NULL;
90 WKStringRef nameWKString = WKStringCreateWithUTF8CString(name);
92 bodyWKString = WKStringCreateWithUTF8CString(body);
94 WKTypeRef retWKType = NULL;
95 WKBundlePostSynchronousMessage(s_injectedBundleRef,
99 WKRelease(nameWKString);
101 WKRelease(bodyWKString);
104 std::string retString = toString(static_cast<WKStringRef>(retWKType));
105 WKRelease(retWKType);
106 return strdup(retString.c_str());