Skip to content

Commit

Permalink
Revert (249987@main, 250226@main and 250267@main): Remove WebArchiveD…
Browse files Browse the repository at this point in the history
…ebugMode

https://bugs.webkit.org/show_bug.cgi?id=245228
<rdar://97580190>

Reviewed by Said Abou-Hallawa.

Changes resulted in too much breakage. Reverting 249987@main, 250226@main and
250267@main.

* Source/WTF/Scripts/Preferences/WebPreferences.yaml:
* Source/WebCore/loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::commitData):
(WebCore::DocumentLoader::scheduleArchiveLoad):
(WebCore::DocumentLoader::isLoadingRemoteArchive const): Deleted.
* Source/WebCore/loader/DocumentLoader.h:
* Source/WebKit/UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetWebArchiveDebugModeEnabled):
(WKPreferencesGetWebArchiveDebugModeEnabled):
(WKPreferencesSetWebArchiveTestingModeEnabled): Deleted.
(WKPreferencesGetWebArchiveTestingModeEnabled): Deleted.
* Source/WebKit/UIProcess/API/C/WKPreferencesRefPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _setWebArchiveDebugModeEnabled:]):
(-[WKPreferences _webArchiveDebugModeEnabled]):
(-[WKPreferences _setWebArchiveTestingModeEnabled:]): Deleted.
(-[WKPreferences _webArchiveTestingModeEnabled]): Deleted.
* Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h:
* Tools/TestWebKitAPI/Tests/mac/LoadWebArchive.mm:
(TestWebKitAPI::constructArchive):
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/254575@main
  • Loading branch information
sysrqb authored and Said Abou-Hallawa committed Sep 16, 2022
1 parent 06d20b1 commit 4949001
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 82 deletions.
11 changes: 0 additions & 11 deletions Source/WTF/Scripts/Preferences/WebPreferences.yaml
Expand Up @@ -2482,17 +2482,6 @@ WebArchiveDebugModeEnabled:
WebCore:
default: false

WebArchiveTestingModeEnabled:
type: bool
condition: ENABLE(WEB_ARCHIVE)
defaultValue:
WebKitLegacy:
default: false
WebKit:
default: false
WebCore:
default: false

WebAudioEnabled:
type: bool
condition: ENABLE(WEB_AUDIO)
Expand Down
32 changes: 6 additions & 26 deletions Source/WebCore/loader/DocumentLoader.cpp
Expand Up @@ -1217,27 +1217,11 @@ static inline bool shouldUseActiveServiceWorkerFromParent(const Document& docume
}
#endif

#if ENABLE(WEB_ARCHIVE)
bool DocumentLoader::isLoadingRemoteArchive() const
{
bool isQuickLookPreview = false;
#if USE(QUICK_LOOK)
isQuickLookPreview = isQuickLookPreviewURL(m_response.url());
#endif
return m_archive && !m_frame->settings().webArchiveTestingModeEnabled() && !isQuickLookPreview;
}
#endif

