OLD | NEW |
---|---|
(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 top-level navigate to resource: %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()) { | |
nasko
2017/04/05 23:55:19
Let's avoid a level of indentation and use:
if (h
meacer
2017/04/06 01:25:42
Sure, looks nicer :)
| |
37 RenderFrameHost* top_frame = | |
38 handle->frame_tree_node()->frame_tree()->root()->current_frame_host(); | |
39 top_frame->AddMessageToConsole( | |
40 CONSOLE_MESSAGE_LEVEL_ERROR, | |
41 base::StringPrintf(kConsoleError, handle->GetURL().spec().c_str())); | |
42 return CANCEL; | |
43 } | |
44 return PROCEED; | |
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::kAllowInsecureDataUrlNavigations)) { | |
57 return base::WrapUnique(new DataUrlNavigationThrottle(navigation_handle)); | |
58 } | |
59 return nullptr; | |
60 } | |
61 | |
62 } // namespace content | |
OLD | NEW |