diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 19:13:49 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 19:13:49 +0000 |
commit | 57ad7b8c12ccd03ec3b273a423608b66ea40da62 (patch) | |
tree | ace0353f5c3e85558acb3e5ab3272d2eba984fcb /chrome/browser | |
parent | b1761521ffef79bdcd8335a64383f591b8a750e4 (diff) | |
download | chromium_src-57ad7b8c12ccd03ec3b273a423608b66ea40da62.zip chromium_src-57ad7b8c12ccd03ec3b273a423608b66ea40da62.tar.gz chromium_src-57ad7b8c12ccd03ec3b273a423608b66ea40da62.tar.bz2 |
Provides API for passing in whether verbatim or predictive should be
used when updating instant. I haven't wired this up to anything yet,
so this doesn't change the actual behavior of anything.
BUG=59217
TEST=none
Review URL: http://codereview.chromium.org/5187001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66654 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/location_bar/location_bar_view_mac.mm | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 28 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 7 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 30 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.h | 6 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 6 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 3 | ||||
-rw-r--r-- | chrome/browser/ui/views/location_bar/location_bar_view.cc | 1 |
9 files changed, 64 insertions, 19 deletions
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 6396115..95edc30 100644 --- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm @@ -317,6 +317,7 @@ void LocationBarViewMac::OnChanged() { instant->Update(browser_->GetSelectedTabContentsWrapper(), edit_view_->model()->CurrentMatch(), WideToUTF16(edit_view_->GetText()), + false, // TODO: make this real &suggested_text); } else { if (instant->is_active()) diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 05fefc3e..65d749d 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -539,6 +539,7 @@ void LocationBarViewGtk::OnChanged() { instant->Update(browser_->GetSelectedTabContentsWrapper(), location_entry_->model()->CurrentMatch(), WideToUTF16(location_entry_->GetText()), + false, // TODO: make this real &suggested_text); } else { instant->DestroyPreviewContents(); diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index c6587fa..5f7d4b6 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -159,6 +159,7 @@ void InstantController::Disable(Profile* profile) { void InstantController::Update(TabContentsWrapper* tab_contents, const AutocompleteMatch& match, const string16& user_text, + bool verbatim, string16* suggested_text) { if (tab_contents != tab_contents_) DestroyPreviewContents(); @@ -169,17 +170,25 @@ void InstantController::Update(TabContentsWrapper* tab_contents, commit_on_mouse_up_ = false; last_transition_type_ = match.transition; - if (loader_manager_.get() && loader_manager_->active_loader()->url() == url) - return; + const TemplateURL* template_url = GetTemplateURL(match); + TemplateURLID template_url_id = template_url ? template_url->id() : 0; + // Verbatim only makes sense if the search engines supports instant. + bool real_verbatim = template_url_id ? verbatim : false; + + if (loader_manager_.get()) { + InstantLoader* active_loader = loader_manager_->active_loader(); + if (active_loader->url() == url && + active_loader->template_url_id() == template_url_id && + (!template_url_id || active_loader->verbatim() == real_verbatim)) { + return; + } + } if (url.is_empty() || !url.is_valid() || !ShouldShowPreviewFor(match)) { DestroyPreviewContents(); return; } - const TemplateURL* template_url = GetTemplateURL(match); - TemplateURLID template_url_id = template_url ? template_url->id() : 0; - if (!loader_manager_.get()) loader_manager_.reset(new InstantLoaderManager(this)); @@ -188,7 +197,7 @@ void InstantController::Update(TabContentsWrapper* tab_contents, if (ShouldUpdateNow(template_url_id, match.destination_url)) { UpdateLoader(template_url, match.destination_url, match.transition, - user_text, suggested_text); + user_text, real_verbatim, suggested_text); } else { ScheduleUpdate(match.destination_url); } @@ -394,7 +403,7 @@ void InstantController::InstantLoaderDoesntSupportInstant( if (needs_reload) { string16 suggested_text; loader->Update(tab_contents_, 0, url_to_load, last_transition_type_, - loader->user_text(), &suggested_text); + loader->user_text(), false, &suggested_text); } } else { loader_manager_->DestroyLoader(loader); @@ -444,7 +453,7 @@ void InstantController::ProcessScheduledUpdate() { // We only delay loading of sites that don't support instant, so we can ignore // suggested_text here. string16 suggested_text; - UpdateLoader(NULL, scheduled_url_, last_transition_type_, string16(), + UpdateLoader(NULL, scheduled_url_, last_transition_type_, string16(), false, &suggested_text); } @@ -452,6 +461,7 @@ void InstantController::UpdateLoader(const TemplateURL* template_url, const GURL& url, PageTransition::Type transition_type, const string16& user_text, + bool verbatim, string16* suggested_text) { update_timer_.Stop(); @@ -463,7 +473,7 @@ void InstantController::UpdateLoader(const TemplateURL* template_url, new_loader->SetOmniboxBounds(omnibox_bounds_); new_loader->Update(tab_contents_, template_url, url, transition_type, - user_text, suggested_text); + user_text, verbatim, suggested_text); if (old_loader != new_loader && new_loader->ready()) delegate_->ShowInstant(new_loader->preview_contents()); } diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index f4e464c..5e268a9 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -77,10 +77,14 @@ class InstantController : public InstantLoaderDelegate { // 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 - // created. + // 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, const AutocompleteMatch& match, const string16& user_text, + bool verbatim, string16* suggested_text); // Sets the bounds of the omnibox (in screen coordinates). The bounds are @@ -172,6 +176,7 @@ class InstantController : public InstantLoaderDelegate { const GURL& url, PageTransition::Type transition_type, const string16& user_text, + bool verbatim, string16* suggested_text); // Returns true if we should show preview for |match|. diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 30c8ba6..596f22e 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -48,9 +48,12 @@ const int kUpdateBoundsDelayMS = 500; // instant after it has loaded. class InstantLoader::FrameLoadObserver : public NotificationObserver { public: - FrameLoadObserver(TabContents* tab_contents, const string16& text) + FrameLoadObserver(TabContents* tab_contents, + const string16& text, + bool verbatim) : tab_contents_(tab_contents), text_(text), + verbatim_(verbatim), unique_id_(tab_contents_->controller().pending_entry()->unique_id()) { registrar_.Add(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME, Source<TabContents>(tab_contents_)); @@ -59,6 +62,9 @@ class InstantLoader::FrameLoadObserver : public NotificationObserver { // Sets the text to send to the page. void set_text(const string16& text) { text_ = text; } + // Sets whether verbatim results are obtained rather than predictive. + void set_verbatim(bool verbatim) { verbatim_ = verbatim; } + // NotificationObserver: virtual void Observe(NotificationType type, const NotificationSource& source, @@ -73,7 +79,7 @@ class InstantLoader::FrameLoadObserver : public NotificationObserver { return; } tab_contents_->render_view_host()->DetermineIfPageSupportsInstant( - text_); + text_, verbatim_); break; } default: @@ -89,6 +95,9 @@ class InstantLoader::FrameLoadObserver : public NotificationObserver { // Text to send down to the page. string16 text_; + // Whether verbatim results are obtained. + bool verbatim_; + // unique_id of the NavigationEntry we're waiting on. const int unique_id_; @@ -396,8 +405,9 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents, const GURL& url, PageTransition::Type transition_type, const string16& user_text, + bool verbatim, string16* suggested_text) { - if (url_ == url) + if (url_ == url && verbatim == verbatim_) return; DCHECK(!url.is_empty() && url.is_valid()); @@ -405,6 +415,7 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents, last_transition_type_ = transition_type; url_ = url; user_text_ = user_text; + verbatim_ = verbatim; bool created_preview_contents; if (preview_contents_.get() == NULL) { @@ -453,16 +464,18 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents, if (is_waiting_for_load()) { // The page hasn't loaded yet. We'll send the script down when it does. frame_load_observer_->set_text(user_text_); + frame_load_observer_->set_verbatim(verbatim); preview_tab_contents_delegate_->set_user_typed_before_load(); return; } preview_contents_->render_view_host()->SearchBoxChange( - user_text_, false, 0, 0); + user_text_, verbatim, 0, 0); string16 complete_suggested_text_lower = l10n_util::ToLower( complete_suggested_text_); string16 user_text_lower = l10n_util::ToLower(user_text_); - if (complete_suggested_text_lower.size() > user_text_lower.size() && + if (!verbatim && + complete_suggested_text_lower.size() > user_text_lower.size() && !complete_suggested_text_lower.compare(0, user_text_lower.size(), user_text_lower)) { *suggested_text = complete_suggested_text_.substr(user_text_.size()); @@ -487,7 +500,7 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents, instant_url, GURL(), transition_type); frame_load_observer_.reset( new FrameLoadObserver(preview_contents()->tab_contents(), - user_text_)); + user_text_, verbatim)); } } else { DCHECK(template_url_id_ == 0); @@ -593,6 +606,11 @@ void InstantLoader::SetCompleteSuggestedText( if (complete_suggested_text == complete_suggested_text_) return; + if (verbatim_) { + // Don't show suggest results for verbatim queries. + return; + } + string16 user_text_lower = l10n_util::ToLower(user_text_); string16 complete_suggested_text_lower = l10n_util::ToLower( complete_suggested_text); diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index 223fffb..bfd3bfd 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -46,6 +46,7 @@ class InstantLoader : public NotificationObserver { const GURL& url, PageTransition::Type transition_type, const string16& user_text, + bool verbatim, string16* suggested_text); // Sets the bounds of the omnibox (in screen coordinates). The bounds are @@ -84,6 +85,8 @@ class InstantLoader : public NotificationObserver { const GURL& url() const { return url_; } + bool verbatim() const { return verbatim_; } + // Are we showing instant results? bool is_showing_instant() const { return template_url_id_ != 0; } @@ -176,6 +179,9 @@ class InstantLoader : public NotificationObserver { // Used to get notifications about renderers coming and going. NotificationRegistrar registrar_; + // Last value of verbatim passed to |Update|. + bool verbatim_; + DISALLOW_COPY_AND_ASSIGN(InstantLoader); }; diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 4dd8a10..c2a8360 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -2054,8 +2054,10 @@ void RenderViewHost::SearchBoxResize(const gfx::Rect& search_box_bounds) { Send(new ViewMsg_SearchBoxResize(routing_id(), search_box_bounds)); } -void RenderViewHost::DetermineIfPageSupportsInstant(const string16& value) { - Send(new ViewMsg_DetermineIfPageSupportsInstant(routing_id(), value)); +void RenderViewHost::DetermineIfPageSupportsInstant(const string16& value, + bool verbatim) { + Send(new ViewMsg_DetermineIfPageSupportsInstant(routing_id(), value, + verbatim)); } void RenderViewHost::OnExtensionPostMessage( diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index eb2233d..077f7ea 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -511,7 +511,8 @@ class RenderViewHost : public RenderWidgetHost { bool verbatim); void SearchBoxCancel(); void SearchBoxResize(const gfx::Rect& search_box_bounds); - void DetermineIfPageSupportsInstant(const string16& value); + void DetermineIfPageSupportsInstant(const string16& value, + bool verbatim); #if defined(UNIT_TEST) // These functions shouldn't be necessary outside of testing. diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 59c191d..655a7b2 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -853,6 +853,7 @@ void LocationBarView::OnChanged() { instant->Update(GetTabContentsWrapper(), location_entry_->model()->CurrentMatch(), WideToUTF16(location_entry_->GetText()), + false, // TODO: make this real &suggested_text); } else { instant->DestroyPreviewContents(); |