OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 50 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
51 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" | 51 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" |
52 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 52 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
53 #include "chrome/browser/ui/search/instant_search_prerenderer.h" | 53 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
54 #include "chrome/browser/ui/search/search_tab_helper.h" | 54 #include "chrome/browser/ui/search/search_tab_helper.h" |
55 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 55 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
56 #include "chrome/common/chrome_switches.h" | 56 #include "chrome/common/chrome_switches.h" |
57 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
58 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
59 #include "components/google/core/browser/google_url_tracker.h" | 59 #include "components/google/core/browser/google_url_tracker.h" |
60 #include "components/url_fixer/url_fixer.h" | 60 #include "components/url_fixer/url_fixer.h" |
Mark P
2014/06/20 00:08:29
you forgot the metrics include here
Jun Mukai
2014/06/20 00:29:51
Done.
| |
61 #include "content/public/browser/navigation_controller.h" | 61 #include "content/public/browser/navigation_controller.h" |
62 #include "content/public/browser/navigation_entry.h" | 62 #include "content/public/browser/navigation_entry.h" |
63 #include "content/public/browser/notification_service.h" | 63 #include "content/public/browser/notification_service.h" |
64 #include "content/public/browser/render_view_host.h" | 64 #include "content/public/browser/render_view_host.h" |
65 #include "content/public/browser/user_metrics.h" | 65 #include "content/public/browser/user_metrics.h" |
66 #include "extensions/common/constants.h" | 66 #include "extensions/common/constants.h" |
67 #include "ui/gfx/image/image.h" | 67 #include "ui/gfx/image/image.h" |
68 #include "url/url_util.h" | 68 #include "url/url_util.h" |
69 | 69 |
70 using metrics::OmniboxEventProto; | |
70 using predictors::AutocompleteActionPredictor; | 71 using predictors::AutocompleteActionPredictor; |
71 | 72 |
72 | 73 |
73 // Helpers -------------------------------------------------------------------- | 74 // Helpers -------------------------------------------------------------------- |
74 | 75 |
75 namespace { | 76 namespace { |
76 | 77 |
77 // Histogram name which counts the number of times that the user text is | 78 // Histogram name which counts the number of times that the user text is |
78 // cleared. IME users are sometimes in the situation that IME was | 79 // cleared. IME users are sometimes in the situation that IME was |
79 // unintentionally turned on and failed to input latin alphabets (ASCII | 80 // unintentionally turned on and failed to input latin alphabets (ASCII |
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1419 bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1420 bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
1420 switch (c) { | 1421 switch (c) { |
1421 case 0x0020: // Space | 1422 case 0x0020: // Space |
1422 case 0x3000: // Ideographic Space | 1423 case 0x3000: // Ideographic Space |
1423 return true; | 1424 return true; |
1424 default: | 1425 default: |
1425 return false; | 1426 return false; |
1426 } | 1427 } |
1427 } | 1428 } |
1428 | 1429 |
1429 AutocompleteInput::PageClassification OmniboxEditModel::ClassifyPage() const { | 1430 OmniboxEventProto::PageClassification OmniboxEditModel::ClassifyPage() const { |
1430 if (!delegate_->CurrentPageExists()) | 1431 if (!delegate_->CurrentPageExists()) |
1431 return AutocompleteInput::OTHER; | 1432 return OmniboxEventProto::OTHER; |
1432 if (delegate_->IsInstantNTP()) { | 1433 if (delegate_->IsInstantNTP()) { |
1433 // Note that we treat OMNIBOX as the source if focus_source_ is INVALID, | 1434 // Note that we treat OMNIBOX as the source if focus_source_ is INVALID, |
1434 // i.e., if input isn't actually in progress. | 1435 // i.e., if input isn't actually in progress. |
1435 return (focus_source_ == FAKEBOX) ? | 1436 return (focus_source_ == FAKEBOX) ? |
1436 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS : | 1437 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS : |
1437 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS; | 1438 OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS; |
1438 } | 1439 } |
1439 const GURL& gurl = delegate_->GetURL(); | 1440 const GURL& gurl = delegate_->GetURL(); |
1440 if (!gurl.is_valid()) | 1441 if (!gurl.is_valid()) |
1441 return AutocompleteInput::INVALID_SPEC; | 1442 return OmniboxEventProto::INVALID_SPEC; |
1442 const std::string& url = gurl.spec(); | 1443 const std::string& url = gurl.spec(); |
1443 if (url == chrome::kChromeUINewTabURL) | 1444 if (url == chrome::kChromeUINewTabURL) |
1444 return AutocompleteInput::NTP; | 1445 return OmniboxEventProto::NTP; |
1445 if (url == url::kAboutBlankURL) | 1446 if (url == url::kAboutBlankURL) |
1446 return AutocompleteInput::BLANK; | 1447 return OmniboxEventProto::BLANK; |
1447 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) | 1448 if (url == profile()->GetPrefs()->GetString(prefs::kHomePage)) |
1448 return AutocompleteInput::HOME_PAGE; | 1449 return OmniboxEventProto::HOME_PAGE; |
1449 if (controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(true)) | 1450 if (controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(true)) |
1450 return AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; | 1451 return OmniboxEventProto::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT; |
1451 if (delegate_->IsSearchResultsPage()) | 1452 if (delegate_->IsSearchResultsPage()) |
1452 return AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT; | 1453 return OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT; |
1453 return AutocompleteInput::OTHER; | 1454 return OmniboxEventProto::OTHER; |
1454 } | 1455 } |
1455 | 1456 |
1456 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1457 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
1457 const base::string16& text, | 1458 const base::string16& text, |
1458 AutocompleteMatch* match, | 1459 AutocompleteMatch* match, |
1459 GURL* alternate_nav_url) const { | 1460 GURL* alternate_nav_url) const { |
1460 DCHECK(match); | 1461 DCHECK(match); |
1461 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( | 1462 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( |
1462 text, false, false, ClassifyPage(), match, alternate_nav_url); | 1463 text, false, false, ClassifyPage(), match, alternate_nav_url); |
1463 } | 1464 } |
1464 | 1465 |
1465 void OmniboxEditModel::SetFocusState(OmniboxFocusState state, | 1466 void OmniboxEditModel::SetFocusState(OmniboxFocusState state, |
1466 OmniboxFocusChangeReason reason) { | 1467 OmniboxFocusChangeReason reason) { |
1467 if (state == focus_state_) | 1468 if (state == focus_state_) |
1468 return; | 1469 return; |
1469 | 1470 |
1470 // Update state and notify view if the omnibox has focus and the caret | 1471 // Update state and notify view if the omnibox has focus and the caret |
1471 // visibility changed. | 1472 // visibility changed. |
1472 const bool was_caret_visible = is_caret_visible(); | 1473 const bool was_caret_visible = is_caret_visible(); |
1473 focus_state_ = state; | 1474 focus_state_ = state; |
1474 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1475 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1475 is_caret_visible() != was_caret_visible) | 1476 is_caret_visible() != was_caret_visible) |
1476 view_->ApplyCaretVisibility(); | 1477 view_->ApplyCaretVisibility(); |
1477 | 1478 |
1478 delegate_->OnFocusChanged(focus_state_, reason); | 1479 delegate_->OnFocusChanged(focus_state_, reason); |
1479 } | 1480 } |
OLD | NEW |