Skip to content

Commit

Permalink
Revert 1eb4751. rdar://problem/88406961
Browse files Browse the repository at this point in the history
  • Loading branch information
alancoon committed Nov 14, 2022
1 parent a35ac4c commit 3ab269b
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 167 deletions.
Expand Up @@ -6,11 +6,11 @@ frame "<!--frame1-->" - didStartProvisionalLoadForFrame
resources/subresource-null-mimetype.webarchive - willSendRequest <NSURLRequest URL resources/subresource-null-mimetype.webarchive, main document URL test-loading-archive-subresource-null-mimetype.html, http method GET> redirectResponse (null)
resources/subresource-null-mimetype.webarchive - didReceiveResponse <NSURLResponse resources/subresource-null-mimetype.webarchive, http status code 0>
frame "<!--frame1-->" - didCommitLoadForFrame
webarchive+file:///test.png - willSendRequest <NSURLRequest URL webarchive+file:///test.png, main document URL test-loading-archive-subresource-null-mimetype.html, http method GET> redirectResponse (null)
test.png - willSendRequest <NSURLRequest URL test.png, main document URL test-loading-archive-subresource-null-mimetype.html, http method GET> redirectResponse (null)
frame "<!--frame1-->" - didFinishDocumentLoadForFrame
resources/subresource-null-mimetype.webarchive - didFinishLoading
webarchive+file:///test.png - didReceiveResponse <NSURLResponse webarchive+file:///test.png, http status code 0>
webarchive+file:///test.png - didFinishLoading
test.png - didReceiveResponse <NSURLResponse test.png, http status code 0>
test.png - didFinishLoading
frame "<!--frame1-->" - didHandleOnloadEventsForFrame
main frame - didHandleOnloadEventsForFrame
frame "<!--frame1-->" - didFinishLoadForFrame
Expand Down
Expand Up @@ -6,11 +6,11 @@ main frame - didFinishDocumentLoadForFrame
test-loading-archive-subresource-null-mimetype.html - didFinishLoading
resources/subresource-null-mimetype.webarchive - didReceiveResponse <NSURLResponse resources/subresource-null-mimetype.webarchive, http status code 0>
frame "<!--frame1-->" - didCommitLoadForFrame
webarchive+file:///test.png - willSendRequest <NSURLRequest URL webarchive+file:///test.png, main document URL test-loading-archive-subresource-null-mimetype.html, http method GET> redirectResponse (null)
test.png - willSendRequest <NSURLRequest URL test.png, main document URL test-loading-archive-subresource-null-mimetype.html, http method GET> redirectResponse (null)
frame "<!--frame1-->" - didFinishDocumentLoadForFrame
resources/subresource-null-mimetype.webarchive - didFinishLoading
webarchive+file:///test.png - didReceiveResponse <NSURLResponse webarchive+file:///test.png, http status code 0>
webarchive+file:///test.png - didFinishLoading
test.png - didReceiveResponse <NSURLResponse test.png, http status code 0>
test.png - didFinishLoading
frame "<!--frame1-->" - didHandleOnloadEventsForFrame
main frame - didHandleOnloadEventsForFrame
frame "<!--frame1-->" - didFinishLoadForFrame
Expand Down
11 changes: 0 additions & 11 deletions Source/WTF/Scripts/Preferences/WebPreferences.yaml
Expand Up @@ -2481,17 +2481,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
2 changes: 1 addition & 1 deletion Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Expand Up @@ -429,7 +429,7 @@ static void replaceRichContentWithAttachments(Frame& frame, DocumentFragment& fr

static std::optional<MarkupAndArchive> extractMarkupAndArchive(SharedBuffer& buffer, const std::function<bool(const String)>& canShowMIMETypeAsHTML)
{
auto archive = LegacyWebArchive::create(buffer);
auto archive = LegacyWebArchive::create(URL(), buffer);
if (!archive)
return std::nullopt;

Expand Down
40 changes: 9 additions & 31 deletions Source/WebCore/loader/DocumentLoader.cpp
Expand Up @@ -1212,21 +1212,6 @@ static inline bool shouldUseActiveServiceWorkerFromParent(const Document& docume
}
#endif

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

void DocumentLoader::commitData(const SharedBuffer& data)
{
if (!m_gotFirstByte) {
Expand Down Expand Up @@ -1254,21 +1239,9 @@ void DocumentLoader::commitData(const SharedBuffer& data)
return;

#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
if (isLoadingRemoteArchive()) {
auto& url { m_archive->mainResource()->url() };
if (m_archive->shouldOverrideBaseURL())
document.setBaseURLOverride(url);
#if ENABLE(WEB_ARCHIVE)
constexpr auto webArchivePrefix { "webarchive+"_s };
if (url.protocol().startsWith(webArchivePrefix)) {
auto unprefixedScheme { url.protocol().substring(webArchivePrefix.length()) };
if (LegacySchemeRegistry::shouldTreatURLSchemeAsLocal(unprefixedScheme.toStringWithoutCopying()))
document.securityOrigin().grantLoadLocalResources();
}
#endif // WEB_ARCHIVE
}
#endif // WEB_ARCHIVE || MHTML

if (m_archive && m_archive->shouldOverrideBaseURL())
document.setBaseURLOverride(m_archive->mainResource()->url());
#endif
#if ENABLE(SERVICE_WORKER)
if (m_canUseServiceWorkers) {
if (!document.securityOrigin().isUnique()) {
Expand Down Expand Up @@ -1819,7 +1792,12 @@ bool DocumentLoader::scheduleArchiveLoad(ResourceLoader& loader, const ResourceR
if (!m_archive)
return false;

DOCUMENTLOADER_RELEASE_LOG("scheduleArchiveLoad: Failed to unarchive subresource");
#if ENABLE(WEB_ARCHIVE)
// 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
// does not try to fetch from the network.
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) || ENABLE(MHTML)
bool isLoadingRemoteArchive() const;
#endif

void willSendRequest(ResourceRequest&&, const ResourceResponse&, CompletionHandler<void(ResourceRequest&&)>&&);
void finishedLoading();
void mainReceivedError(const ResourceError&);
Expand Down
10 changes: 0 additions & 10 deletions Source/WebCore/loader/ResourceLoader.cpp
Expand Up @@ -222,16 +222,6 @@ void ResourceLoader::start()
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
if (m_documentLoader && m_documentLoader->scheduleArchiveLoad(*this, m_request))
return;

#if ENABLE(WEB_ARCHIVE)
constexpr auto webArchivePrefix { "webarchive+"_s };
if (m_request.url().protocol().startsWith(webArchivePrefix)) {
auto url { m_request.url() };
const auto unprefixedScheme { url.protocol().substring(webArchivePrefix.length()) };
url.setProtocol(unprefixedScheme);
m_request.setURL(url);
}
#endif
#endif

if (m_documentLoader && m_documentLoader->applicationCacheHost().maybeLoadResource(*this, m_request, m_request.url()))
Expand Down
33 changes: 7 additions & 26 deletions Source/WebCore/loader/archive/ArchiveResourceCollection.cpp
Expand Up @@ -33,10 +33,6 @@

namespace WebCore {

#if ENABLE(WEB_ARCHIVE) && USE(CF)
constexpr auto webArchivePrefix { "webarchive+"_s };
#endif

void ArchiveResourceCollection::addAllResources(Archive& archive)
{
for (auto& subresource : archive.subresources())
Expand All @@ -57,34 +53,19 @@ void ArchiveResourceCollection::addAllResources(Archive& archive)
// Can we change the design in a manner that will let us deprecate that API without reducing functionality of those apps?
void ArchiveResourceCollection::addResource(Ref<ArchiveResource>&& resource)
{
#if ENABLE(WEB_ARCHIVE) && USE(CF)
const bool addPrefix = !resource->url().protocol().startsWith(webArchivePrefix);
const auto prefix { addPrefix ? webArchivePrefix : ""_s };
const auto subresourceKey { String { prefix + resource->url().string() } };
#else
const auto& subresourceKey = resource->url().string();
#endif
m_subresources.set(subresourceKey, WTFMove(resource));
auto& url = resource->url();
m_subresources.set(url.string(), WTFMove(resource));
}

ArchiveResource* ArchiveResourceCollection::archiveResourceForURL(URL url)
ArchiveResource* ArchiveResourceCollection::archiveResourceForURL(const URL& url)
{
#if ENABLE(WEB_ARCHIVE) && USE(CF)
const auto httpsScheme = String { webArchivePrefix + "https"_str };
const auto httpScheme = String { webArchivePrefix + "http"_str };
if (!url.protocol().startsWith(webArchivePrefix))
url.setProtocol(String { webArchivePrefix + url.protocol() });
#else
constexpr auto httpsScheme = "https"_s;
constexpr auto httpScheme = "http"_s;
#endif

if (auto* resource = m_subresources.get(url.string()))
return resource;
if (!url.protocolIs(httpsScheme))
if (!url.protocolIs("https"_s))
return nullptr;
url.setProtocol(httpScheme);
return m_subresources.get(url.string());
URL httpURL = url;
httpURL.setProtocol("http"_s);
return m_subresources.get(httpURL.string());
}

RefPtr<Archive> ArchiveResourceCollection::popSubframeArchive(const String& frameName, const URL& url)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/archive/ArchiveResourceCollection.h
Expand Up @@ -48,7 +48,7 @@ class ArchiveResourceCollection {
void addResource(Ref<ArchiveResource>&&);
void addAllResources(Archive&);

WEBCORE_EXPORT ArchiveResource* archiveResourceForURL(URL);
WEBCORE_EXPORT ArchiveResource* archiveResourceForURL(const URL&);
RefPtr<Archive> popSubframeArchive(const String& frameName, const URL&);

private:
Expand Down
29 changes: 10 additions & 19 deletions Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp
Expand Up @@ -172,7 +172,7 @@ ResourceResponse LegacyWebArchive::createResourceResponseFromPropertyListData(CF
return ResourceResponse();
}

RefPtr<ArchiveResource> LegacyWebArchive::createResource(CFDictionaryRef dictionary, const UsePrefixedScheme usePrefixedScheme)
RefPtr<ArchiveResource> LegacyWebArchive::createResource(CFDictionaryRef dictionary)
{
ASSERT(dictionary);
if (!dictionary)
Expand All @@ -196,16 +196,12 @@ RefPtr<ArchiveResource> LegacyWebArchive::createResource(CFDictionaryRef diction
return nullptr;
}

const auto cfURL = static_cast<CFStringRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceURLKey));
if (cfURL && CFGetTypeID(cfURL) != CFStringGetTypeID()) {
auto url = static_cast<CFStringRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceURLKey));
if (url && CFGetTypeID(url) != CFStringGetTypeID()) {
LOG(Archives, "LegacyWebArchive - URL is not of type CFString, cannot create invalid resource");
return nullptr;
}

const String stringURL { cfURL };
const auto schemePrefix = usePrefixedScheme == UsePrefixedScheme::Yes ? "webarchive+"_s : ""_s;
const URL url { schemePrefix + stringURL };

auto textEncoding = static_cast<CFStringRef>(CFDictionaryGetValue(dictionary, LegacyWebArchiveResourceTextEncodingNameKey));
if (textEncoding && CFGetTypeID(textEncoding) != CFStringGetTypeID()) {
LOG(Archives, "LegacyWebArchive - Text encoding is not of type CFString, cannot create invalid resource");
Expand All @@ -229,7 +225,7 @@ RefPtr<ArchiveResource> LegacyWebArchive::createResource(CFDictionaryRef diction
response = createResourceResponseFromPropertyListData(resourceResponseData, resourceResponseVersion);
}

return ArchiveResource::create(SharedBuffer::create(resourceData), url, mimeType, textEncoding, frameName, response);
return ArchiveResource::create(SharedBuffer::create(resourceData), URL { url }, mimeType, textEncoding, frameName, response);
}

Ref<LegacyWebArchive> LegacyWebArchive::create()
Expand All @@ -254,15 +250,10 @@ Ref<LegacyWebArchive> LegacyWebArchive::create(Ref<ArchiveResource>&& mainResour

RefPtr<LegacyWebArchive> LegacyWebArchive::create(FragmentedSharedBuffer& data)
{
return create(URL(), data, UsePrefixedScheme::No);
return create(URL(), data);
}

RefPtr<LegacyWebArchive> LegacyWebArchive::create(const URL&, FragmentedSharedBuffer& data)
{
return create(URL(), data, UsePrefixedScheme::Yes);
}

RefPtr<LegacyWebArchive> LegacyWebArchive::create(const URL&, FragmentedSharedBuffer& data, const UsePrefixedScheme usePrefixedScheme)
{
LOG(Archives, "LegacyWebArchive - Creating from raw data");

Expand Down Expand Up @@ -291,13 +282,13 @@ RefPtr<LegacyWebArchive> LegacyWebArchive::create(const URL&, FragmentedSharedBu
return nullptr;
}

if (!archive->extract(plist.get(), usePrefixedScheme))
if (!archive->extract(plist.get()))
return nullptr;

return WTFMove(archive);
}

bool LegacyWebArchive::extract(CFDictionaryRef dictionary, const UsePrefixedScheme usePrefixedScheme)
bool LegacyWebArchive::extract(CFDictionaryRef dictionary)
{
ASSERT(dictionary);
if (!dictionary) {
Expand All @@ -315,7 +306,7 @@ bool LegacyWebArchive::extract(CFDictionaryRef dictionary, const UsePrefixedSche
return false;
}

auto mainResource = createResource(mainResourceDict, usePrefixedScheme);
auto mainResource = createResource(mainResourceDict);
if (!mainResource) {
LOG(Archives, "LegacyWebArchive - Failed to parse main resource from CFDictionary or main resource does not exist, aborting invalid WebArchive");
return false;
Expand Down Expand Up @@ -343,7 +334,7 @@ bool LegacyWebArchive::extract(CFDictionaryRef dictionary, const UsePrefixedSche
return false;
}

if (auto subresource = createResource(subresourceDict, usePrefixedScheme))
if (auto subresource = createResource(subresourceDict))
addSubresource(subresource.releaseNonNull());
}
}
Expand All @@ -364,7 +355,7 @@ bool LegacyWebArchive::extract(CFDictionaryRef dictionary, const UsePrefixedSche
}

auto subframeArchive = create();
if (subframeArchive->extract(subframeDict, usePrefixedScheme))
if (subframeArchive->extract(subframeDict))
addSubframeArchive(WTFMove(subframeArchive));
else
LOG(Archives, "LegacyWebArchive - Invalid subframe archive skipped");
Expand Down
7 changes: 2 additions & 5 deletions Source/WebCore/loader/archive/cf/LegacyWebArchive.h
Expand Up @@ -52,8 +52,6 @@ class LegacyWebArchive final : public Archive {
WEBCORE_EXPORT RetainPtr<CFDataRef> rawDataRepresentation();

private:
enum class UsePrefixedScheme : bool { No, Yes };

LegacyWebArchive() = default;

bool shouldLoadFromArchiveOnly() const final { return false; }
Expand All @@ -63,16 +61,15 @@ class LegacyWebArchive final : public Archive {

enum MainResourceStatus { Subresource, MainResource };

static RefPtr<LegacyWebArchive> create(const URL&, FragmentedSharedBuffer&, const UsePrefixedScheme);
static RefPtr<LegacyWebArchive> create(const String& markupString, Frame&, const Vector<Node*>& nodes, Function<bool(Frame&)>&& frameFilter);
static RefPtr<ArchiveResource> createResource(CFDictionaryRef, const UsePrefixedScheme);
static RefPtr<ArchiveResource> createResource(CFDictionaryRef);
static ResourceResponse createResourceResponseFromMacArchivedData(CFDataRef);
static ResourceResponse createResourceResponseFromPropertyListData(CFDataRef, CFStringRef responseDataType);
static RetainPtr<CFDataRef> createPropertyListRepresentation(const ResourceResponse&);
static RetainPtr<CFDictionaryRef> createPropertyListRepresentation(Archive&);
static RetainPtr<CFDictionaryRef> createPropertyListRepresentation(ArchiveResource*, MainResourceStatus);

bool extract(CFDictionaryRef, const UsePrefixedScheme);
bool extract(CFDictionaryRef);
};

} // namespace WebCore
5 changes: 0 additions & 5 deletions Source/WebCore/page/SecurityOrigin.cpp
Expand Up @@ -119,11 +119,6 @@ static bool shouldTreatAsUniqueOrigin(const URL& url)
|| url.protocolIs("x-apple-ql-id2"_s)
|| url.protocolIs("x-apple-ql-magic"_s)
#endif
#if ENABLE(WEB_ARCHIVE) && USE(CF)
|| url.protocolIs("webarchive+http"_s)
|| url.protocolIs("webarchive+https"_s)
|| url.protocolIs("webarchive+ftp"_s)
#endif
#if PLATFORM(GTK) || PLATFORM(WPE)
|| url.protocolIs("resource"_s)
#if ENABLE(PDFJS)
Expand Down
17 changes: 4 additions & 13 deletions Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Expand Up @@ -555,14 +555,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 @@ -2143,15 +2143,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 @@ -124,8 +124,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 @@ -563,8 +563,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

0 comments on commit 3ab269b

Please sign in to comment.