OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/incident_reporting/omnibox_watcher.h" |
| 6 |
| 7 #include "base/time/time.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/omnibox/omnibox_log.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/safe_browsing/csd.pb.h" |
| 12 #include "components/omnibox/autocomplete_result.h" |
| 13 #include "content/public/browser/notification_details.h" |
| 14 #include "content/public/browser/notification_service.h" |
| 15 |
| 16 namespace safe_browsing { |
| 17 |
| 18 OmniboxWatcher::OmniboxWatcher(Profile* profile, |
| 19 const AddIncidentCallback& callback): |
| 20 incident_callback_(callback) { |
| 21 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
| 22 content::Source<Profile>(profile)); |
| 23 } |
| 24 |
| 25 OmniboxWatcher::~OmniboxWatcher() { |
| 26 } |
| 27 |
| 28 void OmniboxWatcher::Observe(int type, |
| 29 const content::NotificationSource& source, |
| 30 const content::NotificationDetails& details) { |
| 31 DCHECK_EQ(chrome::NOTIFICATION_OMNIBOX_OPENED_URL, type); |
| 32 const OmniboxLog* log = content::Details<OmniboxLog>(details).ptr(); |
| 33 const AutocompleteMatch& selected_suggestion = |
| 34 log->result.match_at(log->selected_index); |
| 35 // Users tend not to type very long strings explicitly (especially without |
| 36 // using the paste-and-go option), and certainly not in under a second. |
| 37 // No normal person can type URLs that fast! Navigating to a URL as a |
| 38 // result of such typing is suspicious. |
| 39 // TODO(mpearson): Add support for suspicious queries. |
| 40 if (!log->is_paste_and_go && log->is_popup_open && |
| 41 (log->text.length() > 200) && |
| 42 (log->elapsed_time_since_user_first_modified_omnibox < |
| 43 base::TimeDelta::FromSeconds(1)) && |
| 44 !AutocompleteMatch::IsSearchType(selected_suggestion.type)) { |
| 45 scoped_ptr<ClientIncidentReport_IncidentData> incident_data( |
| 46 new ClientIncidentReport_IncidentData()); |
| 47 const GURL& origin = selected_suggestion.destination_url.GetOrigin(); |
| 48 incident_data->mutable_omnibox_interaction()->set_origin( |
| 49 origin.possibly_invalid_spec()); |
| 50 incident_callback_.Run(incident_data.Pass()); |
| 51 } |
| 52 } |
| 53 |
| 54 } // namespace safe_browsing |
OLD | NEW |