77f40d5ba29cbc11733acb34d1cc28af1c314b07
[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_PROCESS_PERMISSION_CONTROL)
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
578     const char* pluginProcessExecutablePath = getenv("PLUGIN_PROCESS_EXECUTABLE_PATH");
579     if (pluginProcessExecutablePath) {
580         WKContextRef contextRef = ewkContext->wkContext();
581         toImpl(contextRef)->pluginInfoStore().setExecutablePath(String::fromUTF8(pluginProcessExecutablePath));
582     }
583 #endif
584     return ewkContext;
585 #else
586     return Ewk_Context::create().leakRef();
587 #endif
588 }
589
590 Ewk_Context* ewk_context_new_with_injected_bundle_path(const char* path)
591 {
592     EINA_SAFETY_ON_NULL_RETURN_VAL(path, 0);
593
594 #if ENABLE(TIZEN_WEBKIT2_DDK_CHECK)
595     // FIXME : OpenGL check code for WRT before launching WebProcess.
596     if(!eglGetDisplay(EGL_DEFAULT_DISPLAY)) {
597         EINA_LOG_CRIT("Fail in initiziling view because No DDK is installed.");
598         return 0;
599     }
600 #endif
601
602 #if ENABLE(TIZEN_WRT_LAUNCHING_PERFORMANCE)
603     char* wrtLaunchingPerformance = getenv("WRT_LAUNCHING_PERFORMANCE");
604     if (wrtLaunchingPerformance && !strcmp(wrtLaunchingPerformance, "1")) {
605         static bool firstTime = true;
606         if (firstTime) {
607             firstTime = false;
608
609             if (ProcessLauncher::isInitialFork())
610                 ProcessLauncher::setSkipExec(true);
611             else
612                 ProcessLauncher::setSkipExec(false);
613
614             ProcessLauncher::forkProcess();
615
616             if (ProcessLauncher::isParentProcess()) {
617                 Ewk_Context* ewkContext = ewk_context_new_with_injected_bundle_path(path);
618                 WKContextRef contextRef = ewkContext->wkContext();
619                 toImpl(contextRef)->ensureWebProcess();
620                 return ewkContext;
621             }
622             else if (ProcessLauncher::isChildProcess()) {
623                 ProcessLauncher::callWebProcessMain();
624                 exit(0);
625             }
626
627             ASSERT_NOT_REACHED();
628             return 0;
629         }
630     }
631 #endif
632
633 #if OS(TIZEN)
634     Ewk_Context* ewkContext = Ewk_Context::create(String::fromUTF8(path)).leakRef();
635     ewkContextInjectedBundleClientAttachClient(ewkContext);
636 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
637     const char* webProcessExecutablePath = getenv("WEB_PROCESS_EXECUTABLE_PATH");
638     if (webProcessExecutablePath) {
639         WKContextRef contextRef = ewkContext->wkContext();
640         toImpl(contextRef)->setWebProcessExecutablePath(String::fromUTF8(webProcessExecutablePath));
641     }
642
643     const char* pluginProcessExecutablePath = getenv("PLUGIN_PROCESS_EXECUTABLE_PATH");
644     if (pluginProcessExecutablePath) {
645         WKContextRef contextRef = ewkContext->wkContext();
646         toImpl(contextRef)->pluginInfoStore().setExecutablePath(String::fromUTF8(pluginProcessExecutablePath));
647     }
648 #endif
649     return ewkContext;
650 #else
651     return Ewk_Context::create(String::fromUTF8(path)).leakRef();
652 #endif
653 }
654
655 void ewk_context_delete(Ewk_Context* ewkContext)
656 {
657     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
658     if (ewkContext == ewk_context_default_get() && ewkContext->hasOneRef())
659         return;
660
661     delete ewkContext;
662 }
663
664 void ewk_context_proxy_uri_set(Ewk_Context* ewkContext, const char* proxy)
665 {
666     if (ewkContext && ewkContext->setProxyAddress(proxy)) {
667         WKRetainPtr<WKURLRef> proxyAddress(AdoptWK, WKURLCreateWithUTF8CString(proxy));
668
669         WKContextRef contextRef = ewkContext->wkContext();
670         toImpl(contextRef)->setProxy(toWTFString(proxyAddress.get()));
671     }
672 }
673
674 const char* ewk_context_proxy_uri_get(Ewk_Context* ewkContext)
675 {
676 #if ENABLE(TIZEN_WEBKIT2_PATCH_FOR_TC)
677     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
678 #endif
679     return ewkContext->proxyAddress();
680 }
681
682 void ewk_context_network_session_requests_cancel(Ewk_Context* ewkContext)
683 {
684     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
685
686     WKContextRef contextRef = ewkContext->wkContext();
687     toImpl(contextRef)->abortSession();
688 }
689
690 Eina_Bool ewk_context_notify_low_memory(Ewk_Context* ewkContext)
691 {
692     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
693
694     WKContextRef contextRef = ewkContext->wkContext();
695     toImpl(contextRef)->notifyLowMemory();
696     return true;
697 }
698
699 #if ENABLE(TIZEN_FILE_SYSTEM)
700 static void didGetLocalFileSystemOrigins(WKArrayRef origins, WKErrorRef error, void* context)
701 {
702     Eina_List* originList = 0;
703     for (size_t i = 0; i < WKArrayGetSize(origins); ++i) {
704         WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
705         Ewk_Security_Origin* origin = createSecurityOrigin(securityOriginRef);
706         originList = eina_list_append(originList, origin);
707     }
708
709     Ewk_Context_Callback_Context* locaFileSystemContext = static_cast<Ewk_Context_Callback_Context*>(context);
710     locaFileSystemContext->localFileSystemOriginsCallback(originList, locaFileSystemContext->userData);
711     delete locaFileSystemContext;
712 }
713 #endif
714
715 #if ENABLE(TIZEN_APPLICATION_CACHE)
716 static void didGetWebApplicationOrigins(WKArrayRef origins, WKErrorRef error, void* context)
717 {
718     TIZEN_LOGI("origin size(%d)", WKArrayGetSize(origins));
719     Eina_List* originList = 0;
720
721     for(size_t i = 0; i < WKArrayGetSize(origins); i++) {
722         WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
723         Ewk_Security_Origin* origin = createSecurityOrigin(securityOriginRef);
724         originList = eina_list_append(originList, origin);
725     }
726
727     Ewk_Context_Callback_Context* applicationCacheContext = static_cast<Ewk_Context_Callback_Context*>(context);
728     applicationCacheContext->webApplicationCacheOriginsCallback(originList, applicationCacheContext->userData);
729     delete applicationCacheContext;
730 }
731
732 static void didGetWebApplicationPath(WKStringRef path, WKErrorRef error, void* context)
733 {
734     Ewk_Context_Callback_Context* applicationCacheContext = static_cast<Ewk_Context_Callback_Context*>(context);
735
736     int length = WKStringGetMaximumUTF8CStringSize(path);
737     OwnArrayPtr<char> applicationCachePath = adoptArrayPtr(new char[length]);
738     WKStringGetUTF8CString(path, applicationCachePath.get(), length);
739
740     TIZEN_LOGI("path (%s)", applicationCachePath.get());
741     applicationCacheContext->webApplicationCachePathCallback(eina_stringshare_add(applicationCachePath.get()), applicationCacheContext->userData);
742     delete applicationCacheContext;
743 }
744
745 #if ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
746 static void didGetWebApplicationQuota(WKInt64Ref quota, WKErrorRef error, void* context)
747 {
748     Ewk_Context_Callback_Context* applicationCacheContext = static_cast<Ewk_Context_Callback_Context*>(context);
749     TIZEN_LOGI("quota (%d)", toImpl(quota)->value());
750     applicationCacheContext->webApplicationCacheQuotaCallback(toImpl(quota)->value(), applicationCacheContext->userData);
751     delete applicationCacheContext;
752 }
753
754 static void didGetWebApplicationUsageForOrigin(WKInt64Ref usage, WKErrorRef error, void* context)
755 {
756     Ewk_Context_Callback_Context* applicationCacheContext = static_cast<Ewk_Context_Callback_Context*>(context);
757     TIZEN_LOGI("usage (%d)", toImpl(usage)->value());
758     applicationCacheContext->webApplicationCacheUsageForOriginCallback(toImpl(usage)->value(), applicationCacheContext->userData);
759     delete applicationCacheContext;
760 }
761 #endif
762 #endif
763
764 #if ENABLE(TIZEN_SQL_DATABASE)
765 static void didGetWebDatabaseOrigins(WKArrayRef origins, WKErrorRef error, void* context)
766 {
767     TIZEN_LOGI("origin size(%d)", WKArrayGetSize(origins));
768     Eina_List* originList = 0;
769
770     for(size_t i = 0; i < WKArrayGetSize(origins); i++) {
771         WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
772         Ewk_Security_Origin* origin = createSecurityOrigin(securityOriginRef);
773         originList = eina_list_append(originList, origin);
774     }
775
776     Ewk_Context_Callback_Context* webDatabaseContext = static_cast<Ewk_Context_Callback_Context*>(context);
777     webDatabaseContext->webDatabaseOriginsCallback(originList, webDatabaseContext->userData);
778     delete webDatabaseContext;
779 }
780
781 static void didGetWebDatabaseQuota(WKUInt64Ref quota, WKErrorRef error, void* context)
782 {
783     Ewk_Context_Callback_Context* webDatabaseContext = static_cast<Ewk_Context_Callback_Context*>(context);
784     TIZEN_LOGI("quota (%d)", toImpl(quota)->value());
785     webDatabaseContext->webDatabaseQuotaCallback(toImpl(quota)->value(), webDatabaseContext->userData);
786     delete webDatabaseContext;
787 }
788
789 static void didGetWebDatabaseUsage(WKUInt64Ref usage, WKErrorRef error, void* context)
790 {
791     Ewk_Context_Callback_Context* webDatabaseContext = static_cast<Ewk_Context_Callback_Context*>(context);
792     TIZEN_LOGI("usage (%d)", toImpl(usage)->value());
793     webDatabaseContext->webDatabaseUsageCallback(toImpl(usage)->value(), webDatabaseContext->userData);
794     delete webDatabaseContext;
795 }
796
797 static void didGetWebDatabasePath(WKStringRef path, WKErrorRef error, void * context)
798 {
799     Ewk_Context_Callback_Context* webDatabaseContext = static_cast<Ewk_Context_Callback_Context*>(context);
800
801     int length = WKStringGetMaximumUTF8CStringSize(path);
802     OwnArrayPtr<char> databasePath = adoptArrayPtr(new char[length]);
803     WKStringGetUTF8CString(path, databasePath.get(), length);
804
805     TIZEN_LOGI("path (%s)", databasePath.get());
806     webDatabaseContext->webDatabasePathCallback(eina_stringshare_add(databasePath.get()), webDatabaseContext->userData);
807     delete webDatabaseContext;
808 }
809 #endif
810
811 #if ENABLE(TIZEN_WEB_STORAGE)
812 static void didGetWebStorageOrigins(WKArrayRef origins, WKErrorRef error, void* context)
813 {
814     TIZEN_LOGI("origin size(%d)", WKArrayGetSize(origins));
815     Eina_List* originList = 0;
816
817     for(size_t i = 0; i < WKArrayGetSize(origins); i++) {
818         WKSecurityOriginRef securityOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
819         Ewk_Security_Origin* origin = createSecurityOrigin(securityOriginRef);
820         originList = eina_list_append(originList, origin);
821     }
822
823     Ewk_Context_Callback_Context* webStorageContext = static_cast<Ewk_Context_Callback_Context*>(context);
824     webStorageContext->webStorageOriginsCallback(originList, webStorageContext->userData);
825     delete webStorageContext;
826 }
827
828 static void didGetWebStoragePath(WKStringRef path, WKErrorRef error, void * context)
829 {
830     Ewk_Context_Callback_Context* webStorageContext = static_cast<Ewk_Context_Callback_Context*>(context);
831
832     int length = WKStringGetMaximumUTF8CStringSize(path);
833     OwnArrayPtr<char> storagePath = adoptArrayPtr(new char[length]);
834     WKStringGetUTF8CString(path, storagePath.get(), length);
835
836     TIZEN_LOGI("path (%s)", storagePath.get());
837     webStorageContext->webStoragePathCallback(eina_stringshare_add(storagePath.get()), webStorageContext->userData);
838     delete webStorageContext;
839 }
840
841 #if ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
842 static void didGetWebStorageUsage(WKInt64Ref usage, WKErrorRef error, void* context)
843 {
844     Ewk_Context_Callback_Context* webStorageContext = static_cast<Ewk_Context_Callback_Context*>(context);
845
846     TIZEN_LOGI("usage (%s)", toImpl(usage)->value());
847     webStorageContext->webStorageUsageCallback(toImpl(usage)->value(), webStorageContext->userData);
848     delete webStorageContext;
849 }
850 #endif
851
852 #endif
853
854 Eina_Bool ewk_context_origins_free(Eina_List* originList)
855 {
856     EINA_SAFETY_ON_NULL_RETURN_VAL(originList, false);
857
858     void* currentOrigin;
859     EINA_LIST_FREE(originList, currentOrigin) {
860         Ewk_Security_Origin* origin = static_cast<Ewk_Security_Origin*>(currentOrigin);
861         deleteSecurityOrigin(origin);
862     }
863
864     return true;
865 }
866
867 Eina_Bool ewk_context_application_cache_delete_all(Ewk_Context* ewkContext)
868 {
869 #if ENABLE(TIZEN_APPLICATION_CACHE)
870     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
871
872     TIZEN_LOGI("ewkContext (%p)", ewkContext);
873     WKApplicationCacheManagerRef applicationCache = WKContextGetApplicationCacheManager(ewkContext->wkContext());
874     WKApplicationCacheManagerDeleteAllEntries(applicationCache);
875
876     return true;
877 #else
878     return false;
879 #endif
880 }
881
882 Eina_Bool ewk_context_application_cache_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
883 {
884 #if ENABLE(TIZEN_APPLICATION_CACHE)
885     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
886     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
887
888     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
889     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
890     WKRetainPtr<WKSecurityOriginRef> securityOriginRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
891     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
892     WKApplicationCacheManagerDeleteEntriesForOrigin(applicationCacheRef, securityOriginRef.get());
893
894     return true;
895 #else
896     return false;
897 #endif
898 }
899
900 Eina_Bool ewk_context_application_cache_origins_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Origins_Get_Callback callback, void *userData)
901 {
902 #if ENABLE(TIZEN_APPLICATION_CACHE)
903     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
904     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
905
906     TIZEN_LOGI("ewkContext (%p)", ewkContext);
907     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
908     context->webApplicationCacheOriginsCallback = callback;
909     context->userData = userData;
910
911     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
912     WKApplicationCacheManagerGetApplicationCacheOrigins(applicationCacheRef, context, didGetWebApplicationOrigins);
913
914     return true;
915 #else
916     return false;
917 #endif
918 }
919
920 Eina_Bool ewk_context_application_cache_path_set(Ewk_Context* ewkContext, const char* path)
921 {
922 #if ENABLE(TIZEN_APPLICATION_CACHE)
923     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
924     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
925
926     if (!path) {
927         TIZEN_LOGE("Path value is invalid");
928         return false;
929     }
930
931     TIZEN_LOGI("path (%s)", path);
932     WKRetainPtr<WKStringRef> applicationCachePathRef(AdoptWK, WKStringCreateWithUTF8CString(path));
933     WKContextSetApplicationCacheDirectory(ewkContext->wkContext(), applicationCachePathRef.get());
934
935     return true;
936 #else
937     return false;
938 #endif
939 }
940
941 Eina_Bool ewk_context_application_cache_path_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Path_Get_Callback callback, void* userData)
942 {
943 #if ENABLE(TIZEN_APPLICATION_CACHE)
944     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
945     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
946
947     TIZEN_LOGI("callback (%p)", callback);
948     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
949     context->webApplicationCachePathCallback= callback;
950     context->userData = userData;
951
952     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
953     WKApplicationCacheManagerGetApplicationCachePath(applicationCacheRef, context, didGetWebApplicationPath);
954     return true;
955 #else
956     return false;
957 #endif
958 }
959
960 Eina_Bool ewk_context_application_cache_quota_get(Ewk_Context* ewkContext, Ewk_Web_Application_Cache_Quota_Get_Callback callback, void* userData)
961 {
962 #if ENABLE(TIZEN_APPLICATION_CACHE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
963     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
964     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
965
966     TIZEN_LOGI("callback (%p)", callback);
967     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
968     context->webApplicationCacheQuotaCallback = callback;
969     context->userData = userData;
970
971     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
972     WKApplicationCacheManagerGetApplicationCacheQuota(applicationCacheRef, context, didGetWebApplicationQuota);
973
974     return true;
975 #else
976     return false;
977 #endif
978 }
979
980 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)
981 {
982 #if ENABLE(TIZEN_APPLICATION_CACHE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
983     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
984     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
985     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
986
987     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
988     context->webApplicationCacheUsageForOriginCallback = callback;
989     context->userData = userData;
990     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
991     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
992     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
993
994     WKApplicationCacheManagerRef applicationCache = WKContextGetApplicationCacheManager(ewkContext->wkContext());
995     WKApplicationCacheManagerGetApplicationCacheUsageForOrigin(applicationCache, context, originRef.get(), didGetWebApplicationUsageForOrigin);
996
997     return true;
998 #else
999     return false;
1000 #endif
1001 }
1002
1003 Eina_Bool ewk_context_application_cache_quota_set(Ewk_Context* ewkContext, int64_t quota)
1004 {
1005 #if ENABLE(TIZEN_APPLICATION_CACHE)
1006     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1007     if (!quota) {
1008         TIZEN_LOGE("Quota value is invalid");
1009         return false;
1010     }
1011
1012     TIZEN_LOGI("quota (%d)", quota);
1013     WKApplicationCacheManagerRef applicationCacheRef = WKContextGetApplicationCacheManager(ewkContext->wkContext());
1014     WKApplicationCacheManagerSetApplicationCacheQuota(applicationCacheRef, quota);
1015
1016     return true;
1017 #else
1018     return false;
1019 #endif
1020 }
1021
1022 Eina_Bool ewk_context_application_cache_quota_for_origin_set(Ewk_Context* ewkContext, const Ewk_Security_Origin* origin, int64_t quota)
1023 {
1024 #if ENABLE(TIZEN_APPLICATION_CACHE)
1025     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1026     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1027     if (!quota) {
1028         TIZEN_LOGE("Quota value is invalid");
1029         return false;
1030     }
1031
1032     TIZEN_LOGI("quota (%d)", quota);
1033     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1034     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1035     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1036
1037     WKApplicationCacheManagerRef applicationCache = WKContextGetApplicationCacheManager(ewkContext->wkContext());
1038     WKApplicationCacheManagerSetApplicationCacheQuotaForOrigin(applicationCache, originRef.get(), quota);
1039
1040     return true;
1041 #else
1042     return false;
1043 #endif
1044 }
1045
1046
1047 Eina_Bool ewk_context_icon_database_path_set(Ewk_Context* ewkContext, const char* path)
1048 {
1049     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1050     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1051
1052     WKRetainPtr<WKStringRef> databasePath(AdoptWK, WKStringCreateWithUTF8CString(path));
1053     WKContextSetIconDatabasePath(ewkContext->wkContext(), databasePath.get());
1054
1055     return true;
1056 }
1057
1058 Evas_Object* ewk_context_icon_database_icon_object_add(Ewk_Context* ewkContext, const char* uri, Evas* canvas)
1059 {
1060     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
1061     EINA_SAFETY_ON_NULL_RETURN_VAL(uri, 0);
1062     EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
1063
1064     WKIconDatabaseRef iconDatabase = WKContextGetIconDatabase(ewkContext->wkContext());
1065     WKRetainPtr<WKURLRef> urlString(AdoptWK, WKURLCreateWithUTF8CString(uri));
1066
1067     return WKIconDatabaseTryGetImageForURL(iconDatabase, canvas, urlString.get());
1068 }
1069
1070 void ewk_context_icon_database_delete_all(Ewk_Context* ewkContext)
1071 {
1072     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1073
1074     WKIconDatabaseRef iconDatabase = WKContextGetIconDatabase(ewkContext->wkContext());
1075     WKIconDatabaseRemoveAllIcons(iconDatabase);
1076 }
1077
1078 Eina_Bool ewk_context_local_file_system_path_set(Ewk_Context* ewkContext, const char* path)
1079 {
1080 #if ENABLE(TIZEN_FILE_SYSTEM)
1081     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1082     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1083
1084     TIZEN_LOGI("path (%s)", path);
1085     WKRetainPtr<WKStringRef> localFileSystemPathRef(AdoptWK, WKStringCreateWithUTF8CString(path));
1086     WKContextSetLocalFileSystemDirectory(ewkContext->wkContext(), localFileSystemPathRef.get());
1087
1088     return true;
1089 #else
1090     return false;
1091 #endif
1092 }
1093
1094 Eina_Bool ewk_context_local_file_system_all_delete(Ewk_Context* ewkContext)
1095 {
1096 #if ENABLE(TIZEN_FILE_SYSTEM)
1097     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1098
1099     TIZEN_LOGI("ewkContex (%p)", ewkContext);
1100     WKLocalFileSystemManagerRef localFileSystemManager = WKContextGetLocalFileSystemManager(ewkContext->wkContext());
1101     WKLocalFileSystemManagerDeleteAllLocalFileSystem(localFileSystemManager);
1102
1103     return true;
1104 #else
1105     UNUSED_PARAM(ewkContext);
1106
1107     return false;
1108 #endif
1109 }
1110
1111 Eina_Bool ewk_context_local_file_system_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
1112 {
1113 #if ENABLE(TIZEN_FILE_SYSTEM)
1114     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1115     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1116
1117     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1118     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1119     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1120     WKLocalFileSystemManagerRef localFileSystemManager = WKContextGetLocalFileSystemManager(ewkContext->wkContext());
1121
1122     WKLocalFileSystemManagerDeleteLocalFileSystem(localFileSystemManager, originRef.get());
1123
1124     return true;
1125 #else
1126     UNUSED_PARAM(ewkContext);
1127     UNUSED_PARAM(origin);
1128
1129     return false;
1130 #endif
1131 }
1132
1133 Eina_Bool ewk_context_local_file_system_origins_get(const Ewk_Context* ewkContext, Ewk_Local_File_System_Origins_Get_Callback callback, void* userData)
1134 {
1135 #if ENABLE(TIZEN_FILE_SYSTEM)
1136     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1137     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1138
1139     TIZEN_LOGI("callback (%p)", callback);
1140     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1141     context->localFileSystemOriginsCallback= callback;
1142     context->userData = userData;
1143     WKLocalFileSystemManagerRef localFileSystemManager = WKContextGetLocalFileSystemManager(const_cast<Ewk_Context*>(ewkContext)->wkContext());
1144
1145     WKLocalFileSystemManagerGetLocalFileSystemOrigins(localFileSystemManager, context, didGetLocalFileSystemOrigins);
1146
1147     return true;
1148 #else
1149     UNUSED_PARAM(ewkContext);
1150     UNUSED_PARAM(callback);
1151     UNUSED_PARAM(userData);
1152
1153     return false;
1154 #endif
1155 }
1156
1157 Ewk_Security_Origin* ewk_context_web_database_exceeded_quota_security_origin_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1158 {
1159 #if ENABLE(TIZEN_SQL_DATABASE)
1160     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1161
1162     return exceededQuota->origin;
1163 #else
1164     return 0;
1165 #endif
1166 }
1167
1168 const char* ewk_context_web_database_exceeded_quota_database_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("name (%s)", exceededQuota->databaseName);
1174     return exceededQuota->databaseName;
1175 #else
1176     return 0;
1177 #endif
1178 }
1179
1180 const char* ewk_context_web_database_exceeded_quota_display_name_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("displayName (%s)", exceededQuota->displayName);
1186     return exceededQuota->displayName;
1187 #else
1188     return 0;
1189 #endif
1190 }
1191
1192 unsigned long long ewk_context_web_database_exceeded_quota_current_quota_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("quota (%d)", exceededQuota->currentQuota);
1198     return exceededQuota->currentQuota;
1199 #else
1200     return 0;
1201 #endif
1202 }
1203
1204 unsigned long long ewk_context_web_database_exceeded_quota_current_origin_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("currentOriginUsage (%d)", exceededQuota->currentOriginUsage);
1210     return exceededQuota->currentOriginUsage;
1211 #else
1212     return 0;
1213 #endif
1214 }
1215
1216 unsigned long long ewk_context_web_database_exceeded_quota_current_database_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("currentDatabaseUsage (%d)", exceededQuota->currentDatabaseUsage);
1222     return exceededQuota->currentDatabaseUsage;
1223 #else
1224     return 0;
1225 #endif
1226 }
1227
1228 unsigned long long ewk_context_web_database_exceeded_quota_expected_usage_get(Ewk_Context_Exceeded_Quota* exceededQuota)
1229 {
1230 #if ENABLE(TIZEN_SQL_DATABASE)
1231     EINA_SAFETY_ON_NULL_RETURN_VAL(exceededQuota, 0);
1232
1233     TIZEN_LOGI("expectedUsage (%d)", exceededQuota->expectedUsage);
1234     return exceededQuota->expectedUsage;
1235 #else
1236     return 0;
1237 #endif
1238 }
1239
1240 void ewk_context_web_database_exceeded_quota_new_quota_set(Ewk_Context_Exceeded_Quota* exceededQuota, unsigned long long quota)
1241 {
1242 #if ENABLE(TIZEN_SQL_DATABASE)
1243     EINA_SAFETY_ON_NULL_RETURN(exceededQuota);
1244
1245     TIZEN_LOGI("quota (%d)", quota);
1246     exceededQuota->newQuota = quota;
1247 #endif
1248 }
1249
1250 Eina_Bool ewk_context_web_database_delete_all(Ewk_Context* ewkContext)
1251 {
1252 #if ENABLE(TIZEN_SQL_DATABASE)
1253     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1254
1255     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1256     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1257     WKDatabaseManagerDeleteAllDatabases(databaseManager);
1258
1259     return true;
1260 #else
1261     return false;
1262 #endif
1263 }
1264
1265 Eina_Bool ewk_context_web_database_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
1266 {
1267 #if ENABLE(TIZEN_SQL_DATABASE)
1268     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1269     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1270
1271     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1272     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1273     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1274     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1275     WKDatabaseManagerDeleteDatabasesForOrigin(databaseManager, originRef.get());
1276
1277     return true;
1278 #else
1279     return false;
1280 #endif
1281 }
1282
1283 Eina_Bool ewk_context_web_database_origins_get(Ewk_Context* ewkContext, Ewk_Web_Database_Origins_Get_Callback callback, void* userData)
1284 {
1285 #if ENABLE(TIZEN_SQL_DATABASE)
1286     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1287     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1288
1289     TIZEN_LOGI("callback (%p)", callback);
1290     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1291     context->webDatabaseOriginsCallback = callback;
1292     context->userData = userData;
1293
1294     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1295     WKDatabaseManagerGetDatabaseOrigins(databaseManager, context, didGetWebDatabaseOrigins);
1296
1297     return true;
1298 #else
1299     return false;
1300 #endif
1301 }
1302
1303 Eina_Bool ewk_context_web_database_path_set(Ewk_Context* ewkContext, const char* path)
1304 {
1305 #if ENABLE(TIZEN_SQL_DATABASE)
1306     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1307     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1308
1309     TIZEN_LOGI("path (%s)", path);
1310     WKRetainPtr<WKStringRef> databasePath(AdoptWK, WKStringCreateWithUTF8CString(path));
1311     WKContextSetDatabaseDirectory(ewkContext->wkContext(), databasePath.get());
1312
1313     return true;
1314 #else
1315     return false;
1316 #endif
1317 }
1318
1319 Eina_Bool ewk_context_web_database_path_get(Ewk_Context* ewkContext, Ewk_Web_Database_Path_Get_Callback callback, void* userData)
1320 {
1321 #if ENABLE(TIZEN_WEB_STORAGE)
1322     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1323     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1324
1325     TIZEN_LOGI("callback (%p)", callback);
1326     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1327     context->webDatabasePathCallback= callback;
1328     context->userData = userData;
1329
1330     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1331     WKDatabaseManagerGetDatabasePath(databaseManager, context, didGetWebDatabasePath);
1332     return true;
1333 #else
1334     return false;
1335 #endif
1336 }
1337 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)
1338 {
1339 #if ENABLE(TIZEN_SQL_DATABASE)
1340     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1341     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1342     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1343
1344     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1345     context->webDatabaseQuotaCallback = callback;
1346     context->userData = userData;
1347
1348     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1349     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1350     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1351     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1352     WKDatabaseManagerGetQuotaForOrigin(databaseManager, context, didGetWebDatabaseQuota, originRef.get());
1353
1354     return true;
1355 #else
1356     return false;
1357 #endif
1358 }
1359
1360 Eina_Bool ewk_context_web_database_default_quota_set(Ewk_Context* ewkContext, uint64_t quota)
1361 {
1362 #if ENABLE(TIZEN_SQL_DATABASE)
1363     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1364
1365     TIZEN_LOGI("quota (%d)", quota);
1366     ewkContext->setDefaultDatabaseQuota(quota);
1367
1368     return true;
1369 #else
1370     return false;
1371 #endif
1372 }
1373
1374 Eina_Bool ewk_context_web_database_quota_for_origin_set(Ewk_Context* ewkContext, Ewk_Security_Origin* origin, uint64_t quota)
1375 {
1376 #if ENABLE(TIZEN_SQL_DATABASE)
1377     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1378     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1379
1380     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1381     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1382     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1383     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1384     WKDatabaseManagerSetQuotaForOrigin(databaseManager, originRef.get(), quota);
1385
1386     return true;
1387 #else
1388     return false;
1389 #endif
1390 }
1391
1392 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)
1393 {
1394 #if ENABLE(TIZEN_SQL_DATABASE)
1395     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1396     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1397     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1398
1399     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1400     context->webDatabaseQuotaCallback = callback;
1401     context->userData = userData;
1402
1403     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1404     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1405     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1406     WKDatabaseManagerRef databaseManager = WKContextGetDatabaseManager(ewkContext->wkContext());
1407     WKDatabaseManagerGetUsageForOrigin(databaseManager, context, didGetWebDatabaseUsage, originRef.get());
1408
1409     return true;
1410 #else
1411     return false;
1412 #endif
1413 }
1414
1415 Eina_Bool ewk_context_web_indexed_database_delete_all(Ewk_Context* ewkContext)
1416 {
1417 #if ENABLE(TIZEN_INDEXED_DATABASE)
1418     WKContextDeleteIndexedDatabaseAll(ewkContext->wkContext());
1419
1420     return true;
1421 #else
1422     return false;
1423 #endif
1424 }
1425
1426 Eina_Bool ewk_context_web_storage_delete_all(Ewk_Context* ewkContext)
1427 {
1428 #if ENABLE(TIZEN_WEB_STORAGE)
1429     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1430
1431     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1432     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1433     WKKeyValueStorageManagerDeleteAllEntries(storageManager);
1434
1435     return true;
1436 #else
1437     return false;
1438 #endif
1439 }
1440
1441 Eina_Bool ewk_context_web_storage_origin_delete(Ewk_Context* ewkContext, Ewk_Security_Origin* origin)
1442 {
1443 #if ENABLE(TIZEN_WEB_STORAGE)
1444     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1445     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1446
1447     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1448     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1449     WKRetainPtr<WKSecurityOriginRef> securityOriginRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1450     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1451     WKKeyValueStorageManagerDeleteEntriesForOrigin(storageManager, securityOriginRef.get());
1452
1453     return true;
1454 #else
1455     return false;
1456 #endif
1457 }
1458
1459 Eina_Bool ewk_context_web_storage_origins_get(Ewk_Context* ewkContext, Ewk_Web_Storage_Origins_Get_Callback callback, void* userData)
1460 {
1461 #if ENABLE(TIZEN_WEB_STORAGE)
1462     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1463     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1464
1465     TIZEN_LOGI("callback (%p)", callback);
1466     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1467     context->webStorageOriginsCallback = callback;
1468     context->userData = userData;
1469
1470     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1471     WKKeyValueStorageManagerGetKeyValueStorageOrigins(storageManager, context, didGetWebStorageOrigins);
1472
1473     return true;
1474 #else
1475     return false;
1476 #endif
1477 }
1478
1479 Eina_Bool ewk_context_web_storage_path_set(Ewk_Context* ewkContext, const char* path)
1480 {
1481 #if ENABLE(TIZEN_WEB_STORAGE)
1482     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1483     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1484
1485     TIZEN_LOGI("path (%s)", path);
1486     WKRetainPtr<WKStringRef> webStoragePath(AdoptWK, WKStringCreateWithUTF8CString(path));
1487     WKContextSetLocalStorageDirectory(ewkContext->wkContext(), webStoragePath.get());
1488
1489     return true;
1490 #else
1491     return false;
1492 #endif
1493 }
1494
1495 Eina_Bool ewk_context_web_storage_path_get(Ewk_Context* ewkContext, Ewk_Web_Storage_Path_Get_Callback callback, void* userData)
1496 {
1497 #if ENABLE(TIZEN_WEB_STORAGE)
1498     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1499     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1500
1501     TIZEN_LOGI("callback (%p)", callback);
1502     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1503     context->webStoragePathCallback= callback;
1504     context->userData = userData;
1505
1506     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1507     WKKeyValueStorageManagerGetKeyValueStoragePath(storageManager, context, didGetWebStoragePath);
1508     return true;
1509 #else
1510     return false;
1511 #endif
1512 }
1513 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)
1514 {
1515 #if ENABLE(TIZEN_WEB_STORAGE) && ENABLE(TIZEN_WEBKIT2_NUMBER_TYPE_SUPPORT)
1516     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1517     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1518     EINA_SAFETY_ON_NULL_RETURN_VAL(origin, false);
1519
1520     Ewk_Context_Callback_Context* context = new Ewk_Context_Callback_Context;
1521     context->webStorageUsageCallback = callback;
1522     context->userData = userData;
1523     WKRetainPtr<WKStringRef> protocolRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_protocol_get(origin)));
1524     WKRetainPtr<WKStringRef> hostRef(AdoptWK, WKStringCreateWithUTF8CString(ewk_security_origin_host_get(origin)));
1525     WKRetainPtr<WKSecurityOriginRef> originRef(AdoptWK, WKSecurityOriginCreate(protocolRef.get(), hostRef.get(), ewk_security_origin_port_get(origin)));
1526
1527     WKKeyValueStorageManagerRef storageManager = WKContextGetKeyValueStorageManager(ewkContext->wkContext());
1528     WKKeyValueStorageManagerGetKeyValueStorageUsageForOrigin(storageManager, context, didGetWebStorageUsage, originRef.get());
1529
1530     return true;
1531 #else
1532     return false;
1533 #endif
1534 }
1535
1536 //#if ENABLE(TIZEN_SOUP_COOKIE_CACHE_FOR_WEBKIT2)
1537 Eina_Bool ewk_context_soup_data_directory_set(Ewk_Context* ewkContext, const char* path)
1538 {
1539     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1540     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1541
1542     WKRetainPtr<WKStringRef> soupDataDirectory(AdoptWK, WKStringCreateWithUTF8CString(path));
1543     WKContextSetSoupDataDirectory(ewkContext->wkContext(), soupDataDirectory.get());
1544     return true;
1545 }
1546 //#endif
1547
1548 COMPILE_ASSERT_MATCHING_ENUM(EWK_CACHE_MODEL_DOCUMENT_VIEWER, kWKCacheModelDocumentViewer);
1549 COMPILE_ASSERT_MATCHING_ENUM(EWK_CACHE_MODEL_DOCUMENT_BROWSER, kWKCacheModelDocumentBrowser);
1550 COMPILE_ASSERT_MATCHING_ENUM(EWK_CACHE_MODEL_PRIMARY_WEBBROWSER, kWKCacheModelPrimaryWebBrowser);
1551
1552 Eina_Bool ewk_context_cache_model_set(Ewk_Context* ewkContext, Ewk_Cache_Model cacheModel)
1553 {
1554     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1555
1556     ewkContext->setCacheModel(cacheModel);
1557
1558     return true;
1559 }
1560
1561 Ewk_Cache_Model ewk_context_cache_model_get(Ewk_Context* ewkContext)
1562 {
1563     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
1564
1565     return ewkContext->cacheModel();
1566 }
1567
1568 Eina_Bool ewk_context_cache_disabled_set(Ewk_Context* ewkContext, Eina_Bool cacheDisabled)
1569 {
1570 #if ENABLE(TIZEN_CACHE_CONTROL)
1571     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1572     WKContextSetCacheDisabled(ewkContext->wkContext(), cacheDisabled);
1573 #endif
1574
1575     return true;
1576 }
1577
1578 Eina_Bool ewk_context_cache_disabled_get(Ewk_Context* ewkContext)
1579 {
1580 #if ENABLE(TIZEN_CACHE_CONTROL)
1581     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1582     return WKContextGetCacheDisabled(ewkContext->wkContext());
1583 #else
1584     return false;
1585 #endif
1586 }
1587
1588 Eina_Bool ewk_context_certificate_file_set(Ewk_Context* context, const char* certificateFile)
1589 {
1590     EINA_SAFETY_ON_NULL_RETURN_VAL(context, false);
1591     EINA_SAFETY_ON_NULL_RETURN_VAL(certificateFile, false);
1592 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
1593     if (!context->setCertificateFile(certificateFile))
1594         return true;
1595
1596     if (fileExists(WTF::String::fromUTF8(certificateFile))) {
1597         long long fileSize = -1;
1598         getFileSize(WTF::String::fromUTF8(certificateFile), fileSize);
1599         TIZEN_LOGE("[Network] ewk_context_certificate_file_set certificateFile fileSize [%lld]\n", fileSize);
1600     } else
1601         TIZEN_LOGE("[Network] ewk_context_certificate_file_set certificateFile does not exist!\n");
1602
1603     WKRetainPtr<WKStringRef> certificateFileRef(AdoptWK, WKStringCreateWithUTF8CString(certificateFile));
1604     WKContextSetCertificateFile(context->wkContext(), certificateFileRef.get());
1605     return true;
1606 #else
1607     UNUSED_PARAM(context);
1608     UNUSED_PARAM(certificateFile);
1609     return false;
1610 #endif
1611 }
1612
1613 const char* ewk_context_certificate_file_get(const Ewk_Context* context)
1614 {
1615     EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
1616 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
1617     return context->certificateFile();
1618 #else
1619     UNUSED_PARAM(context);
1620     return 0;
1621 #endif
1622 }
1623
1624 Eina_Bool ewk_context_cache_clear(Ewk_Context* ewkContext)
1625 {
1626     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1627     WKResourceCacheManagerRef cacheManager = WKContextGetResourceCacheManager(ewkContext->wkContext());
1628 #if ENABLE(TIZEN_EWK_CONTEXT_CACHE_MANAGER_NULL_CHECK_WORKAROUND)
1629     if (!cacheManager)
1630         return false;
1631 #endif
1632     WKResourceCacheManagerClearCacheForAllOrigins(cacheManager, WKResourceCachesToClearAll);
1633
1634     return true;
1635 }
1636
1637 void ewk_context_message_post_to_injected_bundle(Ewk_Context* ewkContext, const char* name, const char* body)
1638 {
1639     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1640     EINA_SAFETY_ON_NULL_RETURN(name);
1641     EINA_SAFETY_ON_NULL_RETURN(body);
1642
1643     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString(name));
1644     WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithUTF8CString(body));
1645     WKContextPostMessageToInjectedBundle(ewkContext->wkContext(), messageName.get(), messageBody.get());
1646 }
1647
1648 void ewk_context_message_from_injected_bundle_callback_set(Ewk_Context* ewkContext, Ewk_Context_Message_From_Injected_Bundle_Callback callback, void* userData)
1649 {
1650     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1651
1652     ewkContext->setMessageFromInjectedBundleCallback(callback, userData);
1653 }
1654
1655 void ewk_context_did_start_download_callback_set(Ewk_Context* ewkContext, Ewk_Context_Did_Start_Download_Callback callback, void* userData)
1656 {
1657     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1658
1659     ewkContext->setDidStartDownloadCallback(callback, userData);
1660 }
1661
1662 #if ENABLE(MEMORY_SAMPLER)
1663 void ewk_context_memory_sampler_start(Ewk_Context* ewkContext, double timerInterval)
1664 {
1665     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1666     WKRetainPtr<WKDoubleRef> interval(AdoptWK, WKDoubleCreate(timerInterval));
1667     WKContextStartMemorySampler(ewkContext->wkContext(), interval.get());
1668 }
1669
1670 void ewk_context_memory_sampler_stop(Ewk_Context* ewkContext)
1671 {
1672     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1673     WKContextStopMemorySampler(ewkContext->wkContext());
1674 }
1675 #endif
1676
1677 Eina_Bool ewk_context_additional_plugin_path_set(Ewk_Context* ewkContext, const char* path)
1678 {
1679 #if ENABLE(TIZEN_SUPPORT_PLUGINS)
1680     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1681     EINA_SAFETY_ON_NULL_RETURN_VAL(path, false);
1682
1683     WKRetainPtr<WKStringRef> pluginPath(AdoptWK, WKStringCreateWithUTF8CString(path));
1684     WKContextSetAdditionalPluginsDirectory(ewkContext->wkContext(), pluginPath.get());
1685
1686     return true;
1687 #else
1688     return false;
1689 #endif
1690 }
1691
1692 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
1693 void ewk_context_memory_saving_mode_set(Ewk_Context* ewkContext, Eina_Bool mode)
1694 {
1695     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1696
1697     WKContextRef contextRef = ewkContext->wkContext();
1698     toImpl(contextRef)->setMemorySavingMode(mode);
1699 }
1700 #endif
1701
1702 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
1703 void ewk_context_form_password_data_clear(Ewk_Context* ewkContext)
1704 {
1705     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1706     ewkContext->clearPasswordFormData();
1707 }
1708
1709 void ewk_context_form_candidate_data_clear(Ewk_Context* ewkContext)
1710 {
1711     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1712     ewkContext->clearCandidateFormData();
1713 }
1714 #endif
1715 #endif // #if OS(TIZEN)
1716
1717 Eina_Bool ewk_context_url_scheme_register(Ewk_Context* ewkContext, const char* scheme, Ewk_Url_Scheme_Request_Cb callback, void* userData)
1718 {
1719     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1720     EINA_SAFETY_ON_NULL_RETURN_VAL(scheme, false);
1721     EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
1722
1723     ewkContext->requestManager()->registerURLSchemeHandler(String::fromUTF8(scheme), callback, userData);
1724
1725     return true;
1726 }
1727
1728 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)
1729 {
1730     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1731
1732     TIZEN_LOGI("vibrate (%p)", vibrate);
1733 #if ENABLE(VIBRATION)
1734     ewkContext->vibrationProvider()->setVibrationClientCallbacks(vibrate, cancel, data);
1735 #endif
1736 }
1737
1738 Eina_Bool ewk_context_tizen_extensible_api_set(Ewk_Context* ewkContext,  Ewk_Extensible_API extensibleAPI, Eina_Bool enable)
1739 {
1740 #if ENABLE(TIZEN_EXTENSIBLE_API)
1741     EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false);
1742
1743     TIZEN_LOGI("extensibleAPI (%d) enable (%d)", extensibleAPI, enable);
1744     WKContextSetTizenExtensibleAPI(ewkContext->wkContext(), static_cast<WKTizenExtensibleAPI>(extensibleAPI), enable);
1745
1746     return true;
1747 #else
1748     UNUSED_PARAM(ewkContext);
1749     UNUSED_PARAM(extensibleAPI);
1750     UNUSED_PARAM(enable);
1751
1752     return false;
1753 #endif
1754 }
1755
1756 void ewk_context_storage_path_reset(Ewk_Context* ewkContext)
1757 {
1758 #if ENABLE(TIZEN_RESET_PATH)
1759     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1760
1761     TIZEN_LOGI("ewkContext (%p)", ewkContext);
1762     WKContextResetStoragePath(ewkContext->wkContext());
1763 #else
1764     UNUSED_PARAM(ewkContext);
1765 #endif
1766 }
1767
1768 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)
1769 {
1770     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1771
1772     ewkContext->historyClient()->setCallbacks(navigate, clientRedirect, serverRedirect, titleUpdate, populateVisitedLinks, data);
1773 }
1774
1775 void ewk_context_visited_link_add(Ewk_Context* ewkContext, const char* visitedURL)
1776 {
1777     EINA_SAFETY_ON_NULL_RETURN(ewkContext);
1778     EINA_SAFETY_ON_NULL_RETURN(visitedURL);
1779
1780     ewkContext->addVisitedLink(visitedURL);
1781 }