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