Title: [268989] trunk/Source/WebKit
Revision
268989
Author
[email protected]
Date
2020-10-26 11:40:57 -0700 (Mon, 26 Oct 2020)

Log Message

Add null checks and smart pointers in PDF and Plugin code
https://bugs.webkit.org/show_bug.cgi?id=218144
<rdar://problem/69931543>

Patch by Alex Christensen <[email protected]> on 2020-10-26
Reviewed by Youenn Fablet.

It's nice when things don't crash.
isBeingAsynchronouslyInitialized wasn't called anywhere, so I removed it.

* WebProcess/Plugins/PDF/PDFPlugin.h:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::PDFPlugin):
(WebKit::PDFPlugin::~PDFPlugin):
(WebKit::PDFPlugin::getResourceBytesAtPosition):
(WebKit::PDFPlugin::updateScrollbars):
(WebKit::PDFPlugin::createScrollbar):
(WebKit::PDFPlugin::isActive const):
(WebKit::PDFPlugin::forceUpdateScrollbarsOnMainThreadForPerformanceTesting const):
(WebKit::PDFPlugin::jsPDFDocPrint):
(WebKit::PDFPlugin::installPDFDocument):
(WebKit::PDFPlugin::updatePageAndDeviceScaleFactors):
(WebKit::PDFPlugin::calculateSizes):
(WebKit::PDFPlugin::willDetachRenderer):
(WebKit::PDFPlugin::destroy):
(WebKit::PDFPlugin::paintControlForLayerInContext):
(WebKit::PDFPlugin::convertFromPDFViewToScreen const):
(WebKit::PDFPlugin::boundsOnScreen const):
(WebKit::PDFPlugin::visibilityDidChange):
(WebKit::PDFPlugin::showContextMenuAtPoint):
(WebKit::PDFPlugin::handleContextMenuEvent):
(WebKit::PDFPlugin::isFullFramePlugin const):
(WebKit::PDFPlugin::handlesPageScaleFactor const):
(WebKit::PDFPlugin::clickedLink):
(WebKit::PDFPlugin::save):
(WebKit::PDFPlugin::openWithPreview):
(WebKit::PDFPlugin::saveToPDF):
(WebKit::PDFPlugin::openWithNativeApplication):
(WebKit::PDFPlugin::showDefinitionForAttributedString):
(WebKit::PDFPlugin::notifySelectionChanged):
(WebKit::PDFPlugin::notifyCursorChanged):
(WebKit::PDFPlugin::axObjectCache const):
(WebKit::PDFPlugin::performWebSearch):
(WebKit::PDFPlugin::performSpotlightSearch):
* WebProcess/Plugins/Plugin.cpp:
(WebKit::Plugin::Plugin):
(WebKit::Plugin::initialize):
(WebKit::Plugin::controller):
(WebKit::Plugin::controller const):
(WebKit::Plugin::~Plugin): Deleted.
* WebProcess/Plugins/Plugin.h:
(WebKit::Plugin::controller): Deleted.
(WebKit::Plugin::controller const): Deleted.
* WebProcess/Plugins/PluginController.h:
* WebProcess/WebPage/WebFrame.h:
(WebKit::WebFrame::setLoadListener):
(WebKit::WebFrame::loadListener const):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (268988 => 268989)


