Title: [272122] trunk/Source
Revision
272122
Author
[email protected]
Date
2021-01-30 15:35:46 -0800 (Sat, 30 Jan 2021)

Log Message

Check activeDocumentLoader() for null consistently everywhere
https://bugs.webkit.org/show_bug.cgi?id=221167

Reviewed by Anders Carlsson.

Source/WebCore:

Audited all activeDocumentLoader() calls to see if they check
for null. Many were missing a null check and only a very few had
a good solid reason they don't need one (newly-created frames, basically).

* dom/Document.cpp:
(WebCore::createCachedResourceLoader): Added.
(WebCore::Document::Document): Use createCachedResourceLoader, which
adds a null check for the active document loader.

* html/PluginDocument.cpp:
(WebCore::PluginDocumentParser::appendBytes): Added a null check before
calling setMainResourceDataBufferingPolicy. Also tweaked style a bit.
(WebCore::PluginDocument::cancelManualPluginLoad): Added a null check
before calling cancelMainResourceLoad.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::initialRequest const): Deleted.
(WebCore::FrameLoader::originalRequest const): Deleted.
* loader/FrameLoader.h: Deleted the initialRequest and originalRequest
functions. Both were using activeDocumentLoader() without null checks,
but both also were unused.

* loader/PolicyChecker.cpp:
(WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
Added null check before calling continueAfterSubstituteDataRequest.

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::start): Added null check before calling
scheduleArchiveLoad and null check before callling
applicationCacheHost().maybeLoadResource().
(WebCore::ResourceLoader::willSwitchToSubstituteResource): Added
null check inside an assertion.
(WebCore::ResourceLoader::willSendRequestInternal): Added null check
before calling previewConverter and isCommitted.

* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::selectCache): Added null check before
calling request.

* page/DOMWindow.cpp:
(WebCore::DOMWindow::print): Added null check before calling isLoading.
(WebCore::DOMWindow::finishedLoading): Added null check before calling
mainDocumentError.

Source/WebKit:

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::cancelManualStreamLoad): Added null check before calling
isLoadingMainResource.

Source/WebKitLegacy/mac:

* Plugins/WebNetscapePluginStream.mm:
(WebNetscapePluginStream::cancelLoadWithError): Added null check before calling
isLoadingMainResource.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (272121 => 272122)


--- trunk/Source/WebCore/ChangeLog	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/ChangeLog	2021-01-30 23:35:46 UTC (rev 272122)
@@ -1,3 +1,54 @@
+2021-01-29  Darin Adler  <[email protected]>
+
+        Check activeDocumentLoader() for null consistently everywhere
+        https://bugs.webkit.org/show_bug.cgi?id=221167
+
+        Reviewed by Anders Carlsson.
+
+        Audited all activeDocumentLoader() calls to see if they check
+        for null. Many were missing a null check and only a very few had
+        a good solid reason they don't need one (newly-created frames, basically).
+
+        * dom/Document.cpp:
+        (WebCore::createCachedResourceLoader): Added.
+        (WebCore::Document::Document): Use createCachedResourceLoader, which
+        adds a null check for the active document loader.
+
+        * html/PluginDocument.cpp:
+        (WebCore::PluginDocumentParser::appendBytes): Added a null check before
+        calling setMainResourceDataBufferingPolicy. Also tweaked style a bit.
+        (WebCore::PluginDocument::cancelManualPluginLoad): Added a null check
+        before calling cancelMainResourceLoad.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::initialRequest const): Deleted.
+        (WebCore::FrameLoader::originalRequest const): Deleted.
+        * loader/FrameLoader.h: Deleted the initialRequest and originalRequest
+        functions. Both were using activeDocumentLoader() without null checks,
+        but both also were unused.
+
+        * loader/PolicyChecker.cpp:
+        (WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
+        Added null check before calling continueAfterSubstituteDataRequest.
+
+        * loader/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::start): Added null check before calling
+        scheduleArchiveLoad and null check before callling
+        applicationCacheHost().maybeLoadResource().
+        (WebCore::ResourceLoader::willSwitchToSubstituteResource): Added
+        null check inside an assertion.
+        (WebCore::ResourceLoader::willSendRequestInternal): Added null check
+        before calling previewConverter and isCommitted.
+
+        * loader/appcache/ApplicationCacheGroup.cpp:
+        (WebCore::ApplicationCacheGroup::selectCache): Added null check before
+        calling request.
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::print): Added null check before calling isLoading.
+        (WebCore::DOMWindow::finishedLoading): Added null check before calling
+        mainDocumentError.
+
 2021-01-30  Sam Weinig  <[email protected]>
 
         Additional cleanup of CSSPropertyParserHelpers

