Fix last shown tab not loaded on relaunch of browser 34/148234/3
authorGajendra N <gajendra.n@samsung.com>
Thu, 7 Sep 2017 07:06:22 +0000 (12:36 +0530)
committerHye Kyoung Hwang <cookie@samsung.com>
Mon, 11 Sep 2017 04:45:32 +0000 (04:45 +0000)
[ Problem ]  Current visible tab is not loaded on browser relaunch.
[ Cause ]    The latest tab which was added to browser-provider tab adaptor
             is assumed as the tab that was vsible when browser was killed.
             The user might have switched to some older tab; in that case,
             the currently opened tab should be loaded on browser relaunch.
[ Solution ] Save the currently visible tab id to browser-provider tab
             adaptor's 'is_activated' property. During browser relaunch,
             i.e restoring last session, check the property and accordingly
             load the tab's url.

Change-Id: I8637d89f531eef456e82c44f66d44594eb81a1a1
Signed-off-by: Gajendra N <gajendra.n@samsung.com>
services/SimpleUI/SimpleUI.cpp
services/SimpleUI/SimpleUI.h
services/TabService/TabService.cpp
services/TabService/TabService.h

index 5da7ffb0d4b66f6ef3403283cf78c0e18caa736b..b462af168148054916cad505c6b5af6b0e719965 100755 (executable)
@@ -326,15 +326,27 @@ void SimpleUI::countCheckUrl() {
     }
 }
 
+void SimpleUI::destroyUI() {
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    m_tabService->setVisibleTabAsActivated(m_webEngine->currentTabId().get());
+    m_webEngine->destroyTabs();
+}
+
 void SimpleUI::restoreLastSession() {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
 
     auto vec(m_tabService->getAllTabs());
+    int lastShownTabId = -1;
     for (const auto& i : *vec) {
+        if (m_tabService->wasTabIdActivated(i.getId().get()))
+            lastShownTabId = i.getId().get();
+
         openNewTab(i.getUrl(), i.getTitle(),
                         boost::optional<int>(i.getId().get()), false,
                         i.getOrigin());
     }
+    if (lastShownTabId != -1)
+        switchToTab(lastShownTabId);
 }
 
 void SimpleUI::loadUIServices() {
index 3b3831bec433f332a248259b6f97c7be2080a558..4534a95726e6feea46c4d45d2cd53869008224c5 100755 (executable)
@@ -94,7 +94,7 @@ public:
     void suspend() final override { m_webEngine->suspend(); };
     void resume() final override;
     void languageChanged() final override { m_languageChanged = true; };
-    void destroyUI() final override { m_webEngine->destroyTabs(); };
+    void destroyUI() final override;
 
     enum class rotationLock {
         noLock = 0,
index efbc4123a86eb2f1a4aecbe36bd606a53d9d1611..8d618df31da527fc2c94edeffd19e6a6972b6cd5 100755 (executable)
@@ -49,6 +49,44 @@ int TabService::createTabId(int tabId) const
     return adaptorId;
 }
 
+bool TabService::wasTabIdActivated(int tabId)
+{
+    BROWSER_LOGD("[%s:%d]", __PRETTY_FUNCTION__, __LINE__);
+    int activated = 0;
+    if (bp_tab_adaptor_get_activated(tabId, &activated) < 0) {
+        errorPrint("bp_tab_adaptor_get_activated");
+    }
+    return activated;
+}
+
+void TabService::setVisibleTabAsActivated(int tabId)
+{
+    BROWSER_LOGD("[%s:%d]", __PRETTY_FUNCTION__, __LINE__);
+    int* items = nullptr;
+    int count;
+    if (bp_tab_adaptor_get_full_ids_p(&items, &count) < 0 || !count) {
+        errorPrint("bp_tab_adaptor_get_full_ids_p");
+        return;
+    }
+    for (int i = 0; i < count; ++i) {
+        if (tabId == items[i])
+            continue;
+
+        bp_tab_info_fmt info;
+        if (bp_tab_adaptor_get_easy_all(items[i], &info) < 0) {
+            errorPrint("bp_tab_adaptor_get_easy_all");
+            continue;
+        }
+        if (bp_tab_adaptor_set_activated(items[i], false) < 0) {
+            errorPrint("bp_tab_adaptor_set_activated");
+            continue;
+        }
+    }
+    if (bp_tab_adaptor_set_activated(tabId, true) < 0) {
+        errorPrint("bp_tab_adaptor_set_activated");
+    }
+}
+
 void TabService::errorPrint(std::string method) const
 {
     int error_code = bp_tab_adaptor_get_errorcode();
index e606d09a6ef5e2fd1b46616407369814690a1b54..f5175a177f629ef1c415718baa95a380e469ea1c 100755 (executable)
@@ -60,6 +60,18 @@ public:
      */
     std::shared_ptr<std::vector<basic_webengine::TabContent> > getAllTabs();
 
+    /**
+     * Sets visible tab as activated while browser is being killed,
+     * so that the tabId's url will be loaded on browser relaunch.
+     */
+    void setVisibleTabAsActivated(int tabId);
+
+    /**
+     * @brief Get activated/deactivated value of the tab.
+     * @return true if activated, false otherwise.
+     */
+    bool wasTabIdActivated(int tabId);
+
     /**
      * Remove image thumb for given id from the cache and database.
      */