#ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_
#define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_
#include <string>
#include <vector>
#include "base/containers/hash_tables.h"
#include "base/gtest_prod_util.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/safe_browsing/report.pb.h"
#include "chrome/browser/safe_browsing/ui_manager.h"
#include "content/public/browser/web_contents_observer.h"
#include "net/base/completion_callback.h"
namespace net {
class URLRequestContextGetter;
}
class MalwareDetailsCacheCollector;
class MalwareDetailsRedirectsCollector;
class MalwareDetailsFactory;
class Profile;
struct SafeBrowsingHostMsg_MalwareDOMDetails_Node;
namespace safe_browsing {
typedef base::hash_map<
std::string,
linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap;
}
class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>,
public content::WebContentsObserver {
public:
typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource;
static MalwareDetails* NewMalwareDetails(
SafeBrowsingUIManager* ui_manager,
content::WebContents* web_contents,
const UnsafeResource& resource);
static void RegisterFactory(MalwareDetailsFactory* factory) {
factory_ = factory;
}
void FinishCollection();
void OnCacheCollectionReady();
void OnRedirectionCollectionReady();
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
protected:
friend class MalwareDetailsFactoryImpl;
MalwareDetails(SafeBrowsingUIManager* ui_manager,
content::WebContents* web_contents,
const UnsafeResource& resource);
virtual ~MalwareDetails();
virtual void AddDOMDetails(
const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params);
Profile* profile_;
scoped_ptr<safe_browsing::ClientMalwareReportRequest> report_;
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
private:
friend class base::RefCountedThreadSafe<MalwareDetails>;
void StartCollection();
bool IsPublicUrl(const GURL& url) const;
safe_browsing::ClientMalwareReportRequest::Resource* FindOrCreateResource(
const GURL& url);
void AddUrl(const GURL& url,
const GURL& parent,
const std::string& tagname,
const std::vector<GURL>* children);
void OnReceivedMalwareDOMDetails(
const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params);
void AddRedirectUrlList(const std::vector<GURL>& urls);
scoped_refptr<SafeBrowsingUIManager> ui_manager_;
const UnsafeResource resource_;
safe_browsing::ResourceMap resources_;
bool cache_result_;
static MalwareDetailsFactory* factory_;
scoped_refptr<MalwareDetailsCacheCollector> cache_collector_;
scoped_refptr<MalwareDetailsRedirectsCollector> redirects_collector_;
FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, MalwareDOMDetails);
FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCache);
FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCacheNoEntries);
FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HistoryServiceUrls);
DISALLOW_COPY_AND_ASSIGN(MalwareDetails);
};
class MalwareDetailsFactory {
public:
virtual ~MalwareDetailsFactory() { }
virtual MalwareDetails* CreateMalwareDetails(
SafeBrowsingUIManager* ui_manager,
content::WebContents* web_contents,
const SafeBrowsingUIManager::UnsafeResource& unsafe_resource) = 0;
};
#endif