void DocumentLoader::commitData(const SharedBuffer& data)
{
#if ENABLE(WEB_ARCHIVE)
URL documentOrEmptyURL = isLoadingRemoteArchive() ? URL() : documentURL();
#else
URL documentOrEmptyURL = documentURL();
#endif
if (!m_gotFirstByte) {
m_gotFirstByte = true;
bool hasBegun = m_writer.begin(documentOrEmptyURL, false, nullptr, m_resultingClientId);
bool hasBegun = m_writer.begin(documentURL(), false, nullptr, m_resultingClientId);
if (!hasBegun)
return;

Expand All @@ -1259,12 +1243,9 @@ void DocumentLoader::commitData(const SharedBuffer& data)
if (frameLoader()->stateMachine().creatingInitialEmptyDocument())
return;

#if ENABLE(WEB_ARCHIVE)
if (isLoadingRemoteArchive()) {
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
if (m_archive && m_archive->shouldOverrideBaseURL())
document.setBaseURLOverride(m_archive->mainResource()->url());
if (LegacySchemeRegistry::shouldTreatURLSchemeAsLocal(documentURL().protocol().toStringWithoutCopying()))
document.securityOrigin().grantLoadLocalResources();
}
#endif
#if ENABLE(SERVICE_WORKER)
if (m_canUseServiceWorkers) {
Expand Down Expand Up @@ -1821,11 +1802,10 @@ bool DocumentLoader::scheduleArchiveLoad(ResourceLoader& loader, const ResourceR
return false;

#if ENABLE(WEB_ARCHIVE)
if (isLoadingRemoteArchive()) {
DOCUMENTLOADER_RELEASE_LOG("scheduleArchiveLoad: Failed to unarchive subresource");
loader.didFail(ResourceError(errorDomainWebKitInternal, 0, request.url(), "Failed to unarchive subresource"_s));
// The idea of WebArchiveDebugMode is that we should fail instead of trying to fetch from the network.
// Returning true ensures the caller will not try to fetch from the network.
if (m_frame->settings().webArchiveDebugModeEnabled() && responseMIMEType() == "application/x-webarchive"_s)
return true;
}
#endif

// If we want to load from the archive only, then we should always return true so that the caller
Expand Down
4 changes: 0 additions & 4 deletions Source/WebCore/loader/DocumentLoader.h
Expand Up @@ -507,10 +507,6 @@ class DocumentLoader
void clearArchiveResources();
#endif

#if ENABLE(WEB_ARCHIVE)
bool isLoadingRemoteArchive() const;
#endif

void willSendRequest(ResourceRequest&&, const ResourceResponse&, CompletionHandler<void(ResourceRequest&&)>&&);
void finishedLoading();
void mainReceivedError(const ResourceError&);
Expand Down
17 changes: 4 additions & 13 deletions Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Expand Up @@ -568,14 +568,14 @@ bool WKPreferencesGetDOMTimersThrottlingEnabled(WKPreferencesRef preferencesRef)
return toImpl(preferencesRef)->domTimersThrottlingEnabled();
}

void WKPreferencesSetWebArchiveTestingModeEnabled(WKPreferencesRef preferencesRef, bool enabled)
void WKPreferencesSetWebArchiveDebugModeEnabled(WKPreferencesRef preferencesRef, bool enabled)
{
toImpl(preferencesRef)->setWebArchiveTestingModeEnabled(enabled);
toImpl(preferencesRef)->setWebArchiveDebugModeEnabled(enabled);
}

bool WKPreferencesGetWebArchiveTestingModeEnabled(WKPreferencesRef preferencesRef)
bool WKPreferencesGetWebArchiveDebugModeEnabled(WKPreferencesRef preferencesRef)
{
return toImpl(preferencesRef)->webArchiveTestingModeEnabled();
return toImpl(preferencesRef)->webArchiveDebugModeEnabled();
}

void WKPreferencesSetLocalFileContentSniffingEnabled(WKPreferencesRef preferencesRef, bool enabled)
Expand Down Expand Up @@ -2156,15 +2156,6 @@ bool WKPreferencesGetXSSAuditorEnabled(WKPreferencesRef)
return false;
}

void WKPreferencesSetWebArchiveDebugModeEnabled(WKPreferencesRef preferencesRef, bool enabled)
{
}

bool WKPreferencesGetWebArchiveDebugModeEnabled(WKPreferencesRef preferencesRef)
{
return false;
}

void WKPreferencesSetJavaEnabled(WKPreferencesRef, bool)
{
}
Expand Down
6 changes: 2 additions & 4 deletions Source/WebKit/UIProcess/API/C/WKPreferencesRefPrivate.h
Expand Up @@ -126,8 +126,8 @@ WK_EXPORT void WKPreferencesSetDOMTimersThrottlingEnabled(WKPreferencesRef prefe
WK_EXPORT bool WKPreferencesGetDOMTimersThrottlingEnabled(WKPreferencesRef preferences);

// Defaults to false.
WK_EXPORT void WKPreferencesSetWebArchiveTestingModeEnabled(WKPreferencesRef preferences, bool enabled);
WK_EXPORT bool WKPreferencesGetWebArchiveTestingModeEnabled(WKPreferencesRef preferences);
WK_EXPORT void WKPreferencesSetWebArchiveDebugModeEnabled(WKPreferencesRef preferences, bool enabled);
WK_EXPORT bool WKPreferencesGetWebArchiveDebugModeEnabled(WKPreferencesRef preferences);

// Defaults to false.
WK_EXPORT void WKPreferencesSetLocalFileContentSniffingEnabled(WKPreferencesRef preferences, bool enabled);
Expand Down Expand Up @@ -565,8 +565,6 @@ WK_EXPORT void WKPreferencesSetResourceTimingEnabled(WKPreferencesRef, bool) WK_
WK_EXPORT bool WKPreferencesGetResourceTimingEnabled(WKPreferencesRef) WK_C_API_DEPRECATED;
WK_EXPORT void WKPreferencesSetSubpixelCSSOMElementMetricsEnabled(WKPreferencesRef, bool) WK_C_API_DEPRECATED;
WK_EXPORT bool WKPreferencesGetSubpixelCSSOMElementMetricsEnabled(WKPreferencesRef) WK_C_API_DEPRECATED;
WK_EXPORT void WKPreferencesSetWebArchiveDebugModeEnabled(WKPreferencesRef preferences, bool enabled) WK_C_API_DEPRECATED;
WK_EXPORT bool WKPreferencesGetWebArchiveDebugModeEnabled(WKPreferencesRef preferences) WK_C_API_DEPRECATED;

#ifdef __cplusplus
}
Expand Down
17 changes: 4 additions & 13 deletions Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
Expand Up @@ -992,14 +992,14 @@ - (BOOL)_domTimersThrottlingEnabled
return _preferences->domTimersThrottlingEnabled();
}

- (void)_setWebArchiveTestingModeEnabled:(BOOL)enabled
- (void)_setWebArchiveDebugModeEnabled:(BOOL)enabled
{
_preferences->setWebArchiveTestingModeEnabled(enabled);
_preferences->setWebArchiveDebugModeEnabled(enabled);
}

- (BOOL)_webArchiveTestingModeEnabled
- (BOOL)_webArchiveDebugModeEnabled
{
return _preferences->webArchiveTestingModeEnabled();
return _preferences->webArchiveDebugModeEnabled();
}

- (void)_setLocalFileContentSniffingEnabled:(BOOL)enabled
Expand Down Expand Up @@ -1630,15 +1630,6 @@ - (BOOL)_subpixelCSSOMElementMetricsEnabled
return NO;
}

