Implement IPC between plugins and UI Process
authorJihoon Chung <jihoon.chung@samsung.com>
Sat, 27 Apr 2013 05:24:08 +0000 (14:24 +0900)
committerGerrit Code Review <gerrit2@kim11>
Sat, 4 May 2013 06:01:24 +0000 (15:01 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] Support ipc between plugins and UI Process.
Before use ipc API, injected-bundle must call "setWKBundleRef" to set
WKBundleRef which is used send message to UI Process.
Plugin part call "sendMessageToUiProcess" with message name and body.
Current implementation only support sync message call.
[SCMRequest] N/A

Change-Id: Iad720c69cccf04b473b7e3fca97e8a6ecab7eb5f

CMakeLists.txt
pkgconfigs/wrt-plugins-ipc-message.pc.in [new file with mode: 0644]
src/CMakeLists.txt
src/plugins-ipc-message/CMakeLists.txt [new file with mode: 0644]
src/plugins-ipc-message/ipc_message_support.cpp [new file with mode: 0644]
src/plugins-ipc-message/ipc_message_support.h [new file with mode: 0644]

index 6d2eeb9..12ec039 100644 (file)
@@ -34,7 +34,8 @@ include_directories(
   ${CMAKE_CURRENT_SOURCE_DIR}/src/CommonsJavaScript
   ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-loading
   ${CMAKE_CURRENT_SOURCE_DIR}/src/js-overlay
-  ${CMAKE_CURRENT_SOURCE_DIR}/src/wrt-popup/ace/popup-runner)
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/wrt-popup/ace/popup-runner
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/plugins_ipc_message)
 
 ##############################################################################
 # Build type
@@ -151,6 +152,7 @@ configure_and_install_pkg(wrt-popup-runner.pc)
 configure_and_install_pkg(wrt-popup-ace-runner.pc)
 configure_and_install_pkg(wrt-popup-wrt-runner.pc)
 configure_and_install_pkg(wrt-plugins-api-support.pc)
+configure_and_install_pkg(wrt-plugins-ipc-message.pc)
 
 ################################################################################
 # Cache
diff --git a/pkgconfigs/wrt-plugins-ipc-message.pc.in b/pkgconfigs/wrt-plugins-ipc-message.pc.in
new file mode 100644 (file)
index 0000000..8088720
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=/usr
+project_name=@CMAKE_PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: wrt ipc message support
+Description: Support IPC between plugins and UI Process
+Version: @CMAKE_PROJECT_VERSION@
+Requires: dpl-efl ewebkit2
+Libs: -L${libdir} -lwrt-plugins-ipc-message
+Cflags: -I${includedir}
index 9c0d041..259b2da 100644 (file)
@@ -45,9 +45,11 @@ SET(TARGET_POPUP_ACE_RUNNER_LIB "wrt-popup-ace-runner")
 SET(TARGET_POPUP_WRT "wrt-popup-wrt-runtime")
 SET(TARGET_POPUP_WRT_RUNNER_LIB "wrt-popup-wrt-runner")
 set(TARGET_PLUGINS_API_SUPPORT "wrt-plugins-api-support")
+set(TARGET_PLUGINS_IPC_MESSAGE_LIB "wrt-plugins-ipc-message")
 
 set(PLUGIN_LOADING_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/plugin-loading)
 set(PLUGINS_API_SUPPORT_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/plugins-api-support)
+set(PLUGINS_IPC_MESSAGE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/plugins-ipc-message)
 
 add_subdirectory(plugins-api-support)
 add_subdirectory(plugin-loading)
@@ -58,3 +60,4 @@ add_subdirectory(modules)
 add_subdirectory(standards)
 add_subdirectory(wrt-popup)
 add_subdirectory(plugins-installer)
