[Engine] Add interface to fire custom js event for Tizen Webapp
authorYunchan Cho <yunchan.cho@samsung.com>
Thu, 1 Nov 2012 09:11:24 +0000 (18:11 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Thu, 15 Nov 2012 07:03:57 +0000 (16:03 +0900)
[Issue#] There is needs that wrt provides interface to fire some custom events
[Feature] N/A
[Cause] N/A
[Solution] add new functions to RunnableWidgetObject for firing event
           and modify that plugin module of wrt requests to plugin logic of wrt-plugins-common for many custom events

Change-Id: I9db6cc54e7c462f83067b7c1cf2779a88f1d2d18

14 files changed:
src/api_new/i_runnable_widget_object.h
src/api_new/runnable_widget_object.cpp
src/api_new/runnable_widget_object.h
src/api_new/runnable_widget_object_state.cpp
src/api_new/runnable_widget_object_state.h
src/plugin-service/wrt_plugin_module.cpp
src/plugin-service/wrt_plugin_module.h
src/view/i_view_module.h
src/view/webkit/bundles/plugin_module_support.cpp
src/view/webkit/bundles/plugin_module_support.h
src/view/webkit/bundles/wrt-wk2-bundle.cpp
src/view/webkit/view_logic.cpp
src/view/webkit/view_logic.h
src/wrt-client/CMakeLists.txt

index 26dd362..99164a3 100644 (file)
@@ -157,6 +157,11 @@ public:
     virtual void Backward() = 0;
     virtual void Reload() = 0;
     virtual void Forward() = 0;
+    /**
+     * fire custom javascript event
+     */
+    virtual void FireJavascriptEvent(int event, void* data) = 0;
+
 
     virtual ~IRunnableWidgetObject() {};
 };
index 51749b9..ec5f385 100644 (file)
@@ -262,6 +262,14 @@ void RunnableWidgetObject::Forward() {
     change.commit();
 }
 
+void RunnableWidgetObject::FireJavascriptEvent(int event, void* data)
+{
+    State::StateChange change = m_guardstate->allowFireJavascriptEvent();
+    m_view->fireJavascriptEvent(event, data);
+
+    change.commit();
+}
+
 void RunnableWidgetObject::setNewState(std::shared_ptr<State::RunnableWidgetObjectState> sptr)
 {
     LogInfo("RunnableWidgetObject changes state to: " << sptr->toString());
index 84ba1e5..e35952f 100644 (file)
@@ -62,6 +62,7 @@ public:
     void Backward();
     void Reload();
     void Forward();
+    void FireJavascriptEvent(int event, void* data);
 
 private:
 
index 86deb2c..bb1990f 100644 (file)
@@ -132,6 +132,12 @@ StateChange RunnableWidgetObjectState::allowReload()
              "Reload cannot be called in current state ");
 }
 
+StateChange RunnableWidgetObjectState::allowFireJavascriptEvent()
+{
+    ThrowMsg(IRunnableWidgetObject::MethodInvocationForbidden,
+             "FireJavascriptEvent cannot be called in current state ");
+}
+
 InitialState::InitialState(RunnableWidgetObject & object) : RunnableWidgetObjectState(object)
 {
 }
@@ -225,6 +231,11 @@ StateChange ShowedState::allowReset()
     return StateChange::NoChange;
 }
 
+StateChange ShowedState::allowFireJavascriptEvent()
+{
+    return StateChange::NoChange;
+}
+
 SuspendedState::SuspendedState(RunnableWidgetObject & object) : RunnableWidgetObjectState(object)
 {
 }
index 16af46a..3a246d3 100644 (file)
@@ -89,6 +89,7 @@ public:
     virtual StateChange allowBackward();
     virtual StateChange allowForward();
     virtual StateChange allowReload();
+    virtual StateChange allowFireJavascriptEvent();
 
     virtual std::string toString() const = 0;
     virtual RunnableWidgetObject & getObject() const;
@@ -150,6 +151,7 @@ public:
     StateChange allowForward();
     StateChange allowReload();
     StateChange allowReset();
