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