| 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 289 } |
| 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 preview_height_ = 100; |
| 300 preview_height_units_ = INSTANT_SIZE_PERCENT; |
| 299 delegate_->HideInstant(); | 301 delegate_->HideInstant(); |
| 300 } | 302 } |
| 301 if (GetPreviewContents() && !last_full_text_.empty()) { | 303 if (GetPreviewContents() && !last_full_text_.empty()) { |
| 302 // Send a blank query to ask the preview to clear out old results. | 304 // Send a blank query to ask the preview to clear out old results. |
| 303 last_full_text_.clear(); | 305 last_full_text_.clear(); |
| 304 last_user_text_.clear(); | 306 last_user_text_.clear(); |
| 305 loader_->Update(last_full_text_, true); | 307 loader_->Update(last_full_text_, true); |
| 306 } | 308 } |
| 307 } | 309 } |
| 308 | 310 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 502 |
| 501 void InstantController::CommitInstantLoader(InstantLoader* loader) { | 503 void InstantController::CommitInstantLoader(InstantLoader* loader) { |
| 502 DCHECK_EQ(loader_.get(), loader); | 504 DCHECK_EQ(loader_.get(), loader); |
| 503 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; | 505 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; |
| 504 if (loader_ != loader || !is_showing_ || IsOutOfDate()) | 506 if (loader_ != loader || !is_showing_ || IsOutOfDate()) |
| 505 return; | 507 return; |
| 506 | 508 |
| 507 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); | 509 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); |
| 508 } | 510 } |
| 509 | 511 |
| 512 void InstantController::SetInstantPreviewHeight(InstantLoader* loader, |
| 513 int height, |
| 514 InstantSizeUnits units) { |
| 515 DCHECK_EQ(loader_.get(), loader); |
| 516 if (loader_ != loader || mode_ != EXTENDED) |
| 517 return; |
| 518 |
| 519 preview_height_ = height; |
| 520 preview_height_units_ = units; |
| 521 Show(); |
| 522 } |
| 523 |
| 510 void InstantController::InstantLoaderPreviewLoaded(InstantLoader* loader) { | 524 void InstantController::InstantLoaderPreviewLoaded(InstantLoader* loader) { |
| 511 DCHECK_EQ(loader_.get(), loader); | 525 DCHECK_EQ(loader_.get(), loader); |
| 512 AddPreviewUsageForHistogram(mode_, PREVIEW_LOADED); | 526 AddPreviewUsageForHistogram(mode_, PREVIEW_LOADED); |
| 513 } | 527 } |
| 514 | 528 |
| 515 void InstantController::InstantSupportDetermined(InstantLoader* loader, | 529 void InstantController::InstantSupportDetermined(InstantLoader* loader, |
| 516 bool supports_instant) { | 530 bool supports_instant) { |
| 517 DCHECK_EQ(loader_.get(), loader); | 531 DCHECK_EQ(loader_.get(), loader); |
| 518 if (supports_instant) { | 532 if (supports_instant) { |
| 519 blacklisted_urls_.erase(loader->instant_url()); | 533 blacklisted_urls_.erase(loader->instant_url()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 532 content::Details<const bool> details(&supports_instant); | 546 content::Details<const bool> details(&supports_instant); |
| 533 content::NotificationService::current()->Notify( | 547 content::NotificationService::current()->Notify( |
| 534 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 548 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 535 content::NotificationService::AllSources(), | 549 content::NotificationService::AllSources(), |
| 536 details); | 550 details); |
| 537 } | 551 } |
| 538 | 552 |
| 539 void InstantController::SwappedTabContents(InstantLoader* loader) { | 553 void InstantController::SwappedTabContents(InstantLoader* loader) { |
| 540 DCHECK_EQ(loader_.get(), loader); | 554 DCHECK_EQ(loader_.get(), loader); |
| 541 if (loader_ == loader && is_showing_) | 555 if (loader_ == loader && is_showing_) |
| 542 delegate_->ShowInstant(); | 556 delegate_->ShowInstant(preview_height_, preview_height_units_); |
| 543 } | 557 } |
| 544 | 558 |
| 545 void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { | 559 void InstantController::InstantLoaderContentsFocused(InstantLoader* loader) { |
| 546 DCHECK_EQ(loader_.get(), loader); | 560 DCHECK_EQ(loader_.get(), loader); |
| 547 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; | 561 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; |
| 548 #if defined(USE_AURA) | 562 #if defined(USE_AURA) |
| 549 // On aura the omnibox only receives a focus lost if we initiate the focus | 563 // On aura the omnibox only receives a focus lost if we initiate the focus |
| 550 // change. This does that. | 564 // change. This does that. |
| 551 if (is_showing_ && !IsOutOfDate()) | 565 if (is_showing_ && !IsOutOfDate()) |
| 552 delegate_->InstantPreviewFocused(); | 566 delegate_->InstantPreviewFocused(); |
| 553 #endif | 567 #endif |
| 554 } | 568 } |
| 555 | 569 |
| 556 InstantController::InstantController(InstantControllerDelegate* delegate, | 570 InstantController::InstantController(InstantControllerDelegate* delegate, |
| 557 Mode mode) | 571 Mode mode) |
| 558 : delegate_(delegate), | 572 : delegate_(delegate), |
| 559 mode_(mode), | 573 mode_(mode), |
| 560 last_active_tab_(NULL), | 574 last_active_tab_(NULL), |
| 561 last_verbatim_(false), | 575 last_verbatim_(false), |
| 562 last_transition_type_(content::PAGE_TRANSITION_LINK), | 576 last_transition_type_(content::PAGE_TRANSITION_LINK), |
| 563 last_match_was_search_(false), | 577 last_match_was_search_(false), |
| 564 is_showing_(false), | 578 is_showing_(false), |
| 565 loader_processed_last_update_(false) { | 579 loader_processed_last_update_(false), |
| 580 preview_height_(100), |
| 581 preview_height_units_(INSTANT_SIZE_PERCENT) { |
| 566 } | 582 } |
| 567 | 583 |
| 568 void InstantController::ResetLoader(const std::string& instant_url, | 584 void InstantController::ResetLoader(const std::string& instant_url, |
| 569 const TabContents* active_tab) { | 585 const TabContents* active_tab) { |
| 570 if (GetPreviewContents() && loader_->instant_url() != instant_url) | 586 if (GetPreviewContents() && loader_->instant_url() != instant_url) |
| 571 DeleteLoader(); | 587 DeleteLoader(); |
| 572 | 588 |
| 573 if (!GetPreviewContents()) { | 589 if (!GetPreviewContents()) { |
| 574 DCHECK(!loader_.get()); | 590 DCHECK(!loader_.get()); |
| 575 loader_.reset(new InstantLoader(this, instant_url, active_tab)); | 591 loader_.reset(new InstantLoader(this, instant_url, active_tab)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 url_for_history_ = GURL(); | 645 url_for_history_ = GURL(); |
| 630 Hide(); | 646 Hide(); |
| 631 if (GetPreviewContents()) | 647 if (GetPreviewContents()) |
| 632 AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); | 648 AddPreviewUsageForHistogram(mode_, PREVIEW_DELETED); |
| 633 loader_.reset(); | 649 loader_.reset(); |
| 634 } | 650 } |
| 635 | 651 |
| 636 void InstantController::Show() { | 652 void InstantController::Show() { |
| 637 if (!is_showing_) { | 653 if (!is_showing_) { |
| 638 is_showing_ = true; | 654 is_showing_ = true; |
| 639 delegate_->ShowInstant(); | 655 delegate_->ShowInstant(preview_height_, preview_height_units_); |
| 640 AddPreviewUsageForHistogram(mode_, PREVIEW_SHOWED); | 656 AddPreviewUsageForHistogram(mode_, PREVIEW_SHOWED); |
| 641 } | 657 } |
| 642 } | 658 } |
| 643 | 659 |
| 644 void InstantController::SendBoundsToPage() { | 660 void InstantController::SendBoundsToPage() { |
| 645 if (last_omnibox_bounds_ == omnibox_bounds_ || IsOutOfDate() || | 661 if (last_omnibox_bounds_ == omnibox_bounds_ || IsOutOfDate() || |
| 646 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) | 662 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) |
| 647 return; | 663 return; |
| 648 | 664 |
| 649 last_omnibox_bounds_ = omnibox_bounds_; | 665 last_omnibox_bounds_ = omnibox_bounds_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 iter->second > kMaxInstantSupportFailures) | 733 iter->second > kMaxInstantSupportFailures) |
| 718 return false; | 734 return false; |
| 719 | 735 |
| 720 return true; | 736 return true; |
| 721 } | 737 } |
| 722 | 738 |
| 723 bool InstantController::IsOutOfDate() const { | 739 bool InstantController::IsOutOfDate() const { |
| 724 return !last_active_tab_ || | 740 return !last_active_tab_ || |
| 725 last_active_tab_ != delegate_->GetActiveTabContents(); | 741 last_active_tab_ != delegate_->GetActiveTabContents(); |
| 726 } | 742 } |
| OLD | NEW |