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

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

Issue 2655463006: PlzNavigate: Enforce 'frame-src' CSP on the browser. (Closed)
Patch Set: Addressed comments Created 3 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/render_frame_host_impl.h" 5 #include "content/browser/frame_host/render_frame_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 DCHECK_EQ(site_instance_.get(), site_instance); 856 DCHECK_EQ(site_instance_.get(), site_instance);
857 857
858 // The renderer process is gone, so this frame can no longer be loading. 858 // The renderer process is gone, so this frame can no longer be loading.
859 ResetLoadingState(); 859 ResetLoadingState();
860 860
861 // Any future UpdateState or UpdateTitle messages from this or a recreated 861 // Any future UpdateState or UpdateTitle messages from this or a recreated
862 // process should be ignored until the next commit. 862 // process should be ignored until the next commit.
863 set_nav_entry_id(0); 863 set_nav_entry_id(0);
864 } 864 }
865 865
866 void RenderFrameHostImpl::LogToConsole(const std::string& message) {
867 AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_ERROR, message);
868 }
869
870 void RenderFrameHostImpl::ReportContentSecurityPolicyViolation(
871 const CSPViolationParams& violation_params) {
872 Send(new FrameMsg_ReportContentSecurityPolicyViolation(routing_id_,
873 violation_params));
874 }
875
876 bool RenderFrameHostImpl::SchemeShouldBypassCSP(
877 const base::StringPiece& scheme) {
878 // Blink uses its SchemeRegistry to check if a scheme should be bypassed.
879 // It can't be used on the browser process. It is used for two things:
880 // 1) Bypassing the "chrome-extension" scheme when chrome is built with the
881 // extensions support.
882 // 2) Bypassing arbitrary scheme for testing purpose only in blink and in V8.
883 // TODO(arthursonzogni): url::GetBypassingCSPScheme() is used instead of the
884 // blink::SchemeRegistry. It contains 1) but not 2).
885 const auto& bypassing_schemes = url::GetCSPBypassingSchemes();
886 return std::find(bypassing_schemes.begin(), bypassing_schemes.end(),
887 scheme) != bypassing_schemes.end();
888 }
889
866 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id, 890 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id,
867 int opener_routing_id, 891 int opener_routing_id,
868 int parent_routing_id, 892 int parent_routing_id,
869 int previous_sibling_routing_id) { 893 int previous_sibling_routing_id) {
870 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); 894 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
871 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; 895 DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
872 896
873 // The process may (if we're sharing a process with another host that already 897 // The process may (if we're sharing a process with another host that already
874 // initialized it) or may not (we have our own process or the old process 898 // initialized it) or may not (we have our own process or the old process
875 // crashed) have been initialized. Calling Init multiple times will be 899 // crashed) have been initialized. Calling Init multiple times will be
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 if (frame_tree_node_->current_frame_host() == this) { 1078 if (frame_tree_node_->current_frame_host() == this) {
1055 delegate_->CreateNewWindow(GetSiteInstance(), render_view_route_id, 1079 delegate_->CreateNewWindow(GetSiteInstance(), render_view_route_id,
1056 main_frame_route_id, main_frame_widget_route_id, 1080 main_frame_route_id, main_frame_widget_route_id,
1057 *validated_params, session_storage_namespace); 1081 *validated_params, session_storage_namespace);
1058 } 1082 }
1059 1083
1060 // Our caller (RenderWidgetHelper::OnCreateNewWindowOnUI) will send 1084 // Our caller (RenderWidgetHelper::OnCreateNewWindowOnUI) will send
1061 // ViewMsg_Close if the above step did not adopt |main_frame_route_id|. 1085 // ViewMsg_Close if the above step did not adopt |main_frame_route_id|.
1062 } 1086 }
1063 1087
1088 void RenderFrameHostImpl::SetLastCommittedOrigin(const url::Origin& origin) {
1089 last_committed_origin_ = origin;
1090 CSPContext::SetSelf(origin);
1091 }
1092
1064 void RenderFrameHostImpl::OnDetach() { 1093 void RenderFrameHostImpl::OnDetach() {
1065 frame_tree_->RemoveFrame(frame_tree_node_); 1094 frame_tree_->RemoveFrame(frame_tree_node_);
1066 } 1095 }
1067 1096
1068 void RenderFrameHostImpl::OnFrameFocused() { 1097 void RenderFrameHostImpl::OnFrameFocused() {
1069 delegate_->SetFocusedFrame(frame_tree_node_, GetSiteInstance()); 1098 delegate_->SetFocusedFrame(frame_tree_node_, GetSiteInstance());
1070 } 1099 }
1071 1100
1072 void RenderFrameHostImpl::OnOpenURL(const FrameHostMsg_OpenURL_Params& params) { 1101 void RenderFrameHostImpl::OnOpenURL(const FrameHostMsg_OpenURL_Params& params) {
1073 GURL validated_url(params.url); 1102 GURL validated_url(params.url);
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 void RenderFrameHostImpl::OnDidSetFeaturePolicyHeader( 1842 void RenderFrameHostImpl::OnDidSetFeaturePolicyHeader(
1814 const ParsedFeaturePolicyHeader& parsed_header) { 1843 const ParsedFeaturePolicyHeader& parsed_header) {
1815 frame_tree_node()->SetFeaturePolicyHeader(parsed_header); 1844 frame_tree_node()->SetFeaturePolicyHeader(parsed_header);
1816 ResetFeaturePolicy(); 1845 ResetFeaturePolicy();
1817 feature_policy_->SetHeaderPolicy(parsed_header); 1846 feature_policy_->SetHeaderPolicy(parsed_header);
1818 } 1847 }
1819 1848
1820 void RenderFrameHostImpl::OnDidAddContentSecurityPolicy( 1849 void RenderFrameHostImpl::OnDidAddContentSecurityPolicy(
1821 const ContentSecurityPolicyHeader& header, 1850 const ContentSecurityPolicyHeader& header,
1822 const std::vector<ContentSecurityPolicy>& policies) { 1851 const std::vector<ContentSecurityPolicy>& policies) {
1823 frame_tree_node()->AddContentSecurityPolicy(header, policies); 1852 frame_tree_node()->AddContentSecurityPolicy(header);
1853 for (const ContentSecurityPolicy& policy : policies)
1854 AddContentSecurityPolicy(policy);
1824 } 1855 }
1825 1856
1826 void RenderFrameHostImpl::OnEnforceInsecureRequestPolicy( 1857 void RenderFrameHostImpl::OnEnforceInsecureRequestPolicy(
1827 blink::WebInsecureRequestPolicy policy) { 1858 blink::WebInsecureRequestPolicy policy) {
1828 frame_tree_node()->SetInsecureRequestPolicy(policy); 1859 frame_tree_node()->SetInsecureRequestPolicy(policy);
1829 } 1860 }
1830 1861
1831 void RenderFrameHostImpl::OnUpdateToUniqueOrigin( 1862 void RenderFrameHostImpl::OnUpdateToUniqueOrigin(
1832 bool is_potentially_trustworthy_unique_origin) { 1863 bool is_potentially_trustworthy_unique_origin) {
1833 url::Origin origin; 1864 url::Origin origin;
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
2501 OnDidStartLoading(true); 2532 OnDidStartLoading(true);
2502 } 2533 }
2503 } 2534 }
2504 2535
2505 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) { 2536 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
2506 DCHECK(data_url.SchemeIs(url::kDataScheme)); 2537 DCHECK(data_url.SchemeIs(url::kDataScheme));
2507 CommonNavigationParams common_params( 2538 CommonNavigationParams common_params(
2508 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, 2539 data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
2509 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT, false, false, 2540 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT, false, false,
2510 base::TimeTicks::Now(), FrameMsg_UILoadMetricsReportType::NO_REPORT, 2541 base::TimeTicks::Now(), FrameMsg_UILoadMetricsReportType::NO_REPORT,
2511 GURL(), GURL(), PREVIEWS_OFF, base::TimeTicks::Now(), "GET", nullptr); 2542 GURL(), GURL(), PREVIEWS_OFF, base::TimeTicks::Now(), "GET", nullptr,
2543 false /* should_bypass_main_world_csp */);
2512 if (IsBrowserSideNavigationEnabled()) { 2544 if (IsBrowserSideNavigationEnabled()) {
2513 CommitNavigation(nullptr, nullptr, common_params, RequestNavigationParams(), 2545 CommitNavigation(nullptr, nullptr, common_params, RequestNavigationParams(),
2514 false); 2546 false);
2515 } else { 2547 } else {
2516 Navigate(common_params, StartNavigationParams(), RequestNavigationParams()); 2548 Navigate(common_params, StartNavigationParams(), RequestNavigationParams());
2517 } 2549 }
2518 } 2550 }
2519 2551
2520 void RenderFrameHostImpl::Stop() { 2552 void RenderFrameHostImpl::Stop() {
2521 Send(new FrameMsg_Stop(routing_id_)); 2553 Send(new FrameMsg_Stop(routing_id_));
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
3426 NavigationEntryImpl::FromNavigationEntry( 3458 NavigationEntryImpl::FromNavigationEntry(
3427 frame_tree_node()->navigator()->GetController()->GetPendingEntry()); 3459 frame_tree_node()->navigator()->GetController()->GetPendingEntry());
3428 if (pending_entry && pending_entry->GetUniqueID() == params.nav_entry_id) { 3460 if (pending_entry && pending_entry->GetUniqueID() == params.nav_entry_id) {
3429 pending_nav_entry_id = params.nav_entry_id; 3461 pending_nav_entry_id = params.nav_entry_id;
3430 is_renderer_initiated = pending_entry->is_renderer_initiated(); 3462 is_renderer_initiated = pending_entry->is_renderer_initiated();
3431 } 3463 }
3432 3464
3433 return NavigationHandleImpl::Create( 3465 return NavigationHandleImpl::Create(
3434 params.url, params.redirects, frame_tree_node_, is_renderer_initiated, 3466 params.url, params.redirects, frame_tree_node_, is_renderer_initiated,
3435 params.was_within_same_page, base::TimeTicks::Now(), 3467 params.was_within_same_page, base::TimeTicks::Now(),
3436 pending_nav_entry_id, false); // started_from_context_menu 3468 pending_nav_entry_id,
3469 false, // started_from_context_menu
3470 false); // should_bypass_main_world_csp
3437 } 3471 }
3438 3472
3439 // Determine if the current NavigationHandle can be used. 3473 // Determine if the current NavigationHandle can be used.
3440 if (navigation_handle_ && navigation_handle_->GetURL() == params.url) { 3474 if (navigation_handle_ && navigation_handle_->GetURL() == params.url) {
3441 return std::move(navigation_handle_); 3475 return std::move(navigation_handle_);
3442 } 3476 }
3443 3477
3444 // If the URL does not match what the NavigationHandle expects, treat the 3478 // If the URL does not match what the NavigationHandle expects, treat the
3445 // commit as a new navigation. This can happen when loading a Data 3479 // commit as a new navigation. This can happen when loading a Data
3446 // navigation with LoadDataWithBaseURL. 3480 // navigation with LoadDataWithBaseURL.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3478 // Reset any existing NavigationHandle. 3512 // Reset any existing NavigationHandle.
3479 navigation_handle_.reset(); 3513 navigation_handle_.reset();
3480 } 3514 }
3481 3515
3482 // There is no pending NavigationEntry in these cases, so pass 0 as the 3516 // There is no pending NavigationEntry in these cases, so pass 0 as the
3483 // pending_nav_entry_id. If the previous handle was a prematurely aborted 3517 // pending_nav_entry_id. If the previous handle was a prematurely aborted
3484 // navigation loaded via LoadDataWithBaseURL, propagate the entry id. 3518 // navigation loaded via LoadDataWithBaseURL, propagate the entry id.
3485 return NavigationHandleImpl::Create( 3519 return NavigationHandleImpl::Create(
3486 params.url, params.redirects, frame_tree_node_, is_renderer_initiated, 3520 params.url, params.redirects, frame_tree_node_, is_renderer_initiated,
3487 params.was_within_same_page, base::TimeTicks::Now(), 3521 params.was_within_same_page, base::TimeTicks::Now(),
3488 entry_id_for_data_nav, false); // started_from_context_menu 3522 entry_id_for_data_nav,
3523 false, // started_from_context_menu
3524 false); // should_bypass_main_world_csp
3489 } 3525 }
3490 3526
3491 #if defined(OS_ANDROID) 3527 #if defined(OS_ANDROID)
3492 base::android::ScopedJavaLocalRef<jobject> 3528 base::android::ScopedJavaLocalRef<jobject>
3493 RenderFrameHostImpl::GetJavaRenderFrameHost() { 3529 RenderFrameHostImpl::GetJavaRenderFrameHost() {
3494 RenderFrameHostAndroid* render_frame_host_android = 3530 RenderFrameHostAndroid* render_frame_host_android =
3495 static_cast<RenderFrameHostAndroid*>( 3531 static_cast<RenderFrameHostAndroid*>(
3496 GetUserData(kRenderFrameHostAndroidKey)); 3532 GetUserData(kRenderFrameHostAndroidKey));
3497 if (!render_frame_host_android) { 3533 if (!render_frame_host_android) {
3498 render_frame_host_android = new RenderFrameHostAndroid(this); 3534 render_frame_host_android = new RenderFrameHostAndroid(this);
3499 SetUserData(kRenderFrameHostAndroidKey, render_frame_host_android); 3535 SetUserData(kRenderFrameHostAndroidKey, render_frame_host_android);
3500 } 3536 }
3501 return render_frame_host_android->GetJavaObject(); 3537 return render_frame_host_android->GetJavaObject();
3502 } 3538 }
3503 #endif 3539 #endif
3504 3540
3505 } // namespace content 3541 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698