summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/navigation_interception/intercept_navigation_resource_throttle.cc18
-rw-r--r--components/navigation_interception/intercept_navigation_resource_throttle.h5
-rw-r--r--components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc64
3 files changed, 81 insertions, 6 deletions
diff --git a/components/navigation_interception/intercept_navigation_resource_throttle.cc b/components/navigation_interception/intercept_navigation_resource_throttle.cc
index 390be67..73513ef 100644
--- a/components/navigation_interception/intercept_navigation_resource_throttle.cc
+++ b/components/navigation_interception/intercept_navigation_resource_throttle.cc
@@ -13,6 +13,7 @@
#include "content/public/browser/resource_request_info.h"
#include "content/public/common/page_transition_types.h"
#include "content/public/common/referrer.h"
+#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
using content::BrowserThread;
@@ -68,17 +69,28 @@ InterceptNavigationResourceThrottle::~InterceptNavigationResourceThrottle() {
}
void InterceptNavigationResourceThrottle::WillStartRequest(bool* defer) {
- *defer = CheckIfShouldIgnoreNavigation(request_->url(), false);
+ *defer =
+ CheckIfShouldIgnoreNavigation(request_->url(), request_->method(), false);
}
void InterceptNavigationResourceThrottle::WillRedirectRequest(
const GURL& new_url,
bool* defer) {
- *defer = CheckIfShouldIgnoreNavigation(new_url, true);
+ *defer =
+ CheckIfShouldIgnoreNavigation(new_url, GetMethodAfterRedirect(), true);
+}
+
+std::string InterceptNavigationResourceThrottle::GetMethodAfterRedirect() {
+ net::HttpResponseHeaders* headers = request_->response_headers();
+ if (!headers)
+ return request_->method();
+ return net::URLRequest::ComputeMethodForRedirect(
+ request_->method(), headers->response_code());
}
bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation(
const GURL& url,
+ const std::string& method,
bool is_redirect) {
const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
if (!info)
@@ -92,7 +104,7 @@ bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation(
Referrer(GURL(request_->referrer()),
info->GetReferrerPolicy()),
info->HasUserGesture(),
- request_->method() == "POST",
+ method == "POST",
info->GetPageTransition(),
is_redirect);
diff --git a/components/navigation_interception/intercept_navigation_resource_throttle.h b/components/navigation_interception/intercept_navigation_resource_throttle.h
index 012cd568..79ed57e 100644
--- a/components/navigation_interception/intercept_navigation_resource_throttle.h
+++ b/components/navigation_interception/intercept_navigation_resource_throttle.h
@@ -44,7 +44,10 @@ class InterceptNavigationResourceThrottle : public content::ResourceThrottle {
virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE;
private:
- bool CheckIfShouldIgnoreNavigation(const GURL& url, bool is_redirect);
+ std::string GetMethodAfterRedirect();
+ bool CheckIfShouldIgnoreNavigation(const GURL& url,
+ const std::string& method,
+ bool is_redirect);
void OnResultObtained(bool should_ignore_navigation);
net::URLRequest* request_;
diff --git a/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc b/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc
index 6082e0f..dfccb30 100644
--- a/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc
+++ b/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc
@@ -23,6 +23,8 @@
#include "content/public/common/page_transition_types.h"
#include "content/public/test/mock_resource_context.h"
#include "content/public/test/test_renderer_host.h"
+#include "net/http/http_response_headers.h"
+#include "net/http/http_response_info.h"
#include "net/url_request/url_request.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -102,12 +104,18 @@ class MockResourceController : public content::ResourceController {
// TestIOThreadState ----------------------------------------------------------
+enum RedirectMode {
+ REDIRECT_MODE_NO_REDIRECT,
+ REDIRECT_MODE_302,
+};
+
class TestIOThreadState {
public:
TestIOThreadState(const GURL& url,
int render_process_id,
int render_view_id,
const std::string& request_method,
+ RedirectMode redirect_mode,
MockInterceptCallbackReceiver* callback_receiver)
: request_(url, NULL, resource_context_.GetRequestContext()) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
@@ -126,6 +134,13 @@ class TestIOThreadState {
base::Unretained(callback_receiver))));
throttle_->set_controller_for_testing(&throttle_controller_);
request_.set_method(request_method);
+
+ if (redirect_mode == REDIRECT_MODE_302) {
+ net::HttpResponseInfo& response_info =
+ const_cast<net::HttpResponseInfo&>(request_.response_info());
+ response_info.headers = new net::HttpResponseHeaders(
+ "Status: 302 Found\0\0");
+ }
}
void ThrottleWillStartRequest(bool* defer) {
@@ -133,6 +148,11 @@ class TestIOThreadState {
throttle_->WillStartRequest(defer);
}
+ void ThrottleWillRedirectRequest(const GURL& new_url, bool* defer) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ throttle_->WillRedirectRequest(new_url, defer);
+ }
+
bool request_resumed() const {
return throttle_controller_.status() ==
MockResourceController::RESUMED;
@@ -183,16 +203,22 @@ class InterceptNavigationResourceThrottleTest
void RunThrottleWillStartRequestOnIOThread(
const GURL& url,
const std::string& request_method,
+ RedirectMode redirect_mode,
int render_process_id,
int render_view_id,
bool* defer) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
TestIOThreadState* io_thread_state =
new TestIOThreadState(url, render_process_id, render_view_id,
- request_method, mock_callback_receiver_.get());
+ request_method, redirect_mode,
+ mock_callback_receiver_.get());
SetIOThreadState(io_thread_state);
- io_thread_state->ThrottleWillStartRequest(defer);
+
+ if (redirect_mode == REDIRECT_MODE_NO_REDIRECT)
+ io_thread_state->ThrottleWillStartRequest(defer);
+ else
+ io_thread_state->ThrottleWillRedirectRequest(url, defer);
}
protected:
@@ -220,6 +246,7 @@ class InterceptNavigationResourceThrottleTest
base::Unretained(this),
GURL(kTestUrl),
"GET",
+ REDIRECT_MODE_NO_REDIRECT,
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID(),
base::Unretained(defer)));
@@ -284,6 +311,7 @@ TEST_F(InterceptNavigationResourceThrottleTest,
base::Unretained(this),
GURL(kTestUrl),
"GET",
+ REDIRECT_MODE_NO_REDIRECT,
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID(),
base::Unretained(&defer)));
@@ -317,6 +345,7 @@ TEST_F(InterceptNavigationResourceThrottleTest,
base::Unretained(this),
GURL(kTestUrl),
"GET",
+ REDIRECT_MODE_NO_REDIRECT,
MSG_ROUTING_NONE,
MSG_ROUTING_NONE,
base::Unretained(&defer)));
@@ -347,6 +376,7 @@ TEST_F(InterceptNavigationResourceThrottleTest,
base::Unretained(this),
GURL(kUnsafeTestUrl),
"GET",
+ REDIRECT_MODE_NO_REDIRECT,
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID(),
base::Unretained(&defer)));
@@ -374,6 +404,7 @@ TEST_F(InterceptNavigationResourceThrottleTest,
base::Unretained(this),
GURL(kTestUrl),
"GET",
+ REDIRECT_MODE_NO_REDIRECT,
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID(),
base::Unretained(&defer)));
@@ -401,6 +432,35 @@ TEST_F(InterceptNavigationResourceThrottleTest,
base::Unretained(this),
GURL(kTestUrl),
"POST",
+ REDIRECT_MODE_NO_REDIRECT,
+ web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
+ web_contents()->GetRenderViewHost()->GetRoutingID(),
+ base::Unretained(&defer)));
+
+ // Wait for the request to finish processing.
+ base::RunLoop().RunUntilIdle();
+}
+
+TEST_F(InterceptNavigationResourceThrottleTest,
+ CallbackIsPostFalseForPostConvertedToGetBy302) {
+ bool defer = false;
+
+ EXPECT_CALL(*mock_callback_receiver_,
+ ShouldIgnoreNavigation(_, AllOf(
+ NavigationParamsUrlIsSafe(),
+ Property(&NavigationParams::is_post, Eq(false)))))
+ .WillOnce(Return(false));
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ &InterceptNavigationResourceThrottleTest::
+ RunThrottleWillStartRequestOnIOThread,
+ base::Unretained(this),
+ GURL(kTestUrl),
+ "POST",
+ REDIRECT_MODE_302,
web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID(),
base::Unretained(&defer)));