Add new usercallbacks for executable to know when new webview created and destroyed.
authorYunchan Cho <yunchan.cho@samsung.com>
Wed, 21 Nov 2012 06:10:00 +0000 (15:10 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Thu, 29 Nov 2012 01:43:01 +0000 (10:43 +0900)
[Issue#] executables that use wrt-core lib may need to know when new webview is created or destroyed.
[Bug] N/A
[Cause] Now there is no way for each executable using wrt-core to know that time
[Solution] New two UserDelegates callbacks are added, and they are called in window create, close callback of viewlogic
[Verification] Register new two UserDelegates callbacks in your executable (like wrt-client),
               and let your executable to load specific web contents that executes window.open as '_blank'

Change-Id: I40e81111ad3af115f2684a4957ece921d9a18174

src/api_new/i_runnable_widget_object.h
src/view/webkit/view_logic.cpp
src/view/webkit/view_logic.h
src/wrt-client/wrt-client.cpp
src/wrt-client/wrt-client.h

index 99164a3..783eaf0 100644 (file)
 namespace WRT {
 
 typedef DPL::FastDelegate0<void> ProgressFinishCB;
-typedef DPL::FastDelegate1<bool, void> LoadFinishCB;
+typedef DPL::FastDelegate1<Evas_Object*, void> LoadStartCB;
+typedef DPL::FastDelegate1<Evas_Object*, void> LoadFinishCB;
 typedef DPL::FastDelegate0<void> WebCrashCB;
-typedef DPL::FastDelegate0<void> WindowCloseCB;
+typedef DPL::FastDelegate2<Evas**, Evas_Object*, void> WindowCreateBeforeCB;
+typedef DPL::FastDelegate2<Evas_Object*, Evas_Object*, void> WindowCreateAfterCB;
+typedef DPL::FastDelegate1<Evas_Object*, void> WindowCloseCB;
+typedef DPL::FastDelegate0<void> WebkitExitCB;
 typedef DPL::FastDelegate1<bool, void> ResumeCB;
 typedef DPL::FastDelegate1<bool, void> SuspendCB;
 typedef DPL::FastDelegate1<bool, void> ResetCB;
@@ -46,9 +50,13 @@ typedef DPL::FastDelegate1<bool, void> ToggleFullscreenCB;
 
 typedef struct UserDelegates {
     ProgressFinishCB progressFinish;
+    LoadStartCB loadStart;
     LoadFinishCB loadFinish;
     WebCrashCB webCrash;
+    WindowCreateBeforeCB windowCreateBefore;
+    WindowCreateAfterCB windowCreateAfter;
     WindowCloseCB windowClose;
+    WebkitExitCB webkitExit;
     ResumeCB resume;
     SuspendCB suspend;
     ResetCB reset;
index 33d420a..1d32022 100644 (file)
@@ -138,7 +138,7 @@ void ViewLogic::createWebView(Ewk_Context* context,
     Assert(NULL != m_ewkContext);
     Assert(window);
     m_window = window;
-    createEwkView();
+    createEwkView(evas_object_evas_get(m_window));
 }
 
 void ViewLogic::destroyWebView()
@@ -277,7 +277,7 @@ void ViewLogic::resetWidget()
     // check if already created webview exists
     if (!m_ewkViewList.size()) {
         // create new webview
-        createEwkView();
+        createEwkView(evas_object_evas_get(m_window));
         setStartPage();
         ewkClientInit(m_currentEwkView);
         prepareEwkView(m_currentEwkView);
@@ -363,7 +363,7 @@ void ViewLogic::reloadStartPage()
 
     if (m_ewkViewList.size() == 0) {
         // create new webview
-        createEwkView();
+        createEwkView(evas_object_evas_get(m_window));
         ewkClientInit(m_currentEwkView);
     } else {
         // close opened windows
@@ -786,12 +786,13 @@ void ViewLogic::ewkClientDeinit(Evas_Object *wkView) {
         imeCloseCallback);
 }
 
-void ViewLogic::createEwkView()
+void ViewLogic::createEwkView(Evas* canvas)
 {
     LogDebug("createEwkVeiw");
+    Assert(canvas);
     ADD_PROFILING_POINT("ewk_view_add_with_context", "start");
     Evas_Object* newEwkView = ewk_view_add_with_context(
-        evas_object_evas_get(m_window),
+        canvas,
         m_ewkContext);
     ADD_PROFILING_POINT("ewk_view_add_with_context", "stop");
 
@@ -997,18 +998,24 @@ void ViewLogic::didStartDownloadCallback(
 
 void ViewLogic::loadStartedCallback(
         void* data,
-        Evas_Object* /*obj*/,
+        Evas_Object* obj,
         void* /*eventInfo*/)
 {
     LogDebug("loadStartedCallback called");
     Assert(data);
     ViewLogic* This = static_cast<ViewLogic*>(data);
     evas_object_focus_set(This->m_currentEwkView, EINA_TRUE);
+
+    // call loadFinish callback to wrt-client
+    if (!This->m_cbs->loadStart.empty()) {
+        This->m_cbs->loadStart(obj);
+    }
+
 }
 
 void ViewLogic::loadFinishedCallback(
         void* data,
-        Evas_Object* /*obj*/,
+        Evas_Object* obj,
         void* /*eventInfo*/)
 {
     LogDebug("loadFinishedCallback called");
@@ -1036,7 +1043,7 @@ void ViewLogic::loadFinishedCallback(
 
     // call loadFinish callback to wrt-client
     if (!This->m_cbs->loadFinish.empty()) {
-        This->m_cbs->loadFinish(true);
+        This->m_cbs->loadFinish(obj);
     }
 
     // set only encoded bundle
@@ -1116,27 +1123,30 @@ void ViewLogic::processCrashedCallback(
 
 void ViewLogic::createWindowCallback(
         void* data,
-        Evas_Object* ,
+        Evas_Object* obj,
         void* eventInfo)
 {
     LogDebug("createWindowCallback");
     Assert(data);
     ViewLogic* This = static_cast<ViewLogic*>(data);
 
-    Evas_Object* currentEwkView = This->m_currentEwkView;
-
-    // suspend current ewkview
-    /* In case we support many pages in parallel
-       then view should not be suspended*/
-    //This->suspendEwkView(currentEwkView);
-
+    // First, current webview should be handled by user callback
     if (!This->m_cbs->bufferUnset.empty()) {
-        This->m_cbs->bufferUnset(currentEwkView);
+        This->m_cbs->bufferUnset(obj);
     }
 
-    // create new ewkview
-    This->createEwkView();
+    // this can be set by executable for specific purpose
+    Evas* canvas = NULL;
+    if (!This->m_cbs->windowCreateBefore.empty()) {
+        // 'obj' is parent webview object
+        This->m_cbs->windowCreateBefore(&canvas, obj);
+    }
+    if (!canvas) {
+        canvas = evas_object_evas_get(This->m_window); 
+    }
 
+    // create new ewkview
+    This->createEwkView(canvas);
     Evas_Object* newEwkView = This->m_currentEwkView;
 
     // initialize new ewkview
@@ -1144,8 +1154,14 @@ void ViewLogic::createWindowCallback(
     This->ewkClientInit(newEwkView);
     This->prepareEwkView(newEwkView);
 
-    // show new ewkview
-    if (!This->m_cbs->bufferUnset.empty()) {
+    // Specific jobs of child, parent webview are handled by each executable
+    if (!This->m_cbs->windowCreateAfter.empty()) {
+        // 'obj' is parent webview, 'newEwkView' is child webview
+        This->m_cbs->windowCreateAfter(obj, newEwkView);
+    }
+
+    // Lastly, new webview should be handled by user callback
+    if (!This->m_cbs->bufferSet.empty()) {
         This->m_cbs->bufferSet(newEwkView);
     }
     *(static_cast<Evas_Object **>(eventInfo)) = newEwkView;
@@ -1153,11 +1169,13 @@ void ViewLogic::createWindowCallback(
 
 void ViewLogic::closeWindowCallback(
         void* data,
-        Evas_Object* /*obj*/,
+        Evas_Object* obj,
         void* /*eventInfo*/)
 {
     LogDebug("closeWindowCallback");
-    ecore_idler_add(windowCloseIdlerCallback, data);
+    ViewLogic* This = static_cast<ViewLogic*>(data);
+    This->m_closedEwkView = obj;
+    ecore_idler_add(windowCloseIdlerCallback, This);
 }
 
 void ViewLogic::policyNavigationDecideCallback(
@@ -1757,18 +1775,21 @@ std::string ViewLogic::requestUriChanged(const DPL::String& changedURL)
 void ViewLogic::windowClose()
 {
     LogDebug("windowClose");
+    Assert(m_closedEwkView && "no closed webview");
 
     if (1 >= m_ewkViewList.size()) {
-        if (!m_cbs->windowClose.empty()) {
-            m_cbs->windowClose();
+        if (!m_cbs->webkitExit.empty()) {
+            m_cbs->webkitExit();
         }
     } else {
-        // hide current ewkView
-
+        // call user callbacks
         if (!m_cbs->bufferUnset.empty()) {
             m_cbs->bufferUnset(m_currentEwkView);
         }
-        removeEwkView(m_currentEwkView);
+        if (!m_cbs->windowClose.empty()) {
+            m_cbs->windowClose(m_closedEwkView);
+        }
+        removeEwkView(m_closedEwkView);
 
         // get latest ewkView
         m_currentEwkView = m_ewkViewList.back();
index b5a1484..a7f2884 100644 (file)
@@ -75,7 +75,7 @@ class ViewLogic : public ViewModule::IViewModule
     // EwkView operations
     void ewkClientInit(Evas_Object *wkView);
     void ewkClientDeinit(Evas_Object *wkView);
-    void createEwkView();
+    void createEwkView(Evas* canvas);
     void setStartPage();
     void prepareEwkView(Evas_Object *wkView);
     void removeEwkView(Evas_Object *wkView);
@@ -253,10 +253,10 @@ class ViewLogic : public ViewModule::IViewModule
     // window
     void windowClose(void);
 
-
     Ewk_Context* m_ewkContext;
     std::list<Evas_Object*> m_ewkViewList;
     Evas_Object* m_currentEwkView;
+    Evas_Object* m_closedEwkView;
     Evas_Object* m_window;
     WidgetModel* m_model;
     std::string m_currentUri;
index c314618..94359ff 100755 (executable)
@@ -328,7 +328,7 @@ bool WrtClient::checkWACTestCertififedWidget()
     return true;
 }
 
-void WrtClient::loadFinishCallback(bool success)
+void WrtClient::loadFinishCallback(Evas_Object* webview)
 {
     ADD_PROFILING_POINT("loadFinishCallback", "start");
     SDKDebugData* debug = new SDKDebugData;
@@ -363,7 +363,7 @@ void WrtClient::loadFinishCallback(bool success)
         fclose(doutput);
     }
 
-    if (success) {
+    if (webview) {
         LogDebug("Launch succesfull");
 
         m_launched = true;
@@ -383,17 +383,13 @@ void WrtClient::loadFinishCallback(bool success)
 
     if(debug->debugMode)
     {
-        LogDebug("Send RT signal to wrt-launcher(pid: "
-                << m_sdkLauncherPid << ", status: " << success);
+        LogDebug("Send RT signal to wrt-launcher(pid: " << m_sdkLauncherPid);
         union sigval sv;
         /* send real time signal with result to wrt-launcher */
-        if(success)
-        {
+        if(webview) {
             LogDebug("userData->portnum : " << debug->portnum);
             sv.sival_int = debug->portnum;
-        }
-        else
-        {
+        } else {
            sv.sival_int = -1;
         }
         sigqueue(m_sdkLauncherPid, SIGRTMIN, sv);
@@ -411,7 +407,7 @@ void WrtClient::progressFinishCallback()
     m_splashScreen->stopSplashScreen();
 }
 
-void WrtClient::windowCloseCallback()
+void WrtClient::webkitExitCallback()
 {
     LogDebug("window close called, terminating app");
     SwitchToStep(&WrtClient::shutdownStep);
@@ -518,7 +514,7 @@ void WrtClient::launchStep()
     cbs->loadFinish = DPL::MakeDelegate(this, &WrtClient::loadFinishCallback);
     cbs->bufferSet = DPL::MakeDelegate(this, &WrtClient::setLayout);
     cbs->bufferUnset = DPL::MakeDelegate(this, &WrtClient::unsetLayout);
-    cbs->windowClose = DPL::MakeDelegate(this, &WrtClient::windowCloseCallback);
+    cbs->webkitExit = DPL::MakeDelegate(this, &WrtClient::webkitExitCallback);
     cbs->webCrash = DPL::MakeDelegate(this, &WrtClient::webCrashCallback);
     cbs->toggleFullscreen = DPL::MakeDelegate(m_windowData.get(), &WindowData::toggleFullscreen);
 
index eb734b4..c3e0d65 100644 (file)
@@ -95,9 +95,9 @@ class WrtClient :
     void launchStep();
     void shutdownStep();
     static int languageChangedCallback(void *data);
-    void loadFinishCallback(bool success);
+    void loadFinishCallback(Evas_Object* webview);
     void progressFinishCallback();
-    void windowCloseCallback();
+    void webkitExitCallback();
     void webCrashCallback();
     void setLayout(Evas_Object* newBuffer);
     void unsetLayout(Evas_Object* currentBuffer);