Back to previous tab on back key 15/72715/5
authorMaciej Skrzypkowski <m.skrzypkows@samsung.com>
Thu, 2 Jun 2016 08:59:45 +0000 (10:59 +0200)
committerMaciej Skrzypkowski <m.skrzypkows@samsung.com>
Thu, 2 Jun 2016 08:59:45 +0000 (10:59 +0200)
[Issue]        http://suprem.sec.samsung.net/jira/browse/TWF-1280
[Problem]      When back key was pressed and there was no previous site
               browser closed.
[Solution]     Remembering of previous tab.
[Verify]       Go to news.google.com, open any news, it'll open
               in new tab, press back key, tab should be closed
               previous tab should be shown.

Change-Id: Ib7157b3076fe492c79a37b8d36cd53e4170d5818
Signed-off-by: Maciej Skrzypkowski <m.skrzypkows@samsung.com>
core/AbstractWebEngine/AbstractWebEngine.h
services/WebEngineService/Origin.h [new file with mode: 0644]
services/WebEngineService/WebEngineService.cpp
services/WebEngineService/WebEngineService.h
services/WebEngineService/WebView.cpp
services/WebEngineService/WebView.h

index cd5f74ba429e535209f3eada5c92fd0f98dfab13..4b2a215f44237f67dab1d860a54cdaeb51058f79 100644 (file)
@@ -179,7 +179,8 @@ public:
             const boost::optional<int> tabId = boost::none,
             const std::string& title = std::string(),
             bool desktopMode = true,
-            bool incognitoMode = false) = 0;
+            bool incognitoMode = false,
+            int origin = 0) = 0;
 
     /**
      * @param tab id
diff --git a/services/WebEngineService/Origin.h b/services/WebEngineService/Origin.h
new file mode 100644 (file)
index 0000000..04563f7
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ORIGIN_H_
+#define ORIGIN_H_
+
+
+namespace tizen_browser {
+namespace basic_webengine {
+namespace webengine_service {
+
+/*
+ * Container for webview origin id value
+ */
+class Origin
+{
+public:
+    static const int UNKNOWN = -1;
+    static const int QUICKACCESS = -2;
+    Origin() : m_value(UNKNOWN) { }
+    Origin(int from) : m_value(from) { }
+    int getValue() const { return m_value; }
+    void setValue(int value) { m_value = value; }
+    bool isFromWebView() const { return m_value >= 0; }
+private:
+    int m_value;
+
+};
+
+
+}
+}
+}
+
+#endif
\ No newline at end of file
index eb62d37cf801a0ec9d3ba971f1f343b1dde6721e..3dbc28fd1e2ad9f84e36cfd5ad75aa8da78960b8 100644 (file)
@@ -377,7 +377,7 @@ std::vector<TabContentPtr> WebEngineService::getTabContents() const {
 
 TabId WebEngineService::addTab(const std::string & uri,
         const TabId * tabInitId, const boost::optional<int> tabId,
-        const std::string& title, bool desktopMode, bool incognitoMode)
+        const std::string& title, bool desktopMode, bool incognitoMode, int origin)
 {
     if (!(*AbstractWebEngine::checkIfCreate()))
         return currentTabId();
@@ -396,9 +396,9 @@ TabId WebEngineService::addTab(const std::string & uri,
     m_webViewCacheInitialized = true;
     WebViewPtr p = std::make_shared<WebView>(reinterpret_cast<Evas_Object *>(m_guiParent), newTabId, title, incognitoMode);
     if (tabInitId)
-        p->init(desktopMode, getTabView(*tabInitId));
+        p->init(desktopMode, origin, getTabView(*tabInitId));
     else
-        p->init(desktopMode);
+        p->init(desktopMode, origin);
 
     m_tabs[newTabId] = p;
 
@@ -697,7 +697,10 @@ void WebEngineService::backButtonClicked()
         m_currentWebView->back();
     } else if (m_currentWebView->isPrivateMode()) {
         closeTab();
-        switchToWebPage();
+    } else if (m_currentWebView->getOrigin().isFromWebView() && m_tabs.find(m_currentWebView->getOrigin().getValue()) != m_tabs.end()) {
+        int switchTo = m_currentWebView->getOrigin().getValue();
+        closeTab();
+        switchToTab(switchTo);
     } else {
         tools::ui_app_pause();
     }
index 2cb86e24dd1257972b3ec054674c48314e560280..9c671de7264589eb5e334f648ff0a482ff287f85 100644 (file)
@@ -30,6 +30,7 @@
 #include "AbstractWebEngine/WebConfirmation.h"
 #include "SnapshotType.h"
 #include "BrowserImage.h"
+#include "Origin.h"
 
 namespace tizen_browser {
 namespace basic_webengine {
@@ -100,7 +101,8 @@ public:
             const boost::optional<int> tabId = boost::none,
             const std::string& title = std::string(),
             bool desktopMode = true,
-            bool incognitoMode = false);
+            bool incognitoMode = false,
+            int origin = Origin::UNKNOWN);
     Evas_Object* getTabView(TabId id);
     bool switchToTab(TabId);
     bool closeTab();
index b6212ff09b46c1f38e593c0a40ec87f89188b150..085d98732963fc4c2a203810ae65cc42a688736d 100755 (executable)
@@ -107,7 +107,7 @@ WebView::~WebView()
 #endif
 }
 
