| 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_CROSS_SITE_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_CROSS_SITE_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_CROSS_SITE_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_CROSS_SITE_RESOURCE_HANDLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "content/browser/renderer_host/layered_resource_handler.h" | 9 #include "content/browser/renderer_host/layered_resource_handler.h" |
| 10 #include "net/url_request/url_request_status.h" | 10 #include "net/url_request/url_request_status.h" |
| 11 | 11 |
| 12 namespace net { |
| 13 class URLRequest; |
| 14 } |
| 15 |
| 12 namespace content { | 16 namespace content { |
| 13 class ResourceDispatcherHostImpl; | |
| 14 struct GlobalRequestID; | |
| 15 | 17 |
| 16 // Ensures that cross-site responses are delayed until the onunload handler of | 18 // Ensures that cross-site responses are delayed until the onunload handler of |
| 17 // the previous page is allowed to run. This handler wraps an | 19 // the previous page is allowed to run. This handler wraps an |
| 18 // AsyncEventHandler, and it sits inside SafeBrowsing and Buffered event | 20 // AsyncEventHandler, and it sits inside SafeBrowsing and Buffered event |
| 19 // handlers. This is important, so that it can intercept OnResponseStarted | 21 // handlers. This is important, so that it can intercept OnResponseStarted |
| 20 // after we determine that a response is safe and not a download. | 22 // after we determine that a response is safe and not a download. |
| 21 class CrossSiteResourceHandler : public LayeredResourceHandler { | 23 class CrossSiteResourceHandler : public LayeredResourceHandler { |
| 22 public: | 24 public: |
| 23 CrossSiteResourceHandler(scoped_ptr<ResourceHandler> next_handler, | 25 CrossSiteResourceHandler(scoped_ptr<ResourceHandler> next_handler, |
| 24 int render_process_host_id, | 26 int render_process_host_id, |
| 25 int render_view_id, | 27 int render_view_id, |
| 26 ResourceDispatcherHostImpl* rdh); | 28 net::URLRequest* request); |
| 27 virtual ~CrossSiteResourceHandler(); | 29 virtual ~CrossSiteResourceHandler(); |
| 28 | 30 |
| 29 // ResourceHandler implementation: | 31 // ResourceHandler implementation: |
| 30 virtual bool OnRequestRedirected(int request_id, | 32 virtual bool OnRequestRedirected(int request_id, |
| 31 const GURL& new_url, | 33 const GURL& new_url, |
| 32 ResourceResponse* response, | 34 ResourceResponse* response, |
| 33 bool* defer) OVERRIDE; | 35 bool* defer) OVERRIDE; |
| 34 virtual bool OnResponseStarted(int request_id, | 36 virtual bool OnResponseStarted(int request_id, |
| 35 ResourceResponse* response, | 37 ResourceResponse* response, |
| 36 bool* defer) OVERRIDE; | 38 bool* defer) OVERRIDE; |
| 37 virtual bool OnReadCompleted(int request_id, | 39 virtual bool OnReadCompleted(int request_id, |
| 38 int* bytes_read, | 40 int* bytes_read, |
| 39 bool* defer) OVERRIDE; | 41 bool* defer) OVERRIDE; |
| 40 virtual bool OnResponseCompleted(int request_id, | 42 virtual bool OnResponseCompleted(int request_id, |
| 41 const net::URLRequestStatus& status, | 43 const net::URLRequestStatus& status, |
| 42 const std::string& security_info) OVERRIDE; | 44 const std::string& security_info) OVERRIDE; |
| 43 | 45 |
| 44 // We can now send the response to the new renderer, which will cause | 46 // We can now send the response to the new renderer, which will cause |
| 45 // WebContentsImpl to swap in the new renderer and destroy the old one. | 47 // WebContentsImpl to swap in the new renderer and destroy the old one. |
| 46 void ResumeResponse(); | 48 void ResumeResponse(); |
| 47 | 49 |
| 48 private: | 50 private: |
| 49 // Prepare to render the cross-site response in a new RenderViewHost, by | 51 // Prepare to render the cross-site response in a new RenderViewHost, by |
| 50 // telling the old RenderViewHost to run its onunload handler. | 52 // telling the old RenderViewHost to run its onunload handler. |
| 51 void StartCrossSiteTransition( | 53 void StartCrossSiteTransition( |
| 52 int request_id, | 54 int request_id, |
| 53 ResourceResponse* response, | 55 ResourceResponse* response, |
| 54 const GlobalRequestID& global_id, | |
| 55 bool* defer); | 56 bool* defer); |
| 56 | 57 |
| 57 void ResumeIfDeferred(); | 58 void ResumeIfDeferred(); |
| 58 | 59 |
| 59 int render_process_host_id_; | 60 int render_process_host_id_; |
| 60 int render_view_id_; | 61 int render_view_id_; |
| 62 net::URLRequest* request_; |
| 61 bool has_started_response_; | 63 bool has_started_response_; |
| 62 bool in_cross_site_transition_; | 64 bool in_cross_site_transition_; |
| 63 int request_id_; | 65 int request_id_; |
| 64 bool completed_during_transition_; | 66 bool completed_during_transition_; |
| 65 bool did_defer_; | 67 bool did_defer_; |
| 66 net::URLRequestStatus completed_status_; | 68 net::URLRequestStatus completed_status_; |
| 67 std::string completed_security_info_; | 69 std::string completed_security_info_; |
| 68 ResourceResponse* response_; | 70 ResourceResponse* response_; |
| 69 ResourceDispatcherHostImpl* rdh_; | |
| 70 | 71 |
| 71 DISALLOW_COPY_AND_ASSIGN(CrossSiteResourceHandler); | 72 DISALLOW_COPY_AND_ASSIGN(CrossSiteResourceHandler); |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 } // namespace content | 75 } // namespace content |
| 75 | 76 |
| 76 #endif // CONTENT_BROWSER_RENDERER_HOST_CROSS_SITE_RESOURCE_HANDLER_H_ | 77 #endif // CONTENT_BROWSER_RENDERER_HOST_CROSS_SITE_RESOURCE_HANDLER_H_ |
| OLD | NEW |