OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #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) { | |
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->csp_context()->Allow( | |
48 render_frame->content_security_policies(), CSPDirective::FormAction, | |
49 url, is_redirect)) { | |
50 return NavigationThrottle::CANCEL; | |
51 } | |
52 | |
53 return NavigationThrottle::PROCEED; | |
Mike West
2017/02/22 15:36:07
It seems valuable to add some unit tests for this
arthursonzogni
2017/02/22 17:15:23
Acknowledged. It looks hard since it depends on th
arthursonzogni
2017/02/23 13:28:53
Tests added!
| |
54 } | |
55 | |
56 NavigationThrottle::ThrottleCheckResult | |
57 FormSubmissionThrottle::WillStartRequest() { | |
58 return CheckContentSecurityPolicyFormAction(false /* is_redirect */); | |
Mike West
2017/02/22 15:36:07
I might be misunderstanding things, but I thought
arthursonzogni
2017/02/22 17:15:23
I confirm that WillStartRequest is not called twic
| |
59 } | |
60 | |
61 NavigationThrottle::ThrottleCheckResult | |
62 FormSubmissionThrottle::WillRedirectRequest() { | |
63 return CheckContentSecurityPolicyFormAction(true /* is_redirect */); | |
64 } | |
65 | |
66 FormSubmissionThrottle::FormSubmissionThrottle(NavigationHandle* handle) | |
67 : NavigationThrottle(handle) {} | |
68 | |
69 } // namespace content | |
OLD | NEW |