| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_loader.h" | 5 #include "chrome/browser/instant/instant_loader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 // really have the search params, but we need to use the replace | 550 // really have the search params, but we need to use the replace |
| 551 // functionality so that embeded tags (like {google:baseURL}) are escaped | 551 // functionality so that embeded tags (like {google:baseURL}) are escaped |
| 552 // correctly. | 552 // correctly. |
| 553 // TODO(sky): having to use a replaceable url is a bit of a hack here. | 553 // TODO(sky): having to use a replaceable url is a bit of a hack here. |
| 554 GURL instant_url( | 554 GURL instant_url( |
| 555 template_url->instant_url()->ReplaceSearchTerms( | 555 template_url->instant_url()->ReplaceSearchTerms( |
| 556 *template_url, std::wstring(), -1, std::wstring())); | 556 *template_url, std::wstring(), -1, std::wstring())); |
| 557 CommandLine* cl = CommandLine::ForCurrentProcess(); | 557 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 558 if (cl->HasSwitch(switches::kInstantURL)) | 558 if (cl->HasSwitch(switches::kInstantURL)) |
| 559 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | 559 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); |
| 560 initial_instant_url_ = url; | |
| 561 preview_contents_->controller().LoadURL( | 560 preview_contents_->controller().LoadURL( |
| 562 instant_url, GURL(), transition_type); | 561 instant_url, GURL(), transition_type); |
| 563 frame_load_observer_.reset( | 562 frame_load_observer_.reset( |
| 564 new FrameLoadObserver(preview_contents()->tab_contents(), | 563 new FrameLoadObserver(preview_contents()->tab_contents(), |
| 565 user_text_, verbatim)); | 564 user_text_, verbatim)); |
| 566 } | 565 } |
| 567 } else { | 566 } else { |
| 568 DCHECK(template_url_id_ == 0); | 567 DCHECK(template_url_id_ == 0); |
| 569 frame_load_observer_.reset(NULL); | 568 frame_load_observer_.reset(NULL); |
| 570 preview_contents_->controller().LoadURL(url_, GURL(), transition_type); | 569 preview_contents_->controller().LoadURL(url_, GURL(), transition_type); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 } | 639 } |
| 641 | 640 |
| 642 bool InstantLoader::ShouldCommitInstantOnMouseUp() { | 641 bool InstantLoader::ShouldCommitInstantOnMouseUp() { |
| 643 return delegate_->ShouldCommitInstantOnMouseUp(); | 642 return delegate_->ShouldCommitInstantOnMouseUp(); |
| 644 } | 643 } |
| 645 | 644 |
| 646 void InstantLoader::CommitInstantLoader() { | 645 void InstantLoader::CommitInstantLoader() { |
| 647 delegate_->CommitInstantLoader(this); | 646 delegate_->CommitInstantLoader(this); |
| 648 } | 647 } |
| 649 | 648 |
| 650 void InstantLoader::ClearTemplateURLID() { | |
| 651 // This should only be invoked for sites we thought supported instant. | |
| 652 DCHECK(template_url_id_); | |
| 653 | |
| 654 // The frame load observer should have completed. | |
| 655 DCHECK(!frame_load_observer_.get()); | |
| 656 | |
| 657 // We shouldn't be ready. | |
| 658 DCHECK(!ready()); | |
| 659 | |
| 660 template_url_id_ = 0; | |
| 661 ShowPreview(); | |
| 662 } | |
| 663 | |
| 664 void InstantLoader::SetCompleteSuggestedText( | 649 void InstantLoader::SetCompleteSuggestedText( |
| 665 const string16& complete_suggested_text) { | 650 const string16& complete_suggested_text) { |
| 666 ShowPreview(); | 651 ShowPreview(); |
| 667 | 652 |
| 668 if (complete_suggested_text == complete_suggested_text_) | 653 if (complete_suggested_text == complete_suggested_text_) |
| 669 return; | 654 return; |
| 670 | 655 |
| 671 if (verbatim_) { | 656 if (verbatim_) { |
| 672 // Don't show suggest results for verbatim queries. | 657 // Don't show suggest results for verbatim queries. |
| 673 return; | 658 return; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 // the above operations. In a future UI, these may be removed or adjusted. | 737 // the above operations. In a future UI, these may be removed or adjusted. |
| 753 DCHECK_EQ(0, intersection.y()); | 738 DCHECK_EQ(0, intersection.y()); |
| 754 DCHECK_LE(0, intersection.x()); | 739 DCHECK_LE(0, intersection.x()); |
| 755 DCHECK_LE(0, intersection.width()); | 740 DCHECK_LE(0, intersection.width()); |
| 756 DCHECK_LE(0, intersection.height()); | 741 DCHECK_LE(0, intersection.height()); |
| 757 | 742 |
| 758 return intersection; | 743 return intersection; |
| 759 } | 744 } |
| 760 | 745 |
| 761 void InstantLoader::PageDoesntSupportInstant(bool needs_reload) { | 746 void InstantLoader::PageDoesntSupportInstant(bool needs_reload) { |
| 762 GURL url_to_load = url_; | |
| 763 | |
| 764 // Because we didn't process any of the requests to load in Update we're | |
| 765 // actually at initial_instant_url_. We need to reset url_ so that callers see | |
| 766 // the correct state. | |
| 767 url_ = initial_instant_url_; | |
| 768 | |
| 769 frame_load_observer_.reset(NULL); | 747 frame_load_observer_.reset(NULL); |
| 770 | 748 |
| 771 delegate_->InstantLoaderDoesntSupportInstant(this, needs_reload, url_to_load); | 749 delegate_->InstantLoaderDoesntSupportInstant(this); |
| 772 } | 750 } |
| 773 | 751 |
| 774 void InstantLoader::ProcessBoundsChange() { | 752 void InstantLoader::ProcessBoundsChange() { |
| 775 if (last_omnibox_bounds_ == omnibox_bounds_) | 753 if (last_omnibox_bounds_ == omnibox_bounds_) |
| 776 return; | 754 return; |
| 777 | 755 |
| 778 last_omnibox_bounds_ = omnibox_bounds_; | 756 last_omnibox_bounds_ = omnibox_bounds_; |
| 779 if (preview_contents_.get() && is_showing_instant() && | 757 if (preview_contents_.get() && is_showing_instant() && |
| 780 !is_waiting_for_load()) { | 758 !is_waiting_for_load()) { |
| 781 preview_contents_->render_view_host()->SearchBoxResize( | 759 preview_contents_->render_view_host()->SearchBoxResize( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 Source<NavigationController>(&preview_contents_->controller())); | 794 Source<NavigationController>(&preview_contents_->controller())); |
| 817 #endif | 795 #endif |
| 818 | 796 |
| 819 registrar_.Add( | 797 registrar_.Add( |
| 820 this, | 798 this, |
| 821 NotificationType::NAV_ENTRY_COMMITTED, | 799 NotificationType::NAV_ENTRY_COMMITTED, |
| 822 Source<NavigationController>(&preview_contents_->controller())); | 800 Source<NavigationController>(&preview_contents_->controller())); |
| 823 | 801 |
| 824 preview_contents_->tab_contents()->ShowContents(); | 802 preview_contents_->tab_contents()->ShowContents(); |
| 825 } | 803 } |
| OLD | NEW |