Custom handler callbacks connected to JS API.
[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 <dpl/log/log.h>
28 #include <dpl/assert.h>
29
30 #include <widget_model.h>
31 #include <i_runnable_widget_object.h>
32 #include <common/view_logic_apps_support.h>
33 #include <common/view_logic_vibration_support.h>
34
35 #include <EWebKit2.h>
36
37 class SchemeSupport;
38 namespace ViewModule {
39 class SecurityOriginSupport;
40 }
41
42 class ViewLogic : public ViewModule::IViewModule
43 {
44   public:
45     ViewLogic();
46     virtual ~ViewLogic();
47
48     void createWebView(Ewk_Context* context,
49                        Evas_Object* window);
50     void destroyWebView();
51     void initialize();
52     void terminate();
53     void prepareView(WidgetModel* m, const std::string &startUrl);
54     void showWidget();
55     void hideWidget();
56     void suspendWidget();
57     void resumeWidget();
58     void resetWidget();
59     void backward();
60     void reload();
61     void forward();
62     void reloadStartPage();
63     Evas_Object* getCurrentWebview();
64     void fireJavascriptEvent(int event, void* data);
65     void setUserCallbacks(const WRT::UserDelegatesPtr& cbs);
66
67     // Ewk_Context operations
68     void initializeEwkContext(Ewk_Context* context);
69     void finalizeEwkContext();
70
71   private:
72     void initializeSupport();
73     void initializePluginLoading();
74
75     // EwkView operations
76     void ewkClientInit(Evas_Object *wkView);
77     void ewkClientDeinit(Evas_Object *wkView);
78     void createEwkView(Evas* canvas);
79     void setStartPage();
80     void prepareEwkView(Evas_Object *wkView);
81     void removeEwkView(Evas_Object *wkView);
82     void resumeEwkView(Evas_Object *wkView);
83     void suspendEwkView(Evas_Object *wkView);
84     void resumeWebkit(Evas_Object *wkView);
85     void suspendWebkit(Evas_Object *wkView);
86
87     // message from injected bundle Callback
88     static void contextMessageFromInjectedBundleCallback(
89             const char* name,
90             const char* body,
91             char** returnData,
92             void* userData);
93
94     // EWK Context Callback
95     static void didStartDownloadCallback(
96             const char* downloadUrl,
97             void* data);
98
99     // WKPageLoaderClient
100     static void loadStartedCallback(
101             void* data,
102             Evas_Object* obj,
103             void* eventInfo);
104     static void loadFinishedCallback(
105             void* data,
106             Evas_Object* obj,
107             void* eventInfo);
108     static void titleChangedCallback(
109             void* data,
110             Evas_Object* obj,
111             void* eventInfo);
112     static void loadProgressCallback(
113             void* data,
114             Evas_Object* obj,
115             void* eventInfo);
116     static void loadProgressFinishedCallback(
117             void* data,
118             Evas_Object* obj,
119             void* eventInfo);
120     static void processCrashedCallback(
121             void* data,
122             Evas_Object* obj,
123             void* eventInfo);
124
125     // EWK Callback
126     static void createWindowCallback(
127             void* data,
128             Evas_Object* obj,
129             void* eventInfo);
130     static void closeWindowCallback(
131             void* data,
132             Evas_Object* obj,
133             void* eventInfo);
134
135     // EWK PolicyDecide Callback
136     static void policyNavigationDecideCallback(
137             void* data,
138             Evas_Object* obj,
139             void* eventInfo);
140     static void policyNewWindowDecideCallback(
141             void* data,
142             Evas_Object* obj,
143             void* eventInfo);
144     static void pageResponseDecideCallback(
145             void* data,
146             Evas_Object* obj,
147             void* eventInfo);
148
149     // EWK ContextMenu Callback
150     static void contextmenuCustomizeCallback(
151             void* data,
152             Evas_Object* obj,
153             void* eventInfo);
154
155     // EWK FormClient Callback
156     static void formSubmitCallback(
157             void *data,
158             Evas_Object *obj,
159             void *eventInfo);
160
161     // EWK Geolocation Callback
162     static void geolocationPermissionRequestCallback(
163             void* data,
164             Evas_Object* obj,
165             void* eventInfo);
166
167     // EWK Notification Callback
168     static void notificationShowCallback(
169             void* data,
170             Evas_Object* obj,
171             void* eventInfo);
172     static void notificationCancelCallback(
173             void* data,
174             Evas_Object* obj,
175             void* eventInfo);
176     static void notificationPermissionRequestCallback(
177             void* data,
178             Evas_Object* obj,
179             void* eventInfo);
180
181     // EWK Vibration Callback
182     static void vibrationVibrateCallback(
183             void* data,
184             Evas_Object* obj,
185             void* eventInfo);
186     static void vibrationCancelCallback(
187             void* data,
188             Evas_Object* obj,
189             void* eventInfo);
190
191     // EWK Orientation Callback
192     static Eina_Bool orientationLockCallback(
193             Evas_Object* obj,
194             Eina_Bool needLock,
195             int orientation,
196             void* data);
197
198     // EWK Fullscreen API callbacks
199     static void enterFullscreenCallback(
200             void* data,
201             Evas_Object* obj,
202             void* eventInfo);
203     static void exitFullscreenCallback(
204             void* data,
205             Evas_Object* obj,
206             void* eventInfo);
207
208     // EWK IME Show/Hide Callback
209     static void imeOpenCallback(
210             void* data,
211             Evas_Object* obj,
212             void* eventInfo);
213     static void imeCloseCallback(
214             void* data,
215             Evas_Object* obj,
216             void* eventInfo);
217
218     static void debugCustomHandlerData(void* data);
219
220     // custom content/scheme handlers
221     static void protocolHandlerRegistrationCallback(void* data,
222             Evas_Object* obj,
223             void* eventInfo);
224     static void protocolHandlerIsRegisteredCallback(void* data,
225             Evas_Object* obj,
226             void* eventInfo);
227     static void protocolHandlerUnregistrationCallback(void* data,
228             Evas_Object* obj,
229             void* eventInfo);
230
231     static void contentHandlerRegistrationCallback(void* data,
232             Evas_Object* obj,
233             void* eventInfo);
234     static void contentHandlerIsRegisteredCallback(void* data,
235             Evas_Object* obj,
236             void* eventInfo);
237     static void contentHandlerUnregistrationCallback(void* data,
238             Evas_Object* obj,
239             void* eventInfo);
240
241     // JS execute callback
242     static void didRunJavaScriptCallback(
243             Evas_Object* obj,
244             const char* result,
245             void* userData);
246
247     // idler callback
248     static Eina_Bool windowCloseIdlerCallback(void *data);
249
250     // appcore event callback
251     static int appcoreLowMemoryCallback(void *data);
252     // database usage permission request callback
253     static void databaseUsagePermissionRequestCallback(
254         void* data,
255         Evas_Object* obj,
256         void* eventInfo);
257     // file System Permission Request Callback
258     static void fileSystemPermissionRequestCallback(
259         void* data,
260         Evas_Object* obj,
261         void* eventInfo);
262
263     //bundle
264     void didRecieveMessageFromInjectedBundle(
265             const char* name,
266             const char* body);
267     void didReceiveSynchronousMessage(
268             const char* name,
269             const char* body,
270             char** returnData);
271
272     // security
273     void rememberBlockedURI(const DPL::String& str);
274     std::string requestUriChanged(const DPL::String& changedURL);
275
276     // window
277     void windowClose(void);
278
279     Ewk_Context* m_ewkContext;
280     std::list<Evas_Object*> m_ewkViewList;
281     Evas_Object* m_currentEwkView;
282     Evas_Object* m_closedEwkView;
283     Evas_Object* m_window;
284     WidgetModel* m_model;
285     std::string m_currentUri;
286     std::string m_blockedUri;
287     std::string m_theme;
288     std::string m_startUrl;
289     WRT::UserDelegatesPtr m_cbs;
290
291     std::unique_ptr<SchemeSupport> m_schemeSupport;
292     std::unique_ptr<ViewModule::AppsSupport> m_appsSupport;
293     std::unique_ptr<ViewModule::VibrationSupport> m_vibrationSupport;
294     std::unique_ptr<ViewModule::SecurityOriginSupport> m_securityOriginSupport;
295 };
296
297 #endif //VIEW_LOGIC_H_