~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/UIProcess/API/efl/ewk_settings.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Samsung Electronics
 
3
 * Copyright (C) 2012 Intel Corporation. All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
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.
 
13
 *
 
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.
 
25
 */
 
26
 
 
27
#include "config.h"
 
28
#include "ewk_settings.h"
 
29
 
 
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>
 
35
 
 
36
#if ENABLE(SPELLCHECK)
 
37
#include "WKTextChecker.h"
 
38
#include "ewk_text_checker_private.h"
 
39
#include <Ecore.h>
 
40
#include <wtf/Vector.h>
 
41
#include <wtf/text/CString.h>
 
42
#endif
 
43
 
 
44
using namespace WebKit;
 
45
 
 
46
const WebKit::WebPreferences* EwkSettings::preferences() const
 
47
{
 
48
    return m_viewImpl->page()->pageGroup()->preferences();
 
49
}
 
50
 
 
51
WebKit::WebPreferences* EwkSettings::preferences()
 
52
{
 
53
    return m_viewImpl->page()->pageGroup()->preferences();
 
54
}
 
55
 
 
56
#if ENABLE(SPELLCHECK)
 
57
static struct {
 
58
    bool isContinuousSpellCheckingEnabled : 1;
 
59
    Vector<String> spellCheckingLanguages;
 
60
    Ewk_Settings_Continuous_Spell_Checking_Change_Cb onContinuousSpellChecking;
 
61
} ewkTextCheckerSettings = { false, Vector<String>(), 0 };
 
62
 
 
63
static Eina_Bool onContinuousSpellCheckingIdler(void*)
 
64
{
 
65
    if (ewkTextCheckerSettings.onContinuousSpellChecking)
 
66
        ewkTextCheckerSettings.onContinuousSpellChecking(ewkTextCheckerSettings.isContinuousSpellCheckingEnabled);
 
67
 
 
68
    return ECORE_CALLBACK_CANCEL;
 
69
}
 
70
 
 
71
static Eina_Bool spellCheckingLanguagesSetUpdate(void*)
 
72
{
 
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;
 
76
}
 
77
 
 
78
static void spellCheckingLanguagesSet(const Vector<String>& newLanguages)
 
79
{
 
80
    ewkTextCheckerSettings.spellCheckingLanguages = newLanguages;
 
81
    ecore_idler_add(spellCheckingLanguagesSetUpdate, 0);
 
82
}
 
83
#endif // ENABLE(SPELLCHECK)
 
84
 
 
85
Eina_Bool ewk_settings_fullscreen_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
 
86
{
 
87
#if ENABLE(FULLSCREEN_API)
 
88
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
89
    settings->preferences()->setFullScreenEnabled(enable);
 
90
    return true;
 
91
#else
 
92
    return false;
 
93
#endif
 
94
}
 
95
 
 
96
Eina_Bool ewk_settings_fullscreen_enabled_get(const Ewk_Settings* settings)
 
97
{
 
98
#if ENABLE(FULLSCREEN_API)
 
99
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
100
    return settings->preferences()->fullScreenEnabled();
 
101
#else
 
102
    return false;
 
103
#endif
 
104
}
 
105
 
 
106
Eina_Bool ewk_settings_javascript_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
 
107
{
 
108
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
109
 
 
110
    settings->preferences()->setJavaScriptEnabled(enable);
 
111
 
 
112
    return true;
 
113
}
 
114
 
 
115
Eina_Bool ewk_settings_javascript_enabled_get(const Ewk_Settings* settings)
 
116
{
 
117
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
118
 
 
119
    return settings->preferences()->javaScriptEnabled();
 
120
}
 
121
 
 
122
Eina_Bool ewk_settings_loads_images_automatically_set(Ewk_Settings* settings, Eina_Bool automatic)
 
123
{
 
124
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
125
 
 
126
    settings->preferences()->setLoadsImagesAutomatically(automatic);
 
127
 
 
128
    return true;
 
129
}
 
130
 
 
131
Eina_Bool ewk_settings_loads_images_automatically_get(const Ewk_Settings* settings)
 
132
{
 
133
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
134
 
 
135
    return settings->preferences()->loadsImagesAutomatically();
 
136
}
 
