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;
35 std::string toString(WKStringRef str)
37 if (WKStringIsEmpty(str)) {
40 size_t size = WKStringGetMaximumUTF8CStringSize(str);
41 char buffer[size + 1];
42 WKStringGetUTF8CString(str, buffer, size + 1);
47 void IPCMessageSupport::setWKBundleRef(WKBundleRef bundleRef)
49 LogDebug("setWKBundleRef called");
50 s_injectedBundleRef = bundleRef;
53 const char* IPCMessageSupport::sendMessageToUiProcess(
57 LogDebug("sendMessageToUiProcess called");
58 if (s_injectedBundleRef == NULL) {
59 LogError("UI Process information isn't set");
62 LogDebug("name = [" << name << "]");
63 LogDebug("body = [" << body << "]");
68 WKStringRef bodyWKString = NULL;
69 WKStringRef nameWKString = WKStringCreateWithUTF8CString(name);
71 bodyWKString = WKStringCreateWithUTF8CString(body);
73 WKTypeRef retWKType = NULL;
74 WKBundlePostSynchronousMessage(s_injectedBundleRef,
78 WKRelease(nameWKString);
80 WKRelease(bodyWKString);
82 std::string retString = toString(static_cast<WKStringRef>(retWKType));
85 return strdup(retString.c_str());