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 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 instant->DestroyPreviewContents(); | 442 instant->DestroyPreviewContents(); |
443 } | 443 } |
444 | 444 |
445 autocomplete_controller_->Stop(true); | 445 autocomplete_controller_->Stop(true); |
446 } | 446 } |
447 | 447 |
448 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const { | 448 bool OmniboxEditModel::CanPasteAndGo(const string16& text) const { |
449 if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) | 449 if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) |
450 return false; | 450 return false; |
451 | 451 |
452 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 452 AutocompleteMatch match; |
453 string16(), false, false, &paste_and_go_match_, | 453 ClassifyStringForPasteAndGo(text, &match, NULL); |
454 &paste_and_go_alternate_nav_url_); | 454 return match.destination_url.is_valid(); |
455 return paste_and_go_match_.destination_url.is_valid(); | |
456 } | 455 } |
457 | 456 |
458 void OmniboxEditModel::PasteAndGo() { | 457 void OmniboxEditModel::PasteAndGo(const string16& text) { |
| 458 DCHECK(CanPasteAndGo(text)); |
459 view_->RevertAll(); | 459 view_->RevertAll(); |
460 view_->OpenMatch(paste_and_go_match_, CURRENT_TAB, | 460 AutocompleteMatch match; |
461 paste_and_go_alternate_nav_url_, OmniboxPopupModel::kNoMatch); | 461 GURL alternate_nav_url; |
| 462 ClassifyStringForPasteAndGo(text, &match, &alternate_nav_url); |
| 463 view_->OpenMatch(match, CURRENT_TAB, alternate_nav_url, |
| 464 OmniboxPopupModel::kNoMatch); |
| 465 } |
| 466 |
| 467 bool OmniboxEditModel::IsPasteAndSearch(const string16& text) const { |
| 468 AutocompleteMatch match; |
| 469 ClassifyStringForPasteAndGo(text, &match, NULL); |
| 470 return (match.transition != content::PAGE_TRANSITION_TYPED); |
462 } | 471 } |
463 | 472 |
464 void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, | 473 void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, |
465 bool for_drop) { | 474 bool for_drop) { |
466 // Get the URL and transition type for the selected entry. | 475 // Get the URL and transition type for the selected entry. |
467 AutocompleteMatch match; | 476 AutocompleteMatch match; |
468 GURL alternate_nav_url; | 477 GURL alternate_nav_url; |
469 GetInfoForCurrentText(&match, &alternate_nav_url); | 478 GetInfoForCurrentText(&match, &alternate_nav_url); |
470 | 479 |
471 if (!match.destination_url.is_valid()) | 480 if (!match.destination_url.is_valid()) |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 return metrics::OmniboxEventProto_PageClassification_INVALID_SPEC; | 1159 return metrics::OmniboxEventProto_PageClassification_INVALID_SPEC; |
1151 const std::string& url = gurl.spec(); | 1160 const std::string& url = gurl.spec(); |
1152 if (url == chrome::kChromeUINewTabURL) | 1161 if (url == chrome::kChromeUINewTabURL) |
1153 return metrics::OmniboxEventProto_PageClassification_NEW_TAB_PAGE; | 1162 return metrics::OmniboxEventProto_PageClassification_NEW_TAB_PAGE; |
1154 if (url == chrome::kAboutBlankURL) | 1163 if (url == chrome::kAboutBlankURL) |
1155 return metrics::OmniboxEventProto_PageClassification_BLANK; | 1164 return metrics::OmniboxEventProto_PageClassification_BLANK; |
1156 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) | 1165 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) |
1157 return metrics::OmniboxEventProto_PageClassification_HOMEPAGE; | 1166 return metrics::OmniboxEventProto_PageClassification_HOMEPAGE; |
1158 return metrics::OmniboxEventProto_PageClassification_OTHER; | 1167 return metrics::OmniboxEventProto_PageClassification_OTHER; |
1159 } | 1168 } |
| 1169 |
| 1170 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
| 1171 const string16& text, |
| 1172 AutocompleteMatch* match, |
| 1173 GURL* alternate_nav_url) const { |
| 1174 DCHECK(match); |
| 1175 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
| 1176 string16(), false, false, match, alternate_nav_url); |
| 1177 } |
OLD | NEW |