ea0e6633b4f82e2311467648b2fc4a1f0cd3b030
[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      * Stop loading current page.
78      */
79     virtual void stopLoading(void) = 0;
80
81     /**
82      * Reload current page.
83      */
84     virtual void reload(void) = 0;
85
86     /**
87      * Go to previous page (if possible)
88      */
89     virtual void back(void) = 0;
90
91     /**
92      * Go to next page (if possible)
93      */
94     virtual void forward(void) = 0;
95
96     /**
97      * @return true if it is possible to go back, false otherwise
98      */
99     virtual bool isBackEnabled(void) const = 0;
100
101     /**
102      * @return true if it is possible to go forward, false otherwise
103      */
104     virtual bool isForwardEnabled(void) const = 0;
105
106     /**
107      * @return true if page is still loading, false otherwise
108      */
109     virtual bool isLoading() const = 0;
110
111     /**
112      * @return number of tabs
113      */
114     virtual int tabsCount() const = 0;
115
116     /**
117      * @return TabId of current tab
118      */
119     virtual TabId currentTabId() const = 0;
120
121     /**
122      * @return list (RVO) of tabs in most recent order
123      */
124     virtual std::list<TabId> listTabs() const = 0;
125
126
127     /**
128      *  @return vector of metadata for all opened tabs
129      */
130     virtual std::vector<std::shared_ptr<TabContent>> getTabContents() const = 0;
131
132     /**
133      * Adds new tab
134      * @param uri if not empty opens specified uri
135      * @param desktopMode true if desktop mode, false if mobile mode
136      * @return TabId of created tab
137      */
138     virtual TabId addTab(const std::string & uri = std::string(), const TabId * openerId = NULL, bool desktopMode = true) = 0;
139
140     /**
141      * @param tab id
142      * @return returns underlaying UI component
143      */
144     virtual T* getTabView(TabId id) = 0;
145
146     /**
147      * Switch current tab for tab with tabId
148      * @param tabId of tab
149      * @return true if tab changed, false otherwise
150      */
151     virtual bool switchToTab(TabId tabId) = 0;
152
153     /**
154      * Close current tab. Switch tab to other (not defined which).
155      * Should NOT close last tab (there should be only at least 1 tab)
156      * @return true if tab closed successfully, false otherwise
157      */
158     virtual bool closeTab() = 0;
159
160     /**
161      * Close tab specified with id parameter. Switch tab to other (not defined which).
162      * Should NOT close last tab (there should be only at least 1 tab)
163      * @return true if tab closed successfully, false otherwise
164      */
165     virtual bool closeTab(TabId id) = 0;
166
167     /**
168      * Go to next tab.
169      * @return true if tab changed successfully, false otherwise
170      */
171     virtual bool nextTab() = 0;
172
173     /**
174      * Go to prev tab.
175      * @return true if tab changed successfully, false otherwise
176      */
177     virtual bool prevTab() = 0;
178
179     /**
180      * Process confirmation result
181      * \param web confirmation with request and result value
182      */
183     virtual void confirmationResult(WebConfirmationPtr) = 0;
184
185     /**
186      * Gets snapshot data as void* for current tab
187      */
188     virtual std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(int width = 324, int height = 177) = 0;
189
190     /**
191      * Gets snapshot data as void* for tab provided as parameter
192      */
193     virtual std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(TabId id, int width, int height) = 0;
194
195     /**
196      * Set private mode on/off
197      * \param private mode on when true, off otherwise
198      */
199     virtual void setPrivateMode(bool) = 0;
200
201     virtual bool isPrivateMode() const = 0;
202
203     virtual bool isLoadError() const = 0;
204
205     /**
206      * \brief Sets Focus to URI entry.
207      */
208     virtual void setFocus()=0;
209
210     /**
211      * @brief Remove focus form URI
212      */
213     virtual void clearFocus()=0;
214
215     /**
216      * @brief check if URI is focused
217      */
218     virtual bool hasFocus() const = 0;
219
220     /**
221      * @brief return current zoom factor in percentage.
222      *
223      * @return real zoom, also for "fit to screen" mode
224      */
225     virtual int getZoomFactor()const = 0;
226
227
228     /**
229      * @brief Sets zoom factor in percentage
230      *
231      * @param zoomFactor in percentage of default zoom, 0 means autofit
232      */
233     virtual void setZoomFactor(int zoomFactor) = 0;
234
235     /**
236      * @brief Clear private data of WebView
237      */
238     virtual void clearPrivateData() = 0;
239
240     virtual void disconnectCurrentWebViewSignals() = 0;
241
242     /**
243      * @brief Search string on searchOnWebsite
244      *
245      * @param string to search on searchOnWebsite
246      * @param flags for search options
247      */
248     virtual void searchOnWebsite(const std::string &, int flags) = 0;
249
250     /**
251      * @brief Get favicon of current page loaded
252      */
253     virtual std::shared_ptr<tizen_browser::tools::BrowserImage> getFavicon() = 0;
254
255     /**
256      * @brief back or exit when back key is pressed
257      */
258     virtual void backButtonClicked() const = 0;
259
260     /**
261      * @brief Switch current view to mobile mode
262      */
263     virtual void switchToMobileMode() = 0;
264
265     /**
266      * @brief Switch current view to desktop mode
267      */
268     virtual void switchToDesktopMode() = 0;
269
270     /**
271      * @brief Check if desktop mode is enabled for current view
272      *
273      * @return true if desktop mode is enabled
274      */
275     virtual bool isDesktopMode() const = 0;
276
277     /**
278      * FavIcon of current page changed
279      */
280     boost::signals2::signal<void (std::shared_ptr<tizen_browser::tools::BrowserImage>)> favIconChanged;
281
282     /**
283      * Title of current page changed
284      * \param new title
285      */
286     boost::signals2::signal<void (const std::string &)> titleChanged;
287
288     /**
289      * URI of current page changed
290      * \param new URI
291      */
292     boost::signals2::signal<void (const std::string &)> uriChanged;
293
294     /**
295      * URI on current/other page changed
296      */
297     boost::signals2::signal<void (TabId)> uriOnTabChanged;
298
299     /**
300      * Possibility of go forward changed
301      * \param bool true if it is possible to go forward, false otherwise
302      */
303     boost::signals2::signal<void (bool)> forwardEnableChanged;
304
305     /**
306      * Possibility of go back changed
307      * \param bool true if it is possible to go back, false otherwise
308      */
309     boost::signals2::signal<void (bool)> backwardEnableChanged;
310
311     /**
312      * Page load finished
313      */
314     boost::signals2::signal<void ()> loadFinished;
315
316     /**
317      * Page load started
318      */
319     boost::signals2::signal<void ()> loadStarted;
320
321     /**
322      * Load progress changed
323      * \param double 0..1 of progress
324      */
325     boost::signals2::signal<void (double)> loadProgress;
326
327     /**
328      * Page load stopped.
329      */
330     boost::signals2::signal<void ()> loadStop;
331
332     /**
333      * Page load error.
334      */
335     boost::signals2::signal<void ()> loadError;
336
337     /**
338      * Current tab changed
339      * \param TabId of new tab
340      */
341     boost::signals2::signal<void (TabId)> currentTabChanged;
342
343     /**
344     * New tab was creted. It could be explicit call (by user) or tab could be opened from JavaScript.
345     */
346     boost::signals2::signal<void ()> tabCreated;
347
348     /**
349      * Tab closed
350      * \param TabId of closed tab
351      */
352     boost::signals2::signal<void (TabId)> tabClosed;
353
354     /**
355      * Confirmation Reuest
356      */
357     boost::signals2::signal<void (basic_webengine::WebConfirmationPtr)> confirmationRequest;
358
359     /**
360      * Web Engine area clicked
361      */
362     boost::signals2::signal<void ()> webViewClicked;
363
364     /**
365      * All links to RSS/Atom channels were gathered from webpage.
366      */
367     boost::signals2::signal<void (std::vector<std::string>)> gotFeedLinks;
368
369     /**
370      * Status of IME
371      * \param bool true if IME is opened, false otherwise
372      */
373     boost::signals2::signal<void (bool)> IMEStateChanged;
374 };
375
376 } /* end of basic_webengine */
377 } /* end of tizen_browser */
378
379 #endif /* __ABSTRACT_WEBENGINE_H__ */