Fixed navigating using 'Backspace' key
[profile/tv/apps/web/browser.git] / core / AbstractWebEngine / AbstractWebEngine.h
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 #ifndef __ABSTRACT_WEBENGINE_H__
18 #define __ABSTRACT_WEBENGINE_H__ 1
19
20 #include <boost/signals2/signal.hpp>
21 #include <memory>
22 #include <Evas.h>
23
24 #include "BrowserImage.h"
25 #include "../ServiceManager/Debug/Lifecycle.h"
26 #include "../ServiceManager/AbstractService.h"
27
28 #include "TabId.h"
29 #include "WebConfirmation.h"
30
31 namespace tizen_browser {
32 namespace basic_webengine {
33 /***
34  * AbstractWebEngine defines interface for WebEngine object.
35  * It is designed for multiple tabs operations.
36  * It is designed to be only way for communication with WebEngine. It should NOT return WebEngine object.
37  */
38 template<typename T>
39 #ifndef NDEBUG
40 class AbstractWebEngine : public tizen_browser::core::AbstractService, ShowLifeCycle<AbstractWebEngine<T>>
41 #else
42 class AbstractWebEngine: public tizen_browser::core::AbstractService
43 #endif
44 {
45 public:
46     /**
47      * \todo this function should return nonEFL object in future
48      * Remember that there must be at least 1 tab created to return layout
49      * @return pointer Evas_Object for current WebView.
50      */
51     virtual T * getLayout() = 0;
52
53     /**
54      * Initialize WebEngine.
55      * @param guiParent GUI parent object (now should pass Evas_Object)
56      * \todo make guiParent nonEFL object
57      */
58     virtual void init(void * guiParent) = 0;
59
60     /**
61      * Set URI address for current tab.
62      * @param uri
63      */
64     virtual void setURI(const std::string & uri) = 0;
65
66     /**
67      * @return uri address for current tab.
68      */
69     virtual std::string getURI(void) const = 0;
70
71     /**
72      * @return title of page opened in current tab.
73      */
74     virtual std::string getTitle(void) const = 0;
75
76     /**
77      * Suspend current webview.
78      */
79     virtual void suspend(void) = 0;
80
81     /**
82      * Resume current webview.
83      */
84     virtual void resume(void) = 0;
85
86     /**
87      * @return true if current webview is suspended, false otherwise
88      */
89     virtual bool isSuspended(void) const = 0;
90
91     /**
92      * Stop loading current page.
93      */
94     virtual void stopLoading(void) = 0;
95
96     /**
97      * Reload current page.
98      */
99     virtual void reload(void) = 0;
100
101     /**
102      * Go to previous page (if possible)
103      */
104     virtual void back(void) = 0;
105
106     /**
107      * Go to next page (if possible)
108      */
109     virtual void forward(void) = 0;
110
111     /**
112      * @return true if it is possible to go back, false otherwise
113      */
114     virtual bool isBackEnabled(void) const = 0;
115
116     /**
117      * @return true if it is possible to go forward, false otherwise
118      */
119     virtual bool isForwardEnabled(void) const = 0;
120
121     /**
122      * @return true if page is still loading, false otherwise
123      */
124     virtual bool isLoading() const = 0;
125
126     /**
127      * @return number of tabs
128      */
129     virtual int tabsCount() const = 0;
130
131     /**
132      * @return TabId of current tab
133      */
134     virtual TabId currentTabId() const = 0;
135
136     /**
137      * @return list (RVO) of tabs in most recent order
138      */
139     virtual std::list<TabId> listTabs() const = 0;
140
141
142     /**
143      *  @return vector of metadata for all opened tabs
144      */
145     virtual std::vector<std::shared_ptr<TabContent>> getTabContents() const = 0;
146
147     /**
148      * Adds new tab
149      * @param uri if not empty opens specified uri
150      * @param openerId
151      * @param desktopMode true if desktop mode, false if mobile mode
152      * @param incognitoMode true if incognito mode, false if not
153      * @return TabId of created tab
154      */
155     virtual TabId addTab(
156             const std::string & uri = std::string(),
157             const TabId * openerId = NULL,
158             bool desktopMode = true,
159             bool incognitoMode = false) = 0;
160
161     /**
162      * @param tab id
163      * @return returns underlaying UI component
164      */
165     virtual T* getTabView(TabId id) = 0;
166
167     /**
168      * Switch current tab for tab with tabId
169      * @param tabId of tab
170      * @return true if tab changed, false otherwise
171      */
172     virtual bool switchToTab(TabId tabId) = 0;
173
174     /**
175      * Close current tab. Switch tab to other (not defined which).
176      * Should NOT close last tab (there should be only at least 1 tab)
177      * @return true if tab closed successfully, false otherwise
178      */
179     virtual bool closeTab() = 0;
180
181     /**
182      * Close tab specified with id parameter. Switch tab to other (not defined which).
183      * Should NOT close last tab (there should be only at least 1 tab)
184      * @return true if tab closed successfully, false otherwise
185      */
186     virtual bool closeTab(TabId id) = 0;
187
188     /**
189      * Go to next tab.
190      * @return true if tab changed successfully, false otherwise
191      */
192     virtual bool nextTab() = 0;
193
194     /**
195      * Go to prev tab.
196      * @return true if tab changed successfully, false otherwise
197      */
198     virtual bool prevTab() = 0;
199
200     /**
201      * Process confirmation result
202      * \param web confirmation with request and result value
203      */
204     virtual void confirmationResult(WebConfirmationPtr) = 0;
205
206     /**
207      * Gets snapshot data as void* for current tab
208      */
209     virtual std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(int width = 324, int height = 177) = 0;
210
211     /**
212      * Gets snapshot data as void* for tab provided as parameter
213      */
214     virtual std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(TabId id, int width, int height) = 0;
215
216     /**
217      * Get the state of private mode for a specific tab
218      *
219      * /param id of snapshot
220      * /return state of private mode
221      */
222     virtual bool isPrivateMode(const TabId&) = 0;
223
224     virtual bool isLoadError() const = 0;
225
226     /**
227      * \brief Sets Focus to URI entry.
228      */
229     virtual void setFocus()=0;
230
231     /**
232      * @brief Remove focus form URI
233      */
234     virtual void clearFocus()=0;
235
236     /**
237      * @brief check if URI is focused
238      */
239     virtual bool hasFocus() const = 0;
240
241     /**
242      * @brief return current zoom factor in percentage.
243      *
244      * @return real zoom, also for "fit to screen" mode
245      */
246     virtual int getZoomFactor()const = 0;
247
248
249     /**
250      * @brief Sets zoom factor in percentage
251      *
252      * @param zoomFactor in percentage of default zoom, 0 means autofit
253      */
254     virtual void setZoomFactor(int zoomFactor) = 0;
255
256     /**
257      * @brief Clear private data of WebView
258      */
259     virtual void clearPrivateData() = 0;
260
261     virtual void disconnectCurrentWebViewSignals() = 0;
262
263     /**
264      * @brief Search string on searchOnWebsite
265      *
266      * @param string to search on searchOnWebsite
267      * @param flags for search options
268      */
269     virtual void searchOnWebsite(const std::string &, int flags) = 0;
270
271     /**
272      * @brief Get favicon of current page loaded
273      */
274     virtual std::shared_ptr<tizen_browser::tools::BrowserImage> getFavicon() = 0;
275
276     /**
277      * @brief back or exit when back key is pressed
278      */
279     virtual void backButtonClicked() = 0;
280
281     /**
282      * @brief Switch current view to mobile mode
283      */
284     virtual void switchToMobileMode() = 0;
285
286     /**
287      * @brief Switch current view to desktop mode
288      */
289     virtual void switchToDesktopMode() = 0;
290
291     /**
292      * @brief Check if desktop mode is enabled for current view
293      *
294      * @return true if desktop mode is enabled
295      */
296     virtual bool isDesktopMode() const = 0;
297
298     /**
299      * Sets an absolute scroll of the given view.
300      *
301      * Both values are from zero to the contents size minus the viewport
302      * size.
303      *
304      * @param x horizontal position to scroll
305      * @param y vertical position to scroll
306      */
307     virtual void scrollView(const int& dx, const int& dy) = 0;
308
309     /**
310      * FavIcon of current page changed
311      */
312     boost::signals2::signal<void (std::shared_ptr<tizen_browser::tools::BrowserImage>)> favIconChanged;
313
314     /**
315      * Title of current page changed
316      * \param new title
317      */
318     boost::signals2::signal<void (const std::string &)> titleChanged;
319
320     /**
321      * URI of current page changed
322      * \param new URI
323      */
324     boost::signals2::signal<void (const std::string &)> uriChanged;
325
326     /**
327      * Possibility of go forward changed
328      * \param bool true if it is possible to go forward, false otherwise
329      */
330     boost::signals2::signal<void (bool)> forwardEnableChanged;
331
332     /**
333      * Possibility of go back changed
334      * \param bool true if it is possible to go back, false otherwise
335      */
336     boost::signals2::signal<void (bool)> backwardEnableChanged;
337
338     /**
339      * Page load finished
340      */
341     boost::signals2::signal<void ()> loadFinished;
342
343     /**
344      * Page load started
345      */
346     boost::signals2::signal<void ()> loadStarted;
347
348     /**
349      * Load progress changed
350      * \param double 0..1 of progress
351      */
352     boost::signals2::signal<void (double)> loadProgress;
353
354     /**
355      * Page load stopped.
356      */
357     boost::signals2::signal<void ()> loadStop;
358
359     /**
360      * Page load error.
361      */
362     boost::signals2::signal<void ()> loadError;
363
364     /**
365      * Current tab changed
366      * \param TabId of new tab
367      */
368     boost::signals2::signal<void (TabId)> currentTabChanged;
369
370     /**
371     * New tab was created. It could be explicit call (by user) or tab could be opened from JavaScript.
372     */
373     boost::signals2::signal<void ()> tabCreated;
374
375     /**
376     * Checks if tab can be created.
377     */
378     boost::signals2::signal<bool ()> checkIfCreate;
379
380     /**
381      * Tab closed
382      * \param TabId of closed tab
383      */
384     boost::signals2::signal<void (TabId)> tabClosed;
385
386     /**
387      * Confirmation Reuest
388      */
389     boost::signals2::signal<void (basic_webengine::WebConfirmationPtr)> confirmationRequest;
390
391     /**
392      * Web Engine area clicked
393      */
394     boost::signals2::signal<void ()> webViewClicked;
395
396     /**
397      * All links to RSS/Atom channels were gathered from webpage.
398      */
399     boost::signals2::signal<void (std::vector<std::string>)> gotFeedLinks;
400
401     /**
402      * Status of IME
403      * \param bool true if IME is opened, false otherwise
404      */
405     boost::signals2::signal<void (bool)> IMEStateChanged;
406
407     /**
408      * Switch view to actual web page
409      */
410     boost::signals2::signal<void ()> switchToWebPage;
411 };
412
413 } /* end of basic_webengine */
414 } /* end of tizen_browser */
415
416 #endif /* __ABSTRACT_WEBENGINE_H__ */