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::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > getBookmarkFolders(int folder_id);
124 std::shared_ptr<services::HistoryItemVector> getHistory();
125 std::shared_ptr<services::HistoryItemVector> getMostVisitedItems();
127 //UI signal handling functions
128 void onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
130 void onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
131 void onBookmarkRemoved(const std::string& uri);
133 void onHistoryAdded(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem);
134 void onHistoryRemoved(const std::string& uri);
135 void onOpenURLInNewTab(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode);
136 void onMostVisitedTileClicked(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, int itemsNumber);
137 void onClearHistoryClicked(const std::string&);
139 void onMostVisitedClicked(const std::string&);
140 void onBookmarkButtonClicked(const std::string&);
141 void onBookmarkManagerButtonClicked(const std::string&);
143 void handleConfirmationRequest(basic_webengine::WebConfirmationPtr webConfirmation);
144 void authPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData);
146 void onActionTriggered(const Action& action);
147 void setwvIMEStatus(bool status);
149 sharedAction m_share;
150 sharedAction m_zoom_in;
151 sharedAction m_showBookmarkManagerUI;
152 sharedAction m_settingPointerMode;
153 sharedAction m_settingPrivateBrowsing;
154 sharedAction m_settingDeleteHistory;
155 sharedAction m_settingDeleteData;
156 sharedAction m_settingDeleteFavorite;
157 sharedAction m_mostvisited;
158 sharedAction m_bookmarksvisited;
159 sharedAction m_bookmarks_manager_Add_NewFolder;
160 sharedAction m_bookmarks_manager_BookmarkBar;
161 sharedAction m_bookmarks_manager_Folder1;
162 sharedAction m_bookmarks_manager_Folder2;
163 sharedAction m_bookmarks_manager_Folder3;
166 * \brief filters URL before it is passed to WebEngine.
168 * This function should be connected with m_simpleURI->uriChanged.
169 * it is a good place to check for special urls (like "about:home"),
170 * filter forbidden addresses and to check set favorite icon.
172 void filterURL(const std::string& url);
175 * Checks if correct tab is visible to user, and if not, it update browser view
176 * @param id of tab that should be visible to user
178 void checkTabId(const tizen_browser::basic_webengine::TabId& id);
181 * \brief check if url comming back from WebEngine should be passed to URI.
183 * For filtered addresses we need to hide real URI so the user would be confused.
184 * and this is a back function that checks if address emited from browser should be changed.
186 void webEngineURLChanged(const std::string url);
187 void onmostHistoryvisitedClicked();
188 void onBookmarkvisitedClicked();
190 * @brief Check if the current page exists as a bookmark.
193 bool checkBookmark();
195 * @brief Adds current page to bookmarks.
198 void addToBookmarks(int);
200 * @brief Remove current page from bookmarks
205 void deleteBookmark(void);
209 void addBookmarkFolders();
211 void newFolderBookmarkManager(const char* title, int by_user);
212 void newFolderMoreMenu(const char* title, int by_user);
214 void closeTabUI(const std::string& str);
216 void closeMoreMenu(const std::string& str);
217 void switchToMobileMode();
218 void switchToDesktopMode();
219 void showHistoryUI(const std::string& str);
220 void closeHistoryUI(const std::string&);
223 void hideSettingsMenu();
224 void showSettingsUI(const std::string&);
225 void closeSettingsUI(const std::string&);
227 void closeBookmarkManagerMenu(const std::string& str);
228 void updateBookmarkManagerGenGrid(int folder_id);
229 void showBookmarkManagerMenu();
231 void showPopup(Evas_Object *content, char* btn1_text, char* btn2_text);
234 void closeTab(const tizen_browser::basic_webengine::TabId& id);
236 void settingsPointerModeSwitch(bool newState);
237 void settingsPrivateModeSwitch(bool newState);
238 void settingsDeleteData();
239 void settingsDeleteFavorite();
240 void settingsDeleteSelectedData(const std::string& str);
241 void settingsResetMostVisited(const std::string& str);
242 void settingsResetBrowser(const std::string& str);
243 void onDeleteSelectedDataButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
244 void onDeleteMostVisitedButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
245 void onResetBrowserButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
246 void onDeleteDataButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
247 void onDeleteFavoriteButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
248 void tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/);
249 void disableHistoryButton(bool flag);
252 void onNetworkError();
253 void onNetworkConnected();
254 void onNetErrorButtonPressed(PopupButtons, std::shared_ptr<PopupData>);
256 void onReturnPressed(MenuButton *m);
257 void onBackPressed();
259 boost::signals2::signal<void ()> hidePopup;
261 std::string edjePath(const std::string &);
263 Evas_Object *m_popup;
264 Evas_Object *m_entry;
265 Evas_Object *m_errorLayout;
267 std::shared_ptr<WebPageUI> m_webPageUI;
268 std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>> m_webEngine;
269 // std::shared_ptr<tizen_browser::base_ui::URIEntry> m_simpleURI;
270 std::shared_ptr<tizen_browser::interfaces::AbstractFavoriteService> m_favoriteService;
271 std::shared_ptr<tizen_browser::services::HistoryService> m_historyService;
272 std::shared_ptr<tizen_browser::base_ui::MoreMenuUI> m_moreMenuUI;
273 std::shared_ptr<tizen_browser::base_ui::BookmarkManagerUI> m_bookmarkManagerUI;
274 std::shared_ptr<tizen_browser::base_ui::MainUI> m_mainUI;
275 std::shared_ptr<tizen_browser::base_ui::HistoryUI> m_historyUI;
276 std::shared_ptr<tizen_browser::base_ui::SettingsUI> m_settingsUI;
277 std::shared_ptr<tizen_browser::base_ui::TabUI> m_tabUI;
278 std::shared_ptr<tizen_browser::services::PlatformInputManager> m_platformInputManager;
279 std::shared_ptr<tizen_browser::services::SessionStorage> m_sessionService;
280 tizen_browser::Session::Session m_currentSession;
281 std::shared_ptr<BookmarksManager> m_bookmarks_manager;
284 int m_favoritesLimit;
286 int m_curr_folder_id;
287 // This context object is used to implicitly init internal ewk data used by opengl to create the first and
288 // consecutive webviews in the application, otherwise we would encounter a crash after creating
289 // the first web view
290 Ewk_Context *m_ewkContext;
292 std::vector<std::shared_ptr<tizen_browser::services::HistoryItem>> items_vector;
293 SimplePopup* m_networkErrorPopup;
295 void searchWebPage(std::string &text, int flags);
301 #endif /* SIMPLEUI_H_ */