Skip to content

Commit

Permalink
Move [WKWebViewConfiguration _respectsImageOrientation] to API::PageC…
Browse files Browse the repository at this point in the history
…onfiguration

https://bugs.webkit.org/show_bug.cgi?id=270557
rdar://124115170

Reviewed by Alex Christensen.

This flag already exists in WebPreferences, named "shouldRespectImageOrientation",
so it's just a matter of using it directly through
`API::PageConfiguration::preferences()`.

* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setupPageConfiguration:]):
The flag is already set when copying the WebPreferences pointer above.

* Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration init]):
The flag is already initialized to the same platform-dependent value based on
Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml

(-[WKWebViewConfiguration copyWithZone:]):
The flag is already copied as part of _pageConfiguration's preferences above.

(-[WKWebViewConfiguration _respectsImageOrientation]):
(-[WKWebViewConfiguration _setRespectsImageOrientation:]):
Directly access the flag in _pageConfiguration's preferences through
self.preferences, which ensures it's lazily created if needed.

* Tools/TestWebKitAPI/SourcesCocoa.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/cocoa/TestWKWebViewConfiguration.mm: Added.
(TEST):

Canonical link: https://commits.webkit.org/275929@main
  • Loading branch information
squelart committed Mar 11, 2024
1 parent 01e3f96 commit 19739c6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 13 deletions.
2 changes: 0 additions & 2 deletions Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ - (void)_setupPageConfiguration:(Ref<API::PageConfiguration>&)pageConfiguration
pageConfiguration->setAdditionalSupportedImageTypes(makeVector<String>([_configuration _additionalSupportedImageTypes]));

pageConfiguration->preferences()->setSuppressesIncrementalRendering(!![_configuration suppressesIncrementalRendering]);

