Use a Ref<CachedResourceLoader> in Document instead of a RefPtr
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Jan 2015 05:53:53 +0000 (05:53 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Jan 2015 05:53:53 +0000 (05:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140971

Reviewed by Andreas Kling.

Source/WebCore:

Use a Ref<CachedResourceLoader> in Document instead of a RefPtr as it
can never be null. Also have Document::cachedResourceLoader() return a
reference instead of a pointer. This gets rid of a lot of unnecessary
null-checks.

Source/WebKit/win:

Use more references instead of pointers.

* WebDataSource.cpp:
(WebDataSource::subresourceForURL):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179242 268f45cc-cd09-0410-ab3c-d52691b4dbfc

61 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSCanvasValue.h
Source/WebCore/css/CSSCrossfadeValue.cpp
Source/WebCore/css/CSSCrossfadeValue.h
Source/WebCore/css/CSSCursorImageValue.cpp
Source/WebCore/css/CSSCursorImageValue.h
Source/WebCore/css/CSSFilterImageValue.cpp
Source/WebCore/css/CSSFilterImageValue.h
Source/WebCore/css/CSSFontFaceSrcValue.cpp
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSGradientValue.h
Source/WebCore/css/CSSImageGeneratorValue.cpp
Source/WebCore/css/CSSImageGeneratorValue.h
Source/WebCore/css/CSSImageSetValue.cpp
Source/WebCore/css/CSSImageSetValue.h
Source/WebCore/css/CSSImageValue.cpp
Source/WebCore/css/CSSImageValue.h
Source/WebCore/css/StyleBuilderConverter.h
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/StyleRuleImport.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/ProcessingInstruction.cpp
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/parser/HTMLResourcePreloader.cpp
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/ImageLoader.cpp
Source/WebCore/loader/LinkLoader.cpp
Source/WebCore/loader/MediaResourceLoader.cpp
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/SubresourceLoader.h
Source/WebCore/loader/TextTrackLoader.cpp
Source/WebCore/loader/cache/CachedFont.cpp
Source/WebCore/loader/cache/CachedFont.h
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedImage.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebCore/loader/cache/CachedSVGDocumentReference.cpp
Source/WebCore/loader/cache/CachedSVGDocumentReference.h
Source/WebCore/loader/icon/IconLoader.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/Settings.cpp
Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp
Source/WebCore/svg/SVGFEImageElement.cpp
Source/WebCore/svg/SVGFontFaceUriElement.cpp
Source/WebCore/svg/SVGUseElement.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/xml/XSLStyleSheetLibxslt.cpp
Source/WebCore/xml/XSLTProcessorLibxslt.cpp
Source/WebCore/xml/parser/XMLDocumentParser.h
Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebDataSource.cpp

index a1beca5..4800d78 100644 (file)
@@ -1,3 +1,15 @@
+2015-01-27  Chris Dumez  <cdumez@apple.com>
+
+        Use a Ref<CachedResourceLoader> in Document instead of a RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=140971
+
+        Reviewed by Andreas Kling.
+
+        Use a Ref<CachedResourceLoader> in Document instead of a RefPtr as it
+        can never be null. Also have Document::cachedResourceLoader() return a
+        reference instead of a pointer. This gets rid of a lot of unnecessary
+        null-checks.
+
 2015-01-27  Alexey Proskuryakov  <ap@apple.com>
 
         More build fixes for newer clang.
index 533780d..16956e1 100644 (file)
@@ -45,7 +45,7 @@ public:
     FloatSize fixedSize(const RenderElement*);
 
     bool isPending() const { return false; }
-    void loadSubimages(CachedResourceLoader*) { }
+    void loadSubimages(CachedResourceLoader&) { }
 
     bool equals(const CSSCanvasValue&) const;
 
index 19023cb..ea4db6f 100644 (file)
@@ -84,7 +84,7 @@ FloatSize CSSCrossfadeValue::fixedSize(const RenderElement* renderer)
     float percentage = m_percentageValue->getFloatValue();
     float inversePercentage = 1 - percentage;
 
-    CachedResourceLoader* cachedResourceLoader = renderer->document().cachedResourceLoader();
+    CachedResourceLoader& cachedResourceLoader = renderer->document().cachedResourceLoader();
     CachedImage* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), cachedResourceLoader);
     CachedImage* cachedToImage = cachedImageForCSSValue(m_toValue.get(), cachedResourceLoader);
 
@@ -114,7 +114,7 @@ bool CSSCrossfadeValue::knownToBeOpaque(const RenderElement* renderer) const
     return subimageKnownToBeOpaque(*m_fromValue, renderer) && subimageKnownToBeOpaque(*m_toValue, renderer);
 }
 
-void CSSCrossfadeValue::loadSubimages(CachedResourceLoader* cachedResourceLoader)
+void CSSCrossfadeValue::loadSubimages(CachedResourceLoader& cachedResourceLoader)
 {
     CachedResourceHandle<CachedImage> oldCachedFromImage = m_cachedFromImage;
     CachedResourceHandle<CachedImage> oldCachedToImage = m_cachedToImage;
@@ -142,9 +142,9 @@ void CSSCrossfadeValue::loadSubimages(CachedResourceLoader* cachedResourceLoader
 PassRefPtr<Image> CSSCrossfadeValue::image(RenderElement* renderer, const FloatSize& size)
 {
     if (size.isEmpty())
-        return 0;
+        return nullptr;
 
-    CachedResourceLoader* cachedResourceLoader = renderer->document().cachedResourceLoader();
+    CachedResourceLoader& cachedResourceLoader = renderer->document().cachedResourceLoader();
     CachedImage* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), cachedResourceLoader);
     CachedImage* cachedToImage = cachedImageForCSSValue(m_toValue.get(), cachedResourceLoader);
 
index a2fbc60..52f2226 100644 (file)
@@ -59,7 +59,7 @@ public:
     bool isPending() const;
     bool knownToBeOpaque(const RenderElement*) const;
 
-    void loadSubimages(CachedResourceLoader*);
+    void loadSubimages(CachedResourceLoader&);
 
     void setPercentage(PassRefPtr<CSSPrimitiveValue> percentageValue) { m_percentageValue = percentageValue; }
 
index 241f596..410ae4f 100644 (file)
@@ -130,7 +130,7 @@ bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element)
     return false;
 }
 
