2011-05-04 Anders Carlsson <andersca@apple.com>
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 May 2011 20:33:52 +0000 (20:33 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 May 2011 20:33:52 +0000 (20:33 +0000)
        Reviewed by Dan Bernstein.

        Can't save a link from "Save Linked File to Download" popup menu
        https://bugs.webkit.org/show_bug.cgi?id=60190
        <rdar://problem/9367927>

        Make sure that suggestedFilenameForResourceWithURL and resourceDataForFrame both look
        in the cache if the resource can't be found in the current web page. This matches WebKit1.

        * WebProcess/WebPage/WebFrame.cpp:
        (WebKit::WebFrame::suggestedFilenameForResourceWithURL):
        Call WebPage::cachedSuggestedFilenameForURL if we can't find a resource in the page.

        * WebProcess/WebPage/WebPage.cpp:
        (WebKit::resourceDataForFrame):
        Move code out from getResourceDataFromFrame.

        (WebKit::WebPage::getResourceDataFromFrame):
        Call resourceDataForFrame first and then cachedResponseDataForURL.

        * WebProcess/WebPage/WebPage.h:
        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
        (WebKit::WebPage::platformHasLocalDataForURL):
        (WebKit::WebPage::cachedResponseMIMETypeForURL):
        (WebKit::WebPage::platformCanHandleRequest):
        (WebKit::WebPage::cachedSuggestedFilenameForURL):
        (WebKit::WebPage::cachedResponseDataForURL):
        Add stubs.

        * WebProcess/WebPage/mac/WebPageMac.mm:
        (WebKit::cachedResponseForURL):
        Add helper function.

        (WebKit::WebPage::cachedSuggestedFilenameForURL):
        (WebKit::WebPage::cachedResponseMIMETypeForURL):
        (WebKit::WebPage::cachedResponseDataForURL):
        Call helper function.

        * WebProcess/WebPage/qt/WebPageQt.cpp:
        (WebKit::WebPage::platformHasLocalDataForURL):
        (WebKit::WebPage::cachedResponseMIMETypeForURL):
        (WebKit::WebPage::platformCanHandleRequest):
        (WebKit::WebPage::cachedSuggestedFilenameForURL):
        (WebKit::WebPage::cachedResponseDataForURL):
        Add stubs.

        * WebProcess/WebPage/win/WebPageWin.cpp:
        (WebKit::cachedResponseForURL):
        Add helper function.

        (WebKit::WebPage::platformHasLocalDataForURL):
        (WebKit::WebPage::cachedResponseMIMETypeForURL):
        (WebKit::WebPage::cachedSuggestedFilenameForURL):
        (WebKit::WebPage::cachedResponseDataForURL):
        Call helper function.

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/WebFrame.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
Source/WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp
Source/WebKit2/WebProcess/WebPage/win/WebPageWin.cpp

index 2a24950..aa162bb 100644 (file)
@@ -1,3 +1,61 @@
+2011-05-04  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        Can't save a link from "Save Linked File to Download" popup menu
+        https://bugs.webkit.org/show_bug.cgi?id=60190
+        <rdar://problem/9367927>
+
+        Make sure that suggestedFilenameForResourceWithURL and resourceDataForFrame both look
+        in the cache if the resource can't be found in the current web page. This matches WebKit1.
+
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::suggestedFilenameForResourceWithURL):
+        Call WebPage::cachedSuggestedFilenameForURL if we can't find a resource in the page.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::resourceDataForFrame):
+        Move code out from getResourceDataFromFrame.
+
+        (WebKit::WebPage::getResourceDataFromFrame):
+        Call resourceDataForFrame first and then cachedResponseDataForURL.
+
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
+        (WebKit::WebPage::platformHasLocalDataForURL):
+        (WebKit::WebPage::cachedResponseMIMETypeForURL):
+        (WebKit::WebPage::platformCanHandleRequest):
+        (WebKit::WebPage::cachedSuggestedFilenameForURL):
+        (WebKit::WebPage::cachedResponseDataForURL):
+        Add stubs.
+
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::cachedResponseForURL):
+        Add helper function.
+
+        (WebKit::WebPage::cachedSuggestedFilenameForURL):
+        (WebKit::WebPage::cachedResponseMIMETypeForURL):
+        (WebKit::WebPage::cachedResponseDataForURL):
+        Call helper function.
+
+        * WebProcess/WebPage/qt/WebPageQt.cpp:
+        (WebKit::WebPage::platformHasLocalDataForURL):
+        (WebKit::WebPage::cachedResponseMIMETypeForURL):
+        (WebKit::WebPage::platformCanHandleRequest):
+        (WebKit::WebPage::cachedSuggestedFilenameForURL):
+        (WebKit::WebPage::cachedResponseDataForURL):
+        Add stubs.
+        
+        * WebProcess/WebPage/win/WebPageWin.cpp:
+        (WebKit::cachedResponseForURL):
+        Add helper function.
+
+        (WebKit::WebPage::platformHasLocalDataForURL):
+        (WebKit::WebPage::cachedResponseMIMETypeForURL):
+        (WebKit::WebPage::cachedSuggestedFilenameForURL):
+        (WebKit::WebPage::cachedResponseDataForURL):
+        Call helper function.
+
 2011-05-04  Simon Fraser  <simon.fraser@apple.com>
 
         Reviewed by Anders Carlsson.