pageConfiguration->preferences()->setShouldRespectImageOrientation(!![_configuration _respectsImageOrientation]);
#if !PLATFORM(MAC)
// FIXME: rdar://99156546. Remove this and WKWebViewConfiguration._printsBackgrounds once all iOS clients adopt the new API.
if (!linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::DefaultsToExcludingBackgroundsWhenPrinting))
Expand Down
13 changes: 3 additions & 10 deletions Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#import "APIPageConfiguration.h"
#import "CSPExtensionUtilities.h"
#import "WKPreferencesInternal.h"
#import "WKWebpagePreferencesInternal.h"
#import "WKWebViewContentProviderRegistry.h"
#import "WebKit2Initialize.h"
Expand All @@ -38,7 +39,6 @@
#import "_WKVisitedLinkStore.h"
#import <WebCore/RuntimeApplicationChecks.h>
#import <WebCore/Settings.h>
#import <WebKit/WKPreferences.h>
#import <WebKit/WKProcessPool.h>
#import <WebKit/WKRetainPtr.h>
#import <WebKit/WKUserContentController.h>
Expand Down Expand Up @@ -134,7 +134,6 @@ @implementation WKWebViewConfiguration {
RetainPtr<NSString> _groupIdentifier;
std::optional<RetainPtr<NSString>> _applicationNameForUserAgent;
NSTimeInterval _incrementalRenderingSuppressionTimeout;
BOOL _respectsImageOrientation;
BOOL _allowsJavaScriptMarkup;
BOOL _convertsPositionStyleOnCopy;
BOOL _allowsMetaRefresh;
Expand Down Expand Up @@ -227,12 +226,7 @@ - (instancetype)init
_attachmentElementEnabled = NO;
_attachmentWideLayoutEnabled = NO;

#if PLATFORM(IOS_FAMILY)
_respectsImageOrientation = YES;
#endif

#if PLATFORM(MAC)
_respectsImageOrientation = NO;
_showsURLsInToolTips = NO;
_serviceControlsEnabled = NO;
_imageControlsEnabled = NO;
Expand Down Expand Up @@ -414,7 +408,6 @@ - (id)copyWithZone:(NSZone *)zone
configuration->_suppressesIncrementalRendering = self->_suppressesIncrementalRendering;
configuration->_applicationNameForUserAgent = self->_applicationNameForUserAgent;

configuration->_respectsImageOrientation = self->_respectsImageOrientation;
configuration->_incrementalRenderingSuppressionTimeout = self->_incrementalRenderingSuppressionTimeout;
configuration->_allowsJavaScriptMarkup = self->_allowsJavaScriptMarkup;
configuration->_convertsPositionStyleOnCopy = self->_convertsPositionStyleOnCopy;
Expand Down Expand Up @@ -741,12 +734,12 @@ - (void)_setGroupIdentifier:(NSString *)groupIdentifier

- (BOOL)_respectsImageOrientation
{
return _respectsImageOrientation;
return self.preferences->_preferences->shouldRespectImageOrientation();
}

- (void)_setRespectsImageOrientation:(BOOL)respectsImageOrientation
{
_respectsImageOrientation = respectsImageOrientation;
self.preferences->_preferences->setShouldRespectImageOrientation(respectsImageOrientation);
}

- (BOOL)_printsBackgrounds
Expand Down
3 changes: 2 additions & 1 deletion Tools/TestWebKitAPI/SourcesCocoa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ cocoa/TestNavigationDelegate.mm
cocoa/TestProtocol.mm
cocoa/TestResourceLoadDelegate.mm
cocoa/TestUIDelegate.mm
cocoa/TestWKWebView.mm
cocoa/TestWebExtensionsDelegate.mm
cocoa/TestWKWebView.mm
cocoa/TestWKWebViewConfiguration.mm
cocoa/UserMediaCaptureUIDelegate.mm

Tests/WebKitCocoa/AVFoundationPreference.mm
Expand Down
2 changes: 2 additions & 0 deletions Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,7 @@
2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "input-field-in-scrollable-document.html"; sourceTree = "<group>"; };
2EFF06D21D8AEDBB0004BB30 /* TestWKWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestWKWebView.h; path = cocoa/TestWKWebView.h; sourceTree = "<group>"; };
2EFF06D31D8AEDBB0004BB30 /* TestWKWebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestWKWebView.mm; path = cocoa/TestWKWebView.mm; sourceTree = "<group>"; };
2EFF06D31D8AEDBB0004BB31 /* TestWKWebViewConfiguration.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestWKWebViewConfiguration.mm; path = cocoa/TestWKWebViewConfiguration.mm; sourceTree = "<group>"; };
2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewCandidateTests.mm; sourceTree = "<group>"; };
3128A81223763F0B00D90D40 /* link-with-image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "link-with-image.html"; sourceTree = "<group>"; };
3128A814237640FD00D90D40 /* image.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = image.html; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3905,6 +3906,7 @@
B63EF5462995797F00A190A3 /* TestWebExtensionsDelegate.mm */,
2EFF06D21D8AEDBB0004BB30 /* TestWKWebView.h */,
2EFF06D31D8AEDBB0004BB30 /* TestWKWebView.mm */,
2EFF06D31D8AEDBB0004BB31 /* TestWKWebViewConfiguration.mm */,
41733D7A25DE96DA00A136E5 /* UserMediaCaptureUIDelegate.h */,
41733D7B25DE96DA00A136E5 /* UserMediaCaptureUIDelegate.mm */,
7C83E0391D0A602700FEBCF3 /* UtilitiesCocoa.mm */,
Expand Down
65 changes: 65 additions & 0 deletions Tools/TestWebKitAPI/cocoa/TestWKWebViewConfiguration.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#import "config.h"
#import "Test.h"

#import <WebKit/WKWebViewConfigurationPrivate.h>
#import <WebKit/WKWebViewPrivateForTesting.h>

TEST(WKWebViewConfiguration, FlagsThroughWKWebView)
{
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
auto view = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
BOOL defaultRespectsImageOrientation = [configuration _respectsImageOrientation];
EXPECT_EQ([[view configuration] _respectsImageOrientation], defaultRespectsImageOrientation);
}

{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
BOOL defaultRespectsImageOrientation = [configuration _respectsImageOrientation];
auto view = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
EXPECT_EQ([[view configuration] _respectsImageOrientation], defaultRespectsImageOrientation);
}

{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
BOOL defaultRespectsImageOrientation = [configuration _respectsImageOrientation];
[configuration _setRespectsImageOrientation:!defaultRespectsImageOrientation];
auto view = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
EXPECT_EQ([[view configuration] _respectsImageOrientation], !defaultRespectsImageOrientation);
}

{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
BOOL defaultRespectsImageOrientation = [configuration _respectsImageOrientation];
auto view = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
EXPECT_EQ([[view configuration] _respectsImageOrientation], defaultRespectsImageOrientation);
// Spooky action at a distance, due to API::PageConfiguration::copy() doing a shallow copy and keeping a reference to the same WebPreferences.
[configuration _setRespectsImageOrientation:!defaultRespectsImageOrientation];
EXPECT_EQ([[view configuration] _respectsImageOrientation], !defaultRespectsImageOrientation);
}
}

0 comments on commit 19739c6

Please sign in to comment.