--- trunk/Source/WebKit/ChangeLog	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/ChangeLog	2020-10-26 18:40:57 UTC (rev 268989)
@@ -1,3 +1,62 @@
+2020-10-26  Alex Christensen  <[email protected]>
+
+        Add null checks and smart pointers in PDF and Plugin code
+        https://bugs.webkit.org/show_bug.cgi?id=218144
+        <rdar://problem/69931543>
+
+        Reviewed by Youenn Fablet.
+
+        It's nice when things don't crash.
+        isBeingAsynchronouslyInitialized wasn't called anywhere, so I removed it.
+
+        * WebProcess/Plugins/PDF/PDFPlugin.h:
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::PDFPlugin):
+        (WebKit::PDFPlugin::~PDFPlugin):
+        (WebKit::PDFPlugin::getResourceBytesAtPosition):
+        (WebKit::PDFPlugin::updateScrollbars):
+        (WebKit::PDFPlugin::createScrollbar):
+        (WebKit::PDFPlugin::isActive const):
+        (WebKit::PDFPlugin::forceUpdateScrollbarsOnMainThreadForPerformanceTesting const):
+        (WebKit::PDFPlugin::jsPDFDocPrint):
+        (WebKit::PDFPlugin::installPDFDocument):
+        (WebKit::PDFPlugin::updatePageAndDeviceScaleFactors):
+        (WebKit::PDFPlugin::calculateSizes):
+        (WebKit::PDFPlugin::willDetachRenderer):
+        (WebKit::PDFPlugin::destroy):
+        (WebKit::PDFPlugin::paintControlForLayerInContext):
+        (WebKit::PDFPlugin::convertFromPDFViewToScreen const):
+        (WebKit::PDFPlugin::boundsOnScreen const):
+        (WebKit::PDFPlugin::visibilityDidChange):
+        (WebKit::PDFPlugin::showContextMenuAtPoint):
+        (WebKit::PDFPlugin::handleContextMenuEvent):
+        (WebKit::PDFPlugin::isFullFramePlugin const):
+        (WebKit::PDFPlugin::handlesPageScaleFactor const):
+        (WebKit::PDFPlugin::clickedLink):
+        (WebKit::PDFPlugin::save):
+        (WebKit::PDFPlugin::openWithPreview):
+        (WebKit::PDFPlugin::saveToPDF):
+        (WebKit::PDFPlugin::openWithNativeApplication):
+        (WebKit::PDFPlugin::showDefinitionForAttributedString):
+        (WebKit::PDFPlugin::notifySelectionChanged):
+        (WebKit::PDFPlugin::notifyCursorChanged):
+        (WebKit::PDFPlugin::axObjectCache const):
+        (WebKit::PDFPlugin::performWebSearch):
+        (WebKit::PDFPlugin::performSpotlightSearch):
+        * WebProcess/Plugins/Plugin.cpp:
+        (WebKit::Plugin::Plugin):
+        (WebKit::Plugin::initialize):
+        (WebKit::Plugin::controller):
+        (WebKit::Plugin::controller const):
+        (WebKit::Plugin::~Plugin): Deleted.
+        * WebProcess/Plugins/Plugin.h:
+        (WebKit::Plugin::controller): Deleted.
+        (WebKit::Plugin::controller const): Deleted.
+        * WebProcess/Plugins/PluginController.h:
+        * WebProcess/WebPage/WebFrame.h:
+        (WebKit::WebFrame::setLoadListener):
+        (WebKit::WebFrame::loadListener const):
+
 2020-10-26  Youenn Fablet  <[email protected]>
 
         Add support for VP9 Profile 2 (10-bit color) in WebRTC

Modified: trunk/Source/WebKit/PluginProcess/PluginControllerProxy.cpp (268988 => 268989)


--- trunk/Source/WebKit/PluginProcess/PluginControllerProxy.cpp	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/PluginProcess/PluginControllerProxy.cpp	2020-10-26 18:40:57 UTC (rev 268989)
@@ -119,7 +119,7 @@
     if (creationParameters.windowNPObjectID)
         m_windowNPObject = m_connection->npRemoteObjectMap()->createNPObjectProxy(creationParameters.windowNPObjectID, m_plugin.get());
 
