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/browser_instant_controller.h" | 5 #include "chrome/browser/ui/browser_instant_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search/instant_service.h" | 10 #include "chrome/browser/search/instant_service.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 BrowserInstantController::~BrowserInstantController() { | 98 BrowserInstantController::~BrowserInstantController() { |
99 browser_->search_model()->RemoveObserver(this); | 99 browser_->search_model()->RemoveObserver(this); |
100 | 100 |
101 InstantService* instant_service = | 101 InstantService* instant_service = |
102 InstantServiceFactory::GetForProfile(profile()); | 102 InstantServiceFactory::GetForProfile(profile()); |
103 instant_service->RemoveObserver(this); | 103 instant_service->RemoveObserver(this); |
104 } | 104 } |
105 | 105 |
106 bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition, | 106 void BrowserInstantController::OpenInstant(WindowOpenDisposition disposition, |
107 const GURL& url) { | 107 const GURL& url) { |
108 // Unsupported dispositions. | 108 // Unsupported dispositions. |
109 if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB || | 109 if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB || |
110 disposition == WindowOpenDisposition::NEW_WINDOW || | 110 disposition == WindowOpenDisposition::NEW_WINDOW || |
111 disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) | 111 disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) { |
112 return false; | 112 return; |
| 113 } |
113 | 114 |
114 // The omnibox currently doesn't use other dispositions, so we don't attempt | 115 // The omnibox currently doesn't use other dispositions, so we don't attempt |
115 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add | 116 // to handle them. If you hit this DCHECK file a bug and I'll (sky) add |
116 // support for the new disposition. | 117 // support for the new disposition. |
117 DCHECK(disposition == WindowOpenDisposition::CURRENT_TAB) | 118 DCHECK(disposition == WindowOpenDisposition::CURRENT_TAB) |
118 << static_cast<int>(disposition); | 119 << static_cast<int>(disposition); |
119 | 120 |
120 const base::string16& search_terms = | 121 const base::string16& search_terms = |
121 search::ExtractSearchTermsFromURL(profile(), url); | 122 search::ExtractSearchTermsFromURL(profile(), url); |
122 EmbeddedSearchRequestParams request_params(url); | |
123 if (search_terms.empty()) | 123 if (search_terms.empty()) |
124 return false; | 124 return; |
125 | 125 |
126 InstantSearchPrerenderer* prerenderer = | 126 InstantSearchPrerenderer* prerenderer = |
127 GetInstantSearchPrerenderer(profile()); | 127 GetInstantSearchPrerenderer(profile()); |
128 if (prerenderer) { | 128 if (!prerenderer) |
129 if (prerenderer->CanCommitQuery(GetActiveWebContents(), search_terms)) { | 129 return; |
130 // Submit query to render the prefetched results. Browser will swap the | 130 |
131 // prerendered contents with the active tab contents. | 131 if (prerenderer->CanCommitQuery(GetActiveWebContents(), search_terms)) { |
132 prerenderer->Commit(search_terms, request_params); | 132 // Submit query to render the prefetched results. Browser will swap the |
133 return false; | 133 // prerendered contents with the active tab contents. |
134 } else { | 134 prerenderer->Commit(search_terms, EmbeddedSearchRequestParams(url)); |
135 prerenderer->Cancel(); | 135 } else { |
136 } | 136 prerenderer->Cancel(); |
137 } | 137 } |
138 | |
139 // If we will not be replacing search terms from this URL, don't send to | |
140 // InstantController. | |
141 if (!search::IsQueryExtractionAllowedForURL(profile(), url)) | |
142 return false; | |
143 return instant_.SubmitQuery(search_terms, request_params); | |
144 } | 138 } |
145 | 139 |
146 Profile* BrowserInstantController::profile() const { | 140 Profile* BrowserInstantController::profile() const { |
147 return browser_->profile(); | 141 return browser_->profile(); |
148 } | 142 } |
149 | 143 |
150 content::WebContents* BrowserInstantController::GetActiveWebContents() const { | 144 content::WebContents* BrowserInstantController::GetActiveWebContents() const { |
151 return browser_->tab_strip_model()->GetActiveWebContents(); | 145 return browser_->tab_strip_model()->GetActiveWebContents(); |
152 } | 146 } |
153 | 147 |
(...skipping 10 matching lines...) Expand all Loading... |
164 | 158 |
165 void BrowserInstantController::ModelChanged( | 159 void BrowserInstantController::ModelChanged( |
166 const SearchModel::State& old_state, | 160 const SearchModel::State& old_state, |
167 const SearchModel::State& new_state) { | 161 const SearchModel::State& new_state) { |
168 if (old_state.mode != new_state.mode) { | 162 if (old_state.mode != new_state.mode) { |
169 const SearchMode& new_mode = new_state.mode; | 163 const SearchMode& new_mode = new_state.mode; |
170 | 164 |
171 // Record some actions corresponding to the mode change. Note that to get | 165 // Record some actions corresponding to the mode change. Note that to get |
172 // the full story, it's necessary to look at other UMA actions as well, | 166 // the full story, it's necessary to look at other UMA actions as well, |
173 // such as tab switches. | 167 // such as tab switches. |
174 if (new_mode.is_search_results()) | 168 if (new_mode.is_ntp()) |
175 content::RecordAction(base::UserMetricsAction("InstantExtended.ShowSRP")); | |
176 else if (new_mode.is_ntp()) | |
177 content::RecordAction(base::UserMetricsAction("InstantExtended.ShowNTP")); | 169 content::RecordAction(base::UserMetricsAction("InstantExtended.ShowNTP")); |
178 | 170 |
179 instant_.SearchModeChanged(old_state.mode, new_mode); | 171 instant_.SearchModeChanged(old_state.mode, new_mode); |
180 } | 172 } |
181 | 173 |
182 if (old_state.instant_support != new_state.instant_support) | 174 if (old_state.instant_support != new_state.instant_support) |
183 instant_.InstantSupportChanged(new_state.instant_support); | 175 instant_.InstantSupportChanged(new_state.instant_support); |
184 } | 176 } |
185 | 177 |
186 void BrowserInstantController::DefaultSearchProviderChanged( | 178 void BrowserInstantController::DefaultSearchProviderChanged( |
(...skipping 26 matching lines...) Expand all Loading... |
213 params.referrer = content::Referrer(); | 205 params.referrer = content::Referrer(); |
214 params.transition_type = ui::PAGE_TRANSITION_RELOAD; | 206 params.transition_type = ui::PAGE_TRANSITION_RELOAD; |
215 contents->GetController().LoadURLWithParams(params); | 207 contents->GetController().LoadURLWithParams(params); |
216 } else { | 208 } else { |
217 // Reload the contents to ensure that it gets assigned to a | 209 // Reload the contents to ensure that it gets assigned to a |
218 // non-privileged renderer. | 210 // non-privileged renderer. |
219 TabReloader::Reload(contents); | 211 TabReloader::Reload(contents); |
220 } | 212 } |
221 } | 213 } |
222 } | 214 } |
OLD | NEW |