Title: [101486] trunk/Source
Revision
101486
Author
[email protected]
Date
2011-11-30 04:13:31 -0800 (Wed, 30 Nov 2011)

Log Message

Download page URL should be set by WebCore
https://bugs.webkit.org/show_bug.cgi?id=73358

Reviewed by Darin Adler.

Source/WebCore:

No change in behavior, just refactoring.

* loader/FrameLoader.h:
* loader/FrameLoader.cpp:
(WebCore::originatingURLFromBackForwardList):
(WebCore::FrameLoader::setOriginalURLForDownloadRequest):
Moved implementations from WebKit, added a bunch of FIXMEs.

* loader/MainResourceLoader.cpp: (WebCore::MainResourceLoader::continueAfterContentPolicy):
Set main document URL (incorrectly renamed to "first party for cookies" in WebCore), so that
CFNetwork would automatically use it.

* loader/PolicyChecker.cpp: (WebCore::PolicyChecker::continueAfterNavigationPolicy): Ditto
for requests that start as downloads (as opposed to being converted after reading first bits
of response).

Source/WebKit/mac:

* WebCoreSupport/WebFrameLoaderClient.h: Removed setOriginalURLForDownload, which is now
in WebCore.

* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::download): There is no need to set original URL post factum any more.
(WebFrameLoaderClient::startDownload): Ditto.

Source/WebKit2:

* WebProcess/Downloads/mac/DownloadMac.mm:
(WebKit::Download::start): There is no need to set original URL post factum any more.
(WebKit::Download::startWithHandle): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101485 => 101486)


--- trunk/Source/WebCore/ChangeLog	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebCore/ChangeLog	2011-11-30 12:13:31 UTC (rev 101486)
@@ -1,3 +1,26 @@
+2011-11-30  Alexey Proskuryakov  <[email protected]>
+
+        Download page URL should be set by WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=73358
+
+        Reviewed by Darin Adler.
+
+        No change in behavior, just refactoring.
+
+        * loader/FrameLoader.h:
+        * loader/FrameLoader.cpp:
+        (WebCore::originatingURLFromBackForwardList):
+        (WebCore::FrameLoader::setOriginalURLForDownloadRequest):
+        Moved implementations from WebKit, added a bunch of FIXMEs.
+
+        * loader/MainResourceLoader.cpp: (WebCore::MainResourceLoader::continueAfterContentPolicy):
+        Set main document URL (incorrectly renamed to "first party for cookies" in WebCore), so that
+        CFNetwork would automatically use it.
+
+        * loader/PolicyChecker.cpp: (WebCore::PolicyChecker::continueAfterNavigationPolicy): Ditto
+        for requests that start as downloads (as opposed to being converted after reading first bits
+        of response).
+
 2011-11-30  Rafael Weinstein  <[email protected]>
 
         Remove unused isInlineCode from V8Proxy

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (101485 => 101486)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2011-11-30 12:13:31 UTC (rev 101486)
@@ -2318,6 +2318,60 @@
         m_provisionalDocumentLoader->updateLoading();
 }
 
