summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/generated_resources.grd12
-rw-r--r--chrome/browser/about_flags.cc13
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc40
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h11
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_unittest.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc1
-rw-r--r--chrome/browser/browser.cc2
-rw-r--r--chrome/browser/cocoa/location_bar/location_bar_view_mac.h1
-rw-r--r--chrome/browser/cocoa/location_bar/location_bar_view_mac.mm5
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc5
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h1
-rw-r--r--chrome/browser/instant/instant_controller.cc42
-rw-r--r--chrome/browser/instant/instant_controller.h19
-rw-r--r--chrome/browser/views/location_bar/location_bar_view.cc4
-rw-r--r--chrome/browser/views/location_bar/location_bar_view.h1
-rw-r--r--chrome/common/chrome_switches.cc9
-rw-r--r--chrome/common/chrome_switches.h4
18 files changed, 148 insertions, 25 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index f3baa3d..ba7c986 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -4034,11 +4034,17 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_TABBED_OPTIONS_DESCRIPTION" desc="Description of the 'Tabbed Settings' lab.">
Uses an in-tab UI for the Settings (Options/Preferences) dialog instead of a stand-alone window.
</message>
- <message name="IDS_FLAGS_INSTANT_NAME" desc="Description of the 'Instant' lab.">
+ <message name="IDS_FLAGS_PREDICTIVE_INSTANT_NAME" desc="Description of the predictive 'Instant' lab.">
Instant
</message>
- <message name="IDS_FLAGS_INSTANT_DESCRIPTION" desc="Description of the 'Instant' lab.">
- Makes the address bar load urls as you type.
+ <message name="IDS_FLAGS_PREDICTIVE_INSTANT_DESCRIPTION" desc="Description of the predictive 'Instant' lab.">
+ Makes the address bar load urls as you type. Search results are shown for the best match.
+ </message>
+ <message name="IDS_FLAGS_VERBATIM_INSTANT_NAME" desc="Description of the verbatim 'Instant' lab.">
+ Verbatim Instant
+ </message>
+ <message name="IDS_FLAGS_VERBATIM_INSTANT_DESCRIPTION" desc="Description of the verbatim 'Instant' lab.">
+ Makes the address bar load urls as you type. Search results are shown exactly as you typed them.
</message>
<message name="IDS_FLAGS_REMOTING_NAME" desc="Description of the 'Remoting' lab.">
Remoting
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 277177b..8f552e5 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -99,10 +99,17 @@ const Experiment kExperiments[] = {
},
{
"match-preview", // Do not change; see above.
- IDS_FLAGS_INSTANT_NAME,
- IDS_FLAGS_INSTANT_DESCRIPTION,
+ IDS_FLAGS_PREDICTIVE_INSTANT_NAME,
+ IDS_FLAGS_PREDICTIVE_INSTANT_DESCRIPTION,
kOsMac | kOsLinux,
- switches::kEnableMatchPreview
+ switches::kEnablePredictiveInstant
+ },
+ {
+ "verbatim-instant", // Do not change; see above.
+ IDS_FLAGS_VERBATIM_INSTANT_NAME,
+ IDS_FLAGS_VERBATIM_INSTANT_DESCRIPTION,
+ kOsMac | kOsLinux | kOsWin,
+ switches::kEnableVerbatimInstant
},
// FIXME(scheib): Add Flags entry for accelerated Compositing,
// or pull it and the strings in generated_resources.grd by Dec 2010
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 6505e6d..c86c8b0 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/command_updater.h"
#include "chrome/browser/extensions/extension_omnibox_api.h"
#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/net/predictor_api.h"
#include "chrome/browser/net/url_fixer_upper.h"
@@ -680,6 +681,10 @@ void AutocompleteEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) {
controller_->OnPopupBoundsChanged(bounds);
}
+void AutocompleteEditModel::ResultsUpdated() {
+ UpdateSuggestedSearchText();
+}
+
// Return true if the suggestion type warrants a TCP/IP preconnection.
// i.e., it is now highly likely that the user will select the related domain.
static bool IsPreconnectable(AutocompleteMatch::Type type) {
@@ -767,3 +772,38 @@ void AutocompleteEditModel::GetInfoForCurrentText(
alternate_nav_url);
}
}
+
+// Returns true if suggested search text should be shown for the specified match
+// type.
+static bool ShouldShowSuggestSearchTextFor(AutocompleteMatch::Type type) {
+ // TODO: add support for other engines when in keyword mode.
+ return ((type == AutocompleteMatch::SEARCH_HISTORY) ||
+ (type == AutocompleteMatch::SEARCH_SUGGEST));
+}
+
+void AutocompleteEditModel::UpdateSuggestedSearchText() {
+ if (!InstantController::IsEnabled(profile_, InstantController::VERBATIM_TYPE))
+ return;
+
+ string16 suggested_text;
+ // The suggested text comes from the first search result.
+ if (popup_->IsOpen()) {
+ const AutocompleteResult& result = popup_->result();
+ if ((result.size() > 1) && (popup_->selected_line() == 0) &&
+ ((result.begin()->inline_autocomplete_offset == std::wstring::npos) ||
+ (result.begin()->inline_autocomplete_offset ==
+ result.begin()->fill_into_edit.size()))) {
+ for (AutocompleteResult::const_iterator i = result.begin() + 1;
+ i != result.end(); ++i) {
+ // TODO: add support for other engines when in keyword mode.
+ if (ShouldShowSuggestSearchTextFor(i->type) &&
+ i->inline_autocomplete_offset != std::wstring::npos) {
+ suggested_text = WideToUTF16(i->fill_into_edit.substr(
+ i->inline_autocomplete_offset));
+ break;
+ }
+ }
+ }
+ }
+ controller_->OnSetSuggestedSearchText(suggested_text);
+}
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index 99f5e80..9e94172 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_
#pragma once
+#include "base/string16.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
@@ -49,6 +50,9 @@ class AutocompleteEditController {
// autocomplete. Returns true if the text was committed.
virtual bool OnCommitSuggestedText(const std::wstring& typed_text) = 0;
+ // Sets the suggested search text to |suggested_text|.
+ virtual void OnSetSuggestedSearchText(const string16& suggested_text) = 0;
+
// Invoked when the popup is going to change its bounds to |bounds|.
virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) = 0;
@@ -319,6 +323,9 @@ class AutocompleteEditModel : public NotificationObserver {
// Invoked when the popup is going to change its bounds to |bounds|.
void PopupBoundsChangedTo(const gfx::Rect& bounds);
+ // Invoked when the autocomplete results may have changed in some way.
+ void ResultsUpdated();
+
private:
enum PasteState {
NONE, // Most recent edit was not a paste that replaced all text.
@@ -368,6 +375,10 @@ class AutocompleteEditModel : public NotificationObserver {
void GetInfoForCurrentText(AutocompleteMatch* match,
GURL* alternate_nav_url) const;
+ // Determines the suggested search text and invokes OnSetSuggestedSearchText
+ // on the controller.
+ void UpdateSuggestedSearchText();
+
AutocompleteEditView* view_;
AutocompletePopupModel* popup_;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
index 6451fa6..b0941ad 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
@@ -67,6 +67,7 @@ class TestingAutocompleteEditController : public AutocompleteEditController {
virtual bool OnCommitSuggestedText(const std::wstring& typed_text) {
return false;
}
+ virtual void OnSetSuggestedSearchText(const string16& suggested_text) {}
virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) {}
virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 422aadd6..cf7103e 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -1026,7 +1026,7 @@ void AutocompleteEditViewGtk::HandleViewMoveCursor(
g_object_get(G_OBJECT(text_buffer_), "cursor-position", &cursor_pos,
NULL);
if (cursor_pos == gtk_text_buffer_get_char_count(text_buffer_))
- controller_->OnCommitSuggestedText(std::wstring());
+ controller_->OnCommitSuggestedText(GetText());
else
handled = false;
} else {
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
index 5b8f814..774acd0 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -293,6 +293,7 @@ void AutocompletePopupModel::Observe(NotificationType type,
SetHoveredLine(kNoMatch);
view_->UpdatePopupAppearance();
+ edit_model_->ResultsUpdated();
edit_model_->PopupBoundsChangedTo(view_->GetTargetBounds());
}
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index b238ce6..d772a5e 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -4310,6 +4310,6 @@ bool Browser::OpenInstant(WindowOpenDisposition disposition) {
void Browser::CreateInstantIfNecessary() {
if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) &&
!profile()->IsOffTheRecord()) {
- instant_.reset(new InstantController(this));
+ instant_.reset(new InstantController(profile_, this));
}
}
diff --git a/chrome/browser/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar/location_bar_view_mac.h
index b24e951..687cb1a 100644
--- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.h
+++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.h
@@ -133,6 +133,7 @@ class LocationBarViewMac : public AutocompleteEditController,
virtual void OnAutocompleteLosingFocus(gfx::NativeView unused);
virtual void OnAutocompleteWillAccept();
virtual bool OnCommitSuggestedText(const std::wstring& typed_text);
+ virtual void OnSetSuggestedSearchText(const string16& suggested_text);
virtual void OnPopupBoundsChanged(const gfx::Rect& bounds);
virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
diff --git a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
index 82791c2..d2404ac 100644
--- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm
@@ -249,6 +249,11 @@ bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) {
return false;
}
+void LocationBarViewMac::OnSetSuggestedSearchText(
+ const string16& suggested_text) {
+ SetSuggestedText(suggested_text);
+}
+
void LocationBarViewMac::OnPopupBoundsChanged(const gfx::Rect& bounds) {
InstantController* instant = browser_->instant();
if (instant)
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 89a0d2d..325ff7b 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -467,6 +467,11 @@ bool LocationBarViewGtk::OnCommitSuggestedText(
return rv;
}
+void LocationBarViewGtk::OnSetSuggestedSearchText(
+ const string16& suggested_text) {
+ SetSuggestedText(suggested_text);
+}
+
void LocationBarViewGtk::OnPopupBoundsChanged(const gfx::Rect& bounds) {
InstantController* instant = browser_->instant();
if (instant)
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index 719aec3..0759549 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -93,6 +93,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
virtual void OnAutocompleteWillAccept();
// For this implementation, the parameter is ignored.
virtual bool OnCommitSuggestedText(const std::wstring& typed_text);
+ virtual void OnSetSuggestedSearchText(const string16& suggested_text);
virtual void OnPopupBoundsChanged(const gfx::Rect& bounds);
virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index 74df04c..8fd4746 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -32,23 +32,35 @@ void InstantController::RegisterUserPrefs(PrefService* prefs) {
// static
bool InstantController::IsEnabled(Profile* profile) {
- static bool enabled = false;
- static bool checked = false;
- if (!checked) {
- checked = true;
- enabled = CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableMatchPreview);
+ return IsEnabled(profile, PREDICTIVE_TYPE) ||
+ IsEnabled(profile, VERBATIM_TYPE);
+}
+
+// static
+bool InstantController::IsEnabled(Profile* profile, Type type) {
+ CommandLine* cl = CommandLine::ForCurrentProcess();
+ if (type == PREDICTIVE_TYPE) {
+ return (cl->HasSwitch(switches::kEnablePredictiveInstant) ||
+ (profile->GetPrefs() &&
+ profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)));
}
- PrefService* prefs = profile->GetPrefs();
- return (enabled || (prefs && prefs->GetBoolean(prefs::kInstantEnabled)));
+ return cl->HasSwitch(switches::kEnableVerbatimInstant);
+}
+
+static InstantController::Type GetType(Profile* profile) {
+ return InstantController::IsEnabled(profile,
+ InstantController::PREDICTIVE_TYPE) ?
+ InstantController::PREDICTIVE_TYPE : InstantController::VERBATIM_TYPE;
}
-InstantController::InstantController(InstantDelegate* delegate)
+InstantController::InstantController(Profile* profile,
+ InstantDelegate* delegate)
: delegate_(delegate),
tab_contents_(NULL),
is_active_(false),
commit_on_mouse_up_(false),
- last_transition_type_(PageTransition::LINK) {
+ last_transition_type_(PageTransition::LINK),
+ type_(GetType(profile)) {
}
InstantController::~InstantController() {
@@ -367,6 +379,16 @@ void InstantController::ClearBlacklist() {
const TemplateURL* InstantController::GetTemplateURL(
const AutocompleteMatch& match) {
+ if (type_ == VERBATIM_TYPE) {
+ // When using VERBATIM_TYPE we don't want to attempt to use the instant
+ // JavaScript API, otherwise the page would show predictive results. By
+ // returning NULL here we ensure we don't attempt to use the instant API.
+ //
+ // TODO: when the full search box API is in place we can lift this
+ // restriction and force the page to show verbatim results always.
+ return NULL;
+ }
+
const TemplateURL* template_url = match.template_url;
if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED ||
match.type == AutocompleteMatch::SEARCH_HISTORY ||
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index 396ce6d..009340b 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -38,15 +38,28 @@ class TemplateURL;
// being invoked on the delegate.
class InstantController : public InstantLoaderDelegate {
public:
- explicit InstantController(InstantDelegate* delegate);
+ // Variations of instant support.
+ enum Type {
+ // Search results are shown for the best guess of what we think the user was
+ // planning on typing.
+ PREDICTIVE_TYPE,
+
+ // Search results are shown for exactly what was typed.
+ VERBATIM_TYPE,
+ };
+
+ InstantController(Profile* profile, InstantDelegate* delegate);
~InstantController();
// Registers instant related preferences.
static void RegisterUserPrefs(PrefService* prefs);
- // Is InstantController enabled?
+ // Returns true if either type of instant is enabled.
static bool IsEnabled(Profile* profile);
+ // Returns true if the specified type of instant is enabled.
+ static bool IsEnabled(Profile* profile, Type type);
+
// Invoked as the user types in the omnibox with the url to navigate to. If
// the url is empty and there is a preview TabContents it is destroyed. If url
// is non-empty and the preview TabContents has not been created it is
@@ -195,6 +208,8 @@ class InstantController : public InstantLoaderDelegate {
// URL last pased to ScheduleUpdate.
GURL scheduled_url_;
+ const Type type_;
+
DISALLOW_COPY_AND_ASSIGN(InstantController);
};
diff --git a/chrome/browser/views/location_bar/location_bar_view.cc b/chrome/browser/views/location_bar/location_bar_view.cc
index defe0324..7aaf279 100644
--- a/chrome/browser/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/views/location_bar/location_bar_view.cc
@@ -757,6 +757,10 @@ bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) {
return true;
}
+void LocationBarView::OnSetSuggestedSearchText(const string16& suggested_text) {
+ SetSuggestedText(suggested_text);
+}
+
void LocationBarView::OnPopupBoundsChanged(const gfx::Rect& bounds) {
InstantController* instant = delegate_->GetInstant();
if (instant)
diff --git a/chrome/browser/views/location_bar/location_bar_view.h b/chrome/browser/views/location_bar/location_bar_view.h
index ce70a0c9..019e7a1 100644
--- a/chrome/browser/views/location_bar/location_bar_view.h
+++ b/chrome/browser/views/location_bar/location_bar_view.h
@@ -183,6 +183,7 @@ class LocationBarView : public LocationBar,
virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus);
virtual void OnAutocompleteWillAccept();
virtual bool OnCommitSuggestedText(const std::wstring& typed_text);
+ virtual void OnSetSuggestedSearchText(const string16& suggested_text);
virtual void OnPopupBoundsChanged(const gfx::Rect& bounds);
virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 1098878..8d55f4a 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -435,9 +435,6 @@ const char kEnableGPURendering[] = "enable-gpu-rendering";
// builds.
const char kEnableLogging[] = "enable-logging";
-// Is match preview enabled?
-const char kEnableMatchPreview[] = "enable-match-preview";
-
// Allows reporting memory info (JS heap size) to page.
const char kEnableMemoryInfo[] = "enable-memory-info";
@@ -456,6 +453,9 @@ const char kEnableNaClDebug[] = "enable-nacl-debug";
// Enable Native Web Worker support.
const char kEnableNativeWebWorkers[] = "enable-native-web-workers";
+// Is the predictive varition of instant enabled?
+const char kEnablePredictiveInstant[] = "enable-predictive-instant";
+
// This applies only when the process type is "service". Enables the
// Chromoting Host Process within the service process.
const char kEnableRemoting[] = "enable-remoting";
@@ -508,6 +508,9 @@ const char kEnableTopSites[] = "enable-top-sites";
// Whether or not the touch events API is exposed.
const char kEnableTouch[] = "enable-touch";
+// Is verbatim instant enabled?
+const char kEnableVerbatimInstant[] = "enable-verbatim-instant";
+
// Enables the option to show tabs as a vertical stack down the side of the
// browser window.
const char kEnableVerticalTabs[] = "enable-vertical-tabs";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 4dff38b..77806dc 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -134,13 +134,13 @@ extern const char kEnableGPUPlugin[];
extern const char kEnableGPURendering[];
extern const char kEnableIPv6[];
extern const char kEnableLogging[];
-extern const char kEnableMatchPreview[];
extern const char kEnableMemoryInfo[];
extern const char kEnableMonitorProfile[];
extern const char kEnableNaCl[];
extern const char kEnableNaClDebug[];
extern const char kEnableNativeWebWorkers[];
extern const char kEnablePreconnect[];
+extern const char kEnablePredictiveInstant[];
extern const char kEnablePreparsedJsCaching[];
extern const char kEnablePrintPreview[];
extern const char kEnableRemoting[];
@@ -155,9 +155,9 @@ extern const char kEnableSyncSessions[];
extern const char kEnableSyncTypedUrls[];
extern const char kEnableTabbedOptions[];
extern const char kEnableTcpFastOpen[];
-
extern const char kEnableTopSites[];
extern const char kEnableTouch[];
+extern const char kEnableVerbatimInstant[];
extern const char kEnableVerticalTabs[];
extern const char kEnableVideoFullscreen[];
extern const char kEnableVideoLayering[];