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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 10809063: Adding Javascript support for the Extended Searchbox API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding missing file from last upload. Created 8 years, 4 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
OLDNEW
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_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/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 399
400 ResetLoader(instant_url, active_tab); 400 ResetLoader(instant_url, active_tab);
401 } 401 }
402 402
403 bool InstantController::commit_on_pointer_release() const { 403 bool InstantController::commit_on_pointer_release() const {
404 return GetPreviewContents() && loader_->IsPointerDownFromActivate(); 404 return GetPreviewContents() && loader_->IsPointerDownFromActivate();
405 } 405 }
406 406
407 void InstantController::SetSuggestions( 407 void InstantController::SetSuggestions(
408 InstantLoader* loader, 408 InstantLoader* loader,
409 const std::vector<string16>& suggestions, 409 const std::vector<InstantSuggestion>& suggestions) {
410 InstantCompleteBehavior behavior) {
411 DCHECK_EQ(loader_.get(), loader); 410 DCHECK_EQ(loader_.get(), loader);
412 if (loader_ != loader || IsOutOfDate() || mode_ == SILENT || mode_ == HIDDEN) 411 if (loader_ != loader || IsOutOfDate() || mode_ == SILENT || mode_ == HIDDEN)
413 return; 412 return;
414 413
415 loader_processed_last_update_ = true; 414 loader_processed_last_update_ = true;
416 415
417 string16 suggestion; 416 InstantSuggestion suggestion;
418 if (!suggestions.empty()) 417 if (!suggestions.empty())
419 suggestion = suggestions[0]; 418 suggestion = suggestions[0];
420 419
421 string16 suggestion_lower = base::i18n::ToLower(suggestion); 420 string16 suggestion_lower = base::i18n::ToLower(suggestion.text);
422 string16 user_text_lower = base::i18n::ToLower(last_user_text_); 421 string16 user_text_lower = base::i18n::ToLower(last_user_text_);
423 if (user_text_lower.size() >= suggestion_lower.size() || 422 if (user_text_lower.size() >= suggestion_lower.size() ||
424 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower)) { 423 suggestion_lower.compare(0, user_text_lower.size(), user_text_lower)) {
425 suggestion.clear(); 424 suggestion.text.clear();
426 } else { 425 } else {
427 suggestion.erase(0, last_user_text_.size()); 426 suggestion.text.erase(0, last_user_text_.size());
428 } 427 }
429 428
430 last_suggestion_ = suggestion; 429 last_suggestion_ = suggestion.text;
431 last_complete_behavior_ = behavior; 430 last_complete_behavior_ = suggestion.behavior;
432 if (!last_verbatim_) 431 if (!last_verbatim_)
433 delegate_->SetSuggestedText(suggestion, behavior); 432 delegate_->SetSuggestedText(suggestion.text, suggestion.behavior);
434 433
435 if (mode_ != SUGGEST) 434 if (mode_ != SUGGEST)
436 Show(); 435 Show();
437 } 436 }
438 437
439 void InstantController::CommitInstantLoader(InstantLoader* loader) { 438 void InstantController::CommitInstantLoader(InstantLoader* loader) {
440 DCHECK_EQ(loader_.get(), loader); 439 DCHECK_EQ(loader_.get(), loader);
441 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_; 440 DCHECK(is_showing_ && !IsOutOfDate()) << is_showing_;
442 if (loader_ != loader || !is_showing_ || IsOutOfDate()) 441 if (loader_ != loader || !is_showing_ || IsOutOfDate())
443 return; 442 return;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 return false; 579 return false;
581 } 580 }
582 581
583 return true; 582 return true;
584 } 583 }
585 584
586 bool InstantController::IsOutOfDate() const { 585 bool InstantController::IsOutOfDate() const {
587 return !last_active_tab_ || 586 return !last_active_tab_ ||
588 last_active_tab_ != delegate_->GetActiveTabContents(); 587 last_active_tab_ != delegate_->GetActiveTabContents();
589 } 588 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698