[Release] wrt_0.8.180
[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 Geolocation Callback
149     static void geolocationPermissionRequestCallback(
150         void* data,
151         Evas_Object* obj,
152         void* eventInfo);
153
154     // EWK Notification Callback
155     static void notificationShowCallback(
156         void* data,
157         Evas_Object* obj,
158         void* eventInfo);
159     static void notificationCancelCallback(
160         void* data,
161         Evas_Object* obj,
162         void* eventInfo);
163     static void notificationPermissionRequestCallback(
164         void* data,
165         Evas_Object* obj,
166         void* eventInfo);
167
168     // EWK Orientation Callback
169     static Eina_Bool orientationLockCallback(
170         Evas_Object* obj,
171         Eina_Bool needLock,
172         int orientation,
173         void* data);
174
175     // EWK Fullscreen API callbacks
176     static void enterFullscreenCallback(
177         void* data,
178         Evas_Object* obj,
179         void* eventInfo);
180     static void exitFullscreenCallback(
181         void* data,
182         Evas_Object* obj,
183         void* eventInfo);
184
185     // EWK IME Change/Show/Hide Callback
186     static void imeChangedCallback(
187         void* data,
188         Evas_Object* obj,
189         void* eventInfo);
190     static void imeOpenedCallback(
191         void* data,
192         Evas_Object* obj,
193         void* eventInfo);
194     static void imeClosedCallback(
195         void* data,
196         Evas_Object* obj,
197         void* eventInfo);
198
199     // EWK Usermedia Callback
200     static void usermediaPermissionRequestCallback(
201         void* data,
202         Evas_Object* obj,
203         void* eventInfo);
204
205     // custom content/scheme handlers
206     static void protocolHandlerRegistrationCallback(void* data,
207                                                     Evas_Object* obj,
208                                                     void* eventInfo);
209     static void protocolHandlerIsRegisteredCallback(void* data,
210                                                     Evas_Object* obj,
211                                                     void* eventInfo);
212     static void protocolHandlerUnregistrationCallback(void* data,
213                                                       Evas_Object* obj,
214                                                       void* eventInfo);
215
216     static void contentHandlerRegistrationCallback(void* data,
217                                                    Evas_Object* obj,
218                                                    void* eventInfo);
219     static void contentHandlerIsRegisteredCallback(void* data,
220                                                    Evas_Object* obj,
221                                                    void* eventInfo);
222     static void contentHandlerUnregistrationCallback(void* data,
223                                                      Evas_Object* obj,
224                                                      void* eventInfo);
225
226     static void certificateConfirmRequestCallback(
227         void* data,
228         Evas_Object* obj,
229         void* eventInfo);
230     bool askUserForCertificateConfirm();
231     static void authenticationChallengeRequestCallback(
232         void* data,
233         Evas_Object* obj,
234         void* eventInfo);
235
236     static void viewFrameRenderedCallback(
237         void* data,
238         Evas_Object* obj,
239         void* eventInfo);
240
241 #ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
242     static int appServiceCallerIsKilled(void *data);
243 #endif
244
245     void attachToCustomHandlersDao();
246     void detachFromCustomHandlersDao();
247
248     // JS execute callback
249     static void didRunJavaScriptCallback(
250         Evas_Object* obj,
251         const char* result,
252         void* userData);
253
254     // idler callback
255     static Eina_Bool windowCloseIdlerCallback(void *data);
256
257     // security
258     std::string requestUrlBlocked(const std::string& blockedUrl);
259     std::string requestUrlChanged(const std::string& changedUrl);
260
261     // window
262     void windowClose(void);
263
264     Ewk_Context* m_ewkContext;
265     bool m_attachedToCustomHandlerDao;
266     std::list<Evas_Object*> m_ewkViewList;
267     Evas_Object* m_currentEwkView;
268     Evas_Object* m_closedEwkView;
269     Evas_Object* m_window;
270     WidgetModel* m_model;
271     std::string m_currentUri;
272     std::string m_blockedUri;
273     std::string m_currentTitle;
274     std::string m_theme;
275     std::string m_startUrl;
276     WRT::UserDelegatesPtr m_cbs;
277     size_t m_imeWidth;
278     size_t m_imeHeight;
279     bool m_isBackgroundReload;
280     bool m_isBackgroundSupport;
281
282     std::unique_ptr<SchemeSupport> m_schemeSupport;
283     std::unique_ptr<ViewModule::AppsSupport> m_appsSupport;
284     std::unique_ptr<ViewModule::VibrationSupport> m_vibrationSupport;
285     std::unique_ptr<ViewModule::SecurityOriginSupport> m_securityOriginSupport;
286     std::unique_ptr<ViewModule::CertificateSupport> m_certificateSupport;
287
288     static std::map<const std::string, const Evas_Smart_Cb> m_ewkCallbacksMap;
289 };
290
291 #endif //VIEW_LOGIC_H_