-StyleImage* CSSCursorImageValue::cachedImage(CachedResourceLoader* loader)
+StyleImage* CSSCursorImageValue::cachedImage(CachedResourceLoader& loader)
 {
 #if ENABLE(CSS_IMAGE_SET)
     if (is<CSSImageSetValue>(m_imageValue.get()))
@@ -143,9 +143,9 @@ StyleImage* CSSCursorImageValue::cachedImage(CachedResourceLoader* loader)
         // For SVG images we need to lazily substitute in the correct URL. Rather than attempt
         // to change the URL of the CSSImageValue (which would then change behavior like cssText),
         // we create an alternate CSSImageValue to use.
-        if (isSVGCursor() && loader && loader->document()) {
+        if (isSVGCursor() && loader.document()) {
             // FIXME: This will fail if the <cursor> element is in a shadow DOM (bug 59827)
-            if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(downcast<CSSImageValue>(m_imageValue.get()).url(), *loader->document())) {
+            if (SVGCursorElement* cursorElement = resourceReferencedByCursorElement(downcast<CSSImageValue>(m_imageValue.get()).url(), *loader.document())) {
                 detachPendingImage();
                 Ref<CSSImageValue> svgImageValue(CSSImageValue::create(cursorElement->href()));
                 StyleCachedImage* cachedImage = svgImageValue->cachedImage(loader);
index 61a29a8..20382cb 100644 (file)
@@ -52,7 +52,7 @@ public:
     String customCSSText() const;
 
     bool updateIfSVGCursorIsUsed(Element*);
-    StyleImage* cachedImage(CachedResourceLoader*);
+    StyleImage* cachedImage(CachedResourceLoader&);
     StyleImage* cachedOrPendingImage(Document&);
 
     void removeReferencedElement(SVGElement*);
index a690abd..4cd4181 100644 (file)
@@ -60,7 +60,7 @@ String CSSFilterImageValue::customCSSText() const
 
 FloatSize CSSFilterImageValue::fixedSize(const RenderElement* renderer)
 {
-    CachedResourceLoader* cachedResourceLoader = renderer->document().cachedResourceLoader();
+    CachedResourceLoader& cachedResourceLoader = renderer->document().cachedResourceLoader();
     CachedImage* cachedImage = cachedImageForCSSValue(m_imageValue.get(), cachedResourceLoader);
 
     if (!cachedImage)
@@ -79,7 +79,7 @@ bool CSSFilterImageValue::knownToBeOpaque(const RenderElement*) const
     return false;
 }
 
-void CSSFilterImageValue::loadSubimages(CachedResourceLoader* cachedResourceLoader)
+void CSSFilterImageValue::loadSubimages(CachedResourceLoader& cachedResourceLoader)
 {
     CachedResourceHandle<CachedImage> oldCachedImage = m_cachedImage;
 
@@ -98,9 +98,9 @@ void CSSFilterImageValue::loadSubimages(CachedResourceLoader* cachedResourceLoad
 PassRefPtr<Image> CSSFilterImageValue::image(RenderElement* renderer, const FloatSize& size)
 {
     if (size.isEmpty())
-        return 0;
+        return nullptr;
 
-    CachedResourceLoader* cachedResourceLoader = renderer->document().cachedResourceLoader();
+    CachedResourceLoader& cachedResourceLoader = renderer->document().cachedResourceLoader();
     CachedImage* cachedImage = cachedImageForCSSValue(m_imageValue.get(), cachedResourceLoader);
 
     if (!cachedImage)
index 7d19271..1245cd6 100644 (file)
@@ -62,7 +62,7 @@ public:
     bool isPending() const;
     bool knownToBeOpaque(const RenderElement*) const;
 
-    void loadSubimages(CachedResourceLoader*);
+    void loadSubimages(CachedResourceLoader&);
 
     bool hasFailedOrCanceledSubresources() const;
 
index 4366e57..7e296d6 100644 (file)
@@ -103,7 +103,7 @@ CachedFont* CSSFontFaceSrcValue::cachedFont(Document* document, bool isSVG)
     if (!m_cachedFont) {
         CachedResourceRequest request(ResourceRequest(document->completeURL(m_resource)));
         request.setInitiator(cachedResourceRequestInitiators().css);
-        m_cachedFont = document->cachedResourceLoader()->requestFont(request, isSVG);
+        m_cachedFont = document->cachedResourceLoader().requestFont(request, isSVG);
     }
     return m_cachedFont.get();
 }
index d956f65..82c0eb5 100644 (file)
@@ -540,15 +540,14 @@ void CSSFontSelector::clearDocument()
 
     m_beginLoadingTimer.stop();
 
-    CachedResourceLoader* cachedResourceLoader = m_document->cachedResourceLoader();
-    for (size_t i = 0; i < m_fontsToBeginLoading.size(); ++i) {
+    CachedResourceLoader& cachedResourceLoader = m_document->cachedResourceLoader();
+    for (auto& fontHandle : m_fontsToBeginLoading) {
         // Balances incrementRequestCount() in beginLoadingFontSoon().
-        cachedResourceLoader->decrementRequestCount(m_fontsToBeginLoading[i].get());
+        cachedResourceLoader.decrementRequestCount(fontHandle.get());
     }
-
     m_fontsToBeginLoading.clear();
 
-    m_document = 0;
+    m_document = nullptr;
 }
 
 void CSSFontSelector::beginLoadingFontSoon(CachedFont* font)
@@ -560,7 +559,7 @@ void CSSFontSelector::beginLoadingFontSoon(CachedFont* font)
     // Increment the request count now, in order to prevent didFinishLoad from being dispatched
     // after this font has been requested but before it began loading. Balanced by
     // decrementRequestCount() in beginLoadTimerFired() and in clearDocument().
-    m_document->cachedResourceLoader()->incrementRequestCount(font);
+    m_document->cachedResourceLoader().incrementRequestCount(font);
     m_beginLoadingTimer.startOneShot(0);
 }
 
@@ -572,14 +571,14 @@ void CSSFontSelector::beginLoadTimerFired()
     // CSSFontSelector could get deleted via beginLoadIfNeeded() or loadDone() unless protected.
     Ref<CSSFontSelector> protect(*this);
 
-    CachedResourceLoader* cachedResourceLoader = m_document->cachedResourceLoader();
-    for (size_t i = 0; i < fontsToBeginLoading.size(); ++i) {
-        fontsToBeginLoading[i]->beginLoadIfNeeded(cachedResourceLoader);
+    CachedResourceLoader& cachedResourceLoader = m_document->cachedResourceLoader();
+    for (auto& fontHandle : fontsToBeginLoading) {
+        fontHandle->beginLoadIfNeeded(cachedResourceLoader);
         // Balances incrementRequestCount() in beginLoadingFontSoon().
-        cachedResourceLoader->decrementRequestCount(fontsToBeginLoading[i].get());
+        cachedResourceLoader.decrementRequestCount(fontHandle.get());
     }
     // Ensure that if the request count reaches zero, the frame loader will know about it.
-    cachedResourceLoader->loadDone(0);
+    cachedResourceLoader.loadDone(nullptr);
     // New font loads may be triggered by layout after the document load is complete but before we have dispatched
     // didFinishLoading for the frame. Make sure the delegate is always dispatched by checking explicitly.
     if (m_document && m_document->frame())
index ad2b587..11e372e 100644 (file)
@@ -85,7 +85,7 @@ public:
     bool isPending() const { return false; }
     bool knownToBeOpaque(const RenderElement*) const;
 
-    void loadSubimages(CachedResourceLoader*) { }
+    void loadSubimages(CachedResourceLoader&) { }
     PassRefPtr<CSSGradientValue> gradientWithStylesResolved(StyleResolver*);
 
 protected:
index d2f042d..17d3eeb 100644 (file)
@@ -200,7 +200,7 @@ bool CSSImageGeneratorValue::knownToBeOpaque(const RenderElement* renderer) cons
     return false;
 }
 
-void CSSImageGeneratorValue::loadSubimages(CachedResourceLoader* cachedResourceLoader)
+void CSSImageGeneratorValue::loadSubimages(CachedResourceLoader& cachedResourceLoader)
 {
     switch (classType()) {
     case CrossfadeClass:
@@ -239,7 +239,7 @@ bool CSSImageGeneratorValue::subimageIsPending(CSSValue* value)
     return false;
 }
 
-CachedImage* CSSImageGeneratorValue::cachedImageForCSSValue(CSSValue* value, CachedResourceLoader* cachedResourceLoader)
+CachedImage* CSSImageGeneratorValue::cachedImageForCSSValue(CSSValue* value, CachedResourceLoader& cachedResourceLoader)
 {
     if (!value)
         return nullptr;
index 7d99d41..7ccaccb 100644 (file)
@@ -56,7 +56,7 @@ public:
     bool isPending() const;
     bool knownToBeOpaque(const RenderElement*) const;
 
-    void loadSubimages(CachedResourceLoader*);
+    void loadSubimages(CachedResourceLoader&);
 
 protected:
     CSSImageGeneratorValue(ClassType);
@@ -66,7 +66,7 @@ protected:
     const HashCountedSet<RenderElement*>& clients() const { return m_clients; }
 
     // Helper functions for Crossfade and Filter.
-    static CachedImage* cachedImageForCSSValue(CSSValue*, CachedResourceLoader*);
+    static CachedImage* cachedImageForCSSValue(CSSValue*, CachedResourceLoader&);
     static bool subimageIsPending(CSSValue*);
 
 private:
index 2012f5b..2b3c5d1 100644 (file)
@@ -100,11 +100,9 @@ CSSImageSetValue::ImageWithScale CSSImageSetValue::bestImageForScaleFactor()
     return image;
 }
 
-StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader* loader, const ResourceLoaderOptions& options)
+StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
 {
-    ASSERT(loader);
-
-    Document* document = loader->document();
+    Document* document = loader.document();
     if (Page* page = document->page())
         m_scaleFactor = page->deviceScaleFactor();
     else
@@ -122,7 +120,7 @@ StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader* load
         request.setInitiator(cachedResourceRequestInitiators().css);
         if (options.requestOriginPolicy() == PotentiallyCrossOriginEnabled)
             updateRequestForAccessControl(request.mutableResourceRequest(), document->securityOrigin(), options.allowCredentials());
-        if (CachedResourceHandle<CachedImage> cachedImage = loader->requestImage(request)) {
+        if (CachedResourceHandle<CachedImage> cachedImage = loader.requestImage(request)) {
             detachPendingImage();
             m_imageSet = StyleCachedImageSet::create(cachedImage.get(), image.scaleFactor, this);
             m_accessedBestFitImage = true;
@@ -132,7 +130,7 @@ StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader* load
     return is<StyleCachedImageSet>(m_imageSet.get()) ? downcast<StyleCachedImageSet>(m_imageSet.get()) : nullptr;
 }
 
-StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader* loader)
+StyleCachedImageSet* CSSImageSetValue::cachedImageSet(CachedResourceLoader& loader)
 {
     return cachedImageSet(loader, CachedResourceLoader::defaultCachedResourceOptions());
 }
index 1b0510a..acfd556 100644 (file)
@@ -47,8 +47,8 @@ public:
     }
     ~CSSImageSetValue();
 
-    StyleCachedImageSet* cachedImageSet(CachedResourceLoader*, const ResourceLoaderOptions&);
-    StyleCachedImageSet* cachedImageSet(CachedResourceLoader*);
+    StyleCachedImageSet* cachedImageSet(CachedResourceLoader&, const ResourceLoaderOptions&);
+    StyleCachedImageSet* cachedImageSet(CachedResourceLoader&);
 
     // Returns a StyleCachedImageSet if the best fit image has been cached already, otherwise a StylePendingImage.
     StyleImage* cachedOrPendingImageSet(Document&);
index 65cf3f3..b3d93b6 100644 (file)
@@ -71,23 +71,21 @@ StyleImage* CSSImageValue::cachedOrPendingImage()
     return m_image.get();
 }
 
-StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const ResourceLoaderOptions& options)
+StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
 {
-    ASSERT(loader);
-
     if (!m_accessedImage) {
         m_accessedImage = true;
 
-        CachedResourceRequest request(ResourceRequest(loader->document()->completeURL(m_url)), options);
+        CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url)), options);
         if (m_initiatorName.isEmpty())
             request.setInitiator(cachedResourceRequestInitiators().css);
         else
             request.setInitiator(m_initiatorName);
 
         if (options.requestOriginPolicy() == PotentiallyCrossOriginEnabled)
-            updateRequestForAccessControl(request.mutableResourceRequest(), loader->document()->securityOrigin(), options.allowCredentials());
+            updateRequestForAccessControl(request.mutableResourceRequest(), loader.document()->securityOrigin(), options.allowCredentials());
 
-        if (CachedResourceHandle<CachedImage> cachedImage = loader->requestImage(request)) {
+        if (CachedResourceHandle<CachedImage> cachedImage = loader.requestImage(request)) {
             detachPendingImage();
             m_image = StyleCachedImage::create(cachedImage.get());
         }
@@ -96,7 +94,7 @@ StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const
     return is<StyleCachedImage>(m_image.get()) ? downcast<StyleCachedImage>(m_image.get()) : nullptr;
 }
 
-StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader)
+StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader& loader)
 {
     return cachedImage(loader, CachedResourceLoader::defaultCachedResourceOptions());
 }
