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_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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 complete_suggested_text_); | 720 complete_suggested_text_); |
721 string16 user_text_lower = base::i18n::ToLower(user_text_); | 721 string16 user_text_lower = base::i18n::ToLower(user_text_); |
722 if (!verbatim && | 722 if (!verbatim && |
723 complete_suggested_text_lower.size() > user_text_lower.size() && | 723 complete_suggested_text_lower.size() > user_text_lower.size() && |
724 !complete_suggested_text_lower.compare(0, user_text_lower.size(), | 724 !complete_suggested_text_lower.compare(0, user_text_lower.size(), |
725 user_text_lower)) { | 725 user_text_lower)) { |
726 *suggested_text = last_suggestion_ = | 726 *suggested_text = last_suggestion_ = |
727 complete_suggested_text_.substr(user_text_.size()); | 727 complete_suggested_text_.substr(user_text_.size()); |
728 } | 728 } |
729 } else { | 729 } else { |
730 LoadInstantURL(tab_contents, template_url, transition_type, user_text_, | 730 LoadInstantURL(template_url, transition_type, user_text_, verbatim); |
731 verbatim); | |
732 } | 731 } |
733 } else { | 732 } else { |
734 DCHECK(template_url_id_ == 0); | 733 DCHECK(template_url_id_ == 0); |
735 preview_tab_contents_delegate_->PrepareForNewLoad(); | 734 preview_tab_contents_delegate_->PrepareForNewLoad(); |
736 frame_load_observer_.reset(NULL); | 735 frame_load_observer_.reset(NULL); |
737 preview_contents_->web_contents()->GetController().LoadURL( | 736 preview_contents_->web_contents()->GetController().LoadURL( |
738 url_, content::Referrer(), transition_type, std::string()); | 737 url_, content::Referrer(), transition_type, std::string()); |
739 } | 738 } |
740 return true; | 739 return true; |
741 } | 740 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 const TemplateURL* template_url) { | 848 const TemplateURL* template_url) { |
850 DCHECK(template_url_id_ == template_url->id()); | 849 DCHECK(template_url_id_ == template_url->id()); |
851 | 850 |
852 // If we already have a |preview_contents_|, future search queries will be | 851 // If we already have a |preview_contents_|, future search queries will be |
853 // issued into it (see the "if (!created_preview_contents)" block in |Update| | 852 // issued into it (see the "if (!created_preview_contents)" block in |Update| |
854 // above), so there is no need to load the |template_url|'s instant URL. | 853 // above), so there is no need to load the |template_url|'s instant URL. |
855 if (preview_contents_.get()) | 854 if (preview_contents_.get()) |
856 return; | 855 return; |
857 | 856 |
858 CreatePreviewContents(tab_contents); | 857 CreatePreviewContents(tab_contents); |
859 LoadInstantURL(tab_contents, template_url, content::PAGE_TRANSITION_GENERATED, | 858 LoadInstantURL(template_url, content::PAGE_TRANSITION_GENERATED, string16(), |
860 string16(), true); | 859 true); |
861 } | 860 } |
862 | 861 |
863 bool InstantLoader::IsNavigationPending() const { | 862 bool InstantLoader::IsNavigationPending() const { |
864 return preview_contents_.get() && | 863 return preview_contents_.get() && |
865 preview_contents_->web_contents()->GetController().GetPendingEntry(); | 864 preview_contents_->web_contents()->GetController().GetPendingEntry(); |
866 } | 865 } |
867 | 866 |
868 void InstantLoader::Observe(int type, | 867 void InstantLoader::Observe(int type, |
869 const content::NotificationSource& source, | 868 const content::NotificationSource& source, |
870 const content::NotificationDetails& details) { | 869 const content::NotificationDetails& details) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1104 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
1106 preview_contents_.reset(new TabContentsWrapper(new_contents)); | 1105 preview_contents_.reset(new TabContentsWrapper(new_contents)); |
1107 AddPreviewUsageForHistogram(template_url_id_, PREVIEW_CREATED, group_); | 1106 AddPreviewUsageForHistogram(template_url_id_, PREVIEW_CREATED, group_); |
1108 session_storage_namespace_ = GetSessionStorageNamespace(tab_contents); | 1107 session_storage_namespace_ = GetSessionStorageNamespace(tab_contents); |
1109 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 1108 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
1110 SetupPreviewContents(tab_contents); | 1109 SetupPreviewContents(tab_contents); |
1111 | 1110 |
1112 preview_contents_->web_contents()->ShowContents(); | 1111 preview_contents_->web_contents()->ShowContents(); |
1113 } | 1112 } |
1114 | 1113 |
1115 void InstantLoader::LoadInstantURL(TabContentsWrapper* tab_contents, | 1114 void InstantLoader::LoadInstantURL(const TemplateURL* template_url, |
1116 const TemplateURL* template_url, | |
1117 content::PageTransition transition_type, | 1115 content::PageTransition transition_type, |
1118 const string16& user_text, | 1116 const string16& user_text, |
1119 bool verbatim) { | 1117 bool verbatim) { |
1120 preview_tab_contents_delegate_->PrepareForNewLoad(); | 1118 preview_tab_contents_delegate_->PrepareForNewLoad(); |
1121 | 1119 |
1122 // Load the instant URL. We don't reflect the url we load in url() as | 1120 // Load the instant URL. We don't reflect the url we load in url() as |
1123 // callers expect that we're loading the URL they tell us to. | 1121 // callers expect that we're loading the URL they tell us to. |
1124 // | 1122 // |
1125 // This uses an empty string for the replacement text as the url doesn't | 1123 // This uses an empty string for the replacement text as the url doesn't |
1126 // really have the search params, but we need to use the replace | 1124 // really have the search params, but we need to use the replace |
1127 // functionality so that embeded tags (like {google:baseURL}) are escaped | 1125 // functionality so that embeded tags (like {google:baseURL}) are escaped |
1128 // correctly. | 1126 // correctly. |
1129 // TODO(sky): having to use a replaceable url is a bit of a hack here. | 1127 // TODO(sky): having to use a replaceable url is a bit of a hack here. |
1130 GURL instant_url( | 1128 GURL instant_url(template_url->instant_url_ref().ReplaceSearchTerms( |
1131 template_url->instant_url_ref().ReplaceSearchTermsUsingProfile( | 1129 string16(), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
1132 tab_contents->profile(), string16(), | |
1133 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | |
1134 CommandLine* cl = CommandLine::ForCurrentProcess(); | 1130 CommandLine* cl = CommandLine::ForCurrentProcess(); |
1135 if (cl->HasSwitch(switches::kInstantURL)) | 1131 if (cl->HasSwitch(switches::kInstantURL)) |
1136 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | 1132 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); |
1137 preview_contents_->web_contents()->GetController().LoadURL( | 1133 preview_contents_->web_contents()->GetController().LoadURL( |
1138 instant_url, content::Referrer(), transition_type, std::string()); | 1134 instant_url, content::Referrer(), transition_type, std::string()); |
1139 RenderViewHost* host = preview_contents_->web_contents()->GetRenderViewHost(); | 1135 RenderViewHost* host = preview_contents_->web_contents()->GetRenderViewHost(); |
1140 preview_contents_->web_contents()->HideContents(); | 1136 preview_contents_->web_contents()->HideContents(); |
1141 | 1137 |
1142 // If user_text is empty, this must be a preload of the search homepage. In | 1138 // If user_text is empty, this must be a preload of the search homepage. In |
1143 // that case, send down a SearchBoxResize message, which will switch the page | 1139 // that case, send down a SearchBoxResize message, which will switch the page |
1144 // to "search results" UI. This avoids flicker when the page is shown with | 1140 // to "search results" UI. This avoids flicker when the page is shown with |
1145 // results. In addition, we don't want the page accidentally causing the | 1141 // results. In addition, we don't want the page accidentally causing the |
1146 // preloaded page to be displayed yet (by calling setSuggestions), so don't | 1142 // preloaded page to be displayed yet (by calling setSuggestions), so don't |
1147 // send a SearchBoxChange message. | 1143 // send a SearchBoxChange message. |
1148 if (user_text.empty()) { | 1144 if (user_text.empty()) { |
1149 host->Send(new ChromeViewMsg_SearchBoxResize( | 1145 host->Send(new ChromeViewMsg_SearchBoxResize( |
1150 host->GetRoutingID(), GetOmniboxBoundsInTermsOfPreview())); | 1146 host->GetRoutingID(), GetOmniboxBoundsInTermsOfPreview())); |
1151 } else { | 1147 } else { |
1152 host->Send(new ChromeViewMsg_SearchBoxChange( | 1148 host->Send(new ChromeViewMsg_SearchBoxChange( |
1153 host->GetRoutingID(), user_text, verbatim, 0, 0)); | 1149 host->GetRoutingID(), user_text, verbatim, 0, 0)); |
1154 } | 1150 } |
1155 | 1151 |
1156 frame_load_observer_.reset(new FrameLoadObserver( | 1152 frame_load_observer_.reset(new FrameLoadObserver( |
1157 this, preview_contents()->web_contents(), user_text, verbatim)); | 1153 this, preview_contents()->web_contents(), user_text, verbatim)); |
1158 } | 1154 } |
OLD | NEW |