2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "browser_config.h"
19 #if defined(USE_EWEBKIT)
20 #include <ewk_chromium.h>
23 #include <boost/any.hpp>
26 #include <Elementary.h>
28 #include <Ecore_Wayland.h>
33 #include "BrowserLogger.h"
34 #include "ServiceManager.h"
35 #include "AbstractWebEngine.h"
37 #include "Tools/EflTools.h"
38 #include "BrowserImage.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"
51 namespace tizen_browser{
54 EXPORT_SERVICE(SimpleUI, "org.tizen.browser.simpleui")
56 const std::string HomePageURL = "about:home";
57 const int ROOT_FOLDER = 0;
61 : AbstractMainWindow()
65 , m_bookmarkManagerUI()
70 , m_initialised(false)
71 , m_wvIMEStatus(false)
72 , m_ewkContext(ewk_context_new())
74 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
76 Evas_Object *main_window = elm_win_util_standard_add("browserApp", "browserApp");
77 if (main_window == nullptr)
78 BROWSER_LOGE("Failed to create main window");
80 setMainWindow(main_window);
81 m_viewManager = new ViewManager(main_window);
82 evas_object_size_hint_weight_set(main_window, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
83 evas_object_size_hint_align_set (main_window, EVAS_HINT_FILL, EVAS_HINT_FILL);
85 elm_win_resize_object_add(main_window, m_viewManager->getContent());
86 evas_object_show(main_window);
89 SimpleUI::~SimpleUI() {
90 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
91 m_sessionService->getStorage()->deleteSession(m_currentSession);
92 evas_object_del(m_window.get());
93 ewk_context_delete(m_ewkContext);
96 void SimpleUI::destroyUI()
98 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
99 evas_object_del(m_window.get());
102 std::string SimpleUI::edjePath(const std::string &file)
104 return std::string(EDJE_DIR) + file;
107 std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > SimpleUI::getBookmarks(int folder_id)
109 return m_favoriteService->getBookmarks(folder_id);
112 std::shared_ptr<services::HistoryItemVector> SimpleUI::getMostVisitedItems()
114 return m_historyService->getMostVisitedHistoryItems();
117 std::shared_ptr<services::HistoryItemVector> SimpleUI::getHistory()
119 return m_historyService->getHistoryToday();
122 int SimpleUI::exec(const std::string& _url)
124 BROWSER_LOGD("[%s] _url=%s, initialised=%d", __func__, _url.c_str(), m_initialised);
125 std::string url = _url;
128 if (m_window.get()) {
129 config::DefaultConfig config;
131 m_tabLimit = boost::any_cast <int> (config.get("TAB_LIMIT"));
132 m_favoritesLimit = boost::any_cast <int> (config.get("FAVORITES_LIMIT"));
139 // initModelServices() needs to be called after initUIServices()
144 connectModelSignals();
148 //Push first view to stack.
149 m_viewManager->pushViewToStack(m_webPageUI.get());
151 m_initialised = true;
154 m_currentSession = std::move(m_sessionService->getStorage()->createSession());
158 BROWSER_LOGD("[%s]: changing to homeUrl", __func__);
159 switchViewToQuickAccess();
160 restoreLastSession();
165 BROWSER_LOGD("[%s]:%d url=%s", __func__, __LINE__, url.c_str());
169 void SimpleUI::restoreLastSession()
171 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
172 M_ASSERT(m_sessionService);
173 Session::Session lastSession = std::move(m_sessionService->getStorage()->getLastSession());
174 if(lastSession.items().size() >= 1)
176 for(auto iter=lastSession.items().begin(), end=lastSession.items().end(); iter != end; ++iter)
178 openNewTab(iter->second);
180 m_sessionService->getStorage()->deleteSession(lastSession);
185 //TODO: Move all service creation here:
186 void SimpleUI::loadUIServices()
188 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
191 std::dynamic_pointer_cast
192 <tizen_browser::base_ui::WebPageUI,tizen_browser::core::AbstractService>
193 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webpageui"));
196 std::dynamic_pointer_cast
197 <tizen_browser::base_ui::MainUI,tizen_browser::core::AbstractService>
198 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.mainui"));
201 std::dynamic_pointer_cast
202 <tizen_browser::base_ui::TabUI,tizen_browser::core::AbstractService>
203 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.tabui"));
206 std::dynamic_pointer_cast
207 <tizen_browser::base_ui::HistoryUI,tizen_browser::core::AbstractService>
208 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.historyui"));
211 std::dynamic_pointer_cast
212 <tizen_browser::base_ui::SettingsUI,tizen_browser::core::AbstractService>
213 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.settingsui"));
216 std::dynamic_pointer_cast
217 <tizen_browser::base_ui::MoreMenuUI,tizen_browser::core::AbstractService>
218 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.moremenuui"));
220 m_bookmarkManagerUI =
221 std::dynamic_pointer_cast
222 <tizen_browser::base_ui::BookmarkManagerUI,tizen_browser::core::AbstractService>
223 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.bookmarkmanagerui"));
226 std::dynamic_pointer_cast
227 <tizen_browser::base_ui::ZoomUI, tizen_browser::core::AbstractService>
228 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.zoomui"));
231 void SimpleUI::connectUISignals()
233 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
235 M_ASSERT(m_webPageUI.get());
236 m_webPageUI->getURIEntry().uriChanged.connect(boost::bind(&SimpleUI::filterURL, this, _1));
237 m_webPageUI->backPage.connect(boost::bind(&SimpleUI::switchViewToWebPage, this));
238 m_webPageUI->backPage.connect(boost::bind(&tizen_browser::basic_webengine::AbstractWebEngine<Evas_Object>::back, m_webEngine.get()));
239 m_webPageUI->reloadPage.connect(boost::bind(&SimpleUI::switchViewToWebPage, this));
240 m_webPageUI->showTabUI.connect(boost::bind(&SimpleUI::showTabUI, this));
241 m_webPageUI->showMoreMenu.connect(boost::bind(&SimpleUI::showMoreMenu, this));
242 m_webPageUI->forwardPage.connect(boost::bind(&tizen_browser::basic_webengine::AbstractWebEngine<Evas_Object>::forward, m_webEngine.get()));
243 m_webPageUI->stopLoadingPage.connect(boost::bind(&tizen_browser::basic_webengine::AbstractWebEngine<Evas_Object>::stopLoading, m_webEngine.get()));
244 m_webPageUI->reloadPage.connect(boost::bind(&tizen_browser::basic_webengine::AbstractWebEngine<Evas_Object>::reload, m_webEngine.get()));
245 m_webPageUI->showMainUI.connect(boost::bind(&SimpleUI::showMainUI, this));
246 m_webPageUI->hideMainUI.connect(boost::bind(&MainUI::hideUI, m_mainUI));
249 M_ASSERT(m_mainUI.get());
250 m_mainUI->getDetailPopup().openURLInNewTab.connect(boost::bind(&SimpleUI::onOpenURLInNewTab, this, _1, _2));
251 m_mainUI->openURLInNewTab.connect(boost::bind(&SimpleUI::onOpenURLInNewTab, this, _1, _2));
252 m_mainUI->mostVisitedTileClicked.connect(boost::bind(&SimpleUI::onMostVisitedTileClicked, this, _1, _2));
253 m_mainUI->mostVisitedClicked.connect(boost::bind(&SimpleUI::onMostVisitedClicked, this));
254 m_mainUI->bookmarkClicked.connect(boost::bind(&SimpleUI::onBookmarkButtonClicked, this));
255 m_mainUI->bookmarkManagerClicked.connect(boost::bind(&SimpleUI::showBookmarkManagerUI, this));
257 M_ASSERT(m_tabUI.get());
258 m_tabUI->closeTabUIClicked.connect(boost::bind(&SimpleUI::closeTabUI, this));
259 m_tabUI->newTabClicked.connect(boost::bind(&SimpleUI::newTabClicked, this));
260 m_tabUI->tabClicked.connect(boost::bind(&SimpleUI::tabClicked, this,_1));
261 m_tabUI->closeTabsClicked.connect(boost::bind(&SimpleUI::closeTabsClicked, this,_1));
262 m_tabUI->newIncognitoTabClicked.connect(boost::bind(&SimpleUI::newTabClicked, this));
263 m_tabUI->tabsCount.connect(boost::bind(&SimpleUI::tabsCount, this));
265 M_ASSERT(m_historyUI.get());
266 m_historyUI->clearHistoryClicked.connect(boost::bind(&SimpleUI::onClearHistoryClicked, this));
267 m_historyUI->closeHistoryUIClicked.connect(boost::bind(&SimpleUI::closeHistoryUI, this));
268 // desktop mode as default
269 m_historyUI->historyItemClicked.connect(boost::bind(&SimpleUI::onOpenURLInNewTab, this, _1, true));
271 M_ASSERT(m_settingsUI.get());
272 m_settingsUI->closeSettingsUIClicked.connect(boost::bind(&SimpleUI::closeSettingsUI, this));
273 m_settingsUI->deleteSelectedDataClicked.connect(boost::bind(&SimpleUI::settingsDeleteSelectedData, this,_1));
274 m_settingsUI->resetMostVisitedClicked.connect(boost::bind(&SimpleUI::settingsResetMostVisited, this));
275 m_settingsUI->resetBrowserClicked.connect(boost::bind(&SimpleUI::settingsResetBrowser, this));
277 M_ASSERT(m_moreMenuUI.get());
278 m_moreMenuUI->bookmarkManagerClicked.connect(boost::bind(&SimpleUI::showBookmarkManagerUI, this));
279 m_moreMenuUI->historyUIClicked.connect(boost::bind(&SimpleUI::showHistoryUI, this));
280 m_moreMenuUI->settingsClicked.connect(boost::bind(&SimpleUI::showSettingsUI, this));
281 m_moreMenuUI->closeMoreMenuClicked.connect(boost::bind(&SimpleUI::closeMoreMenu, this));
282 m_moreMenuUI->switchToMobileMode.connect(boost::bind(&SimpleUI::switchToMobileMode, this));
283 m_moreMenuUI->switchToDesktopMode.connect(boost::bind(&SimpleUI::switchToDesktopMode, this));
284 m_moreMenuUI->addToBookmarkClicked.connect(boost::bind(&SimpleUI::addToBookmarks, this, _1));
285 m_moreMenuUI->isBookmark.connect(boost::bind(&SimpleUI::checkBookmark, this));
286 m_moreMenuUI->deleteBookmark.connect(boost::bind(&SimpleUI::deleteBookmark, this));
287 m_moreMenuUI->zoomUIClicked.connect(boost::bind(&SimpleUI::showZoomUI, this));
289 M_ASSERT(m_bookmarkManagerUI.get());
290 m_bookmarkManagerUI->closeBookmarkManagerClicked.connect(boost::bind(&SimpleUI::closeBookmarkManagerUI, this));
291 m_bookmarkManagerUI->bookmarkItemClicked.connect(boost::bind(&SimpleUI::onBookmarkClicked, this, _1));
293 M_ASSERT(m_zoomUI.get());
294 m_zoomUI->setZoom.connect(boost::bind(&SimpleUI::setZoomFactor, this, _1));
295 m_zoomUI->scrollView.connect(boost::bind(&SimpleUI::scrollView, this, _1, _2));
298 void SimpleUI::loadModelServices()
300 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
303 std::dynamic_pointer_cast
304 <basic_webengine::AbstractWebEngine<Evas_Object>,tizen_browser::core::AbstractService>
305 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.webkitengineservice"));
308 std::dynamic_pointer_cast
309 <tizen_browser::interfaces::AbstractFavoriteService,tizen_browser::core::AbstractService>
310 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.favoriteservice"));
313 std::dynamic_pointer_cast
314 <tizen_browser::services::HistoryService,tizen_browser::core::AbstractService>
315 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.historyservice"));
317 m_platformInputManager =
318 std::dynamic_pointer_cast
319 <tizen_browser::services::PlatformInputManager,tizen_browser::core::AbstractService>
320 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.platforminputmanager"));
323 std::dynamic_pointer_cast
324 <tizen_browser::services::SessionStorage,tizen_browser::core::AbstractService>
325 (tizen_browser::core::ServiceManager::getInstance().getService("org.tizen.browser.sessionStorageService"));
328 void SimpleUI::initUIServices()
330 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
331 M_ASSERT (m_viewManager);
333 M_ASSERT(m_webPageUI.get());
334 m_webPageUI->init(m_viewManager->getContent());
336 M_ASSERT(m_mainUI.get());
337 m_mainUI->init(m_webPageUI->getContent());
339 M_ASSERT(m_tabUI.get());
340 m_tabUI->init(m_viewManager->getContent());
342 M_ASSERT(m_historyUI.get());
343 m_historyUI->init(m_viewManager->getContent());
345 M_ASSERT(m_moreMenuUI.get());
346 m_moreMenuUI->init(m_viewManager->getContent());
348 M_ASSERT(m_settingsUI.get());
349 m_settingsUI->init(m_viewManager->getContent());
351 M_ASSERT(m_bookmarkManagerUI.get());
352 m_bookmarkManagerUI->init(m_viewManager->getContent());
354 M_ASSERT(m_zoomUI.get());
355 m_zoomUI->init(m_viewManager->getContent());
358 void SimpleUI::initModelServices()
360 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
362 M_ASSERT(m_webEngine);
363 M_ASSERT(m_webPageUI->getContent());
364 m_webEngine->init(m_webPageUI->getContent());
366 M_ASSERT(m_favoriteService);
367 m_favoriteService->synchronizeBookmarks();
368 m_favoriteService->getBookmarks();
370 M_ASSERT(m_platformInputManager);
371 m_platformInputManager->init(m_window.get());
374 void SimpleUI::connectModelSignals()
376 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
378 m_webEngine->uriChanged.connect(boost::bind(&SimpleUI::webEngineURLChanged, this, _1));
379 m_webEngine->uriChanged.connect(boost::bind(&URIEntry::changeUri, &m_webPageUI->getURIEntry(), _1));
380 m_webEngine->uriChanged.connect(boost::bind(&MoreMenuUI::setURL, m_moreMenuUI.get(), _1));
381 m_webEngine->uriOnTabChanged.connect(boost::bind(&SimpleUI::checkTabId,this,_1));
382 m_webEngine->uriOnTabChanged.connect(boost::bind(&SimpleUI::closeZoomUI, this));
383 m_webEngine->webViewClicked.connect(boost::bind(&URIEntry::clearFocus, &m_webPageUI->getURIEntry()));
384 m_webEngine->backwardEnableChanged.connect(boost::bind(&WebPageUI::setBackButtonEnabled, m_webPageUI.get(), _1));
385 m_webEngine->forwardEnableChanged.connect(boost::bind(&WebPageUI::setForwardButtonEnabled, m_webPageUI.get(), _1));
386 m_webEngine->loadStarted.connect(boost::bind(&SimpleUI::loadStarted, this));
387 m_webEngine->loadProgress.connect(boost::bind(&SimpleUI::progressChanged,this,_1));
388 m_webEngine->loadFinished.connect(boost::bind(&SimpleUI::loadFinished, this));
389 m_webEngine->loadStop.connect(boost::bind(&SimpleUI::loadFinished, this));
390 m_webEngine->loadError.connect(boost::bind(&SimpleUI::loadError, this));
391 m_webEngine->confirmationRequest.connect(boost::bind(&SimpleUI::handleConfirmationRequest, this, _1));
392 m_webEngine->tabCreated.connect(boost::bind(&SimpleUI::tabCreated, this));
393 m_webEngine->tabClosed.connect(boost::bind(&SimpleUI::tabClosed,this,_1));
394 m_webEngine->IMEStateChanged.connect(boost::bind(&SimpleUI::setwvIMEStatus, this, _1));
395 m_webEngine->favIconChanged.connect(boost::bind(&MoreMenuUI::setFavIcon, m_moreMenuUI.get(), _1));
396 m_webEngine->titleChanged.connect(boost::bind(&MoreMenuUI::setWebTitle, m_moreMenuUI.get(), _1));
398 m_favoriteService->bookmarkAdded.connect(boost::bind(&SimpleUI::onBookmarkAdded, this,_1));
399 m_favoriteService->bookmarkDeleted.connect(boost::bind(&SimpleUI::onBookmarkRemoved, this, _1));
401 m_historyService->historyDeleted.connect(boost::bind(&SimpleUI::onHistoryRemoved, this,_1));
403 m_platformInputManager->returnPressed.connect(boost::bind(&elm_exit));
404 m_platformInputManager->backPressed.connect(boost::bind(&SimpleUI::onBackPressed, this));
408 void SimpleUI::createActions()
410 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
411 ///\todo Add MulitStateAction. and convert m_stopLoading and m_reload actons to it?
413 m_settingPrivateBrowsing = sharedAction(new Action("Private browsing"));
414 m_settingPrivateBrowsing->setToolTip("On exit from private mode all cookies, history, and stored data will be deleted");
415 m_settingPrivateBrowsing->setCheckable(true);
416 m_settingPrivateBrowsing->setChecked(m_webEngine->isPrivateMode());
417 m_settingPrivateBrowsing->setEnabled(true);
420 void SimpleUI::connectActions()
422 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
423 m_settingPrivateBrowsing->toggled.connect(boost::bind(&SimpleUI::settingsPrivateModeSwitch, this, _1));
426 void SimpleUI::switchViewToWebPage()
428 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
429 M_ASSERT(m_viewManager);
430 m_webPageUI->switchViewToWebPage(m_webEngine->getLayout(), m_webEngine->getURI());
433 void SimpleUI::switchToTab(const tizen_browser::basic_webengine::TabId& tabId)
435 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
436 if(m_webEngine->currentTabId() != tabId) {
437 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
438 m_webEngine->switchToTab(tabId);
440 if(m_webEngine->isLoadError()){
441 BROWSER_LOGD("[%s:%d] LOAD ERROR!", __PRETTY_FUNCTION__, __LINE__);
445 BROWSER_LOGD("[%s:%d] swiching to web_view ", __PRETTY_FUNCTION__, __LINE__);
446 switchViewToWebPage();
449 bool SimpleUI::isErrorPageActive()
451 return m_webPageUI->isErrorPageActive();
454 void SimpleUI::showMainUI()
456 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
457 m_mainUI->showMostVisited(getMostVisitedItems());
461 void SimpleUI::switchViewToQuickAccess()
463 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
464 M_ASSERT(m_viewManager);
466 m_webPageUI->switchViewToQuickAccess(m_mainUI->getContent());
467 m_webEngine->disconnectCurrentWebViewSignals();
468 m_viewManager->popStackTo(m_webPageUI.get());
471 void SimpleUI::checkTabId(const tizen_browser::basic_webengine::TabId& id){
472 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
473 if(m_webEngine->currentTabId() != id || isErrorPageActive()){
474 BROWSER_LOGD("URL changed on non-visible tab, updating browser view");
479 void SimpleUI::openNewTab(const std::string &uri, bool desktopMode)
481 BROWSER_LOGD("[%s:%d] uri =%s", __PRETTY_FUNCTION__, __LINE__, uri.c_str());
482 switchToTab(m_webEngine->addTab(uri, nullptr, desktopMode));
485 void SimpleUI::closeTab()
487 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
488 auto tabId = m_webEngine->currentTabId();
492 void SimpleUI::closeTab(const tizen_browser::basic_webengine::TabId& id)
494 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
495 m_currentSession.removeItem(id.toString());
496 m_webEngine->closeTab(id);
500 bool SimpleUI::checkBookmark()
502 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
503 if (m_webPageUI->isHomePageActive())
506 if(m_favoriteService->bookmarkExists(m_webEngine->getURI())) {
507 BROWSER_LOGD("[%s] There is bookmark for this site [%s], set indicator on!", __func__, m_webEngine->getURI().c_str());
511 BROWSER_LOGD("[%s] There is no bookmark for this site [%s], set indicator off", __func__, m_webEngine->getURI().c_str());
515 // Consider removing these functions
516 void SimpleUI::onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem>)
519 m_moreMenuUI->changeBookmarkStatus(true);
520 m_moreMenuUI->createToastPopup( (std::string(m_webEngine->getTitle()) + std::string(" added to bookmark")).c_str() );
524 void SimpleUI::onBookmarkRemoved(const std::string& uri)
526 BROWSER_LOGD("[%s] deleted %s", __func__, uri.c_str());
528 m_moreMenuUI->changeBookmarkStatus(false);
529 m_moreMenuUI->createToastPopup( (std::string(m_webEngine->getTitle()) + std::string(" removed from bookmark")).c_str() );
533 void SimpleUI::onOpenURLInNewTab(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode)
535 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
536 m_viewManager->popStackTo(m_webPageUI.get());
537 std::string historyAddress = historyItem->getUrl();
538 openNewTab(historyAddress, desktopMode);
541 void SimpleUI::onMostVisitedTileClicked(std::shared_ptr< services::HistoryItem > historyItem, int itemsNumber)
543 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
544 m_mainUI->openDetailPopup(historyItem, m_historyService->getHistoryItemsByURL(historyItem->getUrl(), itemsNumber));
547 void SimpleUI::onClearHistoryClicked()
549 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
550 m_historyService->clearAllHistory();
553 void SimpleUI::onMostVisitedClicked()
555 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
556 m_mainUI->showMostVisited(getMostVisitedItems());
559 void SimpleUI::onBookmarkButtonClicked()
561 BROWSER_LOGD("%s:%d %s", __FILE__, __LINE__, __func__);
562 m_mainUI->showBookmarks(getBookmarks());
565 void SimpleUI::onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem)
567 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
568 M_ASSERT(m_viewManager);
569 m_viewManager->popStackTo(m_webPageUI.get());
570 std::string bookmarkAddress = bookmarkItem->getAddress();
571 openNewTab(bookmarkAddress);
575 void SimpleUI::onHistoryRemoved(const std::string& uri)
577 BROWSER_LOGD("[%s] deleted %s", __func__, uri.c_str());
580 void SimpleUI::onReturnPressed(MenuButton *m)
582 BROWSER_LOGD("[%s]", __func__);
583 m_platformInputManager->returnPressed.disconnect_all_slots();
584 m_platformInputManager->returnPressed.connect(boost::bind(&elm_exit));
588 void SimpleUI::setwvIMEStatus(bool status)
590 BROWSER_LOGD("[%s]", __func__);
591 m_wvIMEStatus = status;
594 void SimpleUI::onBackPressed()
596 BROWSER_LOGD("[%s]", __func__);
597 if (m_webPageUI->isHomePageActive()) {
598 m_mainUI->backButtonClicked();
600 if (!m_webPageUI->getURIEntry().hasFocus() && !m_wvIMEStatus)
601 m_webEngine->backButtonClicked();
605 void SimpleUI::reloadEnable(bool enable)
607 m_webPageUI->setReloadButtonEnabled(enable);
610 void SimpleUI::stopEnable(bool enable)
612 m_webPageUI->setStopButtonEnabled(enable);
615 void SimpleUI::loadStarted()
617 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
618 if(!m_webEngine->isPrivateMode()){
619 m_currentSession.updateItem(m_webEngine->currentTabId().toString(), m_webEngine->getURI());
621 m_webPageUI->loadStarted();
624 void SimpleUI::progressChanged(double progress)
626 m_webPageUI->progressChanged(progress);
629 void SimpleUI::loadFinished()
631 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
633 if(!m_webEngine->isPrivateMode()){
634 m_historyService->addHistoryItem(std::make_shared<tizen_browser::services::HistoryItem> (m_webEngine->getURI(),
635 m_webEngine->getTitle(),
636 m_webEngine->getFavicon()), m_webEngine->getSnapshotData(MainUI::MAX_THUMBNAIL_WIDTH, MainUI::MAX_THUMBNAIL_HEIGHT));
638 m_webPageUI->loadFinished();
641 void SimpleUI::loadError()
643 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
644 m_webPageUI->switchViewToErrorPage();
647 void SimpleUI::filterURL(const std::string& url)
649 BROWSER_LOGD("[%s:%d] url=%s", __PRETTY_FUNCTION__, __LINE__, url.c_str());
650 //check for special urls (like: 'about:home')
651 //if there will be more addresses may be we should
652 //create some kind of std::man<std::string url, bool *(doSomethingWithUrl)()>
653 //and then just map[url]() ? m_webEngine->setURI(url) : /*do nothing*/;;
654 if(/*url.empty() ||*/ url == HomePageURL){
655 m_webPageUI->getURIEntry().changeUri("");
656 } else if (!url.empty()){
658 //check if url is in favorites
660 //check if url is in blocked
663 if (m_webPageUI->isHomePageActive())
666 m_webEngine->setURI(url);
668 m_webPageUI->getURIEntry().clearFocus();
671 void SimpleUI::webEngineURLChanged(const std::string url)
673 BROWSER_LOGD("webEngineURLChanged:%s", url.c_str());
674 m_webPageUI->getURIEntry().clearFocus();
677 void SimpleUI::showZoomUI()
679 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
680 if(! m_webPageUI->isHomePageActive()) {
681 M_ASSERT(m_viewManager);
682 m_viewManager->popStackTo(m_webPageUI.get());
683 m_webPageUI->showTabUI.connect(boost::bind(&SimpleUI::closeZoomUI, this));
684 m_webPageUI->showMoreMenu.connect(boost::bind(&SimpleUI::closeZoomUI, this));
685 m_zoomUI->show(m_window.get());
689 void SimpleUI::closeZoomUI()
691 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
693 m_webPageUI->showTabUI.disconnect(boost::bind(&SimpleUI::closeZoomUI, this));
694 m_webPageUI->showMoreMenu.disconnect(boost::bind(&SimpleUI::closeZoomUI, this));
698 void SimpleUI::setZoomFactor(int level)
700 m_webEngine->setZoomFactor(level);
703 void SimpleUI::scrollView(const int& dx, const int& dy)
705 m_webEngine->scrollView(dx, dy);
708 void SimpleUI::showTabUI()
710 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
711 M_ASSERT(m_viewManager);
712 m_viewManager->pushViewToStack(m_tabUI.get());
713 m_tabUI->addTabItems(m_webEngine->getTabContents());
716 void SimpleUI::closeTabUI()
718 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
719 M_ASSERT(m_viewManager);
720 if (m_viewManager->topOfStack() == m_tabUI.get())
721 m_viewManager->popTheStack();
724 void SimpleUI::newTabClicked()
726 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
727 switchViewToQuickAccess();
730 void SimpleUI::tabClicked(const tizen_browser::basic_webengine::TabId& tabId)
732 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
733 m_viewManager->popStackTo(m_webPageUI.get());
737 void SimpleUI::closeTabsClicked(const tizen_browser::basic_webengine::TabId& tabId)
739 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
740 m_webEngine->closeTab(tabId);
743 int SimpleUI::tabsCount()
745 return m_webEngine->tabsCount();
748 void SimpleUI::handleConfirmationRequest(basic_webengine::WebConfirmationPtr webConfirmation)
750 BROWSER_LOGD("%s", __func__);
751 switch(webConfirmation->getConfirmationType())
753 case basic_webengine::WebConfirmation::ConfirmationType::Authentication:
755 basic_webengine::AuthenticationConfirmationPtr auth = std::dynamic_pointer_cast<basic_webengine::AuthenticationConfirmation, basic_webengine::WebConfirmation>(webConfirmation);
757 Evas_Object *popup_content = elm_layout_add(m_webPageUI->getContent());
758 std::string edjFilePath = EDJE_DIR;
759 edjFilePath.append("SimpleUI/AuthenticationPopup.edj");
760 Eina_Bool layoutSetResult = elm_layout_file_set(popup_content, edjFilePath.c_str(), "authentication_popup");
761 if (!layoutSetResult)
762 throw std::runtime_error("Layout file not found: " + edjFilePath);
765 elm_object_translatable_part_text_set(popup_content, "login_label", "Login");
766 elm_object_translatable_part_text_set(popup_content, "password_label", "Password");
768 elm_object_part_text_set(popup_content, "login_label", "Login");
769 elm_object_part_text_set(popup_content, "password_label", "Password");
772 Evas_Object *loginEntry = elm_entry_add(popup_content);
773 elm_object_part_content_set(popup_content, "login", loginEntry);
775 Evas_Object *passwordEntry = elm_entry_add(popup_content);
776 elm_object_part_content_set(popup_content, "password", passwordEntry);
778 SimplePopup *popup = SimplePopup::createPopup();
779 popup->setTitle("Authentication request");
780 popup->addButton(OK);
781 popup->addButton(CANCEL);
782 popup->setContent(popup_content);
783 std::shared_ptr<AuthenticationPopupData> popupData = std::make_shared<AuthenticationPopupData>();
784 popupData->loginEntry = loginEntry;
785 popupData->passwordEntry = passwordEntry;
786 popupData->auth = auth;
787 popup->setData(popupData);
788 popup->buttonClicked.connect(boost::bind(&SimpleUI::authPopupButtonClicked, this, _1, _2));
792 case basic_webengine::WebConfirmation::ConfirmationType::CertificateConfirmation:
793 case basic_webengine::WebConfirmation::ConfirmationType::Geolocation:
794 case basic_webengine::WebConfirmation::ConfirmationType::UserMedia:
795 case basic_webengine::WebConfirmation::ConfirmationType::Notification:
797 // Implicitly accepted
798 BROWSER_LOGE("NOT IMPLEMENTED: popups to confirm Ceritificate, Geolocation, UserMedia, Notification");
799 webConfirmation->setResult(tizen_browser::basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
800 m_webEngine->confirmationResult(webConfirmation);
809 void SimpleUI::authPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData)
811 std::shared_ptr<AuthenticationPopupData> authPopupData = std::dynamic_pointer_cast<AuthenticationPopupData, PopupData>(popupData);
814 authPopupData->auth->setLogin(elm_entry_entry_get(authPopupData->loginEntry) ? elm_entry_entry_get(authPopupData->loginEntry) : "");
815 authPopupData->auth->setPassword(elm_entry_entry_get(authPopupData->passwordEntry) ? elm_entry_entry_get(authPopupData->passwordEntry) : "");
816 authPopupData->auth->setResult(basic_webengine::WebConfirmation::ConfirmationResult::Confirmed);
817 m_webEngine->confirmationResult(authPopupData->auth);
820 authPopupData->auth->setResult(basic_webengine::WebConfirmation::ConfirmationResult::Rejected);
821 m_webEngine->confirmationResult(authPopupData->auth);
833 void SimpleUI::showHistoryUI()
835 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
836 M_ASSERT(m_viewManager);
837 m_viewManager->pushViewToStack(m_historyUI.get());
838 m_historyUI->addHistoryItems(getHistory());
841 void SimpleUI::closeHistoryUI()
843 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
844 M_ASSERT(m_viewManager);
845 if (m_viewManager->topOfStack() == m_historyUI.get())
846 m_viewManager->popTheStack();
849 void SimpleUI::showSettingsUI()
851 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
852 M_ASSERT(m_viewManager);
853 m_viewManager->pushViewToStack(m_settingsUI.get());
856 void SimpleUI::closeSettingsUI()
858 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
859 M_ASSERT(m_viewManager);
860 if (m_viewManager->topOfStack() == m_settingsUI.get())
861 m_viewManager->popTheStack();
864 void SimpleUI::showMoreMenu()
866 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
867 M_ASSERT(m_viewManager);
869 bool desktopMode = m_webPageUI->isHomePageActive() ? m_mainUI->isDesktopMode() : m_webEngine->isDesktopMode();
870 m_moreMenuUI->setDesktopMode(desktopMode);
871 m_viewManager->pushViewToStack(m_moreMenuUI.get());
872 m_moreMenuUI->showCurrentTab();
874 if(!m_webPageUI->isHomePageActive()) {
875 m_moreMenuUI->setFavIcon(m_webEngine->getFavicon());
876 m_moreMenuUI->setWebTitle(m_webEngine->getTitle());
877 m_moreMenuUI->setURL(m_webEngine->getURI());
880 m_moreMenuUI->setHomePageInfo();
884 void SimpleUI::closeMoreMenu()
886 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
887 M_ASSERT(m_viewManager);
888 if (m_viewManager->topOfStack() == m_moreMenuUI.get())
889 m_viewManager->popTheStack();
891 BROWSER_LOGD("[%s:%d] WARNING!!! closeMoreMenu is not topOfStack", __PRETTY_FUNCTION__, __LINE__);
894 void SimpleUI::switchToMobileMode()
896 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
897 if (!m_webPageUI->isHomePageActive()) {
898 m_webEngine->switchToMobileMode();
899 m_viewManager->popStackTo(m_webPageUI.get());
900 m_webEngine->reload();
902 m_mainUI->setDesktopMode(false);
906 void SimpleUI::switchToDesktopMode()
908 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
909 if (!m_webPageUI->isHomePageActive()) {
910 m_webEngine->switchToDesktopMode();
911 m_webEngine->reload();
913 m_mainUI->setDesktopMode(true);
917 void SimpleUI::showBookmarkManagerUI()
919 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
920 M_ASSERT(m_viewManager);
921 m_viewManager->pushViewToStack(m_bookmarkManagerUI.get());
922 m_bookmarkManagerUI->addBookmarkItems(getBookmarks(ROOT_FOLDER));
925 void SimpleUI::closeBookmarkManagerUI()
927 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
928 M_ASSERT(m_viewManager);
929 if (m_viewManager->topOfStack() == m_bookmarkManagerUI.get())
930 m_viewManager->popTheStack();
933 void SimpleUI::settingsPrivateModeSwitch(bool newState)
935 BROWSER_LOGD("%s: Setting Private mode to: %s", __func__, (newState ? "true" : "false"));
936 m_webEngine->setPrivateMode(newState);
937 BROWSER_LOGD("[%s:%d] webEngine private mode: %s", __PRETTY_FUNCTION__, __LINE__, (m_webEngine->isPrivateMode() ? "true" : "false"));
940 void SimpleUI::settingsDeleteSelectedData(const std::string& str)
942 BROWSER_LOGD("[%s]: Deleting Hisory", __func__);
943 SimplePopup *popup = SimplePopup::createPopup();
944 popup->setTitle("Delete selected data");
945 popup->addButton(OK);
946 popup->addButton(CANCEL);
947 popup->setMessage("Are you sure you want to delete all selected data?");
948 std::shared_ptr<EntryPopupData> popupData = std::make_shared<EntryPopupData>();
949 popupData->text = str;
950 popup->setData(popupData);
951 popup->buttonClicked.connect(boost::bind(&SimpleUI::onDeleteSelectedDataButton, this, _1, _2));
955 void SimpleUI::onDeleteSelectedDataButton(PopupButtons button, std::shared_ptr< PopupData > popupData)
958 BROWSER_LOGD("[%s]: OK", __func__);
959 std::string dataText = std::static_pointer_cast<EntryPopupData>(popupData)->text;
960 BROWSER_LOGD("[%s]: TYPE : %s", __func__, dataText.c_str());
961 if (dataText.find("CACHE") != std::string::npos)
962 m_webEngine->clearPrivateData();
963 if (dataText.find("COOKIES") != std::string::npos)
964 m_webEngine->clearPrivateData();
965 if (dataText.find("HISTORY") != std::string::npos)
966 m_historyService->clearAllHistory();
970 void SimpleUI::settingsResetMostVisited()
972 BROWSER_LOGD("[%s]: Deleting Hisory", __func__);
973 SimplePopup *popup = SimplePopup::createPopup();
974 popup->setTitle("Delete most visited");
975 popup->addButton(OK);
976 popup->addButton(CANCEL);
977 popup->setMessage("Are you sure you want to delete most visited sites?");
978 popup->buttonClicked.connect(boost::bind(&SimpleUI::onDeleteMostVisitedButton, this, _1, _2));
982 void SimpleUI::onDeleteMostVisitedButton(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/)
985 BROWSER_LOGD("[%s]: OK", __func__);
986 BROWSER_LOGD("[%s]: Deleting most visited", __func__);
988 //TODO: display notification popup
990 m_historyService->cleanMostVisitedHistoryItems();
994 void SimpleUI::settingsResetBrowser()
996 BROWSER_LOGD("[%s]: Deleting Hisory", __func__);
997 SimplePopup *popup = SimplePopup::createPopup();
998 popup->setTitle("Reset browser");
999 popup->addButton(OK);
1000 popup->addButton(CANCEL);
1001 popup->setMessage("Are you sure you want to reset browser?");
1002 popup->buttonClicked.connect(boost::bind(&SimpleUI::onResetBrowserButton, this, _1, _2));
1006 void SimpleUI::onResetBrowserButton(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/)
1009 BROWSER_LOGD("[%s]: OK", __func__);
1010 BROWSER_LOGD("[%s]: Resetting browser", __func__);
1012 m_webEngine->clearPrivateData();
1013 m_historyService->clearAllHistory();
1014 m_favoriteService->deleteAllBookmarks();
1016 // Close all openend tabs
1017 std::vector<std::shared_ptr<tizen_browser::basic_webengine::TabContent>> openedTabs = m_webEngine->getTabContents();
1018 for (auto it = openedTabs.begin(); it < openedTabs.end(); ++it) {
1019 tizen_browser::basic_webengine::TabId id = it->get()->getId();
1020 m_currentSession.removeItem(id.toString());
1021 m_webEngine->closeTab(id);
1024 //TODO: add here any missing functionality that should be cleaned.
1028 void SimpleUI::tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/)
1030 if (button == CLOSE_TAB) {
1031 BROWSER_LOGD("[%s]: CLOSE TAB", __func__);
1036 void SimpleUI::tabCreated()
1038 int tabs = m_webEngine->tabsCount();
1040 if (tabs > m_tabLimit)
1042 SimplePopup *popup = SimplePopup::createPopup();
1043 popup->setTitle("Too many tabs open");
1044 popup->addButton(CONTINUE);
1045 popup->addButton(CLOSE_TAB);
1046 popup->setMessage("Browser might slow down. Are you sure you want to continue?");
1047 popup->buttonClicked.connect(boost::bind(&SimpleUI::tabLimitPopupButtonClicked, this, _1, _2));
1050 m_webPageUI->setTabsNumber(tabs);
1053 void SimpleUI::updateView() {
1054 int tabs = m_webEngine->tabsCount();
1055 BROWSER_LOGD("[%s] Opened tabs: %d", __func__, tabs);
1057 switchViewToQuickAccess();
1058 } else if (!m_webPageUI->isHomePageActive()) {
1059 switchViewToWebPage();
1061 m_webPageUI->setTabsNumber(tabs);
1064 void SimpleUI::tabClosed(const tizen_browser::basic_webengine::TabId&) {
1068 void SimpleUI::searchWebPage(std::string &text, int flags)
1070 m_webEngine->searchOnWebsite(text, flags);
1073 void SimpleUI::addToBookmarks(int folder_id)
1075 BROWSER_LOGD("[%s,%d],", __func__, __LINE__);
1076 if (m_favoriteService)
1078 if (m_webEngine && !m_webEngine->getURI().empty())
1080 m_favoriteService->addToBookmarks(m_webEngine->getURI(), m_webEngine->getTitle(), std::string(),
1081 m_webEngine->getSnapshotData(373, 240),
1082 m_webEngine->getFavicon(),(unsigned int)folder_id);
1087 //TODO: Replace by direct call.
1088 void SimpleUI::deleteBookmark()
1090 if (m_favoriteService)
1091 m_favoriteService->deleteBookmark(m_webEngine->getURI());