DownloadProxy should keep a strong reference to its associated web context
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Dec 2012 22:04:12 +0000 (22:04 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Dec 2012 22:04:12 +0000 (22:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=105107

Reviewed by Alexey Proskuryakov.

While this does create a ref-cycle, it's broken when the download completes, fails, is canceled or
if the process that's doing the download crashes.

* UIProcess/Downloads/DownloadProxy.cpp:
(WebKit::DownloadProxy::processDidClose):
(WebKit::DownloadProxy::didStart):
(WebKit::DownloadProxy::didReceiveAuthenticationChallenge):
(WebKit::DownloadProxy::didReceiveResponse):
(WebKit::DownloadProxy::didReceiveData):
(WebKit::DownloadProxy::shouldDecodeSourceDataOfMIMEType):
(WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):
(WebKit::DownloadProxy::didCreateDestination):
(WebKit::DownloadProxy::didFinish):
(WebKit::DownloadProxy::didFail):
(WebKit::DownloadProxy::didCancel):
* UIProcess/Downloads/DownloadProxy.h:
(DownloadProxy):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp
Source/WebKit2/UIProcess/Downloads/DownloadProxy.h

index 0390edc..8ebd2ed 100644 (file)
@@ -1,5 +1,30 @@
 2012-12-15  Anders Carlsson  <andersca@apple.com>
 
 2012-12-15  Anders Carlsson  <andersca@apple.com>
 
+        DownloadProxy should keep a strong reference to its associated web context
+        https://bugs.webkit.org/show_bug.cgi?id=105107
+
+        Reviewed by Alexey Proskuryakov.
+
+        While this does create a ref-cycle, it's broken when the download completes, fails, is canceled or
+        if the process that's doing the download crashes.
+
+        * UIProcess/Downloads/DownloadProxy.cpp:
+        (WebKit::DownloadProxy::processDidClose):
+        (WebKit::DownloadProxy::didStart):
+        (WebKit::DownloadProxy::didReceiveAuthenticationChallenge):
+        (WebKit::DownloadProxy::didReceiveResponse):
+        (WebKit::DownloadProxy::didReceiveData):
+        (WebKit::DownloadProxy::shouldDecodeSourceDataOfMIMEType):
+        (WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):
+        (WebKit::DownloadProxy::didCreateDestination):
+        (WebKit::DownloadProxy::didFinish):
+        (WebKit::DownloadProxy::didFail):
+        (WebKit::DownloadProxy::didCancel):
+        * UIProcess/Downloads/DownloadProxy.h:
+        (DownloadProxy):
+
+2012-12-15  Anders Carlsson  <andersca@apple.com>
+
         Remove WebContext::downloadFinished
         https://bugs.webkit.org/show_bug.cgi?id=105105
 
         Remove WebContext::downloadFinished
         https://bugs.webkit.org/show_bug.cgi?id=105105
 
index aea6313..3e0a108 100644 (file)
@@ -82,7 +82,7 @@ void DownloadProxy::processDidClose()
     if (!m_webContext)
         return;
 
     if (!m_webContext)
         return;
 
-    m_webContext->downloadClient().processDidCrash(m_webContext, this);
+    m_webContext->downloadClient().processDidCrash(m_webContext.get(), this);
 }
 
 void DownloadProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder)
 }
 
 void DownloadProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder)
@@ -102,7 +102,7 @@ void DownloadProxy::didStart(const ResourceRequest& request)
     if (!m_webContext)
         return;
 
     if (!m_webContext)
         return;
 
-    m_webContext->downloadClient().didStart(m_webContext, this);
+    m_webContext->downloadClient().didStart(m_webContext.get(), this);
 }
 
 void DownloadProxy::didReceiveAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge, uint64_t challengeID)
 }
 
 void DownloadProxy::didReceiveAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge, uint64_t challengeID)
@@ -113,7 +113,7 @@ void DownloadProxy::didReceiveAuthenticationChallenge(const AuthenticationChalle
     // FIXME (Multi-WebProcess): <rdar://problem/12239483> Downloads shouldn't be handled in the web process.
     // Once this is fixed, remove WebContext::deprecatedSharedProcess().
     RefPtr<AuthenticationChallengeProxy> authenticationChallengeProxy = AuthenticationChallengeProxy::create(authenticationChallenge, challengeID, m_webContext->deprecatedSharedProcess());
     // FIXME (Multi-WebProcess): <rdar://problem/12239483> Downloads shouldn't be handled in the web process.
     // Once this is fixed, remove WebContext::deprecatedSharedProcess().
     RefPtr<AuthenticationChallengeProxy> authenticationChallengeProxy = AuthenticationChallengeProxy::create(authenticationChallenge, challengeID, m_webContext->deprecatedSharedProcess());
-    m_webContext->downloadClient().didReceiveAuthenticationChallenge(m_webContext, this, authenticationChallengeProxy.get());
+    m_webContext->downloadClient().didReceiveAuthenticationChallenge(m_webContext.get(), this, authenticationChallengeProxy.get());
 }
 
 void DownloadProxy::didReceiveResponse(const ResourceResponse& response)
 }
 
 void DownloadProxy::didReceiveResponse(const ResourceResponse& response)
