Title: [258080] trunk/Source
Revision
258080
Author
[email protected]
Date
2020-03-07 14:13:14 -0800 (Sat, 07 Mar 2020)

Log Message

Add runtime flag for incremental PDF loading.
https://bugs.webkit.org/show_bug.cgi?id=208763

Reviewed by Tim Horton.

Source/WebCore:

* page/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::setIncrementalPDFLoadingEnabled):
(WebCore::RuntimeEnabledFeatures::incrementalPDFLoadingEnabled const):

Source/WebKit:

* Shared/WebPreferences.yaml:
* Shared/WebPreferencesDefaultValues.cpp:
(WebKit::defaultIncrementalPDFEnabled):
* Shared/WebPreferencesDefaultValues.h:

* WebProcess/Plugins/PDF/PDFPlugin.h:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::PDFPlugin):
(WebKit::PDFPlugin::pdfDocumentDidLoad):
(WebKit::PDFPlugin::manualStreamDidReceiveData):
(WebKit::PDFPlugin::manualStreamDidFail):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (258079 => 258080)


--- trunk/Source/WebCore/ChangeLog	2020-03-07 22:05:45 UTC (rev 258079)
+++ trunk/Source/WebCore/ChangeLog	2020-03-07 22:13:14 UTC (rev 258080)
@@ -1,3 +1,14 @@
+2020-03-07  Brady Eidson  <[email protected]>
+
+        Add runtime flag for incremental PDF loading.
+        https://bugs.webkit.org/show_bug.cgi?id=208763
+
+        Reviewed by Tim Horton.
+
+        * page/RuntimeEnabledFeatures.h:
+        (WebCore::RuntimeEnabledFeatures::setIncrementalPDFLoadingEnabled):
+        (WebCore::RuntimeEnabledFeatures::incrementalPDFLoadingEnabled const):
+
 2020-03-07  Zalan Bujtas  <[email protected]>
 
         [LFC][Verification] Use the table wrapper box's offset when matching out-of-flow tables

Modified: trunk/Source/WebCore/page/RuntimeEnabledFeatures.h (258079 => 258080)


--- trunk/Source/WebCore/page/RuntimeEnabledFeatures.h	2020-03-07 22:05:45 UTC (rev 258079)
+++ trunk/Source/WebCore/page/RuntimeEnabledFeatures.h	2020-03-07 22:13:14 UTC (rev 258080)
@@ -402,6 +402,11 @@
     void setWebShareFileAPIEnabled(bool isEnabled) { m_webShareFileAPIEnabled = isEnabled; }
     bool webShareFileAPIEnabled() const { return m_webShareFileAPIEnabled; }
 
+#if HAVE(INCREMENTAL_PDF_APIS)
+    void setIncrementalPDFLoadingEnabled(bool isEnabled) { m_incrementalPDFLoadingEnabled = isEnabled; }
+    bool incrementalPDFLoadingEnabled() const { return m_incrementalPDFLoadingEnabled; }
+#endif
+
 private:
     // Never instantiate.
     RuntimeEnabledFeatures();
@@ -608,6 +613,10 @@
 #endif
     bool m_webShareFileAPIEnabled { false };
 
+#if HAVE(INCREMENTAL_PDF_APIS)
+    bool m_incrementalPDFLoadingEnabled { false };
+#endif
+
     friend class WTF::NeverDestroyed<RuntimeEnabledFeatures>;
 };
 

Modified: trunk/Source/WebKit/ChangeLog (258079 => 258080)


