Reviewed by Anders Carlsson and Darin Adler.
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / C / WKPreferences.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "WKPreferences.h"
27 #include "WKPreferencesPrivate.h"
28
29 #include "WKAPICast.h"
30 #include "WebPreferences.h"
31 #include <wtf/PassRefPtr.h>
32 #include <wtf/RefPtr.h>
33
34 using namespace WebKit;
35
36 WKTypeID WKPreferencesGetTypeID()
37 {
38     return toAPI(WebPreferences::APIType);
39 }
40
41 WKPreferencesRef WKPreferencesCreate()
42 {
43     RefPtr<WebPreferences> preferences = WebPreferences::create();
44     return toAPI(preferences.release().leakRef());
45 }
46
47 WKPreferencesRef WKPreferencesCreateWithIdentifier(WKStringRef identifierRef)
48 {
49     RefPtr<WebPreferences> preferences = WebPreferences::create(toWTFString(identifierRef));
50     return toAPI(preferences.release().releaseRef());
51 }
52
53 void WKPreferencesSetJavaScriptEnabled(WKPreferencesRef preferencesRef, bool javaScriptEnabled)
54 {
55     toImpl(preferencesRef)->setJavaScriptEnabled(javaScriptEnabled);
56 }
57
58 bool WKPreferencesGetJavaScriptEnabled(WKPreferencesRef preferencesRef)
59 {
60     return toImpl(preferencesRef)->javaScriptEnabled();
61 }
62
63 void WKPreferencesSetLoadsImagesAutomatically(WKPreferencesRef preferencesRef, bool loadsImagesAutomatically)
64 {
65     toImpl(preferencesRef)->setLoadsImagesAutomatically(loadsImagesAutomatically);
66 }
67
68 bool WKPreferencesGetLoadsImagesAutomatically(WKPreferencesRef preferencesRef)
69 {
70     return toImpl(preferencesRef)->loadsImagesAutomatically();
71 }
72
73 void WKPreferencesSetOfflineWebApplicationCacheEnabled(WKPreferencesRef preferencesRef, bool offlineWebApplicationCacheEnabled)
74 {
75     toImpl(preferencesRef)->setOfflineWebApplicationCacheEnabled(offlineWebApplicationCacheEnabled);
76 }
77
78 bool WKPreferencesGetOfflineWebApplicationCacheEnabled(WKPreferencesRef preferencesRef)
79 {
80     return toImpl(preferencesRef)->offlineWebApplicationCacheEnabled();
81 }
82
83 void WKPreferencesSetLocalStorageEnabled(WKPreferencesRef preferencesRef, bool localStorageEnabled)
84 {
85     toImpl(preferencesRef)->setLocalStorageEnabled(localStorageEnabled);
86 }
87
88 bool WKPreferencesGetLocalStorageEnabled(WKPreferencesRef preferencesRef)
89 {
90     return toImpl(preferencesRef)->localStorageEnabled();
91 }
92
93 void WKPreferencesSetDatabasesEnabled(WKPreferencesRef preferencesRef, bool databasesEnabled)
94 {
95     toImpl(preferencesRef)->setDatabasesEnabled(databasesEnabled);
96 }
97
98 bool WKPreferencesGetDatabasesEnabled(WKPreferencesRef preferencesRef)
99 {
100     return toImpl(preferencesRef)->databasesEnabled();
101 }
102
103 void WKPreferencesSetXSSAuditorEnabled(WKPreferencesRef preferencesRef, bool xssAuditorEnabled)
104 {
105     toImpl(preferencesRef)->setXSSAuditorEnabled(xssAuditorEnabled);
106 }
107
108 bool WKPreferencesGetXSSAuditorEnabled(WKPreferencesRef preferencesRef)
109 {
110     return toImpl(preferencesRef)->xssAuditorEnabled();
111 }
112
113 void WKPreferencesSetFrameFlatteningEnabled(WKPreferencesRef preferencesRef, bool frameFlatteningEnabled)
114 {
115     toImpl(preferencesRef)->setFrameFlatteningEnabled(frameFlatteningEnabled);
116 }
117
118 bool WKPreferencesGetFrameFlatteningEnabled(WKPreferencesRef preferencesRef)
119 {
120     return toImpl(preferencesRef)->frameFlatteningEnabled();
121 }
122
123 void WKPreferencesSetPluginsEnabled(WKPreferencesRef preferencesRef, bool pluginsEnabled)
124 {
125     toImpl(preferencesRef)->setPluginsEnabled(pluginsEnabled);
126 }
127
128 bool WKPreferencesGetPluginsEnabled(WKPreferencesRef preferencesRef)
129 {
130     return toImpl(preferencesRef)->pluginsEnabled();
131 }
132
133 void WKPreferencesSetJavaEnabled(WKPreferencesRef preferencesRef, bool javaEnabled)
134 {
135     toImpl(preferencesRef)->setJavaEnabled(javaEnabled);
136 }
137
138 bool WKPreferencesGetJavaEnabled(WKPreferencesRef preferencesRef)
139 {
140     return toImpl(preferencesRef)->javaEnabled();
141 }
142
143 void WKPreferencesSetJavaScriptCanOpenWindowsAutomatically(WKPreferencesRef preferencesRef, bool javaScriptCanOpenWindowsAutomatically)
144 {
145     toImpl(preferencesRef)->setJavaScriptCanOpenWindowsAutomatically(javaScriptCanOpenWindowsAutomatically);
146 }
147
148 bool WKPreferencesGetJavaScriptCanOpenWindowsAutomatically(WKPreferencesRef preferencesRef)
149 {
150     return toImpl(preferencesRef)->javaScriptCanOpenWindowsAutomatically();
151 }
152
153 void WKPreferencesSetHyperlinkAuditingEnabled(WKPreferencesRef preferencesRef, bool hyperlinkAuditingEnabled)
154 {
155     toImpl(preferencesRef)->setHyperlinkAuditingEnabled(hyperlinkAuditingEnabled);
156 }
157
158 bool WKPreferencesGetHyperlinkAuditingEnabled(WKPreferencesRef preferencesRef)
159 {
160     return toImpl(preferencesRef)->hyperlinkAuditingEnabled();
161 }
162
163 void WKPreferencesSetStandardFontFamily(WKPreferencesRef preferencesRef, WKStringRef family)
164 {
165     toImpl(preferencesRef)->setStandardFontFamily(toWTFString(family));
166 }
167
168 WKStringRef WKPreferencesCopyStandardFontFamily(WKPreferencesRef preferencesRef)
169 {
170     return toCopiedAPI(toImpl(preferencesRef)->standardFontFamily());
171 }
172
173 void WKPreferencesSetFixedFontFamily(WKPreferencesRef preferencesRef, WKStringRef family)
174 {
175     toImpl(preferencesRef)->setFixedFontFamily(toWTFString(family));
176 }
177
178 WKStringRef WKPreferencesCopyFixedFontFamily(WKPreferencesRef preferencesRef)
179 {
180     return toCopiedAPI(toImpl(preferencesRef)->fixedFontFamily());
181 }
182
183 void WKPreferencesSetSerifFontFamily(WKPreferencesRef preferencesRef, WKStringRef family)
184 {
185     toImpl(preferencesRef)->setSerifFontFamily(toWTFString(family));
186 }
187
188 WKStringRef WKPreferencesCopySerifFontFamily(WKPreferencesRef preferencesRef)
189 {
190     return toCopiedAPI(toImpl(preferencesRef)->serifFontFamily());
191 }
192
193 void WKPreferencesSetSansSerifFontFamily(WKPreferencesRef preferencesRef, WKStringRef family)
194 {
195     toImpl(preferencesRef)->setSansSerifFontFamily(toWTFString(family));
196 }
197
198 WKStringRef WKPreferencesCopySansSerifFontFamily(WKPreferencesRef preferencesRef)
199 {
200     return toCopiedAPI(toImpl(preferencesRef)->sansSerifFontFamily());
201 }
202
203 void WKPreferencesSetCursiveFontFamily(WKPreferencesRef preferencesRef, WKStringRef family)
204 {
205     toImpl(preferencesRef)->setCursiveFontFamily(toWTFString(family));
206 }
207
208 WKStringRef WKPreferencesCopyCursiveFontFamily(WKPreferencesRef preferencesRef)
209 {
210     return toCopiedAPI(toImpl(preferencesRef)->cursiveFontFamily());
211 }
212
213 void WKPreferencesSetFantasyFontFamily(WKPreferencesRef preferencesRef, WKStringRef family)
214 {
215     toImpl(preferencesRef)->setFantasyFontFamily(toWTFString(family));
216 }
217
218 WKStringRef WKPreferencesCopyFantasyFontFamily(WKPreferencesRef preferencesRef)
219 {
220     return toCopiedAPI(toImpl(preferencesRef)->fantasyFontFamily());
221 }
222
223 void WKPreferencesSetDefaultFontSize(WKPreferencesRef preferencesRef, uint32_t size)
224 {
225     toImpl(preferencesRef)->setDefaultFontSize(size);
226 }
227
228 uint32_t WKPreferencesGetDefaultFontSize(WKPreferencesRef preferencesRef)
229 {
230     return toImpl(preferencesRef)->defaultFontSize();
231 }
232
233 void WKPreferencesSetDefaultFixedFontSize(WKPreferencesRef preferencesRef, uint32_t size)
234 {
235     toImpl(preferencesRef)->setDefaultFixedFontSize(size);
236 }
237
238 uint32_t WKPreferencesGetDefaultFixedFontSize(WKPreferencesRef preferencesRef)
239 {
240     return toImpl(preferencesRef)->defaultFixedFontSize();
241 }
242
243 void WKPreferencesSetMinimumFontSize(WKPreferencesRef preferencesRef, uint32_t size)
244 {
245     toImpl(preferencesRef)->setMinimumFontSize(size);
246 }
247
248 uint32_t WKPreferencesGetMinimumFontSize(WKPreferencesRef preferencesRef)
249 {
250     return toImpl(preferencesRef)->minimumFontSize();
251 }
252
253 void WKPreferencesSetDefaultTextEncodingName(WKPreferencesRef preferencesRef, WKStringRef name)
254 {
255     toImpl(preferencesRef)->setDefaultTextEncodingName(toWTFString(name));
256 }
257
258 WKStringRef WKPreferencesCopyDefaultTextEncodingName(WKPreferencesRef preferencesRef)
259 {
260     return toCopiedAPI(toImpl(preferencesRef)->defaultTextEncodingName());
261 }
262
263 void WKPreferencesSetPrivateBrowsingEnabled(WKPreferencesRef preferencesRef, bool enabled)
264 {
265     toImpl(preferencesRef)->setPrivateBrowsingEnabled(enabled);
266 }
267
268 bool WKPreferencesGetPrivateBrowsingEnabled(WKPreferencesRef preferencesRef)
269 {
270     return toImpl(preferencesRef)->privateBrowsingEnabled();
271 }
272
273 void WKPreferencesSetDeveloperExtrasEnabled(WKPreferencesRef preferencesRef, bool enabled)
274 {
275     toImpl(preferencesRef)->setDeveloperExtrasEnabled(enabled);
276 }
277
278 bool WKPreferencesGetDeveloperExtrasEnabled(WKPreferencesRef preferencesRef)
279 {
280     return toImpl(preferencesRef)->developerExtrasEnabled();
281 }
282
283 void WKPreferencesSetTextAreasAreResizable(WKPreferencesRef preferencesRef, bool resizable)
284 {
285     toImpl(preferencesRef)->setTextAreasAreResizable(resizable);
286 }
287
288 bool WKPreferencesGetTextAreasAreResizable(WKPreferencesRef preferencesRef)
289 {
290     return toImpl(preferencesRef)->textAreasAreResizable();
291 }
292
293 void WKPreferencesSetFontSmoothingLevel(WKPreferencesRef preferencesRef, WKFontSmoothingLevel wkLevel)
294 {
295     toImpl(preferencesRef)->setFontSmoothingLevel(toFontSmoothingLevel(wkLevel));
296 }
297
298 WKFontSmoothingLevel WKPreferencesGetFontSmoothingLevel(WKPreferencesRef preferencesRef)
299 {
300     return toAPI(static_cast<FontSmoothingLevel>(toImpl(preferencesRef)->fontSmoothingLevel()));
301 }
302
303 void WKPreferencesSetAcceleratedCompositingEnabled(WKPreferencesRef preferencesRef, bool flag)
304 {
305     toImpl(preferencesRef)->setAcceleratedCompositingEnabled(flag);
306 }
307
308 bool WKPreferencesGetAcceleratedCompositingEnabled(WKPreferencesRef preferencesRef)
309 {
310     return toImpl(preferencesRef)->acceleratedCompositingEnabled();
311 }
312
313 void WKPreferencesSetCompositingBordersVisible(WKPreferencesRef preferencesRef, bool flag)
314 {
315     toImpl(preferencesRef)->setCompositingBordersVisible(flag);
316 }
317
318 bool WKPreferencesGetCompositingBordersVisible(WKPreferencesRef preferencesRef)
319 {
320     return toImpl(preferencesRef)->compositingBordersVisible();
321 }
322
323 void WKPreferencesSetCompositingRepaintCountersVisible(WKPreferencesRef preferencesRef, bool flag)
324 {
325     toImpl(preferencesRef)->setCompositingRepaintCountersVisible(flag);
326 }
327
328 bool WKPreferencesGetCompositingRepaintCountersVisible(WKPreferencesRef preferencesRef)
329 {
330     return toImpl(preferencesRef)->compositingRepaintCountersVisible();
331 }
332
333 void WKPreferencesSetNeedsSiteSpecificQuirks(WKPreferencesRef preferencesRef, bool flag)
334 {
335     toImpl(preferencesRef)->setNeedsSiteSpecificQuirks(flag);
336 }
337
338 bool WKPreferencesGetNeedsSiteSpecificQuirks(WKPreferencesRef preferencesRef)
339 {
340     return toImpl(preferencesRef)->needsSiteSpecificQuirks();
341 }
342
343 void WKPreferencesSetForceFTPDirectoryListings(WKPreferencesRef preferencesRef, bool flag)
344 {
345     toImpl(preferencesRef)->setForceFTPDirectoryListings(flag);
346 }
347
348 bool WKPreferencesGetForceFTPDirectoryListings(WKPreferencesRef preferencesRef)
349 {
350     return toImpl(preferencesRef)->forceFTPDirectoryListings();
351 }
352
353 void WKPreferencesSetFTPDirectoryTemplatePath(WKPreferencesRef preferencesRef, WKStringRef pathRef)
354 {
355     toImpl(preferencesRef)->setFTPDirectoryTemplatePath(toWTFString(pathRef));
356 }
357
358 WKStringRef WKPreferencesCopyFTPDirectoryTemplatePath(WKPreferencesRef preferencesRef)
359 {
360     return toCopiedAPI(toImpl(preferencesRef)->ftpDirectoryTemplatePath());
361 }
362
363 void WKPreferencesSetTabsToLinks(WKPreferencesRef preferencesRef, bool tabsToLinks)
364 {
365     toImpl(preferencesRef)->setTabsToLinks(tabsToLinks);
366 }
367
368 bool WKPreferencesGetTabsToLinks(WKPreferencesRef preferencesRef)
369 {
370     return toImpl(preferencesRef)->tabsToLinks();
371 }
372
373 void WKPreferencesSetDNSPrefetchingEnabled(WKPreferencesRef preferencesRef, bool enabled)
374 {
375     toImpl(preferencesRef)->setDNSPrefetchingEnabled(enabled);
376 }
377
378 bool WKPreferencesGetDNSPrefetchingEnabled(WKPreferencesRef preferencesRef)
379 {
380     return toImpl(preferencesRef)->dnsPrefetchingEnabled();
381 }
382
383 void WKPreferencesSetAuthorAndUserStylesEnabled(WKPreferencesRef preferencesRef, bool enabled)
384 {
385     toImpl(preferencesRef)->setAuthorAndUserStylesEnabled(enabled);
386 }
387
388 bool WKPreferencesGetAuthorAndUserStylesEnabled(WKPreferencesRef preferencesRef)
389 {
390     return toImpl(preferencesRef)->authorAndUserStylesEnabled();
391 }
392
393 void WKPreferencesSetShouldPrintBackgrounds(WKPreferencesRef preferencesRef, bool flag)
394 {
395     toImpl(preferencesRef)->setShouldPrintBackgrounds(flag);
396 }
397
398 bool WKPreferencesGetShouldPrintBackgrounds(WKPreferencesRef preferencesRef)
399 {
400     return toImpl(preferencesRef)->shouldPrintBackgrounds();
401 }
402
403 void WKPreferencesSetWebArchiveDebugModeEnabled(WKPreferencesRef preferencesRef, bool enabled)
404 {
405     toImpl(preferencesRef)->setWebArchiveDebugModeEnabled(enabled);
406 }
407
408 bool WKPreferencesGetWebArchiveDebugModeEnabled(WKPreferencesRef preferencesRef)
409 {
410     return toImpl(preferencesRef)->webArchiveDebugModeEnabled();
411 }
412
413 void WKPreferencesSetLocalFileContentSniffingEnabled(WKPreferencesRef preferencesRef, bool enabled)
414 {
415     toImpl(preferencesRef)->setLocalFileContentSniffingEnabled(enabled);
416 }
417
418 bool WKPreferencesGetLocalFileContentSniffingEnabled(WKPreferencesRef preferencesRef)
419 {
420     return toImpl(preferencesRef)->localFileContentSniffingEnabled();
421 }
422
423 void WKPreferencesSetPageCacheEnabled(WKPreferencesRef preferencesRef, bool enabled)
424 {
425     toImpl(preferencesRef)->setUsesPageCache(enabled);
426 }
427
428 bool WKPreferencesGetPageCacheEnabled(WKPreferencesRef preferencesRef)
429 {
430     return toImpl(preferencesRef)->usesPageCache();
431 }
432
433 void WKPreferencesSetPaginateDuringLayoutEnabled(WKPreferencesRef preferencesRef, bool enabled)
434 {
435     toImpl(preferencesRef)->setPaginateDuringLayoutEnabled(enabled);
436 }
437
438 bool WKPreferencesGetPaginateDuringLayoutEnabled(WKPreferencesRef preferencesRef)
439 {
440     return toImpl(preferencesRef)->paginateDuringLayoutEnabled();
441 }
442
443 void WKPreferencesSetDOMPasteAllowed(WKPreferencesRef preferencesRef, bool enabled)
444 {
445     toImpl(preferencesRef)->setDOMPasteAllowed(enabled);
446 }
447
448 bool WKPreferencesGetDOMPasteAllowed(WKPreferencesRef preferencesRef)
449 {
450     return toImpl(preferencesRef)->domPasteAllowed();
451 }