Make MainResourceLoader not use m_frame directly.
authorjaphet@chromium.org <japhet@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Dec 2012 18:23:56 +0000 (18:23 +0000)
committerjaphet@chromium.org <japhet@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Dec 2012 18:23:56 +0000 (18:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103907

Reviewed by Darin Adler.

MainResourceLoader will soon cease to be a ResourceLoader subclass.  It currently
makes extensively use of both m_documentLoader and m_frame from ResourceLoader.
By moving everything over to going through m_documentLoader, we reduce the number
of members we have to add to MainResourceLoader in https://bugs.webkit.org/show_bug.cgi?id=49246.

No new tests, refactor only.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::startLoadingMainResource):
* loader/MainResourceLoader.cpp:
(WebCore::MainResourceLoader::MainResourceLoader):
(WebCore::MainResourceLoader::create):
(WebCore::MainResourceLoader::receivedError):
(WebCore::MainResourceLoader::willSendRequest):
(WebCore::MainResourceLoader::continueAfterContentPolicy):
(WebCore::MainResourceLoader::didReceiveResponse):
(WebCore::MainResourceLoader::didReceiveData):
(WebCore::MainResourceLoader::startDataLoadTimer):
* loader/MainResourceLoader.h:
(MainResourceLoader):

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

Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/MainResourceLoader.cpp
Source/WebCore/loader/MainResourceLoader.h

index 5c81638..3c613ce 100644 (file)
@@ -1,3 +1,31 @@
+2012-12-03  Nate Chapin  <japhet@chromium.org>
+
+        Make MainResourceLoader not use m_frame directly.
+        https://bugs.webkit.org/show_bug.cgi?id=103907
+
+        Reviewed by Darin Adler.
+
+        MainResourceLoader will soon cease to be a ResourceLoader subclass.  It currently
+        makes extensively use of both m_documentLoader and m_frame from ResourceLoader.
+        By moving everything over to going through m_documentLoader, we reduce the number
+        of members we have to add to MainResourceLoader in https://bugs.webkit.org/show_bug.cgi?id=49246.
+
+        No new tests, refactor only.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::startLoadingMainResource):
+        * loader/MainResourceLoader.cpp:
+        (WebCore::MainResourceLoader::MainResourceLoader):
+        (WebCore::MainResourceLoader::create):
+        (WebCore::MainResourceLoader::receivedError):
+        (WebCore::MainResourceLoader::willSendRequest):
+        (WebCore::MainResourceLoader::continueAfterContentPolicy):
+        (WebCore::MainResourceLoader::didReceiveResponse):
+        (WebCore::MainResourceLoader::didReceiveData):
+        (WebCore::MainResourceLoader::startDataLoadTimer):
+        * loader/MainResourceLoader.h:
+        (MainResourceLoader):
+
 2012-12-03  Anton Vayvod  <avayvod@chromium.org>
 
         Text Autosizing: don't autosize horizontal menu items implemented via floating list items
index 9f5f048..3218c12 100644 (file)
@@ -872,7 +872,7 @@ void DocumentLoader::startLoadingMainResource()
     if (maybeLoadEmpty())
         return;
 
-    m_mainResourceLoader = MainResourceLoader::create(m_frame);
+    m_mainResourceLoader = MainResourceLoader::create(this);
 
     // FIXME: Is there any way the extra fields could have not been added by now?
     // If not, it would be great to remove this line of code.
index 3ff68d8..678a99d 100644 (file)
@@ -67,8 +67,8 @@
 
 namespace WebCore {
 
-MainResourceLoader::MainResourceLoader(Frame* frame)
-    : ResourceLoader(frame, ResourceLoaderOptions(SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForCrossOriginCredentials, SkipSecurityCheck))
+MainResourceLoader::MainResourceLoader(DocumentLoader* documentLoader)
+    : ResourceLoader(documentLoader->frame(), ResourceLoaderOptions(SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForCrossOriginCredentials, SkipSecurityCheck))
     , m_dataLoadTimer(this, &MainResourceLoader::handleSubstituteDataLoadNow)
     , m_loadingMultipartContent(false)
     , m_waitingForContentPolicy(false)
@@ -86,16 +86,16 @@ MainResourceLoader::~MainResourceLoader()
 #endif
 }
 
