Chromium Code Reviews| Index: content/browser/frame_host/data_url_navigation_throttle.cc |
| diff --git a/content/browser/frame_host/data_url_navigation_throttle.cc b/content/browser/frame_host/data_url_navigation_throttle.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6dde0f39b2833478c42dcc39cc86273892ddd3a9 |
| --- /dev/null |
| +++ b/content/browser/frame_host/data_url_navigation_throttle.cc |
| @@ -0,0 +1,49 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/frame_host/data_url_navigation_throttle.h" |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "content/public/browser/navigation_handle.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/common/console_message_level.h" |
| +#include "url/url_constants.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| +const char kConsoleError[] = |
| + "Not allowed to top-level navigate to resource: %s"; |
| +} |
| + |
| +DataUrlNavigationThrottle::DataUrlNavigationThrottle( |
| + NavigationHandle* navigation_handle) |
| + : NavigationThrottle(navigation_handle) {} |
| + |
| +DataUrlNavigationThrottle::~DataUrlNavigationThrottle() {} |
| + |
| +NavigationThrottle::ThrottleCheckResult |
| +DataUrlNavigationThrottle::WillProcessResponse() { |
| + if (navigation_handle()->GetURL().SchemeIs(url::kDataScheme) && |
| + navigation_handle()->IsInMainFrame() && |
| + navigation_handle()->IsRendererInitiated() && |
| + !navigation_handle()->IsDownload()) { |
| + navigation_handle()->GetRenderFrameHost()->AddMessageToConsole( |
| + CONSOLE_MESSAGE_LEVEL_ERROR, |
| + base::StringPrintf(kConsoleError, |
| + navigation_handle()->GetURL().spec().c_str())); |
|
nasko
2017/03/28 19:58:01
This code might also block navigations to data: UR
meacer
2017/03/28 20:44:35
I've been looking at this in the last few days. IM
|
| + return CANCEL; |
| + } |
| + return PROCEED; |
| +} |
| + |
| +// static |
| +std::unique_ptr<NavigationThrottle> |
| +DataUrlNavigationThrottle::CreateThrottleForNavigation( |
| + NavigationHandle* navigation_handle) { |
| + return base::WrapUnique(new DataUrlNavigationThrottle(navigation_handle)); |
|
nasko
2017/03/28 19:58:01
Does it make sense to install this throttle on all
meacer
2017/03/30 20:43:55
Changed it to install only if the data URL is pote
|
| +} |
| + |
| +} // namespace content |