Fix empty tab opened for window.open request. 33/147333/1
authorcookie <cookie@samsung.com>
Mon, 4 Sep 2017 05:04:25 +0000 (05:04 +0000)
committercookie <cookie@samsung.com>
Mon, 4 Sep 2017 05:04:25 +0000 (05:04 +0000)
[ Problem ]  When already MAX (20) tabs are opened and there is a request
             to window.open from current tab, an empty tab is opened.
[ Cause ]    When new,window callback is triggered, we need to create
             ewk_view and pass it to WebEngine through 'out' argument.
             ewk_view has to be created before the function is exited but
             it was created after user responds to max window popup which
             is very late.
[ Solution ] Immediately creat ewk_view and pass to WebEngine, while
             showing the popup. Based on the user decision, i.e, for
             CANCEL : close the loaded tab, and show the recent tab.
             OK : close the oldest tab and retain the loaded tab.

Change-Id: I02bddeecff04cd696089462c7275365c8afbf7ab
Signed-off-by: cookie <cookie@samsung.com>
services/SimpleUI/SimpleUI.cpp
services/TabUI/TabUI.cpp
services/WebEngineService/WebEngineService.cpp
services/WebEngineService/WebView.cpp

index eaca6bd354a3b1d36b6bb48eb47cd125805d44f1..5da7ffb0d4b66f6ef3403283cf78c0e18caa736b 100755 (executable)
@@ -2185,14 +2185,18 @@ void SimpleUI::onDeleteSelectedDataButton(const PopupButtons& button,
 
 void SimpleUI::tabLimitPopupButtonClicked(PopupButtons button) {
     BROWSER_LOGD("[%s:%d]", __PRETTY_FUNCTION__, __LINE__);
+
+    // While showing the popup, we have already created new tab for window.open() request,
+    // so when user selects OK button, we retain the tab and close the oldest tab.
+    // Otherwise, i.e, if user selects CANCEL button, we just close the current tab.
     if (button == OK) {
         BROWSER_LOGD("[%s:%d] Closing oldest tab and opening requested",
                         __PRETTY_FUNCTION__, __LINE__);
-        if (m_tabUI->getPopupDecision())
-            m_storageService->getSettingsStorage().setSettingsBool(
-                            TAB_LIMIT_DECISION, true);
+        m_storageService->getSettingsStorage().setSettingsBool(
+                        TAB_LIMIT_DECISION, m_tabUI->getPopupDecision());
         closeOldestTab();
-        switchToTab(m_webEngine->openRequestedPage());
+    } else if (button == CANCEL) {
+        closeTab(m_webEngine->currentTabId());
     }
     while (m_popupVector.size() > 1)
         m_popupVector.front()->onBackPressed();
@@ -2217,8 +2221,8 @@ bool SimpleUI::checkIfCreate() {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
 
     if (m_webEngine->tabsCount() >= m_tabLimit) {
-        if (m_storageService->getSettingsStorage().getSettingsBool(
-                        TAB_LIMIT_DECISION, false)) {
+        if (!(m_storageService->getSettingsStorage().getSettingsBool(
+                        TAB_LIMIT_DECISION, true))) {
             closeOldestTab();
             return true;
         }
index 4217b1aaf5a19714414dbfe69808fbd2e3960a1a..fc8732d160e46b720e6bb6456574cc6ad76ac21f 100755 (executable)
@@ -288,9 +288,10 @@ void TabUI::_decision_check_changed(void* data, Evas_Object* obj, void*)
     BROWSER_LOGD("[%s:%d]", __PRETTY_FUNCTION__, __LINE__);
     if (data && obj) {
         auto self = static_cast<TabUI*>(data);
-        self->m_popup_decision = elm_check_state_get(obj) == EINA_TRUE;
-    } else
+        self->m_popup_decision = elm_check_state_get(obj) == EINA_FALSE;
+    } else {
         BROWSER_LOGW("[%s] data or obj = nullptr", __PRETTY_FUNCTION__);
+    }
 }
 
 void TabUI::_close_clicked(void* data, Evas_Object*, void*)
@@ -689,7 +690,7 @@ Evas_Object * TabUI::_genlist_content_get(void *data, Evas_Object *obj, const ch
             TabUI *self = static_cast<TabUI*>(data);
             auto checkbox = elm_check_add(obj);
             evas_object_smart_callback_add(checkbox, "changed", self->_decision_check_changed, self);
-            elm_check_state_set(checkbox, EINA_TRUE);
+            elm_check_state_set(checkbox, EINA_FALSE);
             evas_object_show(checkbox);
             return checkbox;
         }
index 64493935a8afeb77b5386630ce3010efd01b71b7..3d6036638e0f40adf0053c84eb6e72ef3889a70c 100755 (executable)
@@ -565,7 +565,6 @@ TabId WebEngineService::addTab(
         m_requestedPage.title = title;
         m_requestedPage.desktopMode = desktopMode;
         m_requestedPage.origin = origin;
-        return TabId::NONE;
     }
 
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
index 76c1498f20710a228e09c7592b3052fe65130f1e..5618874e1f680432723103264e2648eaad326b79 100755 (executable)
@@ -603,6 +603,14 @@ void WebView::__newWindowRequest(void *data, Evas_Object *, void *out)
     /// \todo: Choose newly created tab.
     TabId id(TabId::NONE);
     TabId currentTabId = m_webEngine->currentTabId();
+
+    // Some sites may request for multiple window.open, in that case, if already max TAB_LIMIT is
+    // reached then only one additional tab should be allowed to create if user chooses to close
+    // oldest tab.
+    auto tabLimit = boost::any_cast<int>(Config::getInstance().get("TAB_LIMIT"));
+    if (m_webEngine->tabsCount() >= tabLimit + 1)
+        return;
+
     if (currentTabId != (id = m_webEngine->addTab(std::string(),
                                                                  boost::none,
                                                                  std::string(),