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>
36
#if ENABLE(SPELLCHECK)
37
#include "WKTextChecker.h"
38
#include "ewk_text_checker_private.h"
40
#include <wtf/Vector.h>
41
#include <wtf/text/CString.h>
44
using namespace WebKit;
46
const WebKit::WebPreferences* EwkSettings::preferences() const
48
return m_viewImpl->page()->pageGroup()->preferences();
51
WebKit::WebPreferences* EwkSettings::preferences()
53
return m_viewImpl->page()->pageGroup()->preferences();
56
#if ENABLE(SPELLCHECK)
58
bool isContinuousSpellCheckingEnabled : 1;
59
Vector<String> spellCheckingLanguages;
60
Ewk_Settings_Continuous_Spell_Checking_Change_Cb onContinuousSpellChecking;
61
} ewkTextCheckerSettings = { false, Vector<String>(), 0 };
63
static Eina_Bool onContinuousSpellCheckingIdler(void*)
65
if (ewkTextCheckerSettings.onContinuousSpellChecking)
66
ewkTextCheckerSettings.onContinuousSpellChecking(ewkTextCheckerSettings.isContinuousSpellCheckingEnabled);
68
return ECORE_CALLBACK_CANCEL;
71
static Eina_Bool spellCheckingLanguagesSetUpdate(void*)
73
// FIXME: Consider to delegate calling of this method in WebProcess to do not delay/block UIProcess.
74
Ewk_Text_Checker::updateSpellCheckingLanguages(ewkTextCheckerSettings.spellCheckingLanguages);
75
return ECORE_CALLBACK_CANCEL;
78
static void spellCheckingLanguagesSet(const Vector<String>& newLanguages)
80
ewkTextCheckerSettings.spellCheckingLanguages = newLanguages;
81
ecore_idler_add(spellCheckingLanguagesSetUpdate, 0);
83
#endif // ENABLE(SPELLCHECK)
85
Eina_Bool ewk_settings_fullscreen_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
87
#if ENABLE(FULLSCREEN_API)
88
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
89
settings->preferences()->setFullScreenEnabled(enable);
96
Eina_Bool ewk_settings_fullscreen_enabled_get(const Ewk_Settings* settings)
98
#if ENABLE(FULLSCREEN_API)
99
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
100
return settings->preferences()->fullScreenEnabled();
106
Eina_Bool ewk_settings_javascript_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
108
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
110
settings->preferences()->setJavaScriptEnabled(enable);
115
Eina_Bool ewk_settings_javascript_enabled_get(const Ewk_Settings* settings)
117
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
119
return settings->preferences()->javaScriptEnabled();
122
Eina_Bool ewk_settings_loads_images_automatically_set(Ewk_Settings* settings, Eina_Bool automatic)
124
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
126
settings->preferences()->setLoadsImagesAutomatically(automatic);
131
Eina_Bool ewk_settings_loads_images_automatically_get(const Ewk_Settings* settings)
133
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
135
return settings->preferences()->loadsImagesAutomatically();
138
Eina_Bool ewk_settings_developer_extras_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
140
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
142
settings->preferences()->setDeveloperExtrasEnabled(enable);
147
Eina_Bool ewk_settings_developer_extras_enabled_get(const Ewk_Settings* settings)
149
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
151
return settings->preferences()->developerExtrasEnabled();
154
Eina_Bool ewk_settings_file_access_from_file_urls_allowed_set(Ewk_Settings* settings, Eina_Bool enable)
156
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
158
settings->preferences()->setAllowFileAccessFromFileURLs(enable);
163
Eina_Bool ewk_settings_file_access_from_file_urls_allowed_get(const Ewk_Settings* settings)
165
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
167
return settings->preferences()->allowFileAccessFromFileURLs();
170
Eina_Bool ewk_settings_frame_flattening_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
172
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
174
settings->preferences()->setFrameFlatteningEnabled(enable);
179
Eina_Bool ewk_settings_frame_flattening_enabled_get(const Ewk_Settings* settings)
181
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
183
return settings->preferences()->frameFlatteningEnabled();
186
Eina_Bool ewk_settings_dns_prefetching_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
188
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
190
settings->preferences()->setDNSPrefetchingEnabled(enable);
195
Eina_Bool ewk_settings_dns_prefetching_enabled_get(const Ewk_Settings* settings)
197
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
199
return settings->preferences()->dnsPrefetchingEnabled();
202
void ewk_settings_continuous_spell_checking_change_cb_set(Ewk_Settings_Continuous_Spell_Checking_Change_Cb callback)
204
#if ENABLE(SPELLCHECK)
205
ewkTextCheckerSettings.onContinuousSpellChecking = callback;
209
Eina_Bool ewk_settings_continuous_spell_checking_enabled_get()
211
#if ENABLE(SPELLCHECK)
212
return ewkTextCheckerSettings.isContinuousSpellCheckingEnabled;
218
void ewk_settings_continuous_spell_checking_enabled_set(Eina_Bool enable)
220
#if ENABLE(SPELLCHECK)
222
if (ewkTextCheckerSettings.isContinuousSpellCheckingEnabled != enable) {
223
ewkTextCheckerSettings.isContinuousSpellCheckingEnabled = enable;
225
WKTextCheckerContinuousSpellCheckingEnabledStateChanged(enable);
227
// Sets the default language if user didn't specify any.
228
if (enable && !Ewk_Text_Checker::hasDictionary())
229
spellCheckingLanguagesSet(Vector<String>());
231
if (ewkTextCheckerSettings.onContinuousSpellChecking)
232
ecore_idler_add(onContinuousSpellCheckingIdler, 0);
237
Eina_List* ewk_settings_spell_checking_available_languages_get()
239
Eina_List* listOflanguages = 0;
240
#if ENABLE(SPELLCHECK)
241
const Vector<String>& languages = Ewk_Text_Checker::availableSpellCheckingLanguages();
242
size_t numberOfLanuages = languages.size();
244
for (size_t i = 0; i < numberOfLanuages; ++i)
245
listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data()));
247
return listOflanguages;
250
void ewk_settings_spell_checking_languages_set(const char* languages)
252
#if ENABLE(SPELLCHECK)
253
Vector<String> newLanguages;
254
String::fromUTF8(languages).split(',', newLanguages);
256
spellCheckingLanguagesSet(newLanguages);
260
Eina_List* ewk_settings_spell_checking_languages_get()
262
Eina_List* listOflanguages = 0;
263
#if ENABLE(SPELLCHECK)
264
Vector<String> languages = Ewk_Text_Checker::loadedSpellCheckingLanguages();
265
size_t numberOfLanuages = languages.size();
267
for (size_t i = 0; i < numberOfLanuages; ++i)
268
listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data()));
271
return listOflanguages;
274
Eina_Bool ewk_settings_encoding_detector_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
276
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
278
settings->preferences()->setUsesEncodingDetector(enable);
283
Eina_Bool ewk_settings_encoding_detector_enabled_get(const Ewk_Settings* settings)
285
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
287
return settings->preferences()->usesEncodingDetector();
290
Eina_Bool ewk_settings_preferred_minimum_contents_width_set(Ewk_Settings *settings, unsigned width)
292
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
294
settings->preferences()->setLayoutFallbackWidth(width);
299
unsigned ewk_settings_preferred_minimum_contents_width_get(const Ewk_Settings *settings)
301
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
303
return settings->preferences()->layoutFallbackWidth();
306
Eina_Bool ewk_settings_offline_web_application_cache_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
308
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
309
settings->preferences()->setOfflineWebApplicationCacheEnabled(enable);
314
Eina_Bool ewk_settings_offline_web_application_cache_enabled_get(const Ewk_Settings* settings)
316
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
318
return settings->preferences()->offlineWebApplicationCacheEnabled();
321
Eina_Bool ewk_settings_scripts_can_open_windows_set(Ewk_Settings* settings, Eina_Bool enable)
323
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
324
settings->preferences()->setJavaScriptCanOpenWindowsAutomatically(enable);
329
Eina_Bool ewk_settings_scripts_can_open_windows_get(const Ewk_Settings* settings)
331
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
333
return settings->preferences()->javaScriptCanOpenWindowsAutomatically();
336
Eina_Bool ewk_settings_local_storage_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
338
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
340
settings->preferences()->setLocalStorageEnabled(enable);
345
Eina_Bool ewk_settings_local_storage_enabled_get(const Ewk_Settings* settings)
347
EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
349
return settings->preferences()->localStorageEnabled();