Tizen 2.1 base
[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 "WKFrame.h"
25 #include "WKPageTizen.h"
26 #include "WKString.h"
27 #include "ewk_view_private.h"
28 #include "ewk_user_media_permission.h"
29 #include "ewk_view.h"
30 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
31 #include "ewk_certificate.h"
32 #endif
33
34 static void decidePolicyForUserMediaPermissionRequest(WKPageRef page, WKUserMediaPermissionRequestRef permissionRequest, const void *clientInfo)
35 {
36 #if ENABLE(TIZEN_MEDIA_STREAM)
37     Evas_Object* ewkView = static_cast<Evas_Object*>(const_cast<void*>(clientInfo));
38     Ewk_User_Media_Permission* userMediaPermission = ewkUserMediaPermissionCreate(permissionRequest);
39     ewkViewRequestUserMediaPermission(ewkView, userMediaPermission);
40 #endif
41 }
42
43 static void processJSBridgePlugin(WKPageRef page, WKStringRef request, WKStringRef message, const void* clientInfo)
44 {
45 #if ENABLE(TIZEN_JSBRIDGE_PLUGIN)
46     ewkViewProcessJSBridgePlugin(static_cast<Evas_Object*>(const_cast<void*>(clientInfo)), request, message);
47 #endif
48 }
49
50 static bool decidePolicyForCertificateError(WKPageRef page, WKStringRef url, WKStringRef certificate, int error, const void* clientInfo)
51 {
52 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
53     Evas_Object* ewkView = static_cast<Evas_Object*>(const_cast<void*>(clientInfo));
54
55     Ewk_Certificate_Policy_Decision* certificatePolicyDecision = ewkCertificatePolicyDecisionCreate(page, url, certificate, error);
56     ewkViewRequestCertificateConfirm(ewkView, certificatePolicyDecision);
57
58     if (!ewkCertificatePolicyDecisionDecided(certificatePolicyDecision) && !ewkCertificatePolicyDecisionSuspended(certificatePolicyDecision))
59         ewk_certificate_policy_decision_allowed_set(certificatePolicyDecision, true);
60
61     return true;
62 #else
63     return false;
64 #endif
65 }
66
67 static bool allowFileSystem(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef origin, const void* clientInfo)
68 {
69 #if ENABLE(TIZEN_FILE_SYSTEM)
70     return ewkViewAllowFileSystem(static_cast<Evas_Object*>(const_cast<void*>(clientInfo)), origin);
71 #else
72     return false;
73 #endif
74 }
75
76 void ewkViewTizenClientAttachClient(Evas_Object* ewkView)
77 {
78     EINA_SAFETY_ON_NULL_RETURN(ewkView);
79
80     WKPageTizenClient tizenClient = {
81         kWKPageTizenClientCurrentVersion,
82         ewkView, // clientInfo
83         0,
84         decidePolicyForUserMediaPermissionRequest,
85         processJSBridgePlugin,
86         decidePolicyForCertificateError,
87         allowFileSystem
88     };
89
90     WKPageSetPageTizenClient(toAPI(ewk_view_page_get(ewkView)), &tizenClient);
91 }
92
93 #endif // #if OS(TIZEN)