1 // Copyright 2013-2015 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ewk_context.h"
7 // TODO: remove dependency
8 #include <../src/base/memory/ref_counted.h>
9 #include <../impl/browser/vibration/vibration_provider_client.h>
10 #include <../impl/browser_context_efl.h>
11 #include <../impl/http_user_agent_settings_efl.h>
12 #include <../impl/API/ewk_cookie_manager_private.h>
13 #include <../impl/API/ewk_context_form_autofill_profile_private.h>
15 #include <tizen_webview/public/tw_security_origin.h>
16 #include <tizen_webview/public/tw_web_context.h>
17 #include <tizen_webview/public/tw_url.h>
19 #include "public/ewk_security_origin.h"
20 #include "private/ewk_context_private.h"
21 #include "private/ewk_private.h"
22 #include "private/ewk_security_origin_private.h"
23 #include "private/chromium_glue.h"
24 #include "private/ewk_favicon_database_private.h"
27 using tizen_webview::WebContext;
29 Ewk_Context *ewk_context_ref(Ewk_Context *context)
31 EINA_SAFETY_ON_NULL_RETURN_VAL(context, NULL);
36 void ewk_context_unref(Ewk_Context *context)
38 EINA_SAFETY_ON_NULL_RETURN(context);
42 Ewk_Cookie_Manager* ewk_context_cookie_manager_get(const Ewk_Context* context)
44 EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
45 return context->ewkCookieManager();
48 Ewk_Context* ewk_context_default_get()
50 return static_cast<Ewk_Context*>(WebContext::DefaultContext());
53 Ewk_Context* ewk_context_new()
55 return static_cast<Ewk_Context*>(WebContext::Create());
58 Ewk_Context *ewk_context_new_with_injected_bundle_path(const char *path)
60 //with chromium engine this API not used.
61 //returning default context
66 void ewk_context_delete(Ewk_Context* context)
72 void ewk_context_proxy_uri_set(Ewk_Context* context, const char* proxy)
75 EINA_SAFETY_ON_NULL_RETURN(context);
76 EINA_SAFETY_ON_NULL_RETURN(proxy);
77 if (0 != strcmp(proxy,""))
78 context->SetProxyUri(proxy);
81 const char* ewk_context_proxy_uri_get(Ewk_Context* context)
83 EINA_SAFETY_ON_NULL_RETURN_VAL(context,0);
84 return context->GetProxyUri();
87 Eina_Bool ewk_context_notify_low_memory(Ewk_Context* context)
89 EINA_SAFETY_ON_NULL_RETURN_VAL(context, false);
90 context->NotifyLowMemory();
94 Eina_Bool ewk_context_origins_free(Eina_List* origins)
96 EINA_SAFETY_ON_NULL_RETURN_VAL(origins, false);
99 EINA_LIST_FREE(origins, current_origin) {
100 Ewk_Security_Origin* origin = static_cast<Ewk_Security_Origin*>(current_origin);
106 Eina_Bool ewk_context_application_cache_delete_all(Ewk_Context* context)
108 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
109 context->DeleteAllApplicationCache();
113 Eina_Bool ewk_context_application_cache_delete(Ewk_Context* context, Ewk_Security_Origin* origin)
115 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
116 EINA_SAFETY_ON_NULL_RETURN_VAL(origin, EINA_FALSE);
117 context->DeleteApplicationCacheForSite(origin->GetURL());
121 Eina_Bool ewk_context_application_cache_origins_get(Ewk_Context* context, Ewk_Web_Application_Cache_Origins_Get_Callback callback, void* user_data)
123 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
124 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
126 context->GetAllOriginsWithApplicationCache(callback, user_data);
130 Eina_Bool ewk_context_application_cache_usage_for_origin_get(Ewk_Context* context, const Ewk_Security_Origin* origin, Ewk_Web_Application_Cache_Usage_For_Origin_Get_Callback callback, void* user_data)
132 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
133 EINA_SAFETY_ON_NULL_RETURN_VAL(origin, EINA_FALSE);
134 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
135 context->GetApplicationCacheUsage(origin->GetURL(), callback, user_data);
139 Eina_Bool ewk_context_application_cache_quota_for_origin_set(Ewk_Context* context, const Ewk_Security_Origin* origin, int64_t quota)
141 NOTIMPLEMENTED() << "Chromium does not support quota management for individual features.";
145 Eina_Bool ewk_context_icon_database_path_set(Ewk_Context* context, const char* path)
147 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
148 return context->SetFaviconDatabasePath(path) ? EINA_TRUE : EINA_FALSE;
151 Evas_Object* ewk_context_icon_database_icon_object_add(Ewk_Context* context, const char* uri, Evas* canvas)
153 EINA_SAFETY_ON_NULL_RETURN_VAL(uri, NULL);
154 EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, NULL);
155 EINA_SAFETY_ON_NULL_RETURN_VAL(context, NULL);
156 return context->AddFaviconObject(uri, canvas);
159 Eina_Bool ewk_context_local_file_system_all_delete(Ewk_Context *context)
161 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
162 context->FileSystemDelete(tizen_webview::URL());
166 Eina_Bool ewk_context_local_file_system_delete(Ewk_Context *context, Ewk_Security_Origin *origin)
168 EINA_SAFETY_ON_NULL_RETURN_VAL(origin, EINA_FALSE);
169 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
170 context->FileSystemDelete(tizen_webview::URL(ewk_security_origin_host_get(origin)));
174 Eina_Bool ewk_context_local_file_system_origins_get(const Ewk_Context *context,
175 Ewk_Local_File_System_Origins_Get_Callback callback,
178 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
179 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
180 context->GetAllOriginsWithFileSystem(callback, user_data);
184 Eina_Bool ewk_context_web_database_delete_all(Ewk_Context* context)
186 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
187 context->WebDBDelete(tizen_webview::URL());
191 Eina_Bool ewk_context_web_database_delete(Ewk_Context* context, Ewk_Security_Origin* origin)
193 EINA_SAFETY_ON_NULL_RETURN_VAL(origin, EINA_FALSE);
194 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
195 context->WebDBDelete(tizen_webview::URL(ewk_security_origin_host_get(origin)));
199 Eina_Bool ewk_context_web_database_origins_get(Ewk_Context* context,
200 Ewk_Web_Database_Origins_Get_Callback callback,
203 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
204 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
205 context->GetAllOriginsWithWebDB(callback, user_data);
209 Eina_Bool ewk_context_web_database_quota_for_origin_get(Ewk_Context* context, Ewk_Web_Database_Quota_Get_Callback callback, void* userData, Ewk_Security_Origin* origin)
211 LOG_EWK_API_MOCKUP();
215 Eina_Bool ewk_context_web_database_quota_for_origin_set(Ewk_Context* context, Ewk_Security_Origin* origin, uint64_t quota)
217 LOG_EWK_API_MOCKUP();
221 Eina_Bool ewk_context_web_indexed_database_delete_all(Ewk_Context* context)
223 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
224 context->IndexedDBDelete();
228 Eina_Bool ewk_context_web_storage_delete_all(Ewk_Context* context)
230 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
231 context->WebStorageDelete();
235 Eina_Bool ewk_context_web_storage_origin_delete(Ewk_Context* context, Ewk_Security_Origin* origin)
237 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
238 EINA_SAFETY_ON_NULL_RETURN_VAL(origin, EINA_FALSE);
240 context->WebStorageDelete(origin->GetURL());
244 Eina_Bool ewk_context_web_storage_origins_get(Ewk_Context* context, Ewk_Web_Storage_Origins_Get_Callback callback, void* user_data)
246 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EINA_FALSE);
247 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
249 context->WebStorageOriginsAllGet(callback, user_data);
253 Eina_Bool ewk_context_web_storage_path_set(Ewk_Context* /*context*/, const char* /*path*/)
255 //With chromium engine no separate path for web storage supported.
256 //This API not implemented
261 Eina_Bool ewk_context_web_storage_usage_for_origin_get(Ewk_Context* context, Ewk_Security_Origin* origin, Ewk_Web_Storage_Usage_Get_Callback callback, void* userData)
263 LOG_EWK_API_MOCKUP();
267 Eina_Bool ewk_context_soup_data_directory_set(Ewk_Context* /*context*/, const char* /*path*/)
269 //chomium engine does not use libsoup hence this API will not be implemented
274 Eina_Bool ewk_context_cache_model_set(Ewk_Context* context, Ewk_Cache_Model model)
276 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
277 context->SetCacheModel(chromium_glue::to(model));
281 Ewk_Cache_Model ewk_context_cache_model_get(Ewk_Context* context)
283 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EWK_CACHE_MODEL_DOCUMENT_VIEWER);
284 return chromium_glue::from(context->GetCacheModel());
287 Eina_Bool ewk_context_cache_disabled_set(Ewk_Context* context, Eina_Bool cacheDisabled)
289 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
290 context->SetNetworkCacheEnable(!cacheDisabled);
294 Eina_Bool ewk_context_cache_disabled_get(Ewk_Context* context)
296 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
297 return !context->GetNetworkCacheEnable();
300 Eina_Bool ewk_context_certificate_file_set(Ewk_Context *context, const char *certificate_file)
302 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
303 EINA_SAFETY_ON_NULL_RETURN_VAL(certificate_file, EINA_FALSE);
304 context->SetCertificate(certificate_file);
308 const char* ewk_context_certificate_file_get(const Ewk_Context* context)
310 EINA_SAFETY_ON_NULL_RETURN_VAL(context, NULL);
311 #if !defined(EWK_BRINGUP)
312 return context->GetCertificate();
314 LOG_EWK_API_MOCKUP();
319 Eina_Bool ewk_context_cache_clear(Ewk_Context* context)
321 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
322 context->ClearNetworkCache();
323 context->ClearWebkitCache();
327 void ewk_context_did_start_download_callback_set(Ewk_Context* context,
328 Ewk_Context_Did_Start_Download_Callback callback,
331 EINA_SAFETY_ON_NULL_RETURN(context);
332 context->SetDidStartDownloadCallback(callback, userData);
335 void ewk_context_mime_override_callback_set(Ewk_Context* context, Ewk_Context_Override_Mime_For_Url_Callback callback, void* user_data)
337 EINA_SAFETY_ON_NULL_RETURN(context);
338 context->SetMimeOverrideCallback(callback, user_data);
341 void ewk_context_memory_sampler_start(Ewk_Context* context, double timerInterval)
343 LOG_EWK_API_MOCKUP();
346 void ewk_context_memory_sampler_stop(Ewk_Context* context)
348 LOG_EWK_API_MOCKUP();
351 Eina_Bool ewk_context_additional_plugin_path_set(Ewk_Context *context, const char *path)
353 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
354 EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE);
355 context->AddExtraPluginDir(path);
359 void ewk_context_memory_saving_mode_set(Ewk_Context* context, Eina_Bool mode)
361 //memory saving mode should be handled in chromium in different way
362 //than it is handled in WebKit, so implementation of this feature
363 //is postponed, for now dummy implementation is enough
368 void ewk_context_form_password_data_delete_all(Ewk_Context* context)
370 EINA_SAFETY_ON_NULL_RETURN(context);
371 context->ClearPasswordData();
374 void ewk_context_form_password_data_delete(Ewk_Context* ewkContext, const char* url)
376 LOG_EWK_API_MOCKUP();
379 Eina_List* ewk_context_form_password_data_list_get(Ewk_Context* ewkContext)
381 LOG_EWK_API_MOCKUP();
385 void ewk_context_form_password_data_list_free(Ewk_Context* ewkContext, Eina_List* list)
387 LOG_EWK_API_MOCKUP();
390 void ewk_context_form_candidate_data_delete_all(Ewk_Context* context)
392 EINA_SAFETY_ON_NULL_RETURN(context);
393 context->ClearCandidateData();
396 void ewk_context_form_autofill_profile_changed_callback_set(
397 Ewk_Context_Form_Autofill_Profile_Changed_Callback callback,
400 EwkContextFormAutofillProfileManager::priv_form_autofill_profile_changed_callback_set(
401 callback, user_data);
404 Eina_List* ewk_context_form_autofill_profile_get_all(Ewk_Context* context)
406 if (NULL == context) {
409 return EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get_all(context);
412 Ewk_Autofill_Profile* ewk_context_form_autofill_profile_get(Ewk_Context* context, unsigned id)
414 if (NULL == context) {
417 return EwkContextFormAutofillProfileManager::priv_form_autofill_profile_get(context, id);
420 Eina_Bool ewk_context_form_autofill_profile_set(Ewk_Context* context, unsigned id, Ewk_Autofill_Profile* profile)
422 if (NULL == context || NULL == profile) {
425 return EwkContextFormAutofillProfileManager::priv_form_autofill_profile_set(context, id, profile);
428 Eina_Bool ewk_context_form_autofill_profile_add(Ewk_Context* context, Ewk_Autofill_Profile* profile)
430 if (NULL == context || NULL == profile) {
433 return EwkContextFormAutofillProfileManager::priv_form_autofill_profile_add(context, profile);
436 Eina_Bool ewk_context_form_autofill_profile_remove(Ewk_Context* context, unsigned id)
438 if (NULL == context) {
441 return EwkContextFormAutofillProfileManager::priv_form_autofill_profile_remove(context, id);
444 void ewk_context_vibration_client_callbacks_set(Ewk_Context* context,
445 Ewk_Vibration_Client_Vibrate_Cb vibrate,
446 Ewk_Vibration_Client_Vibration_Cancel_Cb cancel,
449 VibrationProviderClient* vibra_client = VibrationProviderClient::GetInstance();
450 vibra_client->SetVibrationClientCallbacks(vibrate, cancel, data);
453 Eina_Bool ewk_context_tizen_extensible_api_string_set(Ewk_Context* ewkContext, const char* extensibleAPI, Eina_Bool enable)
455 LOG_EWK_API_MOCKUP();
459 Eina_Bool ewk_context_tizen_extensible_api_set(Ewk_Context * /*context*/, Ewk_Extensible_API /*extensibleAPI*/, Eina_Bool /*enable*/)
461 //This API will not be implemented with chromium engine based Ewk View
466 Eina_Bool ewk_context_tizen_extensible_api_get(Ewk_Context * /*context*/, Ewk_Extensible_API /*extensibleAPI*/)
468 //This API will not be implemented with chromium engine based Ewk View
473 void ewk_context_storage_path_reset(Ewk_Context* /*context*/)
475 //not supported in chromium to dynamically update the storage path
479 Eina_Bool ewk_context_pixmap_set(Ewk_Context *context, int pixmap)
481 EINA_SAFETY_ON_NULL_RETURN_VAL(context, EINA_FALSE);
482 context->SetPixmap(pixmap);
486 int ewk_context_pixmap_get(Ewk_Context *context)
488 EINA_SAFETY_ON_NULL_RETURN_VAL(context, 0);
489 return context->Pixmap();
492 unsigned int ewk_context_inspector_server_start(Ewk_Context* ewkContext, unsigned int port)
494 EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
495 return ewkContext->InspectorServerStart(port);
498 Eina_Bool ewk_context_inspector_server_stop(Ewk_Context* ewkContext)
500 EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, EINA_FALSE);
501 return ewkContext->InspectorServerStop();
504 void ewk_send_widget_info(Ewk_Context *context,
508 const char *encodedBundle)
510 EINA_SAFETY_ON_NULL_RETURN(theme);
511 EINA_SAFETY_ON_NULL_RETURN(encodedBundle);
512 EINA_SAFETY_ON_NULL_RETURN(context);
513 context->SendWidgetInfo(widget_handle, scale, theme, encodedBundle);
516 #if defined(OS_TIZEN_TV)
517 Ewk_Application_Cache_Manager* ewk_context_application_cache_manager_get(const Ewk_Context* ewkContext)
519 LOG_EWK_API_MOCKUP("for Tizen TV Browser");
524 Ewk_Favicon_Database* ewk_context_favicon_database_get(const Ewk_Context* ewkContext)
526 #if defined(OS_TIZEN_TV)
527 EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
528 Ewk_Favicon_Database *favicon_database = Ewk_Favicon_Database::Instance();
529 favicon_database->InitEwkFaviconDatabase(ewkContext);
530 return favicon_database;
532 LOG_EWK_API_MOCKUP("Only for Tizen TV Browser");
537 void ewk_context_resource_cache_clear(Ewk_Context* ewkContext)
539 EINA_SAFETY_ON_NULL_RETURN(ewkContext);
540 ewkContext->ClearNetworkCache();
541 ewkContext->ClearWebkitCache();
544 #if defined(OS_TIZEN_TV)
545 Eina_Bool ewk_context_favicon_database_directory_set(Ewk_Context* ewkContext, const char* directoryPath)
547 LOG_EWK_API_MOCKUP("Tizen TV Browser");
550 #endif // OS_TIZEN_TV
552 void ewk_context_preferred_languages_set(Eina_List* languages)
554 std::string preferredLanguages;
559 EINA_LIST_FOREACH(languages, it, data) {
561 preferredLanguages.append(static_cast<char*>(data));
563 preferredLanguages.append(",");
567 std::transform(preferredLanguages.begin(), preferredLanguages.end(), preferredLanguages.begin(), ::tolower);
568 std::replace(preferredLanguages.begin(), preferredLanguages.end(), '_', '-');
569 HttpUserAgentSettingsEfl::SetAcceptLanguage(preferredLanguages);
572 #if defined(OS_TIZEN_TV)
573 Ewk_Storage_Manager* ewk_context_storage_manager_get(const Ewk_Context* ewkContext)
575 LOG_EWK_API_MOCKUP("Tizen TV Browser");
578 #endif // OS_TIZEN_TV