-    bool returnValue = m_plugin->initialize(this, creationParameters.parameters);
+    bool returnValue = m_plugin->initialize(*this, creationParameters.parameters);
 
     if (!returnValue) {
         // Get the plug-in so we can pass it to removePluginControllerProxy. The pointer is only

Modified: trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapePlugin.h (268988 => 268989)


--- trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapePlugin.h	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapePlugin.h	2020-10-26 18:40:57 UTC (rev 268989)
@@ -60,9 +60,6 @@
 
     static RefPtr<NetscapePlugin> fromNPP(NPP);
 
-    // In-process NetscapePlugins don't support asynchronous initialization.
-    bool isBeingAsynchronouslyInitialized() const override { return false; }
-
 #if PLATFORM(COCOA)
     NPError setDrawingModel(NPDrawingModel);
     NPError setEventModel(NPEventModel);

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


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-10-26 18:40:57 UTC (rev 268989)
@@ -43,6 +43,7 @@
 #include <wtf/RangeSet.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/Threading.h>
+#include <wtf/WeakPtr.h>
 
 typedef const struct OpaqueJSContext* JSContextRef;
 typedef struct OpaqueJSValue* JSObjectRef;
@@ -213,8 +214,6 @@
     void willDetachRenderer() final;
     bool pluginHandlesContentOffsetForAccessibilityHitTest() const final;
     
-    bool isBeingAsynchronouslyInitialized() const final { return false; }
-
     RetainPtr<PDFDocument> pdfDocumentForPrinting() const final { return m_pdfDocument; }
     NSObject *accessibilityObject() const final;
     id accessibilityAssociatedPluginParentForElement(WebCore::Element*) const final;
@@ -303,7 +302,7 @@
     PluginView* pluginView();
     const PluginView* pluginView() const;
 
-    WebFrame& m_frame;
+    WeakPtr<WebFrame> m_frame;
 
     bool m_isPostScript { false };
     bool m_pdfDocumentWasMutated { false };

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


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-10-26 18:40:57 UTC (rev 268989)
@@ -596,7 +596,7 @@
 
 inline PDFPlugin::PDFPlugin(WebFrame& frame)
     : Plugin(PDFPluginType)
-    , m_frame(frame)
+    , m_frame(makeWeakPtr(frame))
     , m_containerLayer(adoptNS([[CALayer alloc] init]))
     , m_contentLayer(adoptNS([[CALayer alloc] init]))
     , m_scrollCornerLayer(adoptNS([[WKPDFPluginScrollbarLayer alloc] initWithPDFPlugin:this]))
@@ -617,7 +617,7 @@
     m_pdfLayerController.get().parentLayer = m_contentLayer.get();
 
     if (supportsForms()) {
-        Document* document = m_frame.coreFrame()->document();
+        auto* document = frame.coreFrame()->document();
         m_annotationContainer = document->createElement(divTag, false);
         m_annotationContainer->setAttributeWithoutSynchronization(idAttr, AtomString("annotationContainer", AtomString::ConstructFromLiteral));
 
@@ -630,13 +630,13 @@
 
     m_accessibilityObject = adoptNS([[WKPDFPluginAccessibilityObject alloc] initWithPDFPlugin:this]);
     [m_accessibilityObject setPdfLayerController:m_pdfLayerController.get()];
-    [m_accessibilityObject setParent:m_frame.page()->accessibilityRemoteObject()];
+    [m_accessibilityObject setParent: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 = m_frame.coreFrame()->view();
+        auto view = frame.coreFrame()->view();
         [m_pdfLayerController setDeviceColorSpace:screenColorSpace(view)];
     }
 #endif
@@ -653,7 +653,7 @@
 PDFPlugin::~PDFPlugin()
 {
 #if ENABLE(UI_PROCESS_PDF_HUD)
-    if (auto* page = m_frame.page())
+    if (auto* page = m_frame ? m_frame->page() : nullptr)
         page->removePDFHUD(*this);
 #endif
 }
@@ -965,7 +965,9 @@
     auto identifier = request.identifier();
     m_outstandingByteRangeRequests.set(identifier, WTFMove(request));
 
-    auto* coreFrame = m_frame.coreFrame();
+    if (!m_frame)
+        return;
+    auto* coreFrame = m_frame->coreFrame();
     if (!coreFrame)
         return;
 
@@ -1289,7 +1291,7 @@
         m_verticalScrollbar->setFrameRect(scrollbarRect);
     }
 
-    FrameView* frameView = m_frame.coreFrame()->view();
+    auto* frameView = m_frame ? m_frame->coreFrame()->view() : nullptr;
     if (!frameView)
         return;
 
@@ -1341,8 +1343,8 @@
     }
     didAddScrollbar(widget.ptr(), orientation);
 
