summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/safe_browsing/malware_dom_details.h
blob: b53a117ab9b17ea1274471ae111acc6854463ecb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// MalwareDOMDetails iterates over a document's frames and gathers
// interesting URLs such as those of scripts and frames. When done, it sends
// them to the MalwareDetails that requested them.

#ifndef CHROME_RENDERER_SAFE_BROWSING_MALWARE_DOM_DETAILS_H_
#define CHROME_RENDERER_SAFE_BROWSING_MALWARE_DOM_DETAILS_H_

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/callback.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
#include "chrome/renderer/render_view_observer.h"

class GURL;
class RenderView;

namespace WebKit {
class WebElement;
class WebFrame;
}

struct ViewHostMsg_MalwareDOMDetails_Params;
struct ViewHostMsg_MalwareDOMDetails_Node;

namespace safe_browsing {

// There is one MalwareDOMDetails per RenderView.
class MalwareDOMDetails : public RenderViewObserver {
 public:
  // An upper limit on the number of nodes we collect. Not const for the test.
  static uint32 kMaxNodes;

  // Creates a MalwareDOMDetails for the specified RenderView.
  // The MalwareDOMDetails should be destroyed prior to destroying
  // the RenderView.
  explicit MalwareDOMDetails(RenderView* render_view);
  ~MalwareDOMDetails();

  // Begins extracting resource urls for the page currently loaded in
  // this object's RenderView.
  void ExtractResources(ViewHostMsg_MalwareDOMDetails_Params* resources);

 private:
  // RenderViewObserver implementation.
  virtual bool OnMessageReceived(const IPC::Message& message);

  void OnGetMalwareDOMDetails();

  // Handler for the various HTML elements that we extract URLs from.
  void HandleElement(const WebKit::WebElement& element,
                     ViewHostMsg_MalwareDOMDetails_Node* parent_node,
                     ViewHostMsg_MalwareDOMDetails_Params* resources);

  // Non-owned pointer to the view that we will extract features from.
  RenderView* render_view_;

  DISALLOW_COPY_AND_ASSIGN(MalwareDOMDetails);
};

}  // namespace safe_browsing

#endif  // CHROME_RENDERER_SAFE_BROWSING_MALWARE_DOM_DETAILS_H_