Title: [145734] trunk/Source/WebCore
Revision
145734
Author
jap...@chromium.org
Date
2013-03-13 12:11:35 -0700 (Wed, 13 Mar 2013)

Log Message

Merge MainResourceLoader's didFinishLoading and dataReceived into DocumentLoader
https://bugs.webkit.org/show_bug.cgi?id=109952

Reviewed by Antti Koivisto.

No new tests, refactor only.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::DocumentLoader):
(WebCore::DocumentLoader::finishedLoading):
(WebCore::DocumentLoader::responseReceived):
(WebCore::DocumentLoader::receivedData):
(WebCore::DocumentLoader::maybeLoadEmpty):
* loader/DocumentLoader.h:
* loader/MainResourceLoader.cpp:
(WebCore::MainResourceLoader::responseReceived): Move content filtering to
    DocumentLoader.
(WebCore::MainResourceLoader::dataReceived): Mostly moved to DocumentLoader.
(WebCore::MainResourceLoader::didFinishLoading): Mostly moved to DocumentLoader.
* loader/MainResourceLoader.h: Expose some variables that haven't been moved
    to DocumentLoader yet.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (145733 => 145734)


--- trunk/Source/WebCore/ChangeLog	2013-03-13 18:52:42 UTC (rev 145733)
+++ trunk/Source/WebCore/ChangeLog	2013-03-13 19:11:35 UTC (rev 145734)
@@ -1,3 +1,27 @@
+2013-03-13  Nate Chapin  <jap...@chromium.org>
+
+        Merge MainResourceLoader's didFinishLoading and dataReceived into DocumentLoader
+        https://bugs.webkit.org/show_bug.cgi?id=109952
+
+        Reviewed by Antti Koivisto.
+
+        No new tests, refactor only.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::DocumentLoader):
+        (WebCore::DocumentLoader::finishedLoading):
+        (WebCore::DocumentLoader::responseReceived):
+        (WebCore::DocumentLoader::receivedData):
+        (WebCore::DocumentLoader::maybeLoadEmpty):
+        * loader/DocumentLoader.h:
+        * loader/MainResourceLoader.cpp:
+        (WebCore::MainResourceLoader::responseReceived): Move content filtering to
+            DocumentLoader.
+        (WebCore::MainResourceLoader::dataReceived): Mostly moved to DocumentLoader.
+        (WebCore::MainResourceLoader::didFinishLoading): Mostly moved to DocumentLoader.
+        * loader/MainResourceLoader.h: Expose some variables that haven't been moved
+            to DocumentLoader yet.
+
 2013-03-13  Andrei Bucur  <abu...@adobe.com>
 
         [CSS Regions] Break after doesn't work correctly with auto-height regions

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (145733 => 145734)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2013-03-13 18:52:42 UTC (rev 145733)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2013-03-13 19:11:35 UTC (rev 145734)
@@ -47,6 +47,7 @@
 #include "InspectorInstrumentation.h"
 #include "Logging.h"
 #include "MainResourceLoader.h"
+#include "MemoryCache.h"
 #include "Page.h"
 #include "ResourceBuffer.h"
 #include "SchemeRegistry.h"
@@ -65,6 +66,10 @@
 #include "ArchiveFactory.h"
 #endif
 
+#if USE(CONTENT_FILTERING)
+#include "ContentFilter.h"
+#endif
+
 namespace WebCore {
 
 static void cancelAll(const ResourceLoaderSet& loaders)
@@ -103,6 +108,7 @@
     , m_stopRecordingResponses(false)
     , m_substituteResourceDeliveryTimer(this, &DocumentLoader::substituteResourceDeliveryTimerFired)
     , m_didCreateGlobalHistoryEntry(false)
+    , m_timeOfLastDataReceived(0.0)
     , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this)))
 {
 }
@@ -297,8 +303,38 @@
     return isLoadingMainResource() || !m_subresourceLoaders.isEmpty() || !m_plugInStreamLoaders.isEmpty();
 }
 
