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_loader.h" | 5 #include "chrome/browser/instant/instant_loader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 complete_suggested_text_); | 721 complete_suggested_text_); |
722 string16 user_text_lower = base::i18n::ToLower(user_text_); | 722 string16 user_text_lower = base::i18n::ToLower(user_text_); |
723 if (!verbatim && | 723 if (!verbatim && |
724 complete_suggested_text_lower.size() > user_text_lower.size() && | 724 complete_suggested_text_lower.size() > user_text_lower.size() && |
725 !complete_suggested_text_lower.compare(0, user_text_lower.size(), | 725 !complete_suggested_text_lower.compare(0, user_text_lower.size(), |
726 user_text_lower)) { | 726 user_text_lower)) { |
727 *suggested_text = last_suggestion_ = | 727 *suggested_text = last_suggestion_ = |
728 complete_suggested_text_.substr(user_text_.size()); | 728 complete_suggested_text_.substr(user_text_.size()); |
729 } | 729 } |
730 } else { | 730 } else { |
731 preview_tab_contents_delegate_->PrepareForNewLoad(); | 731 LoadInstantURL(tab_contents, template_url, transition_type, user_text_, |
732 | 732 verbatim); |
733 // Load the instant URL. We don't reflect the url we load in url() as | |
734 // callers expect that we're loading the URL they tell us to. | |
735 // | |
736 // This uses an empty string for the replacement text as the url doesn't | |
737 // really have the search params, but we need to use the replace | |
738 // functionality so that embeded tags (like {google:baseURL}) are escaped | |
739 // correctly. | |
740 // TODO(sky): having to use a replaceable url is a bit of a hack here. | |
741 GURL instant_url( | |
742 template_url->instant_url()->ReplaceSearchTerms( | |
743 *template_url, string16(), -1, string16())); | |
744 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
745 if (cl->HasSwitch(switches::kInstantURL)) | |
746 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | |
747 preview_contents_->controller().LoadURL( | |
748 instant_url, GURL(), transition_type); | |
749 RenderViewHost* host = preview_contents_->render_view_host(); | |
750 host->Send(new ViewMsg_SearchBoxChange( | |
751 host->routing_id(), user_text_, verbatim, 0, 0)); | |
752 frame_load_observer_.reset( | |
753 new FrameLoadObserver(this, | |
754 preview_contents()->tab_contents(), | |
755 user_text_, | |
756 verbatim)); | |
757 } | 733 } |
758 } else { | 734 } else { |
759 DCHECK(template_url_id_ == 0); | 735 DCHECK(template_url_id_ == 0); |
760 preview_tab_contents_delegate_->PrepareForNewLoad(); | 736 preview_tab_contents_delegate_->PrepareForNewLoad(); |
761 frame_load_observer_.reset(NULL); | 737 frame_load_observer_.reset(NULL); |
762 preview_contents_->controller().LoadURL(url_, GURL(), transition_type); | 738 preview_contents_->controller().LoadURL(url_, GURL(), transition_type); |
763 } | 739 } |
764 return true; | 740 return true; |
765 } | 741 } |
766 | 742 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 } | 825 } |
850 | 826 |
851 bool InstantLoader::ShouldCommitInstantOnMouseUp() { | 827 bool InstantLoader::ShouldCommitInstantOnMouseUp() { |
852 return delegate_->ShouldCommitInstantOnMouseUp(); | 828 return delegate_->ShouldCommitInstantOnMouseUp(); |
853 } | 829 } |
854 | 830 |
855 void InstantLoader::CommitInstantLoader() { | 831 void InstantLoader::CommitInstantLoader() { |
856 delegate_->CommitInstantLoader(this); | 832 delegate_->CommitInstantLoader(this); |
857 } | 833 } |
858 | 834 |
| 835 void InstantLoader::MaybeLoadInstantURL(TabContentsWrapper* tab_contents, |
| 836 const TemplateURL* template_url) { |
| 837 DCHECK(template_url_id_ == template_url->id()); |
| 838 |
| 839 // If we already have a |preview_contents_|, future search queries will be |
| 840 // issued into it (see the "if (!created_preview_contents)" block in |Update| |
| 841 // above), so there is no need to load the |template_url|'s instant URL. |
| 842 if (preview_contents_.get()) |
| 843 return; |
| 844 |
| 845 CreatePreviewContents(tab_contents); |
| 846 LoadInstantURL(tab_contents, template_url, PageTransition::GENERATED, |
| 847 string16(), true); |
| 848 } |
| 849 |
859 void InstantLoader::SetCompleteSuggestedText( | 850 void InstantLoader::SetCompleteSuggestedText( |
860 const string16& complete_suggested_text, | 851 const string16& complete_suggested_text, |
861 InstantCompleteBehavior behavior) { | 852 InstantCompleteBehavior behavior) { |
862 if (!is_showing_instant()) { | 853 if (!is_showing_instant()) { |
863 // We're not trying to use the instant API with this page. Ignore it. | 854 // We're not trying to use the instant API with this page. Ignore it. |
864 return; | 855 return; |
865 } | 856 } |
866 | 857 |
867 ShowPreview(); | 858 ShowPreview(); |
868 | 859 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { | 1077 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { |
1087 TabContents* new_contents = | 1078 TabContents* new_contents = |
1088 new TabContents( | 1079 new TabContents( |
1089 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1080 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
1090 preview_contents_.reset(new TabContentsWrapper(new_contents)); | 1081 preview_contents_.reset(new TabContentsWrapper(new_contents)); |
1091 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 1082 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
1092 SetupPreviewContents(tab_contents); | 1083 SetupPreviewContents(tab_contents); |
1093 | 1084 |
1094 preview_contents_->tab_contents()->ShowContents(); | 1085 preview_contents_->tab_contents()->ShowContents(); |
1095 } | 1086 } |
| 1087 |
| 1088 void InstantLoader::LoadInstantURL(TabContentsWrapper* tab_contents, |
| 1089 const TemplateURL* template_url, |
| 1090 PageTransition::Type transition_type, |
| 1091 const string16& user_text, |
| 1092 bool verbatim) { |
| 1093 preview_tab_contents_delegate_->PrepareForNewLoad(); |
| 1094 |
| 1095 // Load the instant URL. We don't reflect the url we load in url() as |
| 1096 // callers expect that we're loading the URL they tell us to. |
| 1097 // |
| 1098 // This uses an empty string for the replacement text as the url doesn't |
| 1099 // really have the search params, but we need to use the replace |
| 1100 // functionality so that embeded tags (like {google:baseURL}) are escaped |
| 1101 // correctly. |
| 1102 // TODO(sky): having to use a replaceable url is a bit of a hack here. |
| 1103 GURL instant_url(template_url->instant_url()->ReplaceSearchTerms( |
| 1104 *template_url, string16(), -1, string16())); |
| 1105 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 1106 if (cl->HasSwitch(switches::kInstantURL)) |
| 1107 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); |
| 1108 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type); |
| 1109 RenderViewHost* host = preview_contents_->render_view_host(); |
| 1110 host->Send(new ViewMsg_SearchBoxChange( |
| 1111 host->routing_id(), user_text, verbatim, 0, 0)); |
| 1112 frame_load_observer_.reset(new FrameLoadObserver( |
| 1113 this, preview_contents()->tab_contents(), user_text, verbatim)); |
| 1114 } |
OLD | NEW |