Add simple line layout toggle to MiniBrowser
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / Cocoa / WKPreferences.mm
1 /*
2  * Copyright (C) 2014-2016 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 #import "config.h"
27 #import "WKPreferencesInternal.h"
28
29 #if WK_API_ENABLED
30
31 #import "APIArray.h"
32 #import "WKNSArray.h"
33 #import "WebPreferences.h"
34 #import "_WKExperimentalFeature.h"
35 #import "_WKExperimentalFeatureInternal.h"
36 #import <WebCore/SecurityOrigin.h>
37 #import <wtf/RetainPtr.h>
38
39 @implementation WKPreferences
40
41 - (instancetype)init
42 {
43     if (!(self = [super init]))
44         return nil;
45
46     API::Object::constructInWrapper<WebKit::WebPreferences>(self, String(), "WebKit", "WebKitDebug");
47     return self;
48 }
49
50 - (void)dealloc
51 {
52     _preferences->~WebPreferences();
53
54     [super dealloc];
55 }
56
57 // FIXME: We currently only encode/decode API preferences. We should consider whether we should
58 // encode/decode SPI preferences as well.
59
60 - (void)encodeWithCoder:(NSCoder *)coder
61 {
62     [coder encodeDouble:self.minimumFontSize forKey:@"minimumFontSize"];
63     [coder encodeBool:self.javaScriptEnabled forKey:@"javaScriptEnabled"];
64     [coder encodeBool:self.javaScriptCanOpenWindowsAutomatically forKey:@"javaScriptCanOpenWindowsAutomatically"];
65
66 #if PLATFORM(MAC)
67     [coder encodeBool:self.javaEnabled forKey:@"javaEnabled"];
68     [coder encodeBool:self.plugInsEnabled forKey:@"plugInsEnabled"];
69     [coder encodeBool:self.tabFocusesLinks forKey:@"tabFocusesLinks"];
70 #endif
71 }
72
73 - (instancetype)initWithCoder:(NSCoder *)coder
74 {
75     if (!(self = [self init]))
76         return nil;
77
78     self.minimumFontSize = [coder decodeDoubleForKey:@"minimumFontSize"];
79     self.javaScriptEnabled = [coder decodeBoolForKey:@"javaScriptEnabled"];
80     self.javaScriptCanOpenWindowsAutomatically = [coder decodeBoolForKey:@"javaScriptCanOpenWindowsAutomatically"];
81
82 #if PLATFORM(MAC)
83     self.javaEnabled = [coder decodeBoolForKey:@"javaEnabled"];
84     self.plugInsEnabled = [coder decodeBoolForKey:@"plugInsEnabled"];
85     self.tabFocusesLinks = [coder decodeBoolForKey:@"tabFocusesLinks"];
86 #endif
87
88     return self;
89 }
90
91 - (CGFloat)minimumFontSize
92 {
93     return _preferences->minimumFontSize();
94 }
95
96 - (void)setMinimumFontSize:(CGFloat)minimumFontSize
97 {
98     _preferences->setMinimumFontSize(minimumFontSize);
99 }
100
101 - (BOOL)javaScriptEnabled
102 {
103     return _preferences->javaScriptEnabled();
104 }
105
106 - (void)setJavaScriptEnabled:(BOOL)javaScriptEnabled
107 {
108     _preferences->setJavaScriptEnabled(javaScriptEnabled);
109 }
110
111 - (BOOL)javaScriptCanOpenWindowsAutomatically
112 {
113     return _preferences->javaScriptCanOpenWindowsAutomatically();
114 }
115
116 - (void)setJavaScriptCanOpenWindowsAutomatically:(BOOL)javaScriptCanOpenWindowsAutomatically
117 {
118     _preferences->setJavaScriptCanOpenWindowsAutomatically(javaScriptCanOpenWindowsAutomatically);
119 }
120
121 #pragma mark OS X-specific methods
122
123 #if PLATFORM(MAC)
124
125 - (BOOL)javaEnabled
126 {
127     return _preferences->javaEnabled();
128 }
129
130 - (void)setJavaEnabled:(BOOL)javaEnabled
131 {
132     _preferences->setJavaEnabled(javaEnabled);
133 }
134
135 - (BOOL)plugInsEnabled
136 {
137     return _preferences->pluginsEnabled();
138 }
139
140 - (void)setPlugInsEnabled:(BOOL)plugInsEnabled
141 {
142     _preferences->setPluginsEnabled(plugInsEnabled);
143 }
144
145 - (BOOL)tabFocusesLinks
146 {
147     return _preferences->tabsToLinks();
148 }
149
150 - (void)setTabFocusesLinks:(BOOL)tabFocusesLinks
151 {
152     _preferences->setTabsToLinks(tabFocusesLinks);
153 }
154
155 #endif
156
157 #pragma mark WKObject protocol implementation
158
159 - (API::Object&)_apiObject
160 {
161     return *_preferences;
162 }
163
164 @end
165
166 @implementation WKPreferences (WKPrivate)
167
168 - (BOOL)_telephoneNumberDetectionIsEnabled
169 {
170     return _preferences->telephoneNumberParsingEnabled();
171 }
172
173 - (void)_setTelephoneNumberDetectionIsEnabled:(BOOL)telephoneNumberDetectionIsEnabled
174 {
175     _preferences->setTelephoneNumberParsingEnabled(telephoneNumberDetectionIsEnabled);
176 }
177
178 static WebCore::SecurityOrigin::StorageBlockingPolicy toStorageBlockingPolicy(_WKStorageBlockingPolicy policy)
179 {
180     switch (policy) {
181     case _WKStorageBlockingPolicyAllowAll:
182         return WebCore::SecurityOrigin::AllowAllStorage;
183     case _WKStorageBlockingPolicyBlockThirdParty:
184         return WebCore::SecurityOrigin::BlockThirdPartyStorage;
185     case _WKStorageBlockingPolicyBlockAll:
186         return WebCore::SecurityOrigin::BlockAllStorage;
187     }
188
189     ASSERT_NOT_REACHED();
190     return WebCore::SecurityOrigin::AllowAllStorage;
191 }
192
193 static _WKStorageBlockingPolicy toAPI(WebCore::SecurityOrigin::StorageBlockingPolicy policy)
194 {
195     switch (policy) {
196     case WebCore::SecurityOrigin::AllowAllStorage:
197         return _WKStorageBlockingPolicyAllowAll;
198     case WebCore::SecurityOrigin::BlockThirdPartyStorage:
199         return _WKStorageBlockingPolicyBlockThirdParty;
200     case WebCore::SecurityOrigin::BlockAllStorage:
201         return _WKStorageBlockingPolicyBlockAll;
202     }
203
204     ASSERT_NOT_REACHED();
205     return _WKStorageBlockingPolicyAllowAll;
206 }
207
208 - (_WKStorageBlockingPolicy)_storageBlockingPolicy
209 {
210     return toAPI(static_cast<WebCore::SecurityOrigin::StorageBlockingPolicy>(_preferences->storageBlockingPolicy()));
211 }
212
213 - (void)_setStorageBlockingPolicy:(_WKStorageBlockingPolicy)policy
214 {
215     _preferences->setStorageBlockingPolicy(toStorageBlockingPolicy(policy));
216 }
217
218 - (BOOL)_offlineApplicationCacheIsEnabled
219 {
220     return _preferences->offlineWebApplicationCacheEnabled();
221 }
222
223 - (void)_setOfflineApplicationCacheIsEnabled:(BOOL)offlineApplicationCacheIsEnabled
224 {
225     _preferences->setOfflineWebApplicationCacheEnabled(offlineApplicationCacheIsEnabled);
226 }
227
228 - (BOOL)_fullScreenEnabled
229 {
230     return _preferences->fullScreenEnabled();
231 }
232
233 - (void)_setFullScreenEnabled:(BOOL)fullScreenEnabled
234 {
235     _preferences->setFullScreenEnabled(fullScreenEnabled);
236 }
237
238 - (BOOL)_compositingBordersVisible
239 {
240     return _preferences->compositingBordersVisible();
241 }
242
243 - (void)_setCompositingBordersVisible:(BOOL)compositingBordersVisible
244 {
245     _preferences->setCompositingBordersVisible(compositingBordersVisible);
246 }
247
248 - (BOOL)_compositingRepaintCountersVisible
249 {
250     return _preferences->compositingRepaintCountersVisible();
251 }
252
253 - (void)_setCompositingRepaintCountersVisible:(BOOL)repaintCountersVisible
254 {
255     _preferences->setCompositingRepaintCountersVisible(repaintCountersVisible);
256 }
257
258 - (BOOL)_tiledScrollingIndicatorVisible
259 {
260     return _preferences->tiledScrollingIndicatorVisible();
261 }
262
263 - (void)_setTiledScrollingIndicatorVisible:(BOOL)tiledScrollingIndicatorVisible
264 {
265     _preferences->setTiledScrollingIndicatorVisible(tiledScrollingIndicatorVisible);
266 }
267
268 - (BOOL)_resourceUsageOverlayVisible
269 {
270     return _preferences->resourceUsageOverlayVisible();
271 }
272
273 - (void)_setResourceUsageOverlayVisible:(BOOL)resourceUsageOverlayVisible
274 {
275     _preferences->setResourceUsageOverlayVisible(resourceUsageOverlayVisible);
276 }
277
278 - (_WKDebugOverlayRegions)_visibleDebugOverlayRegions
279 {
280     return _preferences->visibleDebugOverlayRegions();
281 }
282
283 - (void)_setVisibleDebugOverlayRegions:(_WKDebugOverlayRegions)regionFlags
284 {
285     _preferences->setVisibleDebugOverlayRegions(regionFlags);
286 }
287
288 - (BOOL)_simpleLineLayoutEnabled
289 {
290     return _preferences->simpleLineLayoutEnabled();
291 }
292
293 - (void)_setSimpleLineLayoutEnabled:(BOOL)simpleLineLayoutEnabled
294 {
295     _preferences->setSimpleLineLayoutEnabled(simpleLineLayoutEnabled);
296 }
297
298 - (BOOL)_simpleLineLayoutDebugBordersEnabled
299 {
300     return _preferences->simpleLineLayoutDebugBordersEnabled();
301 }
302
303 - (void)_setSimpleLineLayoutDebugBordersEnabled:(BOOL)simpleLineLayoutDebugBordersEnabled
304 {
305     _preferences->setSimpleLineLayoutDebugBordersEnabled(simpleLineLayoutDebugBordersEnabled);
306 }
307
308 - (BOOL)_acceleratedDrawingEnabled
309 {
310     return _preferences->acceleratedDrawingEnabled();
311 }
312
313 - (void)_setAcceleratedDrawingEnabled:(BOOL)acceleratedDrawingEnabled
314 {
315     _preferences->setAcceleratedDrawingEnabled(acceleratedDrawingEnabled);
316 }
317
318 - (BOOL)_displayListDrawingEnabled
319 {
320     return _preferences->displayListDrawingEnabled();
321 }
322
323 - (void)_setDisplayListDrawingEnabled:(BOOL)displayListDrawingEnabled
324 {
325     _preferences->setDisplayListDrawingEnabled(displayListDrawingEnabled);
326 }
327
328 - (BOOL)_visualViewportEnabled
329 {
330     return _preferences->visualViewportEnabled();
331 }
332
333 - (void)_setVisualViewportEnabled:(BOOL)_visualViewportEnabled
334 {
335     _preferences->setVisualViewportEnabled(_visualViewportEnabled);
336 }
337
338 - (BOOL)_largeImageAsyncDecodingEnabled
339 {
340     return _preferences->largeImageAsyncDecodingEnabled();
341 }
342
343 - (void)_setLargeImageAsyncDecodingEnabled:(BOOL)_largeImageAsyncDecodingEnabled
344 {
345     _preferences->setLargeImageAsyncDecodingEnabled(_largeImageAsyncDecodingEnabled);
346 }
347
348 - (BOOL)_animatedImageAsyncDecodingEnabled
349 {
350     return _preferences->animatedImageAsyncDecodingEnabled();
351 }
352
353 - (void)_setAnimatedImageAsyncDecodingEnabled:(BOOL)_animatedImageAsyncDecodingEnabled
354 {
355     _preferences->setAnimatedImageAsyncDecodingEnabled(_animatedImageAsyncDecodingEnabled);
356 }
357
358 - (BOOL)_textAutosizingEnabled
359 {
360     return _preferences->textAutosizingEnabled();
361 }
362
363 - (void)_setTextAutosizingEnabled:(BOOL)enabled
364 {
365     _preferences->setTextAutosizingEnabled(enabled);
366 }
367
368 - (BOOL)_developerExtrasEnabled
369 {
370     return _preferences->developerExtrasEnabled();
371 }
372
373 - (void)_setDeveloperExtrasEnabled:(BOOL)developerExtrasEnabled
374 {
375     _preferences->setDeveloperExtrasEnabled(developerExtrasEnabled);
376 }
377
378 - (BOOL)_logsPageMessagesToSystemConsoleEnabled
379 {
380     return _preferences->logsPageMessagesToSystemConsoleEnabled();
381 }
382
383 - (void)_setLogsPageMessagesToSystemConsoleEnabled:(BOOL)logsPageMessagesToSystemConsoleEnabled
384 {
385     _preferences->setLogsPageMessagesToSystemConsoleEnabled(logsPageMessagesToSystemConsoleEnabled);
386 }
387
388 - (BOOL)_hiddenPageDOMTimerThrottlingEnabled
389 {
390     return _preferences->hiddenPageDOMTimerThrottlingEnabled();
391 }
392
393 - (void)_setHiddenPageDOMTimerThrottlingEnabled:(BOOL)hiddenPageDOMTimerThrottlingEnabled
394 {
395     _preferences->setHiddenPageDOMTimerThrottlingEnabled(hiddenPageDOMTimerThrottlingEnabled);
396 }
397
398 - (BOOL)_hiddenPageDOMTimerThrottlingAutoIncreases
399 {
400     return _preferences->hiddenPageDOMTimerThrottlingAutoIncreases();
401 }
402
403 - (void)_setHiddenPageDOMTimerThrottlingAutoIncreases:(BOOL)hiddenPageDOMTimerThrottlingAutoIncreases
404 {
405     _preferences->setHiddenPageDOMTimerThrottlingAutoIncreases(hiddenPageDOMTimerThrottlingAutoIncreases);
406 }
407
408 - (BOOL)_pageVisibilityBasedProcessSuppressionEnabled
409 {
410     return _preferences->pageVisibilityBasedProcessSuppressionEnabled();
411 }
412
413 - (void)_setPageVisibilityBasedProcessSuppressionEnabled:(BOOL)pageVisibilityBasedProcessSuppressionEnabled
414 {
415     _preferences->setPageVisibilityBasedProcessSuppressionEnabled(pageVisibilityBasedProcessSuppressionEnabled);
416 }
417
418 - (BOOL)_allowFileAccessFromFileURLs
419 {
420     return _preferences->allowFileAccessFromFileURLs();
421 }
422
423 - (void)_setAllowFileAccessFromFileURLs:(BOOL)allowFileAccessFromFileURLs
424 {
425     _preferences->setAllowFileAccessFromFileURLs(allowFileAccessFromFileURLs);
426 }
427
428 - (_WKJavaScriptRuntimeFlags)_javaScriptRuntimeFlags
429 {
430     return _preferences->javaScriptRuntimeFlags();
431 }
432
433 - (void)_setJavaScriptRuntimeFlags:(_WKJavaScriptRuntimeFlags)javaScriptRuntimeFlags
434 {
435     _preferences->setJavaScriptRuntimeFlags(javaScriptRuntimeFlags);
436 }
437
438 - (BOOL)_isStandalone
439 {
440     return _preferences->standalone();
441 }
442
443 - (void)_setStandalone:(BOOL)standalone
444 {
445     _preferences->setStandalone(standalone);
446 }
447
448 - (BOOL)_diagnosticLoggingEnabled
449 {
450     return _preferences->diagnosticLoggingEnabled();
451 }
452
453 - (void)_setDiagnosticLoggingEnabled:(BOOL)diagnosticLoggingEnabled
454 {
455     _preferences->setDiagnosticLoggingEnabled(diagnosticLoggingEnabled);
456 }
457
458 - (NSUInteger)_defaultFontSize
459 {
460     return _preferences->defaultFontSize();
461 }
462
463 - (void)_setDefaultFontSize:(NSUInteger)defaultFontSize
464 {
465     _preferences->setDefaultFontSize(defaultFontSize);
466 }
467
468 - (NSUInteger)_defaultFixedPitchFontSize
469 {
470     return _preferences->defaultFixedFontSize();
471 }
472
473 - (void)_setDefaultFixedPitchFontSize:(NSUInteger)defaultFixedPitchFontSize
474 {
475     _preferences->setDefaultFixedFontSize(defaultFixedPitchFontSize);
476 }
477
478 - (NSString *)_fixedPitchFontFamily
479 {
480     return _preferences->fixedFontFamily();
481 }
482
483 - (void)_setFixedPitchFontFamily:(NSString *)fixedPitchFontFamily
484 {
485     _preferences->setFixedFontFamily(fixedPitchFontFamily);
486 }
487
488 + (NSArray<_WKExperimentalFeature *> *)_experimentalFeatures
489 {
490     auto features = WebKit::WebPreferences::experimentalFeatures();
491     return [wrapper(API::Array::create(WTFMove(features)).leakRef()) autorelease];
492 }
493
494 - (BOOL)_isEnabledForFeature:(_WKExperimentalFeature *)feature
495 {
496     return _preferences->isEnabledForFeature(*feature->_experimentalFeature);
497 }
498
499 - (void)_setEnabled:(BOOL)value forFeature:(_WKExperimentalFeature *)feature
500 {
501     _preferences->setEnabledForFeature(value, *feature->_experimentalFeature);
502 }
503
504 - (BOOL)_applePayCapabilityDisclosureAllowed
505 {
506 #if ENABLE(APPLE_PAY)
507     return _preferences->applePayCapabilityDisclosureAllowed();
508 #else
509     return NO;
510 #endif
511 }
512
513 - (void)_setApplePayCapabilityDisclosureAllowed:(BOOL)applePayCapabilityDisclosureAllowed
514 {
515 #if ENABLE(APPLE_PAY)
516     _preferences->setApplePayCapabilityDisclosureAllowed(applePayCapabilityDisclosureAllowed);
517 #endif
518 }
519
520 - (BOOL)_shouldSuppressKeyboardInputDuringProvisionalNavigation
521 {
522     return _preferences->shouldSuppressKeyboardInputDuringProvisionalNavigation();
523 }
524
525 - (void)_setShouldSuppressKeyboardInputDuringProvisionalNavigation:(BOOL)shouldSuppress
526 {
527     _preferences->setShouldSuppressKeyboardInputDuringProvisionalNavigation(shouldSuppress);
528 }
529
530 - (BOOL)_loadsImagesAutomatically
531 {
532     return _preferences->loadsImagesAutomatically();
533 }
534
535 - (void)_setLoadsImagesAutomatically:(BOOL)loadsImagesAutomatically
536 {
537     _preferences->setLoadsImagesAutomatically(loadsImagesAutomatically);
538 }
539
540 @end
541
542 #endif // WK_API_ENABLED