index 11b9f0b..7f06fd1 100644 (file)
@@ -640,10 +640,10 @@ String WebFrame::suggestedFilenameForResourceWithURL(const KURL& url) const
 
     // Next, try subresources.
     RefPtr<ArchiveResource> resource = loader->subresource(url);
-    if (!resource)
-        return String();
-    
-    return resource->response().suggestedFilename();
+    if (resource)
+        return resource->response().suggestedFilename();
+
+    return page()->cachedSuggestedFilenameForURL(url);
 }
 
 String WebFrame::mimeTypeForResourceWithURL(const KURL& url) const
index 324272c..ded4313 100644 (file)
@@ -1386,18 +1386,34 @@ void WebPage::getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID)
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
 }
 
-void WebPage::getResourceDataFromFrame(uint64_t frameID, const String& resourceURL, uint64_t callbackID)
+static PassRefPtr<SharedBuffer> resourceDataForFrame(Frame* frame, const KURL& resourceURL)
+{
+    DocumentLoader* loader = frame->loader()->documentLoader();
+    if (!loader)
+        return 0;
+
+    RefPtr<ArchiveResource> subresource = loader->subresource(resourceURL);
+    if (!subresource)
+        return 0;
+
+    return subresource->data();
+}
+
+void WebPage::getResourceDataFromFrame(uint64_t frameID, const String& resourceURLString, uint64_t callbackID)
 {
     CoreIPC::DataReference dataReference;
+    KURL resourceURL(KURL(), resourceURLString);
 
     RefPtr<SharedBuffer> buffer;
     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
-        if (DocumentLoader* loader = frame->coreFrame()->loader()->documentLoader()) {
-            if (RefPtr<ArchiveResource> subresource = loader->subresource(KURL(KURL(), resourceURL))) {
-                if ((buffer = subresource->data()))
-                    dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
-            }
+        buffer = resourceDataForFrame(frame->coreFrame(), resourceURL);
+        if (!buffer) {
+            // Try to get the resource data from the cache.
+            buffer = cachedResponseDataForURL(resourceURL);
         }
+
+        if (buffer)
+            dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
     }
 
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
index 1c48057..67fc37d 100644 (file)
@@ -291,7 +291,9 @@ public:
     
     bool hasLocalDataForURL(const WebCore::KURL&);
     String cachedResponseMIMETypeForURL(const WebCore::KURL&);
-    
+    String cachedSuggestedFilenameForURL(const WebCore::KURL&);
+    PassRefPtr<WebCore::SharedBuffer> cachedResponseDataForURL(const WebCore::KURL&);
+
     static bool canHandleRequest(const WebCore::ResourceRequest&);
 
     class SandboxExtensionTracker {
index 57c9977..a25e1f7 100644 (file)
@@ -103,23 +103,34 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
     return true;
 }
 
-bool WebPage::platformHasLocalDataForURL(const WebCore::KURL&)
+bool WebPage::platformHasLocalDataForURL(const KURL&)
 {
-    // FIXME: Implement
     notImplemented();
     return false;
 }
 
-String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL&)
+String WebPage::cachedResponseMIMETypeForURL(const KURL&)
 {
-    // FIXME: Implement
+    notImplemented();
     return String();
 }
 
