| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // ThreatDOMDetails iterates over a document's frames and gathers | 5 // ThreatDOMDetails iterates over a document's frames and gathers |
| 6 // interesting URLs such as those of scripts and frames. When done, it sends | 6 // interesting URLs such as those of scripts and frames. When done, it sends |
| 7 // them to the ThreatDetails that requested them. | 7 // them to the ThreatDetails that requested them. |
| 8 | 8 |
| 9 #ifndef CHROME_RENDERER_SAFE_BROWSING_THREAT_DOM_DETAILS_H_ | 9 #ifndef CHROME_RENDERER_SAFE_BROWSING_THREAT_DOM_DETAILS_H_ |
| 10 #define CHROME_RENDERER_SAFE_BROWSING_THREAT_DOM_DETAILS_H_ | 10 #define CHROME_RENDERER_SAFE_BROWSING_THREAT_DOM_DETAILS_H_ |
| 11 | 11 |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/feature_list.h" |
| 15 #include "content/public/renderer/render_frame_observer.h" | 16 #include "content/public/renderer/render_frame_observer.h" |
| 16 | 17 |
| 17 struct SafeBrowsingHostMsg_ThreatDOMDetails_Node; | 18 struct SafeBrowsingHostMsg_ThreatDOMDetails_Node; |
| 18 | 19 |
| 19 namespace safe_browsing { | 20 namespace safe_browsing { |
| 20 | 21 |
| 22 extern const base::Feature kThreatDomDetailsTagAndAttributeFeature; |
| 23 extern const char kTagAndAttributeParamName[]; |
| 24 |
| 25 // Represents the tag name of an HTML Element and its associated attributes. |
| 26 // Used to determine which elements to collect. Populated from the param value |
| 27 // of |kThreatDomDetailsTagAndAttributeFeature|. |
| 28 class TagAndAttributesItem { |
| 29 public: |
| 30 TagAndAttributesItem(); |
| 31 TagAndAttributesItem(const TagAndAttributesItem& item); |
| 32 ~TagAndAttributesItem(); |
| 33 |
| 34 std::string tag_name; |
| 35 std::vector<std::string> attributes; |
| 36 }; |
| 37 |
| 21 // There is one ThreatDOMDetails per RenderFrame. | 38 // There is one ThreatDOMDetails per RenderFrame. |
| 22 class ThreatDOMDetails : public content::RenderFrameObserver { | 39 class ThreatDOMDetails : public content::RenderFrameObserver { |
| 23 public: | 40 public: |
| 24 // An upper limit on the number of nodes we collect. Not const for the test. | 41 // An upper limit on the number of nodes we collect. Not const for the test. |
| 25 static uint32_t kMaxNodes; | 42 static uint32_t kMaxNodes; |
| 26 | 43 |
| 27 static ThreatDOMDetails* Create(content::RenderFrame* render_frame); | 44 static ThreatDOMDetails* Create(content::RenderFrame* render_frame); |
| 28 ~ThreatDOMDetails() override; | 45 ~ThreatDOMDetails() override; |
| 29 | 46 |
| 30 // Begins extracting resource urls for the page currently loaded in | 47 // Begins extracting resource urls for the page currently loaded in |
| 31 // this object's RenderFrame. | 48 // this object's RenderFrame. |
| 32 // Exposed for testing. | 49 // Exposed for testing. |
| 33 void ExtractResources( | 50 void ExtractResources( |
| 34 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>* resources); | 51 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>* resources); |
| 35 | 52 |
| 36 private: | 53 private: |
| 37 // Creates a ThreatDOMDetails for the specified RenderFrame. | 54 // Creates a ThreatDOMDetails for the specified RenderFrame. |
| 38 // The ThreatDOMDetails should be destroyed prior to destroying | 55 // The ThreatDOMDetails should be destroyed prior to destroying |
| 39 // the RenderFrame. | 56 // the RenderFrame. |
| 40 explicit ThreatDOMDetails(content::RenderFrame* render_frame); | 57 explicit ThreatDOMDetails(content::RenderFrame* render_frame); |
| 41 | 58 |
| 42 // RenderFrameObserver implementation. | 59 // RenderFrameObserver implementation. |
| 43 bool OnMessageReceived(const IPC::Message& message) override; | 60 bool OnMessageReceived(const IPC::Message& message) override; |
| 44 void OnDestruct() override; | 61 void OnDestruct() override; |
| 45 | 62 |
| 46 void OnGetThreatDOMDetails(); | 63 void OnGetThreatDOMDetails(); |
| 47 | 64 |
| 65 // A list of tag names and associates attributes, used to determine which |
| 66 // elements need to be collected. |
| 67 std::vector<TagAndAttributesItem> tag_and_attributes_list_; |
| 68 |
| 48 DISALLOW_COPY_AND_ASSIGN(ThreatDOMDetails); | 69 DISALLOW_COPY_AND_ASSIGN(ThreatDOMDetails); |
| 49 }; | 70 }; |
| 50 | 71 |
| 51 } // namespace safe_browsing | 72 } // namespace safe_browsing |
| 52 | 73 |
| 53 #endif // CHROME_RENDERER_SAFE_BROWSING_THREAT_DOM_DETAILS_H_ | 74 #endif // CHROME_RENDERER_SAFE_BROWSING_THREAT_DOM_DETAILS_H_ |
| OLD | NEW |