Modified: trunk/Source/WebCore/dom/Document.cpp (272121 => 272122)


--- trunk/Source/WebCore/dom/Document.cpp	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-01-30 23:35:46 UTC (rev 272122)
@@ -589,6 +589,15 @@
     return 0;
 }
 
+static Ref<CachedResourceLoader> createCachedResourceLoader(Frame* frame)
+{
+    if (frame) {
+        if (auto loader = frame->loader().activeDocumentLoader())
+            return loader->cachedResourceLoader();
+    }
+    return CachedResourceLoader::create(nullptr);
+}
+
 Document::Document(Frame* frame, const Settings& settings, const URL& url, DocumentClassFlags documentClasses, unsigned constructionFlags)
     : ContainerNode(*this, CreateDocument)
     , TreeScope(*this)
@@ -595,7 +604,7 @@
     , FrameDestructionObserver(frame)
     , m_settings(settings)
     , m_quirks(makeUniqueRef<Quirks>(*this))
-    , m_cachedResourceLoader(m_frame ? Ref<CachedResourceLoader>(m_frame->loader().activeDocumentLoader()->cachedResourceLoader()) : CachedResourceLoader::create(nullptr))
+    , m_cachedResourceLoader(createCachedResourceLoader(frame))
     , m_domTreeVersion(++s_globalTreeVersion)
     , m_styleScope(makeUnique<Style::Scope>(*this))
     , m_extensionStyleSheets(makeUnique<ExtensionStyleSheets>(*this))

Modified: trunk/Source/WebCore/html/PluginDocument.cpp (272121 => 272122)


--- trunk/Source/WebCore/html/PluginDocument.cpp	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/html/PluginDocument.cpp	2021-01-30 23:35:46 UTC (rev 272122)
@@ -130,13 +130,15 @@
     // can synchronously redirect data to the plugin.
     frame->view()->flushAnyPendingPostLayoutTasks();
 
-    if (RenderWidget* renderer = m_embedElement->renderWidget()) {
-        if (RefPtr<Widget> widget = renderer->widget()) {
+    if (auto renderer = m_embedElement->renderWidget()) {
+        if (auto widget = makeRefPtr(renderer->widget())) {
             frame->loader().client().redirectDataToPlugin(*widget);
+
             // In a plugin document, the main resource is the plugin. If we have a null widget, that means
             // the loading of the plugin was cancelled, which gives us a null mainResourceLoader(), so we
             // need to have this call in a null check of the widget or of mainResourceLoader().
-            frame->loader().activeDocumentLoader()->setMainResourceDataBufferingPolicy(DataBufferingPolicy::DoNotBufferData);
+            if (auto loader = frame->loader().activeDocumentLoader())
+                loader->setMainResourceDataBufferingPolicy(DataBufferingPolicy::DoNotBufferData);
         }
     }
 }
@@ -182,8 +184,8 @@
         return;
 
     auto& frameLoader = frame()->loader();
-    auto& documentLoader = *frameLoader.activeDocumentLoader();
-    documentLoader.cancelMainResourceLoad(frameLoader.cancelledError(documentLoader.request()));
+    if (auto documentLoader = frameLoader.activeDocumentLoader())
+        documentLoader->cancelMainResourceLoad(frameLoader.cancelledError(documentLoader->request()));
     m_shouldLoadPluginManually = false;
 }
 

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (272121 => 272122)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2021-01-30 23:35:46 UTC (rev 272122)
@@ -1639,11 +1639,6 @@
     frame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Not allowed to load local resource: " + url);
 }
 
-const ResourceRequest& FrameLoader::initialRequest() const
-{
-    return activeDocumentLoader()->originalRequest();
-}
-
 bool FrameLoader::willLoadMediaElementURL(URL& url, Node& initiatorNode)
 {
 #if PLATFORM(IOS_FAMILY)
@@ -3118,11 +3113,6 @@
     return identifier;
 }
 
