From 8085f7314fdc6f07f5f756db980a0f950c514998 Mon Sep 17 00:00:00 2001 From: "m.kawonczyk" Date: Mon, 12 Oct 2015 15:11:53 +0200 Subject: [PATCH] Limit number of opened tabs in brower [Issue] https://bugs.tizen.org/jira/browse/TT-174 [Problem] When more than 30 tabs are opened the browser crashes. [Solution] Limit the number of simultaneously opened tabs to 10. If user wants to add another tab, popup is shown. WebCore Part must check, if sending out=NULL in __newWindowRequest doesn't create another bug. [Verification] Please open 10 tabs and try to add another one, with either + in tab manager or "Open link in new tab" in popup. Change-Id: I342fe4dda10e6ae11e2199893ce3a8412c01227e --- core/AbstractWebEngine/AbstractWebEngine.h | 7 +++++- core/Config/Config.cpp | 2 +- services/SimpleUI/SimpleUI.cpp | 25 ++++++++++++++++------ services/SimpleUI/SimpleUI.h | 1 + .../WebKitEngineService/WebKitEngineService.cpp | 8 +++++++ services/WebKitEngineService/WebView.cpp | 20 ++++++++--------- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/core/AbstractWebEngine/AbstractWebEngine.h b/core/AbstractWebEngine/AbstractWebEngine.h index 99f19c9..22e9c55 100644 --- a/core/AbstractWebEngine/AbstractWebEngine.h +++ b/core/AbstractWebEngine/AbstractWebEngine.h @@ -352,11 +352,16 @@ public: boost::signals2::signal currentTabChanged; /** - * New tab was creted. It could be explicit call (by user) or tab could be opened from JavaScript. + * New tab was created. It could be explicit call (by user) or tab could be opened from JavaScript. */ boost::signals2::signal tabCreated; /** + * Checks if tab can be created. + */ + boost::signals2::signal checkIfCreate; + + /** * Tab closed * \param TabId of closed tab */ diff --git a/core/Config/Config.cpp b/core/Config/Config.cpp index dae7cd3..73e387e 100644 --- a/core/Config/Config.cpp +++ b/core/Config/Config.cpp @@ -38,7 +38,7 @@ void DefaultConfig::load(const std::string &) m_data["TOOLTIP_DELAY"] = 0.05; // time from mouse in to tooltip show m_data["TOOLTIP_HIDE_TIMEOUT"] = 2.0; // time from tooltip show to tooltip hide - m_data["TAB_LIMIT"] = 20; // max number of open tabs + m_data["TAB_LIMIT"] = 10; // max number of open tabs m_data["FAVORITES_LIMIT"] = 40; // max number of added favorites # include "ConfigValues.h" diff --git a/services/SimpleUI/SimpleUI.cpp b/services/SimpleUI/SimpleUI.cpp index a0d577a..bf02679 100644 --- a/services/SimpleUI/SimpleUI.cpp +++ b/services/SimpleUI/SimpleUI.cpp @@ -391,6 +391,7 @@ void SimpleUI::connectModelSignals() m_webEngine->loadError.connect(boost::bind(&SimpleUI::loadError, this)); m_webEngine->confirmationRequest.connect(boost::bind(&SimpleUI::handleConfirmationRequest, this, _1)); m_webEngine->tabCreated.connect(boost::bind(&SimpleUI::tabCreated, this)); + m_webEngine->checkIfCreate.connect(boost::bind(&SimpleUI::checkIfCreate, this)); m_webEngine->tabClosed.connect(boost::bind(&SimpleUI::tabClosed,this,_1)); m_webEngine->IMEStateChanged.connect(boost::bind(&SimpleUI::setwvIMEStatus, this, _1)); m_webEngine->favIconChanged.connect(boost::bind(&MoreMenuUI::setFavIcon, m_moreMenuUI.get(), _1)); @@ -662,6 +663,7 @@ void SimpleUI::filterURL(const std::string& url) //check if url is in blocked //no filtering + if (m_webPageUI->isHomePageActive()) openNewTab(url); else @@ -725,6 +727,9 @@ void SimpleUI::closeTabUI() void SimpleUI::newTabClicked() { + if (!checkIfCreate()) + return; + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); switchViewToQuickAccess(); } @@ -1026,18 +1031,24 @@ void SimpleUI::tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< void SimpleUI::tabCreated() { int tabs = m_webEngine->tabsCount(); + m_webPageUI->setTabsNumber(tabs); +} - if (tabs > m_tabLimit) - { +bool SimpleUI::checkIfCreate() +{ + int tabs = m_webEngine->tabsCount(); + + if (tabs >= m_tabLimit) { SimplePopup *popup = SimplePopup::createPopup(); - popup->setTitle("Too many tabs open"); - popup->addButton(CONTINUE); - popup->addButton(CLOSE_TAB); - popup->setMessage("Browser might slow down. Are you sure you want to continue?"); + popup->setTitle("Maximum tab count reached."); + popup->addButton(OK); + popup->setMessage("Close other tabs to open another new tab"); popup->buttonClicked.connect(boost::bind(&SimpleUI::tabLimitPopupButtonClicked, this, _1, _2)); popup->show(); + return false; } - m_webPageUI->setTabsNumber(tabs); + else + return true; } void SimpleUI::updateView() { diff --git a/services/SimpleUI/SimpleUI.h b/services/SimpleUI/SimpleUI.h index 443eff9..74c425a 100644 --- a/services/SimpleUI/SimpleUI.h +++ b/services/SimpleUI/SimpleUI.h @@ -113,6 +113,7 @@ private: void tabClicked(const tizen_browser::basic_webengine::TabId& tabId); void closeTabsClicked(const tizen_browser::basic_webengine::TabId& tabId); void tabCreated(); + bool checkIfCreate(); void tabClosed(const tizen_browser::basic_webengine::TabId& id); std::vector > getBookmarks(int folder_id = -1); diff --git a/services/WebKitEngineService/WebKitEngineService.cpp b/services/WebKitEngineService/WebKitEngineService.cpp index 59a01e7..923ddf3 100644 --- a/services/WebKitEngineService/WebKitEngineService.cpp +++ b/services/WebKitEngineService/WebKitEngineService.cpp @@ -280,6 +280,14 @@ std::vector > WebKitEngineService::getTabContents() TabId WebKitEngineService::addTab(const std::string & uri, const TabId * openerId, bool desktopMode) { + AbstractWebEngine::checkIfCreate(); + + config::DefaultConfig config; + config.load(""); + + if (tabsCount() >= boost::any_cast(config.get("TAB_LIMIT"))) + return currentTabId(); + BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__); // searching for next available tabId diff --git a/services/WebKitEngineService/WebView.cpp b/services/WebKitEngineService/WebView.cpp index 1d03786..33170c5 100644 --- a/services/WebKitEngineService/WebView.cpp +++ b/services/WebKitEngineService/WebView.cpp @@ -501,11 +501,12 @@ void WebView::__newWindowRequest(void *data, Evas_Object *, void *out) M_ASSERT(m_webEngine); /// \todo: Choose newly created tab. - TabId id = m_webEngine->addTab(std::string(), &self->getTabId()); - BROWSER_LOGD("Created tab: %s", id.toString().c_str()); - - Evas_Object* tab_ewk_view = m_webEngine->getTabView(id); - *static_cast(out) = tab_ewk_view; + TabId id; + if (m_webEngine->currentTabId() != (id = m_webEngine->addTab(std::string(), &self->getTabId()))) { + BROWSER_LOGD("Created tab: %s", id.toString().c_str()); + Evas_Object* tab_ewk_view = m_webEngine->getTabView(id); + *static_cast(out) = tab_ewk_view; + } } void WebView::__closeWindowRequest(void *data, Evas_Object *, void *) @@ -546,6 +547,7 @@ void WebView::__loadFinished(void * data, Evas_Object * /* obj */, void * /* eve BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__); WebView * self = reinterpret_cast(data); + self->m_isLoading = false; self->m_loadProgress = 1; @@ -561,7 +563,6 @@ void WebView::__loadProgress(void * data, Evas_Object * /* obj */, void * event_ WebView * self = reinterpret_cast(data); self->m_loadProgress = *(double *)event_info; - self->loadProgress(self->m_loadProgress); } @@ -597,7 +598,6 @@ void WebView::__titleChanged(void * data, Evas_Object * obj, void * /* event_inf WebView * self = reinterpret_cast(data); self->m_title = fromChar(ewk_view_title_get(obj)); - self->titleChanged(self->m_title); } @@ -801,7 +801,7 @@ bool WebView::hasFocus() const double WebView::getZoomFactor() const { - if(EINA_UNLIKELY(m_ewkView == nullptr)){ + if(EINA_UNLIKELY(m_ewkView == nullptr)) { return 1.0; } @@ -815,7 +815,7 @@ double WebView::getZoomFactor() const void WebView::setZoomFactor(double zoomFactor) { #if defined(USE_EWEBKIT) - if(m_ewkView){ + if(m_ewkView) { //using zoomFactor = 0 sets zoom "fit to screen" if(zoomFactor != getZoomFactor()) @@ -829,7 +829,7 @@ void WebView::scrollView(const int& dx, const int& dy) ewk_view_scroll_by(m_ewkView, dx, dy); } -const TabId& WebView::getTabId(){ +const TabId& WebView::getTabId() { return m_tabId; } -- 2.7.4