@@ -121,7 +121,7 @@ void DownloadProxy::didReceiveResponse(const ResourceResponse& response)
     if (!m_webContext)
         return;
 
     if (!m_webContext)
         return;
 
-    m_webContext->downloadClient().didReceiveResponse(m_webContext, this, response);
+    m_webContext->downloadClient().didReceiveResponse(m_webContext.get(), this, response);
 }
 
 void DownloadProxy::didReceiveData(uint64_t length)
 }
 
 void DownloadProxy::didReceiveData(uint64_t length)
@@ -129,7 +129,7 @@ void DownloadProxy::didReceiveData(uint64_t length)
     if (!m_webContext)
         return;
 
     if (!m_webContext)
         return;
 
-    m_webContext->downloadClient().didReceiveData(m_webContext, this, length);
+    m_webContext->downloadClient().didReceiveData(m_webContext.get(), this, length);
 }
 
 void DownloadProxy::shouldDecodeSourceDataOfMIMEType(const String& mimeType, bool& result)
 }
 
 void DownloadProxy::shouldDecodeSourceDataOfMIMEType(const String& mimeType, bool& result)
@@ -137,7 +137,7 @@ void DownloadProxy::shouldDecodeSourceDataOfMIMEType(const String& mimeType, boo
     if (!m_webContext)
         return;
 
     if (!m_webContext)
         return;
 
-    result = m_webContext->downloadClient().shouldDecodeSourceDataOfMIMEType(m_webContext, this, mimeType);
+    result = m_webContext->downloadClient().shouldDecodeSourceDataOfMIMEType(m_webContext.get(), this, mimeType);
 }
 
 void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filename, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle)
 }
 
 void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filename, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle)
@@ -145,7 +145,7 @@ void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filenam
     if (!m_webContext)
         return;
 
     if (!m_webContext)
         return;
 
-    destination = m_webContext->downloadClient().decideDestinationWithSuggestedFilename(m_webContext, this, filename, allowOverwrite);
+    destination = m_webContext->downloadClient().decideDestinationWithSuggestedFilename(m_webContext.get(), this, filename, allowOverwrite);
 
     if (!destination.isNull())
         SandboxExtension::createHandle(destination, SandboxExtension::WriteOnly, sandboxExtensionHandle);
 
     if (!destination.isNull())
         SandboxExtension::createHandle(destination, SandboxExtension::WriteOnly, sandboxExtensionHandle);
@@ -156,7 +156,7 @@ void DownloadProxy::didCreateDestination(const String& path)
     if (!m_webContext)
         return;
 
     if (!m_webContext)
         return;
 
-    m_webContext->downloadClient().didCreateDestination(m_webContext, this, path);
+    m_webContext->downloadClient().didCreateDestination(m_webContext.get(), this, path);
 }
 
 void DownloadProxy::didFinish()
 }
 
 void DownloadProxy::didFinish()
@@ -164,7 +164,7 @@ void DownloadProxy::didFinish()
     if (!m_webContext)
         return;
 
     if (!m_webContext)
         return;
 
-    m_webContext->downloadClient().didFinish(m_webContext, this);
+    m_webContext->downloadClient().didFinish(m_webContext.get(), this);
 
     // This can cause the DownloadProxy object to be deleted.
     m_downloadProxyMap.downloadFinished(this);
 
     // This can cause the DownloadProxy object to be deleted.
     m_downloadProxyMap.downloadFinished(this);
@@ -185,7 +185,7 @@ void DownloadProxy::didFail(const ResourceError& error, const CoreIPC::DataRefer
 
     m_resumeData = createWebData(resumeData);
 
 
     m_resumeData = createWebData(resumeData);
 
-    m_webContext->downloadClient().didFail(m_webContext, this, error);
+    m_webContext->downloadClient().didFail(m_webContext.get(), this, error);
 
     // This can cause the DownloadProxy object to be deleted.
     m_downloadProxyMap.downloadFinished(this);
 
     // This can cause the DownloadProxy object to be deleted.
     m_downloadProxyMap.downloadFinished(this);
@@ -195,7 +195,7 @@ void DownloadProxy::didCancel(const CoreIPC::DataReference& resumeData)
 {
     m_resumeData = createWebData(resumeData);
 
 {
     m_resumeData = createWebData(resumeData);
 
-    m_webContext->downloadClient().didCancel(m_webContext, this);
+    m_webContext->downloadClient().didCancel(m_webContext.get(), this);
 
     // This can cause the DownloadProxy object to be deleted.
     m_downloadProxyMap.downloadFinished(this);
 
     // This can cause the DownloadProxy object to be deleted.
     m_downloadProxyMap.downloadFinished(this);
index 8e7f2c3..37fde92 100644 (file)
@@ -91,7 +91,7 @@ private:
     void didCancel(const CoreIPC::DataReference& resumeData);
 
     DownloadProxyMap& m_downloadProxyMap;
     void didCancel(const CoreIPC::DataReference& resumeData);
 
     DownloadProxyMap& m_downloadProxyMap;
-    WebContext* m_webContext;
+    RefPtr<WebContext> m_webContext;
     uint64_t m_downloadID;
 
     RefPtr<WebData> m_resumeData;
     uint64_t m_downloadID;
 
     RefPtr<WebData> m_resumeData;