-bool WebPage::platformCanHandleRequest(const WebCore::ResourceRequest&)
+bool WebPage::platformCanHandleRequest(const ResourceRequest&)
 {
-    // FIXME: Implement
+    notImplemented();
     return true;
 }
 
+String WebPage::cachedSuggestedFilenameForURL(const KURL&)
+{
+    notImplemented();
+    return String();
+}
+
+PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL&)
+{
+    notImplemented();
+    return 0;
+}
+
 } // namespace WebKit
index 23bdc10..59b4e7e 100644 (file)
@@ -633,20 +633,32 @@ bool WebPage::platformHasLocalDataForURL(const WebCore::KURL& url)
     return cachedResponse;
 }
 
-String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL& url)
+static NSCachedURLResponse *cachedResponseForURL(WebPage* webPage, const KURL& url)
 {
-    NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
-    [request setValue:(NSString*)userAgent() forHTTPHeaderField:@"User-Agent"];
-    NSCachedURLResponse *cachedResponse;
+    RetainPtr<NSMutableURLRequest> request(AdoptNS, [[NSMutableURLRequest alloc] initWithURL:url]);
+    [request.get() setValue:(NSString *)webPage->userAgent() forHTTPHeaderField:@"User-Agent"];
+
 #if USE(CFURLSTORAGESESSIONS)
     if (CFURLStorageSessionRef storageSession = ResourceHandle::privateBrowsingStorageSession())
-        cachedResponse = WKCachedResponseForRequest(storageSession, request);
-    else
+        return WKCachedResponseForRequest(storageSession, request.get());
 #endif
-        cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
-    [request release];
-    
-    return [[cachedResponse response] MIMEType];
+
+    return [[NSURLCache sharedURLCache] cachedResponseForRequest:request.get()];
+}
+
+String WebPage::cachedSuggestedFilenameForURL(const KURL& url)
+{
+    return [[cachedResponseForURL(this, url) response] suggestedFilename];
+}
+
+String WebPage::cachedResponseMIMETypeForURL(const KURL& url)
+{
+    return [[cachedResponseForURL(this, url) response] MIMEType];
+}
+
+PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL& url)
+{
+    return SharedBuffer::wrapNSData([cachedResponseForURL(this, url) data]);
 }
 
 bool WebPage::platformCanHandleRequest(const WebCore::ResourceRequest& request)
index de8385c..c80cea0 100644 (file)
@@ -27,6 +27,7 @@
 #include "config.h"
 #include "WebPage.h"
 
+#include "NotImplemented.h"
 #include "WebEvent.h"
 #include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
@@ -265,22 +266,34 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
     return true;
 }
 
-bool WebPage::platformHasLocalDataForURL(const WebCore::KURL&)
+bool WebPage::platformHasLocalDataForURL(const KURL&)
 {
-    // FIXME: Implement
+    notImplemented();
     return false;
 }
 
-String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL&)
+String WebPage::cachedResponseMIMETypeForURL(const KURL&)
 {
-    // FIXME: Implement
+    notImplemented();
     return String();
 }
 
-bool WebPage::platformCanHandleRequest(const WebCore::ResourceRequest&)
+bool WebPage::platformCanHandleRequest(const ResourceRequest&)
 {
-    // FIXME: Implement
+    notImplemented();
     return true;
 }
 
+String WebPage::cachedSuggestedFilenameForURL(const KURL&)
+{
+    notImplemented();
+    return String();
+}
+
+PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL&)
+{
+    notImplemented();
+    return 0;
+}
+
 } // namespace WebKit
index 9c7206a..65514bc 100644 (file)
@@ -260,13 +260,13 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
     return true;
 }
 
