| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "components/navigation_interception/intercept_navigation_resource_throt
tle.h" | 10 #include "components/navigation_interception/intercept_navigation_resource_throt
tle.h" |
| 11 #include "components/navigation_interception/navigation_params.h" | 11 #include "components/navigation_interception/navigation_params.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
| 14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/resource_context.h" | 15 #include "content/public/browser/resource_context.h" |
| 16 #include "content/public/browser/resource_controller.h" | 16 #include "content/public/browser/resource_controller.h" |
| 17 #include "content/public/browser/resource_dispatcher_host.h" | 17 #include "content/public/browser/resource_dispatcher_host.h" |
| 18 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 18 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 19 #include "content/public/browser/resource_request_info.h" | 19 #include "content/public/browser/resource_request_info.h" |
| 20 #include "content/public/browser/resource_throttle.h" | 20 #include "content/public/browser/resource_throttle.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_delegate.h" | 22 #include "content/public/browser/web_contents_delegate.h" |
| 23 #include "content/public/test/mock_resource_context.h" | 23 #include "content/public/test/mock_resource_context.h" |
| 24 #include "content/public/test/test_renderer_host.h" | 24 #include "content/public/test/test_renderer_host.h" |
| 25 #include "net/base/request_priority.h" | 25 #include "net/base/request_priority.h" |
| 26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 27 #include "net/http/http_response_info.h" | 27 #include "net/http/http_response_info.h" |
| 28 #include "net/url_request/redirect_info.h" |
| 28 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
| 29 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 33 |
| 33 using content::ResourceType; | 34 using content::ResourceType; |
| 34 using testing::_; | 35 using testing::_; |
| 35 using testing::Eq; | 36 using testing::Eq; |
| 36 using testing::Ne; | 37 using testing::Ne; |
| 37 using testing::Property; | 38 using testing::Property; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 response_info.headers = new net::HttpResponseHeaders( | 148 response_info.headers = new net::HttpResponseHeaders( |
| 148 "Status: 302 Found\0\0"); | 149 "Status: 302 Found\0\0"); |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 | 152 |
| 152 void ThrottleWillStartRequest(bool* defer) { | 153 void ThrottleWillStartRequest(bool* defer) { |
| 153 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 154 throttle_->WillStartRequest(defer); | 155 throttle_->WillStartRequest(defer); |
| 155 } | 156 } |
| 156 | 157 |
| 157 void ThrottleWillRedirectRequest(const GURL& new_url, bool* defer) { | 158 void ThrottleWillRedirectRequest(const net::RedirectInfo& redirect_info, |
| 159 bool* defer) { |
| 158 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 160 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 159 throttle_->WillRedirectRequest(new_url, defer); | 161 throttle_->WillRedirectRequest(redirect_info, defer); |
| 160 } | 162 } |
| 161 | 163 |
| 162 bool request_resumed() const { | 164 bool request_resumed() const { |
| 163 return throttle_controller_.status() == | 165 return throttle_controller_.status() == |
| 164 MockResourceController::RESUMED; | 166 MockResourceController::RESUMED; |
| 165 } | 167 } |
| 166 | 168 |
| 167 bool request_cancelled() const { | 169 bool request_cancelled() const { |
| 168 return throttle_controller_.status() == | 170 return throttle_controller_.status() == |
| 169 MockResourceController::CANCELLED; | 171 MockResourceController::CANCELLED; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 int render_frame_id, | 213 int render_frame_id, |
| 212 bool* defer) { | 214 bool* defer) { |
| 213 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 215 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 214 TestIOThreadState* io_thread_state = | 216 TestIOThreadState* io_thread_state = |
| 215 new TestIOThreadState(url, render_process_id, render_frame_id, | 217 new TestIOThreadState(url, render_process_id, render_frame_id, |
| 216 request_method, redirect_mode, | 218 request_method, redirect_mode, |
| 217 mock_callback_receiver_.get()); | 219 mock_callback_receiver_.get()); |
| 218 | 220 |
| 219 SetIOThreadState(io_thread_state); | 221 SetIOThreadState(io_thread_state); |
| 220 | 222 |
| 221 if (redirect_mode == REDIRECT_MODE_NO_REDIRECT) | 223 if (redirect_mode == REDIRECT_MODE_NO_REDIRECT) { |
| 222 io_thread_state->ThrottleWillStartRequest(defer); | 224 io_thread_state->ThrottleWillStartRequest(defer); |
| 223 else | 225 } else { |
| 224 io_thread_state->ThrottleWillRedirectRequest(url, defer); | 226 // 302 redirects convert POSTs to gets. |
| 227 net::RedirectInfo redirect_info; |
| 228 redirect_info.new_url = url; |
| 229 redirect_info.new_method = "GET"; |
| 230 io_thread_state->ThrottleWillRedirectRequest(redirect_info, defer); |
| 231 } |
| 225 } | 232 } |
| 226 | 233 |
| 227 protected: | 234 protected: |
| 228 enum ShouldIgnoreNavigationCallbackAction { | 235 enum ShouldIgnoreNavigationCallbackAction { |
| 229 IgnoreNavigation, | 236 IgnoreNavigation, |
| 230 DontIgnoreNavigation | 237 DontIgnoreNavigation |
| 231 }; | 238 }; |
| 232 | 239 |
| 233 void SetUpWebContentsDelegateAndDrainRunLoop( | 240 void SetUpWebContentsDelegateAndDrainRunLoop( |
| 234 ShouldIgnoreNavigationCallbackAction callback_action, | 241 ShouldIgnoreNavigationCallbackAction callback_action, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 REDIRECT_MODE_302, | 473 REDIRECT_MODE_302, |
| 467 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | 474 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), |
| 468 web_contents()->GetMainFrame()->GetRoutingID(), | 475 web_contents()->GetMainFrame()->GetRoutingID(), |
| 469 base::Unretained(&defer))); | 476 base::Unretained(&defer))); |
| 470 | 477 |
| 471 // Wait for the request to finish processing. | 478 // Wait for the request to finish processing. |
| 472 base::RunLoop().RunUntilIdle(); | 479 base::RunLoop().RunUntilIdle(); |
| 473 } | 480 } |
| 474 | 481 |
| 475 } // namespace navigation_interception | 482 } // namespace navigation_interception |
| OLD | NEW |