diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/url_request/url_request.h | 14 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.cc | 16 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 17 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.h | 27 |
4 files changed, 51 insertions, 23 deletions
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index f770c89..23e2f6f 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -187,12 +187,18 @@ class URLRequest { request->Cancel(); } - // Called when unable to get cookies due to policy. - virtual void OnGetCookiesBlocked(URLRequest* request) { + // Called when reading cookies. |blocked_by_policy| is true if access to + // cookies was denied due to content settings. This method will never be + // invoked when LOAD_DO_NOT_SEND_COOKIES is specified. + virtual void OnGetCookies(URLRequest* request, bool blocked_by_policy) { } - // Called when unable to set a cookie due to policy. - virtual void OnSetCookieBlocked(URLRequest* request) { + // Called when a cookie is set. |blocked_by_policy| is true if the cookie + // was rejected due to content settings. This method will never be invoked + // when LOAD_DO_NOT_SAVE_COOKIES is specified. + virtual void OnSetCookie(URLRequest* request, + const std::string& cookie_line, + bool blocked_by_policy) { } // After calling Start(), the delegate will receive an OnResponseStarted diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 4f44f2e3..9a03213 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -441,8 +441,9 @@ void URLRequestHttpJob::OnCanGetCookiesCompleted(int policy) { // If the request was destroyed, then there is no more work to do. if (request_ && request_->delegate()) { if (policy == net::ERR_ACCESS_DENIED) { - request_->delegate()->OnGetCookiesBlocked(request_); + request_->delegate()->OnGetCookies(request_, true); } else if (policy == net::OK && request_->context()->cookie_store()) { + request_->delegate()->OnGetCookies(request_, false); net::CookieOptions options; options.set_include_httponly(); std::string cookies = @@ -453,7 +454,7 @@ void URLRequestHttpJob::OnCanGetCookiesCompleted(int policy) { net::HttpRequestHeaders::kCookie, cookies); } } - // We may have been canceled within OnGetCookiesBlocked. + // We may have been canceled within OnGetCookies. if (GetStatus().is_success()) { StartTransaction(); } else { @@ -467,7 +468,10 @@ void URLRequestHttpJob::OnCanSetCookieCompleted(int policy) { // If the request was destroyed, then there is no more work to do. if (request_ && request_->delegate()) { if (policy == net::ERR_ACCESS_DENIED) { - request_->delegate()->OnSetCookieBlocked(request_); + request_->delegate()->OnSetCookie( + request_, + response_cookies_[response_cookies_save_index_], + true); } else if ((policy == net::OK || policy == net::OK_FOR_SESSION_ONLY) && request_->context()->cookie_store()) { // OK to save the current response cookie now. @@ -478,9 +482,13 @@ void URLRequestHttpJob::OnCanSetCookieCompleted(int policy) { request_->context()->cookie_store()->SetCookieWithOptions( request_->url(), response_cookies_[response_cookies_save_index_], options); + request_->delegate()->OnSetCookie( + request_, + response_cookies_[response_cookies_save_index_], + false); } response_cookies_save_index_++; - // We may have been canceled within OnSetCookieBlocked. + // We may have been canceled within OnSetCookie. if (GetStatus().is_success()) { SaveNextCookie(); } else { diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index a15d82f..026038f 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -1265,7 +1265,7 @@ TEST_F(URLRequestTest, DoNotSendCookies) { EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") == std::string::npos); - // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookiesBlocked. + // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. EXPECT_EQ(0, d.blocked_get_cookies_count()); EXPECT_EQ(0, d.blocked_set_cookie_count()); } @@ -1288,6 +1288,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { EXPECT_EQ(0, d.blocked_get_cookies_count()); EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(1, d.set_cookie_count()); } // Try to set-up another cookie and update the previous cookie. @@ -1301,9 +1302,10 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { MessageLoop::current()->Run(); - // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookieBlocked. + // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. EXPECT_EQ(0, d.blocked_get_cookies_count()); EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, d.set_cookie_count()); } // Verify the cookies weren't saved or updated. @@ -1321,6 +1323,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies) { EXPECT_EQ(0, d.blocked_get_cookies_count()); EXPECT_EQ(0, d.blocked_set_cookie_count()); + EXPECT_EQ(0, d.set_cookie_count()); } } @@ -1578,7 +1581,7 @@ TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { MessageLoop::current()->RunAllPending(); } -TEST_F(URLRequestTest, CancelTest_During_OnGetCookiesBlocked) { +TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { scoped_refptr<HTTPTestServer> server = HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); @@ -1607,7 +1610,7 @@ TEST_F(URLRequestTest, CancelTest_During_OnGetCookiesBlocked) { context->set_cookie_policy(NULL); } -TEST_F(URLRequestTest, CancelTest_During_OnSetCookieBlocked) { +TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { scoped_refptr<HTTPTestServer> server = HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); @@ -1630,9 +1633,9 @@ TEST_F(URLRequestTest, CancelTest_During_OnSetCookieBlocked) { EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); // Even though the response will contain 3 set-cookie headers, we expect - // only one to be blocked as that first one will cause OnSetCookieBlocked - // to be called, which will cancel the request. Once canceled, it should - // not attempt to set further cookies. + // only one to be blocked as that first one will cause OnSetCookie to be + // called, which will cancel the request. Once canceled, it should not + // attempt to set further cookies. EXPECT_EQ(0, d.blocked_get_cookies_count()); EXPECT_EQ(1, d.blocked_set_cookie_count()); diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 411e32a..0dfa766 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -204,6 +204,7 @@ class TestDelegate : public URLRequest::Delegate { received_redirect_count_(0), blocked_get_cookies_count_(0), blocked_set_cookie_count_(0), + set_cookie_count_(0), received_data_before_response_(false), request_failed_(false), have_certificate_errors_(false), @@ -306,16 +307,24 @@ class TestDelegate : public URLRequest::Delegate { request->Cancel(); } - virtual void OnGetCookiesBlocked(URLRequest* request) { - blocked_get_cookies_count_++; - if (cancel_in_getcookiesblocked_) - request->Cancel(); + virtual void OnGetCookies(URLRequest* request, bool blocked_by_policy) { + if (blocked_by_policy) { + blocked_get_cookies_count_++; + if (cancel_in_getcookiesblocked_) + request->Cancel(); + } } - virtual void OnSetCookieBlocked(URLRequest* request) { - blocked_set_cookie_count_++; - if (cancel_in_setcookieblocked_) - request->Cancel(); + virtual void OnSetCookie(URLRequest* request, + const std::string& cookie_line, + bool blocked_by_policy) { + if (blocked_by_policy) { + blocked_set_cookie_count_++; + if (cancel_in_setcookieblocked_) + request->Cancel(); + } else { + set_cookie_count_++; + } } void set_cancel_in_received_redirect(bool val) { cancel_in_rr_ = val; } @@ -345,6 +354,7 @@ class TestDelegate : public URLRequest::Delegate { int received_redirect_count() const { return received_redirect_count_; } int blocked_get_cookies_count() const { return blocked_get_cookies_count_; } int blocked_set_cookie_count() const { return blocked_set_cookie_count_; } + int set_cookie_count() const { return set_cookie_count_; } bool received_data_before_response() const { return received_data_before_response_; } @@ -373,6 +383,7 @@ class TestDelegate : public URLRequest::Delegate { int received_redirect_count_; int blocked_get_cookies_count_; int blocked_set_cookie_count_; + int set_cookie_count_; bool received_data_before_response_; bool request_failed_; bool have_certificate_errors_; |