--- trunk/Source/WebKit/ChangeLog	2020-03-07 22:05:45 UTC (rev 258079)
+++ trunk/Source/WebKit/ChangeLog	2020-03-07 22:13:14 UTC (rev 258080)
@@ -1,3 +1,22 @@
+2020-03-07  Brady Eidson  <[email protected]>
+
+        Add runtime flag for incremental PDF loading.
+        https://bugs.webkit.org/show_bug.cgi?id=208763
+
+        Reviewed by Tim Horton.
+
+        * Shared/WebPreferences.yaml:
+        * Shared/WebPreferencesDefaultValues.cpp:
+        (WebKit::defaultIncrementalPDFEnabled):
+        * Shared/WebPreferencesDefaultValues.h:
+        
+        * WebProcess/Plugins/PDF/PDFPlugin.h:
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::PDFPlugin):
+        (WebKit::PDFPlugin::pdfDocumentDidLoad):
+        (WebKit::PDFPlugin::manualStreamDidReceiveData):
+        (WebKit::PDFPlugin::manualStreamDidFail):
+
 2020-03-05  Sam Weinig  <[email protected]>
 
         Move _javascript_Core related feature defines from FeatureDefines.xcconfig to PlatformEnableCocoa.h

Modified: trunk/Source/WebKit/Shared/WebPreferences.yaml (258079 => 258080)


--- trunk/Source/WebKit/Shared/WebPreferences.yaml	2020-03-07 22:05:45 UTC (rev 258079)
+++ trunk/Source/WebKit/Shared/WebPreferences.yaml	2020-03-07 22:13:14 UTC (rev 258080)
@@ -1962,6 +1962,15 @@
     webcoreBinding: RuntimeEnabledFeatures
     category: experimental
 
+IncrementalPDFLoadingEnabled:
+  type: bool
+  defaultValue: defaultIncrementalPDFEnabled()
+  humanReadableName: "Incremental PDF Loading"
+  humanReadableDescription: "Enable Incremental PDF Loading on supported platforms"
+  category: experimental
+  condition: HAVE(INCREMENTAL_PDF_APIS)
+  webcoreBinding: RuntimeEnabledFeatures
+
 # Deprecated
 
 ICECandidateFilteringEnabled:

Modified: trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp (258079 => 258080)


--- trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp	2020-03-07 22:05:45 UTC (rev 258079)
+++ trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp	2020-03-07 22:13:14 UTC (rev 258080)
@@ -213,4 +213,15 @@
     return false;
 }
 
+#if HAVE(INCREMENTAL_PDF_APIS)
+bool defaultIncrementalPDFEnabled()
+{
+#if HAVE(HAVE_SYSTEM_FEATURE_FLAGS)
+    return os_feature_enabled(WebKit, incremental_pdf);
+#endif
+
+    return false;
+}
+#endif
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h (258079 => 258080)


--- trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h	2020-03-07 22:05:45 UTC (rev 258079)
+++ trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h	2020-03-07 22:13:14 UTC (rev 258080)
@@ -334,4 +334,8 @@
 
 bool defaultInAppBrowserPrivacy();
 
+#if HAVE(INCREMENTAL_PDF_APIS)
+bool defaultIncrementalPDFEnabled();
+#endif
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h (258079 => 258080)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-03-07 22:05:45 UTC (rev 258079)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-03-07 22:13:14 UTC (rev 258080)
@@ -38,12 +38,6 @@
 #include <wtf/RetainPtr.h>
 #include <wtf/Threading.h>
 
-// For now, disable new PDF APIs by default even on platforms where otherwise enabled.
-// FIXME: Enable this when ready.
-#ifdef HAVE_INCREMENTAL_PDF_APIS
-#undef HAVE_INCREMENTAL_PDF_APIS
-#endif
-
 typedef const struct OpaqueJSContext* JSContextRef;
 typedef struct OpaqueJSValue* JSObjectRef;
 typedef const struct OpaqueJSValue* JSValueRef;
@@ -333,6 +327,7 @@
     RetainPtr<PDFDocument> m_backgroundThreadDocument;
     RefPtr<Thread> m_pdfThread;
     Vector<ByteRangeRequest> m_outstandingByteRangeRequests;
+    bool m_incrementalPDFLoadingEnabled;
 #endif
 };
 

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (258079 => 258080)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-03-07 22:05:45 UTC (rev 258079)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-03-07 22:13:14 UTC (rev 258080)
@@ -80,6 +80,7 @@
 #import <WebCore/PluginData.h>
 #import <WebCore/PluginDocument.h>
 #import <WebCore/RenderBoxModelObject.h>
