OLD | NEW |
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 #ifndef CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_ |
6 #define CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/timer.h" | 13 #include "base/timer.h" |
14 #include "chrome/browser/renderer_host/resource_handler.h" | 14 #include "chrome/browser/renderer_host/resource_handler.h" |
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
16 #include "chrome/common/notification_observer.h" | |
17 #include "chrome/common/notification_registrar.h" | |
18 | 16 |
19 class ResourceDispatcherHost; | 17 class ResourceDispatcherHost; |
20 | 18 |
21 // SafeBrowsingResourceHandler checks that URLs are "safe" before navigating | 19 // SafeBrowsingResourceHandler checks that URLs are "safe" before navigating |
22 // to them. To be considered "safe", a URL must not appear in the | 20 // to them. To be considered "safe", a URL must not appear in the |
23 // malware/phishing blacklists (see SafeBrowsingService for details). | 21 // malware/phishing blacklists (see SafeBrowsingService for details). |
24 // | 22 // |
25 // This check is done before requesting the original URL, and additionally | 23 // This check is done before requesting the original URL, and additionally |
26 // before following any subsequent redirect. | 24 // before following any subsequent redirect. |
27 // | 25 // |
28 // In the common case, the check completes synchronously (no match in the bloom | 26 // In the common case, the check completes synchronously (no match in the bloom |
29 // filter), so the request's flow is un-interrupted. | 27 // filter), so the request's flow is un-interrupted. |
30 // | 28 // |
31 // However if the URL fails this quick check, it has the possibility of being | 29 // However if the URL fails this quick check, it has the possibility of being |
32 // on the blacklist. Now the request is suspended (prevented from starting), | 30 // on the blacklist. Now the request is suspended (prevented from starting), |
33 // and a more expensive safe browsing check is begun (fetches the full hashes). | 31 // and a more expensive safe browsing check is begun (fetches the full hashes). |
34 // | 32 // |
35 // Note that the safe browsing check takes at most kCheckUrlTimeoutMs | 33 // Note that the safe browsing check takes at most kCheckUrlTimeoutMs |
36 // milliseconds. If it takes longer than this, then the system defaults to | 34 // milliseconds. If it takes longer than this, then the system defaults to |
37 // treating the URL as safe. | 35 // treating the URL as safe. |
38 // | 36 // |
39 // Once the safe browsing check has completed, if the URL was decided to be | 37 // Once the safe browsing check has completed, if the URL was decided to be |
40 // dangerous, a warning page is thrown up and the request remains suspended. | 38 // dangerous, a warning page is thrown up and the request remains suspended. |
41 // If on the other hand the URL was decided to be safe, the request is | 39 // If on the other hand the URL was decided to be safe, the request is |
42 // resumed. | 40 // resumed. |
43 class SafeBrowsingResourceHandler : public ResourceHandler, | 41 class SafeBrowsingResourceHandler : public ResourceHandler, |
44 public SafeBrowsingService::Client, | 42 public SafeBrowsingService::Client { |
45 public NotificationObserver { | |
46 public: | 43 public: |
47 SafeBrowsingResourceHandler(ResourceHandler* handler, | 44 SafeBrowsingResourceHandler(ResourceHandler* handler, |
48 int render_process_host_id, | 45 int render_process_host_id, |
49 int render_view_id, | 46 int render_view_id, |
50 ResourceType::Type resource_type, | 47 ResourceType::Type resource_type, |
51 SafeBrowsingService* safe_browsing, | 48 SafeBrowsingService* safe_browsing, |
52 ResourceDispatcherHost* resource_dispatcher_host); | 49 ResourceDispatcherHost* resource_dispatcher_host); |
53 | 50 |
54 // ResourceHandler implementation: | 51 // ResourceHandler implementation: |
55 virtual bool OnUploadProgress(int request_id, uint64 position, uint64 size); | 52 virtual bool OnUploadProgress(int request_id, uint64 position, uint64 size); |
(...skipping 11 matching lines...) Expand all Loading... |
67 | 64 |
68 // SafeBrowsingService::Client implementation, called on the IO thread once | 65 // SafeBrowsingService::Client implementation, called on the IO thread once |
69 // the URL has been classified. | 66 // the URL has been classified. |
70 virtual void OnBrowseUrlCheckResult( | 67 virtual void OnBrowseUrlCheckResult( |
71 const GURL& url, SafeBrowsingService::UrlCheckResult result); | 68 const GURL& url, SafeBrowsingService::UrlCheckResult result); |
72 | 69 |
73 // SafeBrowsingService::Client implementation, called on the IO thread when | 70 // SafeBrowsingService::Client implementation, called on the IO thread when |
74 // the user has decided to proceed with the current request, or go back. | 71 // the user has decided to proceed with the current request, or go back. |
75 virtual void OnBlockingPageComplete(bool proceed); | 72 virtual void OnBlockingPageComplete(bool proceed); |
76 | 73 |
77 // NotificationObserver interface. | |
78 virtual void Observe(NotificationType type, | |
79 const NotificationSource& source, | |
80 const NotificationDetails& details); | |
81 | |
82 private: | 74 private: |
83 // Describes what phase of the check a handler is in. | 75 // Describes what phase of the check a handler is in. |
84 enum State { | 76 enum State { |
85 STATE_NONE, | 77 STATE_NONE, |
86 STATE_CHECKING_URL, | 78 STATE_CHECKING_URL, |
87 STATE_DISPLAYING_BLOCKING_PAGE, | 79 STATE_DISPLAYING_BLOCKING_PAGE, |
88 }; | 80 }; |
89 | 81 |
90 // Describes what stage of the request got paused by the check. | 82 // Describes what stage of the request got paused by the check. |
91 enum DeferState { | 83 enum DeferState { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 130 |
139 // Timer to abort the safe browsing check if it takes too long. | 131 // Timer to abort the safe browsing check if it takes too long. |
140 base::OneShotTimer<SafeBrowsingResourceHandler> timer_; | 132 base::OneShotTimer<SafeBrowsingResourceHandler> timer_; |
141 | 133 |
142 // Details on the deferred request (either a start or redirect). It is only | 134 // Details on the deferred request (either a start or redirect). It is only |
143 // valid to access these members when defer_state_ != DEFERRED_NONE. | 135 // valid to access these members when defer_state_ != DEFERRED_NONE. |
144 GURL deferred_url_; | 136 GURL deferred_url_; |
145 int deferred_request_id_; | 137 int deferred_request_id_; |
146 scoped_refptr<ResourceResponse> deferred_redirect_response_; | 138 scoped_refptr<ResourceResponse> deferred_redirect_response_; |
147 | 139 |
148 NotificationRegistrar registrar_; | |
149 scoped_refptr<ResourceHandler> next_handler_; | 140 scoped_refptr<ResourceHandler> next_handler_; |
150 int render_process_host_id_; | 141 int render_process_host_id_; |
151 int render_view_id_; | 142 int render_view_id_; |
152 scoped_refptr<SafeBrowsingService> safe_browsing_; | 143 scoped_refptr<SafeBrowsingService> safe_browsing_; |
153 ResourceDispatcherHost* rdh_; | 144 ResourceDispatcherHost* rdh_; |
154 ResourceType::Type resource_type_; | 145 ResourceType::Type resource_type_; |
155 | 146 |
156 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceHandler); | 147 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceHandler); |
157 }; | 148 }; |
158 | 149 |
159 | 150 |
160 #endif // CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_ | 151 #endif // CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_HANDLER_H_ |
OLD | NEW |