Merge "Change value of mediaSliderThumHeight" into tizen_2.1
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_context.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 program 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 program; 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
21 #include "config.h"
22 #include "ewk_context.h"
23
24 #include "BatteryProvider.h"
25 #include "NetworkInfoProvider.h"
26 #include "VibrationProvider.h"
27 #include "WKAPICast.h"
28 #include "WKContextSoup.h"
29 #include "WKRetainPtr.h"
30 #include "WKString.h"
31 #include "ewk_context_download_client_private.h"
32 #include "ewk_context_private.h"
33 #include "ewk_context_request_manager_client_private.h"
34 #include "ewk_cookie_manager_private.h"
35 #include "ewk_download_job.h"
36 #include "ewk_download_job_private.h"
37 #include <wtf/HashMap.h>
38 #include <wtf/text/WTFString.h>
39
40 #if OS(TIZEN)
41 #include "WKApplicationCacheManager.h"
42 #include "WKArray.h"
43 #include "WKContext.h"
44 #include "WKContextPrivate.h"
45 #include "WKContextTizen.h"
46 #include "WKDatabaseManager.h"
47 #include "WKIconDatabase.h"
48 #include "WKIconDatabaseTizen.h"
49 #include "WKKeyValueStorageManager.h"
50 #if ENABLE(TIZEN_FILE_SYSTEM)
51 #include "WKLocalFileSystemManager.h"
52 #endif
53 #include "WKNumber.h"
54 #include "WKSecurityOrigin.h"
55 #include "WKString.h"
56 #include "WKURL.h"
57 #include "WebContext.h"
58 #include "ewk_context_injected_bundle_client.h"
59 #include "ewk_security_origin.h"
60 #include <Eina.h>
61 #include <WebCore/FileSystem.h>
62 #include <wtf/text/WTFString.h>
63
64 #if ENABLE(TIZEN_WRT_LAUNCHING_PERFORMANCE)
65 #include "ProcessLauncher.h"
66 #include <stdlib.h>
67 #endif
68
69 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
70 #include "FormDatabase.h"
71 #include "WKDictionary.h"
72 #endif
73 #endif // #if OS(TIZEN)
74 #if ENABLE(SPELLCHECK)
75 #include "ewk_settings.h"
76 #include "ewk_text_checker_private.h"
77 #endif
78
79 using namespace WebKit;
80
81 struct _Ewk_Url_Scheme_Handler {
82     Ewk_Url_Scheme_Request_Cb callback;
83     void* userData;
84
85     _Ewk_Url_Scheme_Handler()
86         : callback(0)
87         , userData(0)
88     { }
89
90     _Ewk_Url_Scheme_Handler(Ewk_Url_Scheme_Request_Cb callback, void* userData)
91         : callback(callback)
92         , userData(userData)
93     { }
94 };
95
96 typedef HashMap<String, _Ewk_Url_Scheme_Handler> URLSchemeHandlerMap;
97
98 struct _Ewk_Context {
99     WKRetainPtr<WKContextRef> context;
100
101     Ewk_Cookie_Manager* cookieManager;
102 #if ENABLE(BATTERY_STATUS)
103     RefPtr<BatteryProvider> batteryProvider;
104 #endif
105 #if ENABLE(NETWORK_INFO)
106     RefPtr<NetworkInfoProvider> networkInfoProvider;
107 #endif
108 #if ENABLE(VIBRATION)
109     RefPtr<VibrationProvider> vibrationProvider;
110 #endif
111     HashMap<uint64_t, Ewk_Download_Job*> downloadJobs;
112
113     WKRetainPtr<WKSoupRequestManagerRef> requestManager;
114     URLSchemeHandlerMap urlSchemeHandlers;
115
116 #if OS(TIZEN)
117     const char* proxyAddress;
118 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
119     const char* certificateFile;
120 #endif
121 #if ENABLE(TIZEN_SQL_DATABASE)
122     uint64_t defaultDatabaseQuota;
123 #endif
124     struct {
125         Ewk_Context_Message_From_Injected_Bundle_Callback callback;
126         void* userData;
127     } messageFromInjectedBundle;
128     struct {
129         Ewk_Context_Did_Start_Download_Callback callback;
130         void* userData;
131     } didStartDownload;
132 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
133     Ecore_X_Window xWindow;
134 #endif
135 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
136     RefPtr<FormDatabase> formDatabase;
137 #endif
138 #endif
139
140     _Ewk_Context(WKRetainPtr<WKContextRef> contextRef)
141         : context(contextRef)
142         , cookieManager(0)
143         , requestManager(WKContextGetSoupRequestManager(contextRef.get()))
144     {
145 #if ENABLE(BATTERY_STATUS)
146         batteryProvider = BatteryProvider::create(context.get());
147 #endif
148
149 #if ENABLE(NETWORK_INFO)
150         networkInfoProvider = NetworkInfoProvider::create(context.get());
151 #endif
152
153 #if ENABLE(VIBRATION)
154         vibrationProvider = VibrationProvider::create(context.get());
155 #endif
156
157         ewk_context_request_manager_client_attach(this);
158         ewk_context_download_client_attach(this);
159 #if ENABLE(SPELLCHECK)
160         Ewk_Text_Checker::initialize();
161         if (ewk_settings_continuous_spell_checking_enabled_get()) {
162             // Load the default language.
163             ewk_settings_spell_checking_languages_set(0);
164         }
165 #endif
166
167 #if OS(TIZEN)
168         this->proxyAddress = 0;
169 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
170         this->certificateFile = 0;
171 #endif
172 #if ENABLE(TIZEN_SQL_DATABASE)
173         this->defaultDatabaseQuota = 5 * 1024 * 1024;
174 #endif
175         this->messageFromInjectedBundle.callback = 0;
176         this->messageFromInjectedBundle.userData = 0;
177         this->didStartDownload.callback = 0;
178         this->didStartDownload.userData = 0;
179 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
180         this->formDatabase = FormDatabase::create();
181         this->formDatabase->open(FormDatabase::defaultDatabaseDirectoryPath(), FormDatabase::defaultDatabaseFilename());
182 #endif
183 #endif
184     }
185
186     ~_Ewk_Context()
187     {
188         if (cookieManager)
189             ewk_cookie_manager_free(cookieManager);
190
191 #if ENABLE(TIZEN_CACHE_DUMP_SYNC)
192         ewk_context_cache_dump(this);
193 #endif
194
195         HashMap<uint64_t, Ewk_Download_Job*>::iterator it = downloadJobs.begin();
196         HashMap<uint64_t, Ewk_Download_Job*>::iterator end = downloadJobs.end();
197         for ( ; it != end; ++it)
198             ewk_download_job_unref(it->second);
199     }
200 };
201
202 Ewk_Cookie_Manager* ewk_context_cookie_manager_get(const Ewk_Context* ewkContext)
203 {
204     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
205
206     if (!ewkContext->cookieManager)
207         const_cast<Ewk_Context*>(ewkContext)->cookieManager = ewk_cookie_manager_new(WKContextGetCookieManager(ewkContext->context.get()));
208
209     return ewkContext->cookieManager;
210 }
211
212 WKContextRef ewk_context_WKContext_get(const Ewk_Context* ewkContext)
213 {
214     return ewkContext->context.get();
215 }
216
217 /**
218  * @internal
219  * Registers that a new download has been requested.
220  */
221 void ewk_context_download_job_add(Ewk_Context* ewkContext, Ewk_Download_Job* ewkDownload)
222 {
223     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
224     EINA_SAFETY_ON_NULL_RETURN(ewkDownload);
225
226     uint64_t downloadId = ewk_download_job_id_get(ewkDownload);
227     if (ewkContext->downloadJobs.contains(downloadId))
228         return;
229
230     ewk_download_job_ref(ewkDownload);
231     ewkContext->downloadJobs.add(downloadId, ewkDownload);
232 }
233
234 /**
235  * @internal
236  * Returns the #Ewk_Download_Job with the given @a downloadId, or
237  * @c 0 in case of failure.
238  */
239 Ewk_Download_Job* ewk_context_download_job_get(const Ewk_Context* ewkContext, uint64_t downloadId)
240 {
241     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
242
243     return ewkContext->downloadJobs.get(downloadId);
244 }
245
246 /**
247  * @internal
248  * Removes the #Ewk_Download_Job with the given @a downloadId from the internal
249  * HashMap.
250  */
251 void ewk_context_download_job_remove(Ewk_Context* ewkContext, uint64_t downloadId)
252 {
253     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
254     Ewk_Download_Job* download = ewkContext->downloadJobs.take(downloadId);
255     if (download)
256         ewk_download_job_unref(download);
257 }
258
259 /**
260  * Retrieve the request manager for @a ewkContext.
261  *
262  * @param ewkContext a #Ewk_Context object.
263  */
264 WKSoupRequestManagerRef ewk_context_request_manager_get(const Ewk_Context* ewkContext)
265 {
266     return ewkContext->requestManager.get();
267 }
268
269 /**
270  * @internal
271  * A new URL request was received.
272  *
273  * @param ewkContext a #Ewk_Context object.
274  * @param schemeRequest a #Ewk_Url_Scheme_Request object.
275  */
276 void ewk_context_url_scheme_request_received(Ewk_Context* ewkContext, Ewk_Url_Scheme_Request* schemeRequest)
277 {
278     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
279     EINA_SAFETY_ON_NULL_RETURN(schemeRequest);
280
281     _Ewk_Url_Scheme_Handler handler = ewkContext->urlSchemeHandlers.get(ewk_url_scheme_request_scheme_get(schemeRequest));
282     if (!handler.callback)
283         return;
284
285     handler.callback(schemeRequest, handler.userData);
286 }
287
288 static inline Ewk_Context* createDefaultEwkContext()
289 {
290     return new Ewk_Context(WKContextGetSharedProcessContext());
291 }
292
293 Ewk_Context* ewk_context_default_get()
294 {
295 #if OS(TIZEN)
296     static Ewk_Context* defaultContext = ewk_context_new();
297     return defaultContext;
298 #else // #if OS(TIZEN)
299     DEFINE_STATIC_LOCAL(Ewk_Context, defaultContext, (WKContextGetSharedProcessContext()));
300     return &defaultContext;
301 #endif // #if OS(TIZEN)
302 }
303
304 #if OS(TIZEN)
305 typedef struct _Ewk_Context_Callback_Context
306 {
307     union {
308 #if ENABLE(TIZEN_FILE_SYSTEM)
309         Ewk_Local_File_System_Origins_Get_Callback localFileSystemOriginsCallback;
310 #endif
311         Ewk_Web_Application_Cache_Origins_Get_Callback webApplicationCacheOriginsCallback;
312         Ewk_Web_Application_Cache_Quota_Get_Callback webApplicationCacheQuotaCallback;
313         Ewk_Web_Application_Cache_Usage_For_Origin_Get_Callback webApplicationCacheUsageForOriginCallback;
314         Ewk_Web_Application_Cache_Path_Get_Callback webApplicationCachePathCallback;
315         Ewk_Web_Database_Origins_Get_Callback webDatabaseOriginsCallback;
316         Ewk_Web_Database_Quota_Get_Callback webDatabaseQuotaCallback;
317         Ewk_Web_Database_Usage_Get_Callback webDatabaseUsageCallback;
318         Ewk_Web_Database_Path_Get_Callback webDatabasePathCallback;
319         Ewk_Web_Storage_Origins_Get_Callback webStorageOriginsCallback;
320         Ewk_Web_Storage_Usage_Get_Callback webStorageUsageCallback;
321         Ewk_Web_Storage_Path_Get_Callback webStoragePathCallback;
322     };
323     void* userData;
324 } Ewk_Context_Callback_Context;
325
326 #if ENABLE(TIZEN_SQL_DATABASE)
327 struct _Ewk_Context_Exceeded_Quota
328 {
329     Ewk_Security_Origin* origin;
330     const char* databaseName;
331     const char* displayName;
332     unsigned long long currentQuota;
333     unsigned long long currentOriginUsage;
334     unsigned long long currentDatabaseUsage;
335     unsigned long long expectedUsage;
336     unsigned long long newQuota;
337 };
338 #endif
339
340 /**
341  * @internal
342  * Create Ewk_Context with WKContext.
343  */
344 Ewk_Context* ewk_context_new_from_WKContext(WKContextRef contextRef)
345 {
346     EINA_SAFETY_ON_NULL_RETURN_VAL(contextRef, 0);
347
348     return new Ewk_Context(contextRef);
349 }
350
351 #if ENABLE(TIZEN_SQL_DATABASE)
352 Ewk_Context_Exceeded_Quota* ewkContextCreateExceededQuota(WKSecurityOriginRef origin, WKStringRef databaseName, WKStringRef displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage)
353 {
354     Ewk_Context_Exceeded_Quota* exceededQuota = new Ewk_Context_Exceeded_Quota();
355
356     int length = WKStringGetMaximumUTF8CStringSize(databaseName);
357     OwnArrayPtr<char> databaseNameBuffer = adoptArrayPtr(new char[length]);
358     WKStringGetUTF8CString(databaseName, databaseNameBuffer.get(), length);
359
360     length = WKStringGetMaximumUTF8CStringSize(displayName);
361     OwnArrayPtr<char> displayNameBuffer = adoptArrayPtr(new char[length]);
362     WKStringGetUTF8CString(displayName, displayNameBuffer.get(), length);
363
364     exceededQuota->origin = createSecurityOrigin(origin);
365     exceededQuota->databaseName = eina_stringshare_add(databaseNameBuffer.get());
366     exceededQuota->displayName = eina_stringshare_add(displayNameBuffer.get());
367     exceededQuota->currentQuota = currentQuota;
368     exceededQuota->currentOriginUsage = currentOriginUsage;
369     exceededQuota->currentDatabaseUsage = currentDatabaseUsage;
370     exceededQuota->expectedUsage = expectedUsage;
371
372     return exceededQuota;
373 }
374
375 void ewkContextDeleteExceededQuota(Ewk_Context_Exceeded_Quota* exceededQuota)
376 {
377     deleteSecurityOrigin(exceededQuota->origin);
378     eina_stringshare_del(exceededQuota->databaseName);
379     eina_stringshare_del(exceededQuota->displayName);
380     delete exceededQuota;
381 }
382
383 unsigned long long ewkContextGetNewQuotaForExceededQuota(Ewk_Context* ewkContext, Ewk_Context_Exceeded_Quota* exceededQuota)
384 {
385     if (exceededQuota->newQuota)
386         return exceededQuota->newQuota + exceededQuota->currentQuota;
387
388     if (exceededQuota->currentQuota)
389         return exceededQuota->currentQuota;
390
391     return ewkContext->defaultDatabaseQuota;
392 }
393
394 uint64_t ewkContextGetDatabaseQuota(Ewk_Context* ewkContext)
395 {
396     return ewkContext->defaultDatabaseQuota;
397 }
398 #endif
399
400 /* public */
401 Ewk_Context* ewk_context_new()
402 {
403     Ewk_Context* ewk_context = new Ewk_Context(adoptWK(WKContextCreate()));
404
405     ewkContextInjectedBundleClientAttachClient(ewk_context);
406
407     return ewk_context;
408 }
409
410 Ewk_Context* ewk_context_new_with_injected_bundle_path(const char* path)
411 {
412     EINA_SAFETY_ON_NULL_RETURN_VAL(path, 0);
413
414 #if ENABLE(TIZEN_WRT_LAUNCHING_PERFORMANCE)
415     char* wrtLaunchingPerformance = getenv("WRT_LAUNCHING_PERFORMANCE");
416     if (wrtLaunchingPerformance && !strcmp(wrtLaunchingPerformance, "1")) {
417         static bool firstTime = true;
418         if (firstTime) {
419             firstTime = false;
420
421             if (ProcessLauncher::isInitialFork())
422                 ProcessLauncher::setSkipExec(true);
423             else
424                 ProcessLauncher::setSkipExec(false);
425
426             ProcessLauncher::forkProcess();
427
428             if (ProcessLauncher::isParentProcess()) {
429                 Ewk_Context* ewkContext = ewk_context_new_with_injected_bundle_path(path);
430                 WKContextRef contextRef = ewk_context_WKContext_get(ewkContext);
431                 toImpl(contextRef)->ensureWebProcess();
432                 return ewkContext;
433             }
434             else if (ProcessLauncher::isChildProcess()) {
435                 ProcessLauncher::callWebProcessMain();
436                 exit(0);
437             }
438
439             ASSERT_NOT_REACHED();
440             return 0;
441         }
442     }
443 #endif
444
445     WKRetainPtr<WKStringRef> pathRef(AdoptWK, WKStringCreateWithUTF8CString(path));
446     Ewk_Context* ewk_context = new Ewk_Context(adoptWK(WKContextCreateWithInjectedBundlePath(pathRef.get())));
447
448     ewkContextInjectedBundleClientAttachClient(ewk_context);
449
450     return ewk_context;
451 }
452
453 void ewk_context_delete(Ewk_Context* ewkContext)
454 {
455     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
456     if (ewkContext == ewk_context_default_get())
457         return;
458
459     eina_stringshare_del(ewkContext->proxyAddress);
460 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
461     eina_stringshare_del(ewkContext->certificateFile);
462 #endif
463     delete ewkContext;
464 }
465
466 void ewk_context_proxy_uri_set(Ewk_Context* ewkContext, const char* proxy)
467 {
468     if (ewkContext && eina_stringshare_replace(&ewkContext->proxyAddress, proxy)) {
469         WKRetainPtr<WKURLRef> proxyAddress(AdoptWK, WKURLCreateWithUTF8CString(proxy));
470
471         WKContextRef contextRef = ewk_context_WKContext_get(ewkContext);
472         toImpl(contextRef)->setProxy(toWTFString(proxyAddress.get()));
473     }
474 }
475
476 const char* ewk_context_proxy_uri_get(Ewk_Context* ewkContext)
477 {
478 #if ENABLE(TIZEN_WEBKIT2_PATCH_FOR_TC)
479     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
480 #endif
481     return ewkContext->proxyAddress;
482 }
483
484 void ewk_context_network_session_requests_cancel(Ewk_Context* ewkContext)
485 {
486     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
487
488     WKContextRef contextRef = ewk_context_WKContext_get(ewkContext);
489     toImpl(contextRef)->abortSession();
490 }
491
492 Eina_Bool ewk_context_notify_low_memory(Ewk_Context* ewkContext)
493 {
494     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
495
496     WKContextRef contextRef = ewk_context_WKContext_get(ewkContext);
497     toImpl(contextRef)->notifyLowMemory();
498     return true;
499 }
500
501 #if ENABLE(TIZEN_FILE_SYSTEM)
502 static void didGetLocalFileSystemOrigins(WKArrayRef origins, WKErrorRef error, void* context)
503 {
504     Eina_List* originList = 0;
505     for (size_t i = 0; i < WKArrayGetSize(origins); ++i) {
506         WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
507         Ewk_Security_Origin* origin = createSecurityOrigin(securityOriginRef);
508         originList = eina_list_append(originList, origin);
509     }
510
511     Ewk_Context_Callback_Context* locaFileSystemContext = static_cast<Ewk_Context_Callback_Context*>(context);
512     locaFileSystemContext->localFileSystemOriginsCallback(originList, locaFileSystemContext->userData);
513     delete locaFileSystemContext;
514 }
515 #endif
516
517 #if ENABLE(TIZEN_APPLICATION_CACHE)
518 static void didGetWebApplicationOrigins(WKArrayRef origins, WKErrorRef error, void* context)
519 {
520     TIZEN_LOGI("origin size(%d)", WKArrayGetSize(origins));
521     Eina_List* originList = 0;
522
523     for(size_t i = 0; i < WKArrayGetSize(origins); i++) {
524         WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
525         Ewk_Security_Origin* origin = createSecurityOrigin(securityOriginRef);
526         originList = eina_list_append(originList, origin);
527     }
528
529     Ewk_Context_Callback_Context* applicationCacheContext = static_cast<Ewk_Context_Callback_Context*>(context);
530     applicationCacheContext->webApplicationCacheOriginsCallback(originList, applicationCacheContext->userData);
531     delete applicationCacheContext;
532 }
533
534 static void didGetWebApplicationPath(WKStringRef path, WKErrorRef error, void* context)
535 {
536     Ewk_Context_Callback_Context* applicationCacheContext = static_cast<Ewk_Context_Callback_Context*>(context);
537
538     int length = WKStringGetMaximumUTF8CStringSize(path);
539     OwnArrayPtr<char> applicationCachePath = adoptArrayPtr(new char[length]);
540     WKStringGetUTF8CString(path, applicationCachePath.get(), length);
541
542     TIZEN_LOGI("path (%s)", applicationCachePath.get());
543     applicationCacheContext->webApplicationCachePathCallback(eina_stringshare_add(applicationCachePath.get()), applicationCacheContext->userData);
544     delete applicationCacheContext;
545 }
546
547 #if ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
548 static void didGetWebApplicationQuota(WKInt64Ref quota, WKErrorRef error, void* context)
549 {
550     Ewk_Context_Callback_Context* applicationCacheContext = static_cast<Ewk_Context_Callback_Context*>(context);
551     TIZEN_LOGI("quota (%d)", toImpl(quota)->value());
552     applicationCacheContext->webApplicationCacheQuotaCallback(toImpl(quota)->value(), applicationCacheContext->userData);
553     delete applicationCacheContext;
554 }
555
556 static void didGetWebApplicationUsageForOrigin(WKInt64Ref usage, WKErrorRef error, void* context)
557 {
558     Ewk_Context_Callback_Context* applicationCacheContext = static_cast<Ewk_Context_Callback_Context*>(context);
559     TIZEN_LOGI("usage (%d)", toImpl(usage)->value());
560     applicationCacheContext->webApplicationCacheUsageForOriginCallback(toImpl(usage)->value(), applicationCacheContext->userData);
561     delete applicationCacheContext;
562 }
563 #endif
564 #endif
565
566 #if ENABLE(TIZEN_SQL_DATABASE)
567 static void didGetWebDatabaseOrigins(WKArrayRef origins, WKErrorRef error, void* context)
568 {
569     TIZEN_LOGI("origin size(%d)", WKArrayGetSize(origins));
570     Eina_List* originList = 0;
571
572     for(size_t i = 0; i < WKArrayGetSize(origins); i++) {
573         WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
574         Ewk_Security_Origin* origin = createSecurityOrigin(securityOriginRef);
575         originList = eina_list_append(originList, origin);
576     }
577
578     Ewk_Context_Callback_Context* webDatabaseContext = static_cast<Ewk_Context_Callback_Context*>(context);
579     webDatabaseContext->webDatabaseOriginsCallback(originList, webDatabaseContext->userData);
580     delete webDatabaseContext;
581 }
582
583 static void didGetWebDatabaseQuota(WKUInt64Ref quota, WKErrorRef error, void* context)
584 {
585     Ewk_Context_Callback_Context* webDatabaseContext = static_cast<Ewk_Context_Callback_Context*>(context);
586     TIZEN_LOGI("quota (%d)", toImpl(quota)->value());
587     webDatabaseContext->webDatabaseQuotaCallback(toImpl(quota)->value(), webDatabaseContext->userData);
588     delete webDatabaseContext;
589 }
590
591 static void didGetWebDatabaseUsage(WKUInt64Ref usage, WKErrorRef error, void* context)
592 {
593     Ewk_Context_Callback_Context* webDatabaseContext = static_cast<Ewk_Context_Callback_Context*>(context);
594     TIZEN_LOGI("usage (%d)", toImpl(usage)->value());
595     webDatabaseContext->webDatabaseUsageCallback(toImpl(usage)->value(), webDatabaseContext->userData);
596     delete webDatabaseContext;
597 }
598
599 static void didGetWebDatabasePath(WKStringRef path, WKErrorRef error, void * context)
600 {
601     Ewk_Context_Callback_Context* webDatabaseContext = static_cast<Ewk_Context_Callback_Context*>(context);
602
603     int length = WKStringGetMaximumUTF8CStringSize(path);
604     OwnArrayPtr<char> databasePath = adoptArrayPtr(new char[length]);
605     WKStringGetUTF8CString(path, databasePath.get(), length);
606
607     TIZEN_LOGI("path (%s)", databasePath.get());
608     webDatabaseContext->webDatabasePathCallback(eina_stringshare_add(databasePath.get()), webDatabaseContext->userData);
609     delete webDatabaseContext;
610 }
611 #endif
612
613 #if ENABLE(TIZEN_WEB_STORAGE)
614 static void didGetWebStorageOrigins(WKArrayRef origins, WKErrorRef error, void* context)
615 {
616     TIZEN_LOGI("origin size(%d)", WKArrayGetSize(origins));
617     Eina_List* originList = 0;
618
619     for(size_t i = 0; i < WKArrayGetSize(origins); i++) {
620         WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
621         Ewk_Security_Origin* origin = createSecurityOrigin(securityOriginRef);
622         originList = eina_list_append(originList, origin);
623     }
624
625     Ewk_Context_Callback_Context* webStorageContext = static_cast<Ewk_Context_Callback_Context*>(context);
626     webStorageContext->webStorageOriginsCallback(originList, webStorageContext->userData);
627     delete webStorageContext;
628 }
629
630 static void didGetWebStoragePath(WKStringRef path, WKErrorRef error, void * context)
631 {
632     Ewk_Context_Callback_Context* webStorageContext = static_cast<Ewk_Context_Callback_Context*>(context);
633
634     int length = WKStringGetMaximumUTF8CStringSize(path);
635     OwnArrayPtr<char> storagePath = adoptArrayPtr(new char[length]);
636     WKStringGetUTF8CString(path, storagePath.get(), length);
637
638     TIZEN_LOGI("path (%s)", storagePath.get());
639     webStorageContext->webStoragePathCallback(eina_stringshare_add(storagePath.get()), webStorageContext->userData);
640     delete webStorageContext;
641 }
642
643 #if ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
644 static void didGetWebStorageUsage(WKInt64Ref usage, WKErrorRef error, void* context)
645 {
646     Ewk_Context_Callback_Context* webStorageContext = static_cast<Ewk_Context_Callback_Context*>(context);
647
648     TIZEN_LOGI("usage (%s)", toImpl(usage)->value());
649     webStorageContext->webStorageUsageCallback(toImpl(usage)->value(), webStorageContext->userData);
650     delete webStorageContext;
651 }
652 #endif
653
654 #endif
655
656 Eina_Bool ewk_context_origins_free(Eina_List* originList)
657 {
658     EINA_SAFETY_ON_NULL_RETURN_VAL(originList, false);
659
660     void* currentOrigin;
661     EINA_LIST_FREE(originList, currentOrigin) {
662         Ewk_Security_Origin* origin = static_cast<Ewk_Security_Origin*>(currentOrigin);
663         deleteSecurityOrigin(origin);
664     }
665
666     return true;
667 }
668
669 Eina_Bool ewk_context_application_cache_delete_all(Ewk_Context* ewkContext)
670 {
671 #if ENABLE(TIZEN_APPLICATION_CACHE)
672     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
673
674     TIZEN_LOGI("ewkContext (%p)", ewkContext);
675     WKApplicationCacheManagerRef applicationCache = WKContextGetApplicationCacheManager(ewk_context_WKContext_get(ewkContext));
676     WKApplicationCacheManagerDeleteAllEntries(applicationCache);
677
678     return true;
679 #else
680     return false;
681 #endif
682 }
683
684 Eina_Bool ewk_context_application_cache_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
685 {
686 #if ENABLE(TIZEN_APPLICATION_CACHE)
687     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
688     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
689
690     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(origin));
691     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
692     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
693     WKRetainPtr<WKSecurityOriginRef> securityOriginRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
694     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewk_context_WKContext_get(ewkContext));
695     WKApplicationCacheManagerDeleteEntriesForOrigin(applicationCacheRef, securityOriginRef.get());
696
697     return true;
698 #else
699     return false;
700 #endif
701 }
702
703 Eina_Bool ewk_context_application_cache_origins_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Origins_Get_Callback callback, void *userData)
704 {
705 #if ENABLE(TIZEN_APPLICATION_CACHE)
706     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
707     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
708
709     TIZEN_LOGI("ewkContext (%p)", ewkContext);
710     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
711     context->webApplicationCacheOriginsCallback = callback;
712     context->userData = userData;
713
714     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewk_context_WKContext_get(ewkContext));
715     WKApplicationCacheManagerGetApplicationCacheOrigins(applicationCacheRef, context, didGetWebApplicationOrigins);
716
717     return true;
718 #else
719     return false;
720 #endif
721 }
722
723 Eina_Bool ewk_context_application_cache_path_set(Ewk_Context* ewkContext, const char* path)
724 {
725 #if ENABLE(TIZEN_APPLICATION_CACHE)
726     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
727     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
728
729     if (!path) {
730         TIZEN_LOGE("Path value is invalid");
731         return false;
732     }
733
734     TIZEN_LOGI("path (%s)", path);
735     WKRetainPtr<WKStringRef> applicationCachePathRef(AdoptWK, WKStringCreateWithUTF8CString(path));
736     WKContextSetApplicationCacheDirectory(ewk_context_WKContext_get(ewkContext), applicationCachePathRef.get());
737
738     return true;
739 #else
740     return false;
741 #endif
742 }
743
744 Eina_Bool ewk_context_application_cache_path_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Path_Get_Callback callback, void* userData)
745 {
746 #if ENABLE(TIZEN_APPLICATION_CACHE)
747     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
748     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
749
750     TIZEN_LOGI("callback (%p)", callback);
751     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
752     context->webApplicationCachePathCallback= callback;
753     context->userData = userData;
754
755     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewk_context_WKContext_get(ewkContext));
756     WKApplicationCacheManagerGetApplicationCachePath(applicationCacheRef, context, didGetWebApplicationPath);
757     return true;
758 #else
759     return false;
760 #endif
761 }
762
763 Eina_Bool ewk_context_application_cache_quota_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Quota_Get_Callback callback, void* userData)
764 {
765 #if ENABLE(TIZEN_APPLICATION_CACHE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
766     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
767     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
768
769     TIZEN_LOGI("callback (%p)", callback);
770     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
771     context->webApplicationCacheQuotaCallback = callback;
772     context->userData = userData;
773
774     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewk_context_WKContext_get(ewkContext));
775     WKApplicationCacheManagerGetApplicationCacheQuota(applicationCacheRef, context, didGetWebApplicationQuota);
776
777     return true;
778 #else
779     return false;
780 #endif
781 }
782
783 Eina_Bool ewk_context_application_cache_usage_for_origin_get(Ewk_Context* ewkContext, const Ewk_Security_Origin* origin, Ewk_Web_Application_Cache_Usage_For_Origin_Get_Callback callback, void* userData)
784 {
785 #if ENABLE(TIZEN_APPLICATION_CACHE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
786     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
787     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
788     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
789
790     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(origin));
791     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
792     context->webApplicationCacheUsageForOriginCallback = callback;
793     context->userData = userData;
794     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
795     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
796     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
797
798     WKApplicationCacheManagerRef applicationCache = WKContextGetApplicationCacheManager(ewk_context_WKContext_get(ewkContext));
799     WKApplicationCacheManagerGetApplicationCacheUsageForOrigin(applicationCache, context, originRef.get(), didGetWebApplicationUsageForOrigin);
800
801     return true;
802 #else
803     return false;
804 #endif
805 }
806
807 Eina_Bool ewk_context_application_cache_quota_set(Ewk_Context* ewkContext, int64_t quota)
808 {
809 #if ENABLE(TIZEN_APPLICATION_CACHE)
810     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
811     if (!quota) {
812         TIZEN_LOGE("Quota value is invalid");
813         return false;
814     }
815
816     TIZEN_LOGI("quota (%d)", quota);
817     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewk_context_WKContext_get(ewkContext));
818     WKApplicationCacheManagerSetApplicationCacheQuota(applicationCacheRef, quota);
819
820     return true;
821 #else
822     return false;
823 #endif
824 }
825
826 Eina_Bool ewk_context_application_cache_quota_for_origin_set(Ewk_Context* ewkContext, const Ewk_Security_Origin* origin, int64_t quota)
827 {
828 #if ENABLE(TIZEN_APPLICATION_CACHE)
829     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
830     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
831     if (!quota) {
832         TIZEN_LOGE("Quota value is invalid");
833         return false;
834     }
835
836     TIZEN_LOGI("quota (%d)", quota);
837     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
838     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
839     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
840
841     WKApplicationCacheManagerRef applicationCache = WKContextGetApplicationCacheManager(ewk_context_WKContext_get(ewkContext));
842     WKApplicationCacheManagerSetApplicationCacheQuotaForOrigin(applicationCache, originRef.get(), quota);
843
844     return true;
845 #else
846     return false;
847 #endif
848 }
849
850
851 Eina_Bool ewk_context_icon_database_path_set(Ewk_Context* ewkContext, const char* path)
852 {
853     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
854     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
855
856     WKRetainPtr<WKStringRef> databasePath(AdoptWK, WKStringCreateWithUTF8CString(path));
857     WKContextSetIconDatabasePath(ewk_context_WKContext_get(ewkContext), databasePath.get());
858
859     return true;
860 }
861
862 Evas_Object* ewk_context_icon_database_icon_object_add(Ewk_Context* ewkContext, const char* uri, Evas* canvas)
863 {
864     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
865     EINA_SAFETY_ON_NULL_RETURN_VAL(uri, 0);
866     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
867
868     WKIconDatabaseRef iconDatabase = WKContextGetIconDatabase(ewk_context_WKContext_get(ewkContext));
869     WKRetainPtr<WKURLRef> urlString(AdoptWK, WKURLCreateWithUTF8CString(uri));
870
871     return WKIconDatabaseTryGetImageForURL(iconDatabase, canvas, urlString.get());
872 }
873
874 void ewk_context_icon_database_delete_all(Ewk_Context* ewkContext)
875 {
876     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
877
878     WKIconDatabaseRef iconDatabase = WKContextGetIconDatabase(ewk_context_WKContext_get(ewkContext));
879     WKIconDatabaseRemoveAllIcons(iconDatabase);
880 }
881
882 Eina_Bool ewk_context_local_file_system_path_set(Ewk_Context* ewkContext, const char* path)
883 {
884 #if ENABLE(TIZEN_FILE_SYSTEM)
885     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
886     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
887
888     TIZEN_LOGI("path (%s)", path);
889     WKRetainPtr<WKStringRef> localFileSystemPathRef(AdoptWK, WKStringCreateWithUTF8CString(path));
890     WKContextSetLocalFileSystemDirectory(ewk_context_WKContext_get(ewkContext), localFileSystemPathRef.get());
891
892     return true;
893 #else
894     return false;
895 #endif
896 }
897
898 Eina_Bool ewk_context_local_file_system_all_delete(Ewk_Context* ewkContext)
899 {
900 #if ENABLE(TIZEN_FILE_SYSTEM)
901     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
902
903     TIZEN_LOGI("ewkContex (%p)", ewkContext);
904     WKLocalFileSystemManagerRef localFileSystemManager = WKContextGetLocalFileSystemManager(ewk_context_WKContext_get(ewkContext));
905     WKLocalFileSystemManagerDeleteAllLocalFileSystem(localFileSystemManager);
906
907     return true;
908 #else
909     UNUSED_PARAM(ewkContext);
910
911     return false;
912 #endif
913 }
914
915 Eina_Bool ewk_context_local_file_system_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
916 {
917 #if ENABLE(TIZEN_FILE_SYSTEM)
918     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
919     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
920
921     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(origin));
922     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
923     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
924     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
925     WKLocalFileSystemManagerRef localFileSystemManager = WKContextGetLocalFileSystemManager(ewk_context_WKContext_get(ewkContext));
926
927     WKLocalFileSystemManagerDeleteLocalFileSystem(localFileSystemManager, originRef.get());
928
929     return true;
930 #else
931     UNUSED_PARAM(ewkContext);
932     UNUSED_PARAM(origin);
933
934     return false;
935 #endif
936 }
937
938 Eina_Bool ewk_context_local_file_system_origins_get(const Ewk_Context* ewkContext, Ewk_Local_File_System_Origins_Get_Callback callback, void* userData)
939 {
940 #if ENABLE(TIZEN_FILE_SYSTEM)
941     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
942     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
943
944     TIZEN_LOGI("callback (%p)", callback);
945     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
946     context->localFileSystemOriginsCallback= callback;
947     context->userData = userData;
948     WKLocalFileSystemManagerRef localFileSystemManager = WKContextGetLocalFileSystemManager(ewk_context_WKContext_get(ewkContext));
949
950     WKLocalFileSystemManagerGetLocalFileSystemOrigins(localFileSystemManager, context, didGetLocalFileSystemOrigins);
951
952     return true;
953 #else
954     UNUSED_PARAM(ewkContext);
955     UNUSED_PARAM(callback);
956     UNUSED_PARAM(userData);
957
958     return false;
959 #endif
960 }
961
962 Ewk_Security_Origin* ewk_context_web_database_exceeded_quota_security_origin_get(Ewk_Context_Exceeded_Quota* exceededQuota)
963 {
964 #if ENABLE(TIZEN_SQL_DATABASE)
965     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
966
967     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(exceededQuota->origin));
968     return exceededQuota->origin;
969 #else
970     return 0;
971 #endif
972 }
973
974 const char* ewk_context_web_database_exceeded_quota_database_name_get(Ewk_Context_Exceeded_Quota* exceededQuota)
975 {
976 #if ENABLE(TIZEN_SQL_DATABASE)
977     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
978
979     TIZEN_LOGI("name (%s)", exceededQuota->databaseName);
980     return exceededQuota->databaseName;
981 #else
982     return 0;
983 #endif
984 }
985
986 const char* ewk_context_web_database_exceeded_quota_display_name_get(Ewk_Context_Exceeded_Quota* exceededQuota)
987 {
988 #if ENABLE(TIZEN_SQL_DATABASE)
989     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
990
991     TIZEN_LOGI("displayName (%s)", exceededQuota->displayName);
992     return exceededQuota->displayName;
993 #else
994     return 0;
995 #endif
996 }
997
998 unsigned long long ewk_context_web_database_exceeded_quota_current_quota_get(Ewk_Context_Exceeded_Quota* exceededQuota)
999 {
1000 #if ENABLE(TIZEN_SQL_DATABASE)
1001     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1002
1003     TIZEN_LOGI("quota (%d)", exceededQuota->currentQuota);
1004     return exceededQuota->currentQuota;
1005 #else
1006     return 0;
1007 #endif
1008 }
1009
1010 unsigned long long ewk_context_web_database_exceeded_quota_current_origin_usage_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1011 {
1012 #if ENABLE(TIZEN_SQL_DATABASE)
1013     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1014
1015     TIZEN_LOGI("currentOriginUsage (%d)", exceededQuota->currentOriginUsage);
1016     return exceededQuota->currentOriginUsage;
1017 #else
1018     return 0;
1019 #endif
1020 }
1021
1022 unsigned long long ewk_context_web_database_exceeded_quota_current_database_usage_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1023 {
1024 #if ENABLE(TIZEN_SQL_DATABASE)
1025     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1026
1027     TIZEN_LOGI("currentDatabaseUsage (%d)", exceededQuota->currentDatabaseUsage);
1028     return exceededQuota->currentDatabaseUsage;
1029 #else
1030     return 0;
1031 #endif
1032 }
1033
1034 unsigned long long ewk_context_web_database_exceeded_quota_expected_usage_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1035 {
1036 #if ENABLE(TIZEN_SQL_DATABASE)
1037     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1038
1039     TIZEN_LOGI("expectedUsage (%d)", exceededQuota->expectedUsage);
1040     return exceededQuota->expectedUsage;
1041 #else
1042     return 0;
1043 #endif
1044 }
1045
1046 void ewk_context_web_database_exceeded_quota_new_quota_set(Ewk_Context_Exceeded_Quota* exceededQuota, unsigned long long quota)
1047 {
1048 #if ENABLE(TIZEN_SQL_DATABASE)
1049     EINA_SAFETY_ON_NULL_RETURN(exceededQuota);
1050
1051     TIZEN_LOGI("quota (%d)", quota);
1052     exceededQuota->newQuota = quota;
1053 #endif
1054 }
1055
1056 Eina_Bool ewk_context_web_database_delete_all(Ewk_Context* ewkContext)
1057 {
1058 #if ENABLE(TIZEN_SQL_DATABASE)
1059     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1060
1061     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1062     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewk_context_WKContext_get(ewkContext));
1063     WKDatabaseManagerDeleteAllDatabases(databaseManager);
1064
1065     return true;
1066 #else
1067     return false;
1068 #endif
1069 }
1070
1071 Eina_Bool ewk_context_web_database_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
1072 {
1073 #if ENABLE(TIZEN_SQL_DATABASE)
1074     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1075     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1076
1077     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(origin));
1078     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1079     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1080     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1081     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewk_context_WKContext_get(ewkContext));
1082     WKDatabaseManagerDeleteDatabasesForOrigin(databaseManager, originRef.get());
1083
1084     return true;
1085 #else
1086     return false;
1087 #endif
1088 }
1089
1090 Eina_Bool ewk_context_web_database_origins_get(Ewk_Context* ewkContext, Ewk_Web_Database_Origins_Get_Callback callback, void* userData)
1091 {
1092 #if ENABLE(TIZEN_SQL_DATABASE)
1093     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1094     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1095
1096     TIZEN_LOGI("callback (%p)", callback);
1097     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1098     context->webDatabaseOriginsCallback = callback;
1099     context->userData = userData;
1100
1101     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewk_context_WKContext_get(ewkContext));
1102     WKDatabaseManagerGetDatabaseOrigins(databaseManager, context, didGetWebDatabaseOrigins);
1103
1104     return true;
1105 #else
1106     return false;
1107 #endif
1108 }
1109
1110 Eina_Bool ewk_context_web_database_path_set(Ewk_Context* ewkContext, const char* path)
1111 {
1112 #if ENABLE(TIZEN_SQL_DATABASE)
1113     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1114     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1115
1116     TIZEN_LOGI("path (%s)", path);
1117     WKRetainPtr<WKStringRef> databasePath(AdoptWK, WKStringCreateWithUTF8CString(path));
1118     WKContextSetDatabaseDirectory(ewk_context_WKContext_get(ewkContext), databasePath.get());
1119
1120     return true;
1121 #else
1122     return false;
1123 #endif
1124 }
1125
1126 Eina_Bool ewk_context_web_database_path_get(Ewk_Context* ewkContext, Ewk_Web_Database_Path_Get_Callback callback, void* userData)
1127 {
1128 #if ENABLE(TIZEN_WEB_STORAGE)
1129     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1130     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1131
1132     TIZEN_LOGI("callback (%p)", callback);
1133     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1134     context->webDatabasePathCallback= callback;
1135     context->userData = userData;
1136
1137     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewk_context_WKContext_get(ewkContext));
1138     WKDatabaseManagerGetDatabasePath(databaseManager, context, didGetWebDatabasePath);
1139     return true;
1140 #else
1141     return false;
1142 #endif
1143 }
1144 Eina_Bool ewk_context_web_database_quota_for_origin_get(Ewk_Context* ewkContext, Ewk_Web_Database_Quota_Get_Callback callback, void* userData, Ewk_Security_Origin* origin)
1145 {
1146 #if ENABLE(TIZEN_SQL_DATABASE)
1147     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1148     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1149     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1150
1151     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(origin));
1152     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1153     context->webDatabaseQuotaCallback = callback;
1154     context->userData = userData;
1155
1156     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1157     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1158     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1159     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewk_context_WKContext_get(ewkContext));
1160     WKDatabaseManagerGetQuotaForOrigin(databaseManager, context, didGetWebDatabaseQuota, originRef.get());
1161
1162     return true;
1163 #else
1164     return false;
1165 #endif
1166 }
1167
1168 Eina_Bool ewk_context_web_database_default_quota_set(Ewk_Context* ewkContext, uint64_t quota)
1169 {
1170 #if ENABLE(TIZEN_SQL_DATABASE)
1171     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1172
1173     TIZEN_LOGI("quota (%d)", quota);
1174     ewkContext->defaultDatabaseQuota = quota;
1175
1176     return true;
1177 #else
1178     return false;
1179 #endif
1180 }
1181
1182 Eina_Bool ewk_context_web_database_quota_for_origin_set(Ewk_Context* ewkContext, Ewk_Security_Origin* origin, uint64_t quota)
1183 {
1184 #if ENABLE(TIZEN_SQL_DATABASE)
1185     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1186     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1187
1188     TIZEN_LOGI("host (%s) quota(%d)", ewk_security_origin_host_get(origin), quota);
1189     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1190     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1191     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1192     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewk_context_WKContext_get(ewkContext));
1193     WKDatabaseManagerSetQuotaForOrigin(databaseManager, originRef.get(), quota);
1194
1195     return true;
1196 #else
1197     return false;
1198 #endif
1199 }
1200
1201 Eina_Bool ewk_context_web_database_usage_for_origin_get(Ewk_Context* ewkContext, Ewk_Web_Database_Quota_Get_Callback callback, void* userData, Ewk_Security_Origin* origin)
1202 {
1203 #if ENABLE(TIZEN_SQL_DATABASE)
1204     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1205     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1206     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1207
1208     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(origin));
1209     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1210     context->webDatabaseQuotaCallback = callback;
1211     context->userData = userData;
1212
1213     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1214     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1215     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1216     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewk_context_WKContext_get(ewkContext));
1217     WKDatabaseManagerGetUsageForOrigin(databaseManager, context, didGetWebDatabaseUsage, originRef.get());
1218
1219     return true;
1220 #else
1221     return false;
1222 #endif
1223 }
1224
1225 Eina_Bool ewk_context_web_indexed_database_delete_all(Ewk_Context* ewkContext)
1226 {
1227 #if ENABLE(TIZEN_INDEXED_DATABASE)
1228     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1229
1230     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1231     DEFINE_STATIC_LOCAL(const String, fileMatchPattern, ("*"));
1232     DEFINE_STATIC_LOCAL(const String, indexedDatabaseDirectory, ("/opt/apps/com.samsung.browser/data/.webkit/indexedDatabases"));
1233
1234     Vector<String> paths = WebCore::listDirectory(indexedDatabaseDirectory, fileMatchPattern);
1235     Vector<String>::const_iterator end = paths.end();
1236     for(Vector<String>::const_iterator it = paths.begin(); it != end; ++it){
1237         String path = *it;
1238 #if ENABLE(TIZEN_FILE_SYSTEM)
1239         WebCore::removeDirectory(path);
1240 #endif
1241     }
1242
1243     return true;
1244 #else
1245     return false;
1246 #endif
1247 }
1248
1249 Eina_Bool ewk_context_web_storage_delete_all(Ewk_Context* ewkContext)
1250 {
1251 #if ENABLE(TIZEN_WEB_STORAGE)
1252     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1253
1254     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1255     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewk_context_WKContext_get(ewkContext));
1256     WKKeyValueStorageManagerDeleteAllEntries(storageManager);
1257
1258     return true;
1259 #else
1260     return false;
1261 #endif
1262 }
1263
1264 Eina_Bool ewk_context_web_storage_origin_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
1265 {
1266 #if ENABLE(TIZEN_WEB_STORAGE)
1267     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1268     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1269
1270     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(origin));
1271     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1272     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1273     WKRetainPtr<WKSecurityOriginRef> securityOriginRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1274     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewk_context_WKContext_get(ewkContext));
1275     WKKeyValueStorageManagerDeleteEntriesForOrigin(storageManager, securityOriginRef.get());
1276
1277     return true;
1278 #else
1279     return false;
1280 #endif
1281 }
1282
1283 Eina_Bool ewk_context_web_storage_origins_get(Ewk_Context* ewkContext, Ewk_Web_Storage_Origins_Get_Callback callback, void* userData)
1284 {
1285 #if ENABLE(TIZEN_WEB_STORAGE)
1286     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1287     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1288
1289     TIZEN_LOGI("callback (%p)", callback);
1290     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1291     context->webStorageOriginsCallback = callback;
1292     context->userData = userData;
1293
1294     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewk_context_WKContext_get(ewkContext));
1295     WKKeyValueStorageManagerGetKeyValueStorageOrigins(storageManager, context, didGetWebStorageOrigins);
1296
1297     return true;
1298 #else
1299     return false;
1300 #endif
1301 }
1302
1303 Eina_Bool ewk_context_web_storage_path_set(Ewk_Context* ewkContext, const char* path)
1304 {
1305 #if ENABLE(TIZEN_WEB_STORAGE)
1306     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1307     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1308
1309     TIZEN_LOGI("path (%s)", path);
1310     WKRetainPtr<WKStringRef> webStoragePath(AdoptWK, WKStringCreateWithUTF8CString(path));
1311     WKContextSetLocalStorageDirectory(ewk_context_WKContext_get(ewkContext), webStoragePath.get());
1312
1313     return true;
1314 #else
1315     return false;
1316 #endif
1317 }
1318
1319 Eina_Bool ewk_context_web_storage_path_get(Ewk_Context* ewkContext, Ewk_Web_Storage_Path_Get_Callback callback, void* userData)
1320 {
1321 #if ENABLE(TIZEN_WEB_STORAGE)
1322     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1323     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1324
1325     TIZEN_LOGI("callback (%p)", callback);
1326     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1327     context->webStoragePathCallback= callback;
1328     context->userData = userData;
1329
1330     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewk_context_WKContext_get(ewkContext));
1331     WKKeyValueStorageManagerGetKeyValueStoragePath(storageManager, context, didGetWebStoragePath);
1332     return true;
1333 #else
1334     return false;
1335 #endif
1336 }
1337 Eina_Bool ewk_context_web_storage_usage_for_origin_get(Ewk_Context* ewkContext, Ewk_Security_Origin* origin, Ewk_Web_Storage_Usage_Get_Callback callback, void* userData)
1338 {
1339 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
1340     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1341     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1342     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1343
1344     TIZEN_LOGI("host (%s)", ewk_security_origin_host_get(origin));
1345     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1346     context->webStorageUsageCallback = callback;
1347     context->userData = userData;
1348     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1349     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1350     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1351
1352     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewk_context_WKContext_get(ewkContext));
1353     WKKeyValueStorageManagerGetKeyValueStorageUsageForOrigin(storageManager, context, didGetWebStorageUsage, originRef.get());
1354
1355     return true;
1356 #else
1357     return false;
1358 #endif
1359 }
1360
1361 //#if ENABLE(TIZEN_SOUP_COOKIE_CACHE_FOR_WEBKIT2)
1362 Eina_Bool ewk_context_soup_data_directory_set(Ewk_Context* ewkContext, const char* path)
1363 {
1364     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1365     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1366
1367     WKRetainPtr<WKStringRef> soupDataDirectory(AdoptWK, WKStringCreateWithUTF8CString(path));
1368     WKContextSetSoupDataDirectory(ewk_context_WKContext_get(ewkContext), soupDataDirectory.get());
1369     return true;
1370 }
1371 //#endif
1372
1373 Eina_Bool ewk_context_cache_model_set(Ewk_Context* ewkContext, Ewk_Cache_Model model)
1374 {
1375     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1376     if (model == EWK_CACHE_MODEL_DOCUMENT_VIEWER)
1377         WKContextSetCacheModel(ewk_context_WKContext_get(ewkContext), kWKCacheModelDocumentViewer);
1378     else if (model == EWK_CACHE_MODEL_DOCUMENT_BROWSER)
1379         WKContextSetCacheModel(ewk_context_WKContext_get(ewkContext), kWKCacheModelDocumentBrowser);
1380     else
1381         WKContextSetCacheModel(ewk_context_WKContext_get(ewkContext), kWKCacheModelPrimaryWebBrowser);
1382
1383     return true;
1384 }
1385
1386 Ewk_Cache_Model ewk_context_cache_model_get(Ewk_Context* ewkContext)
1387 {
1388     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
1389     WKCacheModel cacheModel = WKContextGetCacheModel(ewk_context_WKContext_get(ewkContext));
1390
1391     if (cacheModel == kWKCacheModelDocumentViewer)
1392         return EWK_CACHE_MODEL_DOCUMENT_VIEWER;
1393     else if (cacheModel == kWKCacheModelDocumentBrowser)
1394         return EWK_CACHE_MODEL_DOCUMENT_BROWSER;
1395     else
1396         return EWK_CACHE_MODEL_PRIMARY_WEBBROWSER;
1397 }
1398
1399 Eina_Bool ewk_context_cache_disabled_set(Ewk_Context* ewkContext, Eina_Bool cacheDisabled)
1400 {
1401 #if ENABLE(TIZEN_CACHE_CONTROL)
1402     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1403     WKContextSetCacheDisabled(ewk_context_WKContext_get(ewkContext), cacheDisabled);
1404 #endif
1405
1406     return true;
1407 }
1408
1409 Eina_Bool ewk_context_cache_disabled_get(Ewk_Context* ewkContext)
1410 {
1411 #if ENABLE(TIZEN_CACHE_CONTROL)
1412     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1413     return WKContextGetCacheDisabled(ewk_context_WKContext_get(ewkContext));
1414 #else
1415     return false;
1416 #endif
1417 }
1418
1419 Eina_Bool ewk_context_certificate_file_set(Ewk_Context* context, const char* certificateFile)
1420 {
1421     EINA_SAFETY_ON_NULL_RETURN_VAL(context, false);
1422     EINA_SAFETY_ON_NULL_RETURN_VAL(certificateFile, false);
1423 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
1424     eina_stringshare_replace(&context->certificateFile, certificateFile);
1425
1426     if (!fileExists(WTF::String::fromUTF8(certificateFile)))
1427         LOG_ERROR("[Network] ewk_context_certificate_file_set certificateFile does not exist!\n");
1428
1429     WKRetainPtr<WKStringRef> certificateFileRef(AdoptWK, WKStringCreateWithUTF8CString(certificateFile));
1430     WKContextSetCertificateFile(ewk_context_WKContext_get(context), certificateFileRef.get());
1431     return true;
1432 #else
1433     UNUSED_PARAM(context);
1434     UNUSED_PARAM(certificateFile);
1435     return false;
1436 #endif
1437 }
1438
1439 const char* ewk_context_certificate_file_get(const Ewk_Context* context)
1440 {
1441     EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1442 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
1443     return context->certificateFile;
1444 #else
1445     UNUSED_PARAM(context);
1446     return 0;
1447 #endif
1448 }
1449
1450 Eina_Bool ewk_context_cache_clear(Ewk_Context* ewkContext)
1451 {
1452     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1453     WKResourceCacheManagerRef cacheManager = WKContextGetResourceCacheManager(ewk_context_WKContext_get(ewkContext));
1454 #if ENABLE(TIZEN_EWK_CONTEXT_CACHE_MANAGER_NULL_CHECK_WORKAROUND)
1455     if (!cacheManager)
1456         return false;
1457 #endif
1458     WKResourceCacheManagerClearCacheForAllOrigins(cacheManager, WKResourceCachesToClearAll);
1459
1460     return true;
1461 }
1462
1463 #if ENABLE(TIZEN_CACHE_DUMP_SYNC)
1464 /**
1465  * @internal
1466  * Request WebProcess to dump cache.
1467  *
1468  * This sends sync message to WebProcess to dump memory cache, that is, soup cache.
1469  *
1470  * @param context context object
1471  *
1472  * @return @c EINA_TRUE on success or @c EINA_FALSE on failure
1473  *
1474  * @note This can effect UIProcess's performance because it calls to sync IPC message eventually.
1475  */
1476 void ewk_context_cache_dump(Ewk_Context* ewkContext)
1477 {
1478     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1479     WKResourceCacheManagerRef cacheManager = WKContextGetResourceCacheManager(ewk_context_WKContext_get(ewkContext));
1480     toImpl(cacheManager)->dumpCache();
1481 }
1482 #endif
1483
1484 void ewk_context_message_post_to_injected_bundle(Ewk_Context* ewkContext, const char* name, const char* body)
1485 {
1486     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1487     EINA_SAFETY_ON_NULL_RETURN(name);
1488     EINA_SAFETY_ON_NULL_RETURN(body);
1489
1490     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString(name));
1491     WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithUTF8CString(body));
1492     WKContextPostMessageToInjectedBundle(ewk_context_WKContext_get(ewkContext), messageName.get(), messageBody.get());
1493 }
1494
1495 void ewk_context_message_from_injected_bundle_callback_set(Ewk_Context* ewkContext, Ewk_Context_Message_From_Injected_Bundle_Callback callback, void* userData)
1496 {
1497     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1498
1499     ewkContext->messageFromInjectedBundle.callback = callback;
1500     ewkContext->messageFromInjectedBundle.userData = userData;
1501 }
1502
1503 void ewkContextDidReceiveMessageFromInjectedBundle(Ewk_Context* ewkContext, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData)
1504 {
1505     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1506
1507     if (!ewkContext->messageFromInjectedBundle.callback)
1508         return;
1509
1510     CString name = toImpl(messageName)->string().utf8();
1511     CString body;
1512     if (messageBody && WKStringGetTypeID() == WKGetTypeID(messageBody))
1513         body = toImpl(static_cast<WKStringRef>(messageBody))->string().utf8();
1514
1515     if (returnData) {
1516         char* returnString = 0;
1517         ewkContext->messageFromInjectedBundle.callback(name.data(), body.data(), &returnString,
1518                                                        ewkContext->messageFromInjectedBundle.userData);
1519         if (returnString) {
1520             *returnData = WKStringCreateWithUTF8CString(returnString);
1521             free(returnString);
1522         } else {
1523             *returnData = WKStringCreateWithUTF8CString("");
1524         }
1525     } else {
1526         ewkContext->messageFromInjectedBundle.callback(name.data(), body.data(), 0,
1527                                                        ewkContext->messageFromInjectedBundle.userData);
1528     }
1529 }
1530
1531 void ewk_context_did_start_download_callback_set(Ewk_Context* ewkContext, Ewk_Context_Did_Start_Download_Callback callback, void* userData)
1532 {
1533     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1534
1535     ewkContext->didStartDownload.callback = callback;
1536     ewkContext->didStartDownload.userData = userData;
1537 }
1538
1539 void ewkContextDidStartDownload(Ewk_Context* ewkContext, WKStringRef downloadURL)
1540 {
1541     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1542     EINA_SAFETY_ON_NULL_RETURN(ewkContext->didStartDownload.callback);
1543
1544     ewkContext->didStartDownload.callback(toImpl(downloadURL)->string().utf8().data(), ewkContext->didStartDownload.userData);
1545 }
1546
1547 #if ENABLE(MEMORY_SAMPLER)
1548 void ewk_context_memory_sampler_start(Ewk_Context* ewkContext, double timerInterval)
1549 {
1550     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1551     WKRetainPtr<WKDoubleRef> interval(AdoptWK, WKDoubleCreate(timerInterval));
1552     WKContextStartMemorySampler(ewk_context_WKContext_get(ewkContext), interval.get());
1553 }
1554
1555 void ewk_context_memory_sampler_stop(Ewk_Context* ewkContext)
1556 {
1557     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1558     WKContextStopMemorySampler(ewk_context_WKContext_get(ewkContext));
1559 }
1560 #endif
1561
1562 #if ENABLE(TIZEN_CACHE_MEMORY_OPTIMIZATION)
1563 Eina_Bool ewk_context_decoded_data_clear_all(Ewk_Context* ewkContext)
1564 {
1565     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1566     WKResourceCacheManagerRef cacheManager = WKContextGetResourceCacheManager(ewk_context_WKContext_get(ewkContext));
1567     WKResourceCacheManagerClearCacheForAllOrigins(cacheManager, WKResourceCachesToClearInDecodedDataOnly);
1568
1569     return true;
1570 }
1571 #endif
1572
1573 Eina_Bool ewk_context_additional_plugin_path_set(Ewk_Context* ewkContext, const char* path)
1574 {
1575 #if ENABLE(TIZEN_SUPPORT_PLUGINS)
1576     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1577     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1578
1579     WKRetainPtr<WKStringRef> pluginPath(AdoptWK, WKStringCreateWithUTF8CString(path));
1580     WKContextSetAdditionalPluginsDirectory(ewk_context_WKContext_get(ewkContext), pluginPath.get());
1581
1582     return true;
1583 #else
1584     return false;
1585 #endif
1586 }
1587
1588 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
1589 void ewk_context_memory_saving_mode_set(Ewk_Context* ewkContext, Eina_Bool mode)
1590 {
1591     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1592
1593     WKContextRef contextRef = ewk_context_WKContext_get(ewkContext);
1594     toImpl(contextRef)->setMemorySavingMode(mode);
1595 }
1596 #endif
1597
1598 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
1599 Ecore_X_Window ewk_context_x_window_get(Ewk_Context* ewkContext)
1600 {
1601     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
1602     return ewkContext->xWindow;
1603 }
1604
1605 void ewk_context_x_window_set(Ewk_Context* ewkContext, Ecore_X_Window xWindow)
1606 {
1607     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1608     WKContextRef contextRef = ewk_context_WKContext_get(ewkContext);
1609     toImpl(contextRef)->setXWindow(xWindow);
1610 }
1611 #endif
1612
1613 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
1614 void ewk_context_form_data_add(Ewk_Context* ewkContext, const char* url, WKDictionaryRef& formData, bool isPasswordForm)
1615 {
1616     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1617     EINA_SAFETY_ON_NULL_RETURN(url);
1618     if (!ewkContext->formDatabase->isOpen())
1619         return;
1620
1621     Vector<std::pair<String, String> > formDataVector;
1622     WKRetainPtr<WKArrayRef> wkKeys(AdoptWK, WKDictionaryCopyKeys(formData));
1623     size_t numKeys = WKArrayGetSize(wkKeys.get());
1624     for (size_t i = 0; i < numKeys; ++i) {
1625         WKStringRef wkKey = static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkKeys.get(), i));
1626         WKStringRef wkValue = static_cast<WKStringRef>(WKDictionaryGetItemForKey(formData, wkKey));
1627
1628         int length = WKStringGetMaximumUTF8CStringSize(wkKey);
1629         if (length <= 0)
1630             continue;
1631         OwnArrayPtr<char> keyBuffer = adoptArrayPtr(new char[length]);
1632         WKStringGetUTF8CString(wkKey, keyBuffer.get(), length);
1633
1634         length = WKStringGetMaximumUTF8CStringSize(wkValue);
1635         if (length <= 0)
1636             continue;
1637         OwnArrayPtr<char> valueBuffer = adoptArrayPtr(new char[length]);
1638         WKStringGetUTF8CString(wkValue, valueBuffer.get(), length);
1639         formDataVector.append(pair<String, String>(keyBuffer.get(), valueBuffer.get()));
1640     }
1641
1642     ewkContext->formDatabase->addFormDataForURL(String::fromUTF8(url), formDataVector, isPasswordForm);
1643 }
1644
1645 void ewk_context_form_password_data_get(Ewk_Context* ewkContext, const char* url, Vector<std::pair<String, String> >& passwordFormData)
1646 {
1647     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1648     EINA_SAFETY_ON_NULL_RETURN(url);
1649     if (!ewkContext->formDatabase->isOpen())
1650         return;
1651     ewkContext->formDatabase->getPasswordFormDataForURL(String::fromUTF8(url), passwordFormData);
1652 }
1653
1654 void ewk_context_form_candidate_data_get(Ewk_Context* ewkContext, const String& name, Vector<String>& candidates)
1655 {
1656     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1657     if (!ewkContext->formDatabase->isOpen())
1658         return;
1659     ewkContext->formDatabase->getCandidateFormDataForName(name, candidates);
1660 }
1661
1662 void ewk_context_form_password_data_clear(Ewk_Context* ewkContext)
1663 {
1664     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1665     ewkContext->formDatabase->clearPasswordFormData();
1666 }
1667
1668 void ewk_context_form_candidate_data_clear(Ewk_Context* ewkContext)
1669 {
1670     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1671     ewkContext->formDatabase->clearCandidateFormData();
1672 }
1673 #endif
1674 #endif // #if OS(TIZEN)
1675
1676 Eina_Bool ewk_context_url_scheme_register(Ewk_Context* ewkContext, const char* scheme, Ewk_Url_Scheme_Request_Cb callback, void* userData)
1677 {
1678     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1679     EINA_SAFETY_ON_NULL_RETURN_VAL(scheme, false);
1680     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1681
1682     ewkContext->urlSchemeHandlers.set(String::fromUTF8(scheme), _Ewk_Url_Scheme_Handler(callback, userData));
1683     WKRetainPtr<WKStringRef> wkScheme(AdoptWK, WKStringCreateWithUTF8CString(scheme));
1684     WKSoupRequestManagerRegisterURIScheme(ewkContext->requestManager.get(), wkScheme.get());
1685
1686     return true;
1687 }
1688
1689 void ewk_context_vibration_client_callbacks_set(Ewk_Context* ewkContext, Ewk_Vibration_Client_Vibrate_Cb vibrate, Ewk_Vibration_Client_Vibration_Cancel_Cb cancel, void* data)
1690 {
1691     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1692
1693     TIZEN_LOGI("vibrate (%p)", vibrate);
1694 #if ENABLE(VIBRATION)
1695     ewkContext->vibrationProvider->setVibrationClientCallbacks(vibrate, cancel, data);
1696 #endif
1697 }
1698
1699 Eina_Bool ewk_context_tizen_extensible_api_set(Ewk_Context* ewkContext,  Ewk_Extensible_API extensibleAPI, Eina_Bool enable)
1700 {
1701 #if ENABLE(TIZEN_EXTENSIBLE_API)
1702     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1703
1704     TIZEN_LOGI("extensibleAPI (%d) enable (%d)", extensibleAPI, enable);
1705     WKContextSetTizenExtensibleAPI(ewk_context_WKContext_get(ewkContext), static_cast<WKTizenExtensibleAPI>(extensibleAPI), enable);
1706
1707     return true;
1708 #else
1709     UNUSED_PARAM(ewkContext);
1710     UNUSED_PARAM(extensibleAPI);
1711     UNUSED_PARAM(enable);
1712
1713     return false;
1714 #endif
1715 }
1716
1717 void ewk_context_storage_path_reset(Ewk_Context* ewkContext)
1718 {
1719 #if ENABLE(TIZEN_RESET_PATH)
1720     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1721
1722     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1723     WKContextResetStoragePath(ewk_context_WKContext_get(ewkContext));
1724 #else
1725     UNUSED_PARAM(ewkContext);
1726 #endif
1727 }