Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit.cc

Issue 7210020: Added prerendering to omnibox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More histograms/rebase Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/autocomplete/autocomplete_edit.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h"
10 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
15 #include "chrome/browser/autocomplete/autocomplete_match.h" 16 #include "chrome/browser/autocomplete/autocomplete_match.h"
16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
17 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" 18 #include "chrome/browser/autocomplete/autocomplete_popup_view.h"
18 #include "chrome/browser/autocomplete/keyword_provider.h" 19 #include "chrome/browser/autocomplete/keyword_provider.h"
19 #include "chrome/browser/autocomplete/search_provider.h" 20 #include "chrome/browser/autocomplete/search_provider.h"
20 #include "chrome/browser/command_updater.h" 21 #include "chrome/browser/command_updater.h"
21 #include "chrome/browser/extensions/extension_omnibox_api.h" 22 #include "chrome/browser/extensions/extension_omnibox_api.h"
22 #include "chrome/browser/google/google_url_tracker.h" 23 #include "chrome/browser/google/google_url_tracker.h"
23 #include "chrome/browser/instant/instant_controller.h" 24 #include "chrome/browser/instant/instant_controller.h"
24 #include "chrome/browser/net/predictor_api.h" 25 #include "chrome/browser/net/predictor_api.h"
25 #include "chrome/browser/net/url_fixer_upper.h" 26 #include "chrome/browser/net/url_fixer_upper.h"
27 #include "chrome/browser/prerender/prerender_manager.h"
26 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/search_engines/template_url.h" 29 #include "chrome/browser/search_engines/template_url.h"
28 #include "chrome/browser/search_engines/template_url_service.h" 30 #include "chrome/browser/search_engines/template_url_service.h"
29 #include "chrome/browser/search_engines/template_url_service_factory.h" 31 #include "chrome/browser/search_engines/template_url_service_factory.h"
30 #include "chrome/browser/ui/browser_list.h" 32 #include "chrome/browser/ui/browser_list.h"
31 #include "chrome/browser/ui/omnibox/omnibox_view.h" 33 #include "chrome/browser/ui/omnibox/omnibox_view.h"
32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 34 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
35 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/url_constants.h" 36 #include "chrome/common/url_constants.h"
34 #include "content/browser/user_metrics.h" 37 #include "content/browser/user_metrics.h"
35 #include "content/common/notification_service.h" 38 #include "content/common/notification_service.h"
36 #include "googleurl/src/gurl.h" 39 #include "googleurl/src/gurl.h"
37 #include "googleurl/src/url_util.h" 40 #include "googleurl/src/url_util.h"
38 #include "third_party/skia/include/core/SkBitmap.h" 41 #include "third_party/skia/include/core/SkBitmap.h"
39 42
40 /////////////////////////////////////////////////////////////////////////////// 43 ///////////////////////////////////////////////////////////////////////////////
41 // AutocompleteEditController 44 // AutocompleteEditController
42 45
(...skipping 29 matching lines...) Expand all
72 popup_(NULL), 75 popup_(NULL),
73 controller_(controller), 76 controller_(controller),
74 has_focus_(false), 77 has_focus_(false),
75 user_input_in_progress_(false), 78 user_input_in_progress_(false),
76 just_deleted_text_(false), 79 just_deleted_text_(false),
77 has_temporary_text_(false), 80 has_temporary_text_(false),
78 paste_state_(NONE), 81 paste_state_(NONE),
79 control_key_state_(UP), 82 control_key_state_(UP),
80 is_keyword_hint_(false), 83 is_keyword_hint_(false),
81 profile_(profile), 84 profile_(profile),
82 update_instant_(true), 85 in_revert_(false),
83 allow_exact_keyword_match_(false), 86 allow_exact_keyword_match_(false),
84 instant_complete_behavior_(INSTANT_COMPLETE_DELAYED) { 87 instant_complete_behavior_(INSTANT_COMPLETE_DELAYED) {
85 } 88 }
86 89
87 AutocompleteEditModel::~AutocompleteEditModel() { 90 AutocompleteEditModel::~AutocompleteEditModel() {
88 } 91 }
89 92
90 void AutocompleteEditModel::SetProfile(Profile* profile) { 93 void AutocompleteEditModel::SetProfile(Profile* profile) {
91 DCHECK(profile); 94 DCHECK(profile);
92 profile_ = profile; 95 profile_ = profile;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 209
207 bool AutocompleteEditModel::AcceptCurrentInstantPreview() { 210 bool AutocompleteEditModel::AcceptCurrentInstantPreview() {
208 return InstantController::CommitIfCurrent(controller_->GetInstant()); 211 return InstantController::CommitIfCurrent(controller_->GetInstant());
209 } 212 }
210 213
211 void AutocompleteEditModel::OnChanged() { 214 void AutocompleteEditModel::OnChanged() {
212 InstantController* instant = controller_->GetInstant(); 215 InstantController* instant = controller_->GetInstant();
213 string16 suggested_text; 216 string16 suggested_text;
214 TabContentsWrapper* tab = controller_->GetTabContentsWrapper(); 217 TabContentsWrapper* tab = controller_->GetTabContentsWrapper();
215 bool might_support_instant = false; 218 bool might_support_instant = false;
216 if (update_instant_ && instant && tab) { 219 if (!in_revert_ && tab) {
217 if (user_input_in_progress() && popup_->IsOpen()) { 220 if (instant) {
218 AutocompleteMatch current_match = CurrentMatch(); 221 if (user_input_in_progress() && popup_->IsOpen()) {
219 if (current_match.destination_url == PermanentURL()) { 222 AutocompleteMatch current_match = CurrentMatch();
220 // The destination is the same as the current url. This typically 223 if (current_match.destination_url == PermanentURL()) {
221 // happens if the user presses the down error in the omnibox, in which 224 // The destination is the same as the current url. This typically
222 // case we don't want to load a preview. 225 // happens if the user presses the down error in the omnibox, in which
223 instant->DestroyPreviewContentsAndLeaveActive(); 226 // case we don't want to load a preview.
227 instant->DestroyPreviewContentsAndLeaveActive();
228 } else {
229 instant->Update(tab, current_match, view_->GetText(),
230 UseVerbatimInstant(), &suggested_text);
231 }
224 } else { 232 } else {
225 instant->Update(tab, CurrentMatch(), view_->GetText(), 233 instant->DestroyPreviewContents();
226 UseVerbatimInstant(), &suggested_text);
227 } 234 }
228 } else { 235 might_support_instant = instant->MightSupportInstant();
229 instant->DestroyPreviewContents(); 236 } else if (user_input_in_progress() && popup_->IsOpen()) {
237 // Start Prerender of this page instead.
238 CommandLine* cl = CommandLine::ForCurrentProcess();
239 if (cl->HasSwitch(switches::kPrerenderFromOmnibox)) {
cbentzel 2011/06/22 17:27:32 Move the command-line check be moved into Prerende
dominich 2011/06/22 19:00:51 Done.
240 CHECK(tab->tab_contents());
241 prerender::PrerenderManager* prerender_manager =
242 tab->tab_contents()->profile()->GetPrerenderManager();
243 if (prerender_manager) {
244 prerender_manager->AddPrerenderWithNoTag(
245 prerender::ORIGIN_OMNIBOX,
246 CurrentMatch().destination_url);
247 }
248 }
230 } 249 }
231 might_support_instant = instant->MightSupportInstant();
232 } 250 }
233 251
234 if (!might_support_instant) { 252 if (!might_support_instant) {
235 // Hide any suggestions we might be showing. 253 // Hide any suggestions we might be showing.
236 view_->SetInstantSuggestion(string16(), false); 254 view_->SetInstantSuggestion(string16(), false);
237 255
238 // No need to wait any longer for instant. 256 // No need to wait any longer for instant.
239 FinalizeInstantQuery(string16(), string16(), false); 257 FinalizeInstantQuery(string16(), string16(), false);
240 } else { 258 } else {
241 SetSuggestedText(suggested_text, instant_complete_behavior_); 259 SetSuggestedText(suggested_text, instant_complete_behavior_);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 autocomplete_controller_->Start( 410 autocomplete_controller_->Start(
393 user_text_, GetDesiredTLD(), 411 user_text_, GetDesiredTLD(),
394 prevent_inline_autocomplete || just_deleted_text_ || 412 prevent_inline_autocomplete || just_deleted_text_ ||
395 (has_selected_text && inline_autocomplete_text_.empty()) || 413 (has_selected_text && inline_autocomplete_text_.empty()) ||
396 (paste_state_ != NONE), keyword_is_selected, 414 (paste_state_ != NONE), keyword_is_selected,
397 keyword_is_selected || allow_exact_keyword_match_, 415 keyword_is_selected || allow_exact_keyword_match_,
398 AutocompleteInput::ALL_MATCHES); 416 AutocompleteInput::ALL_MATCHES);
399 } 417 }
400 418
401 void AutocompleteEditModel::StopAutocomplete() { 419 void AutocompleteEditModel::StopAutocomplete() {
402 if (popup_->IsOpen() && update_instant_) { 420 if (popup_->IsOpen() && !in_revert_) {
403 InstantController* instant = controller_->GetInstant(); 421 InstantController* instant = controller_->GetInstant();
404 if (instant && !instant->commit_on_mouse_up()) 422 if (instant && !instant->commit_on_mouse_up())
405 instant->DestroyPreviewContents(); 423 instant->DestroyPreviewContents();
406 } 424 }
407 425
408 autocomplete_controller_->Stop(true); 426 autocomplete_controller_->Stop(true);
409 } 427 }
410 428
411 bool AutocompleteEditModel::CanPasteAndGo(const string16& text) const { 429 bool AutocompleteEditModel::CanPasteAndGo(const string16& text) const {
412 if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) 430 if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL))
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 if (template_url) { 545 if (template_url) {
528 UserMetrics::RecordAction(UserMetricsAction("AcceptedKeyword")); 546 UserMetrics::RecordAction(UserMetricsAction("AcceptedKeyword"));
529 template_url_service->IncrementUsageCount(template_url); 547 template_url_service->IncrementUsageCount(template_url);
530 } 548 }
531 549
532 // NOTE: We purposefully don't increment the usage count of the default 550 // NOTE: We purposefully don't increment the usage count of the default
533 // search engine, if applicable; see comments in template_url.h. 551 // search engine, if applicable; see comments in template_url.h.
534 } 552 }
535 553
536 if (disposition != NEW_BACKGROUND_TAB) { 554 if (disposition != NEW_BACKGROUND_TAB) {
537 update_instant_ = false; 555 in_revert_ = true;
538 view_->RevertAll(); // Revert the box to its unedited state 556 view_->RevertAll(); // Revert the box to its unedited state
539 } 557 }
540 558
541 if (match.type == AutocompleteMatch::EXTENSION_APP) { 559 if (match.type == AutocompleteMatch::EXTENSION_APP) {
542 LaunchAppFromOmnibox(match, profile_, disposition); 560 LaunchAppFromOmnibox(match, profile_, disposition);
543 } else { 561 } else {
544 controller_->OnAutocompleteAccept(match.destination_url, disposition, 562 controller_->OnAutocompleteAccept(match.destination_url, disposition,
545 match.transition, alternate_nav_url); 563 match.transition, alternate_nav_url);
546 } 564 }
547 565
548 InstantController* instant = controller_->GetInstant(); 566 InstantController* instant = controller_->GetInstant();
549 if (instant && !popup_->IsOpen()) 567 if (instant && !popup_->IsOpen())
550 instant->DestroyPreviewContents(); 568 instant->DestroyPreviewContents();
551 update_instant_ = true; 569 in_revert_ = false;
552 } 570 }
553 571
554 bool AutocompleteEditModel::AcceptKeyword() { 572 bool AutocompleteEditModel::AcceptKeyword() {
555 DCHECK(is_keyword_hint_ && !keyword_.empty()); 573 DCHECK(is_keyword_hint_ && !keyword_.empty());
556 574
557 view_->OnBeforePossibleChange(); 575 view_->OnBeforePossibleChange();
558 view_->SetWindowTextAndCaretPos(string16(), 0); 576 view_->SetWindowTextAndCaretPos(string16(), 0);
559 is_keyword_hint_ = false; 577 is_keyword_hint_ = false;
560 view_->OnAfterPossibleChange(); 578 view_->OnAfterPossibleChange();
561 just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this 579 just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 // static 1031 // static
1014 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { 1032 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) {
1015 switch (c) { 1033 switch (c) {
1016 case 0x0020: // Space 1034 case 0x0020: // Space
1017 case 0x3000: // Ideographic Space 1035 case 0x3000: // Ideographic Space
1018 return true; 1036 return true;
1019 default: 1037 default:
1020 return false; 1038 return false;
1021 } 1039 }
1022 } 1040 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698