From: cookie Date: Mon, 4 Sep 2017 05:04:25 +0000 (+0000) Subject: Fix empty tab opened for window.open request. X-Git-Tag: submit/tizen_4.0/20170908.022150~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0b7feff3a4e09dff70d0804cc09fe652e021a64d;p=profile%2Fmobile%2Fapps%2Fweb%2Fbrowser.git Fix empty tab opened for window.open request. [ 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 --- diff --git a/services/SimpleUI/SimpleUI.cpp b/services/SimpleUI/SimpleUI.cpp index eaca6bd..5da7ffb 100755 --- a/services/SimpleUI/SimpleUI.cpp +++ b/services/SimpleUI/SimpleUI.cpp @@ -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; } diff --git a/services/TabUI/TabUI.cpp b/services/TabUI/TabUI.cpp index 4217b1a..fc8732d 100755 --- a/services/TabUI/TabUI.cpp +++ b/services/TabUI/TabUI.cpp @@ -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(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(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; } diff --git a/services/WebEngineService/WebEngineService.cpp b/services/WebEngineService/WebEngineService.cpp index 6449393..3d60366 100755 --- a/services/WebEngineService/WebEngineService.cpp +++ b/services/WebEngineService/WebEngineService.cpp @@ -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__); diff --git a/services/WebEngineService/WebView.cpp b/services/WebEngineService/WebView.cpp index 76c1498..5618874 100755 --- a/services/WebEngineService/WebView.cpp +++ b/services/WebEngineService/WebView.cpp @@ -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(Config::getInstance().get("TAB_LIMIT")); + if (m_webEngine->tabsCount() >= tabLimit + 1) + return; + if (currentTabId != (id = m_webEngine->addTab(std::string(), boost::none, std::string(),