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.
20 * Created on: Mar 18, 2014
29 #include "AbstractMainWindow.h"
30 #include "AbstractService.h"
31 #include "AbstractFavoriteService.h"
32 #include "ServiceFactory.h"
33 #include "service_macros.h"
36 #include "WebPageUI.h"
37 #include "AbstractWebEngine.h"
38 #include "MoreMenuUI.h"
39 #include "HistoryUI.h"
40 #include "SettingsUI.h"
43 #include "HistoryService.h"
44 #include "BookmarkManagerUI.h"
45 #include "PlatformInputManager.h"
46 #include "SessionStorage.h"
47 #include "SqlStorage.h"
51 #include "SimplePopup.h"
52 #include "WebConfirmation.h"
53 #include "BookmarksManager.h"
56 namespace tizen_browser{
60 void AbstractMainWindow<Evas_Object>::setMainWindow(Evas_Object * rawPtr)
62 m_window = std::shared_ptr<Evas_Object>(rawPtr, evas_object_del);
65 class BROWSER_EXPORT SimpleUI : public AbstractMainWindow<Evas_Object>
68 SimpleUI(/*Evas_Object *window*/);
70 virtual int exec(const std::string& url);
71 virtual std::string getName();
77 void connectActions();
78 void loadUIServices();
79 void connectUISignals();
80 void loadModelServices();
81 void initModelServices();
82 void initUIServices();
83 void connectModelSignals();
84 void restoreLastSession();
85 Evas_Object* createWebLayout(Evas_Object* parent);
86 Evas_Object* createErrorLayout(Evas_Object* parent);
89 void backEnable(bool enable);
90 void forwardEnable(bool enable);
91 void stopEnable(bool enable);
92 void reloadEnable(bool enable);
93 void addBookmarkEnable(bool enable);
94 void removeBookmarkEnable(bool enable);
95 void zoomEnable(bool enable);
97 void settingsButtonEnable(bool enable);
100 void progressChanged(double progress);
104 void setErrorButtons();
105 bool isErrorPageActive();
107 void bookmarkAdded();
108 void bookmarkDeleted();
110 void switchViewToQuickAccess();
111 void switchViewToWebPage();
114 void openNewTab(const std::string &uri, bool desktopMode = true);
115 void switchToTab(const tizen_browser::basic_webengine::TabId& tabId);
116 void newTabClicked(const std::string &);
117 void tabClicked(const tizen_browser::basic_webengine::TabId& tabId);
118 void closeTabsClicked(const tizen_browser::basic_webengine::TabId& tabId);
120 void tabClosed(const tizen_browser::basic_webengine::TabId& id);
122 std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > getBookmarks(int folder_id = -1);
123 std::shared_ptr<services::HistoryItemVector> getHistory();
124 std::shared_ptr<services::HistoryItemVector> getMostVisitedItems();
126 //UI signal handling functions
127 void onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
129 void onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
130 void onBookmarkRemoved(const std::string& uri);
132 void onHistoryAdded(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem);
133 void onHistoryRemoved(const std::string& uri);
134 void onOpenURLInNewTab(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode);
135 void onMostVisitedTileClicked(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, int itemsNumber);
136 void onClearHistoryClicked(const std::string&);
138 void onMostVisitedClicked(const std::string&);
139 void onBookmarkButtonClicked(const std::string&);
140 void onBookmarkManagerButtonClicked(const std::string&);
142 void handleConfirmationRequest(basic_webengine::WebConfirmationPtr webConfirmation);
143 void authPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData);
145 void onActionTriggered(const Action& action);
146 void setwvIMEStatus(bool status);
148 sharedAction m_share;
149 sharedAction m_zoom_in;
150 sharedAction m_showBookmarkManagerUI;
151 sharedAction m_settingPointerMode;
152 sharedAction m_settingPrivateBrowsing;
153 sharedAction m_settingDeleteHistory;
154 sharedAction m_settingDeleteData;
155 sharedAction m_settingDeleteFavorite;
156 sharedAction m_mostvisited;
157 sharedAction m_bookmarksvisited;
158 sharedAction m_bookmarks_manager_BookmarkBar;
161 * \brief filters URL before it is passed to WebEngine.
163 * This function should be connected with m_simpleURI->uriChanged.
164 * it is a good place to check for special urls (like "about:home"),
165 * filter forbidden addresses and to check set favorite icon.
167 void filterURL(const std::string& url);
170 * Checks if correct tab is visible to user, and if not, it update browser view
171 * @param id of tab that should be visible to user
173 void checkTabId(const tizen_browser::basic_webengine::TabId& id);
176 * \brief check if url comming back from WebEngine should be passed to URI.
178 * For filtered addresses we need to hide real URI so the user would be confused.
179 * and this is a back function that checks if address emited from browser should be changed.
181 void webEngineURLChanged(const std::string url);
182 void onmostHistoryvisitedClicked();
183 void onBookmarkvisitedClicked();
185 * @brief Check if the current page exists as a bookmark.
188 bool checkBookmark();
190 * @brief Adds current page to bookmarks.
193 void addToBookmarks(int);
195 * @brief Remove current page from bookmarks
200 void deleteBookmark(void);
206 void closeTabUI(const std::string& str);
208 void closeMoreMenu(const std::string& str);
209 void switchToMobileMode();
210 void switchToDesktopMode();
211 void showHistoryUI(const std::string& str);
212 void closeHistoryUI();
215 void hideSettingsMenu();
216 void showSettingsUI(const std::string&);
217 void closeSettingsUI(const std::string&);
219 void closeBookmarkManagerMenu(const std::string& str);
220 void showBookmarkManagerMenu();
222 void showPopup(Evas_Object *content, char* btn1_text, char* btn2_text);
225 void closeTab(const tizen_browser::basic_webengine::TabId& id);
227 void settingsPointerModeSwitch(bool newState);
228 void settingsPrivateModeSwitch(bool newState);
229 void settingsDeleteData();
230 void settingsDeleteFavorite();
231 void settingsDeleteSelectedData(const std::string& str);
232 void settingsResetMostVisited(const std::string& str);
233 void settingsResetBrowser(const std::string& str);
234 void onDeleteSelectedDataButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
235 void onDeleteMostVisitedButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
236 void onResetBrowserButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
237 void onDeleteDataButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
238 void onDeleteFavoriteButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
239 void tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/);
240 void disableHistoryButton(bool flag);
243 void onNetworkError();
244 void onNetworkConnected();
245 void onNetErrorButtonPressed(PopupButtons, std::shared_ptr<PopupData>);
247 void onReturnPressed(MenuButton *m);
248 void onBackPressed();
250 boost::signals2::signal<void ()> hidePopup;
252 std::string edjePath(const std::string &);
254 Evas_Object *m_popup;
255 Evas_Object *m_entry;
256 Evas_Object *m_errorLayout;
258 std::shared_ptr<WebPageUI> m_webPageUI;
259 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
260 // std::shared_ptr<tizen_browser::base_ui::URIEntry> m_simpleURI;
261 std::shared_ptr<tizen_browser::interfaces::AbstractFavoriteService> m_favoriteService;
262 std::shared_ptr<tizen_browser::services::HistoryService> m_historyService;
263 std::shared_ptr<tizen_browser::base_ui::MoreMenuUI> m_moreMenuUI;
264 std::shared_ptr<tizen_browser::base_ui::BookmarkManagerUI> m_bookmarkManagerUI;
265 std::shared_ptr<tizen_browser::base_ui::MainUI> m_mainUI;
266 std::shared_ptr<tizen_browser::base_ui::HistoryUI> m_historyUI;
267 std::shared_ptr<tizen_browser::base_ui::SettingsUI> m_settingsUI;
268 std::shared_ptr<tizen_browser::base_ui::TabUI> m_tabUI;
269 std::shared_ptr<tizen_browser::services::PlatformInputManager> m_platformInputManager;
270 std::shared_ptr<tizen_browser::services::SessionStorage> m_sessionService;
271 tizen_browser::Session::Session m_currentSession;
272 std::shared_ptr<BookmarksManager> m_bookmarks_manager;
275 int m_favoritesLimit;
277 // This context object is used to implicitly init internal ewk data used by opengl to create the first and
278 // consecutive webviews in the application, otherwise we would encounter a crash after creating
279 // the first web view
280 Ewk_Context *m_ewkContext;
282 std::vector<std::shared_ptr<tizen_browser::services::HistoryItem>> items_vector;
283 SimplePopup* m_networkErrorPopup;
285 void searchWebPage(std::string &text, int flags);
291 #endif /* SIMPLEUI_H_ */