Index: chrome/browser/safe_browsing/threat_details.h |
diff --git a/chrome/browser/safe_browsing/threat_details.h b/chrome/browser/safe_browsing/threat_details.h |
index abd1747be15ae0510743831c61544e119a00d2f0..f02f006230a9a815fe8669544c6a8eb83e67cdc9 100644 |
--- a/chrome/browser/safe_browsing/threat_details.h |
+++ b/chrome/browser/safe_browsing/threat_details.h |
@@ -56,18 +56,13 @@ using ResourceMap = |
// |node_id| is a seqeuntial ID for the element generated by the renderer. |
using ElementMap = base::hash_map<std::string, std::unique_ptr<HTMLElement>>; |
-// Maps a URL to some HTML Elements. Used to maintain parent/child relationship |
-// for HTML Elements across IFrame boundaries. |
-// The key is the string URL set as the src attribute of an iframe. The value is |
-// the HTMLElement proto that represents the iframe element with that URL. |
-// The HTMLElement protos are not owned by this map. |
-using UrlToDomElementMap = base::hash_map<std::string, HTMLElement*>; |
- |
-// Maps a URL to some Element IDs. Used to maintain parent/child relationship |
-// for HTML Elements across IFrame boundaries. |
-// The key is the string URL of a render frame. The value is the set of Element |
-// IDs that are at the top-level of this render frame. |
-using UrlToChildIdsMap = base::hash_map<std::string, std::unordered_set<int>>; |
+// Maps the key of an iframe element to the FrameTreeNodeId of the render frame |
+// that rendered the contents of the iframe. |
+using KeyToFrameTreeIdMap = base::hash_map<std::string, int>; |
+ |
+// Maps a FrameTreeNodeId of a render frame to a set of child IDs. The child IDs |
+// are the Element IDs of the top-level HTML Elements in this render frame. |
+using FrameTreeIdToChildIdsMap = base::hash_map<int, std::unordered_set<int>>; |
class ThreatDetails : public base::RefCountedThreadSafe< |
ThreatDetails, |
@@ -120,6 +115,7 @@ class ThreatDetails : public base::RefCountedThreadSafe< |
// Called on the IO thread with the DOM details. |
virtual void AddDOMDetails( |
+ const int process_id, |
const int frame_tree_node_id, |
const GURL& frame_last_committed_url, |
const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); |
@@ -167,22 +163,32 @@ class ThreatDetails : public base::RefCountedThreadSafe< |
void AddRedirectUrlList(const std::vector<GURL>& urls); |
- // Adds an HTML Element to the DOM structure. |
- // |frame_tree_node_id| is the unique ID of the render frame the element came |
- // from. |frame_url| is the URL that the render frame was handling. |
- // |element_node_id| is a unique ID of the element within the render frame. |
- // |tag_name| is the tag of the element. |parent_element_node_id| is the |
- // unique ID of the parent element with the render frame. |attributes| |
- // containes the names and values of the element's attributes.|resource| is |
- // set if this element is a resource. |
+ // Adds an HTML Element to the DOM structure. |frame_tree_node_id| is the |
+ // unique ID of the render frame the element came from, and |process_id| is |
+ // that renderer's process ID. |other_frame_routing_id| is only set for iframe |
+ // elements, and indicates the routing_id of the render frame containing the |
+ // body of the iframe. |element_node_id| is a unique ID of the element within |
+ // the render frame. |tag_name| is the tag of the element. |
+ // |parent_element_node_id| is the unique ID of the parent element with the |
+ // render frame. |attributes| containes the names and values of the element's |
+ // attributes.|resource| is set if this element is a resource. |
void AddDomElement(const int frame_tree_node_id, |
- const std::string& frame_url, |
+ const int process_id, |
+ const int other_frame_routing_id, |
const int element_node_id, |
const std::string& tag_name, |
const int parent_element_node_id, |
const std::vector<AttributeNameValue>& attributes, |
const ClientSafeBrowsingReportRequest::Resource* resource); |
+ // Looks up the FrameTreeNodeId of a frame with |other_frame_routing_id|, and |
+ // updates |iframe_key_to_frame_tree_id_map_| by mapping |element_key| to the |
+ // FrameTreeNodeId that was looked up. |
+ // Must be called on UI thread to perform the lookup. |
+ void LookupOtherFrameId(const std::string& element_key, |
+ const int sender_process_id, |
+ const int other_frame_routing_id); |
+ |
scoped_refptr<BaseUIManager> ui_manager_; |
const UnsafeResource resource_; |
@@ -194,18 +200,20 @@ class ThreatDetails : public base::RefCountedThreadSafe< |
// Store all HTML elements collected, keep them in a map for easy lookup. |
ElementMap elements_; |
- // For each iframe element encountered we map the src of the iframe to the |
- // iframe element. This is used when we receive elements from a different |
- // frame whose document URL matches the src of an iframe in this map. We can |
- // then add all elements from the subframe as children of the iframe element |
- // stored here. |
- UrlToDomElementMap iframe_src_to_element_map_; |
+ // For each iframe element encountered we map the key of the iframe to the |
+ // FrameTreeNodeId of the render frame containing the contents of that iframe. |
+ // Lookup of FrameTreeNodeId for an iframe element must be done on the UI |
+ // thread, while other processing happens on the IO thread. So we populate |
+ // this map as we encounter iframes, but use it in a second pass (after |
+ // FinishCollection) to attach children to iframe elements. |
+ KeyToFrameTreeIdMap iframe_key_to_frame_tree_id_map_; |
// When getting a set of elements from a render frame, we store the frame's |
- // URL and a collection of all the top-level elements in that frame. When we |
- // later encounter the parent iframe with the same src URL, we can add all of |
- // these elements as children of that iframe. |
- UrlToChildIdsMap document_url_to_children_map_; |
+ // FrameTreeNodeId and a collection of all top-level elements in that frame. |
+ // It is populated as we receive sets of nodes from different render frames. |
+ // It is used together with |iframe_key_to_frame_tree_id_map_| in a second |
+ // pass to insert child elements under their parent iframe elements. |
+ FrameTreeIdToChildIdsMap frame_tree_id_to_children_map_; |
// Result from the cache extractor. |
bool cache_result_; |
@@ -217,11 +225,6 @@ class ThreatDetails : public base::RefCountedThreadSafe< |
// How many times this user has visited this page before. |
int num_visits_; |
- // Keeps track of whether we have an ambiguous DOM in this report. This can |
- // happen when the HTML Elements returned by a render frame can't be |
- // associated with a parent Element in the parent frame. |
- bool ambiguous_dom_; |
- |
// The factory used to instanciate SafeBrowsingBlockingPage objects. |
// Usefull for tests, so they can provide their own implementation of |
// SafeBrowsingBlockingPage. |