137
 
 
138
Eina_Bool ewk_settings_developer_extras_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
 
139
{
 
140
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
141
 
 
142
    settings->preferences()->setDeveloperExtrasEnabled(enable);
 
143
 
 
144
    return true;
 
145
}
 
146
 
 
147
Eina_Bool ewk_settings_developer_extras_enabled_get(const Ewk_Settings* settings)
 
148
{
 
149
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
150
 
 
151
    return settings->preferences()->developerExtrasEnabled();
 
152
}
 
153
 
 
154
Eina_Bool ewk_settings_file_access_from_file_urls_allowed_set(Ewk_Settings* settings, Eina_Bool enable)
 
155
{
 
156
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
157
 
 
158
    settings->preferences()->setAllowFileAccessFromFileURLs(enable);
 
159
 
 
160
    return true;
 
161
}
 
162
 
 
163
Eina_Bool ewk_settings_file_access_from_file_urls_allowed_get(const Ewk_Settings* settings)
 
164
{
 
165
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
166
 
 
167
    return settings->preferences()->allowFileAccessFromFileURLs();
 
168
}
 
169
 
 
170
Eina_Bool ewk_settings_frame_flattening_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
 
171
{
 
172
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
173
 
 
174
    settings->preferences()->setFrameFlatteningEnabled(enable);
 
175
 
 
176
    return true;
 
177
}
 
178
 
 
179
Eina_Bool ewk_settings_frame_flattening_enabled_get(const Ewk_Settings* settings)
 
180
{
 
181
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
182
 
 
183
    return settings->preferences()->frameFlatteningEnabled();
 
184
}
 
185
 
 
186
Eina_Bool ewk_settings_dns_prefetching_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
 
187
{
 
188
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
189
 
 
190
    settings->preferences()->setDNSPrefetchingEnabled(enable);
 
191
 
 
192
    return true;
 
193
}
 
194
 
 
195
Eina_Bool ewk_settings_dns_prefetching_enabled_get(const Ewk_Settings* settings)
 
196
{
 
197
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
198
 
 
199
    return settings->preferences()->dnsPrefetchingEnabled();
 
200
}
 
201
 
 
202
void ewk_settings_continuous_spell_checking_change_cb_set(Ewk_Settings_Continuous_Spell_Checking_Change_Cb callback)
 
203
{
 
204
#if ENABLE(SPELLCHECK)
 
205
    ewkTextCheckerSettings.onContinuousSpellChecking = callback;
 
206
#endif
 
207
}
 
208
 
 
209
Eina_Bool ewk_settings_continuous_spell_checking_enabled_get()
 
210
{
 
211
#if ENABLE(SPELLCHECK)
 
212
    return ewkTextCheckerSettings.isContinuousSpellCheckingEnabled;
 
213
#else
 
214
    return false;
 
215
#endif
 
216
}
 
217
 
 
218
void ewk_settings_continuous_spell_checking_enabled_set(Eina_Bool enable)
 
219
{
 
220
#if ENABLE(SPELLCHECK)
 
221
    enable = !!enable;
 
222
    if (ewkTextCheckerSettings.isContinuousSpellCheckingEnabled != enable) {
 
223
        ewkTextCheckerSettings.isContinuousSpellCheckingEnabled = enable;
 
224
 
 
225
        WKTextCheckerContinuousSpellCheckingEnabledStateChanged(enable);
 
226
 
 
227
        // Sets the default language if user didn't specify any.
 
228
        if (enable && !Ewk_Text_Checker::hasDictionary())
 
229
            spellCheckingLanguagesSet(Vector<String>());
 
230
 
 
231
        if (ewkTextCheckerSettings.onContinuousSpellChecking)
 
232
            ecore_idler_add(onContinuousSpellCheckingIdler, 0);
 
233
    }
 
234
#endif
 
235
}
 
236
 
 
237
Eina_List* ewk_settings_spell_checking_available_languages_get()
 
