OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 349 |
350 if (view_gaining_focus_ancestor) { | 350 if (view_gaining_focus_ancestor) { |
351 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); | 351 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); |
352 return; | 352 return; |
353 } | 353 } |
354 | 354 |
355 DestroyPreviewContents(); | 355 DestroyPreviewContents(); |
356 } | 356 } |
357 #endif | 357 #endif |
358 | 358 |
| 359 void InstantController::OnAutocompleteGotFocus( |
| 360 TabContentsWrapper* tab_contents) { |
| 361 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 362 if (!cl->HasSwitch(switches::kPreloadInstantSearch)) |
| 363 return; |
| 364 |
| 365 if (is_active_) |
| 366 return; |
| 367 |
| 368 TemplateURLModel* model = tab_contents->profile()->GetTemplateURLModel(); |
| 369 if (!model) |
| 370 return; |
| 371 |
| 372 const TemplateURL* template_url = model->GetDefaultSearchProvider(); |
| 373 if (!template_url) |
| 374 return; |
| 375 |
| 376 if (tab_contents != tab_contents_) |
| 377 DestroyPreviewContents(); |
| 378 tab_contents_ = tab_contents; |
| 379 |
| 380 if (!loader_manager_.get()) |
| 381 loader_manager_.reset(new InstantLoaderManager(this)); |
| 382 loader_manager_->GetInstantLoader(template_url->id()) |
| 383 ->MaybeLoadInstantURL(tab_contents, template_url); |
| 384 } |
| 385 |
359 TabContentsWrapper* InstantController::ReleasePreviewContents( | 386 TabContentsWrapper* InstantController::ReleasePreviewContents( |
360 InstantCommitType type) { | 387 InstantCommitType type) { |
361 if (!loader_manager_.get()) | 388 if (!loader_manager_.get()) |
362 return NULL; | 389 return NULL; |
363 | 390 |
364 // Make sure the pending loader is active. Ideally we would call | 391 // Make sure the pending loader is active. Ideally we would call |
365 // ShowTimerFired, but if Release is invoked from the browser we don't want to | 392 // ShowTimerFired, but if Release is invoked from the browser we don't want to |
366 // attempt to show the tab contents (since its being added to a new tab). | 393 // attempt to show the tab contents (since its being added to a new tab). |
367 if (type == INSTANT_COMMIT_PRESSED_ENTER && show_timer_.IsRunning()) { | 394 if (type == INSTANT_COMMIT_PRESSED_ENTER && show_timer_.IsRunning()) { |
368 InstantLoader* loader = loader_manager_->active_loader(); | 395 InstantLoader* loader = loader_manager_->active_loader(); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 const AutocompleteMatch& match) { | 726 const AutocompleteMatch& match) { |
700 const TemplateURL* template_url = match.template_url; | 727 const TemplateURL* template_url = match.template_url; |
701 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || | 728 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || |
702 match.type == AutocompleteMatch::SEARCH_HISTORY || | 729 match.type == AutocompleteMatch::SEARCH_HISTORY || |
703 match.type == AutocompleteMatch::SEARCH_SUGGEST) { | 730 match.type == AutocompleteMatch::SEARCH_SUGGEST) { |
704 TemplateURLModel* model = tab_contents_->profile()->GetTemplateURLModel(); | 731 TemplateURLModel* model = tab_contents_->profile()->GetTemplateURLModel(); |
705 template_url = model ? model->GetDefaultSearchProvider() : NULL; | 732 template_url = model ? model->GetDefaultSearchProvider() : NULL; |
706 } | 733 } |
707 return template_url; | 734 return template_url; |
708 } | 735 } |
OLD | NEW |