Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (258042 => 258043)
--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm 2020-03-07 01:35:40 UTC (rev 258042)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm 2020-03-07 01:44:56 UTC (rev 258043)
@@ -579,7 +579,7 @@
inline PDFPlugin::PDFPlugin(WebFrame& frame)
: Plugin(PDFPluginType)
- , m_frame(&frame)
+ , m_frame(frame)
, m_containerLayer(adoptNS([[CALayer alloc] init]))
, m_contentLayer(adoptNS([[CALayer alloc] init]))
, m_scrollCornerLayer(adoptNS([[WKPDFPluginScrollbarLayer alloc] initWithPDFPlugin:this]))
@@ -593,7 +593,7 @@
m_pdfLayerController.get().parentLayer = m_contentLayer.get();
if (supportsForms()) {
- Document* document = webFrame()->coreFrame()->document();
+ Document* document = m_frame.coreFrame()->document();
m_annotationContainer = document->createElement(divTag, false);
m_annotationContainer->setAttributeWithoutSynchronization(idAttr, AtomString("annotationContainer", AtomString::ConstructFromLiteral));
@@ -606,13 +606,13 @@
m_accessibilityObject = adoptNS([[WKPDFPluginAccessibilityObject alloc] initWithPDFPlugin:this]);
[m_accessibilityObject setPdfLayerController:m_pdfLayerController.get()];
- [m_accessibilityObject setParent:webFrame()->page()->accessibilityRemoteObject()];
+ [m_accessibilityObject setParent:m_frame.page()->accessibilityRemoteObject()];
[m_containerLayer addSublayer:m_contentLayer.get()];
[m_containerLayer addSublayer:m_scrollCornerLayer.get()];
#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
if ([m_pdfLayerController respondsToSelector:@selector(setDeviceColorSpace:)]) {
- auto view = webFrame()->coreFrame()->view();
+ auto view = m_frame.coreFrame()->view();
[m_pdfLayerController setDeviceColorSpace:screenColorSpace(view)];
}
#endif
@@ -733,22 +733,23 @@
void PDFPlugin::unconditionalCompleteRangeRequest(ByteRangeRequest& request)
{
- uint64_t fullSize = m_data ? static_cast<uint64_t>(CFDataGetLength(m_data.get())) : 0;
- if (static_cast<uint64_t>(request.position) >= fullSize) {
+ if (static_cast<uint64_t>(request.position) >= m_streamedBytes) {
request.completionHandler(nullptr, 0);
return;
}
- auto count = request.position + request.count > fullSize ? fullSize - request.position : request.count;
+ ASSERT(m_data);
+
+ auto count = request.position + request.count > m_streamedBytes ? m_streamedBytes - request.position : request.count;
request.completionHandler(CFDataGetBytePtr(m_data.get()) + request.position, count);
}
void PDFPlugin::getResourceBytesAtPosition(size_t count, off_t position, CompletionHandler<void(const uint8_t*, size_t)>&& completionHandler)
{
- ASSERT(isMainThread());
+ ASSERT(isMainThread());
- uint64_t dataLength = m_data ? static_cast<uint64_t>(CFDataGetLength(m_data.get())) : 0;
- if (m_data && dataLength >= position + count) {
+ if (m_streamedBytes >= position + count) {
+ ASSERT(m_data);
completionHandler(CFDataGetBytePtr(m_data.get()) + position, count);
return;
}
@@ -849,7 +850,7 @@
m_verticalScrollbar->setFrameRect(scrollbarRect);
}
- FrameView* frameView = m_frame->coreFrame()->view();
+ FrameView* frameView = m_frame.coreFrame()->view();
if (!frameView)
return;
@@ -900,7 +901,7 @@
[m_containerLayer addSublayer:m_verticalScrollbarLayer.get()];
}
didAddScrollbar(widget.ptr(), orientation);
- if (Frame* frame = webFrame()->coreFrame()) {
+ if (auto* frame = m_frame.coreFrame()) {
if (Page* page = frame->page()) {
if (page->isMonitoringWheelEvents())
scrollAnimator().setWheelEventTestMonitor(page->wheelEventTestMonitor());
@@ -990,7 +991,7 @@
bool PDFPlugin::isActive() const
{
- if (Frame* coreFrame = m_frame->coreFrame()) {
+ if (Frame* coreFrame = m_frame.coreFrame()) {
if (Page* page = coreFrame->page())
return page->focusController().isActive();
}
@@ -1000,7 +1001,7 @@
bool PDFPlugin::forceUpdateScrollbarsOnMainThreadForPerformanceTesting() const
{
- if (Frame* coreFrame = m_frame->coreFrame()) {
+ if (Frame* coreFrame = m_frame.coreFrame()) {
if (Page* page = coreFrame->page())
return page->settings().forceUpdateScrollbarsOnMainThreadForPerformanceTesting();
}
@@ -1068,13 +1069,9 @@
JSValueRef PDFPlugin::jsPDFDocPrint(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
- PDFPlugin* pdfView = static_cast<PDFPlugin*>(JSObjectGetPrivate(thisObject));
+ PDFPlugin* pdfPlugin = static_cast<PDFPlugin*>(JSObjectGetPrivate(thisObject));
- WebFrame* frame = pdfView->m_frame;
- if (!frame)
- return JSValueMakeUndefined(ctx);
-
- Frame* coreFrame = frame->coreFrame();
+ Frame* coreFrame = pdfPlugin->m_frame.coreFrame();
if (!coreFrame)
return JSValueMakeUndefined(ctx);
@@ -1156,7 +1153,7 @@
createPasswordEntryForm();
if ([m_pdfLayerController respondsToSelector:@selector(setURLFragment:)]) {
- String pdfURLFragment = webFrame()->url().fragmentIdentifier();
+ String pdfURLFragment = m_frame.url().fragmentIdentifier();
[m_pdfLayerController setURLFragment:pdfURLFragment];
}
}
@@ -1190,6 +1187,7 @@
m_data = adoptCF(CFDataCreateMutable(0, 0));
CFDataAppendBytes(m_data.get(), reinterpret_cast<const UInt8*>(bytes), length);
+ m_streamedBytes += length;
}
void PDFPlugin::streamDidFinishLoading(uint64_t streamID)
@@ -1221,12 +1219,13 @@
m_data = adoptCF(CFDataCreateMutable(0, 0));
CFDataAppendBytes(m_data.get(), reinterpret_cast<const UInt8*>(bytes), length);
+ m_streamedBytes += length;
#if HAVE(INCREMENTAL_PDF_APIS)
size_t index = 0;
while (index < m_outstandingByteRangeRequests.size()) {
auto& request = m_outstandingByteRangeRequests[index];
- if (static_cast<uint64_t>(CFDataGetLength(m_data.get())) >= request.position + request.count) {
+ if (m_streamedBytes >= request.position + request.count) {
request.completionHandler(CFDataGetBytePtr(m_data.get()) + request.position, request.count);
m_outstandingByteRangeRequests.remove(index);
continue;
@@ -1290,7 +1289,7 @@
{
double newScaleFactor = controller()->contentsScaleFactor();
if (!handlesPageScaleFactor())
- newScaleFactor *= webFrame()->page()->pageScaleFactor();
+ newScaleFactor *= m_frame.page()->pageScaleFactor();
if (newScaleFactor != [m_pdfLayerController deviceScaleFactor])
[m_pdfLayerController setDeviceScaleFactor:newScaleFactor];
@@ -1325,10 +1324,8 @@
void PDFPlugin::willDetachRenderer()
{
- if (webFrame()) {
- if (FrameView* frameView = webFrame()->coreFrame()->view())
- frameView->removeScrollableArea(this);
- }
+ if (auto* frameView = m_frame.coreFrame()->view())
+ frameView->removeScrollableArea(this);
}
void PDFPlugin::destroy()
@@ -1347,10 +1344,8 @@
m_pdfLayerController.get().delegate = 0;
- if (webFrame()) {
- if (FrameView* frameView = webFrame()->coreFrame()->view())
- frameView->removeScrollableArea(this);
- }
+ if (auto* frameView = m_frame.coreFrame()->view())
+ frameView->removeScrollableArea(this);
m_activeAnnotation = nullptr;
m_annotationContainer = nullptr;
@@ -1376,7 +1371,7 @@
void PDFPlugin::paintControlForLayerInContext(CALayer *layer, CGContextRef context)
{
#if PLATFORM(MAC)
- auto* page = webFrame()->coreFrame()->page();
+ auto* page = m_frame.coreFrame()->page();
LocalDefaultSystemAppearance localAppearance(page->useDarkAppearance());
#endif
@@ -1457,7 +1452,7 @@
FloatRect PDFPlugin::convertFromPDFViewToScreen(const FloatRect& rect) const
{
- FrameView* frameView = webFrame()->coreFrame()->view();
+ FrameView* frameView = m_frame.coreFrame()->view();
if (!frameView)
return FloatRect();
@@ -1464,12 +1459,12 @@
FloatRect updatedRect = rect;
updatedRect.setLocation(convertFromPDFViewToRootView(IntPoint(updatedRect.location())));
- return webFrame()->coreFrame()->page()->chrome().rootViewToScreen(enclosingIntRect(updatedRect));
+ return m_frame.coreFrame()->page()->chrome().rootViewToScreen(enclosingIntRect(updatedRect));
}
IntRect PDFPlugin::boundsOnScreen() const
{
- FrameView* frameView = webFrame()->coreFrame()->view();
+ FrameView* frameView = m_frame.coreFrame()->view();
if (!frameView)
return IntRect();
@@ -1721,7 +1716,7 @@
bool PDFPlugin::showContextMenuAtPoint(const IntPoint& point)
{
- FrameView* frameView = webFrame()->coreFrame()->view();
+ FrameView* frameView = m_frame.coreFrame()->view();
IntPoint contentsPoint = frameView->contentsToRootView(point);
WebMouseEvent event(WebEvent::MouseDown, WebMouseEvent::RightButton, 0, contentsPoint, contentsPoint, 0, 0, 0, 1, OptionSet<WebEvent::Modifier> { }, WallTime::now(), WebCore::ForceAtClick);
return handleContextMenuEvent(event);
@@ -1729,11 +1724,11 @@
bool PDFPlugin::handleContextMenuEvent(const WebMouseEvent& event)
{
- if (!webFrame()->page())
+ if (!m_frame.page())
return false;
- WebPage* webPage = webFrame()->page();
- FrameView* frameView = webFrame()->coreFrame()->view();
+ WebPage* webPage = m_frame.page();
+ FrameView* frameView = m_frame.coreFrame()->view();
IntPoint point = frameView->contentsToScreen(IntRect(frameView->windowToContents(event.position()), IntSize())).location();
NSUserInterfaceLayoutDirection uiLayoutDirection = webPage->userInterfaceLayoutDirection() == UserInterfaceLayoutDirection::LTR ? NSUserInterfaceLayoutDirectionLeftToRight : NSUserInterfaceLayoutDirectionRightToLeft;
@@ -1841,13 +1836,13 @@
{
// <object> or <embed> plugins will appear to be in their parent frame, so we have to
// check whether our frame's widget is exactly our PluginView.
- Document* document = webFrame()->coreFrame()->document();
+ Document* document = m_frame.coreFrame()->document();
return document->isPluginDocument() && static_cast<PluginDocument*>(document)->pluginWidget() == pluginView();
}
bool PDFPlugin::handlesPageScaleFactor() const
{
- return webFrame()->isMainFrame() && isFullFramePlugin();
+ return m_frame.isMainFrame() && isFullFramePlugin();
}
void PDFPlugin::clickedLink(NSURL *url)
@@ -1856,7 +1851,7 @@
if (WTF::protocolIsJavaScript(coreURL))
return;
- Frame* frame = webFrame()->coreFrame();
+ auto* frame = m_frame.coreFrame();
RefPtr<Event> coreEvent;
if (m_lastMouseEvent.type() != WebEvent::NoType)
@@ -1933,7 +1928,7 @@
return;
NSData *data = ""
- webFrame()->page()->savePDFToFileInDownloadsFolder(m_suggestedFilename, webFrame()->url(), static_cast<const unsigned char *>([data bytes]), [data length]);
+ m_frame.page()->savePDFToFileInDownloadsFolder(m_suggestedFilename, m_frame.url(), static_cast<const unsigned char *>([data bytes]), [data length]);
}
void PDFPlugin::openWithNativeApplication()
@@ -1949,11 +1944,11 @@
m_temporaryPDFUUID = createCanonicalUUIDString();
ASSERT(m_temporaryPDFUUID);
- webFrame()->page()->savePDFToTemporaryFolderAndOpenWithNativeApplication(m_suggestedFilename, webFrame()->url(), static_cast<const unsigned char *>([data bytes]), [data length], m_temporaryPDFUUID);
+ m_frame.page()->savePDFToTemporaryFolderAndOpenWithNativeApplication(m_suggestedFilename, m_frame.url(), static_cast<const unsigned char *>([data bytes]), [data length], m_temporaryPDFUUID);
return;
}
- webFrame()->page()->send(Messages::WebPageProxy::OpenPDFFromTemporaryFolderWithNativeApplication(m_temporaryPDFUUID));
+ m_frame.page()->send(Messages::WebPageProxy::OpenPDFFromTemporaryFolderWithNativeApplication(m_temporaryPDFUUID));
}
void PDFPlugin::writeItemsToPasteboard(NSString *pasteboardName, NSArray *items, NSArray *types)
@@ -2015,7 +2010,7 @@
dataForSelection.presentationTransition = TextIndicatorPresentationTransition::FadeIn;
dictionaryPopupInfo.textIndicator = dataForSelection;
- webFrame()->page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
+ m_frame.page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
}
unsigned PDFPlugin::countFindMatches(const String& target, WebCore::FindOptions options, unsigned /*maxMatchCount*/)
@@ -2123,7 +2118,7 @@
void PDFPlugin::notifySelectionChanged(PDFSelection *)
{
- webFrame()->page()->didChangeSelection();
+ m_frame.page()->didChangeSelection();
}
static const WebCore::Cursor& coreCursor(PDFLayerControllerCursorType type)
@@ -2141,7 +2136,7 @@
void PDFPlugin::notifyCursorChanged(uint64_t type)
{
- webFrame()->page()->send(Messages::WebPageProxy::SetCursor(coreCursor(static_cast<PDFLayerControllerCursorType>(type))));
+ m_frame.page()->send(Messages::WebPageProxy::SetCursor(coreCursor(static_cast<PDFLayerControllerCursorType>(type))));
}
String PDFPlugin::getSelectionString() const
@@ -2265,7 +2260,7 @@
WebCore::AXObjectCache* PDFPlugin::axObjectCache() const
{
- return webFrame()->coreFrame()->document()->axObjectCache();
+ return m_frame.coreFrame()->document()->axObjectCache();
}
WebCore::FloatRect PDFPlugin::rectForSelectionInRootView(PDFSelection *selection) const
@@ -2294,12 +2289,12 @@
void PDFPlugin::performWebSearch(NSString *string)
{
- webFrame()->page()->send(Messages::WebPageProxy::SearchTheWeb(string));
+ m_frame.page()->send(Messages::WebPageProxy::SearchTheWeb(string));
}
void PDFPlugin::performSpotlightSearch(NSString *string)
{
- webFrame()->page()->send(Messages::WebPageProxy::SearchWithSpotlight(string));
+ m_frame.page()->send(Messages::WebPageProxy::SearchWithSpotlight(string));
}
bool PDFPlugin::handleWheelEvent(const WebWheelEvent& event)