[Release] wrt_0.8.257
[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 #include <system_settings.h>
37
38 #include <EWebKit2.h>
39
40 class SchemeSupport;
41 namespace ViewModule {
42 class SecurityOriginSupport;
43 class CertificateSupport;
44 }
45
46 class ViewLogic : public ViewModule::IViewModule
47 {
48   public:
49     ViewLogic();
50     virtual ~ViewLogic();
51
52     // IViewModule Impl
53     bool createWebView(Ewk_Context* context,
54                        Evas_Object* window);
55     void destroyWebView();
56     void prepareView(WidgetModel* m, const std::string &startUrl);
57     void showWidget();
58     void hideWidget();
59     void suspendWidget();
60     void resumeWidget();
61     void resetWidget();
62     void backward();
63     void reloadStartPage();
64     Evas_Object* getCurrentWebview();
65     void fireJavascriptEvent(int event, void* data);
66     void setUserCallbacks(const WRT::UserDelegatesPtr& cbs);
67     void checkSyncMessageFromBundle(
68             const char* name,
69             const char* body,
70             char** returnData);
71     void checkAsyncMessageFromBundle(
72             const char* name,
73             const char* body);
74     void downloadData(const char* url);
75     void activateVibration(bool on, uint64_t time);
76
77
78   private:
79     void initializeSupport();
80     void initializePluginLoading();
81     void initializeXwindowHandle();
82
83     // EwkView operations
84     void ewkClientInit(Evas_Object *wkView);
85     void ewkClientDeinit(Evas_Object *wkView);
86     bool createEwkView(Evas* canvas);
87     void prepareEwkView(Evas_Object *wkView);
88     void removeEwkView(Evas_Object *wkView);
89     void setEwkViewVisible(Evas_Object *wkView);
90     void setEwkViewInvisible(Evas_Object *wkView);
91     void resumeWebkit(Evas_Object *wkView);
92     void suspendWebkit(Evas_Object *wkView);
93
94     // WKPageLoaderClient
95     static void loadStartedCallback(
96         void* data,
97         Evas_Object* obj,
98         void* eventInfo);
99     static void loadFinishedCallback(
100         void* data,
101         Evas_Object* obj,
102         void* eventInfo);
103     static void titleChangedCallback(
104         void* data,
105         Evas_Object* obj,
106         void* eventInfo);
107     static void loadProgressStartedCallback(
108         void* data,
109         Evas_Object* obj,
110         void* eventInfo);
111     static void loadProgressCallback(
112         void* data,
113         Evas_Object* obj,
114         void* eventInfo);
115     static void loadProgressFinishedCallback(
116         void* data,
117         Evas_Object* obj,
118         void* eventInfo);
119     static void processCrashedCallback(
120         void* data,
121         Evas_Object* obj,
122         void* eventInfo);
123
124     // EWK Callback
125     static void createWindowCallback(
126         void* data,
127         Evas_Object* obj,
128         void* eventInfo);
129     static void closeWindowCallback(
130         void* data,
131         Evas_Object* obj,
132         void* eventInfo);
133
134     // EWK PolicyDecide Callback
135     static void policyNavigationDecideCallback(
136         void* data,
137         Evas_Object* obj,
138         void* eventInfo);
139     static void policyNewWindowDecideCallback(
140         void* data,
141         Evas_Object* obj,
142         void* eventInfo);
143     static void pageResponseDecideCallback(
144         void* data,
145         Evas_Object* obj,
146         void* eventInfo);
147
148     // EWK ContextMenu Callback
149     static void contextmenuCustomizeCallback(
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     static Eina_Bool exceededDatabaseQuotaCallback(Evas_Object* obj,
232                                                    Ewk_Security_Origin* origin,
233                                                    const char* databaseName,
234                                                    unsigned long long expectedQuota,
235                                                    void* data);
236     static Eina_Bool exceededIndexedDatabaseQuotaCallback(Evas_Object* obj,
237                                                           Ewk_Security_Origin* origin,
238                                                           long long expectedQuota,
239                                                           void* data);
240     static Eina_Bool exceededLocalFileSystemQuotaCallback(Evas_Object* obj,
241                                                           Ewk_Security_Origin* origin,
242                                                           long long expectedQuota,
243                                                           void* data);
244     static void certificateConfirmRequestCallback(
245         void* data,
246         Evas_Object* obj,
247         void* eventInfo);
248     static void authenticationChallengeRequestCallback(
249         void* data,
250         Evas_Object* obj,
251         void* eventInfo);
252
253     static void viewFrameRenderedCallback(
254         void* data,
255         Evas_Object* obj,
256         void* eventInfo);
257
258     static void mediacontrolRotateHorizontal(void* data,
259                                              Evas_Object* obj,
260                                              void* eventInfo);
261     static void mediacontrolRotateVertical(void* data,
262                                            Evas_Object* obj,
263                                            void* eventInfo);
264     static void mediacontrolRotateExit(void* data,
265                                        Evas_Object* obj,
266                                        void* eventInfo);
267     static void popupReplyWaitStart(void* data,
268                                     Evas_Object* obj,
269                                     void* eventInfo);
270     static void popupReplyWaitFinish(void* data,
271                                      Evas_Object* obj,
272                                      void* eventInfo);
273
274     void attachToCustomHandlersDao();
275     void detachFromCustomHandlersDao();
276
277     // JS execute callback
278     static void didRunJavaScriptCallback(
279         Evas_Object* obj,
280         const char* result,
281         void* userData);
282
283     // event callback
284     static void eaKeyCallback(void* data,
285                               Evas_Object* obj,
286                               void* eventInfo);
287
288     // idler callback
289     static Eina_Bool windowCloseIdlerCallback(void *data);
290
291     // timer callback
292     static Eina_Bool orientationThresholdTimerCallback(void* data);
293
294     // security
295     void requestUrlBlocked(const std::string& blockedUrl);
296
297     // window
298     void windowClose(void);
299
300     // system settings
301     static void systemSettingsChangedCallback(system_settings_key_e key, void* data);
302
303     Ewk_Context* m_ewkContext;
304     bool m_attachedToCustomHandlerDao;
305     std::list<Evas_Object*> m_ewkViewList;
306     Evas_Object* m_currentEwkView;
307     Evas_Object* m_closedEwkView;
308     Evas_Object* m_window;
309     WidgetModel* m_model;
310     std::string m_blockedUri;
311     std::string m_currentTitle;
312     std::string m_theme;
313     std::string m_startUrl;
314     WRT::UserDelegatesPtr m_cbs;
315     size_t m_imeWidth;
316     size_t m_imeHeight;
317     bool m_isBackgroundReload;
318     bool m_isBackgroundSupport;
319     int m_rotateAngle;
320     int m_deferredRotateAngle;
321     Ecore_Timer* m_orientationThresholdTimer;
322     bool m_isPopupReplyWait;
323
324     std::unique_ptr<SchemeSupport> m_schemeSupport;
325     std::unique_ptr<ViewModule::AppsSupport> m_appsSupport;
326     std::unique_ptr<ViewModule::VibrationSupport> m_vibrationSupport;
327     std::unique_ptr<ViewModule::SecurityOriginSupport> m_securityOriginSupport;
328     std::unique_ptr<ViewModule::CertificateSupport> m_certificateSupport;
329
330     static std::map<const std::string, const Evas_Smart_Cb> m_ewkCallbacksMap;
331 };
332
333 #endif //VIEW_LOGIC_H_