+static KURL originatingURLFromBackForwardList(Page* page)
+{
+    // FIXME: Can this logic be replaced with m_frame->document()->firstPartyForCookies()?
+    // It has the same meaning of "page a user thinks is the current one".
+
+    KURL originalURL;
+    int backCount = page->backForward()->backCount();
+    for (int backIndex = 0; backIndex <= backCount; backIndex++) {
+        // FIXME: At one point we had code here to check a "was user gesture" flag.
+        // Do we need to restore that logic?
+        HistoryItem* historyItem = page->backForward()->itemAtIndex(-backIndex);
+        if (!historyItem)
+            continue;
+
+        originalURL = historyItem->originalURL(); 
+        if (!originalURL.isNull()) 
+            return originalURL;
+    }
+
+    return KURL();
+}
+
+void FrameLoader::setOriginalURLForDownloadRequest(ResourceRequest& request)
+{
+    KURL originalURL;
+    
+    // If there is no referrer, assume that the download was initiated directly, so current document is
+    // completely unrelated to it. See <rdar://problem/5294691>.
+    // FIXME: Referrer is not sent in many other cases, so we will often miss this important information.
+    // Find a better way to decide whether the download was unrelated to current document.
+    if (!request.httpReferrer().isNull()) {
+        // find the first item in the history that was originated by the user
+        originalURL = originatingURLFromBackForwardList(m_frame->page());
+    }
+
+    if (originalURL.isNull())
+        originalURL = request.url();
+
+    if (!originalURL.protocol().isEmpty() && !originalURL.host().isEmpty()) {
+        unsigned port = originalURL.port();
+
+        // Original URL is needed to show the user where a file was downloaded from. We should make a URL that won't result in downloading the file again.
+        // FIXME: Using host-only URL is a very heavy-handed approach. We should attempt to provide the actual page where the download was initiated from, as a reminder to the user.
+        String hostOnlyURLString;
+        if (port)
+            hostOnlyURLString = makeString(originalURL.protocol(), "://", originalURL.host(), ":", String::number(port));
+        else
+            hostOnlyURLString = makeString(originalURL.protocol(), "://", originalURL.host());
+
+        // FIXME: Rename firstPartyForCookies back to mainDocumentURL. It was a mistake to think that it was only used for cookies.
+        request.setFirstPartyForCookies(KURL(KURL(), hostOnlyURLString));
+    }
+}
+
 void FrameLoader::didFirstLayout()
 {
     if (m_frame->page() && isBackForwardLoadType(m_loadType))

Modified: trunk/Source/WebCore/loader/FrameLoader.h (101485 => 101486)


--- trunk/Source/WebCore/loader/FrameLoader.h	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebCore/loader/FrameLoader.h	2011-11-30 12:13:31 UTC (rev 101486)
@@ -261,7 +261,9 @@
     // uses the policy machinery (and therefore is called via the PolicyChecker).  Once we
     // introduce a proper callback type for this function, we should make it private again.
     void continueLoadAfterWillSubmitForm();
-    
+
+    void setOriginalURLForDownloadRequest(ResourceRequest&);
+
     bool suppressOpenerInNewFrame() const { return m_suppressOpenerInNewFrame; }
 
     static ObjectContentType defaultObjectContentType(const KURL&, const String& mimeType, bool shouldPreferPlugInsForImages);

Modified: trunk/Source/WebCore/loader/MainResourceLoader.cpp (101485 => 101486)


--- trunk/Source/WebCore/loader/MainResourceLoader.cpp	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebCore/loader/MainResourceLoader.cpp	2011-11-30 12:13:31 UTC (rev 101486)
@@ -31,6 +31,7 @@
 #include "MainResourceLoader.h"
 
 #include "ApplicationCacheHost.h"
+#include "BackForwardController.h"
 #include "Console.h"
 #include "DOMWindow.h"
 #include "Document.h"
@@ -41,6 +42,7 @@
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
 #include "HTMLFormElement.h"
+#include "HistoryItem.h"
 #include "InspectorInstrumentation.h"
 #include "Page.h"
 #include "ResourceError.h"
@@ -275,19 +277,27 @@
         break;
     }
 
-    case PolicyDownload:
+    case PolicyDownload: {
         // m_handle can be null, e.g. when loading a substitute resource from application cache.
         if (!m_handle) {
             receivedError(cannotShowURLError());
             return;
         }
         InspectorInstrumentation::continueWithPolicyDownload(m_frame.get(), documentLoader(), identifier(), r);
-        frameLoader()->client()->download(m_handle.get(), request(), m_handle.get()->firstRequest(), r);
+
+        // When starting the request, we didn't know that it would result in download and not navigation. Now we know that first party didn't change.
+        // Download may use this knowledge for purposes unrelated to cookies, notably for setting file quarantine data.
+        ResourceRequest request = this->request();
+        frameLoader()->setOriginalURLForDownloadRequest(request);
+
+        // FIXME: Do any ports use first request argument? Most likely, it can be removed.
+        frameLoader()->client()->download(m_handle.get(), request, m_handle.get()->firstRequest(), r);
+
         // It might have gone missing
         if (frameLoader())
             receivedError(interruptedForPolicyChangeError());
         return;
-
+    }
     case PolicyIgnore:
         InspectorInstrumentation::continueWithPolicyIgnore(m_frame.get(), documentLoader(), identifier(), r);
         stopLoadingForPolicyChange();