+    StateChange allowFireJavascriptEvent();
 };
 
 /**
index cda29b3..7260dd9 100644 (file)
@@ -76,11 +76,13 @@ void setCustomProperties(JSGlobalContextRef context,
 }
 
 void dispatchJavaScriptEvent(JSGlobalContextRef context,
-                             WrtPlugins::W3C::CustomEventType eventType)
+                             WrtPlugins::W3C::CustomEventType eventType,
+                             void* data)
 {
     LogDebug("dispatching javascript event");
     PluginLogicSingleton::Instance().dispatchJavaScriptEvent(context,
-                                                             eventType);
+                                                             eventType,
+                                                             data);
 }
 
 void loadFrame(JSGlobalContextRef context)
index c5b013e..f4a1b0e 100644 (file)
@@ -46,7 +46,8 @@ void setCustomProperties(JSGlobalContextRef context,
                          const char* encodedBundle,
                          const char* theme);
 void dispatchJavaScriptEvent(JSGlobalContextRef context,
-                             WrtPlugins::W3C::CustomEventType eventType);
+                             WrtPlugins::W3C::CustomEventType eventType,
+                             void* data);
 void loadFrame(JSGlobalContextRef context);
 void unloadFrame(JSGlobalContextRef context);
 } // PluginModule
index 676e7fa..f4f6d7a 100644 (file)
@@ -54,6 +54,7 @@ public:
     virtual void forward() = 0;
     virtual void reloadStartPage() = 0;
     virtual Evas_Object* getCurrentWebview() = 0;
+    virtual void fireJavascriptEvent(int event, void* data) = 0;
     virtual void setUserCallbacks(const WRT::UserDelegatesPtr& cbs) = 0;
 };
 
index 4eba0df..6abfc93 100644 (file)
@@ -121,13 +121,17 @@ void setCustomProperties(
 
 void dispatchJavaScriptEvent(
         Ewk_Context* ewkContext,
-        WrtPlugins::W3C::CustomEventType eventType)
+        WrtPlugins::W3C::CustomEventType eventType,
+        void *data)
 {
+    using namespace WrtPlugins::W3C;
     std::stringstream str;
     str << eventType;
 
-    std::string msgString = str.str();
+    // if needed, arguments for event should be set here
+    // do something
 
+    std::string msgString = str.str();
     const char* msg = msgString.c_str();
     const char* name = BundleMessages::DISPATCH_JAVASCRIPT_EVENT;
 
index 23cf7bc..d90720b 100644 (file)
@@ -41,7 +41,8 @@ void setCustomProperties(
         const char* theme = NULL);
 void dispatchJavaScriptEvent(
         Ewk_Context* ewkContext,
-        WrtPlugins::W3C::CustomEventType eventType);
+        WrtPlugins::W3C::CustomEventType eventType,
+        void* data);
 } // namespace PluginModuleSupport
 
 #endif /* WRT_SRC_VIEW_WEBKIT2_PLUGIN_MODULE_SUPPORT_H_ */
index 2e3ad76..a61e1e9 100644 (file)
@@ -64,6 +64,8 @@
 #include <scheme_action_map_type.h>
 #include <scheme_action_map_data.h>
 
+#include <js_overlay_types.h>
+
 // URI localization on WebProcess side
 #include "bundle_uri_handling.h"
 
@@ -380,16 +382,25 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
         // set information from ui process
         auto text = toString(static_cast<WKStringRef>(messageBody));
         int eventType;
+        void *args = NULL;
         std::stringstream ss(text);
         ss >> eventType;
 
+        // set arguments to be sent to js handler of this custom event
+        // do something
+
         //apply for each context
         PageGlobalContext::iterator it = m_pageGlobalContext.begin();
         for (; it != m_pageGlobalContext.end(); ++it)
         {
             PluginModule::dispatchJavaScriptEvent(
                     it->second,
-                    static_cast<WrtPlugins::W3C::CustomEventType>(eventType));
+                    static_cast<WrtPlugins::W3C::CustomEventType>(eventType),
+                    args);
+        }
+
+        if (args) {
+            delete args;
         }
     }
 }
index 9369480..0eb14c9 100644 (file)
@@ -290,7 +290,8 @@ void ViewLogic::resetWidget()
             // dispatch 'appservice' js event
             PluginModuleSupport::dispatchJavaScriptEvent(
                 m_ewkContext,
-                WrtPlugins::W3C::ServiceCustomEvent);
+                WrtPlugins::W3C::ServiceCustomEvent,
+                NULL);
             ewk_view_reload(m_currentEwkView);
         } else {
             m_currentUri = DPL::ToUTF8String(*servicedUri);
@@ -388,6 +389,14 @@ Evas_Object* ViewLogic::getCurrentWebview()
     return m_currentEwkView;
 }
 
+void ViewLogic::fireJavascriptEvent(int event, void* data)
+{
+    PluginModuleSupport::dispatchJavaScriptEvent(
+        m_ewkContext,
+        static_cast<WrtPlugins::W3C::CustomEventType>(event),
+        data);
+}
+
 void ViewLogic::setUserCallbacks(const WRT::UserDelegatesPtr& cbs)
 {
     m_cbs = cbs;
@@ -989,11 +998,18 @@ void ViewLogic::loadFinishedCallback(
         This->m_cbs->loadFinish(true);
     }
 
+    // set only encoded bundle
+    double scale = elm_config_scale_get();
+    PluginModuleSupport::setCustomProperties(
+        This->m_ewkContext,
+        &scale,
+        ApplicationDataSingleton::Instance().getEncodedBundle());
     // check if 'appsevice' event is registed at the current frames.
     // If so, dispatch the event to frames.
     PluginModuleSupport::dispatchJavaScriptEvent(
         This->m_ewkContext,
-        WrtPlugins::W3C::ServiceCustomEvent);
+        WrtPlugins::W3C::ServiceCustomEvent,
+        NULL);
 }
 
 void ViewLogic::titleChangedCallback(
index b069206..413af9e 100644 (file)
@@ -58,6 +58,7 @@ class ViewLogic : public ViewModule::IViewModule
     void forward();
     void reloadStartPage();
     Evas_Object* getCurrentWebview();
+    void fireJavascriptEvent(int event, void* data);
     void setUserCallbacks(const WRT::UserDelegatesPtr& cbs);
 
     // Ewk_Context operations
index 0459e3a..96426d2 100644 (file)
@@ -23,6 +23,7 @@ SET(WRT_CLIENT_SRCS
 
 PKG_CHECK_MODULES(CLIENT_DEP
     dpl-wrt-dao-ro
+    wrt-plugin-js-overlay
     REQUIRED
 )