Limit number of opened tabs in brower 23/49323/15 accepted/tizen/tv/20151020.020053 submit/tizen_tv/20151019.233835
authorm.kawonczyk <m.kawonczyk@samsung.com>
Mon, 12 Oct 2015 13:11:53 +0000 (15:11 +0200)
committerJanusz Majnert <j.majnert@samsung.com>
Mon, 19 Oct 2015 12:30:17 +0000 (05:30 -0700)
[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
core/Config/Config.cpp
services/SimpleUI/SimpleUI.cpp
services/SimpleUI/SimpleUI.h
services/WebKitEngineService/WebKitEngineService.cpp
services/WebKitEngineService/WebView.cpp

index 99f19c9..22e9c55 100644 (file)
@@ -352,11 +352,16 @@ public:
     boost::signals2::signal<void (TabId)> 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<void ()> tabCreated;
 
     /**
+    * Checks if tab can be created.
+    */
+    boost::signals2::signal<bool ()> checkIfCreate;
+
+    /**
      * Tab closed
      * \param TabId of closed tab
      */
index dae7cd3..73e387e 100644 (file)
@@ -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"
index a0d577a..bf02679 100644 (file)
@@ -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() {
index 443eff9..74c425a 100644 (file)
@@ -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<std::shared_ptr<tizen_browser::services::BookmarkItem> > getBookmarks(int folder_id = -1);
index 59a01e7..923ddf3 100644 (file)
@@ -280,6 +280,14 @@ std::vector<std::shared_ptr<TabContent> > 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<int>(config.get("TAB_LIMIT")))
+        return currentTabId();
+
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
 
     // searching for next available tabId
index 1d03786..33170c5 100644 (file)
@@ -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<Evas_Object**>(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<Evas_Object**>(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<WebView *>(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<WebView *>(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<WebView *>(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;
 }