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(
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(
const content::WebContents* contents,
const GURL& url) {
......@@ -95,7 +84,7 @@ void InstantController::InstantTabAboutToNavigateMainFrame(
}
void InstantController::ResetInstantTab() {
if (!search_mode_.is_origin_default()) {
if (search_mode_.is_origin_ntp()) {
content::WebContents* active_tab = browser_->GetActiveWebContents();
if (!instant_tab_ || active_tab != instant_tab_->web_contents()) {
instant_tab_.reset(new InstantTab(this, active_tab));
......
......@@ -14,8 +14,8 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/search/instant_tab.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/common/search/search_types.h"
class BrowserInstantController;
......@@ -88,8 +88,6 @@ class InstantController : public InstantTab::Delegate {
// Overridden from InstantTab::Delegate:
// TODO(shishir): We assume that the WebContent's current RenderViewHost is
// 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,
const GURL& url) override;
......
......@@ -4,11 +4,7 @@
#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/render_frame_host.h"
#include "content/public/browser/web_contents.h"
InstantTab::Delegate::~Delegate() {}
......@@ -16,12 +12,7 @@ InstantTab::Delegate::~Delegate() {}
InstantTab::InstantTab(Delegate* delegate, content::WebContents* web_contents)
: delegate_(delegate), pending_web_contents_(web_contents) {}
InstantTab::~InstantTab() {
if (web_contents()) {
SearchTabHelper::FromWebContents(web_contents())->model()->RemoveObserver(
this);
}
}
InstantTab::~InstantTab() {}
void InstantTab::Init() {
if (!pending_web_contents_)
......@@ -29,14 +20,6 @@ void InstantTab::Init() {
Observe(pending_web_contents_);
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(
......@@ -46,23 +29,3 @@ void InstantTab::DidFinishNavigation(
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 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "chrome/browser/ui/search/search_model_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/base/page_transition_types.h"
class GURL;
......@@ -20,19 +18,13 @@ class WebContents;
// InstantTab is used to exchange messages with a page that implements the
// Instant/Embedded Search API (http://dev.chromium.org/embeddedsearch).
class InstantTab : public content::WebContentsObserver,
public SearchModelObserver {
class InstantTab : public content::WebContentsObserver {
public:
// InstantTab calls its delegate in response to messages received from the
// page. Each method is called with the |contents| corresponding to the page
// we are observing.
class Delegate {
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|.
virtual void InstantTabAboutToNavigateMainFrame(
const content::WebContents* contents,
......@@ -42,8 +34,7 @@ class InstantTab : public content::WebContentsObserver,
virtual ~Delegate();
};
explicit InstantTab(Delegate* delegate, content::WebContents* web_contents);
InstantTab(Delegate* delegate, content::WebContents* web_contents);
~InstantTab() override;
// Sets up communication with the WebContents passed to the constructor. Does
......@@ -55,12 +46,6 @@ class InstantTab : public content::WebContentsObserver,
void DidFinishNavigation(
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_;
content::WebContents* pending_web_contents_;
......
......@@ -36,9 +36,6 @@ class FakePageDelegate : public InstantTab::Delegate {
virtual ~FakePageDelegate() {
}
MOCK_METHOD2(InstantSupportDetermined,
void(const content::WebContents* contents,
bool supports_instant));
MOCK_METHOD2(InstantTabAboutToNavigateMainFrame,
void(const content::WebContents* contents, const GURL& url));
};
......@@ -83,7 +80,6 @@ TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) {
EXPECT_FALSE(SupportsInstant());
page->Init();
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
search_tab()->DetermineIfPageSupportsInstant();
EXPECT_TRUE(SupportsInstant());
}
......@@ -107,7 +103,6 @@ TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) {
// SearchTabHelper::DeterminerIfPageSupportsInstant() should return
// immediately without dispatching any message to the renderer.
NavigateAndCommit(GURL("http://www.example.com"));
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false));
EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()).Times(0);
search_tab()->DetermineIfPageSupportsInstant();
......@@ -124,8 +119,6 @@ TEST_F(InstantTabTest, PageSupportsInstant) {
EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant());
search_tab()->DetermineIfPageSupportsInstant();
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
// Assume the page supports instant. Invoke the message reply handler to make
// sure the InstantTab is notified about the instant support state.
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