Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 1617043002: Introduce AncestorThrottle, which will process 'X-Frame-Options' headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@block-response
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/frame_host/navigation_handle_impl.h" 5 #include "content/browser/frame_host/navigation_handle_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "content/browser/frame_host/ancestor_throttle.h"
9 #include "content/browser/frame_host/frame_tree_node.h" 10 #include "content/browser/frame_host/frame_tree_node.h"
10 #include "content/browser/frame_host/navigator.h" 11 #include "content/browser/frame_host/navigator.h"
11 #include "content/browser/frame_host/navigator_delegate.h" 12 #include "content/browser/frame_host/navigator_delegate.h"
12 #include "content/browser/service_worker/service_worker_context_wrapper.h" 13 #include "content/browser/service_worker/service_worker_context_wrapper.h"
13 #include "content/browser/service_worker/service_worker_navigation_handle.h" 14 #include "content/browser/service_worker/service_worker_navigation_handle.h"
14 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/common/browser_side_navigation_policy.h" 16 #include "content/public/common/browser_side_navigation_policy.h"
16 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
17 #include "net/url_request/redirect_info.h" 18 #include "net/url_request/redirect_info.h"
18 19
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // Update the navigation parameters. 227 // Update the navigation parameters.
227 is_post_ = is_post; 228 is_post_ = is_post;
228 sanitized_referrer_ = sanitized_referrer; 229 sanitized_referrer_ = sanitized_referrer;
229 has_user_gesture_ = has_user_gesture; 230 has_user_gesture_ = has_user_gesture;
230 transition_ = transition; 231 transition_ = transition;
231 is_external_protocol_ = is_external_protocol; 232 is_external_protocol_ = is_external_protocol;
232 233
233 state_ = WILL_SEND_REQUEST; 234 state_ = WILL_SEND_REQUEST;
234 complete_callback_ = callback; 235 complete_callback_ = callback;
235 236
236 // Register the navigation throttles. The ScopedVector returned by 237 // Register the platform's navigation throttles.
237 // GetNavigationThrottles is not assigned to throttles_ directly because it 238 scoped_ptr<content::NavigationThrottle> ancestor_throttle =
238 // would overwrite any throttle previously added with 239 AncestorThrottle::MaybeCreateThrottleFor(this);
239 // RegisterThrottleForTesting. 240 if (ancestor_throttle)
241 throttles_.push_back(std::move(ancestor_throttle));
242
243 // Register the embedder's navigation throttles.
240 ScopedVector<NavigationThrottle> throttles_to_register = 244 ScopedVector<NavigationThrottle> throttles_to_register =
241 GetContentClient()->browser()->CreateThrottlesForNavigation(this); 245 GetContentClient()->browser()->CreateThrottlesForNavigation(this);
242 if (throttles_to_register.size() > 0) { 246 if (throttles_to_register.size() > 0) {
243 throttles_.insert(throttles_.end(), throttles_to_register.begin(), 247 throttles_.insert(throttles_.end(), throttles_to_register.begin(),
244 throttles_to_register.end()); 248 throttles_to_register.end());
245 throttles_to_register.weak_clear(); 249 throttles_to_register.weak_clear();
246 } 250 }
247 251
248 // Notify each throttle of the request. 252 // Notify each throttle of the request.
249 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); 253 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 case NavigationThrottle::CANCEL: 340 case NavigationThrottle::CANCEL:
337 case NavigationThrottle::CANCEL_AND_IGNORE: 341 case NavigationThrottle::CANCEL_AND_IGNORE:
338 state_ = CANCELING; 342 state_ = CANCELING;
339 return result; 343 return result;
340 344
341 case NavigationThrottle::DEFER: 345 case NavigationThrottle::DEFER:
342 state_ = DEFERRING_START; 346 state_ = DEFERRING_START;
343 next_index_ = i + 1; 347 next_index_ = i + 1;
344 return result; 348 return result;
345 349
346 default: 350 case NavigationThrottle::BLOCK_RESPONSE:
nasko 2016/02/12 23:21:40 Why did we lose the default?
Mike West 2016/04/12 20:13:30 Because this completely enumerates all the options
347 NOTREACHED(); 351 NOTREACHED();
348 } 352 }
349 } 353 }
350 next_index_ = 0; 354 next_index_ = 0;
351 state_ = WILL_SEND_REQUEST; 355 state_ = WILL_SEND_REQUEST;
352 return NavigationThrottle::PROCEED; 356 return NavigationThrottle::PROCEED;
353 } 357 }
354 358
355 NavigationThrottle::ThrottleCheckResult 359 NavigationThrottle::ThrottleCheckResult
356 NavigationHandleImpl::CheckWillRedirectRequest() { 360 NavigationHandleImpl::CheckWillRedirectRequest() {
(...skipping 10 matching lines...) Expand all
367 case NavigationThrottle::CANCEL: 371 case NavigationThrottle::CANCEL:
368 case NavigationThrottle::CANCEL_AND_IGNORE: 372 case NavigationThrottle::CANCEL_AND_IGNORE:
369 state_ = CANCELING; 373 state_ = CANCELING;
370 return result; 374 return result;
371 375
372 case NavigationThrottle::DEFER: 376 case NavigationThrottle::DEFER:
373 state_ = DEFERRING_REDIRECT; 377 state_ = DEFERRING_REDIRECT;
374 next_index_ = i + 1; 378 next_index_ = i + 1;
375 return result; 379 return result;
376 380
377 default: 381 case NavigationThrottle::BLOCK_RESPONSE:
378 NOTREACHED(); 382 NOTREACHED();
379 } 383 }
380 } 384 }
381 next_index_ = 0; 385 next_index_ = 0;
382 state_ = WILL_REDIRECT_REQUEST; 386 state_ = WILL_REDIRECT_REQUEST;
383 return NavigationThrottle::PROCEED; 387 return NavigationThrottle::PROCEED;
384 } 388 }
385 389
386 NavigationThrottle::ThrottleCheckResult 390 NavigationThrottle::ThrottleCheckResult
387 NavigationHandleImpl::CheckWillProcessResponse() { 391 NavigationHandleImpl::CheckWillProcessResponse() {
388 DCHECK(state_ == WILL_PROCESS_RESPONSE && next_index_ == 0); 392 DCHECK(state_ == WILL_PROCESS_RESPONSE && next_index_ == 0);
389 for (size_t i = next_index_; i < throttles_.size(); ++i) { 393 for (size_t i = next_index_; i < throttles_.size(); ++i) {
390 NavigationThrottle::ThrottleCheckResult result = 394 NavigationThrottle::ThrottleCheckResult result =
391 throttles_[i]->WillProcessResponse(); 395 throttles_[i]->WillProcessResponse();
392 switch (result) { 396 switch (result) {
393 case NavigationThrottle::PROCEED: 397 case NavigationThrottle::PROCEED:
394 continue; 398 continue;
395 399
400 case NavigationThrottle::BLOCK_RESPONSE:
396 case NavigationThrottle::CANCEL: 401 case NavigationThrottle::CANCEL:
397 case NavigationThrottle::CANCEL_AND_IGNORE: 402 case NavigationThrottle::CANCEL_AND_IGNORE:
398 state_ = CANCELING; 403 state_ = CANCELING;
399 return result; 404 return result;
400 405
401 case NavigationThrottle::DEFER: 406 case NavigationThrottle::DEFER:
402 NOTREACHED(); 407 NOTREACHED();
403 } 408 }
404 } 409 }
405 state_ = WILL_PROCESS_RESPONSE; 410 state_ = WILL_PROCESS_RESPONSE;
406 return NavigationThrottle::PROCEED; 411 return NavigationThrottle::PROCEED;
407 } 412 }
408 413
409 void NavigationHandleImpl::RunCompleteCallback( 414 void NavigationHandleImpl::RunCompleteCallback(
410 NavigationThrottle::ThrottleCheckResult result) { 415 NavigationThrottle::ThrottleCheckResult result) {
411 DCHECK(result != NavigationThrottle::DEFER); 416 DCHECK(result != NavigationThrottle::DEFER);
412 417
413 if (!complete_callback_.is_null()) { 418 if (!complete_callback_.is_null()) {
414 ThrottleChecksFinishedCallback callback = std::move(complete_callback_); 419 ThrottleChecksFinishedCallback callback = std::move(complete_callback_);
415 callback.Run(result); 420 callback.Run(result);
416 } 421 }
417 422
418 // No code after running the calback, as it might result in our destruction. 423 // No code after running the calback, as it might result in our destruction.
419 } 424 }
420 425
421 } // namespace content 426 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698