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

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 @alexmos. Created 3 years, 10 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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 DCHECK_EQ(site_instance_.get(), site_instance); 848 DCHECK_EQ(site_instance_.get(), site_instance);
849 849
850 // The renderer process is gone, so this frame can no longer be loading. 850 // The renderer process is gone, so this frame can no longer be loading.
851 ResetLoadingState(); 851 ResetLoadingState();
852 852
853 // Any future UpdateState or UpdateTitle messages from this or a recreated 853 // Any future UpdateState or UpdateTitle messages from this or a recreated
854 // process should be ignored until the next commit. 854 // process should be ignored until the next commit.
855 set_nav_entry_id(0); 855 set_nav_entry_id(0);
856 } 856 }
857 857
858 void RenderFrameHostImpl::LogToConsole(const std::string& message) {
859 AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_ERROR, message);
860 }
861
862 void RenderFrameHostImpl::ReportContentSecurityPolicyViolation(
863 const CSPViolationParams& violation_params) {
864 Send(new FrameMsg_ReportContentSecurityPolicyViolation(routing_id_,
865 violation_params));
866 }
867
868 bool RenderFrameHostImpl::SchemeShouldBypassCSP(
869 const base::StringPiece& scheme) {
870 // Blink uses its SchemeRegistry to check if a scheme should be bypassed.
871 // It can't be used on the browser process. It is used for two things:
872 // 1) Bypassing the "chrome-extension" scheme when chrome is built with the
873 // extensions support.
874 // 2) Bypassing arbitrary scheme for testing purpose only in blink and in V8.
875 // TODO(arthursonzogni): url::GetBypassingCSPScheme() is used instead of the
876 // blink::SchemeRegistry. It contains 1) but not 2).
877 const auto& bypassing_schemes = url::GetCSPBypassingSchemes();
878 return std::find(bypassing_schemes.begin(), bypassing_schemes.end(),
879 scheme) != bypassing_schemes.end();
880 }
881
858 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id, 882 bool RenderFrameHostImpl::CreateRenderFrame(int proxy_routing_id,
859 int opener_routing_id, 883 int opener_routing_id,
860 int parent_routing_id, 884 int parent_routing_id,
861 int previous_sibling_routing_id) { 885 int previous_sibling_routing_id) {
862 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); 886 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
863 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; 887 DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
864 888
865 // The process may (if we're sharing a process with another host that already 889 // The process may (if we're sharing a process with another host that already
866 // initialized it) or may not (we have our own process or the old process 890 // initialized it) or may not (we have our own process or the old process
867 // crashed) have been initialized. Calling Init multiple times will be 891 // crashed) have been initialized. Calling Init multiple times will be
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 void RenderFrameHostImpl::OnDidSetFeaturePolicyHeader( 1830 void RenderFrameHostImpl::OnDidSetFeaturePolicyHeader(
1807 const ParsedFeaturePolicyHeader& parsed_header) { 1831 const ParsedFeaturePolicyHeader& parsed_header) {
1808 frame_tree_node()->SetFeaturePolicyHeader(parsed_header); 1832 frame_tree_node()->SetFeaturePolicyHeader(parsed_header);
1809 ResetFeaturePolicy(); 1833 ResetFeaturePolicy();
1810 feature_policy_->SetHeaderPolicy(parsed_header); 1834 feature_policy_->SetHeaderPolicy(parsed_header);
1811 } 1835 }
1812 1836
1813 void RenderFrameHostImpl::OnDidAddContentSecurityPolicy( 1837 void RenderFrameHostImpl::OnDidAddContentSecurityPolicy(
1814 const ContentSecurityPolicyHeader& header, 1838 const ContentSecurityPolicyHeader& header,
1815 const std::vector<ContentSecurityPolicy>& policies) { 1839 const std::vector<ContentSecurityPolicy>& policies) {
1816 frame_tree_node()->AddContentSecurityPolicy(header, policies); 1840 frame_tree_node()->AddContentSecurityPolicy(header);
1841 for (const ContentSecurityPolicy& policy : policies)
1842 AddContentSecurityPolicy(policy);
1817 } 1843 }
1818 1844
1819 void RenderFrameHostImpl::OnEnforceInsecureRequestPolicy( 1845 void RenderFrameHostImpl::OnEnforceInsecureRequestPolicy(
1820 blink::WebInsecureRequestPolicy policy) { 1846 blink::WebInsecureRequestPolicy policy) {
1821 frame_tree_node()->SetInsecureRequestPolicy(policy); 1847 frame_tree_node()->SetInsecureRequestPolicy(policy);
1822 } 1848 }
1823 1849
1824 void RenderFrameHostImpl::OnUpdateToUniqueOrigin( 1850 void RenderFrameHostImpl::OnUpdateToUniqueOrigin(
1825 bool is_potentially_trustworthy_unique_origin) { 1851 bool is_potentially_trustworthy_unique_origin) {
1826 url::Origin origin; 1852 url::Origin origin;
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2485 if (!common_params.url.SchemeIs(url::kJavaScriptScheme)) 2511 if (!common_params.url.SchemeIs(url::kJavaScriptScheme))
2486 OnDidStartLoading(true); 2512 OnDidStartLoading(true);
2487 } 2513 }
2488 2514
2489 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) { 2515 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
2490 DCHECK(data_url.SchemeIs(url::kDataScheme)); 2516 DCHECK(data_url.SchemeIs(url::kDataScheme));
2491 CommonNavigationParams common_params( 2517 CommonNavigationParams common_params(
2492 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, 2518 data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
2493 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT, false, false, 2519 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT, false, false,
2494 base::TimeTicks::Now(), FrameMsg_UILoadMetricsReportType::NO_REPORT, 2520 base::TimeTicks::Now(), FrameMsg_UILoadMetricsReportType::NO_REPORT,
2495 GURL(), GURL(), PREVIEWS_OFF, base::TimeTicks::Now(), "GET", nullptr); 2521 GURL(), GURL(), PREVIEWS_OFF, base::TimeTicks::Now(), "GET", nullptr,
2522 false /* should_bypass_main_world_csp */);
2496 if (IsBrowserSideNavigationEnabled()) { 2523 if (IsBrowserSideNavigationEnabled()) {
2497 CommitNavigation(nullptr, nullptr, common_params, RequestNavigationParams(), 2524 CommitNavigation(nullptr, nullptr, common_params, RequestNavigationParams(),
2498 false); 2525 false);
2499 } else { 2526 } else {
2500 Navigate(common_params, StartNavigationParams(), RequestNavigationParams()); 2527 Navigate(common_params, StartNavigationParams(), RequestNavigationParams());
2501 } 2528 }
2502 } 2529 }
2503 2530
2504 void RenderFrameHostImpl::Stop() { 2531 void RenderFrameHostImpl::Stop() {
2505 Send(new FrameMsg_Stop(routing_id_)); 2532 Send(new FrameMsg_Stop(routing_id_));
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 NavigationEntryImpl::FromNavigationEntry( 3418 NavigationEntryImpl::FromNavigationEntry(
3392 frame_tree_node()->navigator()->GetController()->GetPendingEntry()); 3419 frame_tree_node()->navigator()->GetController()->GetPendingEntry());
3393 if (pending_entry && pending_entry->GetUniqueID() == params.nav_entry_id) { 3420 if (pending_entry && pending_entry->GetUniqueID() == params.nav_entry_id) {
3394 pending_nav_entry_id = params.nav_entry_id; 3421 pending_nav_entry_id = params.nav_entry_id;
3395 is_renderer_initiated = pending_entry->is_renderer_initiated(); 3422 is_renderer_initiated = pending_entry->is_renderer_initiated();
3396 } 3423 }
3397 3424
3398 return NavigationHandleImpl::Create( 3425 return NavigationHandleImpl::Create(
3399 params.url, params.redirects, frame_tree_node_, is_renderer_initiated, 3426 params.url, params.redirects, frame_tree_node_, is_renderer_initiated,
3400 params.was_within_same_page, base::TimeTicks::Now(), 3427 params.was_within_same_page, base::TimeTicks::Now(),
3401 pending_nav_entry_id, false); // started_from_context_menu 3428 pending_nav_entry_id,
3429 false, // started_from_context_menu
3430 false); // should_bypass_main_world_csp
3402 } 3431 }
3403 3432
3404 // Determine if the current NavigationHandle can be used. 3433 // Determine if the current NavigationHandle can be used.
3405 if (navigation_handle_ && navigation_handle_->GetURL() == params.url) { 3434 if (navigation_handle_ && navigation_handle_->GetURL() == params.url) {
3406 return std::move(navigation_handle_); 3435 return std::move(navigation_handle_);
3407 } 3436 }
3408 3437
3409 // If the URL does not match what the NavigationHandle expects, treat the 3438 // If the URL does not match what the NavigationHandle expects, treat the
3410 // commit as a new navigation. This can happen when loading a Data 3439 // commit as a new navigation. This can happen when loading a Data
3411 // navigation with LoadDataWithBaseURL. 3440 // navigation with LoadDataWithBaseURL.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3443 // Reset any existing NavigationHandle. 3472 // Reset any existing NavigationHandle.
3444 navigation_handle_.reset(); 3473 navigation_handle_.reset();
3445 } 3474 }
3446 3475
3447 // There is no pending NavigationEntry in these cases, so pass 0 as the 3476 // There is no pending NavigationEntry in these cases, so pass 0 as the
3448 // pending_nav_entry_id. If the previous handle was a prematurely aborted 3477 // pending_nav_entry_id. If the previous handle was a prematurely aborted
3449 // navigation loaded via LoadDataWithBaseURL, propagate the entry id. 3478 // navigation loaded via LoadDataWithBaseURL, propagate the entry id.
3450 return NavigationHandleImpl::Create( 3479 return NavigationHandleImpl::Create(
3451 params.url, params.redirects, frame_tree_node_, is_renderer_initiated, 3480 params.url, params.redirects, frame_tree_node_, is_renderer_initiated,
3452 params.was_within_same_page, base::TimeTicks::Now(), 3481 params.was_within_same_page, base::TimeTicks::Now(),
3453 entry_id_for_data_nav, false); // started_from_context_menu 3482 entry_id_for_data_nav,
3483 false, // started_from_context_menu
3484 false); // should_bypass_main_world_csp
3454 } 3485 }
3455 3486
3456 } // namespace content 3487 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698