[Release] wrt_0.8.169
[platform/framework/web/wrt.git] / src / view / webkit / view_logic.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file    view_logic.h
18  * @author  Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @brief   Declaration file for view logic for Webkit2
20  */
21
22 #ifndef VIEW_LOGIC_H_
23 #define VIEW_LOGIC_H_
24
25 #include <i_view_module.h>
26 #include <memory>
27 #include <map>
28 #include <string>
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
31
32 #include <widget_model.h>
33 #include <i_runnable_widget_object.h>
34 #include <common/view_logic_apps_support.h>
35 #include <common/view_logic_vibration_support.h>
36
37 #include <EWebKit2.h>
38
39 class SchemeSupport;
40 namespace ViewModule {
41 class SecurityOriginSupport;
42 class CertificateSupport;
43 }
44
45 class ViewLogic : public ViewModule::IViewModule
46 {
47   public:
48     ViewLogic();
49     virtual ~ViewLogic();
50
51     // IViewModule Impl
52     bool createWebView(Ewk_Context* context,
53                        Evas_Object* window);
54     void destroyWebView();
55     void prepareView(WidgetModel* m, const std::string &startUrl);
56     void showWidget();
57     void hideWidget();
58     void suspendWidget();
59     void resumeWidget();
60     void resetWidget();
61     void backward();
62     void reloadStartPage();
63     Evas_Object* getCurrentWebview();
64     void fireJavascriptEvent(int event, void* data);
65     void setUserCallbacks(const WRT::UserDelegatesPtr& cbs);
66     void checkSyncMessageFromBundle(
67             const char* name,
68             const char* body,
69             char** returnData);
70     void downloadData(const char* url);
71     void activateVibration(bool on, uint64_t time);
72
73
74   private:
75     void initializeSupport();
76     void initializePluginLoading();
77
78     // EwkView operations
79     void ewkClientInit(Evas_Object *wkView);
80     void ewkClientDeinit(Evas_Object *wkView);
81     bool createEwkView(Evas* canvas);
82     void setStartPage();
83     void prepareEwkView(Evas_Object *wkView);
84     void removeEwkView(Evas_Object *wkView);
85     void resumeEwkView(Evas_Object *wkView);
86     void suspendEwkView(Evas_Object *wkView);
87     void setEwkViewVisible(Evas_Object *wkView);
88     void setEwkViewInvisible(Evas_Object *wkView);
89     void resumeWebkit(Evas_Object *wkView);
90     void suspendWebkit(Evas_Object *wkView);
91
92     // WKPageLoaderClient
93     static void loadStartedCallback(
94         void* data,
95         Evas_Object* obj,
96         void* eventInfo);
97     static void loadFinishedCallback(
98         void* data,
99         Evas_Object* obj,
100         void* eventInfo);
101     static void titleChangedCallback(
102         void* data,
103         Evas_Object* obj,
104         void* eventInfo);
105     static void loadProgressCallback(
106         void* data,
107         Evas_Object* obj,
108         void* eventInfo);
109     static void loadProgressFinishedCallback(
110         void* data,
111         Evas_Object* obj,
112         void* eventInfo);
113     static void processCrashedCallback(
114         void* data,
115         Evas_Object* obj,
116         void* eventInfo);
117
118     // EWK Callback
119     static void createWindowCallback(
120         void* data,
121         Evas_Object* obj,
122         void* eventInfo);
123     static void closeWindowCallback(
124         void* data,
125         Evas_Object* obj,
126         void* eventInfo);
127
128     // EWK PolicyDecide Callback
129     static void policyNavigationDecideCallback(
130         void* data,
131         Evas_Object* obj,
132         void* eventInfo);
133     static void policyNewWindowDecideCallback(
134         void* data,
135         Evas_Object* obj,
136         void* eventInfo);
137     static void pageResponseDecideCallback(
138         void* data,
139         Evas_Object* obj,
140         void* eventInfo);
141
142     // EWK ContextMenu Callback
143     static void contextmenuCustomizeCallback(
144         void* data,
145         Evas_Object* obj,
146         void* eventInfo);
147
148     // EWK FormClient Callback
149     static void formSubmitCallback(
150         void *data,
151         Evas_Object *obj,
152         void *eventInfo);
153
154     // EWK Geolocation Callback
155     static void geolocationPermissionRequestCallback(
156         void* data,
157         Evas_Object* obj,
158         void* eventInfo);
159
160     // EWK Notification Callback
161     static void notificationShowCallback(
162         void* data,
163         Evas_Object* obj,
164         void* eventInfo);
165     static void notificationCancelCallback(
166         void* data,
167         Evas_Object* obj,
168         void* eventInfo);
169     static void notificationPermissionRequestCallback(
170         void* data,
171         Evas_Object* obj,
172         void* eventInfo);
173
174     // EWK Orientation Callback
175     static Eina_Bool orientationLockCallback(
176         Evas_Object* obj,
177         Eina_Bool needLock,
178         int orientation,
179         void* data);
180
181     // EWK Fullscreen API callbacks
182     static void enterFullscreenCallback(
183         void* data,
184         Evas_Object* obj,
185         void* eventInfo);
186     static void exitFullscreenCallback(
187         void* data,
188         Evas_Object* obj,
189         void* eventInfo);
190
191     // EWK IME Change/Show/Hide Callback
192     static void imeChangedCallback(
193         void* data,
194         Evas_Object* obj,
195         void* eventInfo);
196     static void imeOpenedCallback(
197         void* data,
198         Evas_Object* obj,
199         void* eventInfo);
200     static void imeClosedCallback(
201         void* data,
202         Evas_Object* obj,
203         void* eventInfo);
204
205     // EWK Usermedia Callback
206     static void usermediaPermissionRequestCallback(
207         void* data,
208         Evas_Object* obj,
209         void* eventInfo);
210
211     // custom content/scheme handlers
212     static void protocolHandlerRegistrationCallback(void* data,
213                                                     Evas_Object* obj,
214                                                     void* eventInfo);
215     static void protocolHandlerIsRegisteredCallback(void* data,
216                                                     Evas_Object* obj,
217                                                     void* eventInfo);
218     static void protocolHandlerUnregistrationCallback(void* data,
219                                                       Evas_Object* obj,
220                                                       void* eventInfo);
221
222     static void contentHandlerRegistrationCallback(void* data,
223                                                    Evas_Object* obj,
224                                                    void* eventInfo);
225     static void contentHandlerIsRegisteredCallback(void* data,
226                                                    Evas_Object* obj,
227                                                    void* eventInfo);
228     static void contentHandlerUnregistrationCallback(void* data,
229                                                      Evas_Object* obj,
230                                                      void* eventInfo);
231
232     static void certificateConfirmRequestCallback(
233         void* data,
234         Evas_Object* obj,
235         void* eventInfo);
236     bool askUserForCertificateConfirm();
237     static void authenticationChallengeRequestCallback(
238         void* data,
239         Evas_Object* obj,
240         void* eventInfo);
241
242     static void viewFrameRenderedCallback(
243         void* data,
244         Evas_Object* obj,
245         void* eventInfo);
246
247     void attachToCustomHandlersDao();
248     void detachFromCustomHandlersDao();
249
250     // JS execute callback
251     static void didRunJavaScriptCallback(
252         Evas_Object* obj,
253         const char* result,
254         void* userData);
255
256     // idler callback
257     static Eina_Bool windowCloseIdlerCallback(void *data);
258
259     // security
260     std::string requestUrlBlocked(const std::string& blockedUrl);
261     std::string requestUrlChanged(const std::string& changedUrl);
262
263     // window
264     void windowClose(void);
265
266     Ewk_Context* m_ewkContext;
267     bool m_attachedToCustomHandlerDao;
268     std::list<Evas_Object*> m_ewkViewList;
269     Evas_Object* m_currentEwkView;
270     Evas_Object* m_closedEwkView;
271     Evas_Object* m_window;
272     WidgetModel* m_model;
273     std::string m_currentUri;
274     std::string m_blockedUri;
275     std::string m_currentTitle;
276     std::string m_theme;
277     std::string m_startUrl;
278     WRT::UserDelegatesPtr m_cbs;
279     size_t m_imeWidth;
280     size_t m_imeHeight;
281     bool m_isBackgroundReload;
282     bool m_isBackgroundSupport;
283
284     std::unique_ptr<SchemeSupport> m_schemeSupport;
285     std::unique_ptr<ViewModule::AppsSupport> m_appsSupport;
286     std::unique_ptr<ViewModule::VibrationSupport> m_vibrationSupport;
287     std::unique_ptr<ViewModule::SecurityOriginSupport> m_securityOriginSupport;
288     std::unique_ptr<ViewModule::CertificateSupport> m_certificateSupport;
289     
290     static std::map<const std::string, const Evas_Smart_Cb> m_ewkCallbacksMap;
291 };
292
293 #endif //VIEW_LOGIC_H_