| 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 // The Safe Browsing service is responsible for downloading anti-phishing and | 5 // The Safe Browsing service is responsible for downloading anti-phishing and |
| 6 // anti-malware tables and checking urls against them. | 6 // anti-malware tables and checking urls against them. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/permissions/permission_uma_util.h" | 19 #include "chrome/browser/permissions/permission_uma_util.h" |
| 20 #include "components/safe_browsing_db/hit_report.h" | 20 #include "components/safe_browsing_db/hit_report.h" |
| 21 #include "components/safe_browsing_db/util.h" | 21 #include "components/safe_browsing_db/util.h" |
| 22 #include "components/security_interstitials/content/unsafe_resource.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/permission_type.h" | 24 #include "content/public/browser/permission_type.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 class NavigationEntry; | 28 class NavigationEntry; |
| 28 class WebContents; | 29 class WebContents; |
| 29 } // namespace content | 30 } // namespace content |
| 30 | 31 |
| 31 namespace safe_browsing { | 32 namespace safe_browsing { |
| 32 | 33 |
| 33 class SafeBrowsingService; | 34 class SafeBrowsingService; |
| 34 | 35 |
| 35 // Construction needs to happen on the main thread. | 36 // Construction needs to happen on the main thread. |
| 36 class SafeBrowsingUIManager | 37 class SafeBrowsingUIManager |
| 37 : public base::RefCountedThreadSafe<SafeBrowsingUIManager> { | 38 : public base::RefCountedThreadSafe<SafeBrowsingUIManager> { |
| 38 public: | 39 public: |
| 39 // Passed a boolean indicating whether or not it is OK to proceed with | 40 typedef security_interstitials::UnsafeResource UnsafeResource; |
| 40 // loading an URL. | |
| 41 typedef base::Callback<void(bool /*proceed*/)> UrlCheckCallback; | |
| 42 | |
| 43 // Structure used to pass parameters between the IO and UI thread when | |
| 44 // interacting with the blocking page. | |
| 45 struct UnsafeResource { | |
| 46 UnsafeResource(); | |
| 47 UnsafeResource(const UnsafeResource& other); | |
| 48 ~UnsafeResource(); | |
| 49 | |
| 50 // Returns true if this UnsafeResource is a main frame load that was blocked | |
| 51 // while the navigation is still pending. Note that a main frame hit may not | |
| 52 // be blocking, eg. client side detection happens after the load is | |
| 53 // committed. | |
| 54 bool IsMainPageLoadBlocked() const; | |
| 55 | |
| 56 // Returns the NavigationEntry for this resource (for a main frame hit) or | |
| 57 // for the page which contains this resource (for a subresource hit). | |
| 58 // This method must only be called while the UnsafeResource is still | |
| 59 // "valid". | |
| 60 // I.e, | |
| 61 // For MainPageLoadBlocked resources, it must not be called if the load | |
| 62 // was aborted (going back or replaced with a different navigation), | |
| 63 // or resumed (proceeded through warning or matched whitelist). | |
| 64 // For non-MainPageLoadBlocked resources, it must not be called if any | |
| 65 // other navigation has committed (whether by going back or unrelated | |
| 66 // navigations), though a pending navigation is okay. | |
| 67 content::NavigationEntry* GetNavigationEntryForResource() const; | |
| 68 | |
| 69 // Helper to build a getter for WebContents* from render frame id. | |
| 70 static base::Callback<content::WebContents*(void)> GetWebContentsGetter( | |
| 71 int render_process_host_id, | |
| 72 int render_frame_id); | |
| 73 | |
| 74 GURL url; | |
| 75 GURL original_url; | |
| 76 std::vector<GURL> redirect_urls; | |
| 77 bool is_subresource; | |
| 78 bool is_subframe; | |
| 79 SBThreatType threat_type; | |
| 80 ThreatMetadata threat_metadata; | |
| 81 UrlCheckCallback callback; // This is called back on |callback_thread|. | |
| 82 scoped_refptr<base::SingleThreadTaskRunner> callback_thread; | |
| 83 base::Callback<content::WebContents*(void)> web_contents_getter; | |
| 84 safe_browsing::ThreatSource threat_source; | |
| 85 }; | |
| 86 | |
| 87 // Observer class can be used to get notified when a SafeBrowsing hit | 41 // Observer class can be used to get notified when a SafeBrowsing hit |
| 88 // was found. | 42 // was found. |
| 89 class Observer { | 43 class Observer { |
| 90 public: | 44 public: |
| 91 // The |resource| was classified as unsafe by SafeBrowsing, and is | 45 // The |resource| was classified as unsafe by SafeBrowsing, and is |
| 92 // not whitelisted. | 46 // not whitelisted. |
| 93 // The |resource| must not be accessed after OnSafeBrowsingHit returns. | 47 // The |resource| must not be accessed after OnSafeBrowsingHit returns. |
| 94 // This method will be called on the UI thread. | 48 // This method will be called on the UI thread. |
| 95 virtual void OnSafeBrowsingHit(const UnsafeResource& resource) = 0; | 49 virtual void OnSafeBrowsingHit(const UnsafeResource& resource) = 0; |
| 96 | 50 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 scoped_refptr<SafeBrowsingService> sb_service_; | 180 scoped_refptr<SafeBrowsingService> sb_service_; |
| 227 | 181 |
| 228 base::ObserverList<Observer> observer_list_; | 182 base::ObserverList<Observer> observer_list_; |
| 229 | 183 |
| 230 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingUIManager); | 184 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingUIManager); |
| 231 }; | 185 }; |
| 232 | 186 |
| 233 } // namespace safe_browsing | 187 } // namespace safe_browsing |
| 234 | 188 |
| 235 #endif // CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ | 189 #endif // CHROME_BROWSER_SAFE_BROWSING_UI_MANAGER_H_ |
| OLD | NEW |