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