-PassRefPtr<MainResourceLoader> MainResourceLoader::create(Frame* frame)
+PassRefPtr<MainResourceLoader> MainResourceLoader::create(DocumentLoader* documentLoader)
 {
-    return adoptRef(new MainResourceLoader(frame));
+    return adoptRef(new MainResourceLoader(documentLoader));
 }
 
 void MainResourceLoader::receivedError(const ResourceError& error)
 {
     // Calling receivedMainResourceError will likely result in the last reference to this object to go away.
     RefPtr<MainResourceLoader> protect(this);
-    RefPtr<Frame> protectFrame(m_frame);
+    RefPtr<Frame> protectFrame(m_documentLoader->frame());
 
     // It is important that we call DocumentLoader::mainReceivedError before calling 
     // ResourceLoadNotifier::didFailToLoad because mainReceivedError clears out the relevant
@@ -212,7 +212,7 @@ void MainResourceLoader::willSendRequest(ResourceRequest& newRequest, const Reso
         // then block the redirect.
         RefPtr<SecurityOrigin> redirectingOrigin = SecurityOrigin::create(redirectResponse.url());
         if (!redirectingOrigin->canDisplay(newRequest.url())) {
-            FrameLoader::reportLocalLoadFailed(m_frame.get(), newRequest.url().string());
+            FrameLoader::reportLocalLoadFailed(m_documentLoader->frame(), newRequest.url().string());
             cancel();
             return;
         }
@@ -231,8 +231,8 @@ void MainResourceLoader::willSendRequest(ResourceRequest& newRequest, const Reso
     if (newRequest.cachePolicy() == UseProtocolCachePolicy && isPostOrRedirectAfterPost(newRequest, redirectResponse))
         newRequest.setCachePolicy(ReloadIgnoringCacheData);
 
-    Frame* top = m_frame->tree()->top();
-    if (top != m_frame) {
+    Frame* top = m_documentLoader->frame()->tree()->top();
+    if (top != m_documentLoader->frame()) {
         if (!frameLoader()->mixedContentChecker()->canDisplayInsecureContent(top->document()->securityOrigin(), newRequest.url())) {
             cancel();
             return;
@@ -290,7 +290,7 @@ void MainResourceLoader::continueAfterContentPolicy(PolicyAction contentPolicy,
             receivedError(cannotShowURLError());
             return;
         }
-        InspectorInstrumentation::continueWithPolicyDownload(m_frame.get(), documentLoader(), identifier(), r);
+        InspectorInstrumentation::continueWithPolicyDownload(m_documentLoader->frame(), documentLoader(), identifier(), r);
 
         // When starting the request, we didn't know that it would result in download and not navigation. Now we know that main document URL didn't change.
         // Download may use this knowledge for purposes unrelated to cookies, notably for setting file quarantine data.
@@ -305,7 +305,7 @@ void MainResourceLoader::continueAfterContentPolicy(PolicyAction contentPolicy,
         return;
     }
     case PolicyIgnore:
-        InspectorInstrumentation::continueWithPolicyIgnore(m_frame.get(), documentLoader(), identifier(), r);
+        InspectorInstrumentation::continueWithPolicyIgnore(m_documentLoader->frame(), documentLoader(), identifier(), r);
         stopLoadingForPolicyChange();
         return;
     
@@ -333,10 +333,10 @@ void MainResourceLoader::continueAfterContentPolicy(PolicyAction contentPolicy,
     if (!reachedTerminalState())
         ResourceLoader::didReceiveResponse(r);
 
-    if (frameLoader() && !frameLoader()->activeDocumentLoader()->isStopping() && m_substituteData.isValid()) {
+    if (m_documentLoader && !m_documentLoader->isStopping() && m_substituteData.isValid()) {
         if (m_substituteData.content()->size())
             didReceiveData(m_substituteData.content()->data(), m_substituteData.content()->size(), m_substituteData.content()->size(), true);
-        if (frameLoader() && !frameLoader()->activeDocumentLoader()->isStopping()) 
+        if (!m_documentLoader->isStopping())
             didFinishLoading(0);
     }
 }
@@ -350,7 +350,7 @@ void MainResourceLoader::continueAfterContentPolicy(PolicyAction policy)
 {
     ASSERT(m_waitingForContentPolicy);
     m_waitingForContentPolicy = false;
-    if (frameLoader() && !frameLoader()->activeDocumentLoader()->isStopping())
+    if (!m_documentLoader->isStopping())
         continueAfterContentPolicy(policy, m_response);
     deref(); // balances ref in didReceiveResponse
 }
@@ -364,10 +364,10 @@ void MainResourceLoader::didReceiveResponse(const ResourceResponse& r)
     HTTPHeaderMap::const_iterator it = r.httpHeaderFields().find(xFrameOptionHeader);
     if (it != r.httpHeaderFields().end()) {
         String content = it->value;
-        if (m_frame->loader()->shouldInterruptLoadForXFrameOptions(content, r.url(), identifier())) {
-            InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_frame.get(), documentLoader(), identifier(), r);
+        if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, r.url(), identifier())) {
+            InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_documentLoader->frame(), documentLoader(), identifier(), r);
             String message = "Refused to display '" + r.url().string() + "' in a frame because it set 'X-Frame-Options' to '" + content + "'.";
-            m_frame->document()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, r.url().string(), 0, 0, identifier());
+            m_documentLoader->frame()->document()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, r.url().string(), 0, 0, identifier());
 
             cancel();
             return;
@@ -400,17 +400,15 @@ void MainResourceLoader::didReceiveResponse(const ResourceResponse& r)
     m_waitingForContentPolicy = true;
     ref(); // balanced by deref in continueAfterContentPolicy and didCancel
 
-    ASSERT(frameLoader()->activeDocumentLoader());
-
     // Always show content with valid substitute data.
-    if (frameLoader()->activeDocumentLoader()->substituteData().isValid()) {
+    if (m_documentLoader->substituteData().isValid()) {
         callContinueAfterContentPolicy(this, PolicyUse);
         return;
     }
 
 #if ENABLE(FTPDIR)
     // Respect the hidden FTP Directory Listing pref so it can be tested even if the policy delegate might otherwise disallow it
-    Settings* settings = m_frame->settings();
+    Settings* settings = m_documentLoader->frame()->settings();
     if (settings && settings->forceFTPDirectoryListings() && m_response.mimeType() == "application/x-ftp-directory") {
         callContinueAfterContentPolicy(this, PolicyUse);
         return;
@@ -436,7 +434,7 @@ void MainResourceLoader::didReceiveData(const char* data, int length, long long
     // Workaround for <rdar://problem/6060782>
     if (m_response.isNull()) {
         m_response = ResourceResponse(KURL(), "text/html", 0, String(), String());
-        if (DocumentLoader* documentLoader = frameLoader()->activeDocumentLoader())
+        if (DocumentLoader* documentLoader = m_documentLoader.get())
             documentLoader->setResponse(m_response);
     }
 #endif
@@ -574,7 +572,7 @@ void MainResourceLoader::startDataLoadTimer()
     m_dataLoadTimer.startOneShot(0);
 
 #if HAVE(RUNLOOP_TIMER)
-    if (SchedulePairHashSet* scheduledPairs = m_frame->page()->scheduledRunLoopPairs())
+    if (SchedulePairHashSet* scheduledPairs = m_documentLoader->frame()->page()->scheduledRunLoopPairs())
         m_dataLoadTimer.schedule(*scheduledPairs);
 #endif
 }
index 350cecd..5943721 100644 (file)
@@ -51,7 +51,7 @@ class ResourceRequest;
 
 class MainResourceLoader : public ResourceLoader {
 public:
-    static PassRefPtr<MainResourceLoader> create(Frame*);
+    static PassRefPtr<MainResourceLoader> create(DocumentLoader*);
     virtual ~MainResourceLoader();
 
     void load(const ResourceRequest&, const SubstituteData&);
@@ -76,7 +76,7 @@ public:
     virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
 
 private:
-    explicit MainResourceLoader(Frame*);
+    explicit MainResourceLoader(DocumentLoader*);
 
     virtual void willCancel(const ResourceError&) OVERRIDE;
     virtual void didCancel(const ResourceError&) OVERRIDE;