From: Dariusz Frankiewicz Date: Tue, 13 Oct 2015 10:16:10 +0000 (+0200) Subject: Add webview suspend and resume functions. X-Git-Tag: accepted/tizen/tv/20151022.010509~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F96%2F49696%2F9;p=profile%2Ftv%2Fapps%2Fweb%2Fbrowser.git Add webview suspend and resume functions. [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 --- diff --git a/core/AbstractWebEngine/AbstractWebEngine.h b/core/AbstractWebEngine/AbstractWebEngine.h index 554c115..39c23c7 100644 --- a/core/AbstractWebEngine/AbstractWebEngine.h +++ b/core/AbstractWebEngine/AbstractWebEngine.h @@ -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; diff --git a/core/BasicUI/AbstractMainWindow.h b/core/BasicUI/AbstractMainWindow.h index 4c1a13a..146ad8f 100644 --- a/core/BasicUI/AbstractMainWindow.h +++ b/core/BasicUI/AbstractMainWindow.h @@ -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 getMainWindow(){return m_window;}; /** @@ -56,6 +56,10 @@ public: */ void setMainWindow(T *rawPtr){ m_window=std::shared_ptr(rawPtr);} virtual void destroyUI() { } + + virtual void suspend() = 0; + virtual void resume() = 0; + protected: std::shared_ptr m_window; }; diff --git a/core/main.cpp b/core/main.cpp index 83d48f0..30f5a94 100755 --- a/core/main.cpp +++ b/core/main.cpp @@ -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> mainUi = + std::dynamic_pointer_cast + < + tizen_browser::base_ui::AbstractMainWindow, + 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> mainUi = + std::dynamic_pointer_cast + < + tizen_browser::base_ui::AbstractMainWindow, + tizen_browser::core::AbstractService + > + (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.simpleui")); + mainUi->resume(); } int main(int argc, char* argv[])try diff --git a/services/SimpleUI/SimpleUI.cpp b/services/SimpleUI/SimpleUI.cpp index 8697e7e..eb15d85 100644 --- a/services/SimpleUI/SimpleUI.cpp +++ b/services/SimpleUI/SimpleUI.cpp @@ -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()); } diff --git a/services/SimpleUI/SimpleUI.h b/services/SimpleUI/SimpleUI.h index f4d41b1..5f59329 100644 --- a/services/SimpleUI/SimpleUI.h +++ b/services/SimpleUI/SimpleUI.h @@ -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: diff --git a/services/WebKitEngineService/WebKitEngineService.cpp b/services/WebKitEngineService/WebKitEngineService.cpp index 11cd07a..0841342 100644 --- a/services/WebKitEngineService/WebKitEngineService.cpp +++ b/services/WebKitEngineService/WebKitEngineService.cpp @@ -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()); diff --git a/services/WebKitEngineService/WebKitEngineService.h b/services/WebKitEngineService/WebKitEngineService.h index 00ec6c7..be37eac 100644 --- a/services/WebKitEngineService/WebKitEngineService.h +++ b/services/WebKitEngineService/WebKitEngineService.h @@ -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); diff --git a/services/WebKitEngineService/WebView.cpp b/services/WebKitEngineService/WebView.cpp index bb42ec7..cef552e 100644 --- a/services/WebKitEngineService/WebView.cpp +++ b/services/WebKitEngineService/WebView.cpp @@ -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) diff --git a/services/WebKitEngineService/WebView.h b/services/WebKitEngineService/WebView.h index 61f6c68..2243c19 100644 --- a/services/WebKitEngineService/WebView.h +++ b/services/WebKitEngineService/WebView.h @@ -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;