Add webview suspend and resume functions. 96/49696/9
authorDariusz Frankiewicz <d.frankiewic@samsung.com>
Tue, 13 Oct 2015 10:16:10 +0000 (12:16 +0200)
committerDariusz Frankiewicz <d.frankiewic@samsung.com>
Wed, 21 Oct 2015 07:33:06 +0000 (09:33 +0200)
[Issue]    https://bugs.tizen.org/jira/browse/TT-208
[Problem]  ewk_view_suspend and ewk_view_resume are not called in
           required moments.
[Cause]    Not implemented function calls.
[Solution] Implement required functions and it's calls.
[Verify]   Open few tabs, try to switch between them.
           Suspend and resume browser.

Change-Id: I9f292a0c316056e3d2c928332bd47a58e9eba23a
Signed-off-by: Dariusz Frankiewicz <d.frankiewic@samsung.com>
core/AbstractWebEngine/AbstractWebEngine.h
core/BasicUI/AbstractMainWindow.h
core/main.cpp
services/SimpleUI/SimpleUI.cpp
services/SimpleUI/SimpleUI.h
services/WebKitEngineService/WebKitEngineService.cpp
services/WebKitEngineService/WebKitEngineService.h
services/WebKitEngineService/WebView.cpp
services/WebKitEngineService/WebView.h

index 554c115..39c23c7 100644 (file)
@@ -74,6 +74,21 @@ public:
     virtual std::string getTitle(void) const = 0;
 
     /**
+     * Suspend current webview.
+     */
+    virtual void suspend(void) = 0;
+
+    /**
+     * Resume current webview.
+     */
+    virtual void resume(void) = 0;
+
+    /**
+     * @return true if current webview is suspended, false otherwise
+     */
+    virtual bool isSuspended(void) const = 0;
+
+    /**
      * Stop loading current page.
      */
     virtual void stopLoading(void) = 0;
index 4c1a13a..146ad8f 100644 (file)
@@ -47,7 +47,7 @@ public:
         : m_window()
     {}
 
-    virtual int exec(const std::string& url)=0;
+    virtual int exec(const std::string& url) = 0;
     std::shared_ptr<T> getMainWindow(){return m_window;};
 
     /**
@@ -56,6 +56,10 @@ public:
      */
     void setMainWindow(T *rawPtr){ m_window=std::shared_ptr<T>(rawPtr);}
     virtual void destroyUI() { }
+
+    virtual void suspend() = 0;
+    virtual void resume() = 0;
+
 protected:
     std::shared_ptr<T> m_window;
 };
