Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page.h

Issue 56135: Adding unit tests for the SafeBrowsingBlockingPage class (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Classes for managing the SafeBrowsing interstitial pages. 5 // Classes for managing the SafeBrowsing interstitial pages.
6 // 6 //
7 // When a user is about to visit a page the SafeBrowsing system has deemed to 7 // When a user is about to visit a page the SafeBrowsing system has deemed to
8 // be malicious, either as malware or a phishing page, we show an interstitial 8 // be malicious, either as malware or a phishing page, we show an interstitial
9 // page with some options (go back, continue) to give the user a chance to avoid 9 // page with some options (go back, continue) to give the user a chance to avoid
10 // the harmful page. 10 // the harmful page.
(...skipping 20 matching lines...) Expand all
31 #include <map> 31 #include <map>
32 #include <vector> 32 #include <vector>
33 33
34 #include "chrome/browser/tab_contents/interstitial_page.h" 34 #include "chrome/browser/tab_contents/interstitial_page.h"
35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
36 #include "googleurl/src/gurl.h" 36 #include "googleurl/src/gurl.h"
37 37
38 class DictionaryValue; 38 class DictionaryValue;
39 class MessageLoop; 39 class MessageLoop;
40 class NavigationController; 40 class NavigationController;
41 class SafeBrowsingBlockingPageFactory;
41 class WebContents; 42 class WebContents;
42 43
43
44 class SafeBrowsingBlockingPage : public InterstitialPage { 44 class SafeBrowsingBlockingPage : public InterstitialPage {
45 public: 45 public:
46 virtual ~SafeBrowsingBlockingPage(); 46 virtual ~SafeBrowsingBlockingPage();
47 47
48 // Shows a blocking page warning the user about phishing/malware for a 48 // Shows a blocking page warning the user about phishing/malware for a
49 // specific resource. 49 // specific resource.
50 // You can call this method several times, if an interstitial is already 50 // You can call this method several times, if an interstitial is already
51 // showing, the new one will be queued and displayed if the user decides 51 // showing, the new one will be queued and displayed if the user decides
52 // to proceed on the currently showing interstitial. 52 // to proceed on the currently showing interstitial.
53 static void ShowBlockingPage( 53 static void ShowBlockingPage(
54 SafeBrowsingService* service, 54 SafeBrowsingService* service,
55 const SafeBrowsingService::UnsafeResource& resource); 55 const SafeBrowsingService::UnsafeResource& resource);
56 56
57 // Makes the passed |factory| the factory used to instanciate
58 // SafeBrowsingBlockingPage objects. Usefull for tests.
59 static void RegisterFactory(SafeBrowsingBlockingPageFactory* factory) {
60 factory_ = factory;
61 }
62
57 // InterstitialPage method: 63 // InterstitialPage method:
58 virtual std::string GetHTMLContents(); 64 virtual std::string GetHTMLContents();
59 virtual void Proceed(); 65 virtual void Proceed();
60 virtual void DontProceed(); 66 virtual void DontProceed();
61 67
68 typedef std::vector<SafeBrowsingService::UnsafeResource> UnsafeResourceList;
69
62 protected: 70 protected:
63 // InterstitialPage method: 71 // InterstitialPage method:
64 virtual void CommandReceived(const std::string& command); 72 virtual void CommandReceived(const std::string& command);
65 73
66 private:
67 typedef std::vector<SafeBrowsingService::UnsafeResource> UnsafeResourceList;
68
69 // Don't instanciate this class directly, use ShowBlockingPage instead. 74 // Don't instanciate this class directly, use ShowBlockingPage instead.
70 SafeBrowsingBlockingPage(SafeBrowsingService* service, 75 SafeBrowsingBlockingPage(SafeBrowsingService* service,
71 WebContents* web_contents, 76 WebContents* web_contents,
72 const UnsafeResourceList& unsafe_resources); 77 const UnsafeResourceList& unsafe_resources);
73 78
79 private:
74 // Fills the passed dictionary with the strings passed to JS Template when 80 // Fills the passed dictionary with the strings passed to JS Template when
75 // creating the HTML. 81 // creating the HTML.
76 void PopulateMultipleThreatStringDictionary(DictionaryValue* strings); 82 void PopulateMultipleThreatStringDictionary(DictionaryValue* strings);
77 void PopulateMalwareStringDictionary(DictionaryValue* strings); 83 void PopulateMalwareStringDictionary(DictionaryValue* strings);
78 void PopulatePhishingStringDictionary(DictionaryValue* strings); 84 void PopulatePhishingStringDictionary(DictionaryValue* strings);
79 85
80 // A helper method used by the Populate methods above used to populate common 86 // A helper method used by the Populate methods above used to populate common
81 // fields. 87 // fields.
82 void PopulateStringDictionary(DictionaryValue* strings, 88 void PopulateStringDictionary(DictionaryValue* strings,
83 const std::wstring& title, 89 const std::wstring& title,
(...skipping 12 matching lines...) Expand all
96 // Notifies the SafeBrowsingService on the IO thread whether to proceed or not 102 // Notifies the SafeBrowsingService on the IO thread whether to proceed or not
97 // for the |resources|. 103 // for the |resources|.
98 static void NotifySafeBrowsingService(SafeBrowsingService* sb_service, 104 static void NotifySafeBrowsingService(SafeBrowsingService* sb_service,
99 const UnsafeResourceList& resources, 105 const UnsafeResourceList& resources,
100 bool proceed); 106 bool proceed);
101 107
102 // Returns true if the passed |unsafe_resources| is for the main page. 108 // Returns true if the passed |unsafe_resources| is for the main page.
103 static bool IsMainPage(const UnsafeResourceList& unsafe_resources); 109 static bool IsMainPage(const UnsafeResourceList& unsafe_resources);
104 110
105 private: 111 private:
112 friend class SafeBrowsingBlockingPageFactoryImpl;
113
106 // For reporting back user actions. 114 // For reporting back user actions.
107 SafeBrowsingService* sb_service_; 115 SafeBrowsingService* sb_service_;
108 MessageLoop* report_loop_; 116 MessageLoop* report_loop_;
109 117
110 // Whether the flagged resource is the main page (or a sub-resource is false). 118 // Whether the flagged resource is the main page (or a sub-resource is false).
111 bool is_main_frame_; 119 bool is_main_frame_;
112 120
113 // The index of a navigation entry that should be removed when DontProceed() 121 // The index of a navigation entry that should be removed when DontProceed()
114 // is invoked, -1 if not entry should be removed. 122 // is invoked, -1 if not entry should be removed.
115 int navigation_entry_index_to_remove_; 123 int navigation_entry_index_to_remove_;
116 124
117 // The list of unsafe resources this page is warning about. 125 // The list of unsafe resources this page is warning about.
118 UnsafeResourceList unsafe_resources_; 126 UnsafeResourceList unsafe_resources_;
119 127
128 // The factory used to instanciate SafeBrowsingBlockingPage objects.
129 // Usefull for tests, so they can provide their own implementation of
130 // SafeBrowsingBlockingPage.
131 static SafeBrowsingBlockingPageFactory* factory_;
132
120 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); 133 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage);
121 }; 134 };
122 135
136 // Factory for creating SafeBrowsingBlockingPage. Useful for tests.
137 class SafeBrowsingBlockingPageFactory {
138 public:
139 ~SafeBrowsingBlockingPageFactory() { }
140
141 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
142 SafeBrowsingService* service,
143 WebContents* web_contents,
144 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) = 0;
145 };
146
123 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ 147 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/mock_render_process_host.cc ('k') | chrome/browser/safe_browsing/safe_browsing_blocking_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698