File: PDFPluginBase.h

package info (click to toggle)
webkit2gtk 2.48.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 429,764 kB
  • sloc: cpp: 3,697,587; javascript: 194,444; ansic: 169,997; python: 46,499; asm: 19,295; ruby: 18,528; perl: 16,602; xml: 4,650; yacc: 2,360; sh: 2,098; java: 1,993; lex: 1,327; pascal: 366; makefile: 298
file content (519 lines) | stat: -rw-r--r-- 21,831 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
/*
 * Copyright (C) 2023 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

#if ENABLE(PDF_PLUGIN)

#include "CursorContext.h"
#include "FrameInfoData.h"
#include "PDFPluginIdentifier.h"
#include "WebFoundTextRange.h"
#include "WebMouseEvent.h"
#include <WebCore/AffineTransform.h>
#include <WebCore/FindOptions.h>
#include <WebCore/FloatRect.h>
#include <WebCore/PageIdentifier.h>
#include <WebCore/PlatformMouseEvent.h>
#include <WebCore/PluginData.h>
#include <WebCore/PluginViewBase.h>
#include <WebCore/ScrollTypes.h>
#include <WebCore/ScrollableArea.h>
#include <WebCore/TextIndicator.h>
#include <wtf/CompletionHandler.h>
#include <wtf/Identified.h>
#include <wtf/Lock.h>
#include <wtf/MainThread.h>
#include <wtf/Range.h>
#include <wtf/RangeSet.h>
#include <wtf/RetainPtr.h>
#include <wtf/TZoneMalloc.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/TypeTraits.h>
#include <wtf/WeakPtr.h>

OBJC_CLASS NSData;
OBJC_CLASS NSDictionary;
OBJC_CLASS NSString;
OBJC_CLASS PDFAnnotation;
OBJC_CLASS PDFDocument;
OBJC_CLASS PDFSelection;
#if PLATFORM(MAC)
OBJC_CLASS WKAccessibilityPDFDocumentObject;
#endif

namespace WebCore {
class Color;
class FragmentedSharedBuffer;
class GraphicsContext;
class Element;
class HTMLPlugInElement;
class NetscapePlugInStreamLoaderClient;
class ResourceResponse;
class Scrollbar;
class ShareableBitmap;
class SharedBuffer;
enum class PlatformCursorType : uint8_t;
struct DictionaryPopupInfo;
}

namespace WebKit {

class PDFIncrementalLoader;
class PDFPluginAnnotation;
class PluginView;
class WebFrame;
class WebKeyboardEvent;
class WebMouseEvent;
class WebWheelEvent;
enum class SelectionEndpoint : bool;
enum class SelectionWasFlipped : bool;
struct DocumentEditingContextRequest;
struct DocumentEditingContext;
struct EditorState;
struct WebHitTestResultData;

enum class ByteRangeRequestIdentifierType;
using ByteRangeRequestIdentifier = ObjectIdentifier<ByteRangeRequestIdentifierType>;

enum class CheckValidRanges : bool { No, Yes };

template<typename T>
concept CanMakeFloatRect = requires(T t)
{
    { WebCore::FloatRect { t } } -> std::same_as<WebCore::FloatRect>;
};

struct PDFPluginPasteboardItem {
    RetainPtr<NSData> data;
    RetainPtr<NSString> type;
};

class PDFPluginBase : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr<PDFPluginBase, WTF::DestructionThread::Main>, public CanMakeThreadSafeCheckedPtr<PDFPluginBase>, public WebCore::ScrollableArea, public Identified<PDFPluginIdentifier> {
    WTF_MAKE_NONCOPYABLE(PDFPluginBase);
    WTF_MAKE_TZONE_ALLOCATED(PDFPluginBase);
    WTF_OVERRIDE_DELETE_FOR_CHECKED_PTR(PDFPluginBase);
    friend class PDFIncrementalLoader;
    friend class PDFPluginChoiceAnnotation;
    friend class PDFPluginTextAnnotation;
public:
    static WebCore::PluginInfo pluginInfo();

    virtual ~PDFPluginBase();

    // CheckedPtr interface
    uint32_t checkedPtrCount() const final { return CanMakeThreadSafeCheckedPtr::checkedPtrCount(); }
    uint32_t checkedPtrCountWithoutThreadCheck() const final { return CanMakeThreadSafeCheckedPtr::checkedPtrCountWithoutThreadCheck(); }
    void incrementCheckedPtrCount() const final { CanMakeThreadSafeCheckedPtr::incrementCheckedPtrCount(); }
    void decrementCheckedPtrCount() const final { CanMakeThreadSafeCheckedPtr::decrementCheckedPtrCount(); }

    void startLoading();
    void destroy();

    virtual bool isUnifiedPDFPlugin() const { return false; }
    virtual bool isLegacyPDFPlugin() const { return false; }

    virtual WebCore::PluginLayerHostingStrategy layerHostingStrategy() const = 0;
    virtual PlatformLayer* platformLayer() const { return nullptr; }
    virtual WebCore::GraphicsLayer* graphicsLayer() const { return nullptr; }

    virtual void setView(PluginView&);

    virtual void willDetachRenderer();

    virtual bool isComposited() const { return false; }

    virtual bool shouldCreateTransientPaintingSnapshot() const { return false; }
    virtual RefPtr<WebCore::ShareableBitmap> snapshot() { return nullptr; }
    virtual void paint(WebCore::GraphicsContext&, const WebCore::IntRect&) { }

    virtual double scaleFactor() const = 0;
    virtual void setPageScaleFactor(double, std::optional<WebCore::IntPoint> origin) = 0;

    virtual double minScaleFactor() const { return 0.25; }
    virtual double maxScaleFactor() const { return 5; }

    bool isLocked() const;

    RetainPtr<PDFDocument> pdfDocument() const { return m_pdfDocument; }
    WebCore::FloatSize pdfDocumentSizeForPrinting() const;

    virtual bool geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::AffineTransform& pluginToRootViewTransform);
    virtual void visibilityDidChange(bool);
    virtual void deviceScaleFactorChanged(float) { }

    bool handlesPageScaleFactor() const;
    virtual void didBeginMagnificationGesture() { }
    virtual void didEndMagnificationGesture() { }

    void updateControlTints(WebCore::GraphicsContext&);

    virtual RefPtr<WebCore::FragmentedSharedBuffer> liveResourceData() const = 0;

    virtual bool wantsWheelEvents() const = 0;
    virtual bool handleMouseEvent(const WebMouseEvent&) = 0;
    virtual bool handleWheelEvent(const WebWheelEvent&) = 0;
    virtual bool handleMouseEnterEvent(const WebMouseEvent&) = 0;
    virtual bool handleMouseLeaveEvent(const WebMouseEvent&) = 0;
    virtual bool handleContextMenuEvent(const WebMouseEvent&) = 0;
    virtual bool handleKeyboardEvent(const WebKeyboardEvent&) = 0;
    virtual bool handleEditingCommand(const String& commandName, const String& argument) = 0;
    virtual bool isEditingCommandEnabled(const String& commandName) = 0;

    virtual String fullDocumentString() const { return { }; }
    virtual String selectionString() const = 0;
    virtual std::pair<String, String> stringsBeforeAndAfterSelection(int /* characterCount */) const { return { }; }
    virtual bool existingSelectionContainsPoint(const WebCore::FloatPoint&) const = 0;
    virtual WebCore::FloatRect rectForSelectionInRootView(PDFSelection *) const = 0;

    virtual unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0;
    virtual bool findString(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0;
    virtual Vector<WebCore::FloatRect> rectsForTextMatchesInRect(const WebCore::IntRect&) const { return { }; }
    virtual bool drawsFindOverlay() const = 0;
    virtual RefPtr<WebCore::TextIndicator> textIndicatorForCurrentSelection(OptionSet<WebCore::TextIndicatorOption>, WebCore::TextIndicatorPresentationTransition) { return { }; }
    virtual WebCore::DictionaryPopupInfo dictionaryPopupInfoForSelection(PDFSelection *, WebCore::TextIndicatorPresentationTransition) = 0;

    virtual Vector<WebFoundTextRange::PDFData> findTextMatches(const String& target, WebCore::FindOptions) = 0;
    virtual Vector<WebCore::FloatRect> rectsForTextMatch(const WebFoundTextRange::PDFData&) = 0;
    virtual RefPtr<WebCore::TextIndicator> textIndicatorForTextMatch(const WebFoundTextRange::PDFData&, WebCore::TextIndicatorPresentationTransition) { return { }; }
    virtual void scrollToRevealTextMatch(const WebFoundTextRange::PDFData&) { }

    virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) = 0;
    void performWebSearch(const String& query);

    bool performImmediateActionHitTestAtLocation(const WebCore::FloatPoint&, WebHitTestResultData&);
    virtual std::pair<String, RetainPtr<PDFSelection>> textForImmediateActionHitTestAtPoint(const WebCore::FloatPoint&, WebHitTestResultData&) = 0;

    virtual id accessibilityHitTest(const WebCore::IntPoint&) const = 0;
    virtual id accessibilityObject() const = 0;
    id accessibilityAssociatedPluginParentForElement(WebCore::Element*) const;

    bool isBeingDestroyed() const { return m_isBeingDestroyed; }
    virtual void releaseMemory() { }

    bool isFullFramePlugin() const;
    WebCore::IntSize size() const { return m_size; }

    void streamDidReceiveResponse(const WebCore::ResourceResponse&);
    void streamDidReceiveData(const WebCore::SharedBuffer&);
    void streamDidFinishLoading();
    void streamDidFail();

    template<typename T>
    T convertFromRootViewToPlugin(const T& value) const
    {
        if constexpr (CanMakeFloatRect<T>)
            return m_rootViewToPluginTransform.mapRect(value);
        else
            return m_rootViewToPluginTransform.mapPoint(value);
    }

    template<typename T>
    T convertFromPluginToRootView(const T& value) const
    {
        auto inverseTransform = m_rootViewToPluginTransform.inverse();
        if constexpr (CanMakeFloatRect<T>)
            return inverseTransform->mapRect(value);
        else
            return inverseTransform->mapPoint(value);
    }

    WebCore::IntRect boundsOnScreen() const;

    bool showContextMenuAtPoint(const WebCore::IntPoint&);
    WebCore::AXObjectCache* axObjectCache() const;

    WebCore::ScrollPosition scrollPositionForTesting() const { return scrollPosition(); }
    WebCore::Scrollbar* horizontalScrollbar() const override { return m_horizontalScrollbar.get(); }
    WebCore::Scrollbar* verticalScrollbar() const override { return m_verticalScrollbar.get(); }
    RefPtr<WebCore::Scrollbar> protectedHorizontalScrollbar() const { return horizontalScrollbar(); }
    RefPtr<WebCore::Scrollbar> protectedVerticalScrollbar() const { return verticalScrollbar(); }
    void setScrollOffset(const WebCore::ScrollOffset&) final;

    virtual void willAttachScrollingNode() { }
    virtual void didAttachScrollingNode() { }
    virtual void didChangeSettings() { }

    // HUD Actions.
