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