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

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

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 7 years, 11 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 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 250c31a6c0d10fb64a05141f033f20517b98aff2..8fc9ee5635aa4de57de4caaa93504ca151bd4d86 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -15,6 +15,7 @@
#include "base/string16.h"
#include "base/time.h"
#include "base/timer.h"
+#include "chrome/browser/instant/instant_api_wrapper.h"
#include "chrome/browser/instant/instant_commit_type.h"
#include "chrome/browser/instant/instant_model.h"
#include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
@@ -27,7 +28,8 @@
struct AutocompleteMatch;
class AutocompleteProvider;
-class InstantLoader;
+class InstantNTP;
+class InstantOverlay;
class InstantTab;
class TemplateURL;
@@ -39,10 +41,12 @@ 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.
-class InstantController {
+// InstantController drives Chrome Instant, i.e., the browser implementation of
+// the Embedded Search API (see http://dev.chromium.org/embeddedsearch). It
+// maintains a WebContents used to show search suggestions and results in an
+// overlay and a WebContents used for the New Tab page. InstantController is
+// owned by Browser via BrowserInstantController.
+class InstantController : public InstantAPIWrapper::Receiver {
public:
// The URL for the local omnibox popup.
static const char* kLocalOmniboxPopupURL;
@@ -72,6 +76,10 @@ class InstantController {
bool escape_pressed,
bool is_keyword_search);
+ // Releases and returns the NTP WebContents. May be NULL. Loads a new
+ // WebContents for the NTP.
+ content::WebContents* ReleaseNTPContents();
+
// Sets the bounds of the omnibox popup, in screen coordinates.
void SetPopupBounds(const gfx::Rect& bounds);
@@ -105,7 +113,7 @@ class InstantController {
gfx::NativeView view_gaining_focus);
// The search mode in the active tab has changed. Pass the message down to
- // the loader which will notify the renderer. Create |instant_tab_| if the
+ // the overlay 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);
@@ -133,94 +141,95 @@ class InstantController {
const InstantModel* model() const { return &model_; }
- // Invoked by the page when it has suggested text.
- void SetSuggestions(const content::WebContents* contents,
- const std::vector<InstantSuggestion>& suggestions);
-
- // 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(InstantShownReason reason,
- int height,
- InstantSizeUnits units);
-
- // Invoked by InstantLoader to request the browser to start capturing user key
- // strokes.
- void StartCapturingKeyStrokes();
-
- // Invoked by InstantLoader to request the browser to stop capturing user key
- // strokes.
- void StopCapturingKeyStrokes();
-
- // Invoked by InstantLoader when it has swapped a different WebContents into
+ // Invoked by InstantOverlay when it has swapped a different WebContents into
// the preview, usually because a prerendered page was navigated to.
- void SwappedWebContents();
+ void SwappedOverlayWebContents();
- // Invoked by InstantLoader when the preview gains focus, usually due to the
+ // Invoked by InstantOverlay when the preview gains focus, usually due to the
// user clicking on it.
- void InstantLoaderContentsFocused();
-
- // Invoked by the InstantLoader when its RenderView crashes.
- void InstantLoaderRenderViewGone();
+ void InstantOverlayContentsFocused();
- // Invoked by InstantLoader when the instant page is about to navigate.
- void InstantLoaderAboutToNavigateMainFrame(const GURL& url);
+ // Called when the |ntp_| might be stale. If it's actually state, the |ntp_|
Jered 2013/01/14 18:22:34 state -> stale
samarth 2013/01/22 15:59:06 Done.
+ // is deleted and recreated.
+ void OnStaleNTP();
- // Invoked by the InstantLoader when the instant page wants to navigate to
- // the speicfied URL.
- void NavigateToURL(const GURL& url, content::PageTransition transition);
+ // Called when the |overlay_| might be stale. If it's actually stale, and the
+ // omnibox doesn't have focus, and the preview isn't showing, the |overlay_|
+ // is deleted and recreated. Else the refresh is skipped.
+ void OnStaleOverlay();
private:
FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant);
FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider);
FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh);
+ // Overridden from InstantAPIWrapper::Receiver.
+ virtual void InstantSupportDetermined(
+ const content::WebContents* contents,
+ bool supports_instant) OVERRIDE;
+ virtual void InstantPageRenderViewGone(
+ const content::WebContents* contents) OVERRIDE;
+ virtual void InstantPageAboutToNavigateMainFrame(
+ const content::WebContents* contents,
+ const GURL& url) OVERRIDE;
+ virtual void SetSuggestions(
+ const content::WebContents* contents,
+ const std::vector<InstantSuggestion>& suggestions) OVERRIDE;
+ virtual void ShowInstantPreview(
+ const content::WebContents* contents,
+ InstantShownReason reason,
+ int height,
+ InstantSizeUnits units) OVERRIDE;
+ virtual void StartCapturingKeyStrokes(
+ const content::WebContents* contents) OVERRIDE;
+ virtual void StopCapturingKeyStrokes(content::WebContents* contents) OVERRIDE;
+ virtual void NavigateToURL(
+ const content::WebContents* contents,
+ const GURL& url,
+ content::PageTransition transition) OVERRIDE;
+
// Helper for OmniboxFocusChanged. Commit or discard the preview.
void OmniboxLostFocus(gfx::NativeView view_gaining_focus);
- // Creates a new loader if necessary, using the instant_url property of the
+ // Creates a new NTP, using the instant_url property of the |template_url|.
+ bool ResetNTP();
+
+ // Creates a new overlay if necessary, using the instant_url property of the
// |template_url| (for example, if the Instant URL has changed since the last
- // time the loader was created). If |fallback_to_local| is true will use
+ // time the overlay was created). If |fallback_to_local| is true will use
// kLocalOmniboxPopupURL as the fallback url (in extended mode) in case
// the |template_url| doesn't have a valid Instant URL. Returns true if an
// instant URL could be determined.
- bool ResetLoader(const TemplateURL* template_url,
- const content::WebContents* active_tab,
- bool fallback_to_local);
+ bool ResetOverlay(const TemplateURL* template_url,
+ const content::WebContents* active_tab,
+ bool fallback_to_local);
- // Ensures that the |loader_| uses the default Instant URL, recreating it if
+ // Ensures that the |overlay_| uses the default Instant URL, recreating it if
// necessary, and returns true. Returns false if the Instant URL could not be
// determined or the active tab is NULL (browser is shutting down).
- bool CreateDefaultLoader();
+ bool CreateDefaultOverlay();
- // Called when the |loader_| might be stale. If it's actually stale, and the
- // omnibox doesn't have focus, and the preview isn't showing, the |loader_| is
- // deleted and recreated. Else the refresh is skipped.
- void OnStaleLoader();
+ // Called by Update() to ensure we have an Instant page that can process
+ // |match|. Returns true if we should continue with the Update().
+ bool ResetOverlayForMatch(const AutocompleteMatch& match);
// 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();
- // Called by Update() to ensure we have an Instant page that can process
- // |match|. Returns true if we should continue with the Update().
- bool ResetLoaderForMatch(const AutocompleteMatch& match);
-
// 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 HideLoader();
+ void HideOverlay();
- // Like HideLoader(), but doesn't call OnStaleLoader(). Use HideLoader()
- // unless you are going to call loader_.reset() yourself subsequently.
+ // Like HideOverlay(), but doesn't call OnStaleOverlay(). Use HideOverlay()
+ // unless you are going to call overlay_.reset() yourself subsequently.
void HideInternal();
- // Counterpart to HideLoader(). Asks the |browser_| to display the preview
+ // Counterpart to HideOverlay(). Asks the |browser_| to display the preview
// with the given |height|.
- void ShowLoader(InstantShownReason reason,
- int height,
- InstantSizeUnits units);
+ void ShowOverlay(InstantShownReason reason,
+ int height,
+ InstantSizeUnits units);
// Send the omnibox popup bounds to the page.
void SendPopupBoundsToPage();
@@ -232,6 +241,12 @@ class InstantController {
bool GetInstantURL(const TemplateURL* template_url,
std::string* instant_url) const;
+ // Add |url| to the blacklist.
+ void AddToBlacklist(const std::string& url);
+
+ // Remove |url| from the blacklist.
+ void RemoveFromBlacklist(const std::string& url);
+
chrome::BrowserInstantController* const browser_;
// Whether the extended API and regular API are enabled. If both are false,
@@ -242,19 +257,23 @@ class InstantController {
// If true, the instant URL is set to kLocalOmniboxPopupURL.
const bool use_local_preview_only_;
- // The state of the preview page, i.e., the page owned by |loader_|. Ignored
+ // The state of the preview page, i.e., the page owned by |overlay_|. Ignored
// if |instant_tab_| is in use.
InstantModel model_;
- // The preview WebContents.
- scoped_ptr<InstantLoader> loader_;
+ // WebContents used to show search suggestions and results in an overlay.
+ scoped_ptr<InstantOverlay> overlay_;
- // A committed WebContents that supports Instant. If non-NULL, the |loader_|
- // is guaranteed to be hidden and messages will be sent to this instead.
+ // WebContents used for New Tab Pages.
+ scoped_ptr<InstantNTP> ntp_;
+
+ // A committed WebContents that supports SearchBoxAPI via the
+ // InstantClient::Delegate interface. If non-NULL, the |overlay_| is
Jered 2013/01/14 18:22:34 InstantClient -> InstantAPIWrapper
samarth 2013/01/22 15:59:06 Done.
+ // guaranteed to be hidden and messages will be sent to this instead.
scoped_ptr<InstantTab> instant_tab_;
// The most recent full_text passed to Update(). If empty, we'll not accept
- // search suggestions from |loader_| or |instant_tab_|.
+ // search suggestions from |overlay_| or |instant_tab_|.
string16 last_omnibox_text_;
// True if the last Update() had an inline autocompletion. Used only to make
@@ -297,9 +316,6 @@ class InstantController {
// Timer used to update the bounds of the omnibox popup.
base::OneShotTimer<InstantController> update_bounds_timer_;
- // Timer used to ensure that the Instant page does not get too stale.
- base::OneShotTimer<InstantController> stale_loader_timer_;
-
// For each key K => value N, the map says that we found that the search
// engine identified by Instant URL K didn't support the Instant API, or
// caused RenderView crashes in each of the last N times that we loaded it.

Powered by Google App Engine
This is Rietveld 408576698