diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-12 00:25:37 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-12 00:25:37 +0000 |
commit | 56505548c2d50a94fb8eac59cd3ad663301c4129 (patch) | |
tree | 6f502d8f71f6a7188482ce66c930b107127b977f | |
parent | c2d9865134afd8c10f392b3bc0b3e9206f9d87a3 (diff) | |
download | chromium_src-56505548c2d50a94fb8eac59cd3ad663301c4129.zip chromium_src-56505548c2d50a94fb8eac59cd3ad663301c4129.tar.gz chromium_src-56505548c2d50a94fb8eac59cd3ad663301c4129.tar.bz2 |
Pass in the full referrer for DownloadFile IPC
BUG=124750
TEST=DownloadTest.LoadURLExternallyReferrerPolicy
Review URL: https://chromiumcodereview.appspot.com/10392050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136724 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download/download_browsertest.cc | 49 | ||||
-rw-r--r-- | chrome/test/data/downloads/referrer_policy.html | 9 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter.cc | 6 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter.h | 3 | ||||
-rw-r--r-- | content/common/view_messages.h | 2 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 8 |
6 files changed, 69 insertions, 8 deletions
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 5dd298f..93c9873 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -2401,3 +2401,52 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousBlobData) { EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); } + +IN_PROC_BROWSER_TEST_F(DownloadTest, LoadURLExternallyReferrerPolicy) { + // Do initial setup. + ASSERT_TRUE(test_server()->Start()); + NullSelectFile(browser()); + std::vector<DownloadItem*> download_items; + GetDownloads(browser(), &download_items); + ASSERT_TRUE(download_items.empty()); + + // Navigate to a page with a referrer policy and a link on it. The link points + // to testserver's /echoheader. + GURL url = test_server()->GetURL("files/downloads/referrer_policy.html"); + ASSERT_TRUE(url.is_valid()); + ui_test_utils::NavigateToURL(browser(), url); + + scoped_ptr<DownloadTestObserver> waiter( + new DownloadTestObserverTerminal( + DownloadManagerForBrowser(browser()), 1, + false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); + + // Click on the link with the alt key pressed. This will download the link + // target. + WebContents* tab = browser()->GetSelectedWebContents(); + WebKit::WebMouseEvent mouse_event; + mouse_event.type = WebKit::WebInputEvent::MouseDown; + mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; + mouse_event.x = 15; + mouse_event.y = 15; + mouse_event.clickCount = 1; + mouse_event.modifiers = WebKit::WebInputEvent::AltKey; + tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); + mouse_event.type = WebKit::WebInputEvent::MouseUp; + tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); + + waiter->WaitForFinished(); + EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); + CheckDownloadStates(1, DownloadItem::COMPLETE); + + // Validate that the correct file was downloaded. + GetDownloads(browser(), &download_items); + ASSERT_EQ(1u, download_items.size()); + ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), + download_items[0]->GetOriginalUrl()); + + // Check that the file contains the expected referrer. + FilePath file(download_items[0]->GetFullPath()); + std::string expected_contents = test_server()->GetURL("").spec(); + ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); +} diff --git a/chrome/test/data/downloads/referrer_policy.html b/chrome/test/data/downloads/referrer_policy.html new file mode 100644 index 0000000..0764499 --- /dev/null +++ b/chrome/test/data/downloads/referrer_policy.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html> +<head> +<meta name="referrer" content="origin"/> +</head> +<body> +<a href="/echoheader?Referer">link</a> +</body> +</html> diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index e704ec62..783de11 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -712,12 +712,14 @@ void RenderMessageFilter::OnGetHardwareInputChannelLayout( void RenderMessageFilter::OnDownloadUrl(const IPC::Message& message, const GURL& url, - const GURL& referrer, + const content::Referrer& referrer, const string16& suggested_name) { content::DownloadSaveInfo save_info; save_info.suggested_name = suggested_name; scoped_ptr<net::URLRequest> request(new net::URLRequest(url, NULL)); - request->set_referrer(referrer.spec()); + request->set_referrer(referrer.url.spec()); + webkit_glue::ConfigureURLRequestForReferrerPolicy( + request.get(), referrer.policy); download_stats::RecordDownloadSource(download_stats::INITIATED_BY_RENDERER); resource_dispatcher_host_->BeginDownload( request.Pass(), diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h index c3e7cdb..fc04214 100644 --- a/content/browser/renderer_host/render_message_filter.h +++ b/content/browser/renderer_host/render_message_filter.h @@ -43,6 +43,7 @@ struct WebScreenInfo; namespace content { class BrowserContext; class MediaObserver; +struct Referrer; class ResourceContext; class ResourceDispatcherHostImpl; } @@ -170,7 +171,7 @@ class RenderMessageFilter : public content::BrowserMessageFilter { void OnGenerateRoutingID(int* route_id); void OnDownloadUrl(const IPC::Message& message, const GURL& url, - const GURL& referrer, + const content::Referrer& referrer, const string16& suggested_name); void OnCheckNotificationPermission(const GURL& source_origin, int* permission_level); diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 4cf55f4..5045b17 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -1604,7 +1604,7 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_AppCacheAccessed, // Initiates a download based on user actions like 'ALT+click'. IPC_MESSAGE_ROUTED3(ViewHostMsg_DownloadUrl, GURL /* url */, - GURL /* referrer */, + content::Referrer /* referrer */, string16 /* suggested_name */) // Used to go to the session history entry at the given offset (ie, -1 will diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index ca97f70..0d83373 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2295,14 +2295,14 @@ void RenderViewImpl::loadURLExternally( WebFrame* frame, const WebURLRequest& request, WebNavigationPolicy policy, const WebString& suggested_name) { - GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); + Referrer referrer( + GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), + GetReferrerPolicyFromRequest(frame, request)); if (policy == WebKit::WebNavigationPolicyDownload) { Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer, suggested_name)); } else { - OpenURL(frame, request.url(), - Referrer(referrer, GetReferrerPolicyFromRequest(frame, request)), - policy); + OpenURL(frame, request.url(), referrer, policy); } } |