-void DocumentLoader::finishedLoading()
+void DocumentLoader::finishedLoading(double finishTime)
 {
+    // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
+    // See <rdar://problem/6304600> for more details.
+#if !USE(CF)
+    ASSERT(!m_frame->page()->defersLoading() || InspectorInstrumentation::isDebuggerPaused(m_frame));
+#endif
+
+    if (mainResourceLoader() && mainResourceLoader()->identifierForLoadWithoutResourceLoader()) {
+        frameLoader()->notifier()->dispatchDidFinishLoading(this, mainResourceLoader()->identifier(), finishTime);
+        mainResourceLoader()->clearIdentifierForLoadWithoutResourceLoader();
+    }
+
+#if USE(CONTENT_FILTERING)
+    if (m_contentFilter && m_contentFilter->needsMoreData()) {
+        m_contentFilter->finishedAddingData();
+        int length;
+        const char* data = ""
+        if (data)
+            receivedData(data, length);
+    }
+#endif
+
+    maybeFinishLoadingMultipartContent();
+
+    double responseEndTime = finishTime;
+    if (!responseEndTime)
+        responseEndTime = m_timeOfLastDataReceived;
+    if (!responseEndTime)
+        responseEndTime = monotonicallyIncreasingTime();
+    timing()->setResponseEnd(responseEndTime);
+
     commitIfReady();
     if (!frameLoader())
         return;
@@ -317,8 +353,27 @@
     clearMainResourceLoader();
     if (!frameLoader()->stateMachine()->creatingInitialEmptyDocument())
         frameLoader()->checkLoadComplete();
+
+    // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache
+    // and deny the appcache the chance to intercept it in the future, so remove from the memory cache.
+    if (frame() && mainResourceLoader()) {
+        if (mainResourceLoader()->cachedMainResource() && frame()->document()->hasManifest())
+            memoryCache()->remove(mainResourceLoader()->cachedMainResource());
+    }
+    m_applicationCacheHost->finishedLoadingMainResource();
 }
 
+void DocumentLoader::responseReceived(const ResourceResponse& response)
+{
+    setResponse(response);
+
+#if USE(CONTENT_FILTERING)
+    if (response.url().protocolIs("https") && ContentFilter::isEnabled())
+        m_contentFilter = ContentFilter::create(response);
+#endif
+
+}
+
 void DocumentLoader::commitLoad(const char* data, int length)
 {
     // Both unloading the old page and parsing the new page may execute _javascript_ which destroys the datasource
@@ -412,8 +467,53 @@
 
 void DocumentLoader::receivedData(const char* data, int length)
 {
+    ASSERT(data);
+    ASSERT(length);
+    ASSERT(!m_response.isNull());
+
+#if USE(CFNETWORK) || PLATFORM(MAC)
+    // Workaround for <rdar://problem/6060782>
+    if (m_response.isNull())
+        setResponse(ResourceResponse(KURL(), "text/html", 0, String(), String()));
+#endif
+
+    // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
+    // See <rdar://problem/6304600> for more details.
+#if !USE(CF)
+    ASSERT(!m_frame->page()->defersLoading());
+#endif
+
+#if USE(CONTENT_FILTERING)
+    bool loadWasBlockedBeforeFinishing = false;
+    if (m_contentFilter && m_contentFilter->needsMoreData()) {
+        m_contentFilter->addData(data, length);
+
+        if (m_contentFilter->needsMoreData()) {
+            // Since the filter still needs more data to make a decision,
+            // transition back to the committed state so that we don't partially
+            // load content that might later be blocked.
+            commitLoad(0, 0);
+            return;
+        }
+
+        data = ""
+        loadWasBlockedBeforeFinishing = m_contentFilter->didBlockData();
+    }
+#endif
+
+    if (mainResourceLoader()->identifierForLoadWithoutResourceLoader())
+        frameLoader()->notifier()->dispatchDidReceiveData(this, mainResourceLoader()->identifier(), data, length, -1);
+
+    m_applicationCacheHost->mainResourceDataReceived(data, length, -1, false);
+    m_timeOfLastDataReceived = monotonicallyIncreasingTime();
+
     if (!isMultipartReplacingLoad())
         commitLoad(data, length);
+
+#if USE(CONTENT_FILTERING)
+    if (loadWasBlockedBeforeFinishing)
+        cancelMainResourceLoad(ResourceError());
+#endif
 }
 
 void DocumentLoader::setupForReplace()
@@ -899,7 +999,7 @@
         m_request.setURL(blankURL());
     String mimeType = shouldLoadEmpty ? "text/html" : frameLoader()->client()->generatedMIMETypeForURLScheme(m_request.url().protocol());
     setResponse(ResourceResponse(m_request.url(), mimeType, 0, String(), String()));
-    finishedLoading();
+    finishedLoading(monotonicallyIncreasingTime());
     return true;
 }
 

Modified: trunk/Source/WebCore/loader/DocumentLoader.h (145733 => 145734)


--- trunk/Source/WebCore/loader/DocumentLoader.h	2013-03-13 18:52:42 UTC (rev 145733)
+++ trunk/Source/WebCore/loader/DocumentLoader.h	2013-03-13 19:11:35 UTC (rev 145734)
@@ -56,6 +56,7 @@
     class ArchiveResource;
     class ArchiveResourceCollection;
     class CachedResourceLoader;
