Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "components/security_interstitials/content/unsafe_resource.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/public/browser/navigation_entry.h" | |
| 9 #include "content/public/browser/render_frame_host.h" | |
| 10 #include "content/public/browser/web_contents.h" | |
| 11 | |
| 12 namespace security_interstitials { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 content::WebContents* GetWebContentsByFrameID(int render_process_id, | |
| 17 int render_frame_id) { | |
| 18 content::RenderFrameHost* render_frame_host = | |
| 19 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
| 20 if (!render_frame_host) | |
| 21 return NULL; | |
| 22 return content::WebContents::FromRenderFrameHost(render_frame_host); | |
| 23 } | |
| 24 | |
| 25 }; // namespace | |
| 26 | |
| 27 UnsafeResource::UnsafeResource() | |
| 28 : is_subresource(false), | |
| 29 is_subframe(false), | |
| 30 threat_type(safe_browsing::SB_THREAT_TYPE_SAFE), | |
| 31 threat_source(safe_browsing::ThreatSource::UNKNOWN) {} | |
| 32 | |
| 33 UnsafeResource::UnsafeResource( | |
| 34 const UnsafeResource& other) = default; | |
| 35 | |
| 36 UnsafeResource::~UnsafeResource() { } | |
|
meacer
2016/12/01 00:55:08
nit: extra space between braces
Jialiu Lin
2016/12/01 01:04:38
Nice catch!
| |
| 37 | |
| 38 bool UnsafeResource::IsMainPageLoadBlocked() const { | |
| 39 // Subresource hits cannot happen until after main page load is committed. | |
| 40 if (is_subresource) | |
| 41 return false; | |
| 42 | |
| 43 // Client-side phishing detection interstitials never block the main frame | |
| 44 // load, since they happen after the page is finished loading. | |
| 45 if (threat_type == safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || | |
| 46 threat_type == safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 content::NavigationEntry* | |
| 54 UnsafeResource::GetNavigationEntryForResource() const { | |
| 55 content::WebContents* web_contents = web_contents_getter.Run(); | |
| 56 if (!web_contents) | |
| 57 return nullptr; | |
| 58 // If a safebrowsing hit occurs during main frame navigation, the navigation | |
| 59 // will not be committed, and the pending navigation entry refers to the hit. | |
| 60 if (IsMainPageLoadBlocked()) | |
| 61 return web_contents->GetController().GetPendingEntry(); | |
| 62 // If a safebrowsing hit occurs on a subresource load, or on a main frame | |
| 63 // after the navigation is committed, the last committed navigation entry | |
| 64 // refers to the page with the hit. Note that there may concurrently be an | |
| 65 // unrelated pending navigation to another site, so GetActiveEntry() would be | |
| 66 // wrong. | |
| 67 return web_contents->GetController().GetLastCommittedEntry(); | |
| 68 } | |
| 69 | |
| 70 // static | |
| 71 base::Callback<content::WebContents*(void)> | |
| 72 UnsafeResource::GetWebContentsGetter( | |
| 73 int render_process_host_id, | |
| 74 int render_frame_id) { | |
| 75 return base::Bind(&GetWebContentsByFrameID, render_process_host_id, | |
| 76 render_frame_id); | |
| 77 } | |
| 78 | |
| 79 } // security_interstitials | |
| OLD | NEW |