diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-12 03:14:18 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-12 03:14:18 +0000 |
commit | 60b55e96140ff69d46342dfff48f573684e86d24 (patch) | |
tree | 59f6b5b17d6796222f25bc8327d27001bc79ba7d | |
parent | 135c4512cb092df13448c198e78627b15b410780 (diff) | |
download | chromium_src-60b55e96140ff69d46342dfff48f573684e86d24.zip chromium_src-60b55e96140ff69d46342dfff48f573684e86d24.tar.gz chromium_src-60b55e96140ff69d46342dfff48f573684e86d24.tar.bz2 |
When doing Paste-And-Go, OpenMatch() should use the pasted text as the input.
BUG=335380
TEST=In debug Chrome, on the NTP, have "false" in the clipboard and do Paste-And-Search.
R=mpearson@chromium.org
Review URL: https://codereview.chromium.org/158093002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250620 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 37 insertions, 26 deletions
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm index f883091..87ed959 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm @@ -498,5 +498,6 @@ void OmniboxPopupViewMac::OpenURLForRow(size_t row, size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0; row += start_match; DCHECK_LT(row, GetResult().size()); - omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), row); + omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), + base::string16(), row); } diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc index 1858f4d..00bdb40 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc @@ -492,7 +492,7 @@ void OmniboxPopupViewGtk::StackWindow() { void OmniboxPopupViewGtk::AcceptLine(size_t line, WindowOpenDisposition disposition) { omnibox_view_->OpenMatch(GetResult().match_at(line), disposition, GURL(), - line); + base::string16(), line); } gfx::Image OmniboxPopupViewGtk::IconForMatch( diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index ce59427..d5da5ae 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -396,7 +396,7 @@ void OmniboxEditModel::OnChanged() { break; // Ask for prerendering if the destination URL is different than the // current URL. - if (current_match.destination_url != PermanentURL()) + if (current_match.destination_url != delegate_->GetURL()) delegate_->DoPrerender(current_match); break; case AutocompleteActionPredictor::ACTION_PRECONNECT: @@ -413,8 +413,7 @@ void OmniboxEditModel::GetDataForURLExport(GURL* url, base::string16* title, gfx::Image* favicon) { *url = CurrentMatch(NULL).destination_url; - if (*url == URLFixerUpper::FixupURL(base::UTF16ToUTF8(permanent_text_), - std::string())) { + if (*url == delegate_->GetURL()) { content::WebContents* web_contents = controller_->GetWebContents(); *title = web_contents->GetTitle(); *favicon = FaviconTabHelper::FromWebContents(web_contents)->GetFavicon(); @@ -599,7 +598,7 @@ void OmniboxEditModel::PasteAndGo(const base::string16& text) { AutocompleteMatch match; GURL alternate_nav_url; ClassifyStringForPasteAndGo(text, &match, &alternate_nav_url); - view_->OpenMatch(match, CURRENT_TAB, alternate_nav_url, + view_->OpenMatch(match, CURRENT_TAB, alternate_nav_url, text, OmniboxPopupModel::kNoMatch); } @@ -652,9 +651,7 @@ void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, return; if ((match.transition == content::PAGE_TRANSITION_TYPED) && - (match.destination_url == - URLFixerUpper::FixupURL(base::UTF16ToUTF8(permanent_text_), - std::string()))) { + (match.destination_url == PermanentURL())) { // When the user hit enter on the existing permanent URL, treat it like a // reload for scoring purposes. We could detect this by just checking // user_input_in_progress_, but it seems better to treat "edits" that end @@ -677,13 +674,14 @@ void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition, if (template_url && template_url->url_ref().HasGoogleBaseURLs()) GoogleURLTracker::GoogleURLSearchCommitted(profile_); - view_->OpenMatch(match, disposition, alternate_nav_url, + view_->OpenMatch(match, disposition, alternate_nav_url, base::string16(), OmniboxPopupModel::kNoMatch); } void OmniboxEditModel::OpenMatch(AutocompleteMatch match, WindowOpenDisposition disposition, const GURL& alternate_nav_url, + const base::string16& pasted_text, size_t index) { const base::TimeTicks& now(base::TimeTicks::Now()); base::TimeDelta elapsed_time_since_user_first_modified_omnibox( @@ -691,14 +689,15 @@ void OmniboxEditModel::OpenMatch(AutocompleteMatch match, autocomplete_controller()->UpdateMatchDestinationURL( elapsed_time_since_user_first_modified_omnibox, &match); - const base::string16& user_text = - user_input_in_progress_ ? user_text_ : permanent_text_; + base::string16 input_text(pasted_text); + if (input_text.empty()) + input_text = user_input_in_progress_ ? user_text_ : permanent_text_; scoped_ptr<OmniboxNavigationObserver> observer( new OmniboxNavigationObserver( - profile_, user_text, match, + profile_, input_text, match, autocomplete_controller()->history_url_provider()->SuggestExactInput( - user_text, alternate_nav_url, - AutocompleteInput::HasHTTPScheme(user_text)))); + input_text, alternate_nav_url, + AutocompleteInput::HasHTTPScheme(input_text)))); // We only care about cases where there is a selection (i.e. the popup is // open). @@ -717,7 +716,7 @@ void OmniboxEditModel::OpenMatch(AutocompleteMatch match, base::TimeDelta::FromMilliseconds(-1); } OmniboxLog log( - user_text, + input_text, just_deleted_text_, autocomplete_controller()->input().type(), popup_model()->selected_line(), @@ -1086,8 +1085,8 @@ void OmniboxEditModel::OnPopupDataChanged( if (inline_autocomplete_text_.empty()) view_->OnInlineAutocompleteTextCleared(); - base::string16 user_text = user_input_in_progress_ ? user_text_ - : permanent_text_; + const base::string16& user_text = + user_input_in_progress_ ? user_text_ : permanent_text_; if (keyword_state_changed && KeywordIsSelected()) { // If we reach here, the user most likely entered keyword mode by inserting // a space between a keyword name and a search string (as pressing space or diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.h b/chrome/browser/ui/omnibox/omnibox_edit_model.h index dd5f04c..e1fa60e 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.h +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.h @@ -194,6 +194,11 @@ class OmniboxEditModel { bool for_drop); // Asks the browser to load the item at |index|, with the given properties. + // OpenMatch() needs to know the original text that drove this action. If + // |pasted_text| is non-empty, this is a Paste-And-Go/Search action, and + // that's the relevant input text. Otherwise, the relevant input text is + // either the user text or the permanent text, depending on if user input is + // in progress. // // |match| is passed by value for two reasons: // (1) This function needs to modify |match|, so a const ref isn't @@ -207,6 +212,7 @@ class OmniboxEditModel { void OpenMatch(AutocompleteMatch match, WindowOpenDisposition disposition, const GURL& alternate_nav_url, + const base::string16& pasted_text, size_t index); OmniboxFocusState focus_state() const { return focus_state_; } diff --git a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc index bc0210e..6115ad7 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc @@ -30,6 +30,7 @@ class TestingOmniboxView : public OmniboxView { virtual void OpenMatch(const AutocompleteMatch& match, WindowOpenDisposition disposition, const GURL& alternate_nav_url, + const base::string16& pasted_text, size_t selected_line) OVERRIDE {} virtual base::string16 GetText() const OVERRIDE { return text_; } virtual void SetUserText(const base::string16& text, diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc index a86c6d9..9395546 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.cc +++ b/chrome/browser/ui/omnibox/omnibox_view.cc @@ -87,12 +87,13 @@ OmniboxView::~OmniboxView() { void OmniboxView::OpenMatch(const AutocompleteMatch& match, WindowOpenDisposition disposition, const GURL& alternate_nav_url, + const base::string16& pasted_text, size_t selected_line) { // Invalid URLs such as chrome://history can end up here. - if (!match.destination_url.is_valid()) - return; - if (model_.get()) - model_->OpenMatch(match, disposition, alternate_nav_url, selected_line); + if (match.destination_url.is_valid() && model_) { + model_->OpenMatch(match, disposition, alternate_nav_url, pasted_text, + selected_line); + } } bool OmniboxView::IsEditingOrEmpty() const { diff --git a/chrome/browser/ui/omnibox/omnibox_view.h b/chrome/browser/ui/omnibox/omnibox_view.h index 8ff3b2f..b838682 100644 --- a/chrome/browser/ui/omnibox/omnibox_view.h +++ b/chrome/browser/ui/omnibox/omnibox_view.h @@ -54,18 +54,21 @@ class OmniboxView { // Called when any relevant state changes other than changing tabs. virtual void Update() = 0; - // Asks the browser to load the specified match's |destination_url|, which - // is assumed to be one of the popup entries, using the supplied disposition - // and transition type. |alternate_nav_url|, if non-empty, contains the + // Asks the browser to load the specified match, using the supplied + // disposition. |alternate_nav_url|, if non-empty, contains the // alternate navigation URL for for this match. See comments on // AutocompleteResult::GetAlternateNavURL(). // + // |pasted_text| should only be set if this call is due to a + // Paste-And-Go/Search action. + // // |selected_line| is passed to SendOpenNotification(); see comments there. // // This may close the popup. virtual void OpenMatch(const AutocompleteMatch& match, WindowOpenDisposition disposition, const GURL& alternate_nav_url, + const base::string16& pasted_text, size_t selected_line); // Returns the current text of the edit control, which could be the diff --git a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc index 3a4b819..a6f839b 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc @@ -497,7 +497,7 @@ void OmniboxPopupContentsView::OpenSelectedLine( if (!HasMatchAt(index)) return; omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, - GURL(), index); + GURL(), base::string16(), index); } OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |