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 COMPONENTS_SAFE_BROWSING_BROWSER_THREAT_DETAILS_H_ | 5 #ifndef COMPONENTS_SAFE_BROWSING_BROWSER_THREAT_DETAILS_H_ |
6 #define COMPONENTS_SAFE_BROWSING_BROWSER_THREAT_DETAILS_H_ | 6 #define COMPONENTS_SAFE_BROWSING_BROWSER_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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 class ThreatDetailsCacheCollector; | 45 class ThreatDetailsCacheCollector; |
46 class ThreatDetailsRedirectsCollector; | 46 class ThreatDetailsRedirectsCollector; |
47 class ThreatDetailsFactory; | 47 class ThreatDetailsFactory; |
48 | 48 |
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 FrameTreeNode ID of the frame containing the element, and |
56 // |node_id| is a sequential ID for the element generated by the renderer. | 56 // |node_id| is a sequential 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 FrameTreeNode ID of the frame that |
60 // for HTML Elements across IFrame boundaries. | 60 // 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 FrameTreeNode ID of a frame to a set of child IDs. The child IDs are |
67 // for HTML Elements across IFrame boundaries. | 64 // the Element IDs of the top-level HTML Elements in this frame. |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( |
123 const int frame_tree_node_id, | 118 const int frame_tree_node_id, |
124 const GURL& frame_last_committed_url, | 119 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params, |
125 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); | 120 const KeyToFrameTreeIdMap& child_frame_tree_map); |
126 | 121 |
127 // The report protocol buffer. | 122 // The report protocol buffer. |
128 std::unique_ptr<ClientSafeBrowsingReportRequest> report_; | 123 std::unique_ptr<ClientSafeBrowsingReportRequest> report_; |
129 | 124 |
130 // Used to get a pointer to the HTTP cache. | 125 // Used to get a pointer to the HTTP cache. |
131 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 126 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
132 | 127 |
133 private: | 128 private: |
134 friend class base::RefCountedThreadSafe<ThreatDetails>; | 129 friend class base::RefCountedThreadSafe<ThreatDetails>; |
135 friend struct content::BrowserThread::DeleteOnThread< | 130 friend struct content::BrowserThread::DeleteOnThread< |
(...skipping 24 matching lines...) Expand all Loading... |
160 const std::string& tagname, | 155 const std::string& tagname, |
161 const std::vector<GURL>* children); | 156 const std::vector<GURL>* children); |
162 | 157 |
163 // Message handler. | 158 // Message handler. |
164 void OnReceivedThreatDOMDetails( | 159 void OnReceivedThreatDOMDetails( |
165 content::RenderFrameHost* sender, | 160 content::RenderFrameHost* sender, |
166 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); | 161 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); |
167 | 162 |
168 void AddRedirectUrlList(const std::vector<GURL>& urls); | 163 void AddRedirectUrlList(const std::vector<GURL>& urls); |
169 | 164 |
170 // Adds an HTML Element to the DOM structure. | 165 // 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 | 166 // unique ID of the frame the element came from. |element_node_id| is a unique |
172 // from. |frame_url| is the URL that the render frame was handling. | 167 // ID of the element within the frame. |tag_name| is the tag of the element. |
173 // |element_node_id| is a unique ID of the element within the render frame. | 168 // |parent_element_node_id| is the unique ID of the parent element within the |
174 // |tag_name| is the tag of the element. |parent_element_node_id| is the | 169 // frame. |attributes| contains the names and values of the element's |
175 // unique ID of the parent element with the render frame. |attributes| | 170 // attributes. |resource| is set if this element is a resource. |
176 // contains the names and values of the element's attributes.|resource| is | |
177 // set if this element is a resource. | |
178 void AddDomElement(const int frame_tree_node_id, | 171 void AddDomElement(const int frame_tree_node_id, |
179 const std::string& frame_url, | |
180 const int element_node_id, | 172 const int element_node_id, |
181 const std::string& tag_name, | 173 const std::string& tag_name, |
182 const int parent_element_node_id, | 174 const int parent_element_node_id, |
183 const std::vector<AttributeNameValue>& attributes, | 175 const std::vector<AttributeNameValue>& attributes, |
184 const ClientSafeBrowsingReportRequest::Resource* resource); | 176 const ClientSafeBrowsingReportRequest::Resource* resource); |
185 | 177 |
186 scoped_refptr<BaseUIManager> ui_manager_; | 178 scoped_refptr<BaseUIManager> ui_manager_; |
187 | 179 |
188 const UnsafeResource resource_; | 180 const UnsafeResource resource_; |
189 | 181 |
190 // For every Url we collect we create a Resource message. We keep | 182 // For every Url we collect we create a Resource message. We keep |
191 // them in a map so we can avoid duplicates. | 183 // them in a map so we can avoid duplicates. |
192 ResourceMap resources_; | 184 ResourceMap resources_; |
193 | 185 |
194 // Store all HTML elements collected, keep them in a map for easy lookup. | 186 // Store all HTML elements collected, keep them in a map for easy lookup. |
195 ElementMap elements_; | 187 ElementMap elements_; |
196 | 188 |
197 // For each iframe element encountered we map the src of the iframe to the | 189 // 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 | 190 // FrameTreeNode ID of the frame containing the contents of that iframe. |
199 // frame whose document URL matches the src of an iframe in this map. We can | 191 // We populate this map when receiving results from ThreatDomDetails, and use |
200 // then add all elements from the subframe as children of the iframe element | 192 // it in a second pass (after FinishCollection) to attach children to iframe |
201 // stored here. | 193 // elements. |
202 UrlToDomElementMap iframe_src_to_element_map_; | 194 // Should only be accessed on the IO thread. |
| 195 KeyToFrameTreeIdMap iframe_key_to_frame_tree_id_map_; |
203 | 196 |
204 // When getting a set of elements from a render frame, we store the frame's | 197 // When getting a set of elements from a frame, we store the frame's |
205 // URL and a collection of all the top-level elements in that frame. When we | 198 // FrameTreeNode ID 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 | 199 // It is populated as we receive sets of nodes from different renderers. |
207 // these elements as children of that iframe. | 200 // It is used together with |iframe_key_to_frame_tree_id_map_| in a second |
208 UrlToChildIdsMap document_url_to_children_map_; | 201 // pass to insert child elements under their parent iframe elements. |
| 202 FrameTreeIdToChildIdsMap frame_tree_id_to_children_map_; |
209 | 203 |
210 // Result from the cache extractor. | 204 // Result from the cache extractor. |
211 bool cache_result_; | 205 bool cache_result_; |
212 | 206 |
213 // Whether user did proceed with the safe browsing blocking page or | 207 // Whether user did proceed with the safe browsing blocking page or |
214 // not. | 208 // not. |
215 bool did_proceed_; | 209 bool did_proceed_; |
216 | 210 |
217 // How many times this user has visited this page before. | 211 // How many times this user has visited this page before. |
218 int num_visits_; | 212 int num_visits_; |
219 | 213 |
220 // Keeps track of whether we have an ambiguous DOM in this report. This can | 214 // Keeps track of whether we have an ambiguous DOM in this report. This can |
221 // happen when the HTML Elements returned by a render frame can't be | 215 // happen when the HTML Elements returned by a renderer can't be |
222 // associated with a parent Element in the parent frame. | 216 // associated with a parent Element in the parent frame. |
223 bool ambiguous_dom_; | 217 bool ambiguous_dom_; |
224 | 218 |
225 // The factory used to instantiate SafeBrowsingBlockingPage objects. | 219 // The factory used to instantiate SafeBrowsingBlockingPage objects. |
226 // Useful for tests, so they can provide their own implementation of | 220 // Useful for tests, so they can provide their own implementation of |
227 // SafeBrowsingBlockingPage. | 221 // SafeBrowsingBlockingPage. |
228 static ThreatDetailsFactory* factory_; | 222 static ThreatDetailsFactory* factory_; |
229 | 223 |
230 // Used to collect details from the HTTP Cache. | 224 // Used to collect details from the HTTP Cache. |
231 scoped_refptr<ThreatDetailsCacheCollector> cache_collector_; | 225 scoped_refptr<ThreatDetailsCacheCollector> cache_collector_; |
(...skipping 21 matching lines...) Expand all Loading... |
253 BaseUIManager* ui_manager, | 247 BaseUIManager* ui_manager, |
254 content::WebContents* web_contents, | 248 content::WebContents* web_contents, |
255 const security_interstitials::UnsafeResource& unsafe_resource, | 249 const security_interstitials::UnsafeResource& unsafe_resource, |
256 net::URLRequestContextGetter* request_context_getter, | 250 net::URLRequestContextGetter* request_context_getter, |
257 history::HistoryService* history_service) = 0; | 251 history::HistoryService* history_service) = 0; |
258 }; | 252 }; |
259 | 253 |
260 } // namespace safe_browsing | 254 } // namespace safe_browsing |
261 | 255 |
262 #endif // COMPONENTS_SAFE_BROWSING_BROWSER_THREAT_DETAILS_H_ | 256 #endif // COMPONENTS_SAFE_BROWSING_BROWSER_THREAT_DETAILS_H_ |
OLD | NEW |