Commit f2ffcffa authored by treib's avatar treib Committed by Commit bot

Remove InstantTab::Delegate::InstantSupportDetermined

This is the first of a series of CLs to get rid of the notion of
"Instant support" entirely, see
https://bugs.chromium.org/p/chromium/issues/detail?id=627747#c41

BUG=627747

Review-Url: https://codereview.chromium.org/2845303002
Cr-Commit-Position: refs/heads/master@{#467974}
parent d2b5298c
...@@ -73,17 +73,6 @@ void InstantController::InstantSupportChanged( ...@@ -73,17 +73,6 @@ void InstantController::InstantSupportChanged(
ResetInstantTab(); ResetInstantTab();
} }
void InstantController::InstantSupportDetermined(
const content::WebContents* contents,
bool supports_instant) {
DCHECK(IsContentsFrom(instant_tab_.get(), contents));
if (!supports_instant) {
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE,
instant_tab_.release());
}
}
void InstantController::InstantTabAboutToNavigateMainFrame( void InstantController::InstantTabAboutToNavigateMainFrame(
const content::WebContents* contents, const content::WebContents* contents,
const GURL& url) { const GURL& url) {
...@@ -95,7 +84,7 @@ void InstantController::InstantTabAboutToNavigateMainFrame( ...@@ -95,7 +84,7 @@ void InstantController::InstantTabAboutToNavigateMainFrame(
} }
void InstantController::ResetInstantTab() { void InstantController::ResetInstantTab() {
if (!search_mode_.is_origin_default()) { if (search_mode_.is_origin_ntp()) {
content::WebContents* active_tab = browser_->GetActiveWebContents(); content::WebContents* active_tab = browser_->GetActiveWebContents();
if (!instant_tab_ || active_tab != instant_tab_->web_contents()) { if (!instant_tab_ || active_tab != instant_tab_->web_contents()) {
instant_tab_.reset(new InstantTab(this, active_tab)); instant_tab_.reset(new InstantTab(this, active_tab));
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/search/instant_tab.h" #include "chrome/browser/ui/search/instant_tab.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/common/search/search_types.h" #include "chrome/common/search/search_types.h"
class BrowserInstantController; class BrowserInstantController;
...@@ -88,8 +88,6 @@ class InstantController : public InstantTab::Delegate { ...@@ -88,8 +88,6 @@ class InstantController : public InstantTab::Delegate {
// Overridden from InstantTab::Delegate: // Overridden from InstantTab::Delegate:
// TODO(shishir): We assume that the WebContent's current RenderViewHost is // TODO(shishir): We assume that the WebContent's current RenderViewHost is
// the RenderViewHost being created which is not always true. Fix this. // the RenderViewHost being created which is not always true. Fix this.
void InstantSupportDetermined(const content::WebContents* contents,
bool supports_instant) override;
void InstantTabAboutToNavigateMainFrame(const content::WebContents* contents, void InstantTabAboutToNavigateMainFrame(const content::WebContents* contents,
const GURL& url) override; const GURL& url) override;
......
...@@ -4,11 +4,7 @@ ...@@ -4,11 +4,7 @@
#include "chrome/browser/ui/search/instant_tab.h" #include "chrome/browser/ui/search/instant_tab.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
InstantTab::Delegate::~Delegate() {} InstantTab::Delegate::~Delegate() {}
...@@ -16,12 +12,7 @@ InstantTab::Delegate::~Delegate() {} ...@@ -16,12 +12,7 @@ InstantTab::Delegate::~Delegate() {}
InstantTab::InstantTab(Delegate* delegate, content::WebContents* web_contents) InstantTab::InstantTab(Delegate* delegate, content::WebContents* web_contents)
: delegate_(delegate), pending_web_contents_(web_contents) {} : delegate_(delegate), pending_web_contents_(web_contents) {}
InstantTab::~InstantTab() { InstantTab::~InstantTab() {}
if (web_contents()) {
SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
this);
}
}
void InstantTab::Init() { void InstantTab::Init() {
if (!pending_web_contents_) if (!pending_web_contents_)
...@@ -29,14 +20,6 @@ void InstantTab::Init() { ...@@ -29,14 +20,6 @@ void InstantTab::Init() {
Observe(pending_web_contents_); Observe(pending_web_contents_);
pending_web_contents_ = nullptr; pending_web_contents_ = nullptr;
SearchModel* model =
SearchTabHelper::FromWebContents(web_contents())->model();
model->AddObserver(this);
// Already know whether the page supports instant.
if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN)
InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES);
} }
void InstantTab::DidFinishNavigation( void InstantTab::DidFinishNavigation(
...@@ -46,23 +29,3 @@ void InstantTab::DidFinishNavigation( ...@@ -46,23 +29,3 @@ void InstantTab::DidFinishNavigation(
web_contents(), navigation_handle->GetURL()); web_contents(), navigation_handle->GetURL());
} }
} }
void InstantTab::ModelChanged(const SearchModel::State& old_state,
const SearchModel::State& new_state) {
if (old_state.instant_support != new_state.instant_support)
InstantSupportDetermined(new_state.instant_support == INSTANT_SUPPORT_YES);
}
void InstantTab::InstantSupportDetermined(bool supports_instant) {
delegate_->InstantSupportDetermined(web_contents(), supports_instant);
// If the page doesn't support Instant, stop listening to it.
if (!supports_instant) {
if (web_contents()) {
SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
this);
}
Observe(nullptr);
}
}
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/search/search_model_observer.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "ui/base/page_transition_types.h"
class GURL; class GURL;
...@@ -20,19 +18,13 @@ class WebContents; ...@@ -20,19 +18,13 @@ class WebContents;
// InstantTab is used to exchange messages with a page that implements the // InstantTab is used to exchange messages with a page that implements the
// Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch). // Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch).
class InstantTab : public content::WebContentsObserver, class InstantTab : public content::WebContentsObserver {
public SearchModelObserver {
public: public:
// InstantTab calls its delegate in response to messages received from the // InstantTab calls its delegate in response to messages received from the
// page. Each method is called with the |contents| corresponding to the page // page. Each method is called with the |contents| corresponding to the page
// we are observing. // we are observing.
class Delegate { class Delegate {
public: public:
// Called upon determination of Instant API support. Either in response to
// the page loading or because we received some other message.
virtual void InstantSupportDetermined(const content::WebContents* contents,
bool supports_instant) = 0;
// Called when the page is about to navigate to |url|. // Called when the page is about to navigate to |url|.
virtual void InstantTabAboutToNavigateMainFrame( virtual void InstantTabAboutToNavigateMainFrame(
const content::WebContents* contents, const content::WebContents* contents,
...@@ -42,8 +34,7 @@ class InstantTab : public content::WebContentsObserver, ...@@ -42,8 +34,7 @@ class InstantTab : public content::WebContentsObserver,
virtual ~Delegate(); virtual ~Delegate();
}; };
explicit InstantTab(Delegate* delegate, content::WebContents* web_contents); InstantTab(Delegate* delegate, content::WebContents* web_contents);
~InstantTab() override; ~InstantTab() override;
// Sets up communication with the WebContents passed to the constructor. Does // Sets up communication with the WebContents passed to the constructor. Does
...@@ -55,12 +46,6 @@ class InstantTab : public content::WebContentsObserver, ...@@ -55,12 +46,6 @@ class InstantTab : public content::WebContentsObserver,
void DidFinishNavigation( void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override; content::NavigationHandle* navigation_handle) override;
// Overridden from SearchModelObserver:
void ModelChanged(const SearchModel::State& old_state,
const SearchModel::State& new_state) override;
void InstantSupportDetermined(bool supports_instant);
Delegate* const delegate_; Delegate* const delegate_;
content::WebContents* pending_web_contents_; content::WebContents* pending_web_contents_;
......
...@@ -36,9 +36,6 @@ class FakePageDelegate : public InstantTab::Delegate { ...@@ -36,9 +36,6 @@ class FakePageDelegate : public InstantTab::Delegate {
virtual ~FakePageDelegate() { virtual ~FakePageDelegate() {
} }
MOCK_METHOD2(InstantSupportDetermined,
void(const content::WebContents* contents,
bool supports_instant));
MOCK_METHOD2(InstantTabAboutToNavigateMainFrame, MOCK_METHOD2(InstantTabAboutToNavigateMainFrame,
void(const content::WebContents* contents, const GURL& url)); void(const content::WebContents* contents, const GURL& url));
}; };
...@@ -83,7 +80,6 @@ TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) { ...@@ -83,7 +80,6 @@ TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) {
EXPECT_FALSE(SupportsInstant()); EXPECT_FALSE(SupportsInstant());
page->Init(); page->Init();
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
search_tab()->DetermineIfPageSupportsInstant(); search_tab()->DetermineIfPageSupportsInstant();
EXPECT_TRUE(SupportsInstant()); EXPECT_TRUE(SupportsInstant());
} }
...@@ -107,7 +103,6 @@ TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) { ...@@ -107,7 +103,6 @@ TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) {
// SearchTabHelper::DeterminerIfPageSupportsInstant() should return // SearchTabHelper::DeterminerIfPageSupportsInstant() should return
// immediately without dispatching any message to the renderer. // immediately without dispatching any message to the renderer.
NavigateAndCommit(GURL("http://www.example.com")); NavigateAndCommit(GURL("http://www.example.com"));
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false));
EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()).Times(0); EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()).Times(0);
search_tab()->DetermineIfPageSupportsInstant(); search_tab()->DetermineIfPageSupportsInstant();
...@@ -124,8 +119,6 @@ TEST_F(InstantTabTest, PageSupportsInstant) { ...@@ -124,8 +119,6 @@ TEST_F(InstantTabTest, PageSupportsInstant) {
EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()); EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant());
search_tab()->DetermineIfPageSupportsInstant(); search_tab()->DetermineIfPageSupportsInstant();
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
// Assume the page supports instant. Invoke the message reply handler to make // Assume the page supports instant. Invoke the message reply handler to make
// sure the InstantTab is notified about the instant support state. // sure the InstantTab is notified about the instant support state.
const content::NavigationEntry* entry = const content::NavigationEntry* entry =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment