Fix for unpresent tab id 22/75122/2
authorMaciej Skrzypkowski <m.skrzypkows@samsung.com>
Thu, 16 Jun 2016 14:22:47 +0000 (16:22 +0200)
committerHye Kyoung Hwang <cookie@samsung.com>
Fri, 17 Jun 2016 06:25:35 +0000 (23:25 -0700)
[Issue]       http://suprem.sec.samsung.net/jira/browse/TWF-1507
[Problem]      There was no check for tab existence in web engine
[Solution]     added check
[Verify]       open few tabs, browse, close all, open some again

Change-Id: Iecd7dd26af085efa81b872e9c8aeee09a374810f
Signed-off-by: Maciej Skrzypkowski <m.skrzypkows@samsung.com>
services/WebEngineService/WebEngineService.cpp

index e61dfae7e98256974bf8262647b687c6a3cb1806..ae2c25e1bf7c0e2db6ae20dce3339c0bda98d622 100644 (file)
@@ -501,6 +501,10 @@ TabId WebEngineService::addTab(const std::string & uri,
 }
 
 Evas_Object* WebEngineService::getTabView(TabId id){
+    if (m_tabs.find(id) == m_tabs.end()) {
+        BROWSER_LOGW("[%s:%d] there is no tab of id %d", __PRETTY_FUNCTION__, __LINE__, id.get());
+        return nullptr;
+    }
     return m_tabs[id]->getLayout();
 }
 
@@ -514,6 +518,11 @@ bool WebEngineService::switchToTab(tizen_browser::basic_webengine::TabId newTabI
         suspend();
     }
 
+    if (m_tabs.find(newTabId) == m_tabs.end()) {
+        BROWSER_LOGW("[%s:%d] there is no tab of id %d", __PRETTY_FUNCTION__, __LINE__, newTabId.get());
+        return false;
+    }
+
     m_currentWebView = m_tabs[newTabId];
     m_currentTabId = newTabId;
     m_mostRecentTab.erase(std::remove(m_mostRecentTab.begin(), m_mostRecentTab.end(), newTabId), m_mostRecentTab.end());
@@ -584,6 +593,10 @@ void WebEngineService::confirmationResult(WebConfirmationPtr c)
 bool WebEngineService::isPrivateMode(const TabId& id)
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    if (m_tabs.find(id) == m_tabs.end()) {
+        BROWSER_LOGW("[%s:%d] there is no tab of id %d", __PRETTY_FUNCTION__, __LINE__, id.get());
+        return false;
+    }
     return m_tabs[id]->isPrivateMode();
 }
 
@@ -599,6 +612,10 @@ std::shared_ptr<tizen_browser::tools::BrowserImage> WebEngineService::getSnapsho
 
 std::shared_ptr<tizen_browser::tools::BrowserImage> WebEngineService::getSnapshotData(TabId id, int width, int height, bool async,
         tizen_browser::tools::SnapshotType snapshot_type){
+    if (m_tabs.find(id) == m_tabs.end()) {
+        BROWSER_LOGW("[%s:%d] there is no tab of id %d", __PRETTY_FUNCTION__, __LINE__, id.get());
+        return std::shared_ptr<tizen_browser::tools::BrowserImage>();
+    }
    return m_tabs[id]->captureSnapshot(width, height, async, snapshot_type);
 }