index 232532a..0cd86a0 100644 (file)
@@ -39,8 +39,8 @@ public:
     static Ref<CSSImageValue> create(const String& url, StyleImage* image) { return adoptRef(*new CSSImageValue(url, image)); }
     ~CSSImageValue();
 
-    StyleCachedImage* cachedImage(CachedResourceLoader*, const ResourceLoaderOptions&);
-    StyleCachedImage* cachedImage(CachedResourceLoader*);
+    StyleCachedImage* cachedImage(CachedResourceLoader&, const ResourceLoaderOptions&);
+    StyleCachedImage* cachedImage(CachedResourceLoader&);
     // Returns a StyleCachedImage if the image is cached already, otherwise a StylePendingImage.
     StyleImage* cachedOrPendingImage();
 
index d53bd75..fc34ff5 100644 (file)
@@ -1059,7 +1059,7 @@ inline Vector<RefPtr<MaskImageOperation>> StyleBuilderConverter::convertMaskImag
                 URL url = styleResolver.document().completeURL(cssUrl);
 
                 bool isExternalDocument = SVGURIReference::isExternalURIReference(cssUrl, styleResolver.document());
-                newMaskImage = MaskImageOperation::create(maskImageValue, cssUrl, url.fragmentIdentifier(), isExternalDocument, styleResolver.document().cachedResourceLoader());
+                newMaskImage = MaskImageOperation::create(maskImageValue, cssUrl, url.fragmentIdentifier(), isExternalDocument, &styleResolver.document().cachedResourceLoader());
                 if (isExternalDocument)
                     styleResolver.state().maskImagesWithPendingSVGDocuments().append(newMaskImage);
             }
index 343b4f4..6d9ecaa 100644 (file)
@@ -2229,7 +2229,7 @@ void StyleResolver::loadPendingSVGDocuments()
     if (!hasFilters && !hasMasks)
         return;
 
