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_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ |
6 #define CONTENT_BROWSER_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "content/browser/loader/layered_resource_handler.h" | 10 #include "content/browser/loader/layered_resource_handler.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 #include "net/url_request/url_request_status.h" | 12 #include "net/url_request/url_request_status.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 class URLRequest; | 15 class URLRequest; |
16 } | 16 } |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 struct TransitionLayerData; | 20 struct TransitionLayerData; |
21 | 21 |
22 // Ensures that cross-site responses are delayed until the onunload handler of | 22 // Ensures that responses are delayed for navigations that must be transferred |
23 // the previous page is allowed to run. This handler wraps an | 23 // to a different process. This handler wraps an AsyncEventHandler, and it sits |
24 // AsyncEventHandler, and it sits inside SafeBrowsing and Buffered event | 24 // inside SafeBrowsing and Buffered event handlers. This is important, so that |
25 // handlers. This is important, so that it can intercept OnResponseStarted | 25 // it can intercept OnResponseStarted after we determine that a response is safe |
26 // after we determine that a response is safe and not a download. | 26 // and not a download. |
27 class CrossSiteResourceHandler : public LayeredResourceHandler { | 27 class CrossSiteResourceHandler : public LayeredResourceHandler { |
28 public: | 28 public: |
29 CrossSiteResourceHandler(scoped_ptr<ResourceHandler> next_handler, | 29 CrossSiteResourceHandler(scoped_ptr<ResourceHandler> next_handler, |
30 net::URLRequest* request); | 30 net::URLRequest* request); |
31 virtual ~CrossSiteResourceHandler(); | 31 virtual ~CrossSiteResourceHandler(); |
32 | 32 |
33 // ResourceHandler implementation: | 33 // ResourceHandler implementation: |
34 virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 34 virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
35 ResourceResponse* response, | 35 ResourceResponse* response, |
36 bool* defer) OVERRIDE; | 36 bool* defer) OVERRIDE; |
(...skipping 16 matching lines...) Expand all Loading... |
53 | 53 |
54 // Navigations are deferred at OnResponseStarted to parse out any navigation | 54 // Navigations are deferred at OnResponseStarted to parse out any navigation |
55 // transition link headers, and give the navigation transition (if it exists) | 55 // transition link headers, and give the navigation transition (if it exists) |
56 // a chance to run. | 56 // a chance to run. |
57 void ResumeResponseDeferredAtStart(int request_id); | 57 void ResumeResponseDeferredAtStart(int request_id); |
58 | 58 |
59 // Returns whether the handler is deferred. | 59 // Returns whether the handler is deferred. |
60 bool did_defer_for_testing() const { return did_defer_; } | 60 bool did_defer_for_testing() const { return did_defer_; } |
61 | 61 |
62 private: | 62 private: |
63 // Prepare to render the cross-site response in a new RenderViewHost, by | 63 // Prepare to transfer the cross-site response to a new RenderFrameHost, by |
64 // telling the old RenderViewHost to run its onunload handler. | 64 // asking it to issue an identical request (on the UI thread). |
65 void StartCrossSiteTransition(ResourceResponse* response, | 65 void StartCrossSiteTransition(ResourceResponse* response); |
66 bool should_transfer); | |
67 | 66 |
68 // Defer the navigation to the UI thread to check whether transfer is required | 67 // Defer the navigation to the UI thread to check whether transfer is required |
69 // or not. Currently only used in --site-per-process. | 68 // or not. Currently only used in --site-per-process. |
70 bool DeferForNavigationPolicyCheck(ResourceRequestInfoImpl* info, | 69 bool DeferForNavigationPolicyCheck(ResourceRequestInfoImpl* info, |
71 ResourceResponse* response, | 70 ResourceResponse* response, |
72 bool* defer); | 71 bool* defer); |
73 | 72 |
74 bool OnNavigationTransitionResponseStarted( | 73 bool OnNavigationTransitionResponseStarted( |
75 ResourceResponse* response, | 74 ResourceResponse* response, |
76 bool* defer, | 75 bool* defer, |
(...skipping 22 matching lines...) Expand all Loading... |
99 // PostTaskAndReplyWithResult. If a transfer is needed, it goes back to the UI | 98 // PostTaskAndReplyWithResult. If a transfer is needed, it goes back to the UI |
100 // thread. This can be removed once the code is changed to only do one hop. | 99 // thread. This can be removed once the code is changed to only do one hop. |
101 base::WeakPtrFactory<CrossSiteResourceHandler> weak_ptr_factory_; | 100 base::WeakPtrFactory<CrossSiteResourceHandler> weak_ptr_factory_; |
102 | 101 |
103 DISALLOW_COPY_AND_ASSIGN(CrossSiteResourceHandler); | 102 DISALLOW_COPY_AND_ASSIGN(CrossSiteResourceHandler); |
104 }; | 103 }; |
105 | 104 |
106 } // namespace content | 105 } // namespace content |
107 | 106 |
108 #endif // CONTENT_BROWSER_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ | 107 #endif // CONTENT_BROWSER_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ |
OLD | NEW |