| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/browser/loader/layered_resource_handler.h" |
| 12 #include "content/common/content_export.h" |
| 13 #include "net/url_request/url_request_status.h" |
| 14 |
| 15 namespace net { |
| 16 class URLRequest; |
| 17 } |
| 18 |
| 19 namespace content { |
| 20 |
| 21 struct TransitionLayerData; |
| 22 |
| 23 // Ensures that responses are delayed for navigations that must be transferred |
| 24 // to a different process. This handler wraps an AsyncEventHandler, and it sits |
| 25 // inside SafeBrowsing and Buffered event handlers. This is important, so that |
| 26 // it can intercept OnResponseStarted after we determine that a response is safe |
| 27 // and not a download. |
| 28 class CrossSiteResourceHandler : public LayeredResourceHandler { |
| 29 public: |
| 30 enum class NavigationDecision { |
| 31 TRANSFER_REQUIRED, |
| 32 USE_EXISTING_RENDERER, |
| 33 CANCEL_REQUEST |
| 34 }; |
| 35 |
| 36 CrossSiteResourceHandler(std::unique_ptr<ResourceHandler> next_handler, |
| 37 net::URLRequest* request); |
| 38 ~CrossSiteResourceHandler() override; |
| 39 |
| 40 // ResourceHandler implementation: |
| 41 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 42 ResourceResponse* response, |
| 43 bool* defer) override; |
| 44 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| 45 bool OnReadCompleted(int bytes_read, bool* defer) override; |
| 46 void OnResponseCompleted(const net::URLRequestStatus& status, |
| 47 bool* defer) override; |
| 48 |
| 49 // We can now send the response to the new renderer, which will cause |
| 50 // WebContentsImpl to swap in the new renderer and destroy the old one. |
| 51 void ResumeResponse(); |
| 52 |
| 53 // When set to true, requests are leaked when they can't be passed to a |
| 54 // RenderViewHost, for unit tests. |
| 55 CONTENT_EXPORT static void SetLeakRequestsForTesting( |
| 56 bool leak_requests_for_testing); |
| 57 |
| 58 private: |
| 59 // Prepare to transfer the cross-site response to a new RenderFrameHost, by |
| 60 // asking it to issue an identical request (on the UI thread). |
| 61 void StartCrossSiteTransition(ResourceResponse* response); |
| 62 |
| 63 // Defer the navigation to the UI thread to check whether transfer is required |
| 64 // or not. Currently only used in --site-per-process. |
| 65 bool DeferForNavigationPolicyCheck(ResourceRequestInfoImpl* info, |
| 66 ResourceResponse* response, |
| 67 bool* defer); |
| 68 |
| 69 bool OnNormalResponseStarted(ResourceResponse* response, |
| 70 bool* defer); |
| 71 |
| 72 void ResumeOrTransfer(NavigationDecision decision); |
| 73 void ResumeIfDeferred(); |
| 74 |
| 75 // Called when about to defer a request. Sets |did_defer_| and logs the |
| 76 // defferral |
| 77 void OnDidDefer(); |
| 78 |
| 79 bool has_started_response_; |
| 80 bool in_cross_site_transition_; |
| 81 bool completed_during_transition_; |
| 82 bool did_defer_; |
| 83 net::URLRequestStatus completed_status_; |
| 84 scoped_refptr<ResourceResponse> response_; |
| 85 |
| 86 // TODO(nasko): WeakPtr is needed in --site-per-process, since all navigations |
| 87 // are deferred to the UI thread and come back to IO thread via |
| 88 // PostTaskAndReplyWithResult. If a transfer is needed, it goes back to the UI |
| 89 // thread. This can be removed once the code is changed to only do one hop. |
| 90 base::WeakPtrFactory<CrossSiteResourceHandler> weak_ptr_factory_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(CrossSiteResourceHandler); |
| 93 }; |
| 94 |
| 95 } // namespace content |
| 96 |
| 97 #endif // CONTENT_BROWSER_LOADER_CROSS_SITE_RESOURCE_HANDLER_H_ |
| OLD | NEW |