-bool WebPage::platformHasLocalDataForURL(const WebCore::KURL& url)
-{
 #if USE(CFNETWORK)
+static RetainPtr<CFCachedURLResponseRef> cachedResponseForURL(WebPage* webPage, const KURL& url)
+{
     RetainPtr<CFURLRef> cfURL(AdoptCF, url.createCFURL());
     RetainPtr<CFMutableURLRequestRef> request(AdoptCF, CFURLRequestCreateMutable(0, cfURL.get(), kCFURLRequestCachePolicyReloadIgnoringCache, 60, 0));
-    
-    RetainPtr<CFStringRef> userAgent(AdoptCF, userAgent().createCFString());
+
+    RetainPtr<CFStringRef> userAgent(AdoptCF, webPage->userAgent().createCFString());
     CFURLRequestSetHTTPHeaderFieldValue(request.get(), CFSTR("User-Agent"), userAgent.get());
 
     RetainPtr<CFURLCacheRef> cache;
@@ -277,40 +277,56 @@ bool WebPage::platformHasLocalDataForURL(const WebCore::KURL& url)
 #endif
         cache.adoptCF(CFURLCacheCopySharedURLCache());
 
-    RetainPtr<CFCachedURLResponseRef> response(AdoptCF, CFURLCacheCopyResponseForRequest(cache.get(), request.get()));    
-    return response;
+    RetainPtr<CFCachedURLResponseRef> response(AdoptCF, CFURLCacheCopyResponseForRequest(cache.get(), request.get()));
+    return response;        
+}
+#endif
+
+bool WebPage::platformHasLocalDataForURL(const KURL& url)
+{
+#if USE(CFNETWORK)
+    return cachedResponseForURL(this, url);
 #else
     return false;
 #endif
 }
 
-String WebPage::cachedResponseMIMETypeForURL(const WebCore::KURL& url)
+String WebPage::cachedResponseMIMETypeForURL(const KURL& url)
 {
 #if USE(CFNETWORK)
-    RetainPtr<CFURLRef> cfURL(AdoptCF, url.createCFURL());
-    RetainPtr<CFMutableURLRequestRef> request(AdoptCF, CFURLRequestCreateMutable(0, cfURL.get(), kCFURLRequestCachePolicyReloadIgnoringCache, 60, 0));
-    
-    RetainPtr<CFStringRef> userAgent(AdoptCF, userAgent().createCFString());
-    CFURLRequestSetHTTPHeaderFieldValue(request.get(), CFSTR("User-Agent"), userAgent.get());
-
-    RetainPtr<CFURLCacheRef> cache;
-#if USE(CFURLSTORAGESESSIONS)
-    if (CFURLStorageSessionRef storageSession = ResourceHandle::privateBrowsingStorageSession())
-        cache.adoptCF(wkCopyURLCache(storageSession));
-    else
+    RetainPtr<CFCachedURLResponseRef> cachedResponse = cachedResponseForURL(this, url);
+    CFURLResponseRef response = CFCachedURLResponseGetWrappedResponse(cachedResponse.get());
+    return response ? CFURLResponseGetMIMEType(response) : String();
+#else
+    return String();
 #endif
-        cache.adoptCF(CFURLCacheCopySharedURLCache());
+}
 
-    RetainPtr<CFCachedURLResponseRef> cachedResponse(AdoptCF, CFURLCacheCopyResponseForRequest(cache.get(), request.get()));
-    
+String WebPage::cachedSuggestedFilenameForURL(const KURL& url)
+{
+#if USE(CFNETWORK)
+    RetainPtr<CFCachedURLResponseRef> cachedResponse = cachedResponseForURL(this, url);
     CFURLResponseRef response = CFCachedURLResponseGetWrappedResponse(cachedResponse.get());
-    
-    return response ? CFURLResponseGetMIMEType(response) : String();
+    if (!response)
+        return String();
+    RetainPtr<CFStringRef> suggestedFilename(AdoptCF, CFURLResponseCopySuggestedFilename(response));
+
+    return suggestedFilename.get();
 #else
     return String();
 #endif
 }
 
+PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL& url)
+{
+    RetainPtr<CFCachedURLResponseRef> cachedResponse = cachedResponseForURL(this, url);
+    CFDataRef data = CFCachedURLResponseGetReceiverData(cachedResponse.get());
+    if (!data)
+        return 0;
+
+    return SharedBuffer::wrapCFData(data);
+}
+
 bool WebPage::platformCanHandleRequest(const WebCore::ResourceRequest& request)
 {
 #if USE(CFNETWORK)