From 46e8ae2f3dca678b6e96772f3015fd56d1db5b9e Mon Sep 17 00:00:00 2001 From: Gajendra N Date: Thu, 7 Sep 2017 12:36:22 +0530 Subject: [PATCH] Fix last shown tab not loaded on relaunch of browser [ 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 Signed-off-by: cookie --- services/SimpleUI/SimpleUI.cpp | 12 ++++++++++++ services/SimpleUI/SimpleUI.h | 2 +- services/TabService/TabService.cpp | 38 ++++++++++++++++++++++++++++++++++++++ services/TabService/TabService.h | 12 ++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/services/SimpleUI/SimpleUI.cpp b/services/SimpleUI/SimpleUI.cpp index 5da7ffb..b462af1 100755 --- a/services/SimpleUI/SimpleUI.cpp +++ b/services/SimpleUI/SimpleUI.cpp @@ -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(i.getId().get()), false, i.getOrigin()); } + if (lastShownTabId != -1) + switchToTab(lastShownTabId); } void SimpleUI::loadUIServices() { diff --git a/services/SimpleUI/SimpleUI.h b/services/SimpleUI/SimpleUI.h index 3b3831b..4534a95 100755 --- a/services/SimpleUI/SimpleUI.h +++ b/services/SimpleUI/SimpleUI.h @@ -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, diff --git a/services/TabService/TabService.cpp b/services/TabService/TabService.cpp index efbc412..8d618df 100755 --- a/services/TabService/TabService.cpp +++ b/services/TabService/TabService.cpp @@ -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(); diff --git a/services/TabService/TabService.h b/services/TabService/TabService.h index e606d09..f5175a1 100755 --- a/services/TabService/TabService.h +++ b/services/TabService/TabService.h @@ -61,6 +61,18 @@ public: std::shared_ptr > 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. */ void removeTab(const basic_webengine::TabId& tabId); -- 2.7.4