Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
nasko
2017/03/16 21:49:46
nit: 2017
alexmos
2017/03/16 23:05:35
nit: 2017
arthursonzogni
2017/03/17 14:58:24
Done.
arthursonzogni
2017/03/17 14:58:24
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/frame_host/form_submission_throttle.h" | |
| 6 #include "content/browser/frame_host/navigation_handle_impl.h" | |
| 7 #include "content/public/browser/browser_thread.h" | |
| 8 #include "content/public/browser/navigation_handle.h" | |
| 9 #include "content/public/browser/navigation_throttle.h" | |
| 10 #include "content/public/common/browser_side_navigation_policy.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 // static | |
| 15 std::unique_ptr<NavigationThrottle> | |
| 16 FormSubmissionThrottle::MaybeCreateThrottleFor(NavigationHandle* handle) { | |
| 17 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 18 | |
| 19 if (!IsBrowserSideNavigationEnabled()) | |
| 20 return nullptr; | |
| 21 | |
| 22 NavigationHandleImpl* handle_impl = | |
| 23 static_cast<NavigationHandleImpl*>(handle); | |
| 24 | |
| 25 if (!handle_impl->is_form_submission()) | |
| 26 return nullptr; | |
| 27 | |
| 28 return std::unique_ptr<NavigationThrottle>( | |
| 29 new FormSubmissionThrottle(handle)); | |
| 30 } | |
| 31 | |
| 32 FormSubmissionThrottle::~FormSubmissionThrottle() {} | |
| 33 | |
| 34 NavigationThrottle::ThrottleCheckResult | |
| 35 FormSubmissionThrottle::CheckContentSecurityPolicyFormAction(bool is_redirect) { | |
|
nasko
2017/03/16 21:49:46
The method ordering in the .cc file should match t
arthursonzogni
2017/03/17 14:58:24
Done.
| |
| 36 NavigationHandleImpl* handle = | |
| 37 static_cast<NavigationHandleImpl*>(navigation_handle()); | |
| 38 | |
| 39 // Allow the request when it bypasses the CSP. | |
| 40 if (handle->should_bypass_main_world_csp()) | |
| 41 return NavigationThrottle::PROCEED; | |
| 42 | |
| 43 const GURL& url = handle->GetURL(); | |
| 44 RenderFrameHostImpl* render_frame = | |
| 45 handle->frame_tree_node()->current_frame_host(); | |
| 46 | |
| 47 if (!render_frame->IsAllowedByCsp(CSPDirective::FormAction, url, is_redirect)) | |
| 48 return NavigationThrottle::CANCEL; | |
|
nasko
2017/03/16 21:49:46
I would invert the if statement and return PROCEED
arthursonzogni
2017/03/17 14:58:24
Done.
| |
| 49 | |
| 50 return NavigationThrottle::PROCEED; | |
| 51 } | |
| 52 | |
| 53 NavigationThrottle::ThrottleCheckResult | |
| 54 FormSubmissionThrottle::WillStartRequest() { | |
| 55 return CheckContentSecurityPolicyFormAction(false /* is_redirect */); | |
| 56 } | |
| 57 | |
| 58 NavigationThrottle::ThrottleCheckResult | |
| 59 FormSubmissionThrottle::WillRedirectRequest() { | |
| 60 return CheckContentSecurityPolicyFormAction(true /* is_redirect */); | |
| 61 } | |
| 62 | |
| 63 FormSubmissionThrottle::FormSubmissionThrottle(NavigationHandle* handle) | |
| 64 : NavigationThrottle(handle) {} | |
| 65 | |
| 66 } // namespace content | |
| OLD | NEW |