#if ENABLE(PDF_HUD)
    virtual void zoomIn() = 0;
    virtual void zoomOut() = 0;
    void save(CompletionHandler<void(const String&, const URL&, std::span<const uint8_t>)>&&);
#endif

    void openWithPreview(CompletionHandler<void(const String&, FrameInfoData&&, std::span<const uint8_t>, const String&)>&&);

    void notifyCursorChanged(WebCore::PlatformCursorType);

    WebCore::ScrollPosition scrollPosition() const final;

#if PLATFORM(MAC)
    PDFPluginAnnotation* activeAnnotation() const { return m_activeAnnotation.get(); }
    RefPtr<PDFPluginAnnotation> protectedActiveAnnotation() const;
#endif

    enum class IsInPluginCleanup : bool { No, Yes };

    struct SetActiveAnnotationParams {
        RetainPtr<PDFAnnotation> annotation;
        IsInPluginCleanup isInPluginCleanup { IsInPluginCleanup::No };
    };

    virtual void setActiveAnnotation(SetActiveAnnotationParams&&) = 0;
    void didMutatePDFDocument() { m_pdfDocumentWasMutated = true; }

    virtual CGRect pluginBoundsForAnnotation(RetainPtr<PDFAnnotation>&) const = 0;
    virtual void focusNextAnnotation() = 0;
    virtual void focusPreviousAnnotation() = 0;

    virtual Vector<WebCore::FloatRect> annotationRectsForTesting() const { return { }; }
    virtual void setTextAnnotationValueForTesting(unsigned pageIndex, unsigned annotationIndex, const String& value) { }
    virtual void setPDFDisplayModeForTesting(const String&) { }
    void registerPDFTest(RefPtr<WebCore::VoidCallback>&&);

    void navigateToURL(const URL&, std::optional<WebCore::PlatformMouseEvent>&& = std::nullopt);

    virtual void attemptToUnlockPDF(const String& password) = 0;

