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

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

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: Fix Android PDF tests where PDFs should be downloaded Created 3 years, 8 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
(Empty)
1 // Copyright 2017 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/data_url_navigation_throttle.h"
6
7 #include "base/feature_list.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/strings/stringprintf.h"
10 #include "content/browser/frame_host/frame_tree.h"
11 #include "content/browser/frame_host/frame_tree_node.h"
12 #include "content/browser/frame_host/navigation_handle_impl.h"
13 #include "content/public/browser/navigation_handle.h"
14 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/common/console_message_level.h"
16 #include "content/public/common/content_features.h"
17 #include "url/url_constants.h"
18
19 namespace content {
20
21 namespace {
22 const char kConsoleError[] =
23 "Not allowed to navigate top frame to data URL: %s";
24 }
25
26 DataUrlNavigationThrottle::DataUrlNavigationThrottle(
27 NavigationHandle* navigation_handle)
28 : NavigationThrottle(navigation_handle) {}
29
30 DataUrlNavigationThrottle::~DataUrlNavigationThrottle() {}
31
32 NavigationThrottle::ThrottleCheckResult
33 DataUrlNavigationThrottle::WillProcessResponse() {
34 NavigationHandleImpl* handle =
35 static_cast<NavigationHandleImpl*>(navigation_handle());
36 if (handle->is_download())
37 return PROCEED;
38
39 RenderFrameHost* top_frame =
40 handle->frame_tree_node()->frame_tree()->root()->current_frame_host();
41 top_frame->AddMessageToConsole(
42 CONSOLE_MESSAGE_LEVEL_ERROR,
43 base::StringPrintf(kConsoleError, handle->GetURL().spec().c_str()));
44 return CANCEL;
45 }
46
47 // static
48 std::unique_ptr<NavigationThrottle>
49 DataUrlNavigationThrottle::CreateThrottleForNavigation(
50 NavigationHandle* navigation_handle) {
51 if (navigation_handle->GetURL().SchemeIs(url::kDataScheme) &&
52 navigation_handle->IsInMainFrame() &&
53 navigation_handle->IsRendererInitiated() &&
54 !navigation_handle->IsSameDocument() &&
55 !base::FeatureList::IsEnabled(
56 features::kAllowContentInitiatedDataUrlNavigations)) {
57 return base::MakeUnique<DataUrlNavigationThrottle>(navigation_handle);
58 }
59 return nullptr;
60 }
61
62 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/data_url_navigation_throttle.h ('k') | content/browser/frame_host/navigation_handle_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698