index 83d48f0..30f5a94 100755 (executable)
@@ -120,10 +120,28 @@ static void app_service(service_h service, void */*app_data*/){
 
 static void app_pause(void *){
     BROWSER_LOGD("%s", __PRETTY_FUNCTION__);
+
+    std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
+    std::dynamic_pointer_cast
+    <
+        tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
+        tizen_browser::core::AbstractService
+    >
+    (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
+    mainUi->suspend();
 }
 
 static void app_resume(void *){
     BROWSER_LOGD("%s", __PRETTY_FUNCTION__);
+
+    std::shared_ptr<tizen_browser::base_ui::AbstractMainWindow<Evas_Object>> mainUi =
+    std::dynamic_pointer_cast
+    <
+        tizen_browser::base_ui::AbstractMainWindow<Evas_Object>,
+        tizen_browser::core::AbstractService
+    >
+    (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui"));
+    mainUi->resume();
 }
 
 int main(int argc, char* argv[])try
index 8697e7e..eb15d85 100644 (file)
@@ -440,6 +440,8 @@ void SimpleUI::switchViewToWebPage()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     M_ASSERT(m_viewManager);
+    if(m_webEngine->isSuspended())
+        m_webEngine->resume();
     m_webPageUI->switchViewToWebPage(m_webEngine->getLayout(), m_webEngine->getURI(), m_webEngine->getTitle());
 }
 
index f4d41b1..5f59329 100644 (file)
@@ -71,6 +71,8 @@ public:
     virtual ~SimpleUI();
     virtual int exec(const std::string& url);
     virtual std::string getName();
+    void suspend() {m_webEngine->suspend();}
+    void resume() {m_webEngine->resume();}
 
     void destroyUI();
 private:
index 11cd07a..0841342 100644 (file)
@@ -143,6 +143,28 @@ std::string WebKitEngineService::getTitle() const
         return std::string("");
 }
 
+void WebKitEngineService::suspend()
+{
+    if(tabsCount()>0) {
+        M_ASSERT(m_currentWebView);
+        m_currentWebView->suspend();
+    }
+}
+
+void WebKitEngineService::resume()
+{
+    if(tabsCount()>0) {
+        M_ASSERT(m_currentWebView);
+        m_currentWebView->resume();
+    }
+}
+
+bool WebKitEngineService::isSuspended() const
+{
+    M_ASSERT(m_currentWebView);
+    return m_currentWebView->isSuspended();
+}
+
 void WebKitEngineService::stopLoading(void)
 {
     M_ASSERT(m_currentWebView);
@@ -323,6 +345,7 @@ bool WebKitEngineService::switchToTab(tizen_browser::basic_webengine::TabId newT
     // if there was any running WebView
     if (m_currentWebView) {
         disconnectSignals(m_currentWebView);
+        suspend();
     }
 
     m_currentWebView = m_tabs[newTabId];
@@ -331,6 +354,7 @@ bool WebKitEngineService::switchToTab(tizen_browser::basic_webengine::TabId newT
     m_mostRecentTab.push_back(newTabId);
 
     connectSignals(m_currentWebView);
+    resume();
 
     titleChanged(m_currentWebView->getTitle());
     uriChanged(m_currentWebView->getURI());
index 00ec6c7..be37eac 100644 (file)
@@ -53,6 +53,10 @@ public:
 
     std::string getTitle(void) const;
 
+    void suspend(void);
+    void resume(void);
+    bool isSuspended(void) const;
+
     void stopLoading(void);
     void reload(void);
 
index bb42ec7..cef552e 100644 (file)
@@ -71,6 +71,7 @@ WebView::WebView(Evas_Object * obj, TabId tabId)
     , m_ewkView(nullptr)
     , m_isLoading(false)
     , m_loadError(false)
+    , m_suspended(false)
     , m_private(-1)
 {
     config.load("whatever");
@@ -117,6 +118,7 @@ void WebView::init(bool desktopMode, Evas_Object * opener)
 
     setupEwkSettings();
     registerCallbacks();
+    resume();
 #else
     m_ewkView = evas_object_rectangle_add(evas_object_evas_get(m_parent));
 #endif
@@ -224,6 +226,24 @@ std::string WebView::getTitle(void)
     return m_title;
 }
 
+void WebView::suspend()
+{
+    BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
+    M_ASSERT(m_ewkView);
+
+    ewk_view_suspend(m_ewkView);
+    m_suspended = true;
+}
+
+void WebView::resume()
+{
+    BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
+    M_ASSERT(m_ewkView);
+
+    ewk_view_resume(m_ewkView);
+    m_suspended = false;
+}
+
 void WebView::stopLoading(void)
 {
 #if defined(USE_EWEBKIT)
index 61f6c68..2243c19 100644 (file)
@@ -48,6 +48,10 @@ public:
 
     std::string getTitle(void);
 
+    void suspend(void);
+    void resume(void);
+    bool isSuspended(void) const { return m_suspended; }
+
     void stopLoading(void);
     void reload(void);
 
@@ -223,6 +227,7 @@ private:
     bool m_loadError;
     // true if desktop view is enabled, false if mobile
     bool m_desktopMode;
+    bool m_suspended;
     int m_private;
 
     config::DefaultConfig config;