238
{
 
239
    Eina_List* listOflanguages = 0;
 
240
#if ENABLE(SPELLCHECK)
 
241
    const Vector<String>& languages = Ewk_Text_Checker::availableSpellCheckingLanguages();
 
242
    size_t numberOfLanuages = languages.size();
 
243
 
 
244
    for (size_t i = 0; i < numberOfLanuages; ++i)
 
245
        listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data()));
 
246
#endif
 
247
    return listOflanguages;
 
248
}
 
249
 
 
250
void ewk_settings_spell_checking_languages_set(const char* languages)
 
251
{
 
252
#if ENABLE(SPELLCHECK)
 
253
    Vector<String> newLanguages;
 
254
    String::fromUTF8(languages).split(',', newLanguages);
 
255
 
 
256
    spellCheckingLanguagesSet(newLanguages);
 
257
#endif
 
258
}
 
259
 
 
260
Eina_List* ewk_settings_spell_checking_languages_get()
 
261
{
 
262
    Eina_List* listOflanguages = 0;
 
263
#if ENABLE(SPELLCHECK)
 
264
    Vector<String> languages = Ewk_Text_Checker::loadedSpellCheckingLanguages();
 
265
    size_t numberOfLanuages = languages.size();
 
266
 
 
267
    for (size_t i = 0; i < numberOfLanuages; ++i)
 
268
        listOflanguages = eina_list_append(listOflanguages, eina_stringshare_add(languages[i].utf8().data()));
 
269
 
 
270
#endif
 
271
    return listOflanguages;
 
272
}
 
273
 
 
274
Eina_Bool ewk_settings_encoding_detector_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
 
275
{
 
276
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
277
 
 
278
    settings->preferences()->setUsesEncodingDetector(enable);
 
279
 
 
280
    return true;
 
281
}
 
282
 
 
283
Eina_Bool ewk_settings_encoding_detector_enabled_get(const Ewk_Settings* settings)
 
284
{
 
285
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
286
 
 
287
    return settings->preferences()->usesEncodingDetector();
 
288
}
 
289
 
 
290
Eina_Bool ewk_settings_preferred_minimum_contents_width_set(Ewk_Settings *settings, unsigned width)
 
291
{
 
292
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
293
 
 
294
    settings->preferences()->setLayoutFallbackWidth(width);
 
295
 
 
296
    return true;
 
297
}
 
298
 
 
299
unsigned ewk_settings_preferred_minimum_contents_width_get(const Ewk_Settings *settings)
 
300
{
 
301
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
302
 
 
303
    return settings->preferences()->layoutFallbackWidth();
 
304
}
 
305
 
 
306
Eina_Bool ewk_settings_offline_web_application_cache_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
 
307
{
 
308
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
309
    settings->preferences()->setOfflineWebApplicationCacheEnabled(enable);
 
310
 
 
311
    return true;
 
312
}
 
313
 
 
314
Eina_Bool ewk_settings_offline_web_application_cache_enabled_get(const Ewk_Settings* settings)
 
315
{
 
316
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
317
 
 
318
    return settings->preferences()->offlineWebApplicationCacheEnabled();
 
319
}
 
320
 
 
321
Eina_Bool ewk_settings_scripts_can_open_windows_set(Ewk_Settings* settings, Eina_Bool enable)
 
322
{
 
323
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
324
    settings->preferences()->setJavaScriptCanOpenWindowsAutomatically(enable);
 
325
 
 
326
    return true;
 
327
}
 
328
 
 
329
Eina_Bool ewk_settings_scripts_can_open_windows_get(const Ewk_Settings* settings)
 
330
{
 
331
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
332
 
 
333
    return settings->preferences()->javaScriptCanOpenWindowsAutomatically();
 
334
}
 
335
 
 
336
Eina_Bool ewk_settings_local_storage_enabled_set(Ewk_Settings* settings, Eina_Bool enable)
 
337
{
 
338
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
339
 
 
340
    settings->preferences()->setLocalStorageEnabled(enable);
 
341
 
 
342
    return true;
 
343
}
 
344
 
 
345
Eina_Bool ewk_settings_local_storage_enabled_get(const Ewk_Settings* settings)
 
346
{
 
347
    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
 
348
 
 
349
    return settings->preferences()->localStorageEnabled();
 
350
}