Index: chrome/browser/instant/instant_controller.h |
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h |
index db74de89ada7713558703d7d1b2a35b5a662f7f4..ee1afe988722b0d0bf97970746582b2dc7a4806a 100644 |
--- a/chrome/browser/instant/instant_controller.h |
+++ b/chrome/browser/instant/instant_controller.h |
@@ -17,6 +17,7 @@ |
#include "base/timer.h" |
#include "chrome/browser/instant/instant_commit_type.h" |
#include "chrome/browser/instant/instant_model.h" |
+#include "chrome/browser/instant/instant_page.h" |
#include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
#include "chrome/common/instant_types.h" |
#include "chrome/common/search_types.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 InstantPage::Delegate { |
dhollowa
2013/01/22 22:34:58
I'm a bit confused here... The controller is a pa
samarth
2013/01/25 21:08:40
It's responding (potentially) to all three. That'
|
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(); |
dhollowa
2013/01/22 22:34:58
This should use scoped_ptr<contents::WebContents>
samarth
2013/01/25 21:08:40
Ah, didn't know about this. This is really nice,
|
+ |
// 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,45 +141,6 @@ 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 |
- // the preview, usually because a prerendered page was navigated to. |
- void SwappedWebContents(); |
- |
- // Invoked by InstantLoader 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(); |
- |
- // Invoked by InstantLoader when the instant page is about to navigate. |
- void InstantLoaderAboutToNavigateMainFrame(const GURL& url); |
- |
- // Invoked by the InstantLoader when the instant page wants to navigate to |
- // the speicfied URL. |
- void NavigateToURL(const GURL& url, content::PageTransition transition); |
- |
private: |
FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); |
FRIEND_TEST_ALL_PREFIXES(InstantTest, SetWithTemplateURL); |
@@ -180,50 +149,87 @@ class InstantController { |
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn); |
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OmniboxFocusLoadsInstant); |
+ // Overridden from InstantPage::Delegate |
dhollowa
2013/01/22 22:34:58
nit: Should end with ":".
samarth
2013/01/25 21:08:40
Done.
|
+ 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; |
+ virtual void OnStalePage(const content::WebContents* contents) OVERRIDE; |
dhollowa
2013/01/22 22:34:58
nit: Shouldn't begin with "On".
samarth
2013/01/25 21:08:40
Done.
|
+ virtual void InstantPageSwappedContents( |
+ content::WebContents* new_contents) OVERRIDE; |
+ virtual void InstantPageFocused( |
+ const content::WebContents* contents) OVERRIDE; |
+ virtual void InstantPageClicked( |
+ const content::WebContents* contents) OVERRIDE; |
+ virtual bool InstantPageAboutToOpenURL( |
+ const content::WebContents* contents) 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 |
+ // 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(); |
dhollowa
2013/01/22 22:34:58
nit: Shouldn't begin with "On".
samarth
2013/01/25 21:08:40
Done.
|
+ |
+ // 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|. |
dhollowa
2013/01/22 22:34:58
nit: "...with the given |height| and |units|."
samarth
2013/01/25 21:08:40
Done.
|
- 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(); |
@@ -235,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, |
@@ -245,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_; |
dhollowa
2013/01/22 22:34:58
It would be helpful to articulate the invariants b
samarth
2013/01/25 21:08:40
Done.
|
- // 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 the SearchBoxAPI. If non-NULL, the |
+ // |overlay_| is 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 |
@@ -300,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. |