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

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

Issue 18346: Adds support for multiple malware/phishing resources in a page (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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.
11 // 11 //
12 // The SafeBrowsingBlockingPage is created by the SafeBrowsingService on the UI 12 // The SafeBrowsingBlockingPage is created by the SafeBrowsingService on the UI
13 // thread when we've determined that a page is malicious. The operation of the 13 // thread when we've determined that a page is malicious. The operation of the
14 // blocking page occurs on the UI thread, where it waits for the user to make a 14 // blocking page occurs on the UI thread, where it waits for the user to make a
15 // decision about what to do: either go back or continue on. 15 // decision about what to do: either go back or continue on.
16 // 16 //
17 // The blocking page forwards the result of the user's choice back to the 17 // The blocking page forwards the result of the user's choice back to the
18 // SafeBrowsingService so that we can cancel the request for the new page, or 18 // SafeBrowsingService so that we can cancel the request for the new page, or
19 // or allow it to continue. 19 // or allow it to continue.
20 //
21 // A web page may contain several resources flagged as malware/phishing. This
22 // results into more than one interstitial being shown. On the first unsafe
23 // resource received we show an interstitial. Any subsequent unsafe resource
24 // notifications while the first interstitial is showing is queued. If the user
25 // decides to proceed in the first interstitial, we display all queued unsafe
26 // resources in a new interstitial.
20 27
21 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ 28 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_
22 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ 29 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_
23 30
31 #include <map>
32 #include <vector>
33
24 #include "base/logging.h" 34 #include "base/logging.h"
25 #include "chrome/browser/tab_contents/interstitial_page.h" 35 #include "chrome/browser/tab_contents/interstitial_page.h"
26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
27 #include "googleurl/src/gurl.h" 37 #include "googleurl/src/gurl.h"
28 38
39 class DictionaryValue;
29 class MessageLoop; 40 class MessageLoop;
30 class TabContents;
31 class NavigationController; 41 class NavigationController;
42 class WebContents;
43
32 44
33 class SafeBrowsingBlockingPage : public InterstitialPage { 45 class SafeBrowsingBlockingPage : public InterstitialPage {
34 public: 46 public:
35 SafeBrowsingBlockingPage(SafeBrowsingService* service,
36 const SafeBrowsingService::BlockingPageParam& param);
37 virtual ~SafeBrowsingBlockingPage(); 47 virtual ~SafeBrowsingBlockingPage();
38 48
49 // Shows a blocking page warning the user about phishing/malware for a
50 // specific resource.
51 // You can call this method several times, if an interstitial is already
52 // showing, the new one will be queued and displayed if the user decides
53 // to proceed on the currently showing interstitial.
54 static void ShowBlockingPage(
55 SafeBrowsingService* service,
56 const SafeBrowsingService::UnsafeResource& resource);
57
39 // InterstitialPage method: 58 // InterstitialPage method:
40 virtual std::string GetHTMLContents(); 59 virtual std::string GetHTMLContents();
60 virtual void Proceed();
41 virtual void DontProceed(); 61 virtual void DontProceed();
42 62
43 protected: 63 protected:
44 // InterstitialPage method: 64 // InterstitialPage method:
45 virtual void CommandReceived(const std::string& command); 65 virtual void CommandReceived(const std::string& command);
46 66
47 private: 67 private:
48 // Tells the SafeBrowsingService that the handling of the current page is 68 typedef std::vector<SafeBrowsingService::UnsafeResource> UnsafeResourceList;
49 // done. 69
50 void NotifyDone(); 70 // Don't instanciate this class directly, use ShowBlockingPage instead.
71 SafeBrowsingBlockingPage(SafeBrowsingService* service,
72 WebContents* web_contents,
73 const UnsafeResourceList& unsafe_resources);
74
75 // Fills the passed dictionary with the strings passed to JS Template when
76 // creating the HTML.
77 void PopulateMultipleThreatStringDictionary(DictionaryValue* strings);
78 void PopulateMalwareStringDictionary(DictionaryValue* strings);
79 void PopulatePhishingStringDictionary(DictionaryValue* strings);
80
81 // A helper method used by the Populate methods above used to populate common
82 // fields.
83 void PopulateStringDictionary(DictionaryValue* strings,
84 const std::wstring& title,
85 const std::wstring& headline,
86 const std::wstring& description1,
87 const std::wstring& description2,
88 const std::wstring& description3);
89
90
91 // A list of SafeBrowsingService::UnsafeResource for a tab that the user
92 // should be warned about. They are queued when displaying more than one
93 // interstitial at a time.
94 typedef std::map<WebContents*, UnsafeResourceList> UnsafeResourceMap;
95 static UnsafeResourceMap* GetUnsafeResourcesMap();
96
97 // Notifies the SafeBrowsingService on the IO thread whether to proceed or not
98 // for the |resources|.
99 static void NotifySafeBrowsingService(SafeBrowsingService* sb_service,
100 const UnsafeResourceList& resources,
101 bool proceed);
102
103 // Returns true if the passed |unsafe_resources| is for the main page.
104 static bool IsMainPage(const UnsafeResourceList& unsafe_resources);
51 105
52 private: 106 private:
53 // For reporting back user actions. 107 // For reporting back user actions.
54 SafeBrowsingService* sb_service_; 108 SafeBrowsingService* sb_service_;
55 SafeBrowsingService::Client* client_;
56 MessageLoop* report_loop_; 109 MessageLoop* report_loop_;
57 SafeBrowsingService::UrlCheckResult result_;
58
59 // For determining which tab to block (note that we need this even though we
60 // have access to the tab as when the interstitial is showing, retrieving the
61 // tab RPH and RV id would return the ones of the interstitial, not the ones
62 // for the page containing the malware).
63 // TODO(jcampan): when we refactor the interstitial to run as a separate view
64 // that does not interact with the WebContents as much, we can
65 // get rid of these.
66 int render_process_host_id_;
67 int render_view_id_;
68
69 // Inform the SafeBrowsingService whether we are continuing with this page
70 // load or going back to the previous page.
71 bool proceed_;
72
73 // Whether we have notify the SafeBrowsingService yet that a decision had been
74 // made whether to proceed or block the unsafe resource.
75 bool did_notify_;
76 110
77 // Whether the flagged resource is the main page (or a sub-resource is false). 111 // Whether the flagged resource is the main page (or a sub-resource is false).
78 bool is_main_frame_; 112 bool is_main_frame_;
79 113
80 // The index of a navigation entry that should be removed when DontProceed() 114 // The index of a navigation entry that should be removed when DontProceed()
81 // is invoked, -1 if not entry should be removed. 115 // is invoked, -1 if not entry should be removed.
82 int navigation_entry_index_to_remove_; 116 int navigation_entry_index_to_remove_;
83 117
118 // The list of unsafe resources this page is warning about.
119 UnsafeResourceList unsafe_resources_;
120
84 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage); 121 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPage);
85 }; 122 };
86 123
87 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_ 124 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_BLOCKING_PAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698