+    class ContentFilter;
     class Frame;
     class FrameLoader;
     class MainResourceLoader;
@@ -120,7 +121,7 @@
         bool isLoading() const;
         void receivedData(const char*, int);
         void setupForReplace();
-        void finishedLoading();
+        void finishedLoading(double finishTime);
         const ResourceResponse& response() const { return m_response; }
         const ResourceError& mainDocumentError() const { return m_mainDocumentError; }
         void mainReceivedError(const ResourceError&);
@@ -243,6 +244,8 @@
         DocumentLoadTiming* timing() { return &m_documentLoadTiming; }
         void resetTiming() { m_documentLoadTiming = DocumentLoadTiming(); }
 
+        void responseReceived(const ResourceResponse&);
+
         // The WebKit layer calls this function when it's ready for the data to
         // actually be added to the document.
         void commitData(const char* bytes, size_t length);
@@ -353,12 +356,18 @@
         bool m_didCreateGlobalHistoryEntry;
 
         DocumentLoadTiming m_documentLoadTiming;
+
+        double m_timeOfLastDataReceived;
     
         RefPtr<IconLoadDecisionCallback> m_iconLoadDecisionCallback;
         RefPtr<IconDataCallback> m_iconDataCallback;
 
         friend class ApplicationCacheHost;  // for substitute resource delivery
         OwnPtr<ApplicationCacheHost> m_applicationCacheHost;
+
+#if USE(CONTENT_FILTERING)
+        RefPtr<ContentFilter> m_contentFilter;
+#endif
     };
 
     inline void DocumentLoader::recordMemoryCacheLoadForFutureClientNotification(const ResourceRequest& request)

Modified: trunk/Source/WebCore/loader/MainResourceLoader.cpp (145733 => 145734)


--- trunk/Source/WebCore/loader/MainResourceLoader.cpp	2013-03-13 18:52:42 UTC (rev 145733)
+++ trunk/Source/WebCore/loader/MainResourceLoader.cpp	2013-03-13 19:11:35 UTC (rev 145734)
@@ -64,10 +64,6 @@
 #include "PluginDatabase.h"
 #endif
 
-#if USE(CONTENT_FILTERING)
-#include "ContentFilter.h"
-#endif
-
 namespace WebCore {
 
 MainResourceLoader::MainResourceLoader(DocumentLoader* documentLoader)
@@ -75,7 +71,6 @@
     , m_documentLoader(documentLoader)
     , m_loadingMultipartContent(false)
     , m_waitingForContentPolicy(false)
-    , m_timeOfLastDataReceived(0.0)
     , m_identifierForLoadWithoutResourceLoader(0)
 {
 }
@@ -438,7 +433,7 @@
     // reference to this object; one example of this is 3266216.
     RefPtr<MainResourceLoader> protect(this);
 
-    m_documentLoader->setResponse(r);
+    m_documentLoader->responseReceived(r);
 
     m_response = r;
 
@@ -464,116 +459,21 @@
     }
 #endif
 
