[WK2] Apply new quota policy for Web Database
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / EwkViewImpl.h
1 /*
2    Copyright (C) 2011 Samsung Electronics
3    Copyright (C) 2012 Intel Corporation. All rights reserved.
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18     Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef EwkViewImpl_h
22 #define EwkViewImpl_h
23
24 #include "RefPtrEfl.h"
25 #include "WKEinaSharedString.h"
26 #include "WKRetainPtr.h"
27 #include <Evas.h>
28 #include <WebCore/TextDirection.h>
29 #include <WebCore/Timer.h>
30 #include <WebKit2/WKBase.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/OwnPtr.h>
33 #include <wtf/RefPtr.h>
34 #include <wtf/text/WTFString.h>
35
36 #if ENABLE(TOUCH_EVENTS)
37 #include "ewk_touch.h"
38 #endif
39
40 #if USE(ACCELERATED_COMPOSITING)
41 #include <Evas_GL.h>
42 #endif
43
44 #if OS(TIZEN)
45 #include "JavaScriptPopup.h"
46 #include "OpenPanel.h"
47 #include "ewk_auth_challenge_private.h"
48 #include <JavaScriptCore/JSRetainPtr.h>
49 #include <WebCore/IntPoint.h>
50
51 #if ENABLE(TIZEN_GESTURE)
52 #include "GestureRecognizer.h"
53 #include "GestureClient.h"
54 #endif
55
56 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
57 #include "InputPicker.h"
58 #endif
59
60 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
61 #include "FocusRing.h"
62 #endif
63
64 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
65 #include "ewk_popup_picker.h"
66 #endif
67 #endif
68
69 #define EWK_VIEW_IMPL_GET(smartData, impl)                                     \
70     EwkViewImpl* impl = smartData->priv
71
72 #define EWK_VIEW_IMPL_GET_OR_RETURN(smartData, impl, ...)                      \
73     if (!smartData) {                                                          \
74         EINA_LOG_CRIT("smart data is null");                                   \
75         return __VA_ARGS__;                                                    \
76     }                                                                          \
77     EWK_VIEW_IMPL_GET(smartData, impl);                                        \
78     do {                                                                       \
79         if (!impl) {                                                           \
80             EINA_LOG_CRIT("no private data for object %p (%s)",                \
81                 smartData->self, evas_object_type_get(smartData->self));       \
82             return __VA_ARGS__;                                                \
83         }                                                                      \
84     } while (0)
85
86 namespace WebKit {
87 class FindClientEfl;
88 class FormClientEfl;
89 class InputMethodContextEfl;
90 class PageClientImpl;
91 class PageLoadClientEfl;
92 class PagePolicyClientEfl;
93 class PageUIClientEfl;
94 class PageViewportControllerClientEfl;
95 class PageViewportController;
96 class ResourceLoadClientEfl;
97 class WebPageProxy;
98 class WebPopupItem;
99 class WebPopupMenuProxyEfl;
100 }
101
102 namespace WebCore {
103 class Color;
104 class Cursor;
105 class IntRect;
106 class IntSize;
107 }
108
109 class Ewk_Back_Forward_List;
110 class Ewk_Context;
111 class Ewk_Download_Job;
112 class Ewk_Error;
113 class Ewk_Form_Submission_Request;
114 class Ewk_Intent;
115 class Ewk_Intent_Service;
116 class Ewk_Navigation_Policy_Decision;
117 class Ewk_Resource;
118 class Ewk_Settings;
119 class Ewk_Url_Request;
120 class Ewk_Url_Response;
121
122 typedef struct Ewk_View_Smart_Data Ewk_View_Smart_Data;
123
124 #if OS(TIZEN)
125 namespace WebCore {
126 class AffineTransform;
127 }
128
129 // FIXME: we have to include ewk_view.h instead of typedef,
130 // because there are "circular include" in the local code unlike open source,
131 // so we can not do typedef again here.
132 //typedef struct Ewk_View_Smart_Data Ewk_View_Smart_Data;
133 #include "ewk_view.h"
134
135 struct Ewk_View_Callback_Context {
136     union {
137         Ewk_Web_App_Capable_Get_Callback webAppCapableCallback;
138         Ewk_Web_App_Icon_URL_Get_Callback webAppIconURLCallback;
139         Ewk_Web_App_Icon_URLs_Get_Callback webAppIconURLsCallback;
140 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
141         Ewk_Web_Storage_Quota_Get_Callback webStorageQuotaCallback;
142 #endif
143         Ewk_View_Script_Execute_Callback scriptExecuteCallback;
144         Ewk_View_Plain_Text_Get_Callback plainTextGetCallback;
145 #if ENABLE(TIZEN_SUPPORT_MHTML)
146         Ewk_View_MHTML_Data_Get_Callback mhtmlDataGetCallback;
147 #endif
148         Ewk_View_JavaScript_Alert_Callback javascriptAlertCallback;
149         Ewk_View_JavaScript_Confirm_Callback javascriptConfirmCallback;
150         Ewk_View_JavaScript_Prompt_Callback javascriptPromptCallback;
151 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
152         Ewk_View_Before_Unload_Confirm_Panel_Callback beforeUnloadConfirmPanelCallback;
153 #endif
154         Ewk_View_Open_Panel_Callback openPanelCallback;
155 #if ENABLE(TIZEN_APPLICATION_CACHE)
156         Ewk_View_Applicacion_Cache_Permission_Callback applicationCachePermissionCallback;
157 #endif
158 #if ENABLE(TIZEN_INDEXED_DATABASE)
159         Ewk_View_Exceeded_Indexed_Database_Quota_Callback exceededIndexedDatabaseQuotaCallback;
160 #endif
161 #if ENABLE(TIZEN_SQL_DATABASE)
162         Ewk_View_Exceeded_Database_Quota_Callback exceededDatabaseQuotaCallback;
163 #endif
164     };
165
166     Evas_Object* ewkView;
167     void* userData;
168 };
169 typedef struct Ewk_View_Callback_Context Ewk_View_Callback_Context;
170 #endif
171
172 class EwkViewImpl {
173 public:
174     explicit EwkViewImpl(Evas_Object* view);
175     ~EwkViewImpl();
176
177     static EwkViewImpl* fromEvasObject(const Evas_Object* view);
178
179     inline Evas_Object* view() { return m_view; }
180     WKPageRef wkPage();
181     inline WebKit::WebPageProxy* page() { return pageProxy.get(); }
182     Ewk_Context* ewkContext() { return context.get(); }
183     Ewk_Settings* settings() { return m_settings.get(); }
184
185     WebCore::IntSize size() const;
186     bool isFocused() const;
187     bool isVisible() const;
188
189     const char* url() const { return m_url; }
190     const char* faviconURL() const { return m_faviconURL; }
191     const char* title() const;
192     WebKit::InputMethodContextEfl* inputMethodContext();
193
194     const char* themePath() const;
195     void setThemePath(const char* theme);
196     const char* customTextEncodingName() const;
197     void setCustomTextEncodingName(const char* encoding);
198
199     bool mouseEventsEnabled() const { return m_mouseEventsEnabled; }
200     void setMouseEventsEnabled(bool enabled);
201 #if ENABLE(TOUCH_EVENTS)
202     bool touchEventsEnabled() const { return m_touchEventsEnabled; }
203     void setTouchEventsEnabled(bool enabled);
204 #endif
205
206     void setCursor(const WebCore::Cursor& cursor);
207     void redrawRegion(const WebCore::IntRect& rect);
208     void setImageData(void* imageData, const WebCore::IntSize& size);
209
210 #if ENABLE(INPUT_TYPE_COLOR)
211     bool setColorPickerColor(const WebCore::Color& color);
212 #endif
213
214     static void addToPageViewMap(const Evas_Object* ewkView);
215     static void removeFromPageViewMap(const Evas_Object* ewkView);
216     static const Evas_Object* viewFromPageViewMap(const WKPageRef);
217
218 #if ENABLE(FULLSCREEN_API)
219     void enterFullScreen();
220     void exitFullScreen();
221 #endif
222
223 #if USE(ACCELERATED_COMPOSITING)
224     bool createGLSurface(const WebCore::IntSize& viewSize);
225     bool enterAcceleratedCompositingMode();
226     bool exitAcceleratedCompositingMode();
227 #endif
228
229 #if ENABLE(INPUT_TYPE_COLOR)
230     void requestColorPicker(int r, int g, int b, int a, WKColorPickerResultListenerRef listener);
231     void dismissColorPicker();
232 #endif
233
234     WKPageRef createNewPage();
235     void closePage();
236
237 #if ENABLE(TIZEN_MULTIPLE_SELECT)
238     void requestPopupMenu(WebKit::WebPopupMenuProxyEfl*, const WebCore::IntRect&, WebCore::TextDirection, double pageScaleFactor, const Vector<WebKit::WebPopupItem>& items, int32_t selectedIndex, bool);
239 #else
240     void requestPopupMenu(WebKit::WebPopupMenuProxyEfl*, const WebCore::IntRect&, WebCore::TextDirection, double pageScaleFactor, const Vector<WebKit::WebPopupItem>& items, int32_t selectedIndex);
241 #endif
242     void updateTextInputState();
243
244     void requestJSAlertPopup(const WKEinaSharedString& message);
245     bool requestJSConfirmPopup(const WKEinaSharedString& message);
246     WKEinaSharedString requestJSPromptPopup(const WKEinaSharedString& message, const WKEinaSharedString& defaultValue);
247
248     void informDownloadJobCancelled(Ewk_Download_Job* download);
249     void informDownloadJobFailed(Ewk_Download_Job* download, Ewk_Error* error);
250     void informDownloadJobFinished(Ewk_Download_Job* download);
251     void informDownloadJobRequested(Ewk_Download_Job* download);
252
253     void informNewFormSubmissionRequest(Ewk_Form_Submission_Request* request);
254     void informLoadError(Ewk_Error* error);
255     void informLoadFinished();
256     void informLoadProgress(double progress);
257     void informProvisionalLoadFailed(Ewk_Error* error);
258 #if USE(TILED_BACKING_STORE)
259     void informLoadCommitted();
260 #endif
261     void informProvisionalLoadRedirect();
262     void informProvisionalLoadStarted();
263
264     void informResourceLoadStarted(Ewk_Resource* resource, Ewk_Url_Request* request);
265     void informResourceLoadResponse(Ewk_Resource* resource, Ewk_Url_Response* response);
266     void informResourceLoadFailed(Ewk_Resource* resource, Ewk_Error* error);
267     void informResourceLoadFinished(Ewk_Resource* resource);
268     void informResourceRequestSent(Ewk_Resource* resource, Ewk_Url_Request* request, Ewk_Url_Response* redirectResponse);
269
270     void informNavigationPolicyDecision(Ewk_Navigation_Policy_Decision* decision);
271     void informNewWindowPolicyDecision(Ewk_Navigation_Policy_Decision* decision);
272     void informBackForwardListChange();
273
274     void informTitleChange(const String& title);
275     void informTooltipTextChange(const String& text);
276     void informTextFound(unsigned matchCount);
277     void informIconChange();
278     void informWebProcessCrashed();
279     void informContentsSizeChange(const WebCore::IntSize& size);
280     unsigned long long informDatabaseQuotaReached(const String& databaseName, const String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage);
281     void informURLChange();
282
283 #if ENABLE(WEB_INTENTS)
284     void informIntentRequest(Ewk_Intent* ewkIntent);
285 #endif
286 #if ENABLE(WEB_INTENTS_TAG)
287     void informIntentServiceRegistration(Ewk_Intent_Service* ewkIntentService);
288 #endif
289
290 #if OS(TIZEN)
291 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
292     WebCore::AffineTransform transformFromView() const;
293     WebCore::AffineTransform transformToView() const;
294 #endif
295     WebCore::AffineTransform transformToScene() const;
296     WebCore::AffineTransform transformFromScene() const;
297     WebCore::AffineTransform transformToScreen() const;
298
299 #if ENABLE(TIZEN_WEBKIT2_SEPERATE_LOAD_PROGRESS)
300     void informLoadProgressStarted();
301     void informLoadProgressFinished();
302 #endif
303
304 #if ENABLE(TIZEN_DATALIST_ELEMENT)
305     void deleteDataList();
306 #endif
307
308 #if USE(TILED_BACKING_STORE)
309     void setScaleFactor(float scaleFactor) { m_scaleFactor = scaleFactor; }
310     float scaleFactor() const { return m_scaleFactor; }
311
312     void setScrollPosition(WebCore::IntPoint position) { m_scrollPosition = position; }
313     const WebCore::IntPoint scrollPosition() const { return m_scrollPosition; }
314 #endif
315
316 #if ENABLE(TOUCH_EVENTS) && ENABLE(TIZEN_GESTURE)
317     void feedTouchEventsByType(Ewk_Touch_Event_Type);
318 #endif
319 #endif
320
321     // FIXME: Make members private for encapsulation.
322     OwnPtr<WebKit::PageClientImpl> pageClient;
323 #if ENABLE(WAIT_UPVERSION)
324 #if USE(TILED_BACKING_STORE)
325     OwnPtr<WebKit::PageViewportControllerClientEfl> pageViewportControllerClient;
326     OwnPtr<WebKit::PageViewportController> pageViewportController;
327 #endif
328 #endif
329     RefPtr<WebKit::WebPageProxy> pageProxy;
330     OwnPtr<WebKit::PageLoadClientEfl> pageLoadClient;
331     OwnPtr<WebKit::PagePolicyClientEfl> pagePolicyClient;
332     OwnPtr<WebKit::PageUIClientEfl> pageUIClient;
333     OwnPtr<WebKit::ResourceLoadClientEfl> resourceLoadClient;
334     OwnPtr<WebKit::FindClientEfl> findClient;
335     OwnPtr<WebKit::FormClientEfl> formClient;
336
337     OwnPtr<Ewk_Back_Forward_List> backForwardList;
338     RefPtr<Ewk_Context> context;
339
340     WebKit::WebPopupMenuProxyEfl* popupMenuProxy;
341     Eina_List* popupMenuItems;
342
343 #if USE(ACCELERATED_COMPOSITING)
344     Evas_GL* evasGl;
345     Evas_GL_Context* evasGlContext;
346     Evas_GL_Surface* evasGlSurface;
347 #endif
348
349 #if OS(TIZEN)
350 #if ENABLE(TIZEN_ORIENTATION_EVENTS)
351     int orientation;
352 #endif
353
354     JSGlobalContextRef javascriptGlobalContext;
355
356     WKEinaSharedString userAgent;
357
358 #if ENABLE(TIZEN_SUPPORT_WEBAPP_META_TAG)
359     WKEinaSharedString webAppIconURL;
360     Eina_List* webAppIconURLs;
361 #endif
362
363     OwnPtr<Ewk_View_Callback_Context> alertContext;
364     OwnPtr<Ewk_View_Callback_Context> confirmContext;
365     OwnPtr<Ewk_View_Callback_Context> promptContext;
366
367 #if ENABLE(TIZEN_SUPPORT_BEFORE_UNLOAD_CONFIRM_PANEL)
368     OwnPtr<Ewk_View_Callback_Context> beforeUnloadConfirmPanelContext;
369 #endif
370
371     OwnPtr<Ewk_View_Callback_Context> openpanelContext;
372     OwnPtr<WebKit::JavaScriptPopup> javascriptPopup;
373     bool isWaitingForJavaScriptPopupReply;
374     OwnPtr<WebKit::OpenPanel> openPanel;
375
376 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
377     OwnPtr<WebKit::InputPicker> inputPicker;
378     WKEinaSharedString inputValue;
379 #endif
380
381     Ewk_Auth_Challenge* authChallenge;
382     Ewk_Policy_Decision* policyDecision;
383     WKOpenPanelResultListenerRef openPanelListener;
384
385 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
386     Ewk_Certificate_Policy_Decision* certificatePolicyDecision;
387 #endif
388
389 #if ENABLE(TIZEN_MEDIA_STREAM)
390     Eina_List* userMediaPermissionRequests;
391 #endif
392
393 #if ENABLE(TIZEN_GEOLOCATION)
394     Ewk_Geolocation* geolocation;
395     Eina_List* geolocationPermissionRequests;
396 #endif
397
398     bool suspendRequested;
399     bool suspendedPainting;
400     bool suspendedResources;
401
402 #if ENABLE(TIZEN_NOTIFICATIONS)
403     Eina_List* notifications;
404     Eina_List* notificationPermissionRequests;
405 #endif
406
407 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
408     Ewk_Popup_Picker* popupPicker;
409 #endif
410
411     bool isVerticalEdge;
412     bool isHorizontalEdge;
413
414 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
415     OwnPtr<FocusRing> focusRing;
416 #endif
417
418 #if ENABLE(TIZEN_GESTURE)
419     OwnPtr<WebKit::GestureRecognizer> gestureRecognizer;
420     OwnPtr<WebKit::GestureClient> gestureClient;
421 #if ENABLE(TOUCH_EVENTS)
422     Evas_Coord_Point touchDownPoint;
423     bool exceedTouchMoveThreshold;
424     bool wasHandledTouchStart;
425     bool wasHandledTouchMove;
426 #endif
427     bool holdHorizontalPanning;
428     bool holdVerticalPanning;
429 #endif // #if ENABLE(TIZEN_GESTURE)
430
431 #if ENABLE(TIZEN_WEBKIT2_TILED_SCROLLBAR)
432     bool mainFrameScrollbarVisibility;
433 #endif
434
435 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
436     Ecore_Animator* compositionAnimator;
437 #endif
438
439 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
440     WKEinaSharedString selectedText;
441 #endif
442
443 #if ENABLE(TIZEN_DATALIST_ELEMENT)
444     Eina_List* dataList;
445 #endif
446
447 #if ENABLE(TIZEN_SCREEN_ORIENTATION_SUPPORT_INTERNAL)
448     struct {
449         Ewk_Orientation_Lock_Cb callback;
450         void* data;
451     } orientationLock;
452 #endif
453
454 #if ENABLE(TIZEN_WEBKIT2_CREATE_VIEW_WITH_CREATED_PAGE_GROUP_WITH_IDENTIFIER)
455     RefPtr<WebKit::WebPageGroup> pageGroup;
456 #endif
457
458 #if ENABLE(TIZEN_APPLICATION_CACHE)
459     OwnPtr<Ewk_View_Callback_Context> applicationCachePermissionContext;
460     Ewk_Security_Origin* applicationCachePermissionOrigin;
461     bool isWaitingForApplicationCachePermission;
462 #endif
463 #if ENABLE(TIZEN_INDEXED_DATABASE)
464     OwnPtr<Ewk_View_Callback_Context> exceededIndexedDatabaseQuotaContext;
465 #endif
466 #if ENABLE(TIZEN_SQL_DATABASE)
467     OwnPtr<Ewk_View_Callback_Context> exceededDatabaseQuotaContext;
468 #endif
469     Ewk_Security_Origin* exceededQuotaOrigin;
470     bool isWaitingForExceededQuotaPopupReply;
471 #endif // #if OS(TIZEN)
472
473 private:
474     inline Ewk_View_Smart_Data* smartData() const;
475     void displayTimerFired(WebCore::Timer<EwkViewImpl>*);
476
477     static void onMouseDown(void* data, Evas*, Evas_Object*, void* eventInfo);
478     static void onMouseUp(void* data, Evas*, Evas_Object*, void* eventInfo);
479     static void onMouseMove(void* data, Evas*, Evas_Object*, void* eventInfo);
480 #if ENABLE(TOUCH_EVENTS)
481     void feedTouchEvents(Ewk_Touch_Event_Type type);
482     static void onTouchDown(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
483     static void onTouchUp(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
484     static void onTouchMove(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */);
485 #endif
486
487     Evas_Object* m_view;
488     OwnPtr<Ewk_Settings> m_settings;
489     RefPtr<Evas_Object> m_cursorObject;
490     WKEinaSharedString m_cursorGroup;
491     WKEinaSharedString m_faviconURL;
492     WKEinaSharedString m_url;
493     mutable WKEinaSharedString m_title;
494     WKEinaSharedString m_theme;
495     mutable WKEinaSharedString m_customEncoding;
496     bool m_mouseEventsEnabled;
497 #if ENABLE(TOUCH_EVENTS)
498     bool m_touchEventsEnabled;
499 #endif
500     WKRetainPtr<WKColorPickerResultListenerRef> m_colorPickerResultListener;
501     WebCore::Timer<EwkViewImpl> m_displayTimer;
502     WTF::Vector <WebCore::IntRect> m_dirtyRects;
503     OwnPtr<WebKit::InputMethodContextEfl> m_inputMethodContext;
504
505     typedef HashMap<WKPageRef, const Evas_Object*> PageViewMap;
506     static PageViewMap pageViewMap;
507
508 #if OS(TIZEN)
509 #if USE(TILED_BACKING_STORE)
510     float m_scaleFactor;
511     WebCore::IntPoint m_scrollPosition;
512 #endif
513 #endif
514 };
515
516 #endif // EwkViewImpl_h