Create string tightly when retrive string from cbhm callback event
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_view_tizen_client.cpp
1 /*
2    Copyright (C) 2012 Samsung Electronics
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "ewk_view_tizen_client.h"
22
23 #if OS(TIZEN)
24 #include "EwkViewImpl.h"
25 #include "WKFrame.h"
26 #include "WKPageTizen.h"
27 #include "WKString.h"
28 #include "ewk_user_media_private.h"
29 #include "ewk_view.h"
30 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
31 #include "ewk_certificate.h"
32 #endif
33
34 static bool decidePolicyForApplicationCachePermissionRequest(WKPageRef page, WKSecurityOriginRef origin, WKFrameRef frame, const void *clientInfo)
35 {
36 #if ENABLE(TIZEN_APPLICATION_CACHE)
37     return ewkViewRequestApplicationCachePermission(static_cast<Evas_Object*>(const_cast<void*>(clientInfo)), origin);
38 #else
39     return false;
40 #endif
41 }
42
43 static void decidePolicyForUserMediaPermissionRequest(WKPageRef page, WKUserMediaPermissionRequestRef permissionRequest, const void *clientInfo)
44 {
45 #if ENABLE(TIZEN_MEDIA_STREAM)
46 #if ENABLE(TIZEN_DLOG_SUPPORT)
47     TIZEN_LOGI("");
48 #endif
49
50     Evas_Object* ewkView = static_cast<Evas_Object*>(const_cast<void*>(clientInfo));
51     Ewk_User_Media_Permission_Request* userMediaPermissionRequest = ewkUserMediaPermissionRequestCreate(ewkView, permissionRequest);
52     ewkViewRequestUserMediaPermission(ewkView, userMediaPermissionRequest);
53 #endif
54 }
55
56 static void processJSBridgePlugin(WKPageRef page, WKStringRef request, WKStringRef message, const void* clientInfo)
57 {
58 #if ENABLE(TIZEN_JSBRIDGE_PLUGIN)
59     ewkViewProcessJSBridgePlugin(static_cast<Evas_Object*>(const_cast<void*>(clientInfo)), request, message);
60 #endif
61 }
62
63 static bool decidePolicyForCertificateError(WKPageRef page, WKStringRef url, WKStringRef certificate, int error, const void* clientInfo)
64 {
65 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
66     Evas_Object* ewkView = static_cast<Evas_Object*>(const_cast<void*>(clientInfo));
67
68     Ewk_Certificate_Policy_Decision* certificatePolicyDecision = ewkCertificatePolicyDecisionCreate(page, url, certificate, error);
69     ewkViewRequestCertificateConfirm(ewkView, certificatePolicyDecision);
70
71     if (!ewkCertificatePolicyDecisionDecided(certificatePolicyDecision) && !ewkCertificatePolicyDecisionSuspended(certificatePolicyDecision))
72         ewk_certificate_policy_decision_allowed_set(certificatePolicyDecision, true);
73
74     return true;
75 #else
76     return false;
77 #endif
78 }
79
80 static bool exceededIndexedDatabaseQuota(WKPageRef page, WKSecurityOriginRef origin, long long currentUsage, WKFrameRef frame, const void *clientInfo)
81 {
82 #if ENABLE(TIZEN_INDEXED_DATABASE)
83     return ewkViewExceededIndexedDatabaseQuota(static_cast<Evas_Object*>(const_cast<void*>(clientInfo)), origin, currentUsage);
84 #else
85     return false;
86 #endif
87 }
88
89 static bool exceededLocalFileSystemQuota(WKPageRef page, WKSecurityOriginRef origin, long long currentUsage, WKFrameRef frame, const void *clientInfo)
90 {
91 #if ENABLE(TIZEN_FILE_SYSTEM)
92     return ewkViewExceededLocalFileSystemQuota(static_cast<Evas_Object*>(const_cast<void*>(clientInfo)), origin, currentUsage);
93 #else
94     return false;
95 #endif
96 }
97
98 void ewkViewTizenClientAttachClient(Evas_Object* ewkView)
99 {
100     EINA_SAFETY_ON_NULL_RETURN(ewkView);
101
102     WKPageTizenClient tizenClient = {
103         kWKPageTizenClientCurrentVersion,
104         ewkView, // clientInfo
105         0,
106         decidePolicyForApplicationCachePermissionRequest,
107         decidePolicyForUserMediaPermissionRequest,
108         processJSBridgePlugin,
109         decidePolicyForCertificateError,
110         exceededIndexedDatabaseQuota,
111         exceededLocalFileSystemQuota
112     };
113
114     WKPageSetPageTizenClient(toAPI(EwkViewImpl::fromEvasObject(ewkView)->page()), &tizenClient);
115 }
116
117 #endif // #if OS(TIZEN)