[Common] Add util.sendRuntimeMessage. Impl of app.exit and app.hide
authorKamil Lysik <k.lysik@samsung.com>
Fri, 20 Mar 2015 11:25:48 +0000 (12:25 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 24 Mar 2015 15:32:16 +0000 (00:32 +0900)
This commit introduces new messaging protocol to communicate
with runtime engine. Plugin may request runtime engine
to perform certain actions, like hide application or exit it.

This commit introduces mockup to make transition easier.

[Verification]
application.exit() should exit application.

Change-Id: Icbf733e28bffd85e2a18e1fab3c311fc7043d6f8
Signed-off-by: Kamil Lysik <k.lysik@samsung.com>
src/application/application_api.js
src/application/application_instance.cc
src/application/application_instance.h
src/utils/utils_api.js

index 28a659c2fed05044af5d84e8337662f51da03377..2b0ced02533f23738a27b6e0bfb91f0bb07187bf 100644 (file)
@@ -457,23 +457,11 @@ function Application() {
 }
 
 Application.prototype.exit = function() {
-  var nativeParam = {
-  };
-  try {
-    var syncResult = callNative('Application_exit', nativeParam);
-  } catch (e) {
-    throw e;
-  }
+  return native_.sendRuntimeMessage('Application_exit');
 };
 
 Application.prototype.hide = function() {
-  var nativeParam = {
-  };
-  try {
-    var syncResult = callNative('Application_hide', nativeParam);
-  } catch (e) {
-    throw e;
-  }
+  return native_.sendRuntimeMessage('Application_hide');
 };
 
 Application.prototype.getRequestedAppControl = function() {
index 6e74ba81e38f4f9a59aea1aec0b3804e6fc5f75e..6f330c1344b6f80d2a1eea19e48f17001991c5a1 100644 (file)
@@ -97,16 +97,12 @@ ApplicationInstance::ApplicationInstance(const std::string& app_id) {
     AppMgrGetAppsInfo);
   REGISTER_SYNC("ApplicationManager_launch",
     AppMgrLaunch);
-  REGISTER_SYNC("Application_hide",
-    AppHide);
   REGISTER_SYNC("ApplicationManager_getAppsContext",
     AppMgrGetAppsContext);
   REGISTER_SYNC("ApplicationManager_getAppContext",
     AppMgrGetAppContext);
   REGISTER_SYNC("RequestedApplicationControl_replyFailure",
     RequestedAppControlReplyFailure);
-  REGISTER_SYNC("Application_exit",
-    AppExit);
   REGISTER_SYNC("ApplicationManager_getCurrentApplication",
     AppMgrGetCurrentApplication);
   REGISTER_SYNC("ApplicationManager_findAppControl",
@@ -1794,30 +1790,6 @@ void ApplicationInstance::AppMgrRemoveAppInfoEventListener(
   ReportSuccess(out);
 }
 
-void ApplicationInstance::AppExit(const picojson::value& args,
-  picojson::object& out) {
-  LoggerD("Hide is called");
-
-  // webkit
-  // IPCSupport::Instance().Post(IPCMsg::MsgExitApp(), "" );
-  // Blink
-  //IPCMessageSupport::sendAsyncMessageToUiProcess(
-  //  IPCMessageSupport::TIZEN_EXIT, NULL, NULL, NULL);
-  ReportSuccess(out);
-}
-
-void ApplicationInstance::AppHide(const picojson::value& args,
-  picojson::object& out) {
-  LoggerD("Hide is called");
-
-  // webkit
-  // IPCSupport::Instance().Post(IPCMsg::MsgHideApp(), "" );
-  // Blink
-  //IPCMessageSupport::sendAsyncMessageToUiProcess(
-  //  IPCMessageSupport::TIZEN_HIDE, NULL, NULL, NULL);
-  ReportSuccess(out);
-}
-
 void ApplicationInstance::AppGetRequestedAppControl(
   const picojson::value& args, picojson::object& out) {
   std::string bundle_str =
index fe95917e60c047c31f44809a9c7fd28eff8a3f07..c1875e16505d080153d8271f8a952504f9dddca6 100644 (file)
@@ -62,8 +62,6 @@ class ApplicationInstance
     picojson::object& out);
   void AppMgrRemoveAppInfoEventListener(const picojson::value& args,
     picojson::object& out);
-  void AppExit(const picojson::value& args, picojson::object& out);
-  void AppHide(const picojson::value& args, picojson::object& out);
   void AppGetRequestedAppControl(const picojson::value& args,
     picojson::object& out);
   void RequestedAppControlReplyResult(const picojson::value& args,
index b3b811d61fd7569ba2bcd70d18198430a84fb7e1..eef5fdcb57a858aacb18de268012ce0e2a312c69 100644 (file)
@@ -792,10 +792,19 @@ var NativeManager = function(extension) {
 
   _validator.isConstructorCall(this, NativeManager);
 
+  // TODO: Remove mockup if WRT implements sendRuntimeMessage
+  // This is temporary mockup!
+  extension.sendRuntimeMessage = extension.sendRuntimeMessage || function(){
+    console.error("Runtime did not implement extension.sendRuntimeMessage!");
+    throw new WebAPIException(WebAPIException.UNKNOWN_ERR,
+      'Runtime did not implement extension.sendRuntimeMessage!');
+  }
+
   // check extension prototype
   if (!extension || !extension.internal ||
       !_type.isFunction(extension.postMessage) ||
       !_type.isFunction(extension.internal.sendSyncMessage) ||
+      !_type.isFunction(extension.sendRuntimeMessage) ||
       !_type.isFunction(extension.setMessageListener)) {
     throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
       'Wrong extension object passed');
@@ -873,6 +882,10 @@ NativeManager.prototype.callSync = function(cmd, args) {
   return JSON.parse(this.extension.internal.sendSyncMessage(request));
 };
 
+NativeManager.prototype.sendRuntimeMessage = function(cmd) {
+    return this.extension.sendRuntimeMessage(cmd);
+}
+
 NativeManager.prototype.addListener = function(name, callback) {
   if (!_type.isString(name) || !name.length) {
     throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR);