Remove ResourceResponse::m_suggestedFilename
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Sep 2014 20:00:11 +0000 (20:00 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Sep 2014 20:00:11 +0000 (20:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136534

Reviewed by Alexey Proskuryakov.

Source/WebCore:

This will simplify things.

* WebCore.exp.in:
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::handleSubstituteDataLoadNow):
(WebCore::DocumentLoader::maybeLoadEmpty):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::willLoadMediaElementURL):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::loadCache):
* loader/archive/ArchiveResource.cpp:
(WebCore::ArchiveResource::create):
* platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::notifyResponseOnSuccess):
(WebCore::BlobResourceHandle::notifyResponseOnError):
* platform/network/ResourceResponseBase.cpp:
(WebCore::ResourceResponseBase::ResourceResponseBase):
(WebCore::ResourceResponseBase::adopt):
(WebCore::ResourceResponseBase::copyData):
(WebCore::ResourceResponseBase::suggestedFilename):
(WebCore::ResourceResponseBase::httpStatusText):
(WebCore::ResourceResponseBase::setHTTPStatusText):
(WebCore::ResourceResponseBase::httpHeaderField):
(WebCore::ResourceResponseBase::setHTTPHeaderField):
(WebCore::ResourceResponseBase::addHTTPHeaderField):
(WebCore::ResourceResponseBase::httpHeaderFields):
(WebCore::ResourceResponseBase::isAttachment):
(WebCore::ResourceResponseBase::wasCached):
(WebCore::ResourceResponseBase::connectionReused):
(WebCore::ResourceResponseBase::setConnectionReused):
(WebCore::ResourceResponseBase::connectionID):
(WebCore::ResourceResponseBase::setConnectionID):

    Remove AllFields initialization. It was only used to get m_suggestedFilename.
    Rename CommonAndUncommonFields to AllFields

(WebCore::ResourceResponseBase::setSuggestedFilename): Deleted.

    No more setter.

* platform/network/ResourceResponseBase.h:
(WebCore::ResourceResponseBase::platformSuggestedFileName):

    Get the suggested filename from the platform class on-demand.

* platform/network/cf/ResourceResponse.h:
(WebCore::ResourceResponse::ResourceResponse):

    Remove never-used file name constructor parameter.

* platform/network/cf/ResourceResponseCFNet.cpp:
(WebCore::ResourceResponse::platformLazyInit):
* platform/network/mac/ResourceResponseMac.mm:
(WebCore::ResourceResponse::initNSURLResponse):

    Synthesize HTTP response properly so it can hold Content-Disposition for file name (and other headers).

(WebCore::ResourceResponse::platformLazyInit):

    Don't pull the suggested filename anymore.

(WebCore::ResourceResponse::platformSuggestedFilename):

    Get the suggested name from the (possibly synthetic) NSURLRequest.

Source/WebKit2:

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<ResourceResponse>::encode):
(IPC::ArgumentCoder<ResourceResponse>::decode):

    No more m_suggestedFilename.

* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::addArchiveResource):

    Fake the suggested filename by using the Content-Disposition header.

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp
Source/WebCore/loader/archive/ArchiveResource.cpp
Source/WebCore/platform/network/BlobResourceHandle.cpp
Source/WebCore/platform/network/ResourceResponseBase.cpp
Source/WebCore/platform/network/ResourceResponseBase.h
Source/WebCore/platform/network/cf/ResourceResponse.h
Source/WebCore/platform/network/cf/ResourceResponseCFNet.cpp
Source/WebCore/platform/network/mac/ResourceResponseMac.mm
Source/WebCore/plugins/PluginStream.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
Source/WebKit2/WebProcess/Plugins/PDF/PDFPlugin.mm

index caf1bdd..bfd69f1 100644 (file)
@@ -1,3 +1,75 @@
+2014-09-04  Antti Koivisto  <antti@apple.com>
+
+        Remove ResourceResponse::m_suggestedFilename
+        https://bugs.webkit.org/show_bug.cgi?id=136534
+
+        Reviewed by Alexey Proskuryakov.
+
+        This will simplify things.
+
+        * WebCore.exp.in:
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::handleSubstituteDataLoadNow):
+        (WebCore::DocumentLoader::maybeLoadEmpty):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::willLoadMediaElementURL):
+        * loader/appcache/ApplicationCacheStorage.cpp:
+        (WebCore::ApplicationCacheStorage::loadCache):
+        * loader/archive/ArchiveResource.cpp:
+        (WebCore::ArchiveResource::create):
+        * platform/network/BlobResourceHandle.cpp:
+        (WebCore::BlobResourceHandle::notifyResponseOnSuccess):
+        (WebCore::BlobResourceHandle::notifyResponseOnError):
+        * platform/network/ResourceResponseBase.cpp:
+        (WebCore::ResourceResponseBase::ResourceResponseBase):
+        (WebCore::ResourceResponseBase::adopt):
+        (WebCore::ResourceResponseBase::copyData):
+        (WebCore::ResourceResponseBase::suggestedFilename):
+        (WebCore::ResourceResponseBase::httpStatusText):
+        (WebCore::ResourceResponseBase::setHTTPStatusText):
+        (WebCore::ResourceResponseBase::httpHeaderField):
+        (WebCore::ResourceResponseBase::setHTTPHeaderField):
+        (WebCore::ResourceResponseBase::addHTTPHeaderField):
+        (WebCore::ResourceResponseBase::httpHeaderFields):
+        (WebCore::ResourceResponseBase::isAttachment):
+        (WebCore::ResourceResponseBase::wasCached):
+        (WebCore::ResourceResponseBase::connectionReused):
+        (WebCore::ResourceResponseBase::setConnectionReused):
+        (WebCore::ResourceResponseBase::connectionID):
+        (WebCore::ResourceResponseBase::setConnectionID):
+
+            Remove AllFields initialization. It was only used to get m_suggestedFilename.
+            Rename CommonAndUncommonFields to AllFields
+
+        (WebCore::ResourceResponseBase::setSuggestedFilename): Deleted.
+
+            No more setter.
+
+        * platform/network/ResourceResponseBase.h:
+        (WebCore::ResourceResponseBase::platformSuggestedFileName):
+
+            Get the suggested filename from the platform class on-demand.
+
+        * platform/network/cf/ResourceResponse.h:
+        (WebCore::ResourceResponse::ResourceResponse):
+
+            Remove never-used file name constructor parameter.
+
+        * platform/network/cf/ResourceResponseCFNet.cpp:
+        (WebCore::ResourceResponse::platformLazyInit):
+        * platform/network/mac/ResourceResponseMac.mm:
+        (WebCore::ResourceResponse::initNSURLResponse):
+
+            Synthesize HTTP response properly so it can hold Content-Disposition for file name (and other headers).
+
+        (WebCore::ResourceResponse::platformLazyInit):
+
+            Don't pull the suggested filename anymore.
+
+        (WebCore::ResourceResponse::platformSuggestedFilename):
+
+            Get the suggested name from the (possibly synthetic) NSURLRequest.
+
 2014-09-04  Eva Balazsfalvi  <evab.u-szeged@partner.samsung.com>
 
         Remove CSS_FILTERS flag
index 330a6b4..3a55421 100644 (file)
@@ -878,7 +878,6 @@ __ZN7WebCore20ResourceResponseBase17setHTTPStatusCodeEi
 __ZN7WebCore20ResourceResponseBase17setHTTPStatusTextERKN3WTF6StringE
 __ZN7WebCore20ResourceResponseBase18setHTTPHeaderFieldERKN3WTF6StringES4_
 __ZN7WebCore20ResourceResponseBase19setTextEncodingNameERKN3WTF6StringE
-__ZN7WebCore20ResourceResponseBase20setSuggestedFilenameERKN3WTF6StringE
 __ZN7WebCore20ResourceResponseBase24setExpectedContentLengthEx
 __ZN7WebCore20ResourceResponseBase6setURLERKNS_3URLE
 __ZN7WebCore20ResourceResponseBaseC2Ev
index ac124ab..9c2363e 100644 (file)
@@ -472,7 +472,7 @@ void DocumentLoader::handleSubstituteDataLoadNow(DocumentLoaderTimer*)
     URL url = m_substituteData.responseURL();
     if (url.isEmpty())
         url = m_request.url();
-    ResourceResponse response(url, m_substituteData.mimeType(), m_substituteData.content()->size(), m_substituteData.textEncoding(), "");
+    ResourceResponse response(url, m_substituteData.mimeType(), m_substituteData.content()->size(), m_substituteData.textEncoding());
     responseReceived(0, response);
 }
 
@@ -1385,7 +1385,7 @@ bool DocumentLoader::maybeLoadEmpty()
     if (m_request.url().isEmpty() && !frameLoader()->stateMachine().creatingInitialEmptyDocument())
         m_request.setURL(blankURL());
     String mimeType = shouldLoadEmpty ? "text/html" : frameLoader()->client().generatedMIMETypeForURLScheme(m_request.url().protocol());
-    m_response = ResourceResponse(m_request.url(), mimeType, 0, String(), String());
+    m_response = ResourceResponse(m_request.url(), mimeType, 0, String());
     finishedLoading(monotonicallyIncreasingTime());
     return true;
 }
index 77e8e0a..06305d7 100644 (file)
@@ -1513,7 +1513,7 @@ bool FrameLoader::willLoadMediaElementURL(URL& url)
     unsigned long identifier;
     ResourceError error;
     requestFromDelegate(request, identifier, error);
-    notifier().sendRemainingDelegateMessages(m_documentLoader.get(), identifier, request, ResourceResponse(url, String(), -1, String(), String()), 0, -1, -1, error);
+    notifier().sendRemainingDelegateMessages(m_documentLoader.get(), identifier, request, ResourceResponse(url, String(), -1, String()), 0, -1, -1, error);
 
     url = request.url();
 
index 4e71c2e..0358f3d 100644 (file)
@@ -1159,7 +1159,7 @@ PassRefPtr<ApplicationCache> ApplicationCacheStorage::loadCache(unsigned storage
         String mimeType = cacheStatement.getColumnText(3);
         String textEncodingName = cacheStatement.getColumnText(4);
         
-        ResourceResponse response(url, mimeType, size, textEncodingName, "");
+        ResourceResponse response(url, mimeType, size, textEncodingName);
         response.setHTTPStatusCode(httpStatusCode);
 
         String headers = cacheStatement.getColumnText(5);
index 3d5c62c..4b05fdc 100644 (file)
@@ -49,7 +49,7 @@ PassRefPtr<ArchiveResource> ArchiveResource::create(PassRefPtr<SharedBuffer> dat
     if (response.isNull()) {
         unsigned dataSize = data->size();
         return adoptRef(new ArchiveResource(data, url, mimeType, textEncoding, frameName,
-            ResourceResponse(url, mimeType, dataSize, textEncoding, String())));
+            ResourceResponse(url, mimeType, dataSize, textEncoding)));
     }
     return adoptRef(new ArchiveResource(data, url, mimeType, textEncoding, frameName, response));
 }
index 4305e9e..a0fe37d 100644 (file)
@@ -596,7 +596,7 @@ void BlobResourceHandle::notifyResponseOnSuccess()
     ASSERT(isMainThread());
 
     bool isRangeRequest = m_rangeOffset != positionNotSpecified;
-    ResourceResponse response(firstRequest().url(), m_blobData->contentType(), m_totalRemainingSize, String(), String());
+    ResourceResponse response(firstRequest().url(), m_blobData->contentType(), m_totalRemainingSize, String());
     response.setExpectedContentLength(m_totalRemainingSize);
     response.setHTTPStatusCode(isRangeRequest ? httpPartialContent : httpOK);
     response.setHTTPStatusText(isRangeRequest ? httpPartialContentText : httpOKText);
@@ -617,7 +617,7 @@ void BlobResourceHandle::notifyResponseOnError()
 {
     ASSERT(m_errorCode);
 
-    ResourceResponse response(firstRequest().url(), "text/plain", 0, String(), String());
+    ResourceResponse response(firstRequest().url(), "text/plain", 0, String());
     switch (m_errorCode) {
     case rangeError:
         response.setHTTPStatusCode(httpRequestedRangeNotSatisfiable);
index 79d4d76..d20aafc 100644 (file)
@@ -67,12 +67,11 @@ ResourceResponseBase::ResourceResponseBase()
 {
 }
 
-ResourceResponseBase::ResourceResponseBase(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename)
+ResourceResponseBase::ResourceResponseBase(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName)
     : m_url(url)
     , m_mimeType(mimeType)
     , m_expectedContentLength(expectedLength)
     , m_textEncodingName(textEncodingName)
-    , m_suggestedFilename(filename)
     , m_httpStatusCode(0)
     , m_connectionID(0)
     , m_cacheControlMaxAge(0)
@@ -101,12 +100,11 @@ PassOwnPtr<ResourceResponse> ResourceResponseBase::adopt(PassOwnPtr<CrossThreadR
     response->setMimeType(data->m_mimeType);
     response->setExpectedContentLength(data->m_expectedContentLength);
     response->setTextEncodingName(data->m_textEncodingName);
-    response->setSuggestedFilename(data->m_suggestedFilename);
 
     response->setHTTPStatusCode(data->m_httpStatusCode);
     response->setHTTPStatusText(data->m_httpStatusText);
 
-    response->lazyInit(CommonAndUncommonFields);
+    response->lazyInit(AllFields);
     response->m_httpHeaderFields.adopt(WTF::move(data->m_httpHeaders));
     response->m_resourceLoadTiming = data->m_resourceLoadTiming;
     response->doPlatformAdopt(data);
@@ -120,7 +118,6 @@ PassOwnPtr<CrossThreadResourceResponseData> ResourceResponseBase::copyData() con
     data->m_mimeType = mimeType().isolatedCopy();
     data->m_expectedContentLength = expectedContentLength();
     data->m_textEncodingName = textEncodingName().isolatedCopy();
-    data->m_suggestedFilename = suggestedFilename().isolatedCopy();
     data->m_httpStatusCode = httpStatusCode();
     data->m_httpStatusText = httpStatusText().isolatedCopy();
     data->m_httpHeaders = httpHeaderFields().copyData();
@@ -209,22 +206,9 @@ void ResourceResponseBase::setTextEncodingName(const String& encodingName)
 }
 
 // FIXME should compute this on the fly
-const String& ResourceResponseBase::suggestedFilename() const
+String ResourceResponseBase::suggestedFilename() const
 {
-    lazyInit(AllFields);
-
-    return m_suggestedFilename;
-}
-
-void ResourceResponseBase::setSuggestedFilename(const String& suggestedName)
-{
-    lazyInit(AllFields);
-    m_isNull = false;
-
-    // FIXME: Suggested file name is calculated based on other headers. There should not be a setter for it.
-    m_suggestedFilename = suggestedName; 
-
-    // FIXME: Should invalidate or update platform response if present.
+    return static_cast<const ResourceResponse*>(this)->platformSuggestedFilename();
 }
 
 int ResourceResponseBase::httpStatusCode() const
@@ -245,14 +229,14 @@ void ResourceResponseBase::setHTTPStatusCode(int statusCode)
 
 const String& ResourceResponseBase::httpStatusText() const 
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     return m_httpStatusText; 
 }
 
 void ResourceResponseBase::setHTTPStatusText(const String& statusText) 
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     m_httpStatusText = statusText; 
 
@@ -268,7 +252,7 @@ String ResourceResponseBase::httpHeaderField(const String& name) const
     if (!value.isEmpty())        
         return value;
 
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     return m_httpHeaderFields.get(name); 
 }
@@ -282,7 +266,7 @@ String ResourceResponseBase::httpHeaderField(HTTPHeaderName name) const
     if (!value.isEmpty())
         return value;
 
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     return m_httpHeaderFields.get(name); 
 }
@@ -318,7 +302,7 @@ void ResourceResponseBase::updateHeaderParsedState(HTTPHeaderName name)
 
 void ResourceResponseBase::setHTTPHeaderField(const String& name, const String& value)
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     HTTPHeaderName headerName;
     if (findHTTPHeaderName(name, headerName))
@@ -331,7 +315,7 @@ void ResourceResponseBase::setHTTPHeaderField(const String& name, const String&
 
 void ResourceResponseBase::setHTTPHeaderField(HTTPHeaderName name, const String& value)
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     updateHeaderParsedState(name);
 
@@ -342,7 +326,7 @@ void ResourceResponseBase::setHTTPHeaderField(HTTPHeaderName name, const String&
 
 void ResourceResponseBase::addHTTPHeaderField(const String& name, const String& value)
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     HTTPHeaderName headerName;
     if (findHTTPHeaderName(name, headerName))
@@ -353,7 +337,7 @@ void ResourceResponseBase::addHTTPHeaderField(const String& name, const String&
 
 const HTTPHeaderMap& ResourceResponseBase::httpHeaderFields() const
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     return m_httpHeaderFields;
 }
@@ -508,7 +492,7 @@ double ResourceResponseBase::lastModified() const
 
 bool ResourceResponseBase::isAttachment() const
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     String value = m_httpHeaderFields.get(HTTPHeaderName::ContentDisposition);
     size_t loc = value.find(';');
@@ -521,7 +505,7 @@ bool ResourceResponseBase::isAttachment() const
   
 bool ResourceResponseBase::wasCached() const
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     return m_wasCached;
 }
@@ -533,28 +517,28 @@ void ResourceResponseBase::setWasCached(bool value)
 
 bool ResourceResponseBase::connectionReused() const
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     return m_connectionReused;
 }
 
 void ResourceResponseBase::setConnectionReused(bool connectionReused)
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     m_connectionReused = connectionReused;
 }
 
 unsigned ResourceResponseBase::connectionID() const
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     return m_connectionID;
 }
 
 void ResourceResponseBase::setConnectionID(unsigned connectionID)
 {
-    lazyInit(CommonAndUncommonFields);
+    lazyInit(AllFields);
 
     m_connectionID = connectionID;
 }
index 4f4a211..3aa4591 100644 (file)
@@ -67,11 +67,6 @@ public:
     WEBCORE_EXPORT const String& textEncodingName() const;
     WEBCORE_EXPORT void setTextEncodingName(const String& name);
 
-    // FIXME: Should compute this on the fly.
-    // There should not be a setter exposed, as suggested file name is determined based on other headers in a manner that WebCore does not necessarily know about.
-    WEBCORE_EXPORT const String& suggestedFilename() const;
-    WEBCORE_EXPORT void setSuggestedFilename(const String&);
-
     WEBCORE_EXPORT int httpStatusCode() const;
     WEBCORE_EXPORT void setHTTPStatusCode(int);
     
@@ -95,6 +90,7 @@ public:
     bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
 
     WEBCORE_EXPORT bool isAttachment() const;
+    WEBCORE_EXPORT String suggestedFilename() const;
     
     // These functions return parsed values of the corresponding response headers.
     // NaN means that the header was not present or had invalid value.
@@ -132,17 +128,17 @@ protected:
     enum InitLevel {
         Uninitialized,
         CommonFieldsOnly,
-        CommonAndUncommonFields,
         AllFields
     };
 
     WEBCORE_EXPORT ResourceResponseBase();
-    ResourceResponseBase(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename);
+    ResourceResponseBase(const URL&, const String& mimeType, long long expectedLength, const String& textEncodingName);
 
     void lazyInit(InitLevel) const;
 
     // The ResourceResponse subclass may "shadow" this method to lazily initialize platform specific fields
     void platformLazyInit(InitLevel) { }
+    String platformSuggestedFileName() { return String(); }
 
     // The ResourceResponse subclass may "shadow" this method to compare platform specific fields
     static bool platformCompare(const ResourceResponse&, const ResourceResponse&) { return true; }
@@ -151,7 +147,6 @@ protected:
     AtomicString m_mimeType;
     long long m_expectedContentLength;
     AtomicString m_textEncodingName;
-    String m_suggestedFilename;
     AtomicString m_httpStatusText;
     HTTPHeaderMap m_httpHeaderFields;
     mutable ResourceLoadTiming m_resourceLoadTiming;
@@ -199,7 +194,6 @@ public:
     String m_mimeType;
     long long m_expectedContentLength;
     String m_textEncodingName;
-    String m_suggestedFilename;
     int m_httpStatusCode;
     String m_httpStatusText;
     std::unique_ptr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
index 776398c..10d09ea 100644 (file)
@@ -40,7 +40,7 @@ namespace WebCore {
 class ResourceResponse : public ResourceResponseBase {
 public:
     ResourceResponse()
-        : m_initLevel(CommonAndUncommonFields)
+        : m_initLevel(AllFields)
         , m_platformResponseIsUpToDate(true)
     {
     }
@@ -66,9 +66,9 @@ public:
     }
 #endif
 
-    ResourceResponse(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename)
-        : ResourceResponseBase(url, mimeType, expectedLength, textEncodingName, filename)
-        , m_initLevel(CommonAndUncommonFields)
+    ResourceResponse(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName)
+        : ResourceResponseBase(url, mimeType, expectedLength, textEncodingName)
+        , m_initLevel(AllFields)
         , m_platformResponseIsUpToDate(false)
     {
     }
@@ -103,6 +103,7 @@ private:
     friend class ResourceResponseBase;
 
     void platformLazyInit(InitLevel);
+    String platformSuggestedFilename() const;
     PassOwnPtr<CrossThreadResourceResponseData> doPlatformCopyData(PassOwnPtr<CrossThreadResourceResponseData> data) const { return data; }
     void doPlatformAdopt(PassOwnPtr<CrossThreadResourceResponseData>) { }
 #if PLATFORM(COCOA)
index f0ad7ef..c18fd2a 100644 (file)
@@ -92,7 +92,7 @@ void ResourceResponse::platformLazyInit(InitLevel initLevel)
             m_httpStatusCode = 0;
     }
 
-    if (m_initLevel < CommonAndUncommonFields && initLevel >= CommonAndUncommonFields) {
+    if (m_initLevel < AllFields) {
         CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(m_cfResponse.get());
         if (httpResponse) {
             RetainPtr<CFStringRef> statusLine = adoptCF(CFHTTPMessageCopyResponseStatusLine(httpResponse));
@@ -107,15 +107,16 @@ void ResourceResponse::platformLazyInit(InitLevel initLevel)
                 m_httpHeaderFields.set((CFStringRef)keys[i], (CFStringRef)values[i]);
         }
     }
-    
-    if (m_initLevel < AllFields && initLevel >= AllFields) {
-        RetainPtr<CFStringRef> suggestedFilename = adoptCF(CFURLResponseCopySuggestedFilename(m_cfResponse.get()));
-        m_suggestedFilename = suggestedFilename.get();
-    }
 
     m_initLevel = initLevel;
 }
-    
+
+String ResourceResponse::platformSuggestedFilename() const
+{
+    RetainPtr<CFStringRef> suggestedFilename = adoptCF(CFURLResponseCopySuggestedFilename(m_cfResponse.get()));
+    return suggestedFilename.get();
+}
+
 bool ResourceResponse::platformCompare(const ResourceResponse& a, const ResourceResponse& b)
 {
     // CFEqual crashes if you pass it 0 so do an early check before calling it.
index 3d87376..aa465dd 100644 (file)
@@ -45,18 +45,24 @@ namespace WebCore {
 
 void ResourceResponse::initNSURLResponse() const
 {
-    // Work around a mistake in the NSURLResponse class - <rdar://problem/6875219>.
-    // The init function takes an NSInteger, even though the accessor returns a long long.
-    // For values that won't fit in an NSInteger, pass -1 instead.
-    NSInteger expectedContentLength;
-    if (m_expectedContentLength < 0 || m_expectedContentLength > std::numeric_limits<NSInteger>::max())
-        expectedContentLength = -1;
-    else
-        expectedContentLength = static_cast<NSInteger>(m_expectedContentLength);
-
-    // FIXME: This creates a very incomplete NSURLResponse, which does not even have a status code.
-
-    m_nsResponse = adoptNS([[NSURLResponse alloc] initWithURL:m_url MIMEType:m_mimeType expectedContentLength:expectedContentLength textEncodingName:m_textEncodingName]);
+    if (!m_httpStatusCode) {
+        // Work around a mistake in the NSURLResponse class - <rdar://problem/6875219>.
+        // The init function takes an NSInteger, even though the accessor returns a long long.
+        // For values that won't fit in an NSInteger, pass -1 instead.
+        NSInteger expectedContentLength;
+        if (m_expectedContentLength < 0 || m_expectedContentLength > std::numeric_limits<NSInteger>::max())
+            expectedContentLength = -1;
+        else
+            expectedContentLength = static_cast<NSInteger>(m_expectedContentLength);
+
+        m_nsResponse = adoptNS([[NSURLResponse alloc] initWithURL:m_url MIMEType:m_mimeType expectedContentLength:-1 textEncodingName:m_textEncodingName]);
+        return;
+    }
+    NSMutableDictionary* headerDictionary = [NSMutableDictionary dictionary];
+    for (auto& header : m_httpHeaderFields)
+        [headerDictionary setObject:(NSString *)header.value forKey:(NSString *)header.key];
+
+    m_nsResponse = adoptNS([[NSHTTPURLResponse alloc] initWithURL:m_url statusCode:m_httpStatusCode HTTPVersion:(NSString*)kCFHTTPVersion1_1 headerFields:headerDictionary]);
 }
 
 #if USE(CFNETWORK)
@@ -139,7 +145,7 @@ void ResourceResponse::platformLazyInit(InitLevel initLevel)
         [pool drain];
     }
 
-    if (m_initLevel < CommonAndUncommonFields && initLevel >= CommonAndUncommonFields) {
+    if (m_initLevel < AllFields) {
         if ([m_nsResponse.get() isKindOfClass:[NSHTTPURLResponse class]]) {
             NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
 
@@ -159,14 +165,15 @@ void ResourceResponse::platformLazyInit(InitLevel initLevel)
             [pool drain];
         }
     }
-     
-    if (m_initLevel < AllFields && initLevel >= AllFields)
-        m_suggestedFilename = [m_nsResponse.get() suggestedFilename];
 
     m_initLevel = initLevel;
 }
 
-    
+String ResourceResponse::platformSuggestedFilename() const
+{
+    return [nsURLResponse() suggestedFilename];
+}
+
 bool ResourceResponse::platformCompare(const ResourceResponse& a, const ResourceResponse& b)
 {
     return a.nsURLResponse() == b.nsURLResponse();
index 95fdec5..3000c9c 100644 (file)
@@ -389,7 +389,7 @@ void PluginStream::deliverData()
 
 void PluginStream::sendJavaScriptStream(const URL& requestURL, const CString& resultString)
 {
-    didReceiveResponse(0, ResourceResponse(requestURL, "text/plain", resultString.length(), "", ""));
+    didReceiveResponse(0, ResourceResponse(requestURL, "text/plain", resultString.length(), ""));
 
     if (m_streamState == StreamStopped)
         return;
index 13a95f4..2c17a60 100644 (file)
@@ -1,3 +1,21 @@
+2014-09-04  Antti Koivisto  <antti@apple.com>
+
+        Remove ResourceResponse::m_suggestedFilename
+        https://bugs.webkit.org/show_bug.cgi?id=136534
+
+        Reviewed by Alexey Proskuryakov.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<ResourceResponse>::encode):
+        (IPC::ArgumentCoder<ResourceResponse>::decode):
+
+            No more m_suggestedFilename.
+
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::addArchiveResource):
+
+            Fake the suggested filename by using the Content-Disposition header.
+
 2014-09-04  Eva Balazsfalvi  <evab.u-szeged@partner.samsung.com>
 
         Remove CSS_FILTERS flag
index ba73ab3..816671e 100644 (file)
@@ -699,7 +699,6 @@ void ArgumentCoder<ResourceResponse>::encode(ArgumentEncoder& encoder, const Res
         encoder << resourceResponse.textEncodingName();
         encoder << static_cast<int64_t>(resourceResponse.expectedContentLength());
         encoder << resourceResponse.httpStatusText();
-        encoder << resourceResponse.suggestedFilename();
     }
     
 #if ENABLE(WEB_TIMING)
@@ -773,11 +772,6 @@ bool ArgumentCoder<ResourceResponse>::decode(ArgumentDecoder& decoder, ResourceR
         if (!decoder.decode(httpStatusText))
             return false;
         response.setHTTPStatusText(httpStatusText);
-
-        String suggestedFilename;
-        if (!decoder.decode(suggestedFilename))
-            return false;
-        response.setSuggestedFilename(suggestedFilename);
     }
     
 #if ENABLE(WEB_TIMING)
index d294c8b..77b71ca 100644 (file)
@@ -809,10 +809,9 @@ void PDFPlugin::addArchiveResource()
     // FIXME: It's a hack to force add a resource to DocumentLoader. PDF documents should just be fetched as CachedResources.
 
     // Add just enough data for context menu handling and web archives to work.
-    ResourceResponse synthesizedResponse;
-    synthesizedResponse.setSuggestedFilename(m_suggestedFilename);
-    synthesizedResponse.setURL(m_sourceURL); // Needs to match the HitTestResult::absolutePDFURL.
-    synthesizedResponse.setMimeType("application/pdf");
+    NSDictionary* headers = @{ @"Content-Disposition": (NSString *)m_suggestedFilename, @"Content-Type" : @"application/pdf" };
+    RetainPtr<NSURLResponse> response = adoptNS([[NSHTTPURLResponse alloc] initWithURL:m_sourceURL statusCode:200 HTTPVersion:(NSString*)kCFHTTPVersion1_1 headerFields:headers]);
+    ResourceResponse synthesizedResponse(response.get());
 
     RefPtr<ArchiveResource> resource = ArchiveResource::create(SharedBuffer::wrapCFData(m_data.get()), m_sourceURL, "application/pdf", String(), String(), synthesizedResponse);
     pluginView()->frame()->document()->loader()->addArchiveResource(resource.release());