-#if USE(CONTENT_FILTERING)
-    if (r.url().protocolIs("https") && ContentFilter::isEnabled())
-        m_contentFilter = ContentFilter::create(r);
-#endif
-
     frameLoader()->policyChecker()->checkContentPolicy(m_response, callContinueAfterContentPolicy, this);
 }
 
 void MainResourceLoader::dataReceived(CachedResource* resource, const char* data, int length)
 {
-    ASSERT(data);
-    ASSERT(length != 0);
     ASSERT_UNUSED(resource, resource == m_resource);
-    ASSERT(!m_response.isNull());
-
-#if USE(CFNETWORK) || PLATFORM(MAC)
-    // Workaround for <rdar://problem/6060782>
-    if (m_response.isNull()) {
-        m_response = ResourceResponse(KURL(), "text/html", 0, String(), String());
-        if (DocumentLoader* documentLoader = m_documentLoader.get())
-            documentLoader->setResponse(m_response);
-    }
-#endif
-
-    // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
-    // See <rdar://problem/6304600> for more details.
-#if !USE(CF)
-    ASSERT(!defersLoading());
-#endif
-
-#if USE(CONTENT_FILTERING)
-    bool loadWasBlockedBeforeFinishing = false;
-    if (m_contentFilter && m_contentFilter->needsMoreData()) {
-        m_contentFilter->addData(data, length);
-
-        if (m_contentFilter->needsMoreData()) {
-            // Since the filter still needs more data to make a decision,
-            // transition back to the committed state so that we don't partially
-            // load content that might later be blocked.
-            documentLoader()->receivedData(0, 0);
-            return;
-        }
-
-        data = ""
-        loadWasBlockedBeforeFinishing = m_contentFilter->didBlockData();
-    }
-#endif
-
-    if (m_identifierForLoadWithoutResourceLoader)
-        frameLoader()->notifier()->dispatchDidReceiveData(documentLoader(), identifier(), data, length, -1);
-
-    documentLoader()->applicationCacheHost()->mainResourceDataReceived(data, length, -1, false);
-
-    // The additional processing can do anything including possibly removing the last
-    // reference to this object; one example of this is 3266216.
-    RefPtr<MainResourceLoader> protect(this);
-
-    m_timeOfLastDataReceived = monotonicallyIncreasingTime();
-
     documentLoader()->receivedData(data, length);
-
-#if USE(CONTENT_FILTERING)
-    if (loadWasBlockedBeforeFinishing)
-        cancel();
-#endif
 }
 
 void MainResourceLoader::didFinishLoading(double finishTime)
 {
-    // There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
-    // See <rdar://problem/6304600> for more details.
-#if !USE(CF)
-    ASSERT(!defersLoading() || InspectorInstrumentation::isDebuggerPaused(m_documentLoader->frame()));
-#endif
-
     // The additional processing can do anything including possibly removing the last
     // reference to this object.
     RefPtr<MainResourceLoader> protect(this);
-    RefPtr<DocumentLoader> dl = documentLoader();
-
-    if (m_identifierForLoadWithoutResourceLoader) {
-        frameLoader()->notifier()->dispatchDidFinishLoading(documentLoader(), identifier(), finishTime);
-        m_identifierForLoadWithoutResourceLoader = 0;
-    }
-
-#if USE(CONTENT_FILTERING)
-    if (m_contentFilter && m_contentFilter->needsMoreData()) {
-        m_contentFilter->finishedAddingData();
-
-        int length;
-        const char* data = ""
-        if (data)
-            dataReceived(m_resource.get(), data, length);
-    }
-#endif
-
-    if (m_loadingMultipartContent)
-        dl->maybeFinishLoadingMultipartContent();
-
-    documentLoader()->timing()->setResponseEnd(finishTime ? finishTime : (m_timeOfLastDataReceived ? m_timeOfLastDataReceived : monotonicallyIncreasingTime()));
-    documentLoader()->finishedLoading();
-
-    // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache
-    // and deny the appcache the chance to intercept it in the future, so remove from the memory cache.
-    if (Frame* frame = documentLoader()->frame()) {
-        if (m_resource && frame->document()->hasManifest())
-            memoryCache()->remove(m_resource.get());
-    }
-
-    dl->applicationCacheHost()->finishedLoadingMainResource();
+    documentLoader()->finishedLoading(finishTime);
 }
 
 void MainResourceLoader::notifyFinished(CachedResource* resource)

Modified: trunk/Source/WebCore/loader/MainResourceLoader.h (145733 => 145734)


--- trunk/Source/WebCore/loader/MainResourceLoader.h	2013-03-13 18:52:42 UTC (rev 145733)
+++ trunk/Source/WebCore/loader/MainResourceLoader.h	2013-03-13 19:11:35 UTC (rev 145734)
@@ -46,10 +46,6 @@
 
 class FormState;
 class ResourceRequest;
-    
-#if USE(CONTENT_FILTERING)
-class ContentFilter;
-#endif
 
 class MainResourceLoader : public RefCounted<MainResourceLoader>, public CachedRawResourceClient {
     WTF_MAKE_FAST_ALLOCATED;
@@ -72,6 +68,10 @@
     typedef Timer<MainResourceLoader> MainResourceLoaderTimer;
 #endif
 
+    CachedRawResource* cachedMainResource() { return m_resource.get(); }
+    unsigned long identifierForLoadWithoutResourceLoader() const { return m_identifierForLoadWithoutResourceLoader; }
+    void clearIdentifierForLoadWithoutResourceLoader() { m_identifierForLoadWithoutResourceLoader = 0; }
+
     unsigned long identifier() const;
     bool isLoadingMultipartContent() const { return m_loadingMultipartContent; }
 
@@ -127,12 +127,7 @@
 
     bool m_loadingMultipartContent;
     bool m_waitingForContentPolicy;
-    double m_timeOfLastDataReceived;
     unsigned long m_identifierForLoadWithoutResourceLoader;
-
-#if USE(CONTENT_FILTERING)
-    RefPtr<ContentFilter> m_contentFilter;
-#endif
 };
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to