4f586cb0320621dc2ecde8908d54174832bc75c9
[profile/tv/apps/web/browser.git] / services / WebKitEngineService / WebKitEngineService.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 WEBKITENGINESERVICE_H_
18 #define WEBKITENGINESERVICE_H_
19
20 #include <boost/noncopyable.hpp>
21 #include <string>
22 #include <Evas.h>
23 #include <memory>
24
25 #include "ServiceFactory.h"
26 #include "service_macros.h"
27
28 #include "AbstractWebEngine/AbstractWebEngine.h"
29 #include "AbstractWebEngine/TabId.h"
30 #include "AbstractWebEngine/WebConfirmation.h"
31 #include "BrowserImage.h"
32
33 namespace tizen_browser {
34 namespace basic_webengine {
35 namespace webkitengine_service {
36
37 class WebView;
38
39 typedef std::shared_ptr<WebView> WebViewPtr;
40
41 class BROWSER_EXPORT WebKitEngineService: public AbstractWebEngine<Evas_Object>, boost::noncopyable
42 {
43 public:
44     WebKitEngineService();
45     virtual ~WebKitEngineService();
46     virtual std::string getName();
47
48     Evas_Object * getLayout();
49     void init(void * guiParent);
50
51     void setURI(const std::string &);
52     std::string getURI(void) const;
53
54     std::string getTitle(void) const;
55
56     void stopLoading(void);
57     void reload(void);
58
59     void back(void);
60     void forward(void);
61
62     bool isBackEnabled(void) const;
63     bool isForwardEnabled(void) const;
64
65     bool isLoading() const;
66
67     void clearPrivateData();
68
69     int tabsCount() const;
70     TabId currentTabId() const;
71     std::list<TabId> listTabs() const;
72     std::vector<std::shared_ptr<TabContent> > getTabContents() const;
73
74     /**
75      * Adds new tab. If uri is specified setURI(uri).
76      * If it first tab in WebEngine switch to this tab.
77      * @param uri
78      * @return TabId of created tab
79      */
80     TabId addTab(const std::string & uri = std::string(), const TabId * openerId = NULL, bool desktopMode = true);
81     Evas_Object* getTabView(TabId id);
82     bool switchToTab(TabId);
83     bool closeTab();
84     bool closeTab(TabId);
85
86     /**
87      * Change tab to next created, dummy implementation.
88      * @return true if changed successfully, false otherwise
89      */
90     bool nextTab();
91     /**
92      * Change tab to previous created, dummy implementation.
93      * @return true if changed successfully, false otherwise
94      */
95     bool prevTab();
96
97     void confirmationResult(WebConfirmationPtr);
98
99     /**
100      * @brief Get snapshot of webpage
101      *
102      * @param width of snapshot
103      * @param height of snapshot
104      * @return Shared pointer to BrowserImage
105      */
106     std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(int width, int height);
107
108     std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(TabId id, int width, int height);
109
110     void setPrivateMode(bool);
111     bool isPrivateMode() const;
112
113
114     /**
115      * @brief Check if current tab has load error.
116      *
117      */
118     bool isLoadError() const;
119
120      /**
121      * \brief Sets Focus to URI entry.
122      */
123     void setFocus();
124
125     /**
126      * @brief Remove focus form URI
127      */
128     void clearFocus();
129
130     /**
131      * @brief check if URI is focused
132      */
133     bool hasFocus() const;
134
135     virtual int getZoomFactor() const;
136
137     /**
138      * @brief check if autofit is enabled
139      */
140
141     virtual void setZoomFactor(int zoomFactor);
142
143
144     /**
145      * @brief Search string on searchOnWebsite
146      *
147      * @param string to search on searchOnWebsite
148      * @param flags for search options
149      */
150     void searchOnWebsite(const std::string &, int flags);
151
152     /**
153      * @brief Get favicon of current page loaded
154      */
155     std::shared_ptr<tizen_browser::tools::BrowserImage> getFavicon();
156
157     /**
158      * @brief back or exit when back key is pressed
159      */
160     void backButtonClicked() const;
161
162     void switchToMobileMode();
163     void switchToDesktopMode();
164     bool isDesktopMode() const;
165
166 private:
167     // callbacks from WebView
168     void _favIconChanged(std::shared_ptr<tizen_browser::tools::BrowserImage> bi);
169     void _titleChanged(const std::string &);
170     void _uriChanged(const std::string &);
171     void _uriChangedOnTab(TabId);
172     void _loadFinished();
173     void _loadStarted();
174     void _loadStop();
175     void _loadError();
176     void _forwardEnableChanged(bool);
177     void _backwardEnableChanged(bool);
178     void _loadProgress(double);
179     void _confirmationRequest(WebConfirmationPtr) ;
180     void _IMEStateChanged(bool);
181     void webViewClicked();
182
183     /**
184      * disconnect signals from specified WebView
185      * \param WebView
186      */
187     void disconnectSignals(WebViewPtr);
188
189     void disconnectCurrentWebViewSignals();
190
191     /**
192      * connect signals of specified WebView
193      * \param WebView
194      */
195     void connectSignals(WebViewPtr);
196
197 private:
198     bool m_initialised;
199     bool m_privateMode;
200     void * m_guiParent;
201
202     // current TabId
203     TabId m_currentTabId;
204     // current WebView
205     WebViewPtr m_currentWebView;
206
207     // map of all tabs (WebViews)
208     std::map<TabId, WebViewPtr > m_tabs;
209     // Most recent tab list
210     std::list<TabId> m_mostRecentTab;
211     // recently added tabs first
212     std::list<TabId> m_chronoTabs;
213 };
214
215 } /* end of webkitengine_service */
216 } /* end of basic_webengine */
217 } /* end of tizen_browser */
218
219 #endif /* WEBKITENGINESERVICE_H_ */