OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ |
7 | 7 |
8 // A class that encapsulates the detailed threat reports sent when | 8 // A class that encapsulates the detailed threat reports sent when |
9 // users opt-in to do so from the safe browsing warning page. | 9 // users opt-in to do so from the safe browsing warning page. |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 using ResourceMap = | 49 using ResourceMap = |
50 base::hash_map<std::string, | 50 base::hash_map<std::string, |
51 std::unique_ptr<ClientSafeBrowsingReportRequest::Resource>>; | 51 std::unique_ptr<ClientSafeBrowsingReportRequest::Resource>>; |
52 | 52 |
53 // Maps a key of an HTML element to its corresponding HTMLElement proto message. | 53 // Maps a key of an HTML element to its corresponding HTMLElement proto message. |
54 // HTML Element keys have the form "<frame_id>-<node_id>", where |frame_id| is | 54 // HTML Element keys have the form "<frame_id>-<node_id>", where |frame_id| is |
55 // the FrameTree NodeID of the render frame containing the element, and | 55 // the FrameTree NodeID of the render frame containing the element, and |
56 // |node_id| is a seqeuntial ID for the element generated by the renderer. | 56 // |node_id| is a seqeuntial ID for the element generated by the renderer. |
57 using ElementMap = base::hash_map<std::string, std::unique_ptr<HTMLElement>>; | 57 using ElementMap = base::hash_map<std::string, std::unique_ptr<HTMLElement>>; |
58 | 58 |
59 // Maps a URL to some HTML Elements. Used to maintain parent/child relationship | 59 // Maps the key of an iframe element to the FrameTreeNodeId of the render frame |
Charlie Reis
2017/05/05 21:03:07
nit: FrameTreeNode ID
nit: s/render frame/frame/
lpz
2017/05/10 14:21:08
Done.
| |
60 // for HTML Elements across IFrame boundaries. | 60 // that rendered the contents of the iframe. |
61 // The key is the string URL set as the src attribute of an iframe. The value is | 61 using KeyToFrameTreeIdMap = base::hash_map<std::string, int>; |
62 // the HTMLElement proto that represents the iframe element with that URL. | |
63 // The HTMLElement protos are not owned by this map. | |
64 using UrlToDomElementMap = base::hash_map<std::string, HTMLElement*>; | |
65 | 62 |
66 // Maps a URL to some Element IDs. Used to maintain parent/child relationship | 63 // Maps a FrameTreeNodeId of a render frame to a set of child IDs. The child IDs |
67 // for HTML Elements across IFrame boundaries. | 64 // are the Element IDs of the top-level HTML Elements in this render frame. |
Charlie Reis
2017/05/05 21:03:07
Same: FrameTreeNode ID, s/render frame/frame/
lpz
2017/05/10 14:21:09
Done.
| |
68 // The key is the string URL of a render frame. The value is the set of Element | 65 using FrameTreeIdToChildIdsMap = base::hash_map<int, std::unordered_set<int>>; |
69 // IDs that are at the top-level of this render frame. | |
70 using UrlToChildIdsMap = base::hash_map<std::string, std::unordered_set<int>>; | |
71 | 66 |
72 class ThreatDetails : public base::RefCountedThreadSafe< | 67 class ThreatDetails : public base::RefCountedThreadSafe< |
73 ThreatDetails, | 68 ThreatDetails, |
74 content::BrowserThread::DeleteOnUIThread>, | 69 content::BrowserThread::DeleteOnUIThread>, |
75 public content::WebContentsObserver { | 70 public content::WebContentsObserver { |
76 public: | 71 public: |
77 typedef security_interstitials::UnsafeResource UnsafeResource; | 72 typedef security_interstitials::UnsafeResource UnsafeResource; |
78 | 73 |
79 // Constructs a new ThreatDetails instance, using the factory. | 74 // Constructs a new ThreatDetails instance, using the factory. |
80 static ThreatDetails* NewThreatDetails( | 75 static ThreatDetails* NewThreatDetails( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 ThreatDetails(BaseUIManager* ui_manager, | 108 ThreatDetails(BaseUIManager* ui_manager, |
114 content::WebContents* web_contents, | 109 content::WebContents* web_contents, |
115 const UnsafeResource& resource, | 110 const UnsafeResource& resource, |
116 net::URLRequestContextGetter* request_context_getter, | 111 net::URLRequestContextGetter* request_context_getter, |
117 history::HistoryService* history_service); | 112 history::HistoryService* history_service); |
118 | 113 |
119 ~ThreatDetails() override; | 114 ~ThreatDetails() override; |
120 | 115 |
121 // Called on the IO thread with the DOM details. | 116 // Called on the IO thread with the DOM details. |
122 virtual void AddDOMDetails( | 117 virtual void AddDOMDetails( |
118 const int process_id, | |
123 const int frame_tree_node_id, | 119 const int frame_tree_node_id, |
124 const GURL& frame_last_committed_url, | 120 const GURL& frame_last_committed_url, |
125 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); | 121 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); |
126 | 122 |
127 // The report protocol buffer. | 123 // The report protocol buffer. |
128 std::unique_ptr<ClientSafeBrowsingReportRequest> report_; | 124 std::unique_ptr<ClientSafeBrowsingReportRequest> report_; |
129 | 125 |
130 // Used to get a pointer to the HTTP cache. | 126 // Used to get a pointer to the HTTP cache. |
131 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 127 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
132 | 128 |
(...skipping 27 matching lines...) Expand all Loading... | |
160 const std::string& tagname, | 156 const std::string& tagname, |
161 const std::vector<GURL>* children); | 157 const std::vector<GURL>* children); |
162 | 158 |
163 // Message handler. | 159 // Message handler. |
164 void OnReceivedThreatDOMDetails( | 160 void OnReceivedThreatDOMDetails( |
165 content::RenderFrameHost* sender, | 161 content::RenderFrameHost* sender, |
166 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); | 162 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); |
167 | 163 |
168 void AddRedirectUrlList(const std::vector<GURL>& urls); | 164 void AddRedirectUrlList(const std::vector<GURL>& urls); |
169 | 165 |
170 // Adds an HTML Element to the DOM structure. | 166 // Adds an HTML Element to the DOM structure. |frame_tree_node_id| is the |
171 // |frame_tree_node_id| is the unique ID of the render frame the element came | 167 // unique ID of the render frame the element came from, and |process_id| is |
Charlie Reis
2017/05/05 21:03:07
nit: s/render frame/frame/
lpz
2017/05/10 14:21:09
Done.
| |
172 // from. |frame_url| is the URL that the render frame was handling. | 168 // that renderer's process ID. |other_frame_routing_id| is only set for iframe |
Charlie Reis
2017/05/05 21:03:07
FrameTreeNodes don't directly have a renderer proc
lpz
2017/05/10 14:21:08
Done.
| |
173 // |element_node_id| is a unique ID of the element within the render frame. | 169 // elements, and indicates the routing_id of the render frame containing the |
Charlie Reis
2017/05/05 21:03:07
"other" is a bit vague-- I thought it might mean p
lpz
2017/05/10 14:21:09
Done.
| |
174 // |tag_name| is the tag of the element. |parent_element_node_id| is the | 170 // body of the iframe. |element_node_id| is a unique ID of the element within |
175 // unique ID of the parent element with the render frame. |attributes| | 171 // the render frame. |tag_name| is the tag of the element. |
176 // containes the names and values of the element's attributes.|resource| is | 172 // |parent_element_node_id| is the unique ID of the parent element with the |
177 // set if this element is a resource. | 173 // render frame. |attributes| containes the names and values of the element's |
174 // attributes.|resource| is set if this element is a resource. | |
178 void AddDomElement(const int frame_tree_node_id, | 175 void AddDomElement(const int frame_tree_node_id, |
179 const std::string& frame_url, | 176 const int process_id, |
177 const int other_frame_routing_id, | |
180 const int element_node_id, | 178 const int element_node_id, |
181 const std::string& tag_name, | 179 const std::string& tag_name, |
182 const int parent_element_node_id, | 180 const int parent_element_node_id, |
183 const std::vector<AttributeNameValue>& attributes, | 181 const std::vector<AttributeNameValue>& attributes, |
184 const ClientSafeBrowsingReportRequest::Resource* resource); | 182 const ClientSafeBrowsingReportRequest::Resource* resource); |
185 | 183 |
184 // Looks up the FrameTreeNodeId of a frame with |other_frame_routing_id|, and | |
Charlie Reis
2017/05/05 21:03:07
nit: FrameTreeNode ID
nit: |child_frame_routing_id
lpz
2017/05/10 14:21:09
Method deleted.
| |
185 // updates |iframe_key_to_frame_tree_id_map_| by mapping |element_key| to the | |
186 // FrameTreeNodeId that was looked up. | |
187 // Must be called on UI thread to perform the lookup. | |
188 void LookupOtherFrameId(const std::string& element_key, | |
Charlie Reis
2017/05/05 21:03:07
Should Other be Child here as well? I don't know
lpz
2017/05/10 14:21:08
Method deleted.
| |
189 const int sender_process_id, | |
190 const int other_frame_routing_id); | |
191 | |
186 scoped_refptr<BaseUIManager> ui_manager_; | 192 scoped_refptr<BaseUIManager> ui_manager_; |
187 | 193 |
188 const UnsafeResource resource_; | 194 const UnsafeResource resource_; |
189 | 195 |
190 // For every Url we collect we create a Resource message. We keep | 196 // For every Url we collect we create a Resource message. We keep |
191 // them in a map so we can avoid duplicates. | 197 // them in a map so we can avoid duplicates. |
192 ResourceMap resources_; | 198 ResourceMap resources_; |
193 | 199 |
194 // Store all HTML elements collected, keep them in a map for easy lookup. | 200 // Store all HTML elements collected, keep them in a map for easy lookup. |
195 ElementMap elements_; | 201 ElementMap elements_; |
196 | 202 |
197 // For each iframe element encountered we map the src of the iframe to the | 203 // For each iframe element encountered we map the key of the iframe to the |
198 // iframe element. This is used when we receive elements from a different | 204 // FrameTreeNodeId of the render frame containing the contents of that iframe. |
Charlie Reis
2017/05/05 21:03:07
Same nits, here and below.
lpz
2017/05/10 14:21:09
Done.
| |
199 // frame whose document URL matches the src of an iframe in this map. We can | 205 // Lookup of FrameTreeNodeId for an iframe element must be done on the UI |
200 // then add all elements from the subframe as children of the iframe element | 206 // thread, while other processing happens on the IO thread. So we populate |
201 // stored here. | 207 // this map as we encounter iframes, but use it in a second pass (after |
202 UrlToDomElementMap iframe_src_to_element_map_; | 208 // FinishCollection) to attach children to iframe elements. |
209 KeyToFrameTreeIdMap iframe_key_to_frame_tree_id_map_; | |
203 | 210 |
204 // When getting a set of elements from a render frame, we store the frame's | 211 // When getting a set of elements from a render frame, we store the frame's |
205 // URL and a collection of all the top-level elements in that frame. When we | 212 // FrameTreeNodeId and a collection of all top-level elements in that frame. |
206 // later encounter the parent iframe with the same src URL, we can add all of | 213 // It is populated as we receive sets of nodes from different render frames. |
207 // these elements as children of that iframe. | 214 // It is used together with |iframe_key_to_frame_tree_id_map_| in a second |
208 UrlToChildIdsMap document_url_to_children_map_; | 215 // pass to insert child elements under their parent iframe elements. |
216 FrameTreeIdToChildIdsMap frame_tree_id_to_children_map_; | |
209 | 217 |
210 // Result from the cache extractor. | 218 // Result from the cache extractor. |
211 bool cache_result_; | 219 bool cache_result_; |
212 | 220 |
213 // Whether user did proceed with the safe browsing blocking page or | 221 // Whether user did proceed with the safe browsing blocking page or |
214 // not. | 222 // not. |
215 bool did_proceed_; | 223 bool did_proceed_; |
216 | 224 |
217 // How many times this user has visited this page before. | 225 // How many times this user has visited this page before. |
218 int num_visits_; | 226 int num_visits_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 BaseUIManager* ui_manager, | 261 BaseUIManager* ui_manager, |
254 content::WebContents* web_contents, | 262 content::WebContents* web_contents, |
255 const security_interstitials::UnsafeResource& unsafe_resource, | 263 const security_interstitials::UnsafeResource& unsafe_resource, |
256 net::URLRequestContextGetter* request_context_getter, | 264 net::URLRequestContextGetter* request_context_getter, |
257 history::HistoryService* history_service) = 0; | 265 history::HistoryService* history_service) = 0; |
258 }; | 266 }; |
259 | 267 |
260 } // namespace safe_browsing | 268 } // namespace safe_browsing |
261 | 269 |
262 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ | 270 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ |
OLD | NEW |