-    CachedResourceLoader* cachedResourceLoader = state.document().cachedResourceLoader();
+    CachedResourceLoader& cachedResourceLoader = state.document().cachedResourceLoader();
     
     if (hasFilters) {
         for (auto& filterOperation : state.filtersWithPendingSVGDocuments())
index d14024d..5d1c0d6 100644 (file)
@@ -96,10 +96,6 @@ void StyleRuleImport::requestStyleSheet()
     if (!document)
         return;
 
-    CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
-    if (!cachedResourceLoader)
-        return;
-
     URL absURL;
     if (!m_parentStyleSheet->baseURL().isNull())
         // use parent styleheet's URL as the base URL
@@ -122,9 +118,9 @@ void StyleRuleImport::requestStyleSheet()
     if (m_cachedSheet)
         m_cachedSheet->removeClient(&m_styleSheetClient);
     if (m_parentStyleSheet->isUserStyleSheet())
-        m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(request);
+        m_cachedSheet = document->cachedResourceLoader().requestUserCSSStyleSheet(request);
     else
-        m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(request);
+        m_cachedSheet = document->cachedResourceLoader().requestCSSStyleSheet(request);
     if (m_cachedSheet) {
         // if the import rule is issued dynamically, the sheet may be
         // removed from the pending sheet count, so let the doc know
index f65042f..f9af643 100644 (file)
@@ -415,6 +415,7 @@ Document::Document(Frame* frame, const URL& url, unsigned documentClasses, unsig
     , m_ignorePendingStylesheets(false)
     , m_pendingSheetLayout(NoLayoutWithPendingSheets)
     , m_frame(frame)
+    , m_cachedResourceLoader(m_frame ? Ref<CachedResourceLoader>(m_frame->loader().activeDocumentLoader()->cachedResourceLoader()) : CachedResourceLoader::create(nullptr))
     , m_activeParserCount(0)
     , m_wellFormed(false)
     , m_printing(false)
@@ -528,10 +529,6 @@ Document::Document(Frame* frame, const URL& url, unsigned documentClasses, unsig
     if ((frame && frame->ownerElement()) || !url.isEmpty())
         setURL(url);
 
-    if (m_frame)
-        m_cachedResourceLoader = &m_frame->loader().activeDocumentLoader()->cachedResourceLoader();
-    if (!m_cachedResourceLoader)
-        m_cachedResourceLoader = CachedResourceLoader::create(nullptr);
     m_cachedResourceLoader->setDocument(this);
 
 #if ENABLE(TEXT_AUTOSIZING)
@@ -625,7 +622,6 @@ Document::~Document()
     // load the initial empty document and the SVGDocument with the same DocumentLoader).
     if (m_cachedResourceLoader->document() == this)
         m_cachedResourceLoader->setDocument(nullptr);
-    m_cachedResourceLoader.clear();
 
     // We must call clearRareData() here since a Document class inherits TreeScope
     // as well as Node. See a comment on TreeScope.h for the reason.
@@ -3816,8 +3812,7 @@ void Document::dispatchWindowLoadEvent()
         return;
     m_domWindow->dispatchLoadEvent();
     m_loadEventFinished = true;
-    if (m_cachedResourceLoader)
-        m_cachedResourceLoader->documentDidFinishLoadEvent();
+    m_cachedResourceLoader->documentDidFinishLoadEvent();
 }
 
 void Document::enqueueWindowEvent(PassRefPtr<Event> event)
index f473494..8c58f2b 100644 (file)
@@ -623,7 +623,7 @@ public:
     // auto is specified.
     WEBCORE_EXPORT void pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft);
 
-    CachedResourceLoader* cachedResourceLoader() { return m_cachedResourceLoader.get(); }
+    CachedResourceLoader& cachedResourceLoader() { return m_cachedResourceLoader; }
 
     void didBecomeCurrentDocumentInFrame();
     void destroyRenderTree();
@@ -1395,7 +1395,7 @@ private:
     Frame* m_frame;
     RefPtr<DOMWindow> m_domWindow;
 
-    RefPtr<CachedResourceLoader> m_cachedResourceLoader;
+    Ref<CachedResourceLoader> m_cachedResourceLoader;
     RefPtr<DocumentParser> m_parser;
     unsigned m_activeParserCount;
 
index ec8fa19..a813c72 100644 (file)
@@ -147,7 +147,7 @@ void ProcessingInstruction::checkStyleSheet()
             CachedResourceRequest request(ResourceRequest(document().completeURL(href)));
 #if ENABLE(XSLT)
             if (m_isXSL)
-                m_cachedSheet = document().cachedResourceLoader()->requestXSLStyleSheet(request);
+                m_cachedSheet = document().cachedResourceLoader().requestXSLStyleSheet(request);
             else
 #endif
             {
@@ -156,7 +156,7 @@ void ProcessingInstruction::checkStyleSheet()
                     charset = document().charset();
                 request.setCharset(charset);
 
-                m_cachedSheet = document().cachedResourceLoader()->requestCSSStyleSheet(request);
+                m_cachedSheet = document().cachedResourceLoader().requestCSSStyleSheet(request);
             }
             if (m_cachedSheet)
                 m_cachedSheet->addClient(this);
index c731b87..3eaae2c 100644 (file)
@@ -261,7 +261,7 @@ bool ScriptElement::requestScript(const String& sourceUrl)
         request.setCharset(scriptCharset());
         request.setInitiator(&element());
 
-        m_cachedScript = m_element.document().cachedResourceLoader()->requestScript(request);
+        m_cachedScript = m_element.document().cachedResourceLoader().requestScript(request);
         m_isExternalScript = true;
     }
 
index fd7da02..15d9b49 100644 (file)
@@ -1281,8 +1281,7 @@ void Editor::paste(Pasteboard& pasteboard)
     if (!canPaste())
         return;
     updateMarkersForWordsAffectedByEditing(false);
-    CachedResourceLoader* loader = document().cachedResourceLoader();
-    ResourceCacheValidationSuppressor validationSuppressor(loader);
+    ResourceCacheValidationSuppressor validationSuppressor(document().cachedResourceLoader());
     if (m_frame.selection().selection().isContentRichlyEditable())
         pasteWithPasteboard(&pasteboard, true);
     else
index 4a576ac..0091a71 100644 (file)
@@ -232,7 +232,7 @@ void HTMLLinkElement::process()
         ResourceLoadPriority priority = isActive ? ResourceLoadPriorityUnresolved : ResourceLoadPriorityVeryLow;
         CachedResourceRequest request(ResourceRequest(document().completeURL(url)), charset, priority);
         request.setInitiator(this);
-        m_cachedSheet = document().cachedResourceLoader()->requestCSSStyleSheet(request);
+        m_cachedSheet = document().cachedResourceLoader().requestCSSStyleSheet(request);
         
         if (m_cachedSheet)
             m_cachedSheet->addClient(this);
index 6d1d16c..d79cf75 100644 (file)
@@ -5721,7 +5721,7 @@ bool HTMLMediaElement::mediaPlayerIsLooping() const
 
 CachedResourceLoader* HTMLMediaElement::mediaPlayerCachedResourceLoader()
 {
-    return document().cachedResourceLoader();
+    return &document().cachedResourceLoader();
 }
 
 PassRefPtr<PlatformMediaResourceLoader> HTMLMediaElement::mediaPlayerCreateResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient> client)
index 3c7b7ad..5e79d4c 100644 (file)
@@ -73,7 +73,7 @@ void HTMLResourcePreloader::preload(std::unique_ptr<PreloadRequest> preload)
         return;
 
     CachedResourceRequest request = preload->resourceRequest(m_document);
-    m_document.cachedResourceLoader()->preload(preload->resourceType(), request, preload->charset());
+    m_document.cachedResourceLoader().preload(preload->resourceType(), request, preload->charset());
 }
 
 
