| Index: chrome/browser/instant/instant_loader.h
|
| diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h
|
| index b9f9fa9eba26cf9f6c9d09963cd0137fdaf89e74..897f422e77eccadd637bfd71d25bcd9d77c44f5a 100644
|
| --- a/chrome/browser/instant/instant_loader.h
|
| +++ b/chrome/browser/instant/instant_loader.h
|
| @@ -6,127 +6,80 @@
|
| #define CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_
|
|
|
| #include "base/basictypes.h"
|
| -#include "base/callback.h"
|
| #include "base/compiler_specific.h"
|
| +#include "base/gtest_prod_util.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/timer.h"
|
| -#include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
|
| -#include "content/public/browser/notification_observer.h"
|
| -#include "content/public/browser/notification_registrar.h"
|
| -#include "content/public/browser/web_contents_delegate.h"
|
| +#include "chrome/browser/instant/instant_page.h"
|
| +#include "chrome/browser/instant/instant_service_observer.h"
|
| +#include "chrome/browser/instant/instant_web_contents_container.h"
|
|
|
| -class GURL;
|
| -class Profile;
|
| +class InstantService;
|
|
|
| namespace content {
|
| -struct OpenURLParams;
|
| class WebContents;
|
| }
|
|
|
| -// InstantLoader is used to create and maintain a WebContents where we can
|
| -// preload a page into. It is used by InstantOverlay and InstantNTP to
|
| -// preload an Instant page.
|
| -class InstantLoader : public content::NotificationObserver,
|
| - public content::WebContentsDelegate,
|
| - public CoreTabHelperDelegate {
|
| +// InstantLoader maintains a hidden WebContents into which it loads the default
|
| +// search engine's Instant URL. InstantLoader is owned by InstantService.
|
| +class InstantLoader : public InstantPage::Delegate,
|
| + public InstantServiceObserver,
|
| + public InstantWebContentsContainer {
|
| public:
|
| - // InstantLoader calls these methods on its delegate in response to certain
|
| - // changes in the underlying contents.
|
| - class Delegate {
|
| - public:
|
| - // Called after someone has swapped in a different WebContents for ours.
|
| - virtual void OnSwappedContents() = 0;
|
| -
|
| - // Called when the underlying contents receive focus.
|
| - virtual void OnFocus() = 0;
|
| -
|
| - // Called when the mouse pointer is down.
|
| - virtual void OnMouseDown() = 0;
|
| -
|
| - // Called when the mouse pointer is released (or a drag event ends).
|
| - virtual void OnMouseUp() = 0;
|
| -
|
| - // Called to open a URL using the underlying contents (see
|
| - // WebContentsDelegate::OpenURLFromTab). The Delegate should return the
|
| - // WebContents the URL is opened in, or NULL if the URL wasn't opened
|
| - // immediately.
|
| - virtual content::WebContents* OpenURLFromTab(
|
| - content::WebContents* source,
|
| - const content::OpenURLParams& params) = 0;
|
| -
|
| - protected:
|
| - ~Delegate();
|
| - };
|
| -
|
| - explicit InstantLoader(Delegate* delegate);
|
| + explicit InstantLoader(InstantService* service);
|
| virtual ~InstantLoader();
|
|
|
| - // Creates a new WebContents in the context of |profile| that will be used to
|
| - // load |instant_url|. The page is not actually loaded until Load() is
|
| - // called. Uses |active_contents|, if non-NULL, to initialize the size of the
|
| - // new contents. |on_stale_callback| will be called after kStalePageTimeoutMS
|
| - // has elapsed after Load() being called.
|
| - void Init(const GURL& instant_url,
|
| - Profile* profile,
|
| - const content::WebContents* active_contents,
|
| - const base::Closure& on_stale_callback);
|
| + // Returns whether the |contents_| is known to support the Instant API.
|
| + bool supports_instant() const { return page_.supports_instant(); }
|
|
|
| - // Loads |instant_url_| in |contents_|.
|
| - void Load();
|
| + // Creates a new |contents_| and loads the Instant URL into it. If |contents_|
|
| + // is already valid, does nothing.
|
| + void InitContents();
|
|
|
| - // Returns the contents currently held. May be NULL.
|
| - content::WebContents* contents() const { return contents_.get(); }
|
| -
|
| - // Replaces the contents held with |contents|. Any existing contents is
|
| - // deleted. The expiration timer is not restarted.
|
| - void SetContents(scoped_ptr<content::WebContents> contents);
|
| -
|
| - // Releases the contents currently held. Must only be called if contents() is
|
| - // not NULL.
|
| - scoped_ptr<content::WebContents> ReleaseContents() WARN_UNUSED_RESULT;
|
| + // Gives up |contents_| to the caller, and creates a new one in its place.
|
| + scoped_ptr<content::WebContents> ReleaseContents();
|
|
|
| private:
|
| - // Overridden from content::NotificationObserver:
|
| - virtual void Observe(int type,
|
| - const content::NotificationSource& source,
|
| - const content::NotificationDetails& details) OVERRIDE;
|
| -
|
| - // Overridden from CoreTabHelperDelegate:
|
| - virtual void SwapTabContents(content::WebContents* old_contents,
|
| - content::WebContents* new_contents) OVERRIDE;
|
| -
|
| - // Overridden from content::WebContentsDelegate:
|
| - virtual bool ShouldSuppressDialogs() OVERRIDE;
|
| - virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
|
| - virtual void LostCapture() OVERRIDE;
|
| - virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
|
| - virtual bool CanDownload(content::RenderViewHost* render_view_host,
|
| - int request_id,
|
| - const std::string& request_method) OVERRIDE;
|
| - virtual void HandleMouseDown() OVERRIDE;
|
| - virtual void HandleMouseUp() OVERRIDE;
|
| - virtual void HandlePointerActivate() OVERRIDE;
|
| - virtual void HandleGestureEnd() OVERRIDE;
|
| - virtual void DragEnded() OVERRIDE;
|
| - virtual bool OnGoToEntryOffset(int offset) OVERRIDE;
|
| - virtual content::WebContents* OpenURLFromTab(
|
| - content::WebContents* source,
|
| - const content::OpenURLParams& params) OVERRIDE;
|
| -
|
| - Delegate* const delegate_;
|
| - scoped_ptr<content::WebContents> contents_;
|
| -
|
| - // The URL we will be loading.
|
| - GURL instant_url_;
|
| -
|
| - // Called when |stale_page_timer_| fires.
|
| - base::Closure on_stale_callback_;
|
| -
|
| - // Used to mark when the page is stale.
|
| - base::Timer stale_page_timer_;
|
| -
|
| - // Used to get notifications about renderers.
|
| - content::NotificationRegistrar registrar_;
|
| + FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh);
|
| +
|
| + // Overridden from InstantPage::Delegate:
|
| + virtual void RenderViewGone(const content::WebContents* contents) OVERRIDE;
|
| + virtual void InitSearchBox(const content::WebContents* contents) OVERRIDE;
|
| + virtual void InstantSupportDetermined(
|
| + const content::WebContents* contents) OVERRIDE;
|
| + virtual void SetSuggestion(const content::WebContents* contents,
|
| + const InstantSuggestion& suggestion) OVERRIDE;
|
| + virtual void NavigateToURL(const content::WebContents* contents,
|
| + const GURL& url,
|
| + content::PageTransition transition,
|
| + WindowOpenDisposition disposition) OVERRIDE;
|
| + virtual void ShowOverlay(const content::WebContents* contents,
|
| + int height,
|
| + bool is_height_in_pixels) OVERRIDE;
|
| + virtual void StartKeyCapture(const content::WebContents* contents) OVERRIDE;
|
| + virtual void StopKeyCapture(const content::WebContents* contents) OVERRIDE;
|
| + virtual void DeleteMostVisitedItem(const content::WebContents* contents,
|
| + const GURL& url) OVERRIDE;
|
| + virtual void UndoMostVisitedItemDeletion(const content::WebContents* contents,
|
| + const GURL& url) OVERRIDE;
|
| + virtual void UndoAllMostVisitedItemDeletions(
|
| + const content::WebContents* contents) OVERRIDE;
|
| +
|
| + // Overridden from InstantServiceObserver:
|
| + virtual void InstantStatusChanged() OVERRIDE;
|
| + virtual void ThemeInfoChanged() OVERRIDE;
|
| + virtual void MostVisitedItemsChanged() OVERRIDE;
|
| + virtual void InstantSupportDecided() OVERRIDE;
|
| +
|
| + // Overridden from InstantWebContentsContainer:
|
| + virtual void CloseContents(content::WebContents* source) OVERRIDE;
|
| + virtual void TearDownContents() OVERRIDE;
|
| +
|
| + void DeleteContents();
|
| + void ReloadContents();
|
| +
|
| + InstantService* const service_;
|
| + base::OneShotTimer<InstantLoader> stale_page_timer_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(InstantLoader);
|
| };
|
|
|