Limit number of opened tabs in brower
[profile/tv/apps/web/browser.git] / services / SimpleUI / SimpleUI.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "browser_config.h"
18
19 #if defined(USE_EWEBKIT)
20 #include <ewk_chromium.h>
21 #endif
22
23 #include <boost/any.hpp>
24 #include <memory>
25 #include <algorithm>
26 #include <Elementary.h>
27 #include <Ecore.h>
28 #include <Ecore_Wayland.h>
29 #include <Edje.h>
30 #include <Evas.h>
31 #include "Config.h"
32
33 #include "BrowserLogger.h"
34 #include "ServiceManager.h"
35 #include "AbstractWebEngine.h"
36 #include "TabId.h"
37 #include "Tools/EflTools.h"
38 #include "BrowserImage.h"
39 #include "SimpleUI.h"
40 #include "BookmarkItem.h"
41 #include "Tools/EflTools.h"
42 #include "BrowserImage.h"
43 #include "HistoryItem.h"
44 #include "BookmarkItem.h"
45 #include "boost/date_time/gregorian/gregorian.hpp"
46 #include "boost/date_time/posix_time/posix_time.hpp"
47 #include "SqlStorage.h"
48 #include "DetailPopup.h"
49 #include "NotificationPopup.h"
50
51
52 namespace tizen_browser{
53 namespace base_ui{
54
55 EXPORT_SERVICE(SimpleUI, "org.tizen.browser.simpleui")
56
57 const std::string HomePageURL = "about:home";
58 const int ROOT_FOLDER = 0;
59
60
61 SimpleUI::SimpleUI()
62     : AbstractMainWindow()
63     , m_popup(nullptr)
64     , m_webPageUI()
65     , m_moreMenuUI()
66     , m_bookmarkManagerUI()
67     , m_quickAccess()
68     , m_historyUI()
69     , m_settingsUI()
70     , m_tabUI()
71     , m_initialised(false)
72     , m_wvIMEStatus(false)
73     , m_ewkContext(ewk_context_new())
74 {
75     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
76     elm_init(0, nullptr);
77     Evas_Object *main_window = elm_win_util_standard_add("browserApp", "browserApp");
78     if (main_window == nullptr)
79         BROWSER_LOGE("Failed to create main window");
80
81     setMainWindow(main_window);
82     m_viewManager = new ViewManager(main_window);
83     evas_object_size_hint_weight_set(main_window, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
84     evas_object_size_hint_align_set (main_window, EVAS_HINT_FILL, EVAS_HINT_FILL);
85
86     elm_win_resize_object_add(main_window, m_viewManager->getContent());
87     evas_object_show(main_window);
88 }
89
90 SimpleUI::~SimpleUI() {
91     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
92     m_sessionService->getStorage()->deleteSession(m_currentSession);
93     evas_object_del(m_window.get());
94     ewk_context_delete(m_ewkContext);
95 }
96
97 void SimpleUI::destroyUI()
98 {
99     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
100     evas_object_del(m_window.get());
101 }
102
103 std::string SimpleUI::edjePath(const std::string &file)
104 {
105     return std::string(EDJE_DIR) + file;
106 }
107
108 std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > SimpleUI::getBookmarks(int folder_id)
109 {
110     return m_favoriteService->getBookmarks(folder_id);
111 }
112
113 std::shared_ptr<services::HistoryItemVector> SimpleUI::getMostVisitedItems()
114 {
115     return m_historyService->getMostVisitedHistoryItems();
116 }
117
118 std::shared_ptr<services::HistoryItemVector> SimpleUI::getHistory()
119 {
120     return m_historyService->getHistoryToday();
121 }
122
123 int SimpleUI::exec(const std::string& _url)
124 {
125     BROWSER_LOGD("[%s] _url=%s, initialised=%d", __func__, _url.c_str(), m_initialised);
126     std::string url = _url;
127
128     if(!m_initialised){
129         if (m_window.get()) {
130             config::DefaultConfig config;
131             config.load("");
132             m_tabLimit = boost::any_cast <int> (config.get("TAB_LIMIT"));
133             m_favoritesLimit = boost::any_cast <int> (config.get("FAVORITES_LIMIT"));
134
135
136             loadUIServices();
137             loadModelServices();
138             createActions();
139
140             // initModelServices() needs to be called after initUIServices()
141             initUIServices();
142             initModelServices();
143
144
145             connectModelSignals();
146             connectUISignals();
147             connectActions();
148
149             //Push first view to stack.
150             m_viewManager->pushViewToStack(m_webPageUI.get());
151         }
152         m_initialised = true;
153     }
154
155     m_currentSession = std::move(m_sessionService->getStorage()->createSession());
156
157     if (url.empty())
158     {
159         BROWSER_LOGD("[%s]: changing to homeUrl", __func__);
160         switchViewToQuickAccess();
161         restoreLastSession();
162     } else {
163         openNewTab(url);
164     }
165
166     BROWSER_LOGD("[%s]:%d url=%s", __func__, __LINE__, url.c_str());
167     return 0;
168 }
169
170 void SimpleUI::restoreLastSession()
171 {
172     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
173     M_ASSERT(m_sessionService);
174     Session::Session lastSession = std::move(m_sessionService->getStorage()->getLastSession());
175     if(lastSession.items().size() >= 1)
176     {
177         for(auto iter=lastSession.items().begin(), end=lastSession.items().end(); iter != end; ++iter)
178         {
179             openNewTab(iter->second);
180         }
181         m_sessionService->getStorage()->deleteSession(lastSession);
182     }
183 }
184
185
186 //TODO: Move all service creation here:
187 void SimpleUI::loadUIServices()
188 {
189     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
190
191     m_webPageUI =
192         std::dynamic_pointer_cast
193         <tizen_browser::base_ui::WebPageUI,tizen_browser::core::AbstractService>
194         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webpageui"));
195
196     m_quickAccess =
197         std::dynamic_pointer_cast
198         <tizen_browser::base_ui::QuickAccess,tizen_browser::core::AbstractService>
199         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.quickaccess"));
200
201     m_tabUI =
202         std::dynamic_pointer_cast
203         <tizen_browser::base_ui::TabUI,tizen_browser::core::AbstractService>
204         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.tabui"));
205
206     m_historyUI =
207         std::dynamic_pointer_cast
208         <tizen_browser::base_ui::HistoryUI,tizen_browser::core::AbstractService>
209         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.historyui"));
210
211     m_settingsUI =
212         std::dynamic_pointer_cast
213         <tizen_browser::base_ui::SettingsUI,tizen_browser::core::AbstractService>
214         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.settingsui"));
215
216     m_moreMenuUI =
217         std::dynamic_pointer_cast
218         <tizen_browser::base_ui::MoreMenuUI,tizen_browser::core::AbstractService>
219         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.moremenuui"));
220
221     m_bookmarkManagerUI =
222         std::dynamic_pointer_cast
223         <tizen_browser::base_ui::BookmarkManagerUI,tizen_browser::core::AbstractService>
224         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.bookmarkmanagerui"));
225
226     m_zoomUI =
227         std::dynamic_pointer_cast
228         <tizen_browser::base_ui::ZoomUI, tizen_browser::core::AbstractService>
229         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.zoomui"));
230 }
231
232 void SimpleUI::connectUISignals()
233 {
234     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
235
236     M_ASSERT(m_webPageUI.get());
237     m_webPageUI->getURIEntry().uriChanged.connect(boost::bind(&SimpleUI::filterURL, this, _1));
238     m_webPageUI->backPage.connect(boost::bind(&SimpleUI::switchViewToWebPage, this));
239     m_webPageUI->backPage.connect(boost::bind(&tizen_browser::basic_webengine::AbstractWebEngine<Evas_Object>::back, m_webEngine.get()));
240     m_webPageUI->reloadPage.connect(boost::bind(&SimpleUI::switchViewToWebPage, this));
241     m_webPageUI->showTabUI.connect(boost::bind(&SimpleUI::showTabUI, this));
242     m_webPageUI->showMoreMenu.connect(boost::bind(&SimpleUI::showMoreMenu, this));
243     m_webPageUI->forwardPage.connect(boost::bind(&tizen_browser::basic_webengine::AbstractWebEngine<Evas_Object>::forward, m_webEngine.get()));
244     m_webPageUI->stopLoadingPage.connect(boost::bind(&tizen_browser::basic_webengine::AbstractWebEngine<Evas_Object>::stopLoading, m_webEngine.get()));
245     m_webPageUI->reloadPage.connect(boost::bind(&tizen_browser::basic_webengine::AbstractWebEngine<Evas_Object>::reload, m_webEngine.get()));
246     m_webPageUI->showQuickAccess.connect(boost::bind(&SimpleUI::showQuickAccess, this));
247     m_webPageUI->hideQuickAccess.connect(boost::bind(&QuickAccess::hideUI, m_quickAccess));
248
249
250     M_ASSERT(m_quickAccess.get());
251     m_quickAccess->getDetailPopup().openURLInNewTab.connect(boost::bind(&SimpleUI::onOpenURLInNewTab, this, _1, _2));
252     m_quickAccess->openURLInNewTab.connect(boost::bind(&SimpleUI::onOpenURLInNewTab, this, _1, _2));
253     m_quickAccess->mostVisitedTileClicked.connect(boost::bind(&SimpleUI::onMostVisitedTileClicked, this, _1, _2));
254     m_quickAccess->mostVisitedClicked.connect(boost::bind(&SimpleUI::onMostVisitedClicked, this));
255     m_quickAccess->bookmarkClicked.connect(boost::bind(&SimpleUI::onBookmarkButtonClicked, this));
256     m_quickAccess->bookmarkManagerClicked.connect(boost::bind(&SimpleUI::showBookmarkManagerUI, this));
257
258     M_ASSERT(m_tabUI.get());
259     m_tabUI->closeTabUIClicked.connect(boost::bind(&SimpleUI::closeTabUI, this));
260     m_tabUI->newTabClicked.connect(boost::bind(&SimpleUI::newTabClicked, this));
261     m_tabUI->tabClicked.connect(boost::bind(&SimpleUI::tabClicked, this,_1));
262     m_tabUI->closeTabsClicked.connect(boost::bind(&SimpleUI::closeTabsClicked, this,_1));
263     m_tabUI->newIncognitoTabClicked.connect(boost::bind(&SimpleUI::newTabClicked, this));
264     m_tabUI->tabsCount.connect(boost::bind(&SimpleUI::tabsCount, this));
265
266     M_ASSERT(m_historyUI.get());
267     m_historyUI->clearHistoryClicked.connect(boost::bind(&SimpleUI::onClearHistoryClicked, this));
268     m_historyUI->closeHistoryUIClicked.connect(boost::bind(&SimpleUI::closeHistoryUI, this));
269     // desktop mode as default
270     m_historyUI->historyItemClicked.connect(boost::bind(&SimpleUI::onOpenURLInNewTab, this, _1, true));
271
272     M_ASSERT(m_settingsUI.get());
273     m_settingsUI->closeSettingsUIClicked.connect(boost::bind(&SimpleUI::closeSettingsUI, this));
274     m_settingsUI->deleteSelectedDataClicked.connect(boost::bind(&SimpleUI::settingsDeleteSelectedData, this,_1));
275     m_settingsUI->resetMostVisitedClicked.connect(boost::bind(&SimpleUI::settingsResetMostVisited, this));
276     m_settingsUI->resetBrowserClicked.connect(boost::bind(&SimpleUI::settingsResetBrowser, this));
277
278     M_ASSERT(m_moreMenuUI.get());
279     m_moreMenuUI->bookmarkManagerClicked.connect(boost::bind(&SimpleUI::showBookmarkManagerUI, this));
280     m_moreMenuUI->historyUIClicked.connect(boost::bind(&SimpleUI::showHistoryUI, this));
281     m_moreMenuUI->settingsClicked.connect(boost::bind(&SimpleUI::showSettingsUI, this));
282     m_moreMenuUI->closeMoreMenuClicked.connect(boost::bind(&SimpleUI::closeMoreMenu, this));
283     m_moreMenuUI->switchToMobileMode.connect(boost::bind(&SimpleUI::switchToMobileMode, this));
284     m_moreMenuUI->switchToDesktopMode.connect(boost::bind(&SimpleUI::switchToDesktopMode, this));
285     m_moreMenuUI->addToBookmarkClicked.connect(boost::bind(&SimpleUI::addToBookmarks, this, _1));
286     m_moreMenuUI->isBookmark.connect(boost::bind(&SimpleUI::checkBookmark, this));
287     m_moreMenuUI->deleteBookmark.connect(boost::bind(&SimpleUI::deleteBookmark, this));
288     m_moreMenuUI->zoomUIClicked.connect(boost::bind(&SimpleUI::showZoomUI, this));
289
290     M_ASSERT(m_bookmarkManagerUI.get());
291     m_bookmarkManagerUI->closeBookmarkManagerClicked.connect(boost::bind(&SimpleUI::closeBookmarkManagerUI, this));
292     m_bookmarkManagerUI->bookmarkItemClicked.connect(boost::bind(&SimpleUI::onBookmarkClicked, this, _1));
293
294     M_ASSERT(m_zoomUI.get());
295     m_zoomUI->setZoom.connect(boost::bind(&SimpleUI::setZoomFactor, this, _1));
296     m_zoomUI->scrollView.connect(boost::bind(&SimpleUI::scrollView, this, _1, _2));
297 }
298
299 void SimpleUI::loadModelServices()
300 {
301     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
302
303     m_webEngine =
304         std::dynamic_pointer_cast
305         <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
306         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
307
308     m_favoriteService =
309         std::dynamic_pointer_cast
310         <tizen_browser::interfaces::AbstractFavoriteService,tizen_browser::core::AbstractService>
311         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.favoriteservice"));
312
313     m_historyService =
314         std::dynamic_pointer_cast
315         <tizen_browser::services::HistoryService,tizen_browser::core::AbstractService>
316         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.historyservice"));
317
318     m_platformInputManager =
319         std::dynamic_pointer_cast
320         <tizen_browser::services::PlatformInputManager,tizen_browser::core::AbstractService>
321         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.platforminputmanager"));
322
323     m_sessionService =
324         std::dynamic_pointer_cast
325         <tizen_browser::services::SessionStorage,tizen_browser::core::AbstractService>
326         (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.sessionStorageService"));
327 }
328
329 void SimpleUI::initUIServices()
330 {
331     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
332     M_ASSERT (m_viewManager);
333
334     M_ASSERT(m_webPageUI.get());
335     m_webPageUI->init(m_viewManager->getContent());
336
337     M_ASSERT(m_quickAccess.get());
338     m_quickAccess->init(m_webPageUI->getContent());
339
340     M_ASSERT(m_tabUI.get());
341     m_tabUI->init(m_viewManager->getContent());
342
343     M_ASSERT(m_historyUI.get());
344     m_historyUI->init(m_viewManager->getContent());
345
346     M_ASSERT(m_moreMenuUI.get());
347     m_moreMenuUI->init(m_viewManager->getContent());
348
349     M_ASSERT(m_settingsUI.get());
350     m_settingsUI->init(m_viewManager->getContent());
351
352     M_ASSERT(m_bookmarkManagerUI.get());
353     m_bookmarkManagerUI->init(m_viewManager->getContent());
354
355     M_ASSERT(m_zoomUI.get());
356     m_zoomUI->init(m_viewManager->getContent());
357 }
358
359 void SimpleUI::initModelServices()
360 {
361     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
362
363     M_ASSERT(m_webEngine);
364     M_ASSERT(m_webPageUI->getContent());
365     m_webEngine->init(m_webPageUI->getContent());
366
367     M_ASSERT(m_favoriteService);
368     m_favoriteService->synchronizeBookmarks();
369     m_favoriteService->getBookmarks();
370
371     M_ASSERT(m_platformInputManager);
372     m_platformInputManager->init(m_window.get());
373 }
374
375 void SimpleUI::connectModelSignals()
376 {
377     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
378
379     m_webEngine->uriChanged.connect(boost::bind(&SimpleUI::webEngineURLChanged, this, _1));
380     m_webEngine->uriChanged.connect(boost::bind(&URIEntry::changeUri, &m_webPageUI->getURIEntry(), _1));
381     m_webEngine->uriChanged.connect(boost::bind(&MoreMenuUI::setURL, m_moreMenuUI.get(), _1));
382     m_webEngine->uriOnTabChanged.connect(boost::bind(&SimpleUI::checkTabId,this,_1));
383     m_webEngine->uriOnTabChanged.connect(boost::bind(&SimpleUI::closeZoomUI, this));
384     m_webEngine->webViewClicked.connect(boost::bind(&URIEntry::clearFocus, &m_webPageUI->getURIEntry()));
385     m_webEngine->backwardEnableChanged.connect(boost::bind(&WebPageUI::setBackButtonEnabled, m_webPageUI.get(), _1));
386     m_webEngine->forwardEnableChanged.connect(boost::bind(&WebPageUI::setForwardButtonEnabled, m_webPageUI.get(), _1));
387     m_webEngine->loadStarted.connect(boost::bind(&SimpleUI::loadStarted, this));
388     m_webEngine->loadProgress.connect(boost::bind(&SimpleUI::progressChanged,this,_1));
389     m_webEngine->loadFinished.connect(boost::bind(&SimpleUI::loadFinished, this));
390     m_webEngine->loadStop.connect(boost::bind(&SimpleUI::loadFinished, this));
391     m_webEngine->loadError.connect(boost::bind(&SimpleUI::loadError, this));
392     m_webEngine->confirmationRequest.connect(boost::bind(&SimpleUI::handleConfirmationRequest, this, _1));
393     m_webEngine->tabCreated.connect(boost::bind(&SimpleUI::tabCreated, this));
394     m_webEngine->checkIfCreate.connect(boost::bind(&SimpleUI::checkIfCreate, this));
395     m_webEngine->tabClosed.connect(boost::bind(&SimpleUI::tabClosed,this,_1));
396     m_webEngine->IMEStateChanged.connect(boost::bind(&SimpleUI::setwvIMEStatus, this, _1));
397     m_webEngine->favIconChanged.connect(boost::bind(&MoreMenuUI::setFavIcon, m_moreMenuUI.get(), _1));
398     m_webEngine->titleChanged.connect(boost::bind(&MoreMenuUI::setWebTitle, m_moreMenuUI.get(), _1));
399     m_webEngine->titleChanged.connect(boost::bind(&WebPageUI::setPageTitle, m_webPageUI.get(), _1));
400
401     m_favoriteService->bookmarkAdded.connect(boost::bind(&SimpleUI::onBookmarkAdded, this,_1));
402     m_favoriteService->bookmarkDeleted.connect(boost::bind(&SimpleUI::onBookmarkRemoved, this, _1));
403
404     m_historyService->historyDeleted.connect(boost::bind(&SimpleUI::onHistoryRemoved, this,_1));
405
406     m_platformInputManager->returnPressed.connect(boost::bind(&elm_exit));
407     m_platformInputManager->backPressed.connect(boost::bind(&SimpleUI::onBackPressed, this));
408
409 }
410
411 void SimpleUI::createActions()
412 {
413     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
414     ///\todo Add MulitStateAction. and convert m_stopLoading and m_reload actons to it?
415
416     m_settingPrivateBrowsing = sharedAction(new Action("Private browsing"));
417     m_settingPrivateBrowsing->setToolTip("On exit from private mode all cookies, history, and stored data will be deleted");
418     m_settingPrivateBrowsing->setCheckable(true);
419     m_settingPrivateBrowsing->setChecked(m_webEngine->isPrivateMode());
420     m_settingPrivateBrowsing->setEnabled(true);
421 }
422
423 void SimpleUI::connectActions()
424 {
425     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
426     m_settingPrivateBrowsing->toggled.connect(boost::bind(&SimpleUI::settingsPrivateModeSwitch, this, _1));
427 }
428
429 void SimpleUI::switchViewToWebPage()
430 {
431     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
432     M_ASSERT(m_viewManager);
433     m_webPageUI->switchViewToWebPage(m_webEngine->getLayout(), m_webEngine->getURI(), m_webEngine->getTitle());
434 }
435
436 void SimpleUI::switchToTab(const tizen_browser::basic_webengine::TabId& tabId)
437 {
438     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
439     if(m_webEngine->currentTabId() != tabId) {
440         BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
441         m_webEngine->switchToTab(tabId);
442     }
443     if(m_webEngine->isLoadError()){
444         BROWSER_LOGD("[%s:%d] LOAD ERROR!", __PRETTY_FUNCTION__, __LINE__);
445         loadError();
446         return;
447     }
448     BROWSER_LOGD("[%s:%d] swiching to web_view ", __PRETTY_FUNCTION__, __LINE__);
449     switchViewToWebPage();
450 }
451
452 bool SimpleUI::isErrorPageActive()
453 {
454     return m_webPageUI->isErrorPageActive();
455 }
456
457 void SimpleUI::showQuickAccess()
458 {
459     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
460     m_quickAccess->showMostVisited(getMostVisitedItems());
461     m_quickAccess->showUI();
462 }
463
464 void SimpleUI::switchViewToQuickAccess()
465 {
466     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
467     M_ASSERT(m_viewManager);
468
469     m_webPageUI->switchViewToQuickAccess(m_quickAccess->getContent());
470     m_webEngine->disconnectCurrentWebViewSignals();
471     m_viewManager->popStackTo(m_webPageUI.get());
472 }
473
474 void SimpleUI::checkTabId(const tizen_browser::basic_webengine::TabId& id){
475     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
476     if(m_webEngine->currentTabId() != id || isErrorPageActive()){
477         BROWSER_LOGD("URL changed on non-visible tab, updating browser view");
478         switchToTab(id);
479     }
480 }
481
482 void SimpleUI::openNewTab(const std::string &uri, bool desktopMode)
483 {
484     BROWSER_LOGD("[%s:%d] uri =%s", __PRETTY_FUNCTION__, __LINE__, uri.c_str());
485     switchToTab(m_webEngine->addTab(uri, nullptr, desktopMode));
486 }
487
488 void SimpleUI::closeTab()
489 {
490     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
491     auto tabId = m_webEngine->currentTabId();
492     closeTab(tabId);
493 }
494
495 void SimpleUI::closeTab(const tizen_browser::basic_webengine::TabId& id)
496 {
497     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
498     m_currentSession.removeItem(id.toString());
499     m_webEngine->closeTab(id);
500     updateView();
501 }
502
503 bool SimpleUI::checkBookmark()
504 {
505     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
506     if (m_webPageUI->isHomePageActive())
507         return false;
508
509     if(m_favoriteService->bookmarkExists(m_webEngine->getURI())) {
510         BROWSER_LOGD("[%s] There is bookmark for this site [%s], set indicator on!", __func__, m_webEngine->getURI().c_str());
511         return true;
512     }
513     else {
514         BROWSER_LOGD("[%s] There is no bookmark for this site [%s], set indicator off", __func__, m_webEngine->getURI().c_str());
515         return false;
516     }
517 }
518 // Consider removing these functions
519 void SimpleUI::onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem>)
520 {
521     if (m_moreMenuUI) {
522         m_moreMenuUI->changeBookmarkStatus(true);
523         m_moreMenuUI->createToastPopup( (std::string(m_webEngine->getTitle()) + std::string(" added to bookmark")).c_str() );
524     }
525 }
526
527 void SimpleUI::onBookmarkRemoved(const std::string& uri)
528 {
529     BROWSER_LOGD("[%s] deleted %s", __func__, uri.c_str());
530     if (m_moreMenuUI) {
531         m_moreMenuUI->changeBookmarkStatus(false);
532         m_moreMenuUI->createToastPopup( (std::string(m_webEngine->getTitle()) + std::string(" removed from bookmark")).c_str() );
533     }
534 }
535
536 void SimpleUI::onOpenURLInNewTab(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode)
537 {
538     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
539     m_viewManager->popStackTo(m_webPageUI.get());
540     std::string historyAddress = historyItem->getUrl();
541     openNewTab(historyAddress, desktopMode);
542 }
543
544 void SimpleUI::onMostVisitedTileClicked(std::shared_ptr< services::HistoryItem > historyItem, int itemsNumber)
545 {
546     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
547     m_quickAccess->openDetailPopup(historyItem, m_historyService->getHistoryItemsByURL(historyItem->getUrl(), itemsNumber));
548 }
549
550 void SimpleUI::onClearHistoryClicked()
551 {
552     BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
553     m_historyService->clearAllHistory();
554 }
555
556 void SimpleUI::onMostVisitedClicked()
557 {
558    BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
559    m_quickAccess->showMostVisited(getMostVisitedItems());
560 }
561
562 void SimpleUI::onBookmarkButtonClicked()
563 {
564    BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
565    m_quickAccess->showBookmarks(getBookmarks());
566 }
567
568 void SimpleUI::onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem)
569 {
570     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
571     M_ASSERT(m_viewManager);
572     m_viewManager->popStackTo(m_webPageUI.get());
573     std::string bookmarkAddress = bookmarkItem->getAddress();
574     openNewTab(bookmarkAddress);
575 }
576
577
578 void SimpleUI::onHistoryRemoved(const std::string& uri)
579 {
580     BROWSER_LOGD("[%s] deleted %s", __func__, uri.c_str());
581 }
582
583 void SimpleUI::onReturnPressed(MenuButton *m)
584 {
585     BROWSER_LOGD("[%s]", __func__);
586     m_platformInputManager->returnPressed.disconnect_all_slots();
587     m_platformInputManager->returnPressed.connect(boost::bind(&elm_exit));
588     m->hidePopup();
589 }
590
591 void SimpleUI::setwvIMEStatus(bool status)
592 {
593     BROWSER_LOGD("[%s]", __func__);
594     m_wvIMEStatus = status;
595 }
596
597 void SimpleUI::onBackPressed()
598 {
599     BROWSER_LOGD("[%s]", __func__);
600     if (m_webPageUI->isHomePageActive()) {
601         m_quickAccess->backButtonClicked();
602     } else {
603         if (!m_webPageUI->getURIEntry().hasFocus() && !m_wvIMEStatus)
604             m_webEngine->backButtonClicked();
605     }
606 }
607
608 void SimpleUI::reloadEnable(bool enable)
609 {
610     m_webPageUI->setReloadButtonEnabled(enable);
611 }
612
613 void SimpleUI::stopEnable(bool enable)
614 {
615     m_webPageUI->setStopButtonEnabled(enable);
616 }
617
618 void SimpleUI::loadStarted()
619 {
620     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
621     if(!m_webEngine->isPrivateMode()){
622         m_currentSession.updateItem(m_webEngine->currentTabId().toString(), m_webEngine->getURI());
623     }
624     m_webPageUI->loadStarted();
625 }
626
627 void SimpleUI::progressChanged(double progress)
628 {
629     m_webPageUI->progressChanged(progress);
630 }
631
632 void SimpleUI::loadFinished()
633 {
634     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
635
636     if(!m_webEngine->isPrivateMode()){
637         m_historyService->addHistoryItem(std::make_shared<tizen_browser::services::HistoryItem> (m_webEngine->getURI(),
638                                                                                                 m_webEngine->getTitle(),
639                                                                                                 m_webEngine->getFavicon()), m_webEngine->getSnapshotData(QuickAccess::MAX_THUMBNAIL_WIDTH, QuickAccess::MAX_THUMBNAIL_HEIGHT));
640     }
641     m_webPageUI->loadFinished();
642 }
643
644 void SimpleUI::loadError()
645 {
646     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
647     m_webPageUI->switchViewToErrorPage();
648 }
649
650 void SimpleUI::filterURL(const std::string& url)
651 {
652     BROWSER_LOGD("[%s:%d] url=%s", __PRETTY_FUNCTION__, __LINE__, url.c_str());
653     //check for special urls (like:  'about:home')
654     //if there will be more addresses may be we should
655     //create some kind of std::man<std::string url, bool *(doSomethingWithUrl)()>
656     //and then just map[url]() ? m_webEngine->setURI(url) : /*do nothing*/;;
657     if(/*url.empty() ||*/ url == HomePageURL){
658         m_webPageUI->getURIEntry().changeUri("");
659     } else if (!url.empty()){
660
661     //check if url is in favorites
662
663     //check if url is in blocked
664
665     //no filtering
666
667         if (m_webPageUI->isHomePageActive())
668             openNewTab(url);
669         else
670             m_webEngine->setURI(url);
671     }
672     m_webPageUI->getURIEntry().clearFocus();
673 }
674
675 void SimpleUI::webEngineURLChanged(const std::string url)
676 {
677     BROWSER_LOGD("webEngineURLChanged:%s", url.c_str());
678     m_webPageUI->getURIEntry().clearFocus();
679 }
680
681 void SimpleUI::showZoomUI()
682 {
683     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
684     if(! m_webPageUI->isHomePageActive()) {
685         M_ASSERT(m_viewManager);
686         m_viewManager->popStackTo(m_webPageUI.get());
687         m_webPageUI->showTabUI.connect(boost::bind(&SimpleUI::closeZoomUI, this));
688         m_webPageUI->showMoreMenu.connect(boost::bind(&SimpleUI::closeZoomUI, this));
689         m_zoomUI->show(m_window.get());
690     }
691 }
692
693 void SimpleUI::closeZoomUI()
694 {
695     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
696     M_ASSERT(m_zoomUI);
697     m_webPageUI->showTabUI.disconnect(boost::bind(&SimpleUI::closeZoomUI, this));
698     m_webPageUI->showMoreMenu.disconnect(boost::bind(&SimpleUI::closeZoomUI, this));
699     m_zoomUI->hideUI();
700 }
701
702 void SimpleUI::setZoomFactor(int level)
703 {
704     m_webEngine->setZoomFactor(level);
705 }
706
707 void SimpleUI::scrollView(const int& dx, const int& dy)
708 {
709     m_webEngine->scrollView(dx, dy);
710 }
711
712 void SimpleUI::showTabUI()
713 {
714     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
715     M_ASSERT(m_viewManager);
716     m_viewManager->pushViewToStack(m_tabUI.get());
717     m_tabUI->addTabItems(m_webEngine->getTabContents());
718 }
719
720 void SimpleUI::closeTabUI()
721 {
722     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
723     M_ASSERT(m_viewManager);
724     if (m_viewManager->topOfStack() == m_tabUI.get())
725         m_viewManager->popTheStack();
726 }
727
728 void SimpleUI::newTabClicked()
729 {
730     if (!checkIfCreate())
731         return;
732
733     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
734     switchViewToQuickAccess();
735 }
736
737 void SimpleUI::tabClicked(const tizen_browser::basic_webengine::TabId& tabId)
738 {
739     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
740     m_viewManager->popStackTo(m_webPageUI.get());
741     switchToTab(tabId);
742 }
743
744 void SimpleUI::closeTabsClicked(const tizen_browser::basic_webengine::TabId& tabId)
745 {
746     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
747     m_webEngine->closeTab(tabId);
748 }
749
750 int SimpleUI::tabsCount()
751 {
752     return m_webEngine->tabsCount();
753 }
754
755 void SimpleUI::handleConfirmationRequest(basic_webengine::WebConfirmationPtr webConfirmation)
756 {
757     BROWSER_LOGD("%s", __func__);
758     switch(webConfirmation->getConfirmationType())
759     {
760         case basic_webengine::WebConfirmation::ConfirmationType::Authentication:
761         {
762         basic_webengine::AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<basic_webengine::AuthenticationConfirmation, basic_webengine::WebConfirmation>(webConfirmation);
763
764         Evas_Object *popup_content = elm_layout_add(m_webPageUI->getContent());
765         std::string edjFilePath = EDJE_DIR;
766         edjFilePath.append("SimpleUI/AuthenticationPopup.edj");
767         Eina_Bool layoutSetResult = elm_layout_file_set(popup_content, edjFilePath.c_str(), "authentication_popup");
768         if (!layoutSetResult)
769             throw std::runtime_error("Layout file not found: " + edjFilePath);
770
771     #if PLATFORM(TIZEN)
772         elm_object_translatable_part_text_set(popup_content, "login_label", "Login");
773         elm_object_translatable_part_text_set(popup_content, "password_label", "Password");
774     #else
775         elm_object_part_text_set(popup_content, "login_label", "Login");
776         elm_object_part_text_set(popup_content, "password_label", "Password");
777     #endif
778
779         Evas_Object *loginEntry = elm_entry_add(popup_content);
780         elm_object_part_content_set(popup_content, "login", loginEntry);
781
782         Evas_Object *passwordEntry = elm_entry_add(popup_content);
783         elm_object_part_content_set(popup_content, "password", passwordEntry);
784
785         SimplePopup *popup = SimplePopup::createPopup();
786         popup->setTitle("Authentication request");
787         popup->addButton(OK);
788         popup->addButton(CANCEL);
789         popup->setContent(popup_content);
790         std::shared_ptr<AuthenticationPopupData> popupData = std::make_shared<AuthenticationPopupData>();
791         popupData->loginEntry = loginEntry;
792         popupData->passwordEntry = passwordEntry;
793         popupData->auth = auth;
794         popup->setData(popupData);
795         popup->buttonClicked.connect(boost::bind(&SimpleUI::authPopupButtonClicked, this, _1, _2));
796         popup->show();
797         break;
798         }
799         case basic_webengine::WebConfirmation::ConfirmationType::CertificateConfirmation:
800         case basic_webengine::WebConfirmation::ConfirmationType::Geolocation:
801         case basic_webengine::WebConfirmation::ConfirmationType::UserMedia:
802         case basic_webengine::WebConfirmation::ConfirmationType::Notification:
803         {
804         // Implicitly accepted
805         BROWSER_LOGE("NOT IMPLEMENTED: popups to confirm Ceritificate, Geolocation, UserMedia, Notification");
806         webConfirmation->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
807         m_webEngine->confirmationResult(webConfirmation);
808         break;
809         }
810
811     default:
812         break;
813     }
814 }
815
816 void SimpleUI::authPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData)
817 {
818     std::shared_ptr<AuthenticationPopupData> authPopupData = std::dynamic_pointer_cast<AuthenticationPopupData, PopupData>(popupData);
819     switch(button){
820         case OK:
821             authPopupData->auth->setLogin(elm_entry_entry_get(authPopupData->loginEntry) ? elm_entry_entry_get(authPopupData->loginEntry) : "");
822             authPopupData->auth->setPassword(elm_entry_entry_get(authPopupData->passwordEntry) ? elm_entry_entry_get(authPopupData->passwordEntry) : "");
823             authPopupData->auth->setResult(basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
824             m_webEngine->confirmationResult(authPopupData->auth);
825             break;
826         case CANCEL:
827             authPopupData->auth->setResult(basic_webengine::WebConfirmation::ConfirmationResult::Rejected);
828             m_webEngine->confirmationResult(authPopupData->auth);
829             break;
830     case YES:
831     case NO:
832     case CLOSE:
833     case CONNECT:
834         break;
835     default:
836         break;
837     }
838 }
839
840 void SimpleUI::showHistoryUI()
841 {
842     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
843     M_ASSERT(m_viewManager);
844     m_viewManager->pushViewToStack(m_historyUI.get());
845     m_historyUI->addHistoryItems(getHistory());
846 }
847
848 void SimpleUI::closeHistoryUI()
849 {
850     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
851     M_ASSERT(m_viewManager);
852     if (m_viewManager->topOfStack() == m_historyUI.get())
853         m_viewManager->popTheStack();
854 }
855
856 void SimpleUI::showSettingsUI()
857 {
858     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
859     M_ASSERT(m_viewManager);
860     m_viewManager->pushViewToStack(m_settingsUI.get());
861 }
862
863 void SimpleUI::closeSettingsUI()
864 {
865     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
866     M_ASSERT(m_viewManager);
867     if (m_viewManager->topOfStack() == m_settingsUI.get())
868         m_viewManager->popTheStack();
869 }
870
871 void SimpleUI::showMoreMenu()
872 {
873     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
874     M_ASSERT(m_viewManager);
875
876     bool desktopMode = m_webPageUI->isHomePageActive() ? m_quickAccess->isDesktopMode() : m_webEngine->isDesktopMode();
877     m_moreMenuUI->setDesktopMode(desktopMode);
878     m_viewManager->pushViewToStack(m_moreMenuUI.get());
879     m_moreMenuUI->showCurrentTab();
880
881     if(!m_webPageUI->isHomePageActive()) {
882         m_moreMenuUI->setFavIcon(m_webEngine->getFavicon());
883         m_moreMenuUI->setWebTitle(m_webEngine->getTitle());
884         m_moreMenuUI->setURL(m_webEngine->getURI());
885     }
886     else {
887         m_moreMenuUI->setHomePageInfo();
888     }
889 }
890
891 void SimpleUI::closeMoreMenu()
892 {
893     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
894     M_ASSERT(m_viewManager);
895     if (m_viewManager->topOfStack() == m_moreMenuUI.get())
896         m_viewManager->popTheStack();
897     else
898         BROWSER_LOGD("[%s:%d] WARNING!!! closeMoreMenu is not topOfStack", __PRETTY_FUNCTION__, __LINE__);
899 }
900
901 void SimpleUI::switchToMobileMode()
902 {
903     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
904     if (!m_webPageUI->isHomePageActive()) {
905         m_webEngine->switchToMobileMode();
906     m_viewManager->popStackTo(m_webPageUI.get());
907         m_webEngine->reload();
908     } else {
909         m_quickAccess->setDesktopMode(false);
910     }
911 }
912
913 void SimpleUI::switchToDesktopMode()
914 {
915     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
916     if (!m_webPageUI->isHomePageActive()) {
917         m_webEngine->switchToDesktopMode();
918         m_webEngine->reload();
919     } else {
920         m_quickAccess->setDesktopMode(true);
921     }
922 }
923
924 void SimpleUI::showBookmarkManagerUI()
925 {
926     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
927     M_ASSERT(m_viewManager);
928     m_viewManager->pushViewToStack(m_bookmarkManagerUI.get());
929     m_bookmarkManagerUI->addBookmarkItems(getBookmarks(ROOT_FOLDER));
930 }
931
932 void SimpleUI::closeBookmarkManagerUI()
933 {
934     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
935     M_ASSERT(m_viewManager);
936     if (m_viewManager->topOfStack() == m_bookmarkManagerUI.get())
937     m_viewManager->popTheStack();
938 }
939
940 void SimpleUI::settingsPrivateModeSwitch(bool newState)
941 {
942     BROWSER_LOGD("%s: Setting Private mode to: %s", __func__, (newState ? "true" : "false"));
943     m_webEngine->setPrivateMode(newState);
944     BROWSER_LOGD("[%s:%d] webEngine private mode: %s", __PRETTY_FUNCTION__, __LINE__, (m_webEngine->isPrivateMode() ? "true" : "false"));
945 }
946
947 void SimpleUI::settingsDeleteSelectedData(const std::string& str)
948 {
949     BROWSER_LOGD("[%s]: Deleting selected data", __func__);
950     M_ASSERT(m_viewManager);
951     NotificationPopup *popup = NotificationPopup::createNotificationPopup(m_viewManager->getContent());
952     popup->show("Delete Web Browsing Data");
953     onDeleteSelectedDataButton(str);
954     popup->dismiss();
955 }
956
957 void SimpleUI::onDeleteSelectedDataButton(const std::string& dataText)
958 {
959         BROWSER_LOGD("[%s]: TYPE : %s", __func__, dataText.c_str());
960         if (dataText.find("CACHE") != std::string::npos)
961                 m_webEngine->clearPrivateData();
962         if (dataText.find("COOKIES") != std::string::npos)
963                 m_webEngine->clearPrivateData();
964         if (dataText.find("HISTORY") != std::string::npos)
965                 m_historyService->clearAllHistory();
966 }
967
968 void SimpleUI::settingsResetMostVisited()
969 {
970     BROWSER_LOGD("[%s]: Deleting most visited sites", __func__);
971     M_ASSERT(m_viewManager);
972     NotificationPopup *popup = NotificationPopup::createNotificationPopup(m_viewManager->getContent());
973     popup->show("Reset Most Visited Sites");
974     onDeleteMostVisitedButton(nullptr);
975     popup->dismiss();
976 }
977
978 void SimpleUI::onDeleteMostVisitedButton(std::shared_ptr< PopupData > /*popupData*/)
979 {
980     BROWSER_LOGD("[%s]: Deleting most visited", __func__);
981     m_historyService->cleanMostVisitedHistoryItems();
982 }
983
984 void SimpleUI::settingsResetBrowser()
985 {
986     BROWSER_LOGD("[%s]: Resetting browser", __func__);
987     SimplePopup *popup = SimplePopup::createPopup();
988     popup->setTitle("Reset browser");
989     popup->addButton(OK);
990     popup->addButton(CANCEL);
991     popup->setMessage("Are you sure you want to reset browser?");
992     popup->buttonClicked.connect(boost::bind(&SimpleUI::onResetBrowserButton, this, _1, _2));
993     popup->show();
994 }
995
996 void SimpleUI::onResetBrowserButton(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/)
997 {
998     if (button == OK) {
999         BROWSER_LOGD("[%s]: OK", __func__);
1000         BROWSER_LOGD("[%s]: Resetting browser", __func__);
1001         M_ASSERT(m_viewManager);
1002
1003         NotificationPopup *popup = NotificationPopup::createNotificationPopup(m_viewManager->getContent());
1004         popup->show("Reset Browser");
1005
1006         m_webEngine->clearPrivateData();
1007         m_historyService->clearAllHistory();
1008         m_favoriteService->deleteAllBookmarks();
1009
1010         // Close all openend tabs
1011         std::vector<std::shared_ptr<tizen_browser::basic_webengine::TabContent>> openedTabs = m_webEngine->getTabContents();
1012         for (auto it = openedTabs.begin(); it < openedTabs.end(); ++it) {
1013             tizen_browser::basic_webengine::TabId id = it->get()->getId();
1014             m_currentSession.removeItem(id.toString());
1015             m_webEngine->closeTab(id);
1016         }
1017         //TODO: add here any missing functionality that should be cleaned.
1018
1019         popup->dismiss();
1020     }
1021 }
1022
1023 void SimpleUI::tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/)
1024 {
1025     if (button == CLOSE_TAB) {
1026         BROWSER_LOGD("[%s]: CLOSE TAB", __func__);
1027         closeTab();
1028     }
1029 }
1030
1031 void SimpleUI::tabCreated()
1032 {
1033     int tabs = m_webEngine->tabsCount();
1034     m_webPageUI->setTabsNumber(tabs);
1035 }
1036
1037 bool SimpleUI::checkIfCreate()
1038 {
1039     int tabs = m_webEngine->tabsCount();
1040
1041     if (tabs >= m_tabLimit) {
1042         SimplePopup *popup = SimplePopup::createPopup();
1043         popup->setTitle("Maximum tab count reached.");
1044         popup->addButton(OK);
1045         popup->setMessage("Close other tabs to open another new tab");
1046         popup->buttonClicked.connect(boost::bind(&SimpleUI::tabLimitPopupButtonClicked, this, _1, _2));
1047         popup->show();
1048         return false;
1049     }
1050     else
1051         return true;
1052 }
1053
1054 void SimpleUI::updateView() {
1055     int tabs = m_webEngine->tabsCount();
1056     BROWSER_LOGD("[%s] Opened tabs: %d", __func__, tabs);
1057     if (tabs == 0) {
1058         switchViewToQuickAccess();
1059     } else if (!m_webPageUI->isHomePageActive()) {
1060         switchViewToWebPage();
1061     }
1062     m_webPageUI->setTabsNumber(tabs);
1063 }
1064
1065 void SimpleUI::tabClosed(const tizen_browser::basic_webengine::TabId& id) {
1066     m_currentSession.removeItem(id.toString());
1067     updateView();
1068 }
1069
1070 void SimpleUI::searchWebPage(std::string &text, int flags)
1071 {
1072     m_webEngine->searchOnWebsite(text, flags);
1073 }
1074
1075 void SimpleUI::addToBookmarks(int folder_id)
1076 {
1077     BROWSER_LOGD("[%s,%d],", __func__, __LINE__);
1078     if (m_favoriteService)
1079     {
1080         if (m_webEngine && !m_webEngine->getURI().empty())
1081          {
1082                m_favoriteService->addToBookmarks(m_webEngine->getURI(), m_webEngine->getTitle(), std::string(),
1083                                                  m_webEngine->getSnapshotData(373, 240),
1084                                                  m_webEngine->getFavicon(),(unsigned int)folder_id);
1085          }
1086     }
1087 }
1088
1089 //TODO: Replace by direct call.
1090 void SimpleUI::deleteBookmark()
1091 {
1092         if (m_favoriteService)
1093                 m_favoriteService->deleteBookmark(m_webEngine->getURI());
1094 }
1095 }
1096 }