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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_web_ui.h" | 9 #include "chrome/browser/extensions/extension_web_ui.h" |
10 #include "chrome/browser/prefs/pref_registry_syncable.h" | 10 #include "chrome/browser/prefs/pref_registry_syncable.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 return instant_.CommitIfPossible(disposition == CURRENT_TAB ? | 176 return instant_.CommitIfPossible(disposition == CURRENT_TAB ? |
177 INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER); | 177 INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER); |
178 } | 178 } |
179 | 179 |
180 Profile* BrowserInstantController::profile() const { | 180 Profile* BrowserInstantController::profile() const { |
181 return browser_->profile(); | 181 return browser_->profile(); |
182 } | 182 } |
183 | 183 |
184 void BrowserInstantController::CommitInstant( | 184 void BrowserInstantController::CommitInstant( |
185 scoped_ptr<content::WebContents> preview, | 185 scoped_ptr<content::WebContents> overlay, |
186 bool in_new_tab) { | 186 bool in_new_tab) { |
187 if (profile()->GetExtensionService()->IsInstalledApp(preview->GetURL())) { | 187 if (profile()->GetExtensionService()->IsInstalledApp(overlay->GetURL())) { |
188 AppLauncherHandler::RecordAppLaunchType( | 188 AppLauncherHandler::RecordAppLaunchType( |
189 extension_misc::APP_LAUNCH_OMNIBOX_INSTANT); | 189 extension_misc::APP_LAUNCH_OMNIBOX_INSTANT); |
190 } | 190 } |
191 if (in_new_tab) { | 191 if (in_new_tab) { |
192 // TabStripModel takes ownership of |preview|. | 192 // TabStripModel takes ownership of |overlay|. |
193 browser_->tab_strip_model()->AddWebContents(preview.release(), -1, | 193 browser_->tab_strip_model()->AddWebContents(overlay.release(), -1, |
194 instant_.last_transition_type(), TabStripModel::ADD_ACTIVE); | 194 instant_.last_transition_type(), TabStripModel::ADD_ACTIVE); |
195 } else { | 195 } else { |
196 ReplaceWebContentsAt( | 196 ReplaceWebContentsAt( |
197 browser_->tab_strip_model()->active_index(), | 197 browser_->tab_strip_model()->active_index(), |
198 preview.Pass()); | 198 overlay.Pass()); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 void BrowserInstantController::ReplaceWebContentsAt( | 202 void BrowserInstantController::ReplaceWebContentsAt( |
203 int index, | 203 int index, |
204 scoped_ptr<content::WebContents> new_contents) { | 204 scoped_ptr<content::WebContents> new_contents) { |
205 DCHECK_NE(TabStripModel::kNoTab, index); | 205 DCHECK_NE(TabStripModel::kNoTab, index); |
206 scoped_ptr<content::WebContents> old_contents(browser_->tab_strip_model()-> | 206 scoped_ptr<content::WebContents> old_contents(browser_->tab_strip_model()-> |
207 ReplaceWebContentsAt(index, new_contents.release())); | 207 ReplaceWebContentsAt(index, new_contents.release())); |
208 instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents.Pass(), | 208 instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents.Pass(), |
209 index); | 209 index); |
210 } | 210 } |
211 | 211 |
212 void BrowserInstantController::SetInstantSuggestion( | 212 void BrowserInstantController::SetInstantSuggestion( |
213 const InstantSuggestion& suggestion) { | 213 const InstantSuggestion& suggestion) { |
214 browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); | 214 browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); |
215 } | 215 } |
216 | 216 |
217 void BrowserInstantController::CommitSuggestedText( | 217 void BrowserInstantController::CommitSuggestedText( |
218 bool skip_inline_autocomplete) { | 218 bool skip_inline_autocomplete) { |
219 browser_->window()->GetLocationBar()->GetLocationEntry()->model()-> | 219 browser_->window()->GetLocationBar()->GetLocationEntry()->model()-> |
220 CommitSuggestedText(skip_inline_autocomplete); | 220 CommitSuggestedText(skip_inline_autocomplete); |
221 } | 221 } |
222 | 222 |
223 gfx::Rect BrowserInstantController::GetInstantBounds() { | 223 gfx::Rect BrowserInstantController::GetInstantBounds() { |
224 return browser_->window()->GetInstantBounds(); | 224 return browser_->window()->GetInstantBounds(); |
225 } | 225 } |
226 | 226 |
227 void BrowserInstantController::InstantPreviewFocused() { | 227 void BrowserInstantController::InstantOverlayFocused() { |
228 // NOTE: This is only invoked on aura. | 228 // NOTE: This is only invoked on aura. |
229 browser_->window()->WebContentsFocused(instant_.GetPreviewContents()); | 229 browser_->window()->WebContentsFocused(instant_.GetOverlayContents()); |
230 } | 230 } |
231 | 231 |
232 void BrowserInstantController::FocusOmniboxInvisibly() { | 232 void BrowserInstantController::FocusOmniboxInvisibly() { |
233 OmniboxView* omnibox_view = browser_->window()->GetLocationBar()-> | 233 OmniboxView* omnibox_view = browser_->window()->GetLocationBar()-> |
234 GetLocationEntry(); | 234 GetLocationEntry(); |
235 omnibox_view->SetFocus(); | 235 omnibox_view->SetFocus(); |
236 omnibox_view->model()->SetCaretVisibility(false); | 236 omnibox_view->model()->SetCaretVisibility(false); |
237 } | 237 } |
238 | 238 |
239 content::WebContents* BrowserInstantController::GetActiveWebContents() const { | 239 content::WebContents* BrowserInstantController::GetActiveWebContents() const { |
(...skipping 27 matching lines...) Expand all Loading... |
267 transition, | 267 transition, |
268 false)); | 268 false)); |
269 } | 269 } |
270 | 270 |
271 void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) { | 271 void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) { |
272 instant_.SetOmniboxBounds(bounds); | 272 instant_.SetOmniboxBounds(bounds); |
273 } | 273 } |
274 | 274 |
275 void BrowserInstantController::ResetInstant() { | 275 void BrowserInstantController::ResetInstant() { |
276 bool instant_enabled = IsInstantEnabled(profile()); | 276 bool instant_enabled = IsInstantEnabled(profile()); |
277 bool use_local_preview_only = profile()->IsOffTheRecord() || | 277 bool use_local_overlay_only = profile()->IsOffTheRecord() || |
278 (!instant_enabled && | 278 (!instant_enabled && |
279 !profile()->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled)); | 279 !profile()->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled)); |
280 instant_.SetInstantEnabled(instant_enabled, use_local_preview_only); | 280 instant_.SetInstantEnabled(instant_enabled, use_local_overlay_only); |
281 } | 281 } |
282 | 282 |
283 //////////////////////////////////////////////////////////////////////////////// | 283 //////////////////////////////////////////////////////////////////////////////// |
284 // BrowserInstantController, search::SearchModelObserver implementation: | 284 // BrowserInstantController, search::SearchModelObserver implementation: |
285 | 285 |
286 void BrowserInstantController::ModeChanged(const search::Mode& old_mode, | 286 void BrowserInstantController::ModeChanged(const search::Mode& old_mode, |
287 const search::Mode& new_mode) { | 287 const search::Mode& new_mode) { |
288 // If mode is now |NTP|, send theme-related information to instant. | 288 // If mode is now |NTP|, send theme-related information to Instant. |
289 if (new_mode.is_ntp()) | 289 if (new_mode.is_ntp()) |
290 UpdateThemeInfo(false); | 290 UpdateThemeInfo(false); |
291 | 291 |
292 instant_.SearchModeChanged(old_mode, new_mode); | 292 instant_.SearchModeChanged(old_mode, new_mode); |
293 } | 293 } |
294 | 294 |
295 //////////////////////////////////////////////////////////////////////////////// | 295 //////////////////////////////////////////////////////////////////////////////// |
296 // BrowserInstantController, content::NotificationObserver implementation: | 296 // BrowserInstantController, content::NotificationObserver implementation: |
297 | 297 |
298 void BrowserInstantController::Observe( | 298 void BrowserInstantController::Observe( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 initialized_theme_info_ = true; | 380 initialized_theme_info_ = true; |
381 } | 381 } |
382 | 382 |
383 DCHECK(initialized_theme_info_); | 383 DCHECK(initialized_theme_info_); |
384 | 384 |
385 if (browser_->search_model()->mode().is_ntp()) | 385 if (browser_->search_model()->mode().is_ntp()) |
386 instant_.ThemeChanged(theme_info_); | 386 instant_.ThemeChanged(theme_info_); |
387 } | 387 } |
388 | 388 |
389 } // namespace chrome | 389 } // namespace chrome |
OLD | NEW |