| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 8 #include "content/public/browser/navigation_entry.h" | 8 #include "content/public/browser/navigation_entry.h" |
| 9 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 9 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 10 #include "content/public/browser/resource_throttle.h" | 10 #include "content/public/browser/resource_throttle.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 : public ShellResourceDispatcherHostDelegate { | 31 : public ShellResourceDispatcherHostDelegate { |
| 32 public: | 32 public: |
| 33 TrackingResourceDispatcherHostDelegate() : throttle_created_(false) { | 33 TrackingResourceDispatcherHostDelegate() : throttle_created_(false) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 virtual void RequestBeginning( | 36 virtual void RequestBeginning( |
| 37 net::URLRequest* request, | 37 net::URLRequest* request, |
| 38 ResourceContext* resource_context, | 38 ResourceContext* resource_context, |
| 39 AppCacheService* appcache_service, | 39 AppCacheService* appcache_service, |
| 40 ResourceType resource_type, | 40 ResourceType resource_type, |
| 41 ScopedVector<ResourceThrottle>* throttles) OVERRIDE { | 41 ScopedVector<ResourceThrottle>* throttles) override { |
| 42 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 42 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 43 ShellResourceDispatcherHostDelegate::RequestBeginning( | 43 ShellResourceDispatcherHostDelegate::RequestBeginning( |
| 44 request, resource_context, appcache_service, resource_type, throttles); | 44 request, resource_context, appcache_service, resource_type, throttles); |
| 45 // Expect only a single request for the tracked url. | 45 // Expect only a single request for the tracked url. |
| 46 ASSERT_FALSE(throttle_created_); | 46 ASSERT_FALSE(throttle_created_); |
| 47 // If this is a request for the tracked URL, add a throttle to track it. | 47 // If this is a request for the tracked URL, add a throttle to track it. |
| 48 if (request->url() == tracked_url_) | 48 if (request->url() == tracked_url_) |
| 49 throttles->push_back(new TrackingThrottle(request, this)); | 49 throttles->push_back(new TrackingThrottle(request, this)); |
| 50 } | 50 } |
| 51 | 51 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 virtual ~TrackingThrottle() { | 91 virtual ~TrackingThrottle() { |
| 92 // If the request is deleted without being cancelled, its status will | 92 // If the request is deleted without being cancelled, its status will |
| 93 // indicate it succeeded, so have to check if the request is still pending | 93 // indicate it succeeded, so have to check if the request is still pending |
| 94 // as well. | 94 // as well. |
| 95 tracker_->OnTrackedRequestDestroyed( | 95 tracker_->OnTrackedRequestDestroyed( |
| 96 !request_->is_pending() && request_->status().is_success()); | 96 !request_->is_pending() && request_->status().is_success()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // ResourceThrottle implementation: | 99 // ResourceThrottle implementation: |
| 100 virtual const char* GetNameForLogging() const OVERRIDE { | 100 virtual const char* GetNameForLogging() const override { |
| 101 return "TrackingThrottle"; | 101 return "TrackingThrottle"; |
| 102 } | 102 } |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 net::URLRequest* request_; | 105 net::URLRequest* request_; |
| 106 TrackingResourceDispatcherHostDelegate* tracker_; | 106 TrackingResourceDispatcherHostDelegate* tracker_; |
| 107 | 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(TrackingThrottle); | 108 DISALLOW_COPY_AND_ASSIGN(TrackingThrottle); |
| 109 }; | 109 }; |
| 110 | 110 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 138 DISALLOW_COPY_AND_ASSIGN(TrackingResourceDispatcherHostDelegate); | 138 DISALLOW_COPY_AND_ASSIGN(TrackingResourceDispatcherHostDelegate); |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 // WebContentsDelegate that fails to open a URL when there's a request that | 141 // WebContentsDelegate that fails to open a URL when there's a request that |
| 142 // needs to be transferred between renderers. | 142 // needs to be transferred between renderers. |
| 143 class NoTransferRequestDelegate : public WebContentsDelegate { | 143 class NoTransferRequestDelegate : public WebContentsDelegate { |
| 144 public: | 144 public: |
| 145 NoTransferRequestDelegate() {} | 145 NoTransferRequestDelegate() {} |
| 146 | 146 |
| 147 virtual WebContents* OpenURLFromTab(WebContents* source, | 147 virtual WebContents* OpenURLFromTab(WebContents* source, |
| 148 const OpenURLParams& params) OVERRIDE { | 148 const OpenURLParams& params) override { |
| 149 bool is_transfer = | 149 bool is_transfer = |
| 150 (params.transferred_global_request_id != GlobalRequestID()); | 150 (params.transferred_global_request_id != GlobalRequestID()); |
| 151 if (is_transfer) | 151 if (is_transfer) |
| 152 return NULL; | 152 return NULL; |
| 153 NavigationController::LoadURLParams load_url_params(params.url); | 153 NavigationController::LoadURLParams load_url_params(params.url); |
| 154 load_url_params.referrer = params.referrer; | 154 load_url_params.referrer = params.referrer; |
| 155 load_url_params.frame_tree_node_id = params.frame_tree_node_id; | 155 load_url_params.frame_tree_node_id = params.frame_tree_node_id; |
| 156 load_url_params.transition_type = params.transition; | 156 load_url_params.transition_type = params.transition; |
| 157 load_url_params.extra_headers = params.extra_headers; | 157 load_url_params.extra_headers = params.extra_headers; |
| 158 load_url_params.should_replace_current_entry = | 158 load_url_params.should_replace_current_entry = |
| 159 params.should_replace_current_entry; | 159 params.should_replace_current_entry; |
| 160 load_url_params.is_renderer_initiated = true; | 160 load_url_params.is_renderer_initiated = true; |
| 161 source->GetController().LoadURLWithParams(load_url_params); | 161 source->GetController().LoadURLWithParams(load_url_params); |
| 162 return source; | 162 return source; |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 DISALLOW_COPY_AND_ASSIGN(NoTransferRequestDelegate); | 166 DISALLOW_COPY_AND_ASSIGN(NoTransferRequestDelegate); |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 class CrossSiteTransferTest : public ContentBrowserTest { | 169 class CrossSiteTransferTest : public ContentBrowserTest { |
| 170 public: | 170 public: |
| 171 CrossSiteTransferTest() : old_delegate_(NULL) { | 171 CrossSiteTransferTest() : old_delegate_(NULL) { |
| 172 } | 172 } |
| 173 | 173 |
| 174 // ContentBrowserTest implementation: | 174 // ContentBrowserTest implementation: |
| 175 virtual void SetUpOnMainThread() OVERRIDE { | 175 virtual void SetUpOnMainThread() override { |
| 176 BrowserThread::PostTask( | 176 BrowserThread::PostTask( |
| 177 BrowserThread::IO, FROM_HERE, | 177 BrowserThread::IO, FROM_HERE, |
| 178 base::Bind( | 178 base::Bind( |
| 179 &CrossSiteTransferTest::InjectResourceDisptcherHostDelegate, | 179 &CrossSiteTransferTest::InjectResourceDisptcherHostDelegate, |
| 180 base::Unretained(this))); | 180 base::Unretained(this))); |
| 181 } | 181 } |
| 182 | 182 |
| 183 virtual void TearDownOnMainThread() OVERRIDE { | 183 virtual void TearDownOnMainThread() override { |
| 184 BrowserThread::PostTask( | 184 BrowserThread::PostTask( |
| 185 BrowserThread::IO, FROM_HERE, | 185 BrowserThread::IO, FROM_HERE, |
| 186 base::Bind( | 186 base::Bind( |
| 187 &CrossSiteTransferTest::RestoreResourceDisptcherHostDelegate, | 187 &CrossSiteTransferTest::RestoreResourceDisptcherHostDelegate, |
| 188 base::Unretained(this))); | 188 base::Unretained(this))); |
| 189 } | 189 } |
| 190 | 190 |
| 191 protected: | 191 protected: |
| 192 void NavigateToURLContentInitiated(Shell* window, | 192 void NavigateToURLContentInitiated(Shell* window, |
| 193 const GURL& url, | 193 const GURL& url, |
| 194 bool should_replace_current_entry, | 194 bool should_replace_current_entry, |
| 195 bool should_wait_for_navigation) { | 195 bool should_wait_for_navigation) { |
| 196 std::string script; | 196 std::string script; |
| 197 if (should_replace_current_entry) | 197 if (should_replace_current_entry) |
| 198 script = base::StringPrintf("location.replace('%s')", url.spec().c_str()); | 198 script = base::StringPrintf("location.replace('%s')", url.spec().c_str()); |
| 199 else | 199 else |
| 200 script = base::StringPrintf("location.href = '%s'", url.spec().c_str()); | 200 script = base::StringPrintf("location.href = '%s'", url.spec().c_str()); |
| 201 TestNavigationObserver load_observer(shell()->web_contents(), 1); | 201 TestNavigationObserver load_observer(shell()->web_contents(), 1); |
| 202 bool result = ExecuteScript(window->web_contents(), script); | 202 bool result = ExecuteScript(window->web_contents(), script); |
| 203 EXPECT_TRUE(result); | 203 EXPECT_TRUE(result); |
| 204 if (should_wait_for_navigation) | 204 if (should_wait_for_navigation) |
| 205 load_observer.Wait(); | 205 load_observer.Wait(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 208 virtual void SetUpCommandLine(CommandLine* command_line) override { |
| 209 // Use --site-per-process to force process swaps for cross-site transfers. | 209 // Use --site-per-process to force process swaps for cross-site transfers. |
| 210 command_line->AppendSwitch(switches::kSitePerProcess); | 210 command_line->AppendSwitch(switches::kSitePerProcess); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void InjectResourceDisptcherHostDelegate() { | 213 void InjectResourceDisptcherHostDelegate() { |
| 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 215 old_delegate_ = ResourceDispatcherHostImpl::Get()->delegate(); | 215 old_delegate_ = ResourceDispatcherHostImpl::Get()->delegate(); |
| 216 ResourceDispatcherHostImpl::Get()->SetDelegate(&tracking_delegate_); | 216 ResourceDispatcherHostImpl::Get()->SetDelegate(&tracking_delegate_); |
| 217 } | 217 } |
| 218 | 218 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 454 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 455 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); | 455 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); |
| 456 | 456 |
| 457 // Make sure the request for url2 did not complete. | 457 // Make sure the request for url2 did not complete. |
| 458 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); | 458 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); |
| 459 | 459 |
| 460 shell()->web_contents()->SetDelegate(old_delegate); | 460 shell()->web_contents()->SetDelegate(old_delegate); |
| 461 } | 461 } |
| 462 | 462 |
| 463 } // namespace content | 463 } // namespace content |
| OLD | NEW |