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

Unified Diff: chrome/browser/instant/instant_controller.h

Issue 11421079: Persist the Instant API to committed search result pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Kittens live! Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/instant/instant_controller.h
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index 436f9866560268177df9731e72a553709fb0e405..5830643e731b1ee58f7b220e76cb0334df918914 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -27,14 +27,18 @@
struct AutocompleteMatch;
class AutocompleteProvider;
class InstantLoader;
-class TabContents;
+class InstantTab;
class TemplateURL;
-struct ThemeBackgroundInfo;
+
namespace chrome {
class BrowserInstantController;
}
+namespace content {
+class WebContents;
+}
+
// InstantController maintains a WebContents that is intended to give a preview
// of search suggestions and results. InstantController is owned by Browser via
// BrowserInstantController.
@@ -69,10 +73,10 @@ class InstantController {
// handled the key press.
bool OnUpOrDownKeyPressed(int count);
- // The preview TabContents. May be NULL if ReleasePreviewContents() has been
- // called, with no subsequent successful call to Update(). InstantController
- // retains ownership of the object.
- TabContents* GetPreviewContents() const;
+ // The preview WebContents. May be NULL if CommitIfCurrent() has been called,
+ // with no subsequent successful call to Update(). InstantController retains
+ // ownership of the object.
+ content::WebContents* GetPreviewContents() const;
// Returns true if the Instant preview can be committed now.
bool IsCurrent() const;
@@ -89,11 +93,13 @@ class InstantController {
void OmniboxGotFocus();
// The search mode in the active tab has changed. Pass the message down to
- // the loader which will notify the renderer.
+ // the loader which will notify the renderer. Create |instant_tab_| if the
+ // |new_mode| reflects an Instant search results page.
void SearchModeChanged(const chrome::search::Mode& old_mode,
const chrome::search::Mode& new_mode);
- // The user switched tabs. Hide the preview if needed.
+ // The user switched tabs. Hide the preview if needed. Create |instant_tab_|
+ // if the newly active tab is an Instant search results page.
void ActiveTabChanged();
// Sets whether Instant should show result previews.
@@ -114,37 +120,30 @@ class InstantController {
const InstantModel* model() const { return &model_; }
- // Invoked by InstantLoader when it has suggested text.
- void SetSuggestions(InstantLoader* loader,
+ // Invoked by the page when it has suggested text.
+ void SetSuggestions(const content::WebContents* contents,
const std::vector<InstantSuggestion>& suggestions);
- // Invoked by InstantLoader to commit the preview.
- void CommitInstantLoader(InstantLoader* loader);
+ // Invoked by the page when its support for the Instant API is determined.
+ void InstantSupportDetermined(const content::WebContents* contents,
+ bool supports_instant);
// Invoked by InstantLoader to request that the preview be shown.
- void ShowInstantPreview(InstantLoader* loader,
- InstantShownReason reason,
+ void ShowInstantPreview(InstantShownReason reason,
int height,
InstantSizeUnits units);
- // Invoked by InstantLoader when it has determined whether or not the page
- // supports the Instant API.
- void InstantSupportDetermined(InstantLoader* loader, bool supports_instant);
-
- // Invoked by InstantLoader when it has swapped a different TabContents into
+ // Invoked by InstantLoader when it has swapped a different WebContents into
// the preview, usually because a prerendered page was navigated to.
- void SwappedTabContents(InstantLoader* loader);
+ void SwappedWebContents();
// Invoked by InstantLoader when the preview gains focus, usually due to the
// user clicking on it.
- void InstantLoaderContentsFocused(InstantLoader* loader);
-
-#if defined(UNIT_TEST)
- // Accessors used only in tests.
- InstantLoader* loader() const { return loader_.get(); }
-#endif
+ void InstantLoaderContentsFocused();
private:
+ FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant);
+ FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider);
FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh);
// Creates a new loader if necessary, using the instant_url property of the
@@ -152,7 +151,7 @@ class InstantController {
// time the loader was created). Returns false if the |template_url| doesn't
// have a valid Instant URL; true otherwise.
bool ResetLoader(const TemplateURL* template_url,
- const TabContents* active_tab);
+ const content::WebContents* active_tab);
// Ensures that the |loader_| uses the default Instant URL, recreating it if
// necessary, and returns true. Returns false if the Instant URL could not be
@@ -164,16 +163,20 @@ class InstantController {
// deleted and recreated. Else the refresh is skipped.
void OnStaleLoader();
- // Destroys the |loader_| and its preview contents.
- void DeleteLoader();
+ // If the active tab is an Instant search results page, sets |instant_tab_| to
+ // point to it. Else, deletes any existing |instant_tab_|.
+ void ResetInstantTab();
+
+ // Hide the preview. Also sends an onchange event (with blank query) to the
+ // preview, telling it to clear out results for any old queries.
+ void Hide();
- // Hide the preview. If |clear_query| is true, clears query text and sends a
- // an onchange event (with blank query) to the preview, telling it to clear
- // out results for any old queries.
- void Hide(bool clear_query);
+ // Like Hide(), but doesn't call OnStaleLoader(). You'll almost always want
+ // Hide(). Use this only if you are going to call loader_.reset() afterwards.
+ void HideInternal();
- // Counterpart to Hide(). Asks the |browser_| to display the preview with
- // the given |height|.
+ // Counterpart to Hide(). Asks the |browser_| to display the preview with the
+ // given |height|.
void Show(InstantShownReason reason, int height, InstantSizeUnits units);
// Send the omnibox dropdown bounds to the page.
@@ -193,10 +196,17 @@ class InstantController {
const bool extended_enabled_;
bool instant_enabled_;
+ // The state of the preview page, i.e., the page owned by |loader_|. Ignored
+ // if |instant_tab_| is in use.
InstantModel model_;
+ // The preview WebContents.
scoped_ptr<InstantLoader> loader_;
+ // A committed WebContents that supports Instant. If non-NULL, messages will
+ // be sent to this, instead of |loader_| (which will be hidden).
+ scoped_ptr<InstantTab> instant_tab_;
+
// The most recent user_text passed to Update().
string16 last_user_text_;
@@ -248,8 +258,7 @@ class InstantController {
GURL url_for_history_;
// The timestamp at which query editing began. This value is used when the
- // first set of suggestions is processed and cleared when the overlay is
- // hidden.
+ // preview is showed and cleared when the preview is hidden.
base::Time first_interaction_time_;
DISALLOW_COPY_AND_ASSIGN(InstantController);

Powered by Google App Engine
This is Rietveld 408576698