Support multiple webkit context on wrt-core
authorYunchan Cho <yunchan.cho@samsung.com>
Wed, 6 Feb 2013 07:54:19 +0000 (16:54 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Wed, 13 Feb 2013 08:41:49 +0000 (17:41 +0900)
Existing wrt-core considered only one webkit context on one UI process.
In case of webapp, this was enough to handle webapp, but not other usage of wrt-core like web-provider.
Web-provider that handles web-liveboxes can have one UI process and multiple Web Processes.

From now on, CoreModule handle special jobs that are processed process-widely once like attaching database.
So CoreModule continues to be used as singleton instance.
But created RunnableWidgetObject instance has one Ewk Context, that is matched to specific Web Process.
One Ewk Context may be shared with several RunnableWidgetObject instances.
But in this case, the Ewk Context's setting includeing callbacks can be overwritten due to internal webkit implementation.
Web-provider with multiple Ewk Contextes should consider this.

If an executable(like wrt-client) linking libwrt-core create one Ewk_Context itself, the executable should remove the Ewk_Context explicitly on termination.
Because libwrt-core doesn't remove Ewk_Context passed from executable, and remove only Ewk_Context created internally by RunnableWidgetObject.

[Issue#]       N/A
[Problem]      Existing libwrt-core considers only one webkit context on one UI process
[Cause]        In webapp case, this was enough to existing implementation.
               But wrt-provider that links libwrt-core and may have multiple Ewk Context couldn't support livebox requirements
[Solution]     WRT code is modified to support multiple webkit context

Change-Id: Ibc70f882e317d2cb07650aa9dc028fcb605d03b5

13 files changed:
src/api_new/CMakeLists.txt
src/api_new/core_module.cpp
src/api_new/core_module.h
src/api_new/ewk_context_manager.cpp [new file with mode: 0644]
src/api_new/ewk_context_manager.h [new file with mode: 0644]
src/api_new/i_runnable_widget_object.h
src/api_new/runnable_widget_object.cpp
src/api_new/runnable_widget_object.h
src/view/i_view_module.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 2aa2a27..56c4012 100644 (file)
@@ -17,6 +17,7 @@ ADD_LIBRARY(${TARGET_CORE_MODULE_LIB} SHARED
     ${PROJECT_SOURCE_DIR}/src/api_new/core_module.cpp
     ${PROJECT_SOURCE_DIR}/src/api_new/runnable_widget_object.cpp
     ${PROJECT_SOURCE_DIR}/src/api_new/runnable_widget_object_state.cpp
+    ${PROJECT_SOURCE_DIR}/src/api_new/ewk_context_manager.cpp
 )
 
 SET_TARGET_PROPERTIES(${TARGET_CORE_MODULE_LIB} PROPERTIES
index 62030b2..73a8c75 100644 (file)
@@ -116,38 +116,9 @@ class CoreModuleImpl
             }
             Try
             {
-                if (!m_ewkContext) {
-                    // Needed settings for WKContext are located here
-                    // create Ewk_Context
-                    Ewk_Context* newEwkContext =
-                        ewk_context_new_with_injected_bundle_path(bundlePath);
-                    if (!newEwkContext) {
-                        LogError("Failed to create Ewk_Context");
-                        ThrowMsg(DPL::Exception, "Failed to create ewk context");
-                    }
-
-                    m_ewkContext = newEwkContext;
-                }
-
-                // cache model setting
-                ewk_context_cache_model_set(m_ewkContext,
-                                            EWK_CACHE_MODEL_DOCUMENT_BROWSER);
-                ADD_PROFILING_POINT("WebProcess fork", "start");
-
-                // To fork a Webprocess as soon as possible,
-                // the following ewk_api is called explicitly.
-                Ewk_Cookie_Manager *ewkCookieManager;
-                ewkCookieManager =
-                    ewk_context_cookie_manager_get(m_ewkContext);
-                ewk_cookie_manager_accept_policy_set(
-                    ewkCookieManager,
-                    EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
-                ADD_PROFILING_POINT("WebProcess fork", "stop");
-
                 ADD_PROFILING_POINT("attach databases", "start");
                 MainThreadSingleton::Instance().AttachDatabases();
                 ADD_PROFILING_POINT("attach databases", "stop");
-
                 LogDebug("Initialize finished");
             } catch (const DPL::Exception& ex) {
                 LogError("Internal Error during screen preparation:");
@@ -163,37 +134,20 @@ class CoreModuleImpl
         return true;
     }
 
-    bool Init(Ewk_Context* ewk_context)
-    {
-        if (ewk_context) {
-            m_ewkContext = ewk_context;
-        }
-
-        return Init();
-    }
-
     void Terminate()
     {
-        if (m_ewkContext) {
-            LogInfo("finalizeEwkContext called");
-            ewk_context_delete(m_ewkContext);
-            m_ewkContext = 0;
-        }
         MainThreadSingleton::Instance().DetachDatabases();
-
         m_initialized = false;
     }
 
     RunnableWidgetObjectPtr getRunnableWidgetObject(
         const std::string& tizenId)
     {
-        PluginModuleSupport::init(m_ewkContext, tizenId);
-
         try {
             RunnableWidgetObjectPtr runnable;
             WidgetModelPtr model = Domain::deserializeWidgetModel(tizenId);
             if (!!model) {
-                runnable.reset(new RunnableWidgetObject(model, m_ewkContext));
+                runnable.reset(new RunnableWidgetObject(model));
             }
             return runnable;
         } catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
@@ -255,11 +209,6 @@ bool CoreModule::Init()
     return m_impl->Init();
 }
 
-bool CoreModule::Init(Ewk_Context* ewk_context)
-{
-    return m_impl->Init(ewk_context);
-}
-
 void CoreModule::Terminate()
 {
     return m_impl->Terminate();
index 93d5a47..026b289 100644 (file)
@@ -54,7 +54,6 @@ class CoreModule
      * @return true on success, false when it fails
      */
     bool Init();
-    bool Init(Ewk_Context* ewk_context);
     /**
      * Deinitialize CoreModule. If it called without Init() some internal
      * asserts will fail.
diff --git a/src/api_new/ewk_context_manager.cpp b/src/api_new/ewk_context_manager.cpp
new file mode 100644 (file)
index 0000000..f5f3740
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2013 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    ewk_context_manager.cpp
+ * @author  Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 0.1
+ * @brief   Implementation of EwkContextManager class.
+ *          This file handles operation regarding Ewk_Context
+ */
+
+#include <string>
+#include <vconf.h>
+#include <ewk_context.h>
+#include <dpl/log/log.h>
+#include <dpl/exception.h>
+#include <profiling_util.h>
+#include <i_view_module.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/vconf_config.h>
+#include <dpl/utils/wrt_global_settings.h>
+#include "ewk_context_manager.h"
+
+static const std::string bundlePath("/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so");
+static const std::string caCertPath("/opt/usr/share/certs/ca-certificate.crt");
+
+EwkContextManager::EwkContextManager(
+        std::string& tizenAppId,
+        Ewk_Context* ewkContext,
+        ViewModule::IViewModulePtr viewModule)
+    : m_initialized(false)
+    , m_isInternalContext(false)
+    , m_appId(tizenAppId)
+    , m_ewkContext(ewkContext)
+    , m_view(viewModule)
+{
+    if (!initialize()) {
+        ThrowMsg(DPL::Exception, "Fail to intialize EwkContextManager");
+    }
+    // set ewk context callbacks
+    setCallbacks();
+}
+
+EwkContextManager::~EwkContextManager()
+{
+    // unset registered ewk context callbacks
+    unsetCallbacks();
+    destroy();
+}
+
+EwkContextManagerPtr EwkContextManager::create(
+        std::string& tizenAppId,
+        Ewk_Context* ewkContext,
+        ViewModule::IViewModulePtr viewModule)
+{
+    return EwkContextManagerPtr(new EwkContextManager(tizenAppId, ewkContext, viewModule));
+}
+
+Ewk_Context* EwkContextManager::getEwkContext()
+{
+    return m_ewkContext;
+}
+
+bool EwkContextManager::initialize()
+{
+    if (!m_ewkContext) {
+        m_ewkContext = ewk_context_new_with_injected_bundle_path(bundlePath.c_str());
+
+        if (!m_ewkContext) {
+            return false;
+        }
+
+        m_isInternalContext = true;
+    }
+
+    // cache model setting
+    ewk_context_cache_model_set(
+            m_ewkContext,
+            EWK_CACHE_MODEL_DOCUMENT_BROWSER);
+    ADD_PROFILING_POINT("WebProcess fork", "start");
+    // To fork a Webprocess as soon as possible,
+    // the following ewk_api is called explicitly.
+    ewk_cookie_manager_accept_policy_set(
+            ewk_context_cookie_manager_get(m_ewkContext),
+            EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
+    ADD_PROFILING_POINT("WebProcess fork", "stop");
+
+    // proxy server setting
+    char *proxyAddress = vconf_get_str(VCONFKEY_NETWORK_PROXY);
+    if (proxyAddress && strcmp(proxyAddress, "0.0.0.0")) {
+        LogInfo("proxy address: " << proxyAddress);
+        ewk_context_proxy_uri_set(m_ewkContext,  proxyAddress);
+    } else {
+        LogInfo("proxy address is empty");
+        ewk_context_proxy_uri_set(m_ewkContext, NULL);
+    }
+
+    if (proxyAddress) {
+        free(proxyAddress);
+    }
+
+    ewk_context_certificate_file_set(m_ewkContext, caCertPath.c_str());
+
+    // set local stroage database path
+    WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_appId));
+    ewk_context_web_storage_path_set(
+            m_ewkContext,
+            dao.getPrivateLocalStoragePath().c_str());
+
+    // memory saving mode
+    int result;
+    vconf_get_int(
+            WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
+                DPL::FromUTF8String(m_appId)).c_str(), &result);
+
+    ewk_context_memory_saving_mode_set(
+            m_ewkContext,
+            static_cast<WrtDB::SettingsType>(result) ==
+            WrtDB::SETTINGS_TYPE_ON ? EINA_TRUE : EINA_FALSE);
+
+    m_initialized = true;
+
+    return true;
+}
+
+void EwkContextManager::destroy()
+{
+    // only in the following case, webkit context should be deleted
+    if (m_initialized && m_isInternalContext) {
+        ewk_context_delete(m_ewkContext);
+    }
+}
+
+void EwkContextManager::setCallbacks()
+{
+    if (!m_initialized) {
+        return;
+    }
+
+    ewk_context_message_from_injected_bundle_callback_set(
+            m_ewkContext,
+            messageFromInjectedBundleCallback,
+            this);
+
+    ewk_context_did_start_download_callback_set(
+            m_ewkContext,
+            didStartDownloadCallback,
+            this);
+
+    ewk_context_vibration_client_callbacks_set(
+            m_ewkContext,
+            vibrationClientStartCallback,
+            vibrationClientStopCallback,
+            this);
+}
+
+void EwkContextManager::unsetCallbacks()
+{
+    if (!m_initialized) {
+        return;
+    }
+
+    ewk_context_message_from_injected_bundle_callback_set(
+            m_ewkContext, NULL, NULL);
+    ewk_context_did_start_download_callback_set(
+            m_ewkContext, NULL, NULL);
+    ewk_context_vibration_client_callbacks_set(
+            m_ewkContext, NULL, NULL, NULL);
+}
+
+
+void EwkContextManager::messageFromInjectedBundleCallback(
+        const char* name,
+        const char* body,
+        char** returnData,
+        void* clientInfo)
+{
+    LogDebug("enter");
+    LogDebug("did recive message: " << name);
+
+    EwkContextManager* This = static_cast<EwkContextManager*>(clientInfo);
+    if (!returnData) {
+        This->m_view->checkSyncMessageFromBundle(name, body, returnData);
+    }
+}
+
+void EwkContextManager::didStartDownloadCallback(const char* downloadUrl, void* data)
+{
+    LogDebug("enter");
+    LogDebug("download url: " << downloadUrl);
+
+    EwkContextManager* This = static_cast<EwkContextManager*>(data);
+    This->m_view->downloadData(downloadUrl);
+}
+
+void EwkContextManager::vibrationClientStartCallback(uint64_t time, void* data)
+{
+    LogDebug("enter");
+
+    EwkContextManager* This = static_cast<EwkContextManager*>(data);
+    This->m_view->activateVibration(true, static_cast<long>(time));
+}
+
+void EwkContextManager::vibrationClientStopCallback(void* data)
+{
+    LogDebug("enter");
+
+    EwkContextManager* This = static_cast<EwkContextManager*>(data);
+    This->m_view->activateVibration(false, 0);
+}
+
+void EwkContextManager::handleLowMemory()
+{
+    if (!m_ewkContext) {
+        return;
+    }
+
+    //ewk_context_cache_clear(m_ewkContext);
+    //ewk_context_notify_low_memory(m_ewkContext);
+}
+
diff --git a/src/api_new/ewk_context_manager.h b/src/api_new/ewk_context_manager.h
new file mode 100644 (file)
index 0000000..78aada8
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2013 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    ewk_context_manager.h
+ * @author  Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 0.1
+ * @brief   Declaration of EwkContextManager class.
+ *          This file handles operation regarding Ewk_Context.
+ */
+
+#ifndef EWK_CONTEXT_MANAGER_H
+#define EWK_CONTEXT_MANAGER_H
+
+#include <memory>
+#include <ewk_context.h>
+#include <i_view_module.h>
+
+class EwkContextManager;
+typedef std::shared_ptr<EwkContextManager> EwkContextManagerPtr;
+
+class EwkContextManager {
+    public:
+        static EwkContextManagerPtr create(
+                std::string& tizenAppId,
+                Ewk_Context* ewkContext,
+                ViewModule::IViewModulePtr viewModule);
+        Ewk_Context* getEwkContext();
+        void handleLowMemory();
+        ~EwkContextManager();
+
+    private:
+        bool initialize();
+        void destroy();
+        void setCallbacks();
+        void unsetCallbacks();
+
+        // ewk context callback functions
+        static void messageFromInjectedBundleCallback(
+                const char* name,
+                const char* body,
+                char** returnData,
+                void* clientInfo);
+        static void didStartDownloadCallback(const char* downloadUrl, void* data);
+        static void vibrationClientStartCallback(uint64_t time, void* data);
+        static void vibrationClientStopCallback(void* data);
+
+        explicit EwkContextManager(
+                std::string& tizenAppId,
+                Ewk_Context* ewkContext,
+                ViewModule::IViewModulePtr viewModule);
+
+        // members
+        bool m_initialized;
+        bool m_isInternalContext;
+        std::string m_appId;
+        Ewk_Context* m_ewkContext;
+        ViewModule::IViewModulePtr m_view;
+};
+
+#endif // EWK_CONTEXT_MANAGER_H
index dca9c3a..49af1d8 100644 (file)
@@ -28,7 +28,7 @@
 #include <memory>
 #include <Evas.h>
 #include <widget_model.h>
-
+#include <ewk_context.h>
 #include <dpl/exception.h>
 
 namespace WRT {
@@ -122,7 +122,8 @@ class IRunnableWidgetObject
      * @param callbacks passed to viewLogic
      */
     virtual bool PrepareView(const std::string &startUrl,
-                             Evas_Object *window) = 0;
+                             Evas_Object *window,
+                             Ewk_Context* ewkContext = NULL) = 0;
     /**
      * Shows widget asynchronously. Callback will be called when
      * webkit generates website.
index 6e37f4b..44c23fe 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <runnable_widget_object.h>
 #include <privilege-control.h>
+#include <dpl/exception.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/utils/wrt_global_settings.h>
 #include <appcore-common.h>
@@ -32,6 +33,7 @@
 #include <runnable_widget_object_state.h>
 #include <wrt_ocsp_api.h>
 #include <popup-runner/PopupInvoker.h>
+#include "ewk_context_manager.h"
 
 namespace { //Anonymous
 const std::string ACCESS_DENIED = _("IDS_BR_POP_ACCESS_DENIED");
@@ -42,11 +44,9 @@ const unsigned int UID_ROOT = 0;
 } // namespace anonymous
 
 namespace WRT {
-RunnableWidgetObject::RunnableWidgetObject(WidgetModelPtr &model,
-                                           Ewk_Context* context) :
-    m_widgetModel(model),
-    m_view(ViewModule::createView()),
-    m_ewkContext(context)
+RunnableWidgetObject::RunnableWidgetObject(WidgetModelPtr &model) :
+        m_widgetModel(model),
+        m_view(ViewModule::createView())
 {
     //set initial state of runnable object
     m_guardstate = std::shared_ptr<State::RunnableWidgetObjectState>(
@@ -104,16 +104,41 @@ bool RunnableWidgetObject::CheckBeforeLaunch()
 }
 
 bool RunnableWidgetObject::PrepareView(const std::string &startUrl,
-                                       Evas_Object *window)
+        Evas_Object *window, Ewk_Context* ewkContext)
 {
     State::StateChange change = m_guardstate->allowPrepareView();
-    Assert(window);
+    if (!window) {
+        return false;
+    }
+
+    std::string appId = DPL::ToUTF8String(m_widgetModel->TizenId);
+    Try {
+        if(!m_ewkContextManager) {
+            m_ewkContextManager =
+                EwkContextManager::create(appId, ewkContext, m_view);
+        } else {
+            if (ewkContext && 
+                    ewkContext != m_ewkContextManager->getEwkContext()) 
+            {
+                m_ewkContextManager =
+                    EwkContextManager::create(appId, ewkContext, m_view);
+            }
+        }
+    } Catch (DPL::Exception) {
+        LogError("Internal Error during create or initialize Ewk Context");
+        return false;
+    }
 
     ADD_PROFILING_POINT("view_logic_init", "start");
-    if (!m_view->createWebView(m_ewkContext, window)) {
+    Ewk_Context* context = m_ewkContextManager->getEwkContext();
+
+    // plugin init
+    PluginModuleSupport::init(context, DPL::ToUTF8String(m_widgetModel->TizenId));
+
+    // view init
+    if(!m_view->createWebView(context, window)) {
         return false;
     }
-    m_view->initialize();
     m_view->prepareView(m_widgetModel.get(), startUrl);
     ADD_PROFILING_POINT("view_logic_init", "stop");
 
@@ -135,7 +160,6 @@ void RunnableWidgetObject::Hide()
     State::StateChange change = m_guardstate->allowHide();
 
     m_view->hideWidget();
-    m_view->destroyWebView();
 
     change.commit();
 }
@@ -215,6 +239,6 @@ void RunnableWidgetObject::setNewState(
 RunnableWidgetObject::~RunnableWidgetObject()
 {
     LogDebug("");
-    PluginModuleSupport::shutdown(m_ewkContext);
+    PluginModuleSupport::shutdown(m_ewkContextManager->getEwkContext());
 }
 } /* namespace WRT */
index 1855a14..c3e8432 100644 (file)
@@ -34,21 +34,23 @@ class StateChange;
 #include <string>
 #include <memory>
 
+#include <EWebKit2.h>
 #include <widget_model.h>
+#include <dpl/exception.h>
 #include <i_view_module.h>
+#include "ewk_context_manager.h"
 #include "i_runnable_widget_object.h"
-#include <EWebKit2.h>
 
 namespace WRT {
 class RunnableWidgetObject : public IRunnableWidgetObject
 {
-  public:
-    RunnableWidgetObject(WidgetModelPtr &model, Ewk_Context* context);
+public:
+    RunnableWidgetObject(WidgetModelPtr &model);
     virtual ~RunnableWidgetObject();
 
     bool CheckBeforeLaunch();
     bool PrepareView(const std::string &startUrl,
-                     Evas_Object *window);
+            Evas_Object *window, Ewk_Context* ewkContext = NULL);
     void Show(); //asynchronous function
     void Hide();
     void Suspend();
@@ -63,14 +65,12 @@ class RunnableWidgetObject : public IRunnableWidgetObject
   private:
 
     bool CheckWACTestCertififedWidget();
+    void setNewState(std::shared_ptr<WRT::State::RunnableWidgetObjectState> sptr);
 
     WidgetModelPtr m_widgetModel;
     ViewModule::IViewModulePtr m_view;
-    Ewk_Context* m_ewkContext;
-    void setNewState(
-        std::shared_ptr<WRT::State::RunnableWidgetObjectState> sptr);
-
     std::shared_ptr<State::RunnableWidgetObjectState> m_guardstate;
+    EwkContextManagerPtr m_ewkContextManager;
 
     friend class State::StateChange;
 };
index c63b5d3..26adb24 100644 (file)
@@ -39,9 +39,6 @@ class IViewModule
   public:
     virtual bool createWebView(Ewk_Context* context,
                                Evas_Object* window) = 0;
-    virtual void destroyWebView() = 0;
-    virtual void initialize() = 0;
-    virtual void terminate() = 0;
     virtual void prepareView(WidgetModel *, const std::string &) = 0;
     virtual void showWidget() = 0;
     virtual void hideWidget() = 0;
@@ -53,6 +50,12 @@ class IViewModule
     virtual Evas_Object* getCurrentWebview() = 0;
     virtual void fireJavascriptEvent(int event, void* data) = 0;
     virtual void setUserCallbacks(const WRT::UserDelegatesPtr& cbs) = 0;
+    virtual void checkSyncMessageFromBundle(
+            const char* name,
+            const char* body,
+            char** returnData) = 0;
+    virtual void downloadData(const char* url) = 0;
+    virtual void activateVibration(bool on, uint64_t time) = 0;
 };
 
 typedef std::shared_ptr<IViewModule> IViewModulePtr;
index 14eb871..bbcaed3 100644 (file)
@@ -30,7 +30,6 @@
 #include <dpl/string.h>
 #include <dpl/foreach.h>
 
-#include <appcore-common.h>
 #include <pcrecpp.h>
 #include <vconf.h>
 #include <sysman.h>
@@ -180,7 +179,9 @@ ViewLogic::ViewLogic() :
     m_appsSupport(new ViewModule::AppsSupport()),
     m_vibrationSupport(new ViewModule::VibrationSupport()),
     m_attachedToCustomHandlerDao(false)
-{}
+{
+    ApplicationLauncherSingleton::Instance().Touch();
+}
 
 ViewLogic::~ViewLogic()
 {
@@ -190,43 +191,24 @@ ViewLogic::~ViewLogic()
 bool ViewLogic::createWebView(Ewk_Context* context,
                               Evas_Object* window)
 {
-    LogDebug("");
-    initializeEwkContext(context);
-    Assert(NULL != m_ewkContext);
-    Assert(window);
-    m_window = window;
-    if (!createEwkView(evas_object_evas_get(m_window))) {
+    LogDebug("enter");
+    if (!context || !window) {
         return false;
     }
-    return true;
-}
 
-void ViewLogic::destroyWebView()
-{
-    if (m_ewkContext) {
-        finalizeEwkContext();
+    // theme setting
+    const char *theme = elm_theme_get(NULL);
+    if (theme) {
+        m_theme = theme;
+        LogInfo("theme is " << m_theme);
     }
-}
 
-void ViewLogic::initialize()
-{
-    LogDebug("Initializing");
-    ApplicationLauncherSingleton::Instance().Touch();
-    appcore_set_event_callback(
-        APPCORE_EVENT_LOW_MEMORY,
-        &appcoreLowMemoryCallback,
-        this);
-}
+    // set members
+    m_ewkContext = context;
+    m_window = window;
 
-void ViewLogic::terminate()
-{
-    LogDebug("terminating view logic");
-    if (m_model) {
-        hideWidget();
-    } else {
-        LogError("Widget model not created");
-    }
-    LogDebug("done");
+    Evas* canvas = evas_object_evas_get(m_window);
+    return createEwkView(canvas);
 }
 
 void ViewLogic::prepareView(WidgetModel* m, const std::string &startUrl)
@@ -451,77 +433,53 @@ void ViewLogic::setUserCallbacks(const WRT::UserDelegatesPtr& cbs)
     m_cbs = cbs;
 }
 
-void ViewLogic::initializeEwkContext(Ewk_Context* newEwkContext)
+void ViewLogic::checkSyncMessageFromBundle(
+        const char* name,
+        const char* body,
+        char** returnData)
 {
-    LogInfo("initializeEwkContext called");
-    Assert(newEwkContext && "Ewk_Context provided can not be null");
-    // bundle callback setting
-    ewk_context_message_from_injected_bundle_callback_set(
-        newEwkContext,
-        contextMessageFromInjectedBundleCallback,
-        static_cast<void*>(this));
+    LogDebug("didReceiveSynchronousMessage called");
+    Assert(name);
+    Assert(returnData);
 
-    // proxy server setting
-    char *proxyAddress = vconf_get_str(VCONFKEY_NETWORK_PROXY);
-    if ((!proxyAddress) || (strlen(proxyAddress) == 0)
-        || (strstr(proxyAddress, "0.0.0.0")))
-    {
-        LogInfo("proxy address is empty");
-        ewk_context_proxy_uri_set(newEwkContext, NULL);
-    } else {
-        LogInfo("proxy address [" << proxyAddress << "]");
-        ewk_context_proxy_uri_set(newEwkContext, proxyAddress);
+    if (!body) {
+        LogDebug("body is empty");
+        *returnData = NULL;
+        return;
     }
-
-    if (proxyAddress) {
-        free(proxyAddress);
-        proxyAddress = NULL;
+    if (!strcmp(name, uriBlockedMessageName)) {
+        LogDebug("received : " << uriBlockedMessageName);
+        // Currently WebProcess informs obly about blocked
+        // URI - URI localization and security chekcs are
+        // done by WebProcess itself (see: wrt-wk2-bundle.cpp
+        // and bundle_uri_handling.cpp)
+        rememberBlockedURI(DPL::FromUTF8String(body));
+        *returnData = NULL;
+    } else if (!strcmp(name, uriChangedMessageName)) {
+        LogDebug("received : " << uriChangedMessageName);
+        std::string ret = requestUriChanged(DPL::FromUTF8String(body));
+        *returnData = strdup(ret.c_str());
     }
+}
 
-    // theme setting
-    const char *theme = elm_theme_get(NULL);
-    if (theme) {
-        m_theme = theme;
-        LogInfo("theme is " << m_theme);
+void ViewLogic::downloadData(const char* url)
+{
+    LogInfo("enter");
+    if (!url) {
+        return;
     }
 
-    // Ewk download callback (WKContextDownloadClient)
-    ewk_context_did_start_download_callback_set(
-        newEwkContext,
-        didStartDownloadCallback,
-        this);
-
-    ewk_context_vibration_client_callbacks_set(
-        newEwkContext,
-        vibrationVibrateCallback,
-        vibrationCancelCallback,
-        this);
-
-    ewk_context_certificate_file_set(m_ewkContext,
-                                     "/opt/usr/share/certs/ca-certificate.crt");
-
-    // set to member value
-    m_ewkContext = newEwkContext;
+    m_appsSupport->downloadRequest(url, NULL, NULL);
 }
 
-void ViewLogic::finalizeEwkContext()
+void ViewLogic::activateVibration(bool on, uint64_t time)
 {
-    LogInfo("finalizeEwkContext called");
-    ewk_context_message_from_injected_bundle_callback_set(
-        m_ewkContext,
-        NULL,
-        NULL);
-    ewk_context_did_start_download_callback_set(
-        m_ewkContext,
-        NULL,
-        NULL);
-    ewk_context_vibration_client_callbacks_set(
-        m_ewkContext,
-        NULL,
-        NULL,
-        NULL);
-    //    ewk_context_delete(m_ewkContext);
-    //    m_ewkContext = 0;
+    LogInfo("enter");
+    if (on) {
+        m_vibrationSupport->startVibration(static_cast<long>(time));
+    } else {
+        m_vibrationSupport->stopVibration();
+    }
 }
 
 void ViewLogic::initializeSupport()
@@ -551,20 +509,6 @@ void ViewLogic::initializeSupport()
     }
 #endif
 
-    // set local stroage database path
-    WrtDB::WidgetDAOReadOnly dao(m_model->TizenId);
-    ewk_context_web_storage_path_set(m_ewkContext,
-                                     dao.getPrivateLocalStoragePath().c_str());
-    // memory saving mode
-    int result;
-    vconf_get_int(
-        WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
-            m_model->TizenId).c_str(),
-        &result);
-    ewk_context_memory_saving_mode_set(
-        m_ewkContext,
-        static_cast<WrtDB::SettingsType>(result) ==
-        WrtDB::SETTINGS_TYPE_ON ? EINA_TRUE : EINA_FALSE);
     m_schemeSupport.reset(new SchemeSupport(m_model->Type.Get().appType));
     ViewModule::StorageSupport::initializeStorage(m_model);
     m_appsSupport->initialize(m_model);
@@ -823,45 +767,6 @@ void ViewLogic::suspendWebkit(Evas_Object *wkView)
     return;
 }
 
-void ViewLogic::contextMessageFromInjectedBundleCallback(
-    const char* name,
-    const char* body,
-    char** returnData,
-    void* clientInfo)
-{
-    LogDebug("contextMessageFromInjectedBundleCallback called");
-    Assert(clientInfo);
-    ViewLogic* This = static_cast<ViewLogic*>(clientInfo);
-    // didRecieveMessageFromInjectedBundleCallback - returnData is null
-    // didReceiveSynchronousMessageCallback - returnData isn't null
-    // WKContextInjectedBundleClient bundleClient = {
-    //     kWKContextInjectedBundleClientCurrentVersion,
-    //     static_cast<void*>(this),
-    //     &didRecieveMessageFromInjectedBundleCallback,
-    //     &didReceiveSynchronousMessageCallback
-    // };
-    if (NULL == returnData) {
-        This->didRecieveMessageFromInjectedBundle(name, body);
-    } else {
-        This->didReceiveSynchronousMessage(name, body, returnData);
-    }
-}
-
-void ViewLogic::didStartDownloadCallback(
-    const char* downloadUrl,
-    void* data)
-{
-    LogDebug("didStartDownloadCallback called");
-    Assert(data);
-    ViewLogic* This = static_cast<ViewLogic*>(data);
-    Assert(downloadUrl);
-    LogDebug("download url = " << downloadUrl);
-    This->m_appsSupport->downloadRequest(
-        downloadUrl,
-        NULL,
-        NULL);
-}
-
 void ViewLogic::loadStartedCallback(
     void* data,
     Evas_Object* obj,
@@ -1373,26 +1278,6 @@ void ViewLogic::notificationPermissionRequestCallback(
     return;
 }
 
-void ViewLogic::vibrationVibrateCallback(uint64_t time, void* data)
-{
-    LogDebug("vibrationVibrateCallback called");
-    Assert(data);
-    ViewLogic* This = static_cast<ViewLogic*>(data);
-    This->m_vibrationSupport->startVibration(static_cast<long>(time));
-    return;
-}
-
-void ViewLogic::vibrationCancelCallback(void* data)
-{
-    LogDebug("vibrationCancelCallback called");
-    Assert(data);
-    ViewLogic* This = static_cast<ViewLogic*>(data);
-
-    This->m_vibrationSupport->stopVibration();
-
-    return;
-}
-
 // EWK Orientation Callback
 Eina_Bool ViewLogic::orientationLockCallback(
     Evas_Object* obj,
@@ -1928,23 +1813,6 @@ Eina_Bool ViewLogic::windowCloseIdlerCallback(void* data)
     return ECORE_CALLBACK_CANCEL;
 }
 
-int ViewLogic::appcoreLowMemoryCallback(void *data)
-{
-    LogInfo("appcoreLowMemoryCallback");
-    Assert(data);
-    ViewLogic* This = static_cast<ViewLogic*>(data);
-
-    if (NULL == This->m_ewkContext) {
-        LogInfo("ewk isn't initialize at this moment");
-    } else {
-        // Crash may occur on specific situation
-        // So use the followings after they become stable
-        //ewk_context_cache_clear(This->m_ewkContext);
-        //ewk_context_notify_low_memory(This->m_ewkContext);
-    }
-
-    return 0;
-}
 
 void ViewLogic::databaseUsagePermissionRequestCallback(
     void* data,
@@ -2029,42 +1897,6 @@ bool ViewLogic::askUserForCertificateConfirm()
                CERTIFICATE_CONFIRM_REQUEST_ASK_BODY);
 }
 
-void ViewLogic::didRecieveMessageFromInjectedBundle(
-    const char* name,
-    const char* /*body*/)
-{
-    LogDebug("did recive message " << name);
-}
-
-void ViewLogic::didReceiveSynchronousMessage(
-    const char* name,
-    const char* body,
-    char** returnData)
-{
-    LogDebug("didReceiveSynchronousMessage called");
-    Assert(name);
-    Assert(returnData);
-
-    if (!body) {
-        LogDebug("body is empty");
-        *returnData = NULL;
-        return;
-    }
-    if (!strcmp(name, uriBlockedMessageName)) {
-        LogDebug("received : " << uriBlockedMessageName);
-        // Currently WebProcess informs obly about blocked
-        // URI - URI localization and security chekcs are
-        // done by WebProcess itself (see: wrt-wk2-bundle.cpp
-        // and bundle_uri_handling.cpp)
-        rememberBlockedURI(DPL::FromUTF8String(body));
-        *returnData = NULL;
-    } else if (!strcmp(name, uriChangedMessageName)) {
-        LogDebug("received : " << uriChangedMessageName);
-        std::string ret = requestUriChanged(DPL::FromUTF8String(body));
-        *returnData = strdup(ret.c_str());
-    }
-}
-
 void ViewLogic::rememberBlockedURI(const DPL::String& inputURI)
 {
     m_blockedUri = DPL::ToUTF8String(inputURI);
index b7006c1..03a8615 100644 (file)
@@ -47,11 +47,10 @@ class ViewLogic : public ViewModule::IViewModule
     ViewLogic();
     virtual ~ViewLogic();
 
+    // IViewModule Impl
     bool createWebView(Ewk_Context* context,
                        Evas_Object* window);
     void destroyWebView();
-    void initialize();
-    void terminate();
     void prepareView(WidgetModel* m, const std::string &startUrl);
     void showWidget();
     void hideWidget();
@@ -63,10 +62,13 @@ class ViewLogic : public ViewModule::IViewModule
     Evas_Object* getCurrentWebview();
     void fireJavascriptEvent(int event, void* data);
     void setUserCallbacks(const WRT::UserDelegatesPtr& cbs);
+    void checkSyncMessageFromBundle(
+            const char* name,
+            const char* body,
+            char** returnData);
+    void downloadData(const char* url);
+    void activateVibration(bool on, uint64_t time);
 
-    // Ewk_Context operations
-    void initializeEwkContext(Ewk_Context* context);
-    void finalizeEwkContext();
 
   private:
     void initializeSupport();
@@ -86,18 +88,6 @@ class ViewLogic : public ViewModule::IViewModule
     void resumeWebkit(Evas_Object *wkView);
     void suspendWebkit(Evas_Object *wkView);
 
-    // message from injected bundle Callback
-    static void contextMessageFromInjectedBundleCallback(
-        const char* name,
-        const char* body,
-        char** returnData,
-        void* userData);
-
-    // EWK Context Callback
-    static void didStartDownloadCallback(
-        const char* downloadUrl,
-        void* data);
-
     // WKPageLoaderClient
     static void loadStartedCallback(
         void* data,
@@ -180,10 +170,6 @@ class ViewLogic : public ViewModule::IViewModule
         Evas_Object* obj,
         void* eventInfo);
 
-    // EWK Vibration Callback
-    static void vibrationVibrateCallback(uint64_t time, void* data);
-    static void vibrationCancelCallback(void* data);
-
     // EWK Orientation Callback
     static Eina_Bool orientationLockCallback(
         Evas_Object* obj,
@@ -270,18 +256,6 @@ class ViewLogic : public ViewModule::IViewModule
     // idler callback
     static Eina_Bool windowCloseIdlerCallback(void *data);
 
-    // appcore event callback
-    static int appcoreLowMemoryCallback(void *data);
-
-    //bundle
-    void didRecieveMessageFromInjectedBundle(
-        const char* name,
-        const char* body);
-    void didReceiveSynchronousMessage(
-        const char* name,
-        const char* body,
-        char** returnData);
-
     // security
     void rememberBlockedURI(const DPL::String& str);
     std::string requestUriChanged(const DPL::String& changedURL);
index 7a17e38..d153cd7 100644 (file)
@@ -15,6 +15,7 @@
  */
 #include "wrt-client.h"
 #include <appcore-efl.h>
+#include <appcore-common.h>
 #include <cstdlib>
 #include <cstdio>
 #include <string>
@@ -127,6 +128,12 @@ void WrtClient::OnReset(bundle *b)
             showHelpAndQuit();
         }
     }
+
+    // low memory callback set
+    appcore_set_event_callback(
+            APPCORE_EVENT_LOW_MEMORY,
+            WrtClient::appcoreLowMemoryCallback,
+            this);
 }
 
 void WrtClient::OnTerminate()
@@ -285,7 +292,7 @@ void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
 void WrtClient::initStep()
 {
     LogDebug("");
-    if (WRT::CoreModuleSingleton::Instance().Init(s_ewk_context)) {
+    if (WRT::CoreModuleSingleton::Instance().Init()) {
         m_initialized = true;
     } else {
         m_returnStatus = ReturnStatus::Failed;
@@ -487,7 +494,7 @@ void WrtClient::launchStep()
     ADD_PROFILING_POINT("Create splash screen", "stop");
     DPL::OptionalString startUrl = W3CFileLocalization::getStartFile(m_dao);
     if (!m_widget->PrepareView(DPL::ToUTF8String(*startUrl),
-                               m_windowData->m_win))
+            m_windowData->m_win, s_ewk_context))
     {
         DPL::Event::ControllerEventHandler<NextStepEvent>::PostEvent(
             NextStepEvent());
@@ -580,6 +587,17 @@ void WrtClient::backButtonCallback(void* data,
     This->m_widget->Backward();
 }
 
+int WrtClient::appcoreLowMemoryCallback(void* data)
+{
+    LogInfo("appcoreLowMemoryCallback");
+    WrtClient* This = static_cast<WrtClient*>(data);
+
+    // TODO call RunnableWidgetObject API regarding low memory
+    // The API should be implemented
+
+    return 0;
+}
+
 void WrtClient::connectElmCallback()
 {
     Assert(m_windowData);
@@ -636,6 +654,7 @@ void WrtClient::shutdownStep()
         m_widgetState = WidgetState_Stopped;
         m_widget->Hide();
         m_widget.reset();
+        ewk_context_delete(s_ewk_context);
         WRT::CoreModuleSingleton::Instance().Terminate();
     }
     if (m_initialized) {
index 334a603..93f2d73 100644 (file)
@@ -82,6 +82,8 @@ class WrtClient :
     static void backButtonCallback(void* data,
                                    Evas_Object* obj,
                                    void* event_info);
+    // Low Memory Callback
+    static int appcoreLowMemoryCallback(void* data);
 
     // launching steps
     void initStep();