-void WebView::init(bool desktopMode, Evas_Object*)
+void WebView::init(bool desktopMode, int origin, Evas_Object*)
 {
     m_ewkView = m_private ? ewk_view_add_in_incognito_mode(evas_object_evas_get(m_parent)) :
                             ewk_view_add_with_context(evas_object_evas_get(m_parent), ewk_context_default_get());
@@ -128,6 +128,7 @@ void WebView::init(bool desktopMode, Evas_Object*)
     } else {
         switchToMobileMode();
     }
+    m_origin.setValue(origin);
 
     ewk_context_cache_model_set(m_ewkContext, EWK_CACHE_MODEL_PRIMARY_WEBBROWSER);
     std::string path = app_get_data_path() + COOKIES_PATH;
@@ -872,12 +873,14 @@ void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
 
     /// \todo: Choose newly created tab.
     TabId id(TabId::NONE);
-    if (m_webEngine->currentTabId() != (id = m_webEngine->addTab(std::string(),
+    TabId currentTabId = m_webEngine->currentTabId();
+    if (currentTabId != (id = m_webEngine->addTab(std::string(),
                                                                  &self->getTabId(),
                                                                  boost::none,
                                                                  std::string(),
                                                                  self->isDesktopMode(),
-                                                                 self->isPrivateMode()))) {
+                                                                 self->isPrivateMode(),
+                                                                 currentTabId.get()))) {
         BROWSER_LOGD("Created tab: %s", id.toString().c_str());
         Evas_Object* tab_ewk_view = m_webEngine->getTabView(id);
         *static_cast<Evas_Object**>(out) = tab_ewk_view;
index bf1fb1308f5a9b1828d3cadc17f3e49234b97985..45dc3f2e75e521bd08b219a669ef34e55a8d3fae 100644 (file)
@@ -29,6 +29,7 @@
 #include "SnapshotType.h"
 #include "AbstractWebEngine/TabId.h"
 #include "AbstractWebEngine/WebConfirmation.h"
+#include "Origin.h"
 
 #if PROFILE_MOBILE
 #include "DownloadControl/DownloadControl.h"
@@ -75,7 +76,7 @@ class WebView
 public:
     WebView(Evas_Object *, TabId, const std::string& title, bool incognitoMode);
     virtual ~WebView();
-    void init(bool desktopMode, Evas_Object * view = NULL);
+    void init(bool desktopMode, int origin, Evas_Object * view = NULL);
 
 #if PROFILE_MOBILE
     virtual void orientationChanged() override;
@@ -197,6 +198,8 @@ public:
      */
     void scrollView(const int& dx, const int& dy);
 
+    Origin getOrigin() { return m_origin; }
+
 #if PROFILE_MOBILE
     /**
      * @brief Searches for word in the current page.
@@ -375,6 +378,7 @@ private:
     bool m_suspended;
     bool m_private;
     bool m_fullscreen;
+    Origin m_origin;
 
     std::map<CertificateConfirmationPtr, Ewk_Certificate_Policy_Decision *> m_confirmationCertificatenMap;