-const ResourceRequest& FrameLoader::originalRequest() const
-{
-    return activeDocumentLoader()->originalRequestCopy();
-}
-
 void FrameLoader::receivedMainResourceError(const ResourceError& error)
 {
     // Retain because the stop may release the last reference to it.

Modified: trunk/Source/WebCore/loader/FrameLoader.h (272121 => 272122)


--- trunk/Source/WebCore/loader/FrameLoader.h	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/loader/FrameLoader.h	2021-01-30 23:35:46 UTC (rev 272122)
@@ -174,8 +174,6 @@
 #if PLATFORM(IOS_FAMILY)
     RetainPtr<CFDictionaryRef> connectionProperties(ResourceLoader*);
 #endif
-    const ResourceRequest& originalRequest() const;
-    const ResourceRequest& initialRequest() const;
     void receivedMainResourceError(const ResourceError&);
 
     bool willLoadMediaElementURL(URL&, Node&);

Modified: trunk/Source/WebCore/loader/PolicyChecker.cpp (272121 => 272122)


--- trunk/Source/WebCore/loader/PolicyChecker.cpp	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/loader/PolicyChecker.cpp	2021-01-30 23:35:46 UTC (rev 272122)
@@ -150,7 +150,8 @@
     if (substituteData.isValid() && !substituteData.failingURL().isEmpty()) {
         bool shouldContinue = true;
 #if ENABLE(CONTENT_FILTERING)
-        shouldContinue = ContentFilter::continueAfterSubstituteDataRequest(*m_frame.loader().activeDocumentLoader(), substituteData);
+        if (auto loader = m_frame.loader().activeDocumentLoader())
+            shouldContinue = ContentFilter::continueAfterSubstituteDataRequest(*loader, substituteData);
 #endif
         if (isBackForwardLoadType(m_loadType))
             m_loadType = FrameLoadType::Reload;

Modified: trunk/Source/WebCore/loader/ResourceLoader.cpp (272121 => 272122)


--- trunk/Source/WebCore/loader/ResourceLoader.cpp	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/loader/ResourceLoader.cpp	2021-01-30 23:35:46 UTC (rev 272122)
@@ -199,11 +199,11 @@
     ASSERT(frameLoader());
 
 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
-    if (m_documentLoader->scheduleArchiveLoad(*this, m_request))
+    if (m_documentLoader && m_documentLoader->scheduleArchiveLoad(*this, m_request))
         return;
 #endif
 
-    if (m_documentLoader->applicationCacheHost().maybeLoadResource(*this, m_request, m_request.url()))
+    if (m_documentLoader && m_documentLoader->applicationCacheHost().maybeLoadResource(*this, m_request, m_request.url()))
         return;
 
     if (m_defersLoading) {
@@ -297,7 +297,7 @@
 
 void ResourceLoader::willSwitchToSubstituteResource()
 {
-    ASSERT(!m_documentLoader->isSubstituteLoadPending(this));
+    ASSERT(m_documentLoader && !m_documentLoader->isSubstituteLoadPending(this));
     platformStrategies()->loaderStrategy()->remove(this);
     if (m_handle)
         m_handle->cancel();
@@ -394,8 +394,10 @@
         InspectorInstrumentation::willSendRequest(m_frame.get(), m_identifier, m_frame->loader().documentLoader(), request, redirectResponse);
 
 #if USE(QUICK_LOOK)
-    if (auto previewConverter = m_documentLoader->previewConverter())
-        request = previewConverter->safeRequest(request);
+    if (m_documentLoader) {
+        if (auto previewConverter = m_documentLoader->previewConverter())
+            request = previewConverter->safeRequest(request);
+    }
 #endif
 
     bool isRedirect = !redirectResponse.isNull();
@@ -409,7 +411,7 @@
 
     if (isRedirect) {
         auto& redirectURL = request.url();
-        if (!m_documentLoader->isCommitted())
+        if (m_documentLoader && !m_documentLoader->isCommitted())
             frameLoader()->client().dispatchDidReceiveServerRedirectForProvisionalLoad();
 
         if (redirectURL.protocolIsData()) {

Modified: trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp (272121 => 272122)


--- trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp	2021-01-30 23:35:46 UTC (rev 272122)
@@ -180,8 +180,10 @@
     }
 
     // The resource was loaded from the network, check if it is a HTTP/HTTPS GET.    
-    auto& request = frame.loader().activeDocumentLoader()->request();
-
+    auto loader = frame.loader().activeDocumentLoader();
+    if (!loader)
+        return;
+    auto& request = loader->request();
     if (!ApplicationCache::requestIsHTTPOrHTTPSGet(request))
         return;
 

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (272121 => 272122)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2021-01-30 23:35:46 UTC (rev 272122)
@@ -1073,7 +1073,7 @@
     if (page->isControlledByAutomation())
         return;
 
-    if (frame->loader().activeDocumentLoader()->isLoading()) {
+    if (auto loader = frame->loader().activeDocumentLoader(); loader && loader->isLoading()) {
         m_shouldPrintWhenFinishedLoading = true;
         return;
     }
@@ -2326,7 +2326,7 @@
 {
     if (m_shouldPrintWhenFinishedLoading) {
         m_shouldPrintWhenFinishedLoading = false;
-        if (frame()->loader().activeDocumentLoader()->mainDocumentError().isNull())
+        if (auto loader = frame()->loader().activeDocumentLoader(); !loader || loader->mainDocumentError().isNull())
             print();
     }
 }

Modified: trunk/Source/WebKit/ChangeLog (272121 => 272122)


--- trunk/Source/WebKit/ChangeLog	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebKit/ChangeLog	2021-01-30 23:35:46 UTC (rev 272122)
@@ -1,3 +1,14 @@
+2021-01-29  Darin Adler  <[email protected]>
+
+        Check activeDocumentLoader() for null consistently everywhere
+        https://bugs.webkit.org/show_bug.cgi?id=221167
+
+        Reviewed by Anders Carlsson.
+
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::cancelManualStreamLoad): Added null check before calling
+        isLoadingMainResource.
+
 2021-01-30  Wenson Hsieh  <[email protected]>
 
         [macOS] Remove support for image controls

Modified: trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp (272121 => 272122)


--- trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp	2021-01-30 23:35:46 UTC (rev 272122)
@@ -1399,8 +1399,7 @@
 
     DocumentLoader* documentLoader = frame()->loader().activeDocumentLoader();
     ASSERT(documentLoader);
-    
-    if (documentLoader->isLoadingMainResource())
+    if (documentLoader && documentLoader->isLoadingMainResource())
         documentLoader->cancelMainResourceLoad(frame()->loader().cancelledError(m_parameters.url));
 }
 

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (272121 => 272122)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-01-30 23:35:46 UTC (rev 272122)
@@ -1,3 +1,14 @@
+2021-01-29  Darin Adler  <[email protected]>
+
+        Check activeDocumentLoader() for null consistently everywhere
+        https://bugs.webkit.org/show_bug.cgi?id=221167
+
+        Reviewed by Anders Carlsson.
+
+        * Plugins/WebNetscapePluginStream.mm:
+        (WebNetscapePluginStream::cancelLoadWithError): Added null check before calling
+        isLoadingMainResource.
+
 2021-01-30  Wenson Hsieh  <[email protected]>
 
         [macOS] Remove support for image controls

Modified: trunk/Source/WebKitLegacy/mac/Plugins/WebNetscapePluginStream.mm (272121 => 272122)


--- trunk/Source/WebKitLegacy/mac/Plugins/WebNetscapePluginStream.mm	2021-01-30 22:33:00 UTC (rev 272121)
+++ trunk/Source/WebKitLegacy/mac/Plugins/WebNetscapePluginStream.mm	2021-01-30 23:35:46 UTC (rev 272122)
@@ -479,15 +479,11 @@
 {
     if (m_frameLoader) {
         ASSERT(!m_loader);
-        
-        DocumentLoader* documentLoader = m_frameLoader->activeDocumentLoader();
-        ASSERT(documentLoader);
-        
-        if (documentLoader->isLoadingMainResource())
+        auto documentLoader = m_frameLoader->activeDocumentLoader();
+        if (documentLoader && documentLoader->isLoadingMainResource())
             documentLoader->cancelMainResourceLoad(error);
         return;
     }
-    
     if (!m_loader->isDone())
         m_loader->cancel(error);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to