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

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.cc

Issue 11415292: [Search] No longer reverting omnibox text on instant search (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix tests Created 8 years 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
OLDNEW
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/search/search_tab_helper.h" 5 #include "chrome/browser/ui/search/search_tab_helper.h"
6 6
7 #include "chrome/browser/google/google_util.h" 7 #include "chrome/browser/google/google_util.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search_engines/template_url_service.h"
10 #include "chrome/browser/search_engines/template_url_service_factory.h"
9 #include "chrome/browser/ui/search/search.h" 11 #include "chrome/browser/ui/search/search.h"
10 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
11 #include "content/public/browser/navigation_controller.h" 13 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/navigation_details.h" 14 #include "content/public/browser/navigation_details.h"
13 #include "content/public/browser/navigation_entry.h" 15 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
16 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
17 19
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper) 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const content::NotificationDetails& details) { 94 const content::NotificationDetails& details) {
93 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); 95 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
94 content::LoadCommittedDetails* committed_details = 96 content::LoadCommittedDetails* committed_details =
95 content::Details<content::LoadCommittedDetails>(details).ptr(); 97 content::Details<content::LoadCommittedDetails>(details).ptr();
96 // See comment in |NavigateToPendingEntry()| about why |!IsNTP()| is used. 98 // See comment in |NavigateToPendingEntry()| about why |!IsNTP()| is used.
97 if (!IsNTP(committed_details->entry->GetURL())) { 99 if (!IsNTP(committed_details->entry->GetURL())) {
98 UpdateModelBasedOnURL(committed_details->entry->GetURL(), 100 UpdateModelBasedOnURL(committed_details->entry->GetURL(),
99 !is_initial_navigation_commit_); 101 !is_initial_navigation_commit_);
100 } 102 }
101 is_initial_navigation_commit_ = false; 103 is_initial_navigation_commit_ = false;
104
105 // Update the extracted search terms (if any) in the model.
106 Profile* profile =
107 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
108 TemplateURLService* template_url_service =
109 TemplateURLServiceFactory::GetForProfile(profile);
110 string16 search_terms =
111 template_url_service->TryToExtractSearchTermsFromURL(
112 committed_details->entry->GetURL());
113 if (!search_terms.empty())
114 committed_details->entry->SetSearchTerms(search_terms);
102 } 115 }
103 116
104 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, bool animate) { 117 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, bool animate) {
105 Mode::Type type = Mode::MODE_DEFAULT; 118 Mode::Type type = Mode::MODE_DEFAULT;
106 Mode::Origin origin = Mode::ORIGIN_DEFAULT; 119 Mode::Origin origin = Mode::ORIGIN_DEFAULT;
107 if (IsNTP(url)) { 120 if (IsNTP(url)) {
108 type = Mode::MODE_NTP; 121 type = Mode::MODE_NTP;
109 origin = Mode::ORIGIN_NTP; 122 origin = Mode::ORIGIN_NTP;
110 } else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) { 123 } else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) {
111 type = Mode::MODE_SEARCH_RESULTS; 124 type = Mode::MODE_SEARCH_RESULTS;
112 origin = Mode::ORIGIN_SEARCH; 125 origin = Mode::ORIGIN_SEARCH;
113 } 126 }
114 if (user_input_in_progress_) 127 if (user_input_in_progress_)
115 type = Mode::MODE_SEARCH_SUGGESTIONS; 128 type = Mode::MODE_SEARCH_SUGGESTIONS;
116 model_.SetMode(Mode(type, origin, animate)); 129 model_.SetMode(Mode(type, origin, animate));
117 } 130 }
118 131
119 const content::WebContents* SearchTabHelper::web_contents() const { 132 const content::WebContents* SearchTabHelper::web_contents() const {
120 return model_.web_contents(); 133 return model_.web_contents();
121 } 134 }
122 135
123 } // namespace search 136 } // namespace search
124 } // namespace chrome 137 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698