#if HAVE(INCREMENTAL_PDF_APIS)
    bool incrementalPDFLoadingEnabled() const { return m_incrementalPDFLoadingEnabled; }
    void receivedNonLinearizedPDFSentinel();
    void startByteRangeRequest(WebCore::NetscapePlugInStreamLoaderClient&, ByteRangeRequestIdentifier, uint64_t position, size_t count);
    void adoptBackgroundThreadDocument(RetainPtr<PDFDocument>&&);
    void maybeClearHighLatencyDataProviderFlag();
#endif

    void notifySelectionChanged();

    virtual void windowActivityDidChange() { }

    virtual void didChangeIsInWindow() { }

    virtual void didSameDocumentNavigationForFrame(WebFrame&) { }

    using PasteboardItem = PDFPluginPasteboardItem;
    void writeItemsToGeneralPasteboard(Vector<PasteboardItem>&&) const;

    uint64_t streamedBytes() const;
    std::optional<WebCore::FrameIdentifier> rootFrameID() const final;

#if PLATFORM(IOS_FAMILY)
    virtual void setSelectionRange(WebCore::FloatPoint /* pointInRootView */, WebCore::TextGranularity) { }
    virtual void clearSelection() { }
    virtual std::pair<URL, WebCore::FloatRect> linkURLAndBoundsAtPoint(WebCore::FloatPoint /* pointInRootView */) const { return { }; }
    virtual std::optional<WebCore::FloatRect> highlightRectForTapAtPoint(WebCore::FloatPoint /* pointInRootView */) const { return std::nullopt; }
    virtual void handleSyntheticClick(WebCore::PlatformMouseEvent&&) { }
    virtual SelectionWasFlipped moveSelectionEndpoint(WebCore::FloatPoint /* pointInRootView */, SelectionEndpoint);
    virtual SelectionEndpoint extendInitialSelection(WebCore::FloatPoint /* pointInRootView */, WebCore::TextGranularity);
    virtual CursorContext cursorContext(WebCore::FloatPoint /* pointInRootView */) const { return { }; }
    virtual DocumentEditingContext documentEditingContext(DocumentEditingContextRequest&&) const;
