OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.h" | |
9 #include "base/metrics/histogram.h" | |
10 #include "base/task.h" | |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/browser_thread.h" | |
13 #include "chrome/browser/renderer_host/render_process_host.h" | |
14 #include "chrome/browser/renderer_host/render_view_host.h" | |
15 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | |
16 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | |
17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
18 #include "chrome/browser/tab_contents/navigation_controller.h" | |
19 #include "chrome/browser/tab_contents/tab_contents.h" | |
20 #include "chrome/common/safebrowsing_messages.h" | |
21 #include "chrome/common/chrome_switches.h" | |
22 #include "chrome/common/render_messages_params.h" | |
23 #include "googleurl/src/gurl.h" | |
24 #include "ipc/ipc_message.h" | |
25 #include "ipc/ipc_message_macros.h" | |
26 | |
27 namespace safe_browsing { | |
28 | |
29 ClientSideDetectionHost::ClientSideDetectionHost(TabContents* tab) | |
30 : tab_(tab), | |
31 service_(g_browser_process->safe_browsing_detection_service()), | |
32 cb_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
33 DCHECK(tab); | |
34 // Note: service_ and sb_service_ might be NULL. | |
35 ResourceDispatcherHost* resource = | |
36 g_browser_process->resource_dispatcher_host(); | |
37 if (resource) { | |
38 sb_service_ = resource->safe_browsing_service(); | |
39 } | |
40 } | |
41 | |
42 ClientSideDetectionHost::~ClientSideDetectionHost() { | |
43 } | |
44 | |
45 bool ClientSideDetectionHost::OnMessageReceived(const IPC::Message& message) { | |
46 bool handled = true; | |
47 IPC_BEGIN_MESSAGE_MAP(ClientSideDetectionHost, message) | |
48 IPC_MESSAGE_HANDLER(SafeBrowsingDetectionHostMsg_DetectedPhishingSite, | |
49 OnDetectedPhishingSite) | |
50 IPC_MESSAGE_UNHANDLED(handled = false) | |
51 IPC_END_MESSAGE_MAP() | |
52 return handled; | |
53 } | |
54 | |
55 void ClientSideDetectionHost::DidNavigateMainFramePostCommit( | |
56 const NavigationController::LoadCommittedDetails& details, | |
57 const ViewHostMsg_FrameNavigate_Params& params) { | |
58 // TODO(noelutz): move this DCHECK to TabContents and fix all the unit tests | |
59 // that don't call this method on the UI thread. | |
60 // DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
Brian Ryner
2011/02/11 01:30:39
Just so I understand, is the issue that the tests
noelutz
2011/02/15 23:00:55
Tests just don't create the UI browser thread obje
| |
61 | |
62 // If we navigate away and there currently is a pending phishing | |
63 // report request we have to cancel it to make sure we don't display | |
64 // an interstitial for the wrong page. Note that this won't cancel | |
65 // the server ping back but only cancel the showing of the | |
66 // interstial. | |
67 if (cb_factory_.HasPendingCallbacks()) { | |
Brian Ryner
2011/02/11 01:30:39
Is there a reason why you're wrapping this in HasP
noelutz
2011/02/15 23:00:55
You're right. It's not needed.
| |
68 cb_factory_.RevokeAll(); | |
69 } | |
70 } | |
71 | |
72 void ClientSideDetectionHost::OnDetectedPhishingSite(const GURL& phishing_url, | |
73 double phishing_score) { | |
74 // There is something seriously wrong if there is no service class but | |
75 // this method is called. The renderer should not start phishing detection | |
Brian Ryner
2011/02/11 01:30:39
Would this ever happen during shutdown? i.e. could
noelutz
2011/02/15 23:00:55
Good question. The ClientSideDetectionService cla
| |
76 // if there isn't any service class in the browser. | |
77 DCHECK(service_); | |
78 if (service_ && tab_) { | |
79 // There shouldn't be any pending requests because we revoke them everytime | |
80 // we navigate away. | |
81 DCHECK(!cb_factory_.HasPendingCallbacks()); | |
82 service_->SendClientReportPhishingRequest( | |
83 phishing_url, | |
84 phishing_score, | |
85 cb_factory_.NewCallback( | |
86 &ClientSideDetectionHost::MaybeShowPhishingWarning)); | |
87 } | |
88 } | |
89 | |
90 void ClientSideDetectionHost::MaybeShowPhishingWarning(GURL phishing_url, | |
91 bool is_phishing) { | |
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
93 if (is_phishing && | |
94 CommandLine::ForCurrentProcess()->HasSwitch( | |
95 switches::kEnableClientSidePhishingInterstitial)) { | |
96 DCHECK(tab_); | |
97 // TODO(noelutz): this is not perfect. It's still possible that the | |
98 // user browses away before the interstitial is shown. Maybe we should | |
Brian Ryner
2011/02/11 01:30:39
It would be kind of nice if we could change SafeBr
noelutz
2011/02/15 23:00:55
Page id might work. We can't simply check the phis
| |
99 // stop all pending navigations? | |
100 if (sb_service_) { | |
101 // TODO(noelutz): refactor this code so that we don't need to use | |
102 // the SafeBrowsing service class. | |
lzheng
2011/02/11 19:39:42
I will be happy if the DisplayBlockingPage could b
noelutz
2011/02/15 23:00:55
what does download do right now? We do share malw
lzheng
2011/02/16 19:09:32
Download doesn't use the interstitial page(I shoul
noelutz
2011/02/16 21:24:43
I'm not sure I fully understand your comment. Thi
| |
103 BrowserThread::PostTask( | |
104 BrowserThread::IO, | |
105 FROM_HERE, | |
106 NewRunnableMethod(sb_service_.get(), | |
107 &SafeBrowsingService::DisplayBlockingPage, | |
108 phishing_url, phishing_url, | |
109 // We only classify the main frame URL. | |
110 ResourceType::MAIN_FRAME, | |
111 // TODO(noelutz): create a separate threat type | |
112 // for client-side phishing detection. | |
113 SafeBrowsingService::URL_PHISHING, | |
114 new CsdClient() /* will delete itself */, | |
115 tab_->GetRenderProcessHost()->id(), | |
116 tab_->render_view_host()->routing_id())); | |
117 } | |
118 } | |
119 } | |
120 | |
121 void ClientSideDetectionHost::set_client_side_detection_service( | |
122 ClientSideDetectionService* service) { | |
123 service_ = service; | |
124 } | |
125 | |
126 void ClientSideDetectionHost::set_safe_browsing_service( | |
127 SafeBrowsingService* service) { | |
128 sb_service_ = service; | |
129 } | |
130 | |
131 CsdClient::CsdClient() {} | |
132 | |
133 CsdClient::~CsdClient() {} | |
134 | |
135 void CsdClient::OnBlockingPageComplete(bool proceed) { | |
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
137 // Delete this on the UI thread since it was created there. | |
138 BrowserThread::PostTask(BrowserThread::UI, | |
139 FROM_HERE, | |
140 new DeleteTask<CsdClient>(this)); | |
141 } | |
142 | |
143 } // namespace safe_browsing | |
OLD | NEW |