Diff
Modified: trunk/Source/WebCore/ChangeLog (289548 => 289549)
--- trunk/Source/WebCore/ChangeLog 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/ChangeLog 2022-02-10 17:49:26 UTC (rev 289549)
@@ -1,3 +1,34 @@
+2022-02-10 Tim Nguyen <[email protected]>
+
+ Add webkit-pdfjs-viewer scheme for PDF.js resources
+ https://bugs.webkit.org/show_bug.cgi?id=236062
+
+ Reviewed by Youenn Fablet.
+
+ The code handling the scheme is under WebCore::BundleResourceLoader.
+ It reads files from the pdfjs/ sub-folder in the WebCore.framework resources folder.
+ Right now, this sub-folder does not exist yet, but this scheme can be tested by manually populating it.
+
+ Bug 235981 will take care of populating this folder at build-time.
+
+ Note: This scheme can only be loaded inside a PDFDocument <iframe>
+
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * html/PDFDocument.cpp:
+ (WebCore::PDFDocument::createDocumentStructure):
+ * loader/cocoa/BundleResourceLoader.mm: Added
+ * loader/cocoa/BundleResourceLoader.h: Added
+ * loader/PolicyChecker.cpp:
+ (WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
+ * loader/ResourceLoader.cpp:
+ (WebCore::ResourceLoader::start):
+ (WebCore::ResourceLoader::isPDFJSResourceLoad const):
+ * loader/ResourceLoader.h:
+ * loader/SubresourceLoader.h:
+ * platform/LegacySchemeRegistry.cpp:
+ (WebCore::builtinSecureSchemes):
+
2022-02-10 Eric Carlson <[email protected]>
[macOS] Support both versions of ScreenCaptureKit API
Modified: trunk/Source/WebCore/SourcesCocoa.txt (289548 => 289549)
--- trunk/Source/WebCore/SourcesCocoa.txt 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2022-02-10 17:49:26 UTC (rev 289549)
@@ -183,6 +183,7 @@
inspector/mac/PageDebuggerMac.mm
loader/archive/cf/LegacyWebArchive.cpp
loader/archive/cf/LegacyWebArchiveMac.mm
+loader/cocoa/BundleResourceLoader.mm
loader/cocoa/DiskCacheMonitorCocoa.mm
loader/cocoa/PrivateClickMeasurementCocoa.mm
loader/cocoa/SubresourceLoaderCocoa.mm
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (289548 => 289549)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-02-10 17:49:26 UTC (rev 289549)
@@ -9385,6 +9385,8 @@
4958782012A57DDF007238AC /* PlatformCALayerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformCALayerCocoa.mm; sourceTree = "<group>"; };
4969B0F013D0B33F00DF3521 /* HitTestingTransformState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestingTransformState.cpp; sourceTree = "<group>"; };
4969B0F113D0B33F00DF3521 /* HitTestingTransformState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HitTestingTransformState.h; sourceTree = "<group>"; };
+ 4970FC8027B54DFA00C25017 /* BundleResourceLoader.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BundleResourceLoader.mm; sourceTree = "<group>"; };
+ 4970FC8127B54DFB00C25017 /* BundleResourceLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BundleResourceLoader.h; sourceTree = "<group>"; };
4998AEC413F9D0EA0090B1AA /* RequestAnimationFrameCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RequestAnimationFrameCallback.h; sourceTree = "<group>"; };
4998AEC513F9D0EA0090B1AA /* RequestAnimationFrameCallback.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RequestAnimationFrameCallback.idl; sourceTree = "<group>"; };
4998AECB13F9D6C90090B1AA /* JSRequestAnimationFrameCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSRequestAnimationFrameCallback.cpp; sourceTree = "<group>"; };
@@ -25049,6 +25051,8 @@
7E4DE10B198B10810051CB02 /* cocoa */ = {
isa = PBXGroup;
children = (
+ 4970FC8127B54DFB00C25017 /* BundleResourceLoader.h */,
+ 4970FC8027B54DFA00C25017 /* BundleResourceLoader.mm */,
7EDAAFC819A2CBD10034DFD1 /* DiskCacheMonitorCocoa.h */,
7E4DE10C198B10B60051CB02 /* DiskCacheMonitorCocoa.mm */,
57F1C8E325DC6EE700E8F6EA /* PrivateClickMeasurementCocoa.mm */,
Modified: trunk/Source/WebCore/html/PDFDocument.cpp (289548 => 289549)
--- trunk/Source/WebCore/html/PDFDocument.cpp 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/html/PDFDocument.cpp 2022-02-10 17:49:26 UTC (rev 289549)
@@ -94,8 +94,7 @@
void PDFDocument::createDocumentStructure()
{
- // FIXME: Replace about:blank with actual viewer URL
- auto viewerURL = "about:blank?file=";
+ auto viewerURL = "webkit-pdfjs-viewer://pdfjs/web/viewer.html?file=";
auto rootElement = HTMLHtmlElement::create(*this);
appendChild(rootElement);
rootElement->insertedByParser();
Modified: trunk/Source/WebCore/loader/PolicyChecker.cpp (289548 => 289549)
--- trunk/Source/WebCore/loader/PolicyChecker.cpp 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/loader/PolicyChecker.cpp 2022-02-10 17:49:26 UTC (rev 289549)
@@ -169,6 +169,13 @@
loader->setLastCheckedRequest(ResourceRequest(request));
+ // Only the PDFDocument iframe is allowed to navigate to webkit-pdfjs-viewer URLs
+ bool isInPDFDocumentFrame = m_frame.ownerElement() && m_frame.ownerElement()->document().isPDFDocument();
+ if (isInPDFDocumentFrame && request.url().protocolIs("webkit-pdfjs-viewer")) {
+ POLICYCHECKER_RELEASE_LOG("checkNavigationPolicy: continuing because PDFJS URL");
+ return function(WTFMove(request), formState, NavigationPolicyDecision::ContinueLoad);
+ }
+
#if USE(QUICK_LOOK)
// Always allow QuickLook-generated URLs based on the protocol scheme.
if (!request.isNull() && isQuickLookPreviewURL(request.url())) {
Modified: trunk/Source/WebCore/loader/ResourceLoader.cpp (289548 => 289549)
--- trunk/Source/WebCore/loader/ResourceLoader.cpp 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/loader/ResourceLoader.cpp 2022-02-10 17:49:26 UTC (rev 289549)
@@ -40,6 +40,7 @@
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
+#include "HTMLFrameOwnerElement.h"
#include "InspectorInstrumentation.h"
#include "LoaderStrategy.h"
#include "Logging.h"
@@ -63,6 +64,10 @@
#include "PreviewConverter.h"
#endif
+#if PLATFORM(COCOA)
+#include "BundleResourceLoader.h"
+#endif
+
#undef RESOURCELOADER_RELEASE_LOG
#define PAGE_ID ((frame() ? valueOrDefault(frame()->pageID()) : PageIdentifier()).toUInt64())
#define FRAME_ID ((frame() ? valueOrDefault(frame()->frameID()) : FrameIdentifier()).toUInt64())
@@ -234,6 +239,13 @@
return;
}
+#if PLATFORM(COCOA)
+ if (isPDFJSResourceLoad()) {
+ BundleResourceLoader::loadResourceFromBundle(*this, "pdfjs/");
+ return;
+ }
+#endif
+
#if USE(SOUP)
if (m_request.url().protocolIs("resource")) {
loadGResource();
@@ -855,6 +867,19 @@
}
#endif
+bool ResourceLoader::isPDFJSResourceLoad() const
+{
+#if PLATFORM(COCOA)
+ if (!m_request.url().protocolIs("webkit-pdfjs-viewer"))
+ return false;
+
+ auto* document = frame() && frame()->ownerElement() ? &frame()->ownerElement()->document() : nullptr;
+ return document ? document->isPDFDocument() : false;
+#else
+ return false;
+#endif
+}
+
} // namespace WebCore
#undef RESOURCELOADER_RELEASE_LOG
Modified: trunk/Source/WebCore/loader/ResourceLoader.h (289548 => 289549)
--- trunk/Source/WebCore/loader/ResourceLoader.h 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/loader/ResourceLoader.h 2022-02-10 17:49:26 UTC (rev 289549)
@@ -159,6 +159,8 @@
const ResourceRequest& deferredRequest() const { return m_deferredRequest; }
ResourceRequest takeDeferredRequest() { return std::exchange(m_deferredRequest, { }); }
+ bool isPDFJSResourceLoad() const;
+
protected:
ResourceLoader(Frame&, ResourceLoaderOptions);
Modified: trunk/Source/WebCore/loader/SubresourceLoader.h (289548 => 289549)
--- trunk/Source/WebCore/loader/SubresourceLoader.h 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/loader/SubresourceLoader.h 2022-02-10 17:49:26 UTC (rev 289549)
@@ -52,7 +52,7 @@
CachedResource* cachedResource() const override { return m_resource; };
WEBCORE_EXPORT const HTTPHeaderMap* originalHeaders() const;
- SecurityOrigin* origin() { return m_origin.get(); }
+ SecurityOrigin* origin() const { return m_origin.get(); }
#if PLATFORM(IOS_FAMILY)
void startLoading() override;
Added: trunk/Source/WebCore/loader/cocoa/BundleResourceLoader.h (0 => 289549)
--- trunk/Source/WebCore/loader/cocoa/BundleResourceLoader.h (rev 0)
+++ trunk/Source/WebCore/loader/cocoa/BundleResourceLoader.h 2022-02-10 17:49:26 UTC (rev 289549)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#pragma once
+
+namespace WebCore {
+class ResourceLoader;
+
+namespace BundleResourceLoader {
+void loadResourceFromBundle(ResourceLoader&, const String&);
+}
+
+}
Added: trunk/Source/WebCore/loader/cocoa/BundleResourceLoader.mm (0 => 289549)
--- trunk/Source/WebCore/loader/cocoa/BundleResourceLoader.mm (rev 0)
+++ trunk/Source/WebCore/loader/cocoa/BundleResourceLoader.mm 2022-02-10 17:49:26 UTC (rev 289549)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#pragma once
+
+#import "config.h"
+#import "BundleResourceLoader.h"
+
+#import "HTTPHeaderMap.h"
+#import "MIMETypeRegistry.h"
+#import "ResourceError.h"
+#import "ResourceLoader.h"
+#import "ResourceResponse.h"
+#import "SharedBuffer.h"
+#import <wtf/RunLoop.h>
+#import <wtf/WorkQueue.h>
+
+namespace WebCore {
+namespace BundleResourceLoader {
+
+static WorkQueue& loadQueue()
+{
+ static auto& queue = WorkQueue::create("org.WebCore.BundleResourceLoader", WorkQueue::QOS::Utility).leakRef();
+ return queue;
+}
+
+void loadResourceFromBundle(ResourceLoader& loader, const String& subdirectory)
+{
+ ASSERT(RunLoop::isMain());
+
+ loadQueue().dispatch([protectedLoader = Ref { loader }, url = "" subdirectory = subdirectory.isolatedCopy()]() mutable {
+ auto *relativePath = [subdirectory stringByAppendingString: url.path().toString()];
+ auto *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebCore"];
+ auto *path = [bundle pathForResource:relativePath ofType:nil];
+ auto *data = "" dataWithContentsOfFile:path];
+
+ if (!data) {
+ RunLoop::main().dispatch([protectedLoader = WTFMove(protectedLoader), url = "" {
+ protectedLoader->didFail(ResourceError { errorDomainWebKitInternal, 0, url, "URL is invalid"_s });
+ });
+ return;
+ }
+
+ RunLoop::main().dispatch([protectedLoader = WTFMove(protectedLoader), url = "" buffer = SharedBuffer::create(data)]() mutable {
+ auto mimeType = MIMETypeRegistry::mimeTypeForPath(url.path().toString());
+ ResourceResponse response { url, mimeType, static_cast<long long>(buffer->size()), MIMETypeRegistry::isTextMIMEType(mimeType) ? "UTF-8"_s : nullptr };
+ response.setHTTPStatusCode(200);
+ response.setHTTPStatusText("OK"_s);
+ response.setSource(ResourceResponse::Source::Network);
+
+ // Allow images to load.
+ response.addHTTPHeaderField(HTTPHeaderName::AccessControlAllowOrigin, "*");
+
+ protectedLoader->deliverResponseAndData(response, WTFMove(buffer));
+ });
+ });
+}
+}
+}
Modified: trunk/Source/WebCore/platform/LegacySchemeRegistry.cpp (289548 => 289549)
--- trunk/Source/WebCore/platform/LegacySchemeRegistry.cpp 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebCore/platform/LegacySchemeRegistry.cpp 2022-02-10 17:49:26 UTC (rev 289549)
@@ -143,6 +143,9 @@
#if PLATFORM(GTK) || PLATFORM(WPE)
"resource"_s,
#endif
+#if PLATFORM(COCOA)
+ "webkit-pdfjs-viewer"_s,
+#endif
};
return schemes;
}
Modified: trunk/Source/WebKit/ChangeLog (289548 => 289549)
--- trunk/Source/WebKit/ChangeLog 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebKit/ChangeLog 2022-02-10 17:49:26 UTC (rev 289549)
@@ -1,3 +1,23 @@
+2022-02-10 Tim Nguyen <[email protected]>
+
+ Add webkit-pdfjs-viewer scheme for PDF.js resources
+ https://bugs.webkit.org/show_bug.cgi?id=236062
+
+ Reviewed by Youenn Fablet.
+
+ The code handling the scheme is under WebCore::BundleResourceLoader.
+ It reads files from the pdfjs/ sub-folder in the WebCore.framework resources folder.
+ Right now, this sub-folder does not exist yet, but this scheme can be tested by manually populating it.
+
+ Bug 235981 will take care of populating this folder at build-time.
+
+ Note: This scheme can only be loaded inside a PDFDocument <iframe>
+
+ * WebProcess/Network/WebLoaderStrategy.cpp:
+ (WebKit::WebLoaderStrategy::scheduleLoad):
+ (WebKit::WebLoaderStrategy::tryLoadingUsingPDFJSHandler):
+ * WebProcess/Network/WebLoaderStrategy.h:
+
2022-02-10 Aditya Keerthi <[email protected]>
An element with both -webkit-user-select: all and -webkit-user-drag: element does not get the nice drag snapshot that you get if you just have -webkit-user-drag: element
Modified: trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp (289548 => 289549)
--- trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp 2022-02-10 17:49:26 UTC (rev 289549)
@@ -231,6 +231,9 @@
}
#endif
+ if (tryLoadingUsingPDFJSHandler(resourceLoader, trackingParameters))
+ return;
+
if (!tryLoadingUsingURLSchemeHandler(resourceLoader, trackingParameters)) {
WEBLOADERSTRATEGY_RELEASE_LOG("scheduleLoad: URL will be scheduled with the NetworkProcess");
@@ -269,6 +272,18 @@
return true;
}
+bool WebLoaderStrategy::tryLoadingUsingPDFJSHandler(ResourceLoader& resourceLoader, const WebResourceLoader::TrackingParameters& trackingParameters)
+{
+ if (!resourceLoader.request().url().protocolIs("webkit-pdfjs-viewer"))
+ return false;
+
+ LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be handled as a PDFJS resource.", resourceLoader.url().string().utf8().data());
+ WEBLOADERSTRATEGY_RELEASE_LOG("tryLoadingUsingPDFJSHandler: URL will be scheduled with the PDFJS url scheme handler");
+
+ startLocalLoad(resourceLoader);
+ return true;
+}
+
static void addParametersShared(const Frame* frame, NetworkResourceLoadParameters& parameters)
{
parameters.crossOriginAccessControlCheckEnabled = CrossOriginAccessControlCheckDisabler::singleton().crossOriginAccessControlCheckEnabled();
Modified: trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h (289548 => 289549)
--- trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h 2022-02-10 17:46:59 UTC (rev 289548)
+++ trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h 2022-02-10 17:49:26 UTC (rev 289549)
@@ -99,7 +99,8 @@
void internallyFailedLoadTimerFired();
void startLocalLoad(WebCore::ResourceLoader&);
bool tryLoadingUsingURLSchemeHandler(WebCore::ResourceLoader&, const WebResourceLoader::TrackingParameters&);
-
+ bool tryLoadingUsingPDFJSHandler(WebCore::ResourceLoader&, const WebResourceLoader::TrackingParameters&);
+
struct SyncLoadResult {
WebCore::ResourceResponse response;
WebCore::ResourceError error;