#endif

    bool populateEditorStateIfNeeded(EditorState&) const;

    virtual bool shouldSizeToFitContent() const { return false; }

    virtual WebCore::FloatRect absoluteBoundingRectForSmartMagnificationAtPoint(WebCore::FloatPoint) const { return { }; }

protected:
    virtual double contentScaleFactor() const = 0;
    virtual bool platformPopulateEditorStateIfNeeded(EditorState&) const { return false; }

private:
    bool documentFinishedLoading() const { return m_documentFinishedLoading; }
    void ensureDataBufferLength(uint64_t) WTF_REQUIRES_LOCK(m_streamedDataLock);

    bool haveStreamedDataForRange(uint64_t offset, size_t count) const WTF_REQUIRES_LOCK(m_streamedDataLock);
    // This just checks whether the CFData is large enough; it doesn't know if we filled this range with data.

    void insertRangeRequestData(uint64_t offset, const Vector<uint8_t>&);

    // Returns the number of bytes copied.
    size_t copyDataAtPosition(std::span<uint8_t> buffer, uint64_t sourcePosition) const;
    // FIXME: It would be nice to avoid having both the "copy into a buffer" and "return a pointer" ways of getting data.
    void dataSpanForRange(uint64_t sourcePosition, size_t count, CheckValidRanges, CompletionHandler<void(std::span<const uint8_t>)>&&) const;
    // Returns true only if we can satisfy all of the requests.
    bool getByteRanges(CFMutableArrayRef, std::span<const CFRange>) const;

