Implemented ZoomUI service
[profile/tv/apps/web/browser.git] / services / WebKitEngineService / WebView.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 WEBVIEW_H_
18 #define WEBVIEW_H_
19
20 #include <boost/signals2/signal.hpp>
21 #include <string>
22 #include <Evas.h>
23
24 #if defined(USE_EWEBKIT)
25 //#include <EWebKit2.h>
26 #include <ewk_chromium.h>
27 #endif
28
29 #include "browser_config.h"
30 #include "Config/Config.h"
31 #include "BrowserImage.h"
32 #include "AbstractWebEngine/TabId.h"
33 #include "AbstractWebEngine/WebConfirmation.h"
34
35 namespace tizen_browser {
36 namespace basic_webengine {
37 namespace webkitengine_service {
38
39 class WebView
40 {
41 public:
42     WebView(Evas_Object *, TabId);
43     virtual ~WebView();
44     void init(bool desktopMode, Evas_Object * opener = NULL);
45
46     void setURI(const std::string &);
47     std::string getURI(void);
48
49     std::string getTitle(void);
50
51     void stopLoading(void);
52     void reload(void);
53
54     void back(void);
55     void forward(void);
56
57     bool isBackEnabled(void);
58     bool isForwardEnabled(void);
59
60     bool isLoading();
61     bool isLoadError() const;
62
63     Evas_Object * getLayout();
64
65     void confirmationResult(WebConfirmationPtr);
66
67     void setPrivateMode(bool);
68
69     std::shared_ptr<tizen_browser::tools::BrowserImage> captureSnapshot(int width, int height);
70      /**
71      * \brief Sets Focus to URI entry.
72      */
73     void setFocus();
74
75     /**
76      * @brief Remove focus form URI
77      */
78     void clearFocus();
79
80     /**
81      * @brief check if URI is focused
82      */
83     bool hasFocus() const;
84
85     /**
86      * @brief get current real zoom factor from webkit
87      */
88     double getZoomFactor() const;
89
90     /**
91      * @brief set zoom factor of website
92      */
93     void setZoomFactor(double zoomFactor);
94
95
96     void clearPrivateData();
97
98     /**
99      * @return tab id
100      */
101     const TabId& getTabId();
102
103     /**
104      * @brief Search string on searchOnWebsite
105      *
106      * @param string to search on searchOnWebsite
107      * @param flags for search options
108      */
109     void searchOnWebsite(const std::string &, int);
110
111     /**
112      * @brief Change user agent to desktop type
113      */
114     void switchToDesktopMode();
115
116     /**
117      * @brief Change user agent to mobile type
118      */
119     void switchToMobileMode();
120
121     /**
122      * @brief Check if desktop mode is enabled
123      *
124      * @return true if desktop mode is enabled
125      */
126     bool isDesktopMode() const;
127
128     /**
129      * @brief Get favicon of URL
130      */
131     std::shared_ptr<tizen_browser::tools::BrowserImage> getFavicon();
132
133     /**
134      * Sets an absolute scroll of the given view.
135      *
136      * Both values are from zero to the contents size minus the viewport
137      * size.
138      *
139      * @param x horizontal position to scroll
140      * @param y vertical position to scroll
141      */
142     void scrollView(const int& dx, const int& dy);
143
144 // signals
145     boost::signals2::signal<void (std::shared_ptr<tizen_browser::tools::BrowserImage>)> favIconChanged;
146     boost::signals2::signal<void (const std::string &)> titleChanged;
147     boost::signals2::signal<void (const std::string)> uriChanged;
148     boost::signals2::signal<void (TabId)> tabIdChecker;
149
150     boost::signals2::signal<void ()> loadFinished;
151     boost::signals2::signal<void ()> loadStarted;
152     boost::signals2::signal<void ()> loadStop;
153     boost::signals2::signal<void ()> loadError;
154     boost::signals2::signal<void (double)> loadProgress;
155
156     boost::signals2::signal<void (bool)> forwardEnableChanged;
157     boost::signals2::signal<void (bool)> backwardEnableChanged;
158
159     boost::signals2::signal<void (WebConfirmationPtr)> cofirmationRequest;
160
161     boost::signals2::signal<void ()> ewkViewClicked;
162
163     boost::signals2::signal<void (bool)> IMEStateChanged;
164
165 private:
166     void registerCallbacks();
167     void unregisterCallbacks();
168     void setupEwkSettings();
169
170 #if defined(USE_EWEBKIT)
171     static std::string securityOriginToUri(const Ewk_Security_Origin *);
172     static void __setFocusToEwkView(void * data, Evas * e, Evas_Object * obj, void * event_info);
173     static void __newWindowRequest(void * data, Evas_Object *, void *out);
174     static void __closeWindowRequest(void * data, Evas_Object *, void *);
175 #endif
176
177     // Load
178     static void __loadStarted(void * data, Evas_Object * obj, void * event_info);
179     static void __loadStop(void * data, Evas_Object * obj, void * event_info);
180     static void __loadFinished(void * data, Evas_Object * obj, void * event_info);
181     static void __loadProgress(void * data, Evas_Object * obj, void * event_info);
182     static void __loadError(void* data, Evas_Object* obj, void *ewkError);
183
184     static void __titleChanged(void * data, Evas_Object * obj, void * event_info);
185     static void __urlChanged(void * data, Evas_Object * obj, void * event_info);
186
187     static void __backForwardListChanged(void * data, Evas_Object * obj, void * event_info);
188
189     // Favicon - from database
190     static void __faviconChanged(void* data, Evas_Object*, void*);
191
192     static void __IMEClosed(void * data, Evas_Object *obj, void *event_info);
193     static void __IMEOpened(void * data, Evas_Object *obj, void *event_info);
194
195     // confirmation requests
196     static void __geolocationPermissionRequest(void * data, Evas_Object * obj, void * event_info);
197     static void __usermediaPermissionRequest(void * data, Evas_Object * obj, void * event_info);
198     static void __notificationPermissionRequest(void * data, Evas_Object * obj, void * event_info);
199     static void __authenticationRequest(void * data, Evas_Object * obj, void * event_info);
200     static void __requestCertificationConfirm(void * data, Evas_Object * obj, void * event_info);
201
202     static void scriptLinkSearchCallback(Evas_Object *o, const char *value, void *data);
203 private:
204     Evas_Object * m_parent;
205     TabId m_tabId;
206     Evas_Object * m_ewkView;
207     // ewk context of this web view
208     Ewk_Context * m_ewkContext;
209     std::string m_title;
210     std::shared_ptr<tizen_browser::tools::BrowserImage> faviconImage;
211     bool m_isLoading;
212     double m_loadProgress;
213     bool m_loadError;
214     // true if desktop view is enabled, false if mobile
215     bool m_desktopMode;
216
217     config::DefaultConfig config;
218
219 #if defined(USE_EWEBKIT)
220 #if PLATFORM(TIZEN)
221     std::map<WebConfirmationPtr, Ewk_Geolocation_Permission_Request *> m_confirmationGeolocationMap;
222     std::map<WebConfirmationPtr, Ewk_User_Media_Permission_Request *> m_confirmationUserMediaMap;
223     std::map<WebConfirmationPtr, Ewk_Notification_Permission_Request *> m_confirmationNotificationMap;
224     std::map<CertificateConfirmationPtr, Ewk_Certificate_Policy_Decision *> m_confirmationCertificatenMap;
225     std::map<AuthenticationConfirmationPtr, Ewk_Auth_Request *> m_confirmationAuthenticationMap;
226 #endif
227 #endif
228 };
229
230 } /* namespace webkitengine_service */
231 } /* end of basic_webengine */
232 } /* end of tizen_browser */
233 #endif /* WEBVIEW_H_ */