+#import <WebCore/RuntimeEnabledFeatures.h>
 #import <WebCore/ScrollAnimator.h>
 #import <WebCore/ScrollbarTheme.h>
 #import <WebCore/Settings.h>
@@ -586,7 +587,7 @@
     , m_pdfLayerController(adoptNS([[pdfLayerControllerClass() alloc] init]))
     , m_pdfLayerControllerDelegate(adoptNS([[WKPDFLayerControllerDelegate alloc] initWithPDFPlugin:this]))
 #if HAVE(INCREMENTAL_PDF_APIS)
-    , m_pdfThread(Thread::create("PDF document thread", [protectedThis = makeRef(*this), this] () mutable { threadEntry(WTFMove(protectedThis)); }))
+    , m_incrementalPDFLoadingEnabled(WebCore::RuntimeEnabledFeatures::sharedFeatures().incrementalPDFLoadingEnabled())
 #endif
 {
     m_pdfLayerController.get().delegate = m_pdfLayerControllerDelegate.get();
@@ -616,6 +617,14 @@
         [m_pdfLayerController setDeviceColorSpace:screenColorSpace(view)];
     }
 #endif
+
+#if HAVE(INCREMENTAL_PDF_APIS)
+    if (m_incrementalPDFLoadingEnabled) {
+        m_pdfThread = Thread::create("PDF document thread", [protectedThis = makeRef(*this), this] () mutable {
+            threadEntry(WTFMove(protectedThis));
+        });
+    }
+#endif
 }
 
 PDFPlugin::~PDFPlugin()
@@ -1121,12 +1130,15 @@
     m_documentFinishedLoading = true;
 
 #if HAVE(INCREMENTAL_PDF_APIS)
-    // At this point we know all data for the document, and therefore we know how to answer any outstanding range requests.
-    unconditionalCompleteOutstandingRangeRequests();
-#else
-    m_pdfDocument = adoptNS([[pdfDocumentClass() alloc] initWithData:rawData()]);
-    installPDFDocument();
+    if (m_incrementalPDFLoadingEnabled) {
+        // At this point we know all data for the document, and therefore we know how to answer any outstanding range requests.
+        unconditionalCompleteOutstandingRangeRequests();
+    } else
 #endif
+    {
+        m_pdfDocument = adoptNS([[pdfDocumentClass() alloc] initWithData:rawData()]);
+        installPDFDocument();
+    }
 }
 
 void PDFPlugin::installPDFDocument()
@@ -1222,15 +1234,17 @@
     m_streamedBytes += length;
 
 #if HAVE(INCREMENTAL_PDF_APIS)
-    size_t index = 0;
-    while (index < m_outstandingByteRangeRequests.size()) {
-        auto& request = m_outstandingByteRangeRequests[index];
-        if (m_streamedBytes >= request.position + request.count) {
-            request.completionHandler(CFDataGetBytePtr(m_data.get()) + request.position, request.count);
-            m_outstandingByteRangeRequests.remove(index);
-            continue;
+    if (m_incrementalPDFLoadingEnabled) {
+        size_t index = 0;
+        while (index < m_outstandingByteRangeRequests.size()) {
+            auto& request = m_outstandingByteRangeRequests[index];
+            if (m_streamedBytes >= request.position + request.count) {
+                request.completionHandler(CFDataGetBytePtr(m_data.get()) + request.position, request.count);
+                m_outstandingByteRangeRequests.remove(index);
+                continue;
+            }
+            ++index;
         }
-        ++index;
     }
 #endif
 }
@@ -1245,7 +1259,8 @@
 {
     m_data = nullptr;
 #if HAVE(INCREMENTAL_PDF_APIS)
-    unconditionalCompleteOutstandingRangeRequests();
+    if (m_incrementalPDFLoadingEnabled)
+        unconditionalCompleteOutstandingRangeRequests();
 #endif
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to