-    if (auto* frame = m_frame.coreFrame()) {
-        if (Page* page = frame->page()) {
+    if (auto* frame = m_frame ? m_frame->coreFrame() : nullptr) {
+        if (auto* page = frame->page()) {
             if (page->isMonitoringWheelEvents())
                 scrollAnimator().setWheelEventTestMonitor(page->wheelEventTestMonitor());
         }
@@ -1443,8 +1445,8 @@
 
 bool PDFPlugin::isActive() const
 {
-    if (Frame* coreFrame = m_frame.coreFrame()) {
-        if (Page* page = coreFrame->page())
+    if (auto* coreFrame = m_frame ? m_frame->coreFrame() : nullptr) {
+        if (auto* page = coreFrame->page())
             return page->focusController().isActive();
     }
 
@@ -1453,8 +1455,8 @@
 
 bool PDFPlugin::forceUpdateScrollbarsOnMainThreadForPerformanceTesting() const
 {
-    if (Frame* coreFrame = m_frame.coreFrame()) {
-        if (Page* page = coreFrame->page())
+    if (auto* coreFrame = m_frame ? m_frame->coreFrame() : nullptr) {
+        if (auto* page = coreFrame->page())
             return page->settings().forceUpdateScrollbarsOnMainThreadForPerformanceTesting();
     }
 
@@ -1524,13 +1526,17 @@
 
 JSValueRef PDFPlugin::jsPDFDocPrint(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
-    PDFPlugin* pdfPlugin = static_cast<PDFPlugin*>(JSObjectGetPrivate(thisObject));
+    auto* pdfPlugin = static_cast<PDFPlugin*>(JSObjectGetPrivate(thisObject));
 
-    Frame* coreFrame = pdfPlugin->m_frame.coreFrame();
+    auto* frame = pdfPlugin->m_frame.get();
+    if (!frame)
+        return JSValueMakeUndefined(ctx);
+
+    auto* coreFrame = frame->coreFrame();
     if (!coreFrame)
         return JSValueMakeUndefined(ctx);
 
-    Page* page = coreFrame->page();
+    auto* page = coreFrame->page();
     if (!page)
         return JSValueMakeUndefined(ctx);
 
@@ -1632,8 +1638,8 @@
     if ([m_pdfDocument isLocked])
         createPasswordEntryForm();
 
-    if ([m_pdfLayerController respondsToSelector:@selector(setURLFragment:)])
-        [m_pdfLayerController setURLFragment:m_frame.url().fragmentIdentifier().createNSString().get()];
+    if (m_frame && [m_pdfLayerController respondsToSelector:@selector(setURLFragment:)])
+        [m_pdfLayerController setURLFragment:m_frame->url().fragmentIdentifier().createNSString().get()];
 }
 
 void PDFPlugin::setSuggestedFilename(const String& suggestedFilename)
@@ -1814,7 +1820,7 @@
 
     double newScaleFactor = controller()->contentsScaleFactor();
     if (!handlesPageScaleFactor()) {
-        if (auto* page = m_frame.page())
+        if (auto* page = m_frame ? m_frame->page() : nullptr)
             newScaleFactor *= page->pageScaleFactor();
     }
 
@@ -1844,7 +1850,9 @@
     setPDFDocumentSize(IntSize([m_pdfLayerController contentSizeRespectingZoom]));
 
 #if ENABLE(UI_PROCESS_PDF_HUD)
-    m_frame.page()->updatePDFHUDLocation(*this, frameForHUD());
+    if (!m_frame || !m_frame->page())
+        return;
+    m_frame->page()->updatePDFHUDLocation(*this, frameForHUD());
 #endif
 }
 
@@ -1860,7 +1868,9 @@
 
 void PDFPlugin::willDetachRenderer()
 {
-    if (auto* frameView = m_frame.coreFrame()->view())
+    if (!m_frame || !m_frame->coreFrame())
+        return;
+    if (auto* frameView = m_frame->coreFrame()->view())
         frameView->removeScrollableArea(this);
 }
 
@@ -1881,7 +1891,7 @@
 
     m_pdfLayerController.get().delegate = 0;
 
-    if (auto* frameView = m_frame.coreFrame()->view())
+    if (auto* frameView = m_frame && m_frame->coreFrame() ? m_frame->coreFrame()->view() : nullptr)
         frameView->removeScrollableArea(this);
 
     m_activeAnnotation = nullptr;
@@ -1908,7 +1918,9 @@
 void PDFPlugin::paintControlForLayerInContext(CALayer *layer, CGContextRef context)
 {
 #if PLATFORM(MAC)
-    auto* page = m_frame.coreFrame()->page();
+    auto* page = m_frame && m_frame->coreFrame() ? m_frame->coreFrame()->page() : nullptr;
+    if (!page)
+        return;
     LocalDefaultSystemAppearance localAppearance(page->useDarkAppearance());
 #endif
 
@@ -1997,22 +2009,26 @@
 
 FloatRect PDFPlugin::convertFromPDFViewToScreen(const FloatRect& rect) const
 {
-    FrameView* frameView = m_frame.coreFrame()->view();
-
+    auto* coreFrame = m_frame ? m_frame->coreFrame() : nullptr;
+    if (!coreFrame)
+        return { };
+    auto* frameView = coreFrame->view();
     if (!frameView)
-        return FloatRect();
+        return { };
 
     FloatRect updatedRect = rect;
     updatedRect.setLocation(convertFromPDFViewToRootView(IntPoint(updatedRect.location())));
-    return m_frame.coreFrame()->page()->chrome().rootViewToScreen(enclosingIntRect(updatedRect));
+    auto* page = coreFrame->page();
+    if (!page)
+        return { };
+    return page->chrome().rootViewToScreen(enclosingIntRect(updatedRect));
 }
 
 IntRect PDFPlugin::boundsOnScreen() const
 {
-    FrameView* frameView = m_frame.coreFrame()->view();
-
+    auto* frameView = m_frame ? m_frame->coreFrame()->view() : nullptr;
     if (!frameView)
-        return IntRect();
+        return { };
 
     FloatRect bounds = FloatRect(FloatPoint(), size());
     FloatRect rectInRootViewCoordinates = m_rootViewToPluginTransform.inverse().valueOr(AffineTransform()).mapRect(bounds);
@@ -2022,10 +2038,12 @@
 void PDFPlugin::visibilityDidChange(bool visible)
 {
 #if ENABLE(UI_PROCESS_PDF_HUD)
+    if (!m_frame)
+        return;
     if (visible)
-        m_frame.page()->createPDFHUD(*this, frameForHUD());
+        m_frame->page()->createPDFHUD(*this, frameForHUD());
     else
-        m_frame.page()->removePDFHUD(*this);
+        m_frame->page()->removePDFHUD(*this);
 #else
     UNUSED_PARAM(visible);
 #endif
@@ -2273,7 +2291,9 @@
     
 bool PDFPlugin::showContextMenuAtPoint(const IntPoint& point)
 {
-    FrameView* frameView = m_frame.coreFrame()->view();
+    auto* frameView = m_frame ? m_frame->coreFrame()->view() : nullptr;
+    if (!frameView)
+        return false;
     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);
@@ -2281,11 +2301,15 @@
 
 bool PDFPlugin::handleContextMenuEvent(const WebMouseEvent& event)
 {
-    if (!m_frame.page())
+    if (!m_frame || !m_frame->coreFrame())
         return false;
+    auto* webPage = m_frame->page();
+    if (!webPage)
+        return false;
+    auto* frameView = m_frame->coreFrame()->view();
+    if (!frameView)
+        return false;
 
-    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;
@@ -2393,13 +2417,17 @@
 {
     // <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 = m_frame.coreFrame()->document();
+    if (!m_frame || !m_frame->coreFrame())
+        return false;
+    auto* document = m_frame->coreFrame()->document();
+    if (!document)
+        return false;
     return document->isPluginDocument() && static_cast<PluginDocument*>(document)->pluginWidget() == pluginView();
 }
 
 bool PDFPlugin::handlesPageScaleFactor() const
 {
-    return m_frame.isMainFrame() && isFullFramePlugin();
+    return m_frame && m_frame->isMainFrame() && isFullFramePlugin();
 }
 
 void PDFPlugin::clickedLink(NSURL *url)
@@ -2408,7 +2436,9 @@
     if (coreURL.protocolIsJavaScript())
         return;
 
-    auto* frame = m_frame.coreFrame();
+    auto* frame = m_frame ? m_frame->coreFrame() : nullptr;
+    if (!frame)
+        return;
 
     RefPtr<Event> coreEvent;
     if (m_lastMouseEvent.type() != WebEvent::NoType)
@@ -2491,13 +2521,19 @@
 void PDFPlugin::save(CompletionHandler<void(const String&, const URL&, const IPC::DataReference&)>&& completionHandler)
 {
     NSData *data = ""
-    completionHandler(m_suggestedFilename, m_frame.url(), IPC:: DataReference(static_cast<const uint8_t*>(data.bytes), data.length));
+    URL url;
+    if (m_frame)
+        url = ""
+    completionHandler(m_suggestedFilename, url, IPC:: DataReference(static_cast<const uint8_t*>(data.bytes), data.length));
 }
 
 void PDFPlugin::openWithPreview(CompletionHandler<void(const String&, FrameInfoData&&, const IPC::DataReference&, const String&)>&& completionHandler)
 {
     NSData *data = ""
-    completionHandler(m_suggestedFilename, m_frame.info(), IPC:: DataReference { static_cast<const uint8_t*>(data.bytes), data.length }, createCanonicalUUIDString());
+    FrameInfoData frameInfo;
+    if (m_frame)
+        frameInfo = m_frame->info();
+    completionHandler(m_suggestedFilename, WTFMove(frameInfo), IPC:: DataReference { static_cast<const uint8_t*>(data.bytes), data.length }, createCanonicalUUIDString());
 }
 
 #else // ENABLE(UI_PROCESS_PDF_HUD)
@@ -2510,11 +2546,16 @@
         return;
 
     NSData *data = ""
-    m_frame.page()->savePDFToFileInDownloadsFolder(m_suggestedFilename, m_frame.url(), static_cast<const unsigned char *>([data bytes]), [data length]);
+    if (!m_frame || !m_frame->page())
+        return;
+    m_frame->page()->savePDFToFileInDownloadsFolder(m_suggestedFilename, m_frame->url(), static_cast<const unsigned char *>([data bytes]), [data length]);
 }
 
 void PDFPlugin::openWithNativeApplication()
 {
+    if (!m_frame || !m_frame->page())
+        return;
+
     if (!m_temporaryPDFUUID) {
         // FIXME: We should probably notify the user that they can't save before the document is finished loading.
         // PDFViewController does an NSBeep(), but that seems insufficient.
@@ -2526,11 +2567,11 @@
         m_temporaryPDFUUID = createCanonicalUUIDString();
         ASSERT(m_temporaryPDFUUID);
 
-        m_frame.page()->savePDFToTemporaryFolderAndOpenWithNativeApplication(m_suggestedFilename, m_frame.info(), static_cast<const unsigned char *>([data bytes]), [data length], m_temporaryPDFUUID);
+        m_frame->page()->savePDFToTemporaryFolderAndOpenWithNativeApplication(m_suggestedFilename, m_frame->info(), static_cast<const unsigned char *>([data bytes]), [data length], m_temporaryPDFUUID);
         return;
     }
 
-    m_frame.page()->send(Messages::WebPageProxy::OpenPDFFromTemporaryFolderWithNativeApplication(m_frame.info(), m_temporaryPDFUUID));
+    m_frame->page()->send(Messages::WebPageProxy::OpenPDFFromTemporaryFolderWithNativeApplication(m_frame->info(), m_temporaryPDFUUID));
 }
 
 #endif // ENABLE(UI_PROCESS_PDF_HUD)
@@ -2591,7 +2632,10 @@
     dataForSelection.presentationTransition = TextIndicatorPresentationTransition::FadeIn;
     dictionaryPopupInfo.textIndicator = dataForSelection;
     
-    m_frame.page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
+    if (!m_frame || !m_frame->page())
+        return;
+
+    m_frame->page()->send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfo));
 }
 
 unsigned PDFPlugin::countFindMatches(const String& target, WebCore::FindOptions options, unsigned /*maxMatchCount*/)
@@ -2699,7 +2743,9 @@
 
 void PDFPlugin::notifySelectionChanged(PDFSelection *)
 {
-    m_frame.page()->didChangeSelection();
+    if (!m_frame || !m_frame->page())
+        return;
+    m_frame->page()->didChangeSelection();
 }
 
 static const WebCore::Cursor& coreCursor(PDFLayerControllerCursorType type)
@@ -2717,7 +2763,10 @@
 
 void PDFPlugin::notifyCursorChanged(uint64_t type)
 {
-    m_frame.page()->send(Messages::WebPageProxy::SetCursor(coreCursor(static_cast<PDFLayerControllerCursorType>(type))));
+    if (!m_frame || !m_frame->page())
+        return;
+
+    m_frame->page()->send(Messages::WebPageProxy::SetCursor(coreCursor(static_cast<PDFLayerControllerCursorType>(type))));
 }
 
 String PDFPlugin::getSelectionString() const
@@ -2841,7 +2890,9 @@
     
 WebCore::AXObjectCache* PDFPlugin::axObjectCache() const
 {
-    return m_frame.coreFrame()->document()->axObjectCache();
+    if (!m_frame || !m_frame->coreFrame() || !m_frame->coreFrame()->document())
+        return nullptr;
+    return m_frame->coreFrame()->document()->axObjectCache();
 }
 
 WebCore::FloatRect PDFPlugin::rectForSelectionInRootView(PDFSelection *selection) const
@@ -2870,12 +2921,16 @@
 
 void PDFPlugin::performWebSearch(NSString *string)
 {
-    m_frame.page()->send(Messages::WebPageProxy::SearchTheWeb(string));
+    if (!m_frame || !m_frame->page())
+        return;
+    m_frame->page()->send(Messages::WebPageProxy::SearchTheWeb(string));
 }
 
 void PDFPlugin::performSpotlightSearch(NSString *string)
 {
-    m_frame.page()->send(Messages::WebPageProxy::SearchWithSpotlight(string));
+    if (!m_frame || !m_frame->page())
+        return;
+    m_frame->page()->send(Messages::WebPageProxy::SearchWithSpotlight(string));
 }
 
 bool PDFPlugin::handleWheelEvent(const WebWheelEvent& event)

Modified: trunk/Source/WebKit/WebProcess/Plugins/Plugin.cpp (268988 => 268989)


--- trunk/Source/WebKit/WebProcess/Plugins/Plugin.cpp	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/Plugins/Plugin.cpp	2020-10-26 18:40:57 UTC (rev 268989)
@@ -27,6 +27,7 @@
 #include "Plugin.h"
 
 #include "LayerTreeContext.h"
+#include "PluginController.h"
 #include "WebCoreArgumentCoders.h"
 #include <WebCore/IntPoint.h>
 #include <wtf/SetForScope.h>
@@ -82,20 +83,16 @@
 
 Plugin::Plugin(PluginType type)
     : m_type(type)
-    , m_pluginController(0)
 {
 }
 
-Plugin::~Plugin()
-{
-}
+Plugin::~Plugin() = default;
 
-bool Plugin::initialize(PluginController* pluginController, const Parameters& parameters)
+bool Plugin::initialize(PluginController& pluginController, const Parameters& parameters)
 {
     ASSERT(!m_pluginController);
-    ASSERT(pluginController);
 
-    m_pluginController = pluginController;
+    m_pluginController = makeWeakPtr(pluginController);
 
     return initialize(parameters);
 }
@@ -120,4 +117,14 @@
     return IntPoint();
 }
 
+PluginController* Plugin::controller()
+{
+    return m_pluginController.get();
+}
+
+const PluginController* Plugin::controller() const
+{
+    return m_pluginController.get();
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Plugins/Plugin.h (268988 => 268989)


--- trunk/Source/WebKit/WebProcess/Plugins/Plugin.h	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/Plugins/Plugin.h	2020-10-26 18:40:57 UTC (rev 268989)
@@ -33,6 +33,7 @@
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/URL.h>
 #include <wtf/Vector.h>
+#include <wtf/WeakPtr.h>
 
 #if PLATFORM(COCOA)
 typedef struct objc_object* id;
@@ -96,19 +97,14 @@
         static WARN_UNUSED_RETURN bool decode(IPC::Decoder&, Parameters&);
     };
 
-    // Sets the active plug-in controller and initializes the plug-in.
-    bool initialize(PluginController*, const Parameters&);
+    bool initialize(PluginController&, const Parameters&);
 
-    virtual bool isBeingAsynchronouslyInitialized() const = 0;
-
-    // Destroys the plug-in.
     void destroyPlugin();
 
     bool isBeingDestroyed() const { return m_isBeingDestroyed; }
 
-    // Returns the plug-in controller for this plug-in.
-    PluginController* controller() { return m_pluginController; }
-    const PluginController* controller() const { return m_pluginController; }
+    PluginController* controller();
+    const PluginController* controller() const;
 
     virtual ~Plugin();
 
@@ -317,7 +313,7 @@
     bool m_isBeingDestroyed { false };
 
 private:
-    PluginController* m_pluginController;
+    WeakPtr<PluginController> m_pluginController;
 };
     
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Plugins/PluginController.h (268988 => 268989)


--- trunk/Source/WebKit/WebProcess/Plugins/PluginController.h	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/Plugins/PluginController.h	2020-10-26 18:40:57 UTC (rev 268989)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <wtf/Forward.h>
+#include <wtf/WeakPtr.h>
 
 #if PLATFORM(COCOA)
 #include "PluginComplexTextInputState.h"
@@ -47,7 +48,7 @@
 
 namespace WebKit {
 
-class PluginController {
+class PluginController : public CanMakeWeakPtr<PluginController> {
 public:
     // Tells the controller that the plug-in wants the given rect to be repainted. The rect is in the plug-in's coordinate system.
     virtual void invalidate(const WebCore::IntRect&) = 0;

Modified: trunk/Source/WebKit/WebProcess/Plugins/PluginProxy.h (268988 => 268989)


--- trunk/Source/WebKit/WebProcess/Plugins/PluginProxy.h	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/Plugins/PluginProxy.h	2020-10-26 18:40:57 UTC (rev 268989)
@@ -64,8 +64,6 @@
     void didReceivePluginProxyMessage(IPC::Connection&, IPC::Decoder&);
     void didReceiveSyncPluginProxyMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
 
-    bool isBeingAsynchronouslyInitialized() const override { return m_waitingOnAsynchronousInitialization; }
-
 private:
     explicit PluginProxy(uint64_t pluginProcessToken, bool isRestartedProcess);
 

Modified: trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp (268988 => 268989)


--- trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp	2020-10-26 18:40:57 UTC (rev 268989)
@@ -334,7 +334,7 @@
 {
     // Cancel all pending frame loads.
     for (FrameLoadMap::iterator it = m_pendingFrameLoads.begin(), end = m_pendingFrameLoads.end(); it != end; ++it)
-        it->key->setLoadListener(0);
+        it->key->setLoadListener(nullptr);
 
     if (m_plugin) {
         m_plugin->destroyPlugin();
@@ -601,7 +601,7 @@
     HTMLPlugInImageElement& plugInImageElement = downcast<HTMLPlugInImageElement>(*m_pluginElement);
     m_didPlugInStartOffScreen = !m_webPage->plugInIntersectsSearchRect(plugInImageElement);
 #endif
-    m_plugin->initialize(this, m_parameters);
+    m_plugin->initialize(*this, m_parameters);
     
     // Plug-in initialization continued in didFailToInitializePlugin() or didInitializePlugin().
 }
@@ -1666,7 +1666,7 @@
 {
     RefPtr<URLRequest> request = m_pendingFrameLoads.take(webFrame);
     ASSERT(request);
-    webFrame->setLoadListener(0);
+    webFrame->setLoadListener(nullptr);
 
     m_plugin->frameDidFinishLoading(request->requestID());
 }
@@ -1675,7 +1675,7 @@
 {
     RefPtr<URLRequest> request = m_pendingFrameLoads.take(webFrame);
     ASSERT(request);
-    webFrame->setLoadListener(0);
+    webFrame->setLoadListener(nullptr);
     
     m_plugin->frameDidFail(request->requestID(), wasCancelled);
 }

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebFrame.h (268988 => 268989)


--- trunk/Source/WebKit/WebProcess/WebPage/WebFrame.h	2020-10-26 18:24:10 UTC (rev 268988)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebFrame.h	2020-10-26 18:40:57 UTC (rev 268989)
@@ -40,6 +40,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/WeakPtr.h>
 
 namespace API {
 class Array;
@@ -149,7 +150,7 @@
     void documentLoaderDetached(uint64_t navigationID);
 
     // Simple listener class used by plug-ins to know when frames finish or fail loading.
-    class LoadListener {
+    class LoadListener : public CanMakeWeakPtr<LoadListener> {
     public:
         virtual ~LoadListener() { }
 
@@ -156,8 +157,8 @@
         virtual void didFinishLoad(WebFrame*) = 0;
         virtual void didFailLoad(WebFrame*, bool wasCancelled) = 0;
     };
-    void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; }
-    LoadListener* loadListener() const { return m_loadListener; }
+    void setLoadListener(LoadListener* loadListener) { m_loadListener = makeWeakPtr(loadListener); }
+    LoadListener* loadListener() const { return m_loadListener.get(); }
     
 #if PLATFORM(COCOA)
     typedef bool (*FrameFilterFunction)(WKBundleFrameRef, WKBundleFrameRef subframe, void* context);
@@ -192,7 +193,7 @@
     HashMap<uint64_t, CompletionHandler<void()>> m_willSubmitFormCompletionHandlers;
     Optional<DownloadID> m_policyDownloadID;
 
-    LoadListener* m_loadListener { nullptr };
+    WeakPtr<LoadListener> m_loadListener;
     
     WebCore::FrameIdentifier m_frameID;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to