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 const char* const TIZEN_GET_WINDOW_HANDLE = "tizen://getWindowHandle";
37 const char* const TIZEN_CLEAR_ALL_COOKIES = "tizen://clearAllCookies";
39 std::string toString(WKStringRef str)
41 if (WKStringIsEmpty(str)) {
44 size_t size = WKStringGetMaximumUTF8CStringSize(str);
45 char buffer[size + 1];
46 WKStringGetUTF8CString(str, buffer, size + 1);
50 std::string sendSyncMessage(const char* name, const char* body)
52 WKStringRef nameWKString = WKStringCreateWithUTF8CString(name);
53 WKStringRef bodyWKString = NULL;
55 bodyWKString = WKStringCreateWithUTF8CString(body);
57 WKTypeRef retWKType = NULL;
58 WKBundlePostSynchronousMessage(s_injectedBundleRef,
62 WKRelease(nameWKString);
64 WKRelease(bodyWKString);
67 std::string retString = toString(static_cast<WKStringRef>(retWKType));
75 void sendAsyncMessage(const char* name, const char* body)
77 WKStringRef nameWKString = WKStringCreateWithUTF8CString(name);
78 WKStringRef bodyWKString = NULL;
80 bodyWKString = WKStringCreateWithUTF8CString(body);
82 WKTypeRef retWKType = NULL;
83 WKBundlePostMessage(s_injectedBundleRef,
86 WKRelease(nameWKString);
88 WKRelease(bodyWKString);
93 void IPCMessageSupport::setWKBundleRef(WKBundleRef bundleRef)
95 LogDebug("setWKBundleRef called");
96 s_injectedBundleRef = bundleRef;
99 void IPCMessageSupport::setXwindowHandle(unsigned int handle)
101 LogDebug("setXwindowHandle called");
102 s_xWindowHandle = handle;
105 const char* IPCMessageSupport::sendMessageToUiProcess(
109 LogDebug("sendMessageToUiProcess called");
110 if (s_injectedBundleRef == NULL) {
111 LogError("UI Process information isn't set");
114 LogDebug("name = [" << name << "]");
116 LogDebug("body = [" << body << "]");
123 // tizen://getWindowHandle
124 if (!strcmp(name, TIZEN_GET_WINDOW_HANDLE)) {
125 if (s_xWindowHandle == 0) {
128 std::stringstream ss;
129 ss << s_xWindowHandle;
130 std::string ret = ss.str();
131 return strdup(ret.c_str());
135 // tizen://clearAllCookies
136 if (!strcmp(name, TIZEN_CLEAR_ALL_COOKIES)) {
137 sendAsyncMessage(name, body);