OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 const char* InstantController::kLocalOmniboxPopupURL = | 151 const char* InstantController::kLocalOmniboxPopupURL = |
152 "chrome://local-omnibox-popup/local-omnibox-popup.html"; | 152 "chrome://local-omnibox-popup/local-omnibox-popup.html"; |
153 | 153 |
154 InstantController::InstantController(chrome::BrowserInstantController* browser, | 154 InstantController::InstantController(chrome::BrowserInstantController* browser, |
155 bool extended_enabled, | 155 bool extended_enabled, |
156 bool use_local_preview_only) | 156 bool use_local_preview_only) |
157 : browser_(browser), | 157 : browser_(browser), |
158 extended_enabled_(extended_enabled), | 158 extended_enabled_(extended_enabled), |
159 instant_enabled_(false), | 159 instant_enabled_(false), |
160 use_local_preview_only_(use_local_preview_only), | 160 use_local_preview_only_(use_local_preview_only), |
| 161 in_testing_mode_(false), |
161 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 162 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
162 last_omnibox_text_has_inline_autocompletion_(false), | 163 last_omnibox_text_has_inline_autocompletion_(false), |
163 last_verbatim_(false), | 164 last_verbatim_(false), |
164 last_transition_type_(content::PAGE_TRANSITION_LINK), | 165 last_transition_type_(content::PAGE_TRANSITION_LINK), |
165 last_match_was_search_(false), | 166 last_match_was_search_(false), |
166 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 167 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
167 start_margin_(0), | 168 start_margin_(0), |
168 end_margin_(0), | 169 end_margin_(0), |
169 allow_preview_to_show_search_suggestions_(false) { | 170 allow_preview_to_show_search_suggestions_(false) { |
170 } | 171 } |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 | 915 |
915 void InstantController::NavigateToURL(const GURL& url, | 916 void InstantController::NavigateToURL(const GURL& url, |
916 content::PageTransition transition) { | 917 content::PageTransition transition) { |
917 if (!extended_enabled_) | 918 if (!extended_enabled_) |
918 return; | 919 return; |
919 if (loader_) | 920 if (loader_) |
920 HideLoader(); | 921 HideLoader(); |
921 browser_->OpenURLInCurrentTab(url, transition); | 922 browser_->OpenURLInCurrentTab(url, transition); |
922 } | 923 } |
923 | 924 |
| 925 void InstantController::SetTestingMode() { |
| 926 in_testing_mode_ = true; |
| 927 } |
| 928 |
924 bool InstantController::ResetLoader(const TemplateURL* template_url, | 929 bool InstantController::ResetLoader(const TemplateURL* template_url, |
925 const content::WebContents* active_tab, | 930 const content::WebContents* active_tab, |
926 bool fallback_to_local) { | 931 bool fallback_to_local) { |
927 std::string instant_url; | 932 std::string instant_url; |
928 if (!GetInstantURL(template_url, &instant_url)) { | 933 if (!GetInstantURL(template_url, &instant_url)) { |
929 if (!fallback_to_local || !extended_enabled_) | 934 if (!fallback_to_local || !extended_enabled_) |
930 return false; | 935 return false; |
931 | 936 |
932 // If we are in extended mode, fallback to the local popup. | 937 // If we are in extended mode, fallback to the local popup. |
933 instant_url = kLocalOmniboxPopupURL; | 938 instant_url = kLocalOmniboxPopupURL; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 return false; | 1170 return false; |
1166 | 1171 |
1167 // Even if the URL template doesn't have search terms, it may have other | 1172 // Even if the URL template doesn't have search terms, it may have other |
1168 // components (such as {google:baseURL}) that need to be replaced. | 1173 // components (such as {google:baseURL}) that need to be replaced. |
1169 *instant_url = instant_url_ref.ReplaceSearchTerms( | 1174 *instant_url = instant_url_ref.ReplaceSearchTerms( |
1170 TemplateURLRef::SearchTermsArgs(string16())); | 1175 TemplateURLRef::SearchTermsArgs(string16())); |
1171 | 1176 |
1172 // Extended mode should always use HTTPS. TODO(sreeram): This section can be | 1177 // Extended mode should always use HTTPS. TODO(sreeram): This section can be |
1173 // removed if TemplateURLs supported "https://{google:host}/..." instead of | 1178 // removed if TemplateURLs supported "https://{google:host}/..." instead of |
1174 // only supporting "{google:baseURL}...". | 1179 // only supporting "{google:baseURL}...". |
1175 if (extended_enabled_) { | 1180 if (extended_enabled_ && !in_testing_mode_) { |
1176 GURL url_obj(*instant_url); | 1181 GURL url_obj(*instant_url); |
1177 if (!url_obj.is_valid()) | 1182 if (!url_obj.is_valid()) |
1178 return false; | 1183 return false; |
1179 | 1184 |
1180 if (!url_obj.SchemeIsSecure()) { | 1185 if (!url_obj.SchemeIsSecure()) { |
1181 std::string new_scheme = "https"; | 1186 std::string new_scheme = "https"; |
1182 std::string new_port = "443"; | 1187 std::string new_port = "443"; |
1183 GURL::Replacements secure; | 1188 GURL::Replacements secure; |
1184 secure.SetSchemeStr(new_scheme); | 1189 secure.SetSchemeStr(new_scheme); |
1185 secure.SetPortStr(new_port); | 1190 secure.SetPortStr(new_port); |
1186 url_obj = url_obj.ReplaceComponents(secure); | 1191 url_obj = url_obj.ReplaceComponents(secure); |
1187 | 1192 |
1188 if (!url_obj.is_valid()) | 1193 if (!url_obj.is_valid()) |
1189 return false; | 1194 return false; |
1190 | 1195 |
1191 *instant_url = url_obj.spec(); | 1196 *instant_url = url_obj.spec(); |
1192 } | 1197 } |
1193 } | 1198 } |
1194 | 1199 |
1195 std::map<std::string, int>::const_iterator iter = | 1200 std::map<std::string, int>::const_iterator iter = |
1196 blacklisted_urls_.find(*instant_url); | 1201 blacklisted_urls_.find(*instant_url); |
1197 if (iter != blacklisted_urls_.end() && | 1202 if (iter != blacklisted_urls_.end() && |
1198 iter->second > kMaxInstantSupportFailures) | 1203 iter->second > kMaxInstantSupportFailures) |
1199 return false; | 1204 return false; |
1200 | 1205 |
1201 return true; | 1206 return true; |
1202 } | 1207 } |
OLD | NEW |