Modified: trunk/Source/WebCore/loader/PolicyChecker.cpp (101485 => 101486)


--- trunk/Source/WebCore/loader/PolicyChecker.cpp	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebCore/loader/PolicyChecker.cpp	2011-11-30 12:13:31 UTC (rev 101486)
@@ -145,10 +145,13 @@
         case PolicyIgnore:
             callback.clearRequest();
             break;
-        case PolicyDownload:
-            m_frame->loader()->client()->startDownload(callback.request());
+        case PolicyDownload: {
+            ResourceRequest request = callback.request();
+            m_frame->loader()->setOriginalURLForDownloadRequest(request);
+            m_frame->loader()->client()->startDownload(request);
             callback.clearRequest();
             break;
+        }
         case PolicyUse: {
             ResourceRequest request(callback.request());
 

Modified: trunk/Source/WebKit/mac/ChangeLog (101485 => 101486)


--- trunk/Source/WebKit/mac/ChangeLog	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebKit/mac/ChangeLog	2011-11-30 12:13:31 UTC (rev 101486)
@@ -1,3 +1,17 @@
+2011-11-30  Alexey Proskuryakov  <[email protected]>
+
+        Download page URL should be set by WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=73358
+
+        Reviewed by Darin Adler.
+
+        * WebCoreSupport/WebFrameLoaderClient.h: Removed setOriginalURLForDownload, which is now
+        in WebCore.
+
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::download): There is no need to set original URL post factum any more.
+        (WebFrameLoaderClient::startDownload): Ditto.
+
 2011-11-29  David Levin  <[email protected]>
 
         Add a way to revert a variable to its previous value after leaving a scope.

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h (101485 => 101486)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.h	2011-11-30 12:13:31 UTC (rev 101486)
@@ -231,8 +231,6 @@
     virtual RemoteAXObjectRef accessibilityRemoteObject() OVERRIDE { return 0; }
 #endif
     
-    void setOriginalURLForDownload(WebDownload *, const WebCore::ResourceRequest&) const;
-
     RetainPtr<WebFramePolicyListener> setUpPolicyListener(WebCore::FramePolicyFunction);
 
     NSDictionary *actionDictionary(const WebCore::NavigationAction&, PassRefPtr<WebCore::FormState>) const;

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm (101485 => 101486)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm	2011-11-30 12:13:31 UTC (rev 101486)
@@ -146,10 +146,6 @@
 @end
 #endif
 
-@interface NSURLDownload (WebNSURLDownloadDetails)
-- (void)_setOriginatingURL:(NSURL *)originatingURL;
-@end
-
 // For backwards compatibility with older WebKit plug-ins.
 NSString *WebPluginBaseURLKey = @"WebPluginBaseURL";
 NSString *WebPluginAttributesKey = @"WebPluginAttributes";
@@ -284,12 +280,11 @@
     ASSERT([WebDownload respondsToSelector:@selector(_downloadWithLoadingCFURLConnection:request:response:delegate:proxy:)]);
     WebView *webView = getWebView(m_webFrame.get());
     CFURLConnectionRef connection = handle->connection();