- (void)_setWebArchiveDebugModeEnabled:(BOOL)enabled
{
}

- (BOOL)_webArchiveDebugModeEnabled
{
return NO;
}

#endif

#if PLATFORM(MAC)
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
Expand Up @@ -186,7 +186,7 @@ typedef NS_ENUM(NSInteger, _WKPitchCorrectionAlgorithm) {
@property (nonatomic, setter=_setDefaultTextEncodingName:) NSString *_defaultTextEncodingName WK_API_AVAILABLE(macos(10.13.4));
@property (nonatomic, setter=_setAuthorAndUserStylesEnabled:) BOOL _authorAndUserStylesEnabled WK_API_AVAILABLE(macos(10.13.4));
@property (nonatomic, setter=_setDOMTimersThrottlingEnabled:) BOOL _domTimersThrottlingEnabled WK_API_AVAILABLE(macos(10.13.4));
@property (nonatomic, setter=_setWebArchiveTestingModeEnabled:) BOOL _webArchiveTestingModeEnabled WK_API_AVAILABLE(macos(13.0));
@property (nonatomic, setter=_setWebArchiveDebugModeEnabled:) BOOL _webArchiveDebugModeEnabled WK_API_AVAILABLE(macos(10.13.4));
@property (nonatomic, setter=_setLocalFileContentSniffingEnabled:) BOOL _localFileContentSniffingEnabled WK_API_AVAILABLE(macos(10.13.4));
@property (nonatomic, setter=_setUsesPageCache:) BOOL _usesPageCache WK_API_AVAILABLE(macos(10.13.4));
@property (nonatomic, setter=_setPageCacheSupportsPlugins:) BOOL _pageCacheSupportsPlugins WK_API_AVAILABLE(macos(10.13.4));
Expand Down Expand Up @@ -231,6 +231,6 @@ typedef NS_ENUM(NSInteger, _WKPitchCorrectionAlgorithm) {
@property (nonatomic, setter=_setRequestAnimationFrameEnabled:) BOOL _requestAnimationFrameEnabled WK_API_DEPRECATED("requestAnimationFrame is always enabled", macos(10.15.4, 13.0), ios(13.4, 16.0));
#if !TARGET_OS_IPHONE
@property (nonatomic, setter=_setSubpixelCSSOMElementMetricsEnabled:) BOOL _subpixelCSSOMElementMetricsEnabled WK_API_DEPRECATED("Subpixel CSSOM element metrics are no longer supported", macos(10.13.4, 10.15));
@property (nonatomic, setter=_setWebArchiveDebugModeEnabled:) BOOL _webArchiveDebugModeEnabled WK_API_DEPRECATED("WebArchive Debug Mode is no longer supported", macos(10.13.4, 13.0));
#endif

@end
13 changes: 4 additions & 9 deletions Tools/TestWebKitAPI/Tests/mac/LoadWebArchive.mm
Expand Up @@ -32,7 +32,6 @@
#import "TestWKWebView.h"
#import <WebKit/WKDragDestinationAction.h>
#import <WebKit/WKNavigationPrivate.h>
#import <WebKit/WKPreferencesPrivate.h>
#import <WebKit/WKWebView.h>
#import <WebKit/WKWebViewConfigurationPrivate.h>
#import <WebKit/WKWebViewPrivate.h>
Expand Down Expand Up @@ -206,9 +205,9 @@ - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWe
EXPECT_WK_STREQ(finalURL, "");
}

static NSData* constructArchive(const char *script)
static NSData* constructArchive()
{
auto *js = [NSString stringWithUTF8String:script];
NSString *js = @"alert('loaded http subresource successfully')";
auto response = adoptNS([[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://download/script.js"] MIMEType:@"application/javascript" expectedContentLength:js.length textEncodingName:@"utf-8"]);
auto responseArchiver = adoptNS([[NSKeyedArchiver alloc] initRequiringSecureCoding:YES]);
[responseArchiver encodeObject:response.get() forKey:@"WebResourceResponse"];
Expand All @@ -233,7 +232,7 @@ - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWe

TEST(LoadWebArchive, HTTPSUpgrade)
{
NSData *data = constructArchive("alert('loaded http subresource successfully')");
NSData *data = constructArchive();

auto webView = adoptNS([WKWebView new]);
[webView loadData:data MIMEType:@"application/x-webarchive" characterEncodingName:@"utf-8" baseURL:[NSURL URLWithString:@"http://download/"]];
Expand All @@ -242,7 +241,7 @@ - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWe

TEST(LoadWebArchive, DisallowedNetworkHosts)
{
NSData *data = constructArchive("alert('loaded http subresource successfully')");
NSData *data = constructArchive();

auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
configuration.get()._allowedNetworkHosts = [NSSet set];
Expand All @@ -253,7 +252,3 @@ - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWe
}

} // namespace TestWebKitAPI

#if USE(APPLE_INTERNAL_SDK)
#import <WebKitAdditions/LoadWebArchiveAdditions.mm>
#endif

0 comments on commit 4949001

Please sign in to comment.