Merge "[Cherry-pick][[Text Autosizing] Refactoring to eliminate boolean parameter...
[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     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
844     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
845     WKRetainPtr<WKSecurityOriginRef> securityOriginRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
846     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
847     WKApplicationCacheManagerDeleteEntriesForOrigin(applicationCacheRef, securityOriginRef.get());
848
849     return true;
850 #else
851     return false;
852 #endif
853 }
854
855 Eina_Bool ewk_context_application_cache_origins_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Origins_Get_Callback callback, void *userData)
856 {
857 #if ENABLE(TIZEN_APPLICATION_CACHE)
858     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
859     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
860
861     TIZEN_LOGI("ewkContext (%p)", ewkContext);
862     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
863     context->webApplicationCacheOriginsCallback = callback;
864     context->userData = userData;
865
866     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
867     WKApplicationCacheManagerGetApplicationCacheOrigins(applicationCacheRef, context, didGetWebApplicationOrigins);
868
869     return true;
870 #else
871     return false;
872 #endif
873 }
874
875 Eina_Bool ewk_context_application_cache_path_set(Ewk_Context* ewkContext, const char* path)
876 {
877 #if ENABLE(TIZEN_APPLICATION_CACHE)
878     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
879     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
880
881     if (!path) {
882         TIZEN_LOGE("Path value is invalid");
883         return false;
884     }
885
886     TIZEN_LOGI("path (%s)", path);
887     WKRetainPtr<WKStringRef> applicationCachePathRef(AdoptWK, WKStringCreateWithUTF8CString(path));
888     WKContextSetApplicationCacheDirectory(ewkContext->wkContext(), applicationCachePathRef.get());
889
890     return true;
891 #else
892     return false;
893 #endif
894 }
895
896 Eina_Bool ewk_context_application_cache_path_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Path_Get_Callback callback, void* userData)
897 {
898 #if ENABLE(TIZEN_APPLICATION_CACHE)
899     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
900     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
901
902     TIZEN_LOGI("callback (%p)", callback);
903     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
904     context->webApplicationCachePathCallback= callback;
905     context->userData = userData;
906
907     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
908     WKApplicationCacheManagerGetApplicationCachePath(applicationCacheRef, context, didGetWebApplicationPath);
909     return true;
910 #else
911     return false;
912 #endif
913 }
914
915 Eina_Bool ewk_context_application_cache_quota_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Quota_Get_Callback callback, void* userData)
916 {
917 #if ENABLE(TIZEN_APPLICATION_CACHE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
918     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
919     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
920
921     TIZEN_LOGI("callback (%p)", callback);
922     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
923     context->webApplicationCacheQuotaCallback = callback;
924     context->userData = userData;
925
926     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
927     WKApplicationCacheManagerGetApplicationCacheQuota(applicationCacheRef, context, didGetWebApplicationQuota);
928
929     return true;
930 #else
931     return false;
932 #endif
933 }
934
935 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)
936 {
937 #if ENABLE(TIZEN_APPLICATION_CACHE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
938     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
939     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
940     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
941
942     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
943     context->webApplicationCacheUsageForOriginCallback = callback;
944     context->userData = userData;
945     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
946     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
947     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
948
949     WKApplicationCacheManagerRef applicationCache = WKContextGetApplicationCacheManager(ewkContext->wkContext());
950     WKApplicationCacheManagerGetApplicationCacheUsageForOrigin(applicationCache, context, originRef.get(), didGetWebApplicationUsageForOrigin);
951
952     return true;
953 #else
954     return false;
955 #endif
956 }
957
958 Eina_Bool ewk_context_application_cache_quota_set(Ewk_Context* ewkContext, int64_t quota)
959 {
960 #if ENABLE(TIZEN_APPLICATION_CACHE)
961     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
962     if (!quota) {
963         TIZEN_LOGE("Quota value is invalid");
964         return false;
965     }
966
967     TIZEN_LOGI("quota (%d)", quota);
968     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
969     WKApplicationCacheManagerSetApplicationCacheQuota(applicationCacheRef, quota);
970
971     return true;
972 #else
973     return false;
974 #endif
975 }
976
977 Eina_Bool ewk_context_application_cache_quota_for_origin_set(Ewk_Context* ewkContext, const Ewk_Security_Origin* origin, int64_t quota)
978 {
979 #if ENABLE(TIZEN_APPLICATION_CACHE)
980     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
981     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
982     if (!quota) {
983         TIZEN_LOGE("Quota value is invalid");
984         return false;
985     }
986
987     TIZEN_LOGI("quota (%d)", quota);
988     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
989     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
990     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
991
992     WKApplicationCacheManagerRef applicationCache = WKContextGetApplicationCacheManager(ewkContext->wkContext());
993     WKApplicationCacheManagerSetApplicationCacheQuotaForOrigin(applicationCache, originRef.get(), quota);
994
995     return true;
996 #else
997     return false;
998 #endif
999 }
1000
1001
1002 Eina_Bool ewk_context_icon_database_path_set(Ewk_Context* ewkContext, const char* path)
1003 {
1004     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1005     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1006
1007     WKRetainPtr<WKStringRef> databasePath(AdoptWK, WKStringCreateWithUTF8CString(path));
1008     WKContextSetIconDatabasePath(ewkContext->wkContext(), databasePath.get());
1009
1010     return true;
1011 }
1012
1013 Evas_Object* ewk_context_icon_database_icon_object_add(Ewk_Context* ewkContext, const char* uri, Evas* canvas)
1014 {
1015     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
1016     EINA_SAFETY_ON_NULL_RETURN_VAL(uri, 0);
1017     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1018
1019     WKIconDatabaseRef iconDatabase = WKContextGetIconDatabase(ewkContext->wkContext());
1020     WKRetainPtr<WKURLRef> urlString(AdoptWK, WKURLCreateWithUTF8CString(uri));
1021
1022     return WKIconDatabaseTryGetImageForURL(iconDatabase, canvas, urlString.get());
1023 }
1024
1025 void ewk_context_icon_database_delete_all(Ewk_Context* ewkContext)
1026 {
1027     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1028
1029     WKIconDatabaseRef iconDatabase = WKContextGetIconDatabase(ewkContext->wkContext());
1030     WKIconDatabaseRemoveAllIcons(iconDatabase);
1031 }
1032
1033 Eina_Bool ewk_context_local_file_system_path_set(Ewk_Context* ewkContext, const char* path)
1034 {
1035 #if ENABLE(TIZEN_FILE_SYSTEM)
1036     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1037     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1038
1039     TIZEN_LOGI("path (%s)", path);
1040     WKRetainPtr<WKStringRef> localFileSystemPathRef(AdoptWK, WKStringCreateWithUTF8CString(path));
1041     WKContextSetLocalFileSystemDirectory(ewkContext->wkContext(), localFileSystemPathRef.get());
1042
1043     return true;
1044 #else
1045     return false;
1046 #endif
1047 }
1048
1049 Eina_Bool ewk_context_local_file_system_all_delete(Ewk_Context* ewkContext)
1050 {
1051 #if ENABLE(TIZEN_FILE_SYSTEM)
1052     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1053
1054     TIZEN_LOGI("ewkContex (%p)", ewkContext);
1055     WKLocalFileSystemManagerRef localFileSystemManager = WKContextGetLocalFileSystemManager(ewkContext->wkContext());
1056     WKLocalFileSystemManagerDeleteAllLocalFileSystem(localFileSystemManager);
1057
1058     return true;
1059 #else
1060     UNUSED_PARAM(ewkContext);
1061
1062     return false;
1063 #endif
1064 }
1065
1066 Eina_Bool ewk_context_local_file_system_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
1067 {
1068 #if ENABLE(TIZEN_FILE_SYSTEM)
1069     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1070     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1071
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     return exceededQuota->origin;
1118 #else
1119     return 0;
1120 #endif
1121 }
1122
1123 const char* ewk_context_web_database_exceeded_quota_database_name_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1124 {
1125 #if ENABLE(TIZEN_SQL_DATABASE)
1126     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1127
1128     TIZEN_LOGI("name (%s)", exceededQuota->databaseName);
1129     return exceededQuota->databaseName;
1130 #else
1131     return 0;
1132 #endif
1133 }
1134
1135 const char* ewk_context_web_database_exceeded_quota_display_name_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1136 {
1137 #if ENABLE(TIZEN_SQL_DATABASE)
1138     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1139
1140     TIZEN_LOGI("displayName (%s)", exceededQuota->displayName);
1141     return exceededQuota->displayName;
1142 #else
1143     return 0;
1144 #endif
1145 }
1146
1147 unsigned long long ewk_context_web_database_exceeded_quota_current_quota_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1148 {
1149 #if ENABLE(TIZEN_SQL_DATABASE)
1150     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1151
1152     TIZEN_LOGI("quota (%d)", exceededQuota->currentQuota);
1153     return exceededQuota->currentQuota;
1154 #else
1155     return 0;
1156 #endif
1157 }
1158
1159 unsigned long long ewk_context_web_database_exceeded_quota_current_origin_usage_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1160 {
1161 #if ENABLE(TIZEN_SQL_DATABASE)
1162     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1163
1164     TIZEN_LOGI("currentOriginUsage (%d)", exceededQuota->currentOriginUsage);
1165     return exceededQuota->currentOriginUsage;
1166 #else
1167     return 0;
1168 #endif
1169 }
1170
1171 unsigned long long ewk_context_web_database_exceeded_quota_current_database_usage_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1172 {
1173 #if ENABLE(TIZEN_SQL_DATABASE)
1174     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1175
1176     TIZEN_LOGI("currentDatabaseUsage (%d)", exceededQuota->currentDatabaseUsage);
1177     return exceededQuota->currentDatabaseUsage;
1178 #else
1179     return 0;
1180 #endif
1181 }
1182
1183 unsigned long long ewk_context_web_database_exceeded_quota_expected_usage_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1184 {
1185 #if ENABLE(TIZEN_SQL_DATABASE)
1186     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1187
1188     TIZEN_LOGI("expectedUsage (%d)", exceededQuota->expectedUsage);
1189     return exceededQuota->expectedUsage;
1190 #else
1191     return 0;
1192 #endif
1193 }
1194
1195 void ewk_context_web_database_exceeded_quota_new_quota_set(Ewk_Context_Exceeded_Quota* exceededQuota, unsigned long long quota)
1196 {
1197 #if ENABLE(TIZEN_SQL_DATABASE)
1198     EINA_SAFETY_ON_NULL_RETURN(exceededQuota);
1199
1200     TIZEN_LOGI("quota (%d)", quota);
1201     exceededQuota->newQuota = quota;
1202 #endif
1203 }
1204
1205 Eina_Bool ewk_context_web_database_delete_all(Ewk_Context* ewkContext)
1206 {
1207 #if ENABLE(TIZEN_SQL_DATABASE)
1208     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1209
1210     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1211     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1212     WKDatabaseManagerDeleteAllDatabases(databaseManager);
1213
1214     return true;
1215 #else
1216     return false;
1217 #endif
1218 }
1219
1220 Eina_Bool ewk_context_web_database_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
1221 {
1222 #if ENABLE(TIZEN_SQL_DATABASE)
1223     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1224     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1225
1226     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1227     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1228     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1229     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1230     WKDatabaseManagerDeleteDatabasesForOrigin(databaseManager, originRef.get());
1231
1232     return true;
1233 #else
1234     return false;
1235 #endif
1236 }
1237
1238 Eina_Bool ewk_context_web_database_origins_get(Ewk_Context* ewkContext, Ewk_Web_Database_Origins_Get_Callback callback, void* userData)
1239 {
1240 #if ENABLE(TIZEN_SQL_DATABASE)
1241     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1242     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1243
1244     TIZEN_LOGI("callback (%p)", callback);
1245     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1246     context->webDatabaseOriginsCallback = callback;
1247     context->userData = userData;
1248
1249     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1250     WKDatabaseManagerGetDatabaseOrigins(databaseManager, context, didGetWebDatabaseOrigins);
1251
1252     return true;
1253 #else
1254     return false;
1255 #endif
1256 }
1257
1258 Eina_Bool ewk_context_web_database_path_set(Ewk_Context* ewkContext, const char* path)
1259 {
1260 #if ENABLE(TIZEN_SQL_DATABASE)
1261     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1262     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1263
1264     TIZEN_LOGI("path (%s)", path);
1265     WKRetainPtr<WKStringRef> databasePath(AdoptWK, WKStringCreateWithUTF8CString(path));
1266     WKContextSetDatabaseDirectory(ewkContext->wkContext(), databasePath.get());
1267
1268     return true;
1269 #else
1270     return false;
1271 #endif
1272 }
1273
1274 Eina_Bool ewk_context_web_database_path_get(Ewk_Context* ewkContext, Ewk_Web_Database_Path_Get_Callback callback, void* userData)
1275 {
1276 #if ENABLE(TIZEN_WEB_STORAGE)
1277     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1278     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1279
1280     TIZEN_LOGI("callback (%p)", callback);
1281     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1282     context->webDatabasePathCallback= callback;
1283     context->userData = userData;
1284
1285     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1286     WKDatabaseManagerGetDatabasePath(databaseManager, context, didGetWebDatabasePath);
1287     return true;
1288 #else
1289     return false;
1290 #endif
1291 }
1292 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)
1293 {
1294 #if ENABLE(TIZEN_SQL_DATABASE)
1295     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1296     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1297     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1298
1299     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1300     context->webDatabaseQuotaCallback = callback;
1301     context->userData = userData;
1302
1303     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1304     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1305     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1306     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1307     WKDatabaseManagerGetQuotaForOrigin(databaseManager, context, didGetWebDatabaseQuota, originRef.get());
1308
1309     return true;
1310 #else
1311     return false;
1312 #endif
1313 }
1314
1315 Eina_Bool ewk_context_web_database_default_quota_set(Ewk_Context* ewkContext, uint64_t quota)
1316 {
1317 #if ENABLE(TIZEN_SQL_DATABASE)
1318     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1319
1320     TIZEN_LOGI("quota (%d)", quota);
1321     ewkContext->setDefaultDatabaseQuota(quota);
1322
1323     return true;
1324 #else
1325     return false;
1326 #endif
1327 }
1328
1329 Eina_Bool ewk_context_web_database_quota_for_origin_set(Ewk_Context* ewkContext, Ewk_Security_Origin* origin, uint64_t quota)
1330 {
1331 #if ENABLE(TIZEN_SQL_DATABASE)
1332     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1333     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1334
1335     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1336     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1337     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1338     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1339     WKDatabaseManagerSetQuotaForOrigin(databaseManager, originRef.get(), quota);
1340
1341     return true;
1342 #else
1343     return false;
1344 #endif
1345 }
1346
1347 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)
1348 {
1349 #if ENABLE(TIZEN_SQL_DATABASE)
1350     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1351     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1352     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1353
1354     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1355     context->webDatabaseQuotaCallback = callback;
1356     context->userData = userData;
1357
1358     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1359     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1360     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1361     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1362     WKDatabaseManagerGetUsageForOrigin(databaseManager, context, didGetWebDatabaseUsage, originRef.get());
1363
1364     return true;
1365 #else
1366     return false;
1367 #endif
1368 }
1369
1370 Eina_Bool ewk_context_web_indexed_database_delete_all(Ewk_Context* ewkContext)
1371 {
1372 #if ENABLE(TIZEN_INDEXED_DATABASE)
1373     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1374
1375     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1376     DEFINE_STATIC_LOCAL(const String, fileMatchPattern, ("*"));
1377     DEFINE_STATIC_LOCAL(const String, indexedDatabaseDirectory, ("/opt/apps/com.samsung.browser/data/.webkit/indexedDatabases"));
1378
1379     Vector<String> paths = WebCore::listDirectory(indexedDatabaseDirectory, fileMatchPattern);
1380     Vector<String>::const_iterator end = paths.end();
1381     for(Vector<String>::const_iterator it = paths.begin(); it != end; ++it){
1382         String path = *it;
1383 #if ENABLE(TIZEN_FILE_SYSTEM)
1384         WebCore::removeDirectory(path);
1385 #endif
1386     }
1387
1388     return true;
1389 #else
1390     return false;
1391 #endif
1392 }
1393
1394 Eina_Bool ewk_context_web_storage_delete_all(Ewk_Context* ewkContext)
1395 {
1396 #if ENABLE(TIZEN_WEB_STORAGE)
1397     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1398
1399     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1400     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1401     WKKeyValueStorageManagerDeleteAllEntries(storageManager);
1402
1403     return true;
1404 #else
1405     return false;
1406 #endif
1407 }
1408
1409 Eina_Bool ewk_context_web_storage_origin_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
1410 {
1411 #if ENABLE(TIZEN_WEB_STORAGE)
1412     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1413     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1414
1415     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1416     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1417     WKRetainPtr<WKSecurityOriginRef> securityOriginRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1418     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1419     WKKeyValueStorageManagerDeleteEntriesForOrigin(storageManager, securityOriginRef.get());
1420
1421     return true;
1422 #else
1423     return false;
1424 #endif
1425 }
1426
1427 Eina_Bool ewk_context_web_storage_origins_get(Ewk_Context* ewkContext, Ewk_Web_Storage_Origins_Get_Callback callback, void* userData)
1428 {
1429 #if ENABLE(TIZEN_WEB_STORAGE)
1430     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1431     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1432
1433     TIZEN_LOGI("callback (%p)", callback);
1434     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1435     context->webStorageOriginsCallback = callback;
1436     context->userData = userData;
1437
1438     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1439     WKKeyValueStorageManagerGetKeyValueStorageOrigins(storageManager, context, didGetWebStorageOrigins);
1440
1441     return true;
1442 #else
1443     return false;
1444 #endif
1445 }
1446
1447 Eina_Bool ewk_context_web_storage_path_set(Ewk_Context* ewkContext, const char* path)
1448 {
1449 #if ENABLE(TIZEN_WEB_STORAGE)
1450     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1451     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1452
1453     TIZEN_LOGI("path (%s)", path);
1454     WKRetainPtr<WKStringRef> webStoragePath(AdoptWK, WKStringCreateWithUTF8CString(path));
1455     WKContextSetLocalStorageDirectory(ewkContext->wkContext(), webStoragePath.get());
1456
1457     return true;
1458 #else
1459     return false;
1460 #endif
1461 }
1462
1463 Eina_Bool ewk_context_web_storage_path_get(Ewk_Context* ewkContext, Ewk_Web_Storage_Path_Get_Callback callback, void* userData)
1464 {
1465 #if ENABLE(TIZEN_WEB_STORAGE)
1466     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1467     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1468
1469     TIZEN_LOGI("callback (%p)", callback);
1470     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1471     context->webStoragePathCallback= callback;
1472     context->userData = userData;
1473
1474     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1475     WKKeyValueStorageManagerGetKeyValueStoragePath(storageManager, context, didGetWebStoragePath);
1476     return true;
1477 #else
1478     return false;
1479 #endif
1480 }
1481 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)
1482 {
1483 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
1484     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1485     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1486     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1487
1488     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1489     context->webStorageUsageCallback = callback;
1490     context->userData = userData;
1491     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1492     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1493     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1494
1495     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1496     WKKeyValueStorageManagerGetKeyValueStorageUsageForOrigin(storageManager, context, didGetWebStorageUsage, originRef.get());
1497
1498     return true;
1499 #else
1500     return false;
1501 #endif
1502 }
1503
1504 //#if ENABLE(TIZEN_SOUP_COOKIE_CACHE_FOR_WEBKIT2)
1505 Eina_Bool ewk_context_soup_data_directory_set(Ewk_Context* ewkContext, const char* path)
1506 {
1507     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1508     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1509
1510     WKRetainPtr<WKStringRef> soupDataDirectory(AdoptWK, WKStringCreateWithUTF8CString(path));
1511     WKContextSetSoupDataDirectory(ewkContext->wkContext(), soupDataDirectory.get());
1512     return true;
1513 }
1514 //#endif
1515
1516 COMPILE_ASSERT_MATCHING_ENUM(EWK_CACHE_MODEL_DOCUMENT_VIEWER, kWKCacheModelDocumentViewer);
1517 COMPILE_ASSERT_MATCHING_ENUM(EWK_CACHE_MODEL_DOCUMENT_BROWSER, kWKCacheModelDocumentBrowser);
1518 COMPILE_ASSERT_MATCHING_ENUM(EWK_CACHE_MODEL_PRIMARY_WEBBROWSER, kWKCacheModelPrimaryWebBrowser);
1519
1520 Eina_Bool ewk_context_cache_model_set(Ewk_Context* ewkContext, Ewk_Cache_Model cacheModel)
1521 {
1522     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1523
1524     ewkContext->setCacheModel(cacheModel);
1525
1526     return true;
1527 }
1528
1529 Ewk_Cache_Model ewk_context_cache_model_get(Ewk_Context* ewkContext)
1530 {
1531     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
1532
1533     return ewkContext->cacheModel();
1534 }
1535
1536 Eina_Bool ewk_context_cache_disabled_set(Ewk_Context* ewkContext, Eina_Bool cacheDisabled)
1537 {
1538 #if ENABLE(TIZEN_CACHE_CONTROL)
1539     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1540     WKContextSetCacheDisabled(ewkContext->wkContext(), cacheDisabled);
1541 #endif
1542
1543     return true;
1544 }
1545
1546 Eina_Bool ewk_context_cache_disabled_get(Ewk_Context* ewkContext)
1547 {
1548 #if ENABLE(TIZEN_CACHE_CONTROL)
1549     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1550     return WKContextGetCacheDisabled(ewkContext->wkContext());
1551 #else
1552     return false;
1553 #endif
1554 }
1555
1556 Eina_Bool ewk_context_certificate_file_set(Ewk_Context* context, const char* certificateFile)
1557 {
1558     EINA_SAFETY_ON_NULL_RETURN_VAL(context, false);
1559     EINA_SAFETY_ON_NULL_RETURN_VAL(certificateFile, false);
1560 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
1561     if (!context->setCertificateFile(certificateFile))
1562         return true;
1563
1564     if (fileExists(WTF::String::fromUTF8(certificateFile))) {
1565         long long fileSize = -1;
1566         getFileSize(WTF::String::fromUTF8(certificateFile), fileSize);
1567         TIZEN_LOGE("[Network] ewk_context_certificate_file_set certificateFile fileSize [%lld]\n", fileSize);
1568     } else
1569         TIZEN_LOGE("[Network] ewk_context_certificate_file_set certificateFile does not exist!\n");
1570
1571     WKRetainPtr<WKStringRef> certificateFileRef(AdoptWK, WKStringCreateWithUTF8CString(certificateFile));
1572     WKContextSetCertificateFile(context->wkContext(), certificateFileRef.get());
1573     return true;
1574 #else
1575     UNUSED_PARAM(context);
1576     UNUSED_PARAM(certificateFile);
1577     return false;
1578 #endif
1579 }
1580
1581 const char* ewk_context_certificate_file_get(const Ewk_Context* context)
1582 {
1583     EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1584 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
1585     return context->certificateFile();
1586 #else
1587     UNUSED_PARAM(context);
1588     return 0;
1589 #endif
1590 }
1591
1592 Eina_Bool ewk_context_cache_clear(Ewk_Context* ewkContext)
1593 {
1594     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1595     WKResourceCacheManagerRef cacheManager = WKContextGetResourceCacheManager(ewkContext->wkContext());
1596 #if ENABLE(TIZEN_EWK_CONTEXT_CACHE_MANAGER_NULL_CHECK_WORKAROUND)
1597     if (!cacheManager)
1598         return false;
1599 #endif
1600     WKResourceCacheManagerClearCacheForAllOrigins(cacheManager, WKResourceCachesToClearAll);
1601
1602     return true;
1603 }
1604
1605 void ewk_context_message_post_to_injected_bundle(Ewk_Context* ewkContext, const char* name, const char* body)
1606 {
1607     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1608     EINA_SAFETY_ON_NULL_RETURN(name);
1609     EINA_SAFETY_ON_NULL_RETURN(body);
1610
1611     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString(name));
1612     WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithUTF8CString(body));
1613     WKContextPostMessageToInjectedBundle(ewkContext->wkContext(), messageName.get(), messageBody.get());
1614 }
1615
1616 void ewk_context_message_from_injected_bundle_callback_set(Ewk_Context* ewkContext, Ewk_Context_Message_From_Injected_Bundle_Callback callback, void* userData)
1617 {
1618     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1619
1620     ewkContext->setMessageFromInjectedBundleCallback(callback, userData);
1621 }
1622
1623 void ewk_context_did_start_download_callback_set(Ewk_Context* ewkContext, Ewk_Context_Did_Start_Download_Callback callback, void* userData)
1624 {
1625     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1626
1627     ewkContext->setDidStartDownloadCallback(callback, userData);
1628 }
1629
1630 #if ENABLE(MEMORY_SAMPLER)
1631 void ewk_context_memory_sampler_start(Ewk_Context* ewkContext, double timerInterval)
1632 {
1633     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1634     WKRetainPtr<WKDoubleRef> interval(AdoptWK, WKDoubleCreate(timerInterval));
1635     WKContextStartMemorySampler(ewkContext->wkContext(), interval.get());
1636 }
1637
1638 void ewk_context_memory_sampler_stop(Ewk_Context* ewkContext)
1639 {
1640     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1641     WKContextStopMemorySampler(ewkContext->wkContext());
1642 }
1643 #endif
1644
1645 Eina_Bool ewk_context_additional_plugin_path_set(Ewk_Context* ewkContext, const char* path)
1646 {
1647 #if ENABLE(TIZEN_SUPPORT_PLUGINS)
1648     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1649     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1650
1651     WKRetainPtr<WKStringRef> pluginPath(AdoptWK, WKStringCreateWithUTF8CString(path));
1652     WKContextSetAdditionalPluginsDirectory(ewkContext->wkContext(), pluginPath.get());
1653
1654     return true;
1655 #else
1656     return false;
1657 #endif
1658 }
1659
1660 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
1661 void ewk_context_memory_saving_mode_set(Ewk_Context* ewkContext, Eina_Bool mode)
1662 {
1663     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1664
1665     WKContextRef contextRef = ewkContext->wkContext();
1666     toImpl(contextRef)->setMemorySavingMode(mode);
1667 }
1668 #endif
1669
1670 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
1671 void ewk_context_form_password_data_clear(Ewk_Context* ewkContext)
1672 {
1673     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1674     ewkContext->clearPasswordFormData();
1675 }
1676
1677 void ewk_context_form_candidate_data_clear(Ewk_Context* ewkContext)
1678 {
1679     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1680     ewkContext->clearCandidateFormData();
1681 }
1682 #endif
1683 #endif // #if OS(TIZEN)
1684
1685 Eina_Bool ewk_context_url_scheme_register(Ewk_Context* ewkContext, const char* scheme, Ewk_Url_Scheme_Request_Cb callback, void* userData)
1686 {
1687     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1688     EINA_SAFETY_ON_NULL_RETURN_VAL(scheme, false);
1689     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1690
1691     ewkContext->requestManager()->registerURLSchemeHandler(String::fromUTF8(scheme), callback, userData);
1692
1693     return true;
1694 }
1695
1696 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)
1697 {
1698     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1699
1700     TIZEN_LOGI("vibrate (%p)", vibrate);
1701 #if ENABLE(VIBRATION)
1702     ewkContext->vibrationProvider()->setVibrationClientCallbacks(vibrate, cancel, data);
1703 #endif
1704 }
1705
1706 Eina_Bool ewk_context_tizen_extensible_api_set(Ewk_Context* ewkContext,  Ewk_Extensible_API extensibleAPI, Eina_Bool enable)
1707 {
1708 #if ENABLE(TIZEN_EXTENSIBLE_API)
1709     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1710
1711     TIZEN_LOGI("extensibleAPI (%d) enable (%d)", extensibleAPI, enable);
1712     WKContextSetTizenExtensibleAPI(ewkContext->wkContext(), static_cast<WKTizenExtensibleAPI>(extensibleAPI), enable);
1713
1714     return true;
1715 #else
1716     UNUSED_PARAM(ewkContext);
1717     UNUSED_PARAM(extensibleAPI);
1718     UNUSED_PARAM(enable);
1719
1720     return false;
1721 #endif
1722 }
1723
1724 void ewk_context_storage_path_reset(Ewk_Context* ewkContext)
1725 {
1726 #if ENABLE(TIZEN_RESET_PATH)
1727     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1728
1729     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1730     WKContextResetStoragePath(ewkContext->wkContext());
1731 #else
1732     UNUSED_PARAM(ewkContext);
1733 #endif
1734 }
1735
1736 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)
1737 {
1738     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1739
1740     ewkContext->historyClient()->setCallbacks(navigate, clientRedirect, serverRedirect, titleUpdate, populateVisitedLinks, data);
1741 }
1742
1743 void ewk_context_visited_link_add(Ewk_Context* ewkContext, const char* visitedURL)
1744 {
1745     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1746     EINA_SAFETY_ON_NULL_RETURN(visitedURL);
1747
1748     ewkContext->addVisitedLink(visitedURL);
1749 }