-    WebDownload *download = [WebDownload _downloadWithLoadingCFURLConnection:connection
+    [WebDownload _downloadWithLoadingCFURLConnection:connection
                                                                      request:request.cfURLRequest()
                                                                     response:response.cfURLResponse()
                                                                     delegate:[webView downloadDelegate]
                                                                        proxy:nil];
-    setOriginalURLForDownload(download, initialRequest);
 
     // Release the connection since the NSURLDownload (actually CFURLDownload) will retain the connection and use it.
     handle->releaseConnectionForDownload();
@@ -299,58 +294,14 @@
     ASSERT(proxy);
     
     WebView *webView = getWebView(m_webFrame.get());
-    WebDownload *download = [WebDownload _downloadWithLoadingConnection:handle->connection()
+    [WebDownload _downloadWithLoadingConnection:handle->connection()
                                                                 request:request.nsURLRequest()
                                                                response:response.nsURLResponse()
                                                                delegate:[webView downloadDelegate]
                                                                   proxy:proxy];
-    
-    setOriginalURLForDownload(download, initialRequest);    
 #endif
 }
 
-void WebFrameLoaderClient::setOriginalURLForDownload(WebDownload *download, const ResourceRequest& initialRequest) const
-{
-    NSURLRequest *initialURLRequest = initialRequest.nsURLRequest();
-    NSURL *originalURL = nil;
-    
-    // If there was no referrer, don't traverse the back/forward history
-    // since this download was initiated directly. <rdar://problem/5294691>
-    if ([initialURLRequest valueForHTTPHeaderField:@"Referer"]) {
-        // find the first item in the history that was originated by the user
-        WebView *webView = getWebView(m_webFrame.get());
-        WebBackForwardList *history = [webView backForwardList];
-        int backListCount = [history backListCount];
-        for (int backIndex = 0; backIndex <= backListCount && !originalURL; backIndex++) {
-            // FIXME: At one point we had code here to check a "was user gesture" flag.
-            // Do we need to restore that logic?
-            originalURL = [[history itemAtIndex:-backIndex] URL];
-        }
-    }
-
-    if (!originalURL)
-        originalURL = [initialURLRequest URL];
-
-    if ([download respondsToSelector:@selector(_setOriginatingURL:)]) {
-        NSString *scheme = [originalURL scheme];
-        NSString *host = [originalURL host];
-        if (scheme && host && [scheme length] && [host length]) {
-            NSNumber *port = [originalURL port];
-            if (port && [port intValue] < 0)
-                port = nil;
-            NSString *hostOnlyURLString;
-            if (port)
-                hostOnlyURLString = [[NSString alloc] initWithFormat:@"%@://%@:%d", scheme, host, [port intValue]];
-            else
-                hostOnlyURLString = [[NSString alloc] initWithFormat:@"%@://%@", scheme, host];
-            NSURL *hostOnlyURL = [[NSURL alloc] initWithString:hostOnlyURLString];
-            [hostOnlyURLString release];
-            [download _setOriginatingURL:hostOnlyURL];
-            [hostOnlyURL release];
-        }
-    }
-}
-
 bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader* loader, const ResourceRequest& request, const ResourceResponse& response, int length)
 {
     applyAppleDictionaryApplicationQuirk(this, request);
@@ -866,9 +817,7 @@
 void WebFrameLoaderClient::startDownload(const ResourceRequest& request, const String& /* suggestedName */)
 {
     // FIXME: Should download full request.
-    WebDownload *download = [getWebView(m_webFrame.get()) _downloadURL:request.url()];
-    
-    setOriginalURLForDownload(download, request);
+    [getWebView(m_webFrame.get()) _downloadURL:request.url()];
 }
 
 void WebFrameLoaderClient::willChangeTitle(DocumentLoader* loader)

Modified: trunk/Source/WebKit2/ChangeLog (101485 => 101486)


--- trunk/Source/WebKit2/ChangeLog	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebKit2/ChangeLog	2011-11-30 12:13:31 UTC (rev 101486)
@@ -1,3 +1,14 @@
+2011-11-30  Alexey Proskuryakov  <[email protected]>
+
+        Download page URL should be set by WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=73358
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/Downloads/mac/DownloadMac.mm:
+        (WebKit::Download::start): There is no need to set original URL post factum any more.
+        (WebKit::Download::startWithHandle): Ditto.
+
 2011-11-30  Kenneth Rohde Christiansen  <[email protected]>
 
         Rename WebKit::ViewportUpdateGuard to *Deferrer and add some better

Modified: trunk/Source/WebKit2/WebProcess/Downloads/mac/DownloadMac.mm (101485 => 101486)


--- trunk/Source/WebKit2/WebProcess/Downloads/mac/DownloadMac.mm	2011-11-30 12:09:43 UTC (rev 101485)
+++ trunk/Source/WebKit2/WebProcess/Downloads/mac/DownloadMac.mm	2011-11-30 12:13:31 UTC (rev 101486)
@@ -27,10 +27,7 @@
 #import "Download.h"
 
 #import <WebCore/AuthenticationMac.h>
-#import <WebCore/BackForwardController.h>
-#import <WebCore/HistoryItem.h>
 #import <WebCore/NotImplemented.h>
-#import <WebCore/Page.h>
 #import <WebCore/ResourceHandle.h>
 #import <WebCore/ResourceResponse.h>
 #import "DataReference.h"
@@ -42,7 +39,6 @@
                            response:(NSURLResponse *)r
                            delegate:(id)delegate
                               proxy:(id)proxy;
-- (void)_setOriginatingURL:(NSURL *)originatingURL;
 @end
 
 @interface WKDownloadAsDelegate : NSObject <NSURLDownloadDelegate> {
@@ -56,67 +52,6 @@
 
 namespace WebKit {
 
-static KURL originatingURLFromBackForwardList(WebPage *webPage)
-{
-    if (!webPage)
-        return KURL();
-
-    Page* page = webPage->corePage();
-    if (!page)
-        return KURL();
-
-    KURL originalURL;
-    int backCount = page->backForward()->backCount();
-    for (int backIndex = 0; backIndex <= backCount; backIndex++) {
-        // FIXME: At one point we had code here to check a "was user gesture" flag.
-        // Do we need to restore that logic?
-        HistoryItem* historyItem = page->backForward()->itemAtIndex(-backIndex);
-        if (!historyItem)
-            continue;
-
-        originalURL = historyItem->originalURL(); 
-        if (!originalURL.isNull()) 
-            return originalURL;
-    }
-
-    return KURL();
-}
-
-static void setOriginalURLForDownload(WebPage *webPage, NSURLDownload *download, const ResourceRequest& initialRequest)
-{
-    KURL originalURL;
-    
-    // If there was no referrer, don't traverse the back/forward history
-    // since this download was initiated directly. <rdar://problem/5294691>
-    if (!initialRequest.httpReferrer().isNull()) {
-        // find the first item in the history that was originated by the user
-        originalURL = originatingURLFromBackForwardList(webPage);
-    }
-
-    if (originalURL.isNull())
-        originalURL = initialRequest.url();
-
-    NSURL *originalNSURL = originalURL;
-
-    NSString *scheme = [originalNSURL scheme];
-    NSString *host = [originalNSURL host];
-    if (scheme && host && [scheme length] && [host length]) {
-        NSNumber *port = [originalNSURL port];
-        if (port && [port intValue] < 0)
-            port = nil;
-        RetainPtr<NSString> hostOnlyURLString;
-        if (port)
-            hostOnlyURLString.adoptNS([[NSString alloc] initWithFormat:@"%@://%@:%d", scheme, host, [port intValue]]);
-        else
-            hostOnlyURLString.adoptNS([[NSString alloc] initWithFormat:@"%@://%@", scheme, host]);
-
-        RetainPtr<NSURL> hostOnlyURL(AdoptNS, [[NSURL alloc] initWithString:hostOnlyURLString.get()]);
-
-        ASSERT([download respondsToSelector:@selector(_setOriginatingURL:)]);
-        [download _setOriginatingURL:hostOnlyURL.get()];
-    }
-}
-
 void Download::start(WebPage* initiatingPage)
 {
     ASSERT(!m_nsURLDownload);
@@ -127,8 +62,6 @@
 
     // FIXME: Allow this to be changed by the client.
     [m_nsURLDownload.get() setDeletesFileUponFailure:NO];
-
-    setOriginalURLForDownload(initiatingPage, m_nsURLDownload.get(), m_request);
 }
 
 void Download::startWithHandle(WebPage* initiatingPage, ResourceHandle* handle, const ResourceRequest& initialRequest, const ResourceResponse& response)
@@ -148,8 +81,6 @@
 
     // FIXME: Allow this to be changed by the client.
     [m_nsURLDownload.get() setDeletesFileUponFailure:NO];
-                                                            
-    setOriginalURLForDownload(initiatingPage, m_nsURLDownload.get(), initialRequest);
 }
 
 void Download::cancel()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to