+add_subdirectory(plugins-ipc-message)
diff --git a/src/plugins-ipc-message/CMakeLists.txt b/src/plugins-ipc-message/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d3da03e
--- /dev/null
@@ -0,0 +1,60 @@
+# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+
+# @file     CMakeLists.txt
+# @author   Jihoon Chung (jihoon.chung@samsung.com)
+# @version  1.0
+#
+
+pkg_search_module(dpl REQUIRED dpl-efl)
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+
+set(PLUGINS_IPC_MESSAGE_SOURCES
+    ${PLUGINS_IPC_MESSAGE_DIRS}/ipc_message_support.cpp
+)
+
+INCLUDE_DIRECTORIES(
+    ${PLUGINS_IPC_MESSAGE_DIRS}
+    ${webkit2_INCLUDE_DIRS}
+)
+
+ADD_LIBRARY(${TARGET_PLUGINS_IPC_MESSAGE_LIB} SHARED
+    ${PLUGINS_IPC_MESSAGE_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGINS_IPC_MESSAGE_LIB} PROPERTIES
+    COMPILE_FLAGS -fPIC
+    LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGINS_IPC_MESSAGE_LIB} PROPERTIES
+    SOVERSION ${CMAKE_PROJECT_API_VERSION}
+    VERSION ${CMAKE_PROJECT_VERSION}
+)
+
+target_link_libraries(${TARGET_PLUGINS_IPC_MESSAGE_LIB}
+    ${dpl_LIBRARIES}
+    ${webkit2_LIBRARIES}
+)
+
+INSTALL(TARGETS ${TARGET_PLUGINS_IPC_MESSAGE_LIB}
+    DESTINATION lib
+    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+    GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+)
+
+INSTALL(FILES
+    ipc_message_support.h
+    DESTINATION include/plugins-ipc-message)
diff --git a/src/plugins-ipc-message/ipc_message_support.cpp b/src/plugins-ipc-message/ipc_message_support.cpp
new file mode 100644 (file)
index 0000000..db1e8a8
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file        ipc_message_support.cpp
+ * @author      Jihoon Chung (jihoon.chung@samsung.com)
+ * @version     1.0
+ * @brief       Implementation of IPC between plugins and UI Process
+ */
+#include "ipc_message_support.h"
+
+#include <string>
+#include <sstream>
+#include <WKBundle.h>
+#include <WKString.h>
+#include <WKType.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+
+static WKBundleRef s_injectedBundleRef = NULL;
+
+namespace {
+std::string toString(WKStringRef str)
+{
+    if (WKStringIsEmpty(str)) {
+        return std::string();
+    }
+    size_t size = WKStringGetMaximumUTF8CStringSize(str);
+    char buffer[size + 1];
+    WKStringGetUTF8CString(str, buffer, size + 1);
+    return buffer;
+}
+}
+
+void IPCMessageSupport::setWKBundleRef(WKBundleRef bundleRef)
+{
+    LogDebug("setWKBundleRef called");
+    s_injectedBundleRef = bundleRef;
+}
+
+const char* IPCMessageSupport::sendMessageToUiProcess(
+    const char* name,
+    const char* body)
+{
+    LogDebug("sendMessageToUiProcess called");
+    if (s_injectedBundleRef == NULL) {
+        LogError("UI Process information isn't set");
+        return NULL;
+    }
+    LogDebug("name = [" << name << "]");
+    LogDebug("body = [" << body << "]");
+
+    if (!name) {
+        return NULL;
+    }
+    WKStringRef bodyWKString = NULL;
+    WKStringRef nameWKString = WKStringCreateWithUTF8CString(name);
+    if (body) {
+        bodyWKString = WKStringCreateWithUTF8CString(body);
+    }
+    WKTypeRef retWKType = NULL;
+    WKBundlePostSynchronousMessage(s_injectedBundleRef,
+                                   nameWKString,
+                                   bodyWKString,
+                                   &retWKType);
+    WKRelease(nameWKString);
+    if (bodyWKString) {
+        WKRelease(bodyWKString);
+    }
+    std::string retString = toString(static_cast<WKStringRef>(retWKType));
+    WKRelease(retWKType);
+
+    return strdup(retString.c_str());
+}
diff --git a/src/plugins-ipc-message/ipc_message_support.h b/src/plugins-ipc-message/ipc_message_support.h
new file mode 100644 (file)
index 0000000..0bde70a
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file        ipc_message_support.h
+ * @author      Jihoon Chung (jihoon.chung@samsung.com)
+ * @version     1.0
+ * @brief       Implementation of IPC between plugins and UI Process
+ */
+#ifndef WRT_SRC_IPC_MESSAGE_SUPPORT
+#define WRT_SRC_IPC_MESSAGE_SUPPORT
+
+#include <string>
+#include <WKBundle.h>
+
+namespace IPCMessageSupport {
+void setWKBundleRef(WKBundleRef bundleRef);
+const char* sendMessageToUiProcess(const char* name, const char* body);
+}
+
+#endif // WRT_SRC_IPC_MESSAGE_SUPPORT
\ No newline at end of file