Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 11418043: Remove TabContents from OmniboxEditController and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cros Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // We only care about cases where there is a selection (i.e. the popup is 541 // We only care about cases where there is a selection (i.e. the popup is
542 // open). 542 // open).
543 if (popup_->IsOpen()) { 543 if (popup_->IsOpen()) {
544 // TODO(sreeram): Handle is_temporary_text_set_by_instant_ correctly. 544 // TODO(sreeram): Handle is_temporary_text_set_by_instant_ correctly.
545 AutocompleteLog log( 545 AutocompleteLog log(
546 autocomplete_controller_->input().text(), 546 autocomplete_controller_->input().text(),
547 just_deleted_text_, 547 just_deleted_text_,
548 autocomplete_controller_->input().type(), 548 autocomplete_controller_->input().type(),
549 popup_->selected_line(), 549 popup_->selected_line(),
550 -1, // don't yet know tab ID; set later if appropriate 550 -1, // don't yet know tab ID; set later if appropriate
551 ClassifyPage(controller_->GetTabContents()-> 551 ClassifyPage(controller_->GetWebContents()->GetURL()),
552 web_contents()->GetURL()),
553 base::TimeTicks::Now() - time_user_first_modified_omnibox_, 552 base::TimeTicks::Now() - time_user_first_modified_omnibox_,
554 string16::npos, // inline autocomplete length; possibly set later 553 string16::npos, // inline autocomplete length; possibly set later
555 result()); 554 result());
556 DCHECK(user_input_in_progress_ || 555 DCHECK(user_input_in_progress_ ||
557 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST) 556 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST)
558 << "We didn't get here through the expected series of calls. " 557 << "We didn't get here through the expected series of calls. "
559 << "time_user_first_modified_omnibox_ is not set correctly and other " 558 << "time_user_first_modified_omnibox_ is not set correctly and other "
560 << "things may be wrong. Match provider: " << match.provider->GetName(); 559 << "things may be wrong. Match provider: " << match.provider->GetName();
561 if (index != OmniboxPopupModel::kNoMatch) 560 if (index != OmniboxPopupModel::kNoMatch)
562 log.selected_index = index; 561 log.selected_index = index;
563 else if (!has_temporary_text_) 562 else if (!has_temporary_text_)
564 log.inline_autocompleted_length = inline_autocomplete_text_.length(); 563 log.inline_autocompleted_length = inline_autocomplete_text_.length();
565 if (disposition == CURRENT_TAB) { 564 if (disposition == CURRENT_TAB) {
566 // If we know the destination is being opened in the current tab, 565 // If we know the destination is being opened in the current tab,
567 // we can easily get the tab ID. (If it's being opened in a new 566 // we can easily get the tab ID. (If it's being opened in a new
568 // tab, we don't know the tab ID yet.) 567 // tab, we don't know the tab ID yet.)
569 log.tab_id = SessionTabHelper::FromWebContents( 568 log.tab_id = SessionTabHelper::FromWebContents(
570 controller_->GetTabContents()->web_contents())->session_id().id(); 569 controller_->GetWebContents())->session_id().id();
571 } 570 }
572 autocomplete_controller_->AddProvidersInfo(&log.providers_info); 571 autocomplete_controller_->AddProvidersInfo(&log.providers_info);
573 content::NotificationService::current()->Notify( 572 content::NotificationService::current()->Notify(
574 chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 573 chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
575 content::Source<Profile>(profile_), 574 content::Source<Profile>(profile_),
576 content::Details<AutocompleteLog>(&log)); 575 content::Details<AutocompleteLog>(&log));
577 HISTOGRAM_ENUMERATION("Omnibox.EventCount", 1, 2); 576 HISTOGRAM_ENUMERATION("Omnibox.EventCount", 1, 2);
578 } 577 }
579 578
580 TemplateURL* template_url = match.GetTemplateURL(profile_, false); 579 TemplateURL* template_url = match.GetTemplateURL(profile_, false);
581 if (template_url) { 580 if (template_url) {
582 if (match.transition == content::PAGE_TRANSITION_KEYWORD) { 581 if (match.transition == content::PAGE_TRANSITION_KEYWORD) {
583 // The user is using a non-substituting keyword or is explicitly in 582 // The user is using a non-substituting keyword or is explicitly in
584 // keyword mode. 583 // keyword mode.
585 584
586 // Special case for extension keywords. Don't increment usage count for 585 // Special case for extension keywords. Don't increment usage count for
587 // these. 586 // these.
588 if (template_url->IsExtensionKeyword()) { 587 if (template_url->IsExtensionKeyword()) {
589 AutocompleteMatch current_match; 588 AutocompleteMatch current_match;
590 GetInfoForCurrentText(&current_match, NULL); 589 GetInfoForCurrentText(&current_match, NULL);
591 590
592 const AutocompleteMatch& match = 591 const AutocompleteMatch& match =
593 (index == OmniboxPopupModel::kNoMatch) ? 592 (index == OmniboxPopupModel::kNoMatch) ?
594 current_match : result().match_at(index); 593 current_match : result().match_at(index);
595 594
596 // Strip the keyword + leading space off the input. 595 // Strip the keyword + leading space off the input.
597 size_t prefix_length = match.keyword.length() + 1; 596 size_t prefix_length = match.keyword.length() + 1;
598 extensions::ExtensionOmniboxEventRouter::OnInputEntered( 597 extensions::ExtensionOmniboxEventRouter::OnInputEntered(
599 controller_->GetTabContents(), 598 controller_->GetWebContents(),
600 template_url->GetExtensionId(), 599 template_url->GetExtensionId(),
601 UTF16ToUTF8(match.fill_into_edit.substr(prefix_length))); 600 UTF16ToUTF8(match.fill_into_edit.substr(prefix_length)));
602 view_->RevertAll(); 601 view_->RevertAll();
603 return; 602 return;
604 } 603 }
605 604
606 content::RecordAction(UserMetricsAction("AcceptedKeyword")); 605 content::RecordAction(UserMetricsAction("AcceptedKeyword"));
607 TemplateURLServiceFactory::GetForProfile(profile_)->IncrementUsageCount( 606 TemplateURLServiceFactory::GetForProfile(profile_)->IncrementUsageCount(
608 template_url); 607 template_url);
609 } else { 608 } else {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 } 713 }
715 714
716 void OmniboxEditModel::OnSetFocus(bool control_down) { 715 void OmniboxEditModel::OnSetFocus(bool control_down) {
717 has_focus_ = true; 716 has_focus_ = true;
718 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; 717 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP;
719 718
720 InstantController* instant = controller_->GetInstant(); 719 InstantController* instant = controller_->GetInstant();
721 if (instant) 720 if (instant)
722 instant->OnAutocompleteGotFocus(); 721 instant->OnAutocompleteGotFocus();
723 722
724 TabContents* tab_contents = controller_->GetTabContents(); 723 content::WebContents* web_contents = controller_->GetWebContents();
725 if (tab_contents) { 724 if (web_contents) {
726 // TODO(jered): We may want to merge this into Start() and just call that 725 // TODO(jered): We may want to merge this into Start() and just call that
727 // here rather than having a special entry point for zero-suggest. Note 726 // here rather than having a special entry point for zero-suggest. Note
728 // that we avoid PermanentURL() here because it's not guaranteed to give us 727 // that we avoid PermanentURL() here because it's not guaranteed to give us
729 // the actual underlying current URL, e.g. if we're on the NTP and the 728 // the actual underlying current URL, e.g. if we're on the NTP and the
730 // |permanent_text_| is empty. 729 // |permanent_text_| is empty.
731 autocomplete_controller_->StartZeroSuggest( 730 autocomplete_controller_->StartZeroSuggest(web_contents->GetURL(),
732 tab_contents->web_contents()->GetURL(), user_text_); 731 user_text_);
733 } 732 }
734 733
735 NotifySearchTabHelper(); 734 NotifySearchTabHelper();
736 } 735 }
737 736
738 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { 737 void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) {
739 SetInstantSuggestion(InstantSuggestion()); 738 SetInstantSuggestion(InstantSuggestion());
740 739
741 if (InstantController* instant = controller_->GetInstant()) 740 if (InstantController* instant = controller_->GetInstant())
742 instant->OnAutocompleteLostFocus(view_gaining_focus); 741 instant->OnAutocompleteLostFocus(view_gaining_focus);
(...skipping 14 matching lines...) Expand all
757 AutocompleteMatch match; 756 AutocompleteMatch match;
758 InfoForCurrentSelection(&match, NULL); 757 InfoForCurrentSelection(&match, NULL);
759 if (match.destination_url != original_url_) { 758 if (match.destination_url != original_url_) {
760 RevertTemporaryText(true); 759 RevertTemporaryText(true);
761 return true; 760 return true;
762 } 761 }
763 } 762 }
764 763
765 // We do not clear the pending entry from the omnibox when a load is first 764 // We do not clear the pending entry from the omnibox when a load is first
766 // stopped. If the user presses Escape while stopped, we clear it. 765 // stopped. If the user presses Escape while stopped, we clear it.
767 content::WebContents* contents = 766 content::WebContents* contents = controller_->GetWebContents();
768 controller_->GetTabContents()->web_contents();
769 if (!contents->IsLoading()) { 767 if (!contents->IsLoading()) {
770 contents->GetController().DiscardNonCommittedEntries(); 768 contents->GetController().DiscardNonCommittedEntries();
771 view_->Update(NULL); 769 view_->Update(NULL);
772 } 770 }
773 771
774 // Let Instant decide whether to hide itself. 772 // Let Instant decide whether to hide itself.
775 if (InstantController* instant = controller_->GetInstant()) 773 if (InstantController* instant = controller_->GetInstant())
776 instant->OnEscapeKeyPressed(); 774 instant->OnEscapeKeyPressed();
777 775
778 // If the user wasn't editing, but merely had focus in the edit, allow <esc> 776 // If the user wasn't editing, but merely had focus in the edit, allow <esc>
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 string16 keyword; 1175 string16 keyword;
1178 TrimWhitespace(new_text.substr(0, space_position), TRIM_LEADING, &keyword); 1176 TrimWhitespace(new_text.substr(0, space_position), TRIM_LEADING, &keyword);
1179 // TODO(sreeram): Once the Instant extended API supports keywords properly, 1177 // TODO(sreeram): Once the Instant extended API supports keywords properly,
1180 // keyword_provider() should never be NULL. Remove that clause. 1178 // keyword_provider() should never be NULL. Remove that clause.
1181 return !keyword.empty() && autocomplete_controller_->keyword_provider() && 1179 return !keyword.empty() && autocomplete_controller_->keyword_provider() &&
1182 !autocomplete_controller_->keyword_provider()-> 1180 !autocomplete_controller_->keyword_provider()->
1183 GetKeywordForText(keyword).empty(); 1181 GetKeywordForText(keyword).empty();
1184 } 1182 }
1185 1183
1186 void OmniboxEditModel::NotifySearchTabHelper() { 1184 void OmniboxEditModel::NotifySearchTabHelper() {
1187 if (controller_->GetTabContents()) { 1185 if (controller_->GetWebContents()) {
1188 chrome::search::SearchTabHelper::FromWebContents( 1186 chrome::search::SearchTabHelper::FromWebContents(
1189 controller_->GetTabContents()->web_contents())-> 1187 controller_->GetWebContents())->
1190 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_); 1188 OmniboxEditModelChanged(user_input_in_progress_, !in_revert_);
1191 } 1189 }
1192 } 1190 }
1193 1191
1194 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) { 1192 bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) {
1195 if (in_revert_) 1193 if (in_revert_)
1196 return false; 1194 return false;
1197 1195
1198 InstantController* instant = controller_->GetInstant(); 1196 InstantController* instant = controller_->GetInstant();
1199 1197
(...skipping 27 matching lines...) Expand all
1227 return false; 1225 return false;
1228 } 1226 }
1229 1227
1230 void OmniboxEditModel::DoPrerender(const AutocompleteMatch& match) { 1228 void OmniboxEditModel::DoPrerender(const AutocompleteMatch& match) {
1231 // Do not prerender if the destination URL is the same as the current URL. 1229 // Do not prerender if the destination URL is the same as the current URL.
1232 if (match.destination_url == PermanentURL()) 1230 if (match.destination_url == PermanentURL())
1233 return; 1231 return;
1234 // It's possible the tab strip does not have an active tab contents, for 1232 // It's possible the tab strip does not have an active tab contents, for
1235 // instance if the tab has been closed or on return from a sleep state 1233 // instance if the tab has been closed or on return from a sleep state
1236 // (http://crbug.com/105689) 1234 // (http://crbug.com/105689)
1237 TabContents* tab = controller_->GetTabContents(); 1235 content::WebContents* tab = controller_->GetWebContents();
1238 if (!tab) 1236 if (!tab)
1239 return; 1237 return;
1240 gfx::Rect container_bounds; 1238 gfx::Rect container_bounds;
1241 tab->web_contents()->GetView()->GetContainerBounds(&container_bounds); 1239 tab->GetView()->GetContainerBounds(&container_bounds);
1242 AutocompleteActionPredictorFactory::GetForProfile(profile_)-> 1240 AutocompleteActionPredictorFactory::GetForProfile(profile_)->
1243 StartPrerendering(match.destination_url, 1241 StartPrerendering(match.destination_url,
1244 tab->web_contents()->GetController() 1242 tab->GetController().GetSessionStorageNamespaceMap(),
1245 .GetSessionStorageNamespaceMap(),
1246 container_bounds.size()); 1243 container_bounds.size());
1247 } 1244 }
1248 1245
1249 void OmniboxEditModel::DoPreconnect(const AutocompleteMatch& match) { 1246 void OmniboxEditModel::DoPreconnect(const AutocompleteMatch& match) {
1250 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) { 1247 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) {
1251 // Warm up DNS Prefetch cache, or preconnect to a search service. 1248 // Warm up DNS Prefetch cache, or preconnect to a search service.
1252 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, 1249 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type,
1253 AutocompleteMatch::NUM_TYPES); 1250 AutocompleteMatch::NUM_TYPES);
1254 if (profile_->GetNetworkPredictor()) { 1251 if (profile_->GetNetworkPredictor()) {
1255 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( 1252 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 } 1285 }
1289 1286
1290 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1287 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1291 const string16& text, 1288 const string16& text,
1292 AutocompleteMatch* match, 1289 AutocompleteMatch* match,
1293 GURL* alternate_nav_url) const { 1290 GURL* alternate_nav_url) const {
1294 DCHECK(match); 1291 DCHECK(match);
1295 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1292 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1296 string16(), false, false, match, alternate_nav_url); 1293 string16(), false, false, match, alternate_nav_url);
1297 } 1294 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_edit_controller.h ('k') | chrome/browser/ui/omnibox/omnibox_edit_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698