#if !LOG_DISABLED
    uint64_t streamedBytesForDebugLogging() const;
    void incrementalLoaderLogWithBytes(const String&, uint64_t streamedBytes);
#endif

protected:
    explicit PDFPluginBase(WebCore::HTMLPlugInElement&);

    WebCore::Page* page() const;

    virtual void teardown();

    bool supportsForms() const;

    void createPDFDocument();
    virtual void installPDFDocument() = 0;
    void tryRunScriptsInPDFDocument();

    virtual unsigned firstPageHeight() const = 0;

    NSData *originalData() const;
    virtual NSData *liveData() const = 0;

    void addArchiveResource();

    void invalidateRect(const WebCore::IntRect&);

    void print();

    // ScrollableArea functions.
    WebCore::IntRect scrollCornerRect() const final;
    WebCore::ScrollableArea* enclosingScrollableArea() const final;
    bool scrollAnimatorEnabled() const final { return true; }
    bool isScrollableOrRubberbandable() final { return true; }
    bool hasScrollableOrRubberbandableAncestor() final { return true; }
    WebCore::IntRect scrollableAreaBoundingBox(bool* = nullptr) const final;
    bool isActive() const final;
    bool isScrollCornerVisible() const final { return false; }
    WebCore::ScrollPosition minimumScrollPosition() const final;
    WebCore::ScrollPosition maximumScrollPosition() const final;
    WebCore::IntSize visibleSize() const final { return m_size; }
    WebCore::IntSize overhangAmount() const final;
    WebCore::IntPoint lastKnownMousePositionInView() const override;

    float deviceScaleFactor() const override;
    bool shouldSuspendScrollAnimations() const final { return false; } // If we return true, ScrollAnimatorMac will keep cycling a timer forever, waiting for a good time to animate.
    void scrollbarStyleChanged(WebCore::ScrollbarStyle, bool forceUpdate) override;

    WebCore::IntRect convertFromScrollbarToContainingView(const WebCore::Scrollbar&, const WebCore::IntRect& scrollbarRect) const final;
    WebCore::IntRect convertFromContainingViewToScrollbar(const WebCore::Scrollbar&, const WebCore::IntRect& parentRect) const final;
    WebCore::IntPoint convertFromScrollbarToContainingView(const WebCore::Scrollbar&, const WebCore::IntPoint& scrollbarPoint) const final;
    WebCore::IntPoint convertFromContainingViewToScrollbar(const WebCore::Scrollbar&, const WebCore::IntPoint& parentPoint) const final;

    bool forceUpdateScrollbarsOnMainThreadForPerformanceTesting() const final;
    bool shouldPlaceVerticalScrollbarOnLeft() const final { return false; }

    WebCore::IntRect viewRelativeVerticalScrollbarRect() const;
    WebCore::IntRect viewRelativeHorizontalScrollbarRect() const;
    WebCore::IntRect viewRelativeScrollCornerRect() const;

    String debugDescription() const final;

    // Scrolling, but not ScrollableArea:
    virtual void didChangeScrollOffset() = 0;
    virtual void updateScrollbars();
    virtual Ref<WebCore::Scrollbar> createScrollbar(WebCore::ScrollbarOrientation);
    virtual void destroyScrollbar(WebCore::ScrollbarOrientation);

    void wantsWheelEventsChanged();

    virtual void incrementalLoadingDidProgress() { }
    virtual void incrementalLoadingDidCancel() { }
    virtual void incrementalLoadingDidFinish() { }