index fd733d6..f91f7ee 100644 (file)
@@ -255,7 +255,7 @@ String InspectorPageAgent::sourceMapURLForResource(CachedResource* cachedResourc
 
 CachedResource* InspectorPageAgent::cachedResource(Frame* frame, const URL& url)
 {
-    CachedResource* cachedResource = frame->document()->cachedResourceLoader()->cachedResource(url);
+    CachedResource* cachedResource = frame->document()->cachedResourceLoader().cachedResource(url);
     if (!cachedResource) {
         ResourceRequest request(url);
 #if ENABLE(CACHE_PARTITIONING)
@@ -447,7 +447,7 @@ static Vector<CachedResource*> cachedResourcesForFrame(Frame* frame)
 {
     Vector<CachedResource*> result;
 
-    for (auto& cachedResourceHandle : frame->document()->cachedResourceLoader()->allCachedResources().values()) {
+    for (auto& cachedResourceHandle : frame->document()->cachedResourceLoader().allCachedResources().values()) {
         auto* cachedResource = cachedResourceHandle.get();
         if (cachedResource->resourceRequest().hiddenFromInspector())
             continue;
index a737182..9529811 100644 (file)
@@ -366,7 +366,7 @@ void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur
         newRequest.setInitiator(m_options.initiator);
 #endif
         ASSERT(!m_resource);
-        m_resource = m_document.cachedResourceLoader()->requestRawResource(newRequest);
+        m_resource = m_document.cachedResourceLoader().requestRawResource(newRequest);
         if (m_resource) {
             if (m_resource->loader()) {
                 unsigned long identifier = m_resource->loader()->identifier();
index 723eac2..a95969f 100644 (file)
@@ -713,8 +713,8 @@ void FrameLoader::didBeginDocument(bool dispatch)
     m_frame.document()->initContentSecurityPolicy();
 
     const Settings& settings = m_frame.settings();
-    m_frame.document()->cachedResourceLoader()->setImagesEnabled(settings.areImagesEnabled());
-    m_frame.document()->cachedResourceLoader()->setAutoLoadImages(settings.loadsImagesAutomatically());
+    m_frame.document()->cachedResourceLoader().setImagesEnabled(settings.areImagesEnabled());
+    m_frame.document()->cachedResourceLoader().setAutoLoadImages(settings.loadsImagesAutomatically());
 
     if (m_documentLoader) {
         String dnsPrefetchControl = m_documentLoader->response().httpHeaderField(HTTPHeaderName::XDNSPrefetchControl);
@@ -811,7 +811,7 @@ void FrameLoader::checkCompleted()
         return;
 
     // Still waiting for images/scripts?
-    if (m_frame.document()->cachedResourceLoader()->requestCount())
+    if (m_frame.document()->cachedResourceLoader().requestCount())
         return;
 
     // Still waiting for elements that don't go through a FrameLoader?
@@ -2447,11 +2447,11 @@ void FrameLoader::checkLoadComplete()
 int FrameLoader::numPendingOrLoadingRequests(bool recurse) const
 {
     if (!recurse)
-        return m_frame.document()->cachedResourceLoader()->requestCount();
+        return m_frame.document()->cachedResourceLoader().requestCount();
 
     int count = 0;
     for (Frame* frame = &m_frame; frame; frame = frame->tree().traverseNext(&m_frame))
-        count += frame->document()->cachedResourceLoader()->requestCount();
+        count += frame->document()->cachedResourceLoader().requestCount();
     return count;
 }
 
index 8b556ad..d9c1bd3 100644 (file)
@@ -188,15 +188,15 @@ void ImageLoader::updateFromElement()
         }
 
         if (m_loadManually) {
-            bool autoLoadOtherImages = document.cachedResourceLoader()->autoLoadImages();
-            document.cachedResourceLoader()->setAutoLoadImages(false);
+            bool autoLoadOtherImages = document.cachedResourceLoader().autoLoadImages();
+            document.cachedResourceLoader().setAutoLoadImages(false);
             newImage = new CachedImage(request.resourceRequest(), m_element.document().page()->sessionID());
             newImage->setLoading(true);
-            newImage->setOwningCachedResourceLoader(document.cachedResourceLoader());
-            document.cachedResourceLoader()->m_documentResources.set(newImage->url(), newImage.get());
-            document.cachedResourceLoader()->setAutoLoadImages(autoLoadOtherImages);
+            newImage->setOwningCachedResourceLoader(&document.cachedResourceLoader());
+            document.cachedResourceLoader().m_documentResources.set(newImage->url(), newImage.get());
+            document.cachedResourceLoader().setAutoLoadImages(autoLoadOtherImages);
         } else
-            newImage = document.cachedResourceLoader()->requestImage(request);
+            newImage = document.cachedResourceLoader().requestImage(request);
 
         // If we do not have an image here, it means that a cross-site
         // violation occurred, or that the image was blocked via Content
index ab9ebea..2ffaf60 100644 (file)
@@ -117,9 +117,9 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const String& ty
         
         if (m_cachedLinkResource) {
             m_cachedLinkResource->removeClient(this);
-            m_cachedLinkResource = 0;
+            m_cachedLinkResource = nullptr;
         }
-        m_cachedLinkResource = document->cachedResourceLoader()->requestLinkResource(type, linkRequest);
+        m_cachedLinkResource = document->cachedResourceLoader().requestLinkResource(type, linkRequest);
         if (m_cachedLinkResource)
             m_cachedLinkResource->addClient(this);
     }
index 87de3c6..0018ebe 100644 (file)
@@ -66,8 +66,7 @@ bool MediaResourceLoader::start(const ResourceRequest& request, LoadOptions opti
 
     m_didPassAccessControlCheck = false;
 
-    CachedResourceLoader* loader = m_document.cachedResourceLoader();
-    m_resource = loader ? loader->requestRawResource(cacheRequest) : nullptr;
+    m_resource = m_document.cachedResourceLoader().requestRawResource(cacheRequest);
     if (!m_resource)
         return false;
 
index 7258d8a..aa5c2cd 100644 (file)
@@ -54,16 +54,16 @@ namespace WebCore {
 
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, subresourceLoaderCounter, ("SubresourceLoader"));
 
-SubresourceLoader::RequestCountTracker::RequestCountTracker(CachedResourceLoader* cachedResourceLoader, CachedResource* resource)
+SubresourceLoader::RequestCountTracker::RequestCountTracker(CachedResourceLoader& cachedResourceLoader, CachedResource* resource)
     : m_cachedResourceLoader(cachedResourceLoader)
     , m_resource(resource)
 {
-    m_cachedResourceLoader->incrementRequestCount(m_resource);
+    m_cachedResourceLoader.incrementRequestCount(m_resource);
 }
 
 SubresourceLoader::RequestCountTracker::~RequestCountTracker()
 {
-    m_cachedResourceLoader->decrementRequestCount(m_resource);
+    m_cachedResourceLoader.decrementRequestCount(m_resource);
 }
 
 SubresourceLoader::SubresourceLoader(Frame* frame, CachedResource* resource, const ResourceLoaderOptions& options)
index e270f24..df0432a 100644 (file)
@@ -107,10 +107,10 @@ private:
 
     class RequestCountTracker {
     public:
-        RequestCountTracker(CachedResourceLoader*, CachedResource*);
+        RequestCountTracker(CachedResourceLoader&, CachedResource*);
         ~RequestCountTracker();
     private:
-        CachedResourceLoader* m_cachedResourceLoader;
+        CachedResourceLoader& m_cachedResourceLoader;
         CachedResource* m_resource;
     };
 
index 994cedd..b85055d 100644 (file)
@@ -169,8 +169,7 @@ bool TextTrackLoader::load(const URL& url, const String& crossOriginMode)
         }
     }
 
-    CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
-    m_resource = cachedResourceLoader->requestTextTrack(cueRequest);
+    m_resource = document->cachedResourceLoader().requestTextTrack(cueRequest);
     if (!m_resource)
         return false;
 
index c48807f..8f3e888 100644 (file)
@@ -62,7 +62,7 @@ CachedFont::~CachedFont()
 {
 }
 
-void CachedFont::load(CachedResourceLoader*, const ResourceLoaderOptions& options)
+void CachedFont::load(CachedResourceLoader&, const ResourceLoaderOptions& options)
 {
     // Don't load the file yet.  Wait for an access before triggering the load.
     setLoading(true);
@@ -84,11 +84,11 @@ void CachedFont::finishLoading(SharedBuffer* data)
     checkNotify();
 }
 
-void CachedFont::beginLoadIfNeeded(CachedResourceLoader* dl)
+void CachedFont::beginLoadIfNeeded(CachedResourceLoader& loader)
 {
     if (!m_loadInitiated) {
         m_loadInitiated = true;
-        CachedResource::load(dl, m_options);
+        CachedResource::load(loader, m_options);
     }
 }
 
index a93a651..44702ff 100644 (file)
@@ -47,7 +47,7 @@ public:
     CachedFont(const ResourceRequest&, SessionID, Type = FontResource);
     virtual ~CachedFont();
 
-    void beginLoadIfNeeded(CachedResourceLoader* dl);
+    void beginLoadIfNeeded(CachedResourceLoader&);
     virtual bool stillNeedsLoad() const override { return !m_loadInitiated; }
 
     virtual bool ensureCustomFontData(bool externalSVG, const AtomicString& remoteURI);
@@ -63,7 +63,7 @@ private:
     virtual void checkNotify() override;
     virtual bool mayTryReplaceEncodedData() const override;
 
-    virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&) override;
+    virtual void load(CachedResourceLoader&, const ResourceLoaderOptions&) override;
 
     virtual void didAddClient(CachedResourceClient*) override;
     virtual void finishLoading(SharedBuffer*) override;
index 1840b7b..3d72118 100644 (file)
@@ -107,9 +107,9 @@ CachedImage::~CachedImage()
     clearImage();
 }
 
-void CachedImage::load(CachedResourceLoader* cachedResourceLoader, const ResourceLoaderOptions& options)
+void CachedImage::load(CachedResourceLoader& cachedResourceLoader, const ResourceLoaderOptions& options)
 {
-    if (!cachedResourceLoader || cachedResourceLoader->autoLoadImages())
+    if (cachedResourceLoader.autoLoadImages())
         CachedResource::load(cachedResourceLoader, options);
     else
         setLoading(false);
index a703427..e67988e 100644 (file)
@@ -85,7 +85,7 @@ public:
 
     bool isManuallyCached() const { return m_isManuallyCached; }
     virtual bool mustRevalidateDueToCacheHeaders(const CachedResourceLoader&, CachePolicy) const override;
-    virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&) override;
+    virtual void load(CachedResourceLoader&, const ResourceLoaderOptions&) override;
 
     bool isOriginClean(SecurityOrigin*);
 
index 99b1a71..2ebb700 100644 (file)
@@ -185,13 +185,13 @@ void CachedResource::failBeforeStarting()
     error(CachedResource::LoadError);
 }
 
-void CachedResource::addAdditionalRequestHeaders(CachedResourceLoader* cachedResourceLoader)
+void CachedResource::addAdditionalRequestHeaders(CachedResourceLoader& cachedResourceLoader)
 {
     // Note: We skip the Content-Security-Policy check here because we check
     // the Content-Security-Policy at the CachedResourceLoader layer so we can
     // handle different resource types differently.
 
-    FrameLoader& frameLoader = cachedResourceLoader->frame()->loader();
+    FrameLoader& frameLoader = cachedResourceLoader.frame()->loader();
     String outgoingReferrer;
     String outgoingOrigin;
     if (m_resourceRequest.httpReferrer().isNull()) {
@@ -202,7 +202,7 @@ void CachedResource::addAdditionalRequestHeaders(CachedResourceLoader* cachedRes
         outgoingOrigin = SecurityOrigin::createFromString(outgoingReferrer)->toString();
     }
 
-    outgoingReferrer = SecurityPolicy::generateReferrerHeader(cachedResourceLoader->document()->referrerPolicy(), m_resourceRequest.url(), outgoingReferrer);
+    outgoingReferrer = SecurityPolicy::generateReferrerHeader(cachedResourceLoader.document()->referrerPolicy(), m_resourceRequest.url(), outgoingReferrer);
     if (outgoingReferrer.isEmpty())
         m_resourceRequest.clearHTTPReferrer();
     else
@@ -212,14 +212,14 @@ void CachedResource::addAdditionalRequestHeaders(CachedResourceLoader* cachedRes
     frameLoader.addExtraFieldsToSubresourceRequest(m_resourceRequest);
 }
 
-void CachedResource::load(CachedResourceLoader* cachedResourceLoader, const ResourceLoaderOptions& options)
+void CachedResource::load(CachedResourceLoader& cachedResourceLoader, const ResourceLoaderOptions& options)
 {
-    if (!cachedResourceLoader->frame()) {
+    if (!cachedResourceLoader.frame()) {
         failBeforeStarting();
         return;
     }
 
-    FrameLoader& frameLoader = cachedResourceLoader->frame()->loader();
+    FrameLoader& frameLoader = cachedResourceLoader.frame()->loader();
     if (options.securityCheck() == DoSecurityCheck && (frameLoader.state() == FrameStateProvisional || !frameLoader.activeDocumentLoader() || frameLoader.activeDocumentLoader()->isStopping())) {
         failBeforeStarting();
         return;
@@ -233,7 +233,7 @@ void CachedResource::load(CachedResourceLoader* cachedResourceLoader, const Reso
         // When QuickLook is invoked to convert a document, it returns a unique URL in the
         // NSURLReponse for the main document. To make safeQLURLForDocumentURLAndResourceURL()
         // work, we need to use the QL URL not the original URL.
-        const URL& documentURL = cachedResourceLoader->frame() ? cachedResourceLoader->frame()->loader().documentLoader()->response().url() : cachedResourceLoader->document()->url();
+        const URL& documentURL = cachedResourceLoader.frame() ? cachedResourceLoader.frame()->loader().documentLoader()->response().url() : cachedResourceLoader.document()->url();
         m_resourceRequest.setURL(safeQLURLForDocumentURLAndResourceURL(documentURL, url()));
     }
 #endif
@@ -248,8 +248,8 @@ void CachedResource::load(CachedResourceLoader* cachedResourceLoader, const Reso
         const String& lastModified = resourceToRevalidate->response().httpHeaderField(HTTPHeaderName::LastModified);
         const String& eTag = resourceToRevalidate->response().httpHeaderField(HTTPHeaderName::ETag);
         if (!lastModified.isEmpty() || !eTag.isEmpty()) {
-            ASSERT(cachedResourceLoader->cachePolicy(type()) != CachePolicyReload);
-            if (cachedResourceLoader->cachePolicy(type()) == CachePolicyRevalidate)
+            ASSERT(cachedResourceLoader.cachePolicy(type()) != CachePolicyReload);
+            if (cachedResourceLoader.cachePolicy(type()) == CachePolicyRevalidate)
                 m_resourceRequest.setHTTPHeaderField(HTTPHeaderName::CacheControl, "max-age=0");
             if (!lastModified.isEmpty())
                 m_resourceRequest.setHTTPHeaderField(HTTPHeaderName::IfModifiedSince, lastModified);
@@ -277,7 +277,7 @@ void CachedResource::load(CachedResourceLoader* cachedResourceLoader, const Reso
         m_fragmentIdentifierForRequest = String();
     }
 
-    m_loader = platformStrategies()->loaderStrategy()->resourceLoadScheduler()->scheduleSubresourceLoad(cachedResourceLoader->frame(), this, request, options);
+    m_loader = platformStrategies()->loaderStrategy()->resourceLoadScheduler()->scheduleSubresourceLoad(cachedResourceLoader.frame(), this, request, options);
     if (!m_loader) {
         failBeforeStarting();
         return;
index f9770d7..648e745 100644 (file)
@@ -94,7 +94,7 @@ public:
     CachedResource(const ResourceRequest&, Type, SessionID);
     virtual ~CachedResource();
 
-    virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&);
+    virtual void load(CachedResourceLoader&, const ResourceLoaderOptions&);
 
     virtual void setEncoding(const String&) { }
     virtual String encoding() const { return String(); }
@@ -282,7 +282,7 @@ private:
 
     double freshnessLifetime(const ResourceResponse&) const;
 
-    void addAdditionalRequestHeaders(CachedResourceLoader*);
+    void addAdditionalRequestHeaders(CachedResourceLoader&);
     void failBeforeStarting();
 
     HashMap<CachedResourceClient*, std::unique_ptr<Callback>> m_clientsAwaitingCallback;
index 524a4e7..95cc505 100644 (file)
@@ -228,7 +228,7 @@ CachedResourceHandle<CachedCSSStyleSheet> CachedResourceLoader::requestUserCSSSt
     memoryCache().add(userSheet.get());
     // FIXME: loadResource calls setOwningCachedResourceLoader() if the resource couldn't be added to cache. Does this function need to call it, too?
 
-    userSheet->load(this, ResourceLoaderOptions(DoNotSendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo));
+    userSheet->load(*this, ResourceLoaderOptions(DoNotSendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo));
     
     return userSheet;
 }
@@ -516,7 +516,7 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
         resource->setLoadPriority(request.priority());
 
     if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest::NoDefer == request.defer()) {
-        resource->load(this, request.options());
+        resource->load(*this, request.options());
 
         // We don't support immediate loads, but we do support immediate failure.
         if (resource->errorOccurred()) {
@@ -763,7 +763,7 @@ void CachedResourceLoader::reloadImagesIfNotDeferred()
     for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != end; ++it) {
         CachedResource* resource = it->value.get();
         if (is<CachedImage>(*resource) && resource->stillNeedsLoad() && !clientDefersImage(resource->url()))
-            downcast<CachedImage>(*resource).load(this, defaultCachedResourceOptions());
+            downcast<CachedImage>(*resource).load(*this, defaultCachedResourceOptions());
     }
 }
 
index ebe3e4d..1fd570b 100644 (file)
@@ -194,22 +194,18 @@ class ResourceCacheValidationSuppressor {
     WTF_MAKE_NONCOPYABLE(ResourceCacheValidationSuppressor);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    ResourceCacheValidationSuppressor(CachedResourceLoader* loader)
+    ResourceCacheValidationSuppressor(CachedResourceLoader& loader)
         : m_loader(loader)
-        , m_previousState(false)
+        , m_previousState(m_loader.m_allowStaleResources)
     {
-        if (m_loader) {
-            m_previousState = m_loader->m_allowStaleResources;
-            m_loader->m_allowStaleResources = true;
-        }
+        m_loader.m_allowStaleResources = true;
     }
     ~ResourceCacheValidationSuppressor()
     {
-        if (m_loader)
-            m_loader->m_allowStaleResources = m_previousState;
+        m_loader.m_allowStaleResources = m_previousState;
     }
 private:
-    CachedResourceLoader* m_loader;
+    CachedResourceLoader& m_loader;
     bool m_previousState;
 };
 
index b6b4626..c627f4e 100644 (file)
@@ -53,15 +53,14 @@ CachedSVGDocumentReference::~CachedSVGDocumentReference()
     }
 }
 
-void CachedSVGDocumentReference::load(CachedResourceLoader* loader)
+void CachedSVGDocumentReference::load(CachedResourceLoader& loader)
 {
-    ASSERT(loader);
     if (m_loadRequested)
         return;
 
-    CachedResourceRequest request(ResourceRequest(loader->document()->completeURL(m_url)));
+    CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url)));
     request.setInitiator(cachedResourceRequestInitiators().css);
-    m_document = loader->requestSVGDocument(request);
+    m_document = loader.requestSVGDocument(request);
     if (m_document) {
         m_document->setCanReuse(m_canReuseResource);
         m_document->addClient(this);
index 41f41db..5e032ad 100644 (file)
@@ -41,7 +41,7 @@ public:
 
     virtual ~CachedSVGDocumentReference();
 
-    void load(CachedResourceLoader*);
+    void load(CachedResourceLoader&);
     bool loadRequested() const { return m_loadRequested; }
 
     CachedSVGDocument* document() { return m_document.get(); }
index 56921cd..de0c994 100644 (file)
@@ -63,7 +63,7 @@ void IconLoader::startLoading()
     request.mutableResourceRequest().setPriority(ResourceLoadPriorityLow);
     request.setInitiator(cachedResourceRequestInitiators().icon);
 
-    m_resource = m_frame.document()->cachedResourceLoader()->requestRawResource(request);
+    m_resource = m_frame.document()->cachedResourceLoader().requestRawResource(request);
     if (m_resource)
         m_resource->addClient(this);
     else
@@ -74,7 +74,7 @@ void IconLoader::stopLoading()
 {
     if (m_resource) {
         m_resource->removeClient(this);
-        m_resource = 0;
+        m_resource = nullptr;
     }
 }
 
index d4bab51..1961a3f 100644 (file)
@@ -487,8 +487,7 @@ bool DragController::concludeEditDrag(DragData& dragData)
     if (!range)
         return false;
 
-    CachedResourceLoader* cachedResourceLoader = range->ownerDocument().cachedResourceLoader();
-    ResourceCacheValidationSuppressor validationSuppressor(cachedResourceLoader);
+    ResourceCacheValidationSuppressor validationSuppressor(range->ownerDocument().cachedResourceLoader());
     if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRichlyEditable()) {
         bool chosePlainText = false;
         RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, *innerFrame, *range, true, chosePlainText);
index 89b4323..6b9d23c 100644 (file)
@@ -57,8 +57,8 @@ static void setImageLoadingSettings(Page* page)
         return;
 
     for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
-        frame->document()->cachedResourceLoader()->setImagesEnabled(page->settings().areImagesEnabled());
-        frame->document()->cachedResourceLoader()->setAutoLoadImages(page->settings().loadsImagesAutomatically());
+        frame->document()->cachedResourceLoader().setImagesEnabled(page->settings().areImagesEnabled());
+        frame->document()->cachedResourceLoader().setAutoLoadImages(page->settings().loadsImagesAutomatically());
     }
 }
 
index ce8e33e..184ec2e 100644 (file)
@@ -196,8 +196,8 @@ void MediaPlayerPrivateMediaFoundation::setSize(const IntSize& size)
     LayoutSize scrollOffset;
 
     FrameView* view = nullptr;
-    if (m_player && m_player->cachedResourceLoader() && m_player->cachedResourceLoader()->document())
-        view = m_player->cachedResourceLoader()->document()->view();
+    if (m_player && m_player->cachedResourceLoader() && m_player->cachedResourceLoader().document())
+        view = m_player->cachedResourceLoader().document()->view();
     if (view)
         scrollOffset = view->scrollOffsetForFixedPosition();
 
@@ -434,9 +434,9 @@ void MediaPlayerPrivateMediaFoundation::createVideoWindow()
 {
     HWND hWndParent = nullptr;
     FrameView* view = nullptr;
-    if (!m_player || !m_player->cachedResourceLoader() || !m_player->cachedResourceLoader()->document())
+    if (!m_player || !m_player->cachedResourceLoader() || !m_player->cachedResourceLoader().document())
         return;
-    view = m_player->cachedResourceLoader()->document()->view();
+    view = m_player->cachedResourceLoader().document()->view();
     if (!view || !view->hostWindow())
         return;
     hWndParent = view->hostWindow()->platformPageClient();
index 0867233..105a06e 100644 (file)
@@ -82,7 +82,7 @@ void SVGFEImageElement::requestImageResource()
 {
     CachedResourceRequest request(ResourceRequest(document().completeURL(href())));
     request.setInitiator(this);
-    m_cachedImage = document().cachedResourceLoader()->requestImage(request);
+    m_cachedImage = document().cachedResourceLoader().requestImage(request);
 
     if (m_cachedImage)
         m_cachedImage->addClient(this);
index 813f266..b2b5057 100644 (file)
@@ -101,10 +101,10 @@ void SVGFontFaceUriElement::loadFont()
 
     const AtomicString& href = getAttribute(XLinkNames::hrefAttr);
     if (!href.isNull()) {
-        CachedResourceLoader* cachedResourceLoader = document().cachedResourceLoader();
+        CachedResourceLoader& cachedResourceLoader = document().cachedResourceLoader();
         CachedResourceRequest request(ResourceRequest(document().completeURL(href)));
         request.setInitiator(this);
-        m_cachedFont = cachedResourceLoader->requestFont(request, isSVGFontTarget(*this));
+        m_cachedFont = cachedResourceLoader.requestFont(request, isSVGFontTarget(*this));
         if (m_cachedFont) {
             m_cachedFont->addClient(this);
             m_cachedFont->beginLoadIfNeeded(cachedResourceLoader);
index a220a78..3c13ea9 100644 (file)
@@ -260,7 +260,7 @@ void SVGUseElement::svgAttributeChanged(const QualifiedName& attrName)
             if (url.hasFragmentIdentifier()) {
                 CachedResourceRequest request(ResourceRequest(url.string()));
                 request.setInitiator(this);
-                setCachedDocument(document().cachedResourceLoader()->requestSVGDocument(request));
+                setCachedDocument(document().cachedResourceLoader().requestSVGDocument(request));
             }
         } else
             setCachedDocument(0);
index 8fa386a..b3d1aa8 100644 (file)
@@ -373,7 +373,7 @@ String Internals::description(Deprecated::ScriptValue value)
 bool Internals::isPreloaded(const String& url)
 {
     Document* document = contextDocument();
-    return document->cachedResourceLoader()->isPreloaded(url);
+    return document->cachedResourceLoader().isPreloaded(url);
 }
 
 bool Internals::isLoadingFromMemoryCache(const String& url)
@@ -1685,11 +1685,7 @@ void Internals::garbageCollectDocumentResources(ExceptionCode& ec) const
         ec = INVALID_ACCESS_ERR;
         return;
     }
-
-    CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
-    if (!cachedResourceLoader)
-        return;
-    cachedResourceLoader->garbageCollectDocumentResources();
+    document->cachedResourceLoader().garbageCollectDocumentResources();
 }
 
 void Internals::allowRoundingHacks() const
index d489efd..7799dfa 100644 (file)
@@ -127,8 +127,8 @@ CachedResourceLoader* XSLStyleSheet::cachedResourceLoader()
 {
     Document* document = ownerDocument();
     if (!document)
-        return 0;
-    return document->cachedResourceLoader();
+        return nullptr;
+    return &document->cachedResourceLoader();
 }
 
 bool XSLStyleSheet::parseString(const String& string)
index f1915e7..0b19ace 100644 (file)
@@ -288,7 +288,7 @@ static inline String resultMIMEType(xmlDocPtr resultDoc, xsltStylesheetPtr sheet
     // HTML (create an HTML document), XML (create an XML document),
     // and text (wrap in a <pre> and create an XML document).
 
-    const xmlChar* resultType = 0;
+    const xmlChar* resultType = nullptr;
     XSLT_GET_IMPORT_PTR(resultType, sheet, method);
     if (!resultType && resultDoc->type == XML_HTML_DOCUMENT_NODE)
         resultType = (const xmlChar*)"html";
@@ -305,11 +305,11 @@ bool XSLTProcessor::transformToString(Node& sourceNode, String& mimeType, String
 {
     Ref<Document> ownerDocument(sourceNode.document());
 
-    setXSLTLoadCallBack(docLoaderFunc, this, ownerDocument->cachedResourceLoader());
+    setXSLTLoadCallBack(docLoaderFunc, this, &ownerDocument->cachedResourceLoader());
     xsltStylesheetPtr sheet = xsltStylesheetPointer(m_stylesheet, m_stylesheetRootNode.get());
     if (!sheet) {
-        setXSLTLoadCallBack(0, 0, 0);
-        m_stylesheet = 0;
+        setXSLTLoadCallBack(nullptr, nullptr, nullptr);
+        m_stylesheet = nullptr;
         return false;
     }
     m_stylesheet->clearDocuments();
index 5273e24..a551613 100644 (file)
@@ -192,7 +192,7 @@ class Text;
     };
 
 #if ENABLE(XSLT)
-void* xmlDocPtrForString(CachedResourceLoader*, const String& source, const String& url);
+void* xmlDocPtrForString(CachedResourceLoader&, const String& source, const String& url);
 #endif
 
 HashMap<String, String> parseAttributes(const String&, bool& attrsOK);
index b299cb6..60a0a5b 100644 (file)
@@ -680,7 +680,7 @@ void XMLDocumentParser::doWrite(const String& parseString)
         // keep this alive until this function is done.
         Ref<XMLDocumentParser> protect(*this);
 
-        XMLDocumentParserScope scope(document()->cachedResourceLoader());
+        XMLDocumentParserScope scope(&document()->cachedResourceLoader());
 
         // FIXME: Can we parse 8-bit strings directly as Latin-1 instead of upconverting to UTF-16?
         switchToUTF16(context->context());
@@ -1352,7 +1352,7 @@ void XMLDocumentParser::initializeParserContext(const CString& chunk)
     m_sawXSLTransform = false;
     m_sawFirstElement = false;
 
-    XMLDocumentParserScope scope(document()->cachedResourceLoader());
+    XMLDocumentParserScope scope(&document()->cachedResourceLoader());
     if (m_parsingFragment)
         m_context = XMLParserContext::createMemoryParser(&sax, this, chunk);
     else {
@@ -1367,11 +1367,11 @@ void XMLDocumentParser::doEnd()
         if (m_context) {
             // Tell libxml we're done.
             {
-                XMLDocumentParserScope scope(document()->cachedResourceLoader());
+                XMLDocumentParserScope scope(&document()->cachedResourceLoader());
                 xmlParseChunk(context(), 0, 0, 1);
             }
 
-            m_context = 0;
+            m_context = nullptr;
         }
     }
 
@@ -1406,10 +1406,10 @@ static inline const char* nativeEndianUTF16Encoding()
     return BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE";
 }
 
-void* xmlDocPtrForString(CachedResourceLoader* cachedResourceLoader, const String& source, const String& url)
+void* xmlDocPtrForString(CachedResourceLoader& cachedResourceLoader, const String& source, const String& url)
 {
     if (source.isEmpty())
-        return 0;
+        return nullptr;
 
     // Parse in a single chunk into an xmlDocPtr
     // FIXME: Hook up error handlers so that a failure to parse the main document results in
@@ -1420,7 +1420,7 @@ void* xmlDocPtrForString(CachedResourceLoader* cachedResourceLoader, const Strin
     size_t sizeInBytes = source.length() * (is8Bit ? sizeof(LChar) : sizeof(UChar));
     const char* encoding = is8Bit ? "iso-8859-1" : nativeEndianUTF16Encoding();
 
-    XMLDocumentParserScope scope(cachedResourceLoader, errorFunc, 0);
+    XMLDocumentParserScope scope(&cachedResourceLoader, errorFunc);
     return xmlReadMemory(characters, sizeInBytes, url.latin1().data(), encoding, XSLT_PARSE_OPTIONS);
 }
 #endif
index 411c601..71362cc 100644 (file)
@@ -1,3 +1,15 @@
+2015-01-27  Chris Dumez  <cdumez@apple.com>
+
+        Use a Ref<CachedResourceLoader> in Document instead of a RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=140971
+
+        Reviewed by Andreas Kling.
+
+        Use more references instead of pointers.
+
+        * WebDataSource.cpp:
+        (WebDataSource::subresourceForURL):
+
 2015-01-26  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] ASSERTION FAILED !m_ptr under AccessibilityController::winAddNotificationListener
index b11fffa..91dc7e4 100644 (file)
@@ -288,14 +288,14 @@ HRESULT STDMETHODCALLTYPE WebDataSource::subresourceForURL(
         return E_POINTER;
     }
 
-    *resource = 0;
+    *resource = nullptr;
 
-    Document *doc = m_loader->frameLoader()->frame().document();
+    Documentdoc = m_loader->frameLoader()->frame().document();
 
     if (!doc)
         return E_FAIL;
 
-    CachedResource *cachedResource = doc->cachedResourceLoader()->cachedResource(String(url));
+    CachedResource* cachedResource = doc->cachedResourceLoader().cachedResource(String(url));
 
     if (!cachedResource)
         return E_FAIL;