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/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 12 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
13 #include "chrome/browser/google/google_util.h" | 13 #include "chrome/browser/google/google_util.h" |
14 #include "chrome/browser/history/history_service.h" | 14 #include "chrome/browser/history/history_service.h" |
15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
16 #include "chrome/browser/history/history_tab_helper.h" | 16 #include "chrome/browser/history/history_tab_helper.h" |
17 #include "chrome/browser/instant/instant_ntp.h" | 17 #include "chrome/browser/instant/instant_ntp.h" |
18 #include "chrome/browser/instant/instant_overlay.h" | 18 #include "chrome/browser/instant/instant_overlay.h" |
19 #include "chrome/browser/instant/instant_tab.h" | 19 #include "chrome/browser/instant/instant_tab.h" |
20 #include "chrome/browser/platform_util.h" | 20 #include "chrome/browser/platform_util.h" |
21 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
23 #include "chrome/browser/ui/browser_instant_controller.h" | 23 #include "chrome/browser/ui/browser_instant_controller.h" |
| 24 #include "chrome/browser/ui/search/search.h" |
24 #include "chrome/browser/ui/search/search_tab_helper.h" | 25 #include "chrome/browser/ui/search/search_tab_helper.h" |
25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
28 #include "content/public/browser/navigation_entry.h" | 29 #include "content/public/browser/navigation_entry.h" |
29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/render_widget_host_view.h" | 31 #include "content/public/browser/render_widget_host_view.h" |
31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
32 #include "net/base/escape.h" | 33 #include "net/base/escape.h" |
33 #include "third_party/icu/public/common/unicode/normalizer2.h" | 34 #include "third_party/icu/public/common/unicode/normalizer2.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 return model.height() == 100 && model.height_units() == INSTANT_SIZE_PERCENT; | 159 return model.height() == 100 && model.height_units() == INSTANT_SIZE_PERCENT; |
159 } | 160 } |
160 | 161 |
161 bool IsContentsFrom(const InstantPage* page, | 162 bool IsContentsFrom(const InstantPage* page, |
162 const content::WebContents* contents) { | 163 const content::WebContents* contents) { |
163 return page && (page->contents() == contents); | 164 return page && (page->contents() == contents); |
164 } | 165 } |
165 | 166 |
166 } // namespace | 167 } // namespace |
167 | 168 |
168 // static | |
169 const char* InstantController::kLocalOmniboxPopupURL = | |
170 "chrome://local-omnibox-popup/local-omnibox-popup.html"; | |
171 | |
172 InstantController::InstantController(chrome::BrowserInstantController* browser, | 169 InstantController::InstantController(chrome::BrowserInstantController* browser, |
173 bool extended_enabled) | 170 bool extended_enabled) |
174 : browser_(browser), | 171 : browser_(browser), |
175 extended_enabled_(extended_enabled), | 172 extended_enabled_(extended_enabled), |
176 instant_enabled_(false), | 173 instant_enabled_(false), |
177 use_local_preview_only_(true), | 174 use_local_preview_only_(true), |
178 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 175 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
179 last_omnibox_text_has_inline_autocompletion_(false), | 176 last_omnibox_text_has_inline_autocompletion_(false), |
180 last_verbatim_(false), | 177 last_verbatim_(false), |
181 last_transition_type_(content::PAGE_TRANSITION_LINK), | 178 last_transition_type_(content::PAGE_TRANSITION_LINK), |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 instant_tab_->Update(user_text, selection_start, selection_end, verbatim); | 382 instant_tab_->Update(user_text, selection_start, selection_end, verbatim); |
386 } else { | 383 } else { |
387 if (first_interaction_time_.is_null()) | 384 if (first_interaction_time_.is_null()) |
388 first_interaction_time_ = base::Time::Now(); | 385 first_interaction_time_ = base::Time::Now(); |
389 allow_preview_to_show_search_suggestions_ = true; | 386 allow_preview_to_show_search_suggestions_ = true; |
390 | 387 |
391 // For extended mode, if the loader is not ready at this point, switch over | 388 // For extended mode, if the loader is not ready at this point, switch over |
392 // to a backup loader. | 389 // to a backup loader. |
393 if (extended_enabled_ && !overlay_->supports_instant() && | 390 if (extended_enabled_ && !overlay_->supports_instant() && |
394 !overlay_->IsUsingLocalPreview() && browser_->GetActiveWebContents()) { | 391 !overlay_->IsUsingLocalPreview() && browser_->GetActiveWebContents()) { |
395 CreateOverlay(kLocalOmniboxPopupURL, browser_->GetActiveWebContents()); | 392 CreateOverlay(chrome::search::kLocalOmniboxPopupURL, |
| 393 browser_->GetActiveWebContents()); |
396 } | 394 } |
397 | 395 |
398 overlay_->Update(extended_enabled_ ? user_text : full_text, | 396 overlay_->Update(extended_enabled_ ? user_text : full_text, |
399 selection_start, selection_end, verbatim); | 397 selection_start, selection_end, verbatim); |
400 } | 398 } |
401 | 399 |
402 content::NotificationService::current()->Notify( | 400 content::NotificationService::current()->Notify( |
403 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, | 401 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, |
404 content::Source<InstantController>(this), | 402 content::Source<InstantController>(this), |
405 content::NotificationService::NoDetails()); | 403 content::NotificationService::NoDetails()); |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 const content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1119 const content::WebContents* active_tab = browser_->GetActiveWebContents(); |
1122 if (!active_tab) | 1120 if (!active_tab) |
1123 return false; | 1121 return false; |
1124 | 1122 |
1125 Profile* profile = Profile::FromBrowserContext( | 1123 Profile* profile = Profile::FromBrowserContext( |
1126 active_tab->GetBrowserContext()); | 1124 active_tab->GetBrowserContext()); |
1127 std::string instant_url; | 1125 std::string instant_url; |
1128 if (!GetInstantURL(profile, ignore_blacklist, &instant_url)) { | 1126 if (!GetInstantURL(profile, ignore_blacklist, &instant_url)) { |
1129 // If we are in extended mode, fallback to the local popup. | 1127 // If we are in extended mode, fallback to the local popup. |
1130 if (extended_enabled_) | 1128 if (extended_enabled_) |
1131 instant_url = kLocalOmniboxPopupURL; | 1129 instant_url = chrome::search::kLocalOmniboxPopupURL; |
1132 else | 1130 else |
1133 return false; | 1131 return false; |
1134 } | 1132 } |
1135 | 1133 |
1136 if (!overlay_ || overlay_->instant_url() != instant_url) | 1134 if (!overlay_ || overlay_->instant_url() != instant_url) |
1137 CreateOverlay(instant_url, active_tab); | 1135 CreateOverlay(instant_url, active_tab); |
1138 | 1136 |
1139 return true; | 1137 return true; |
1140 } | 1138 } |
1141 | 1139 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 overlay_->SetPopupBounds(intersection); | 1287 overlay_->SetPopupBounds(intersection); |
1290 } | 1288 } |
1291 | 1289 |
1292 bool InstantController::GetInstantURL(Profile* profile, | 1290 bool InstantController::GetInstantURL(Profile* profile, |
1293 bool ignore_blacklist, | 1291 bool ignore_blacklist, |
1294 std::string* instant_url) const { | 1292 std::string* instant_url) const { |
1295 DCHECK(profile); | 1293 DCHECK(profile); |
1296 instant_url->clear(); | 1294 instant_url->clear(); |
1297 | 1295 |
1298 if (extended_enabled_ && use_local_preview_only_) { | 1296 if (extended_enabled_ && use_local_preview_only_) { |
1299 *instant_url = kLocalOmniboxPopupURL; | 1297 *instant_url = chrome::search::kLocalOmniboxPopupURL; |
1300 return true; | 1298 return true; |
1301 } | 1299 } |
1302 | 1300 |
1303 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( | 1301 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
1304 profile)->GetDefaultSearchProvider(); | 1302 profile)->GetDefaultSearchProvider(); |
1305 | 1303 |
1306 if (!template_url) { | 1304 if (!template_url) { |
1307 LOG_INSTANT_DEBUG_EVENT(this, "GetInstantURL: No template URL"); | 1305 LOG_INSTANT_DEBUG_EVENT(this, "GetInstantURL: No template URL"); |
1308 return false; | 1306 return false; |
1309 } | 1307 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 delete overlay_->ReleaseContents().release(); | 1396 delete overlay_->ReleaseContents().release(); |
1399 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); | 1397 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
1400 EnsureOverlayIsCurrent(false); | 1398 EnsureOverlayIsCurrent(false); |
1401 } | 1399 } |
1402 | 1400 |
1403 void InstantController::RemoveFromBlacklist(const std::string& url) { | 1401 void InstantController::RemoveFromBlacklist(const std::string& url) { |
1404 if (blacklisted_urls_.erase(url)) { | 1402 if (blacklisted_urls_.erase(url)) { |
1405 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); | 1403 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); |
1406 } | 1404 } |
1407 } | 1405 } |
OLD | NEW |