#if ENABLE(PDF_HUD)
    void updateHUDLocation();
    WebCore::IntRect frameForHUDInRootViewCoordinates() const;
    bool hudEnabled() const;
    bool shouldShowHUD() const;
    void updateHUDVisibility();
#endif

#if !LOG_DISABLED
    void incrementalLoaderLog(const String&);
#endif

    virtual void teardownPasswordEntryForm() = 0;

    String annotationStyle() const;

    static NSString *htmlPasteboardType();
    static NSString *rtfPasteboardType();
    static NSString *stringPasteboardType();
    static NSString *urlPasteboardType();

#if PLATFORM(MAC)
    void writeStringToFindPasteboard(const String&) const;
#endif

    std::optional<WebCore::PageIdentifier> pageIdentifier() const;

    static WebCore::Color pluginBackgroundColor();

    SingleThreadWeakPtr<PluginView> m_view;
    WeakPtr<WebFrame> m_frame;
    WeakPtr<WebCore::HTMLPlugInElement, WebCore::WeakPtrImplWithEventTargetData> m_element;

    // m_data grows as we receive data in the primary request (PDFPluginBase::streamDidReceiveData())
    // but also as byte range requests are received via m_incrementalLoader, so it may have "holes"
    // before the main resource is fully loaded.
    mutable Lock m_streamedDataLock;
    RetainPtr<CFMutableDataRef> m_data WTF_GUARDED_BY_LOCK(m_streamedDataLock);
    uint64_t m_streamedBytes WTF_GUARDED_BY_LOCK(m_streamedDataLock) { 0 };
    RangeSet<WTF::Range<uint64_t>> m_validRanges WTF_GUARDED_BY_LOCK(m_streamedDataLock);

    RetainPtr<PDFDocument> m_pdfDocument;
#if PLATFORM(MAC)
    RetainPtr<WKAccessibilityPDFDocumentObject> m_accessibilityDocumentObject;
#endif

    String m_suggestedFilename;

    String m_lastFindString;

    WebCore::IntSize m_size;
    WebCore::AffineTransform m_rootViewToPluginTransform;

    WebCore::IntSize m_scrollOffset;
    std::optional<WebMouseEvent> m_lastMouseEvent;

    RefPtr<WebCore::Scrollbar> m_horizontalScrollbar;
    RefPtr<WebCore::Scrollbar> m_verticalScrollbar;

    bool m_documentFinishedLoading { false };
    bool m_isBeingDestroyed { false };
    std::atomic<bool> m_hasBeenDestroyed { false };
    bool m_didRunScripts { false };

#if PLATFORM(MAC)
    RefPtr<PDFPluginAnnotation> m_activeAnnotation;
#endif
    RefPtr<WebCore::Element> m_annotationContainer;
    bool m_pdfDocumentWasMutated { false };

#if HAVE(INCREMENTAL_PDF_APIS)
    RefPtr<PDFIncrementalLoader> m_incrementalLoader;
    std::atomic<bool> m_incrementalPDFLoadingEnabled { false };
#endif

    RefPtr<WebCore::VoidCallback> m_pdfTestCallback;

#if ENABLE(PDF_HUD)
    CompletionHandler<void(const String&, const URL&, std::span<const uint8_t>)> m_pendingSaveCompletionHandler;
    CompletionHandler<void(const String&, FrameInfoData&&, std::span<const uint8_t>, const String&)> m_pendingOpenCompletionHandler;
#endif
};

} // namespace WebKit

#endif // ENABLE(PDF_PLUGIN)