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

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 downloads, plugin handling and browser side navigations 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
(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/memory/ptr_util.h"
8 #include "base/strings/stringprintf.h"
9 #include "content/public/browser/navigation_handle.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/common/browser_side_navigation_policy.h"
12 #include "content/public/common/console_message_level.h"
13 #include "url/url_constants.h"
14
15 namespace content {
16
17 namespace {
18 const char kConsoleError[] =
19 "Not allowed to top-level navigate to resource: %s";
20 }
21
22 DataUrlNavigationThrottle::DataUrlNavigationThrottle(
23 NavigationHandle* navigation_handle)
24 : NavigationThrottle(navigation_handle) {}
25
26 DataUrlNavigationThrottle::~DataUrlNavigationThrottle() {}
27
28 NavigationThrottle::ThrottleCheckResult
29 DataUrlNavigationThrottle::WillProcessResponse() {
30 if (navigation_handle()->GetURL().SchemeIs(url::kDataScheme) &&
31 navigation_handle()->IsInMainFrame() &&
32 navigation_handle()->IsRendererInitiated() &&
33 !navigation_handle()->IsDownload()) {
34 navigation_handle()->GetRenderFrameHost()->AddMessageToConsole(
35 CONSOLE_MESSAGE_LEVEL_ERROR,
36 base::StringPrintf(kConsoleError,
37 navigation_handle()->GetURL().spec().c_str()));
38 return CANCEL;
39 }
40 return PROCEED;
41 }
42
43 // static
44 std::unique_ptr<NavigationThrottle>
45 DataUrlNavigationThrottle::CreateThrottleForNavigation(
46 NavigationHandle* navigation_handle) {
47 if (IsBrowserSideNavigationEnabled())
48 return base::WrapUnique(new DataUrlNavigationThrottle(navigation_handle));
49 return nullptr;
50 }
51
52 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698