summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc33
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h7
-rw-r--r--chrome/browser/instant/instant_controller.cc21
-rw-r--r--chrome/browser/instant/instant_controller.h5
4 files changed, 35 insertions, 31 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 97e7d0c..b4950e8 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -217,8 +217,9 @@ void AutocompleteEditModel::OnChanged() {
network_action_predictor_.RecommendAction(user_text_, current_match);
UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action", recommended_action,
NetworkActionPredictor::LAST_PREDICT_ACTION);
- if (!DoInstant(current_match, &suggested_text)) {
- // Ignore the recommended action if the flag is not set.
+ bool might_support_instant = false;
+ if (!DoInstant(current_match, &suggested_text, &might_support_instant)) {
+ // Ignore the recommended action if Omnibox prerendering is not enabled.
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kPrerenderFromOmnibox)) {
recommended_action = NetworkActionPredictor::ACTION_NONE;
@@ -237,7 +238,9 @@ void AutocompleteEditModel::OnChanged() {
NOTREACHED() << "Unexpected recommended action: " << recommended_action;
break;
}
+ }
+ if (!might_support_instant) {
// Hide any suggestions we might be showing.
view_->SetInstantSuggestion(string16(), false);
@@ -978,8 +981,12 @@ bool AutocompleteEditModel::ShouldAllowExactKeywordMatch(
}
bool AutocompleteEditModel::DoInstant(const AutocompleteMatch& match,
- string16* suggested_text) {
+ string16* suggested_text,
+ bool* might_support_instant) {
DCHECK(suggested_text);
+ DCHECK(might_support_instant);
+
+ *might_support_instant = false;
if (in_revert_)
return false;
@@ -991,6 +998,7 @@ bool AutocompleteEditModel::DoInstant(const AutocompleteMatch& match,
TabContentsWrapper* tab = controller_->GetTabContentsWrapper();
+ bool instant_is_active = false;
if (user_input_in_progress() && popup_->IsOpen()) {
if (match.destination_url == PermanentURL()) {
// The destination is the same as the current url. This typically
@@ -998,25 +1006,28 @@ bool AutocompleteEditModel::DoInstant(const AutocompleteMatch& match,
// case we don't want to load a preview.
instant->DestroyPreviewContentsAndLeaveActive();
} else {
- instant->Update(tab, match, view_->GetText(), UseVerbatimInstant(),
- suggested_text);
+ instant_is_active = instant->Update(tab, match, view_->GetText(),
+ UseVerbatimInstant(), suggested_text);
}
} else {
instant->DestroyPreviewContents();
}
- return instant->MightSupportInstant();
+ *might_support_instant = instant->MightSupportInstant();
+ return instant_is_active;
}
void AutocompleteEditModel::DoPrerender(const AutocompleteMatch& match) {
// Do not prerender if the destination URL is the same as the current URL.
if (match.destination_url == PermanentURL())
return;
- TabContentsWrapper* tab = controller_->GetTabContentsWrapper();
- prerender::PrerenderManager* prerender_manager =
- tab->profile()->GetPrerenderManager();
- if (prerender_manager)
- prerender_manager->AddPrerenderFromOmnibox(match.destination_url);
+ if (user_input_in_progress() && popup_->IsOpen()) {
+ TabContentsWrapper* tab = controller_->GetTabContentsWrapper();
+ prerender::PrerenderManager* prerender_manager =
+ tab->profile()->GetPrerenderManager();
+ if (prerender_manager)
+ prerender_manager->AddPrerenderFromOmnibox(match.destination_url);
+ }
}
void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index ff92b70..b31b2a6 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -423,8 +423,11 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate {
size_t caret_position);
// Tries to start an instant preview for |match|. Returns true if instant is
- // supported. |suggested_text| must be non-NULL.
- bool DoInstant(const AutocompleteMatch& match, string16* suggested_text);
+ // showing and sets |might_support_instant| to true if instant is supported.
+ // |suggested_text| and |might_support_instant| must be non-NULL.
+ bool DoInstant(const AutocompleteMatch& match,
+ string16* suggested_text,
+ bool* might_support_instant);
// Starts a prerender for the given |match|.
void DoPrerender(const AutocompleteMatch& match);
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index c7dd79b..832a2d7 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -17,7 +17,6 @@
#include "chrome/browser/instant/promo_counter.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
@@ -176,7 +175,7 @@ bool InstantController::CommitIfCurrent(InstantController* controller) {
return false;
}
-void InstantController::Update(TabContentsWrapper* tab_contents,
+bool InstantController::Update(TabContentsWrapper* tab_contents,
const AutocompleteMatch& match,
const string16& user_text,
bool verbatim,
@@ -195,26 +194,15 @@ void InstantController::Update(TabContentsWrapper* tab_contents,
if (url.is_empty() || !url.is_valid()) {
// Assume we were invoked with GURL() and should destroy all.
DestroyPreviewContents();
- return;
+ return false;
}
PreviewCondition preview_condition = GetPreviewConditionFor(match,
&template_url);
- if (preview_condition == PREVIEW_CONDITION_SUCCESS) {
- // Do nothing if we should show it.
- } else if (preview_condition == PREVIEW_CONDITION_INSTANT_SEARCH_ONLY) {
- // Start Prerender of this page instead.
- prerender::PrerenderManager* prerender_manager =
- tab_contents_->profile()->GetPrerenderManager();
- if (prerender_manager)
- prerender_manager->AddPrerenderFromOmnibox(match.destination_url);
-
- DestroyPreviewContentsAndLeaveActive();
- return;
- } else {
+ if (preview_condition != PREVIEW_CONDITION_SUCCESS) {
// Just destroy the preview and cancel the update.
DestroyPreviewContentsAndLeaveActive();
- return;
+ return false;
}
if (!loader_manager_.get())
@@ -240,6 +228,7 @@ void InstantController::Update(TabContentsWrapper* tab_contents,
chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED,
Source<InstantController>(this),
NotificationService::NoDetails());
+ return true;
}
void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) {
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index 591d0f3..36ab76f 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -78,8 +78,9 @@ class InstantController : public InstantLoaderDelegate {
// created. If |verbatim| is true search results are shown for |user_text|
// rather than the best guess as to what the search thought the user meant.
// |verbatim| only matters if the AutocompleteMatch is for a search engine
- // that supports instant.
- void Update(TabContentsWrapper* tab_contents,
+ // that supports instant. Returns true if the attempt to update does not
+ // result in the preview TabContents being destroyed.
+ bool Update(TabContentsWrapper* tab_contents,
const AutocompleteMatch& match,
const string16& user_text,
bool verbatim,