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