2 * Copyright (C) 2012 Samsung Electronics
3 * Copyright (C) 2012 Intel Corporation. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include "ewk_settings.h"
30 #include "EwkViewImpl.h"
31 #include "ewk_settings_private.h"
32 #include <WebKit2/WebPageGroup.h>
33 #include <WebKit2/WebPageProxy.h>
34 #include <WebKit2/WebPreferences.h>
37 #include "WKAPICast.h"
38 #include "WKPreferences.h"
39 #include "WKPreferencesTizen.h"
40 #include "WKRetainPtr.h"
43 #include <wtf/OwnArrayPtr.h>
46 #if ENABLE(SPELLCHECK)
47 #include "WKTextChecker.h"
48 #include "ewk_text_checker_private.h"
50 #include <wtf/Vector.h>
51 #include <wtf/text/CString.h>
54 using namespace WebKit;
56 const WebKit::WebPreferences* Ewk_Settings::preferences() const
58 return m_viewImpl->pageProxy->pageGroup()->preferences();
61 WebKit::WebPreferences* Ewk_Settings::preferences()
63 return m_viewImpl->pageProxy->pageGroup()->preferences();
67 void Ewk_Settings::setDefaultTextEncoding(const char* defaultTextEncoding)
69 m_defaultTextEncoding = defaultTextEncoding;
72 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
73 void Ewk_Settings::setAutofillPasswordForm(bool enable)
75 m_autofillPasswordForm = enable;
78 void Ewk_Settings::setFormCandidateData(bool enable)
80 m_formCandidateData = enable;
85 #if ENABLE(SPELLCHECK)
87 bool isContinuousSpellCheckingEnabled : 1;
88 Vector<String> spellCheckingLanguages;
89 Ewk_Settings_Continuous_Spell_Checking_Change_Cb onContinuousSpellChecking;
90 } ewkTextCheckerSettings = { false, Vector<String>(), 0 };
92 static Eina_Bool onContinuousSpellCheckingIdler(void*)
94 if (ewkTextCheckerSettings.onContinuousSpellChecking)
95 ewkTextCheckerSettings.onContinuousSpellChecking(ewkTextCheckerSettings.isContinuousSpellCheckingEnabled);
97 return ECORE_CALLBACK_CANCEL;
100 static Eina_Bool spellCheckingLanguagesSetUpdate(void*)
102 // FIXME: Consider to delegate calling of this method in WebProcess to do not delay/block UIProcess.
103 Ewk_Text_Checker::updateSpellCheckingLanguages(ewkTextCheckerSettings.spellCheckingLanguages);
104 return ECORE_CALLBACK_CANCEL;
107 static void spellCheckingLanguagesSet(const Vector<String>& newLanguages)
109 ewkTextCheckerSettings.spellCheckingLanguages = newLanguages;
110 ecore_idler_add(spellCheckingLanguagesSetUpdate, 0);
112 #endif // ENABLE(SPELLCHECK)
114 Eina_Bool ewk_settings_fullscreen_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
116 #if ENABLE(FULLSCREEN_API)
117 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
118 settings->preferences()->setFullScreenEnabled(enable);
125 Eina_Bool ewk_settings_fullscreen_enabled_get(const Ewk_Settings* settings)
127 #if ENABLE(FULLSCREEN_API)
128 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
129 return settings->preferences()->fullScreenEnabled();
135 Eina_Bool ewk_settings_javascript_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
137 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
139 settings->preferences()->setJavaScriptEnabled(enable);
144 Eina_Bool ewk_settings_javascript_enabled_get(const Ewk_Settings* settings)
146 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
148 return settings->preferences()->javaScriptEnabled();
151 Eina_Bool ewk_settings_loads_images_automatically_set(Ewk_Settings* settings, Eina_Bool automatic)
153 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
155 settings->preferences()->setLoadsImagesAutomatically(automatic);
160 Eina_Bool ewk_settings_loads_images_automatically_get(const Ewk_Settings* settings)
162 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
164 return settings->preferences()->loadsImagesAutomatically();
168 Eina_Bool ewk_settings_plugins_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
170 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
172 settings->preferences()->setPluginsEnabled(enable);
177 Eina_Bool ewk_settings_plugins_enabled_get(const Ewk_Settings* settings)
179 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
181 return settings->preferences()->pluginsEnabled();
184 Eina_Bool ewk_settings_auto_fitting_set(Ewk_Settings* settings, Eina_Bool enable)
186 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
188 settings->preferences()->setAutoFittingEnabled(enable);
193 Eina_Bool ewk_settings_auto_fitting_get(const Ewk_Settings* settings)
195 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
197 return settings->preferences()->autoFittingEnabled();
200 Eina_Bool ewk_settings_font_default_size_set(Ewk_Settings* settings, int size)
202 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
204 settings->preferences()->setDefaultFontSize(size);
209 int ewk_settings_font_default_size_get(const Ewk_Settings* settings)
211 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, 0);
213 return settings->preferences()->defaultFontSize();
216 Eina_Bool ewk_settings_scripts_window_open_set(Ewk_Settings* settings, Eina_Bool allow)
218 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
220 settings->preferences()->setJavaScriptCanOpenWindowsAutomatically(allow);
225 Eina_Bool ewk_settings_scripts_window_open_get(const Ewk_Settings* settings)
227 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
229 return settings->preferences()->javaScriptCanOpenWindowsAutomatically();
232 Eina_Bool ewk_settings_compositing_borders_visible_set(Ewk_Settings* settings, Eina_Bool enable)
234 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
236 settings->preferences()->setCompositingBordersVisible(enable);
241 Eina_Bool ewk_settings_default_encoding_set(Ewk_Settings* settings, const char* encoding)
243 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
245 settings->preferences()->setDefaultTextEncodingName(String::fromUTF8(encoding));
250 const char* ewk_settings_default_encoding_get(const Ewk_Settings* settings)
252 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, 0);
254 const String& encodingString(settings->preferences()->defaultTextEncodingName());
255 const_cast<Ewk_Settings*>(settings)->setDefaultTextEncoding(encodingString.utf8().data());
257 return settings->defaultTextEncoding();
260 Eina_Bool ewk_settings_private_browsing_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
262 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
264 settings->preferences()->setPrivateBrowsingEnabled(enable);
269 Eina_Bool ewk_settings_private_browsing_enabled_get(const Ewk_Settings* settings)
271 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
273 return settings->preferences()->privateBrowsingEnabled();
276 Eina_Bool ewk_settings_editable_link_behavior_set(Ewk_Settings* settings, Ewk_Editable_Link_Behavior behavior)
278 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
280 settings->preferences()->setEditableLinkBehavior(static_cast<WKEditableLinkBehavior>(behavior));
285 #if ENABLE(TIZEN_LOAD_REMOTE_IMAGES)
286 Eina_Bool ewk_settings_load_remote_images_set(Ewk_Settings* settings, Eina_Bool loadRemoteImages)
288 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
290 settings->preferences()->setLoadRemoteImages(loadRemoteImages);
295 Eina_Bool ewk_settings_load_remote_images_get(const Ewk_Settings* settings)
297 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
299 return settings->preferences()->loadRemoteImages();
303 Eina_Bool ewk_settings_link_effect_enabled_set(Ewk_Settings* settings, Eina_Bool linkEffectEnabled)
305 #if ENABLE(TIZEN_LINK_EFFECT)
306 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
308 settings->preferences()->setLinkEffectEnabled(linkEffectEnabled);
316 Eina_Bool ewk_settings_link_effect_enabled_get(const Ewk_Settings* settings)
318 #if ENABLE(TIZEN_LINK_EFFECT)
319 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
321 return settings->preferences()->linkEffectEnabled();
327 Eina_Bool ewk_settings_uses_encoding_detector_set(Ewk_Settings* settings, Eina_Bool use)
329 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
331 settings->preferences()->setUsesEncodingDetector(use);
336 Eina_Bool ewk_settings_uses_encoding_detector_get(const Ewk_Settings* settings)
338 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
340 return settings->preferences()->usesEncodingDetector();
343 #if ENABLE(TIZEN_ISF_PORT)
344 Eina_Bool ewk_settings_show_ime_on_autofocus_set(Ewk_Settings* settings, Eina_Bool enable)
349 Eina_Bool ewk_settings_show_ime_on_autofocus_get(const Ewk_Settings* settings)
354 Eina_Bool ewk_settings_default_keypad_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
356 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
358 settings->preferences()->setEnableDefaultKeypad(enable);
363 Eina_Bool ewk_settings_default_keypad_enabled_get(const Ewk_Settings* settings)
365 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
367 return settings->preferences()->defaultKeypadEnabled();
370 Eina_Bool ewk_settings_uses_keypad_without_user_action_set(Ewk_Settings* settings, Eina_Bool use)
372 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
374 settings->preferences()->setUsesKeypadWithoutUserAction(use);
379 Eina_Bool ewk_settings_uses_keypad_without_user_action_get(const Ewk_Settings* settings)
381 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, true);
383 return settings->preferences()->usesKeypadWithoutUserAction();
387 Eina_Bool ewk_settings_frame_flattening_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
389 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
391 settings->preferences()->setFrameFlatteningEnabled(enable);
396 Eina_Bool ewk_settings_frame_flattening_enabled_get(const Ewk_Settings* settings)
398 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
400 return settings->preferences()->frameFlatteningEnabled();
403 #if ENABLE(TIZEN_WEBKIT2_TEXT_ZOOM)
404 Eina_Bool ewk_settings_text_zoom_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
406 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
408 settings->preferences()->setTextZoomEnabled(enable);
413 Eina_Bool ewk_settings_text_zoom_enabled_get(const Ewk_Settings* settings)
415 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
417 return settings->preferences()->textZoomEnabled();
421 Eina_Bool ewk_settings_style_scoped_set(Ewk_Settings* settings, Eina_Bool enable)
423 #if ENABLE(TIZEN_STYLE_SCOPED)
424 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
425 TIZEN_LOGI("enable (%d)", enable);
427 settings->preferences()->setStyleScopedEnabled(enable);
432 Eina_Bool ewk_settings_style_scoped_get(Ewk_Settings* settings)
434 #if ENABLE(TIZEN_STYLE_SCOPED)
435 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
436 TIZEN_LOGI("settings (%p), settings");
438 return settings->preferences()->styleScopedEnabled();
442 Eina_Bool ewk_settings_autofill_password_form_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
444 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
445 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
446 settings->setAutofillPasswordForm(enable);
452 Eina_Bool ewk_settings_autofill_password_form_enabled_get(Ewk_Settings* settings)
454 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
455 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
456 return settings->autofillPasswordForm();
461 Eina_Bool ewk_settings_form_candidate_data_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
463 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
464 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
465 settings->setFormCandidateData(enable);
471 Eina_Bool ewk_settings_form_candidate_data_enabled_get(Ewk_Settings* settings)
473 #if ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
474 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
475 return settings->formCandidateData();
479 #endif // if OS(TIZEN)
481 void ewk_settings_continuous_spell_checking_change_cb_set(Ewk_Settings_Continuous_Spell_Checking_Change_Cb callback)
483 #if ENABLE(SPELLCHECK)
484 ewkTextCheckerSettings.onContinuousSpellChecking = callback;
488 Eina_Bool ewk_settings_continuous_spell_checking_enabled_get()
490 #if ENABLE(SPELLCHECK)
491 return ewkTextCheckerSettings.isContinuousSpellCheckingEnabled;
497 void ewk_settings_continuous_spell_checking_enabled_set(Eina_Bool enable)
499 #if ENABLE(SPELLCHECK)
501 if (ewkTextCheckerSettings.isContinuousSpellCheckingEnabled != enable) {
502 ewkTextCheckerSettings.isContinuousSpellCheckingEnabled = enable;
504 WKTextCheckerContinuousSpellCheckingEnabledStateChanged(enable);
506 // Sets the default language if user didn't specify any.
507 if (enable && !Ewk_Text_Checker::hasDictionary())
508 spellCheckingLanguagesSet(Vector<String>());
510 if (ewkTextCheckerSettings.onContinuousSpellChecking)
511 ecore_idler_add(onContinuousSpellCheckingIdler, 0);
516 Eina_List* ewk_settings_spell_checking_available_languages_get()
518 Eina_List* listOflanguages = 0;
519 #if ENABLE(SPELLCHECK)
520 const Vector<String>& languages = Ewk_Text_Checker::availableSpellCheckingLanguages();
521 size_t numberOfLanuages = languages.size();
523 for (size_t i = 0; i < numberOfLanuages; ++i)
524 listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data()));
526 return listOflanguages;
529 void ewk_settings_spell_checking_languages_set(const char* languages)
531 #if ENABLE(SPELLCHECK)
532 Vector<String> newLanguages;
533 String::fromUTF8(languages).split(',', newLanguages);
535 spellCheckingLanguagesSet(newLanguages);
539 Eina_List* ewk_settings_spell_checking_languages_get()
541 Eina_List* listOflanguages = 0;
542 #if ENABLE(SPELLCHECK)
543 Vector<String> languages = Ewk_Text_Checker::loadedSpellCheckingLanguages();
544 size_t numberOfLanuages = languages.size();
546 for (size_t i = 0; i < numberOfLanuages; ++i)
547 listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data()));
550 return listOflanguages;
553 void ewk_settings_link_magnifier_enabled_set(Ewk_Settings* settings, Eina_Bool enabled)
555 EINA_SAFETY_ON_NULL_RETURN(settings);
556 // settings->preferences()->setLinkMagnifierEnabled(enabled);
559 Eina_Bool ewk_settings_link_magnifier_enabled_get(const Ewk_Settings* settings)
561 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
562 return settings->preferences()->linkMagnifierEnabled();
565 Eina_Bool ewk_settings_text_selection_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
567 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
569 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
570 settings->setTextSelectionEnabled(enable);
577 Eina_Bool ewk_settings_text_selection_enabled_get(const Ewk_Settings* settings)
579 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
581 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
582 return settings->textSelectionEnabled();
588 Eina_Bool ewk_settings_clear_text_selection_automatically_set(Ewk_Settings* settings, Eina_Bool enable)
590 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
592 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
593 settings->setAutoClearTextSelection(enable);
600 Eina_Bool ewk_settings_clear_text_selection_automatically_get(const Ewk_Settings* settings)
602 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
604 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
605 return settings->autoClearTextSelection();
611 Eina_Bool ewk_settings_text_autosizing_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
613 #if ENABLE(TEXT_AUTOSIZING)
614 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
616 settings->preferences()->setTextAutosizingEnabled(enable);
620 UNUSED_PARAM(settings);
621 UNUSED_PARAM(enable);
626 Eina_Bool ewk_settings_text_autosizing_enabled_get(const Ewk_Settings* settings)
628 #if ENABLE(TEXT_AUTOSIZING)
629 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
631 return settings->preferences()->textAutosizingEnabled();
633 UNUSED_PARAM(settings);