| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/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/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 last_suggestion_.behavior); | 215 last_suggestion_.behavior); |
| 216 | 216 |
| 217 // We need to call Show() here because of this: | 217 // We need to call Show() here because of this: |
| 218 // 1. User has typed a query (say Q). Instant overlay is showing results. | 218 // 1. User has typed a query (say Q). Instant overlay is showing results. |
| 219 // 2. User arrows-down to a URL entry or erases all omnibox text. Both of | 219 // 2. User arrows-down to a URL entry or erases all omnibox text. Both of |
| 220 // these cause the overlay to Hide(). | 220 // these cause the overlay to Hide(). |
| 221 // 3. User arrows-up to Q or types Q again. The last text we processed is | 221 // 3. User arrows-up to Q or types Q again. The last text we processed is |
| 222 // still Q, so we don't Update() the loader, but we do need to Show(). | 222 // still Q, so we don't Update() the loader, but we do need to Show(). |
| 223 if (loader_processed_last_update_ && | 223 if (loader_processed_last_update_ && |
| 224 (mode_ == INSTANT || mode_ == EXTENDED)) | 224 (mode_ == INSTANT || mode_ == EXTENDED)) |
| 225 Show(); | 225 Show(100, INSTANT_SIZE_PERCENT); |
| 226 return true; | 226 return true; |
| 227 } | 227 } |
| 228 | 228 |
| 229 last_verbatim_ = verbatim; | 229 last_verbatim_ = verbatim; |
| 230 loader_processed_last_update_ = false; | 230 loader_processed_last_update_ = false; |
| 231 last_suggestion_ = InstantSuggestion(); | 231 last_suggestion_ = InstantSuggestion(); |
| 232 | 232 |
| 233 if (mode_ != SILENT) { | 233 if (mode_ != SILENT) { |
| 234 loader_->Update(query_text, verbatim); | 234 loader_->Update(query_text, verbatim); |
| 235 | 235 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 290 |
| 291 TabContents* InstantController::GetPreviewContents() const { | 291 TabContents* InstantController::GetPreviewContents() const { |
| 292 return loader_.get() ? loader_->preview_contents() : NULL; | 292 return loader_.get() ? loader_->preview_contents() : NULL; |
| 293 } | 293 } |
| 294 | 294 |
| 295 void InstantController::Hide() { | 295 void InstantController::Hide() { |
| 296 last_active_tab_ = NULL; | 296 last_active_tab_ = NULL; |
| 297 if (is_showing_) { | 297 if (is_showing_) { |
| 298 is_showing_ = false; | 298 is_showing_ = false; |
| 299 delegate_->HideInstant(); | 299 delegate_->HideInstant(); |
| 300 |
| 301 content::NotificationService::current()->Notify( |
| 302 chrome::NOTIFICATION_INSTANT_CONTROLLER_HIDDEN, |
| 303 content::Source<InstantController>(this), |
| 304 content::NotificationService::NoDetails()); |
| 300 } | 305 } |
| 301 if (GetPreviewContents() && !last_full_text_.empty()) { | 306 if (GetPreviewContents() && !last_full_text_.empty()) { |
| 302 // Send a blank query to ask the preview to clear out old results. | 307 // Send a blank query to ask the preview to clear out old results. |
| 303 last_full_text_.clear(); | 308 last_full_text_.clear(); |
| 304 last_user_text_.clear(); | 309 last_user_text_.clear(); |
| 305 loader_->Update(last_full_text_, true); | 310 loader_->Update(last_full_text_, true); |
| 306 } | 311 } |
| 307 } | 312 } |
| 308 | 313 |
| 309 bool InstantController::IsCurrent() const { | 314 bool InstantController::IsCurrent() const { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower)) | 493 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower)) |
| 489 suggestion.text.clear(); | 494 suggestion.text.clear(); |
| 490 else | 495 else |
| 491 suggestion.text.erase(0, last_user_text_.size()); | 496 suggestion.text.erase(0, last_user_text_.size()); |
| 492 | 497 |
| 493 last_suggestion_ = suggestion; | 498 last_suggestion_ = suggestion; |
| 494 if (!last_verbatim_) | 499 if (!last_verbatim_) |
| 495 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior); | 500 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior); |
| 496 | 501 |
| 497 if (mode_ != SUGGEST) | 502 if (mode_ != SUGGEST) |
| 498 Show(); | 503 Show(100, INSTANT_SIZE_PERCENT); |
| 499 } | 504 } |
| 500 | 505 |
| 501 void InstantController::CommitInstantLoader(InstantLoader* loader) { | 506 void InstantController::CommitInstantLoader(InstantLoader* loader) { |
| 502 DCHECK_EQ(loader_.get(), loader); | 507 DCHECK_EQ(loader_.get(), loader); |
| 503 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; | 508 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; |
| 504 if (loader_ != loader || !is_showing_ || IsOutOfDate()) | 509 if (loader_ != loader || !is_showing_ || IsOutOfDate()) |
| 505 return; | 510 return; |
| 506 | 511 |
| 507 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); | 512 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); |
| 508 } | 513 } |
| 509 | 514 |
| 515 void InstantController::SetInstantPreviewHeight(InstantLoader* loader, |
| 516 int height, |
| 517 InstantSizeUnits units) { |
| 518 DCHECK_EQ(loader_.get(), loader); |
| 519 if (loader_ != loader || mode_ != EXTENDED) |
| 520 return; |
| 521 |
| 522 Show(height, units); |
| 523 } |
| 524 |
| 510 void InstantController::InstantLoaderPreviewLoaded(InstantLoader* loader) { | 525 void InstantController::InstantLoaderPreviewLoaded(InstantLoader* loader) { |
| 511 DCHECK_EQ(loader_.get(), loader); | 526 DCHECK_EQ(loader_.get(), loader); |
| 512 AddPreviewUsageForHistogram(mode_, PREVIEW_LOADED); | 527 AddPreviewUsageForHistogram(mode_, PREVIEW_LOADED); |
| 513 } | 528 } |
| 514 | 529 |
| 515 void InstantController::InstantSupportDetermined(InstantLoader* loader, | 530 void InstantController::InstantSupportDetermined(InstantLoader* loader, |
| 516 bool supports_instant) { | 531 bool supports_instant) { |
| 517 DCHECK_EQ(loader_.get(), loader); | 532 DCHECK_EQ(loader_.get(), loader); |
| 518 if (supports_instant) { | 533 if (supports_instant) { |
| 519 blacklisted_urls_.erase(loader->instant_url()); | 534 blacklisted_urls_.erase(loader->instant_url()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 532 content::Details<const bool> details(&supports_instant); | 547 content::Details<const bool> details(&supports_instant); |
| 533 content::NotificationService::current()->Notify( | 548 content::NotificationService::current()->Notify( |
| 534 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 549 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 535 content::NotificationService::AllSources(), | 550 content::NotificationService::AllSources(), |
| 536 details); | 551 details); |
| 537 } | 552 } |
| 538 | 553 |
| 539 void InstantController::SwappedTabContents(InstantLoader* loader) { | 554 void InstantController::SwappedTabContents(InstantLoader* loader) { |
| 540 DCHECK_EQ(loader_.get(), loader); | 555 DCHECK_EQ(loader_.get(), loader); |
| 541 if (loader_ == loader && is_showing_) | 556 if (loader_ == loader && is_showing_) |
| 542 delegate_->ShowInstant(); | 557 delegate_->ShowInstant(100, INSTANT_SIZE_PERCENT); |
| 543 } | 558 } |
| 544 | 559 |
| 545 void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { | 560 void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { |
| 546 DCHECK_EQ(loader_.get(), loader); | 561 DCHECK_EQ(loader_.get(), loader); |
| 547 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; | 562 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; |
| 548 #if defined(USE_AURA) | 563 #if defined(USE_AURA) |
| 549 // On aura the omnibox only receives a focus lost if we initiate the focus | 564 // On aura the omnibox only receives a focus lost if we initiate the focus |
| 550 // change. This does that. | 565 // change. This does that. |
| 551 if (is_showing_ && !IsOutOfDate()) | 566 if (is_showing_ && !IsOutOfDate()) |
| 552 delegate_->InstantPreviewFocused(); | 567 delegate_->InstantPreviewFocused(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 last_transition_type_ = content::PAGE_TRANSITION_LINK; | 641 last_transition_type_ = content::PAGE_TRANSITION_LINK; |
| 627 last_match_was_search_ = false; | 642 last_match_was_search_ = false; |
| 628 last_omnibox_bounds_ = gfx::Rect(); | 643 last_omnibox_bounds_ = gfx::Rect(); |
| 629 url_for_history_ = GURL(); | 644 url_for_history_ = GURL(); |
| 630 Hide(); | 645 Hide(); |
| 631 if (GetPreviewContents()) | 646 if (GetPreviewContents()) |
| 632 AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); | 647 AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); |
| 633 loader_.reset(); | 648 loader_.reset(); |
| 634 } | 649 } |
| 635 | 650 |
| 636 void InstantController::Show() { | 651 void InstantController::Show(int height, InstantSizeUnits units) { |
| 652 // Call even if showing in case height changed. |
| 653 delegate_->ShowInstant(height, units); |
| 637 if (!is_showing_) { | 654 if (!is_showing_) { |
| 638 is_showing_ = true; | 655 is_showing_ = true; |
| 639 delegate_->ShowInstant(); | |
| 640 AddPreviewUsageForHistogram(mode_, PREVIEW_SHOWED); | 656 AddPreviewUsageForHistogram(mode_, PREVIEW_SHOWED); |
| 657 |
| 658 content::NotificationService::current()->Notify( |
| 659 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, |
| 660 content::Source<InstantController>(this), |
| 661 content::NotificationService::NoDetails()); |
| 641 } | 662 } |
| 642 } | 663 } |
| 643 | 664 |
| 644 void InstantController::SendBoundsToPage() { | 665 void InstantController::SendBoundsToPage() { |
| 645 if (last_omnibox_bounds_ == omnibox_bounds_ || IsOutOfDate() || | 666 if (last_omnibox_bounds_ == omnibox_bounds_ || IsOutOfDate() || |
| 646 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) | 667 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) |
| 647 return; | 668 return; |
| 648 | 669 |
| 649 last_omnibox_bounds_ = omnibox_bounds_; | 670 last_omnibox_bounds_ = omnibox_bounds_; |
| 650 gfx::Rect preview_bounds = delegate_->GetInstantBounds(); | 671 gfx::Rect preview_bounds = delegate_->GetInstantBounds(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 iter->second > kMaxInstantSupportFailures) | 738 iter->second > kMaxInstantSupportFailures) |
| 718 return false; | 739 return false; |
| 719 | 740 |
| 720 return true; | 741 return true; |
| 721 } | 742 } |
| 722 | 743 |
| 723 bool InstantController::IsOutOfDate() const { | 744 bool InstantController::IsOutOfDate() const { |
| 724 return !last_active_tab_ || | 745 return !last_active_tab_ || |
| 725 last_active_tab_ != delegate_->GetActiveTabContents(); | 746 last_active_tab_ != delegate_->GetActiveTabContents(); |
| 726 } | 747 } |
| OLD | NEW |