summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsamarth@chromium.org <samarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-12 02:10:54 +0000
committersamarth@chromium.org <samarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-12 02:10:54 +0000
commit58e2806f18c789e91f89c0a836013f29926e8028 (patch)
tree8196ce9f086b5c8b13684ac0e457303c3a6efd87
parentd57ecffa058b2af3b0678c43dce75f731550bbce (diff)
downloadchromium_src-58e2806f18c789e91f89c0a836013f29926e8028.zip
chromium_src-58e2806f18c789e91f89c0a836013f29926e8028.tar.gz
chromium_src-58e2806f18c789e91f89c0a836013f29926e8028.tar.bz2
InstantExtended: remove dead code related to the non-cacheable NTP.
BUG=none Review URL: https://codereview.chromium.org/132733002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244407 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd3
-rw-r--r--chrome/browser/search/instant_service.cc49
-rw-r--r--chrome/browser/search/instant_service.h34
-rw-r--r--chrome/browser/search/instant_service_unittest.cc38
-rw-r--r--chrome/browser/search/search.cc78
-rw-r--r--chrome/browser/search/search.h14
-rw-r--r--chrome/browser/search/search_unittest.cc80
-rw-r--r--chrome/browser/task_manager/extension_process_resource_provider.cc1
-rw-r--r--chrome/browser/task_manager/panel_resource_provider.cc1
-rw-r--r--chrome/browser/task_manager/tab_contents_resource_provider.cc16
-rw-r--r--chrome/browser/task_manager/task_manager_util.cc3
-rw-r--r--chrome/browser/task_manager/task_manager_util.h1
-rw-r--r--chrome/browser/task_manager/task_manager_util_unittest.cc19
-rw-r--r--chrome/browser/ui/browser_instant_controller.cc71
-rw-r--r--chrome/browser/ui/browser_instant_controller.h14
-rw-r--r--chrome/browser/ui/browser_navigator.cc27
-rw-r--r--chrome/browser/ui/search/instant_controller.cc34
-rw-r--r--chrome/browser/ui/search/instant_controller.h10
-rw-r--r--chrome/browser/ui/search/instant_extended_interactive_uitest.cc161
-rw-r--r--chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc29
-rw-r--r--chrome/browser/ui/search/instant_loader.cc176
-rw-r--r--chrome/browser/ui/search/instant_loader.h119
-rw-r--r--chrome/browser/ui/search/instant_ntp.cc61
-rw-r--r--chrome/browser/ui/search/instant_ntp.h66
-rw-r--r--chrome/browser/ui/search/instant_ntp_prerenderer.cc269
-rw-r--r--chrome/browser/ui/search/instant_ntp_prerenderer.h154
-rw-r--r--chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc244
-rw-r--r--chrome/browser/ui/search/instant_page.cc22
-rw-r--r--chrome/browser/ui/search/instant_page.h14
-rw-r--r--chrome/browser/ui/search/instant_page_unittest.cc1
-rw-r--r--chrome/browser/ui/search/instant_test_utils.cc41
-rw-r--r--chrome/browser/ui/search/instant_test_utils.h6
-rw-r--r--chrome/browser/ui/search/instant_unload_handler.cc106
-rw-r--r--chrome/browser/ui/search/instant_unload_handler.h65
-rw-r--r--chrome/browser/ui/search/local_ntp_browsertest.cc8
-rw-r--r--chrome/browser/ui/search/search_tab_helper.cc4
-rw-r--r--chrome/browser/ui/webui/memory_internals/memory_internals_proxy.cc10
-rw-r--r--chrome/chrome_browser_ui.gypi8
-rw-r--r--chrome/chrome_tests_unit.gypi2
-rw-r--r--chrome/test/data/instant_extended_ntp.html165
40 files changed, 254 insertions, 1970 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 3221173..bebc67a 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -3649,9 +3649,6 @@ Make sure you do not expose any sensitive information.
<message name="IDS_TASK_MANAGER_NOTIFICATION_PREFIX" desc="The prefix for a Desktop Notification in the Task Manager">
Notification: <ph name="NOTIFICATION_NAME">$1<ex>http://www.domain.com</ex></ph>
</message>
- <message name="IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX" desc="The prefix for an Instant overlay in the Task Manager">
- Instant: <ph name="INSTANT_OVERLAY_NAME">$1<ex>http://www.google.com/</ex></ph>
- </message>
<message name="IDS_TASK_MANAGER_WEBVIEW_TAG_PREFIX" desc="The prefix for a guest page loaded in webview tag in the Task Manager">
Webview: <ph name="WEBVIEW_TAG_NAME">$1<ex>Google</ex></ph>
</message>
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index 7b671d2..1e4fa9f 100644
--- a/chrome/browser/search/instant_service.cc
+++ b/chrome/browser/search/instant_service.cc
@@ -67,8 +67,6 @@ RGBAColor SkColorToRGBAColor(const SkColor& sKColor) {
InstantService::InstantService(Profile* profile)
: profile_(profile),
- ntp_prerenderer_(profile, this, profile->GetPrefs()),
- browser_instant_controller_object_count_(0),
weak_ptr_factory_(this) {
// Stub for unit tests.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
@@ -124,8 +122,6 @@ InstantService::InstantService(Profile* profile)
registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
content::Source<Profile>(profile_->GetOriginalProfile()));
- registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
- content::Source<Profile>(profile_));
}
InstantService::~InstantService() {
@@ -205,37 +201,6 @@ void InstantService::Shutdown() {
instant_io_context_ = NULL;
}
-scoped_ptr<content::WebContents> InstantService::ReleaseNTPContents() {
- return ntp_prerenderer_.ReleaseNTPContents();
-}
-
-content::WebContents* InstantService::GetNTPContents() const {
- return ntp_prerenderer_.GetNTPContents();
-}
-
-void InstantService::OnBrowserInstantControllerCreated() {
- if (profile_->IsOffTheRecord())
- return;
-
- ++browser_instant_controller_object_count_;
-
- if (browser_instant_controller_object_count_ == 1)
- ntp_prerenderer_.ReloadInstantNTP();
-}
-
-void InstantService::OnBrowserInstantControllerDestroyed() {
- if (profile_->IsOffTheRecord())
- return;
-
- DCHECK_GT(browser_instant_controller_object_count_, 0U);
- --browser_instant_controller_object_count_;
-
- // All browser windows have closed, so release the InstantNTP resources to
- // work around http://crbug.com/180810.
- if (browser_instant_controller_object_count_ == 0)
- ntp_prerenderer_.DeleteNTPContents();
-}
-
void InstantService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -263,16 +228,6 @@ void InstantService::Observe(int type,
break;
}
#endif // defined(ENABLE_THEMES)
- case chrome::NOTIFICATION_PROFILE_DESTROYED: {
- // Last chance to delete InstantNTP contents. We generally delete
- // preloaded InstantNTP when the last BrowserInstantController object is
- // destroyed. When the browser shutdown happens without closing browsers,
- // there is a race condition between BrowserInstantController destruction
- // and Profile destruction.
- if (GetNTPContents())
- ntp_prerenderer_.DeleteNTPContents();
- break;
- }
case chrome::NOTIFICATION_GOOGLE_URL_UPDATED: {
OnGoogleURLUpdated(
content::Source<Profile>(source).ptr(),
@@ -476,10 +431,6 @@ void InstantService::OnDefaultSearchProviderChanged(
InstantServiceObserver, observers_, DefaultSearchProviderChanged());
}
-InstantNTPPrerenderer* InstantService::ntp_prerenderer() {
- return &ntp_prerenderer_;
-}
-
void InstantService::ResetInstantSearchPrerenderer() {
if (!chrome::ShouldPrefetchSearchResults())
return;
diff --git a/chrome/browser/search/instant_service.h b/chrome/browser/search/instant_service.h
index 4b50da3..6da171d 100644
--- a/chrome/browser/search/instant_service.h
+++ b/chrome/browser/search/instant_service.h
@@ -11,8 +11,6 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
@@ -20,7 +18,6 @@
#include "base/prefs/pref_change_registrar.h"
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/history/history_types.h"
-#include "chrome/browser/ui/search/instant_ntp_prerenderer.h"
#include "chrome/browser/ui/search/instant_search_prerenderer.h"
#include "chrome/common/instant_types.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
@@ -36,7 +33,7 @@ class Profile;
class ThemeService;
namespace content {
-class WebContents;
+class RenderProcessHost;
}
namespace net {
@@ -89,22 +86,6 @@ class InstantService : public BrowserContextKeyedService,
// NTP.
void UpdateMostVisitedItemsInfo();
- // Forwards the request to InstantNTPPrerenderer to release and return the
- // preloaded InstantNTP WebContents. May be NULL. InstantNTPPrerenderer will
- // load a new InstantNTP after releasing the preloaded contents.
- scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT;
-
- // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership.
- content::WebContents* GetNTPContents() const;
-
- // Notifies InstantService about the creation of a BrowserInstantController
- // object. Used to preload InstantNTP.
- void OnBrowserInstantControllerCreated();
-
- // Notifies InstantService about the destruction of a BrowserInstantController
- // object. Used to destroy the preloaded InstantNTP.
- void OnBrowserInstantControllerDestroyed();
-
// Sends the current set of search URLs to a renderer process.
void SendSearchURLsToRenderer(content::RenderProcessHost* rph);
@@ -118,10 +99,6 @@ class InstantService : public BrowserContextKeyedService,
friend class InstantTestBase;
friend class InstantUnitTestBase;
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedNetworkTest,
- NTPReactsToNetworkChanges);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest,
- MANUAL_ShowsGoogleNTP);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest,
MANUAL_SearchesFromFakebox);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation);
@@ -154,9 +131,6 @@ class InstantService : public BrowserContextKeyedService,
void OnDefaultSearchProviderChanged(const std::string& pref_name);
- // Used by tests.
- InstantNTPPrerenderer* ntp_prerenderer();
-
void ResetInstantSearchPrerenderer();
Profile* const profile_;
@@ -178,12 +152,6 @@ class InstantService : public BrowserContextKeyedService,
scoped_refptr<InstantIOContext> instant_io_context_;
- InstantNTPPrerenderer ntp_prerenderer_;
-
- // Total number of BrowserInstantController objects (does not include objects
- // created for OTR browser windows). Used to preload and delete InstantNTP.
- size_t browser_instant_controller_object_count_;
-
// Set to NULL if the default search provider does not support Instant.
scoped_ptr<InstantSearchPrerenderer> instant_prerenderer_;
diff --git a/chrome/browser/search/instant_service_unittest.cc b/chrome/browser/search/instant_service_unittest.cc
index c9fd5c2..a4e9163 100644
--- a/chrome/browser/search/instant_service_unittest.cc
+++ b/chrome/browser/search/instant_service_unittest.cc
@@ -20,8 +20,6 @@
#include "components/variations/entropy_provider.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/mock_render_process_host.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_test_sink.h"
@@ -34,22 +32,6 @@ class MockInstantServiceObserver : public InstantServiceObserver {
MOCK_METHOD0(GoogleURLUpdated, void());
};
-class MockWebContentsObserver : public content::WebContentsObserver {
- public:
- MOCK_METHOD1(WebContentsDestroyed, void(content::WebContents*));
-
- // Dumb override to make MSVC happy.
- void Observe_(content::WebContents* contents) {
- content::WebContentsObserver::Observe(contents);
- }
-
- protected:
- friend class InstantServiceTest;
- FRIEND_TEST_ALL_PREFIXES(InstantServiceTest,
- DispatchDefaultSearchProviderChanged);
- FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DispatchGoogleURLUpdated);
-};
-
class InstantServiceTest : public InstantUnitTestBase {
protected:
virtual void SetUp() OVERRIDE {
@@ -57,15 +39,10 @@ class InstantServiceTest : public InstantUnitTestBase {
instant_service_observer_.reset(new MockInstantServiceObserver());
instant_service_->AddObserver(instant_service_observer_.get());
-
- instant_ntp_contents_observer_.reset(new MockWebContentsObserver());
- instant_ntp_contents_observer_->Observe_(
- instant_service_->GetNTPContents());
}
virtual void TearDown() OVERRIDE {
instant_service_->RemoveObserver(instant_service_observer_.get());
- instant_ntp_contents_observer_->Observe_(NULL);
InstantUnitTestBase::TearDown();
}
@@ -74,36 +51,21 @@ class InstantServiceTest : public InstantUnitTestBase {
}
scoped_ptr<MockInstantServiceObserver> instant_service_observer_;
- scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_;
};
TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) {
EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged())
.Times(1);
- EXPECT_CALL(*instant_ntp_contents_observer_.get(),
- WebContentsDestroyed(instant_service_->GetNTPContents()))
- .Times(1);
- GURL ntp_url = instant_service_->GetNTPContents()->GetURL();
const std::string& new_base_url = "https://bar.com/";
SetDefaultSearchProvider(new_base_url);
- GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL();
- EXPECT_NE(ntp_url, new_ntp_url);
- EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true));
}
TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) {
EXPECT_CALL(*instant_service_observer_.get(), GoogleURLUpdated()).Times(1);
- EXPECT_CALL(*instant_ntp_contents_observer_.get(),
- WebContentsDestroyed(instant_service_->GetNTPContents()))
- .Times(1);
- GURL ntp_url = instant_service_->GetNTPContents()->GetURL();
const std::string& new_base_url = "https://www.google.es/";
NotifyGoogleBaseURLUpdate(new_base_url);
- GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL();
- EXPECT_NE(ntp_url, new_ntp_url);
- EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true));
}
TEST_F(InstantServiceTest, SendsSearchURLsToRenderer) {
diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc
index d4387a1..d4cc070 100644
--- a/chrome/browser/search/search.cc
+++ b/chrome/browser/search/search.cc
@@ -7,7 +7,6 @@
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
-#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
@@ -59,13 +58,7 @@ const uint64 kEmbeddedPageVersionDefault = 1;
const uint64 kEmbeddedPageVersionDefault = 2;
#endif
-// The staleness timeout can be set (in seconds) via this config.
-const char kStalePageTimeoutFlagName[] = "stale";
-const int kStalePageTimeoutDefault = 3 * 3600; // 3 hours.
-
const char kHideVerbatimFlagName[] = "hide_verbatim";
-const char kShowNtpFlagName[] = "show_ntp";
-const char kUseCacheableNTP[] = "use_cacheable_ntp";
const char kPrefetchSearchResultsFlagName[] = "prefetch_results";
const char kPrefetchSearchResultsOnSRP[] = "prefetch_results_srp";
const char kDisplaySearchButtonFlagName[] = "display_search_button";
@@ -395,14 +388,9 @@ bool NavEntryIsInstantNTP(const content::WebContents* contents,
if (entry->GetURL() == GetLocalInstantURL(profile))
return true;
- if (ShouldUseCacheableNTP()) {
- GURL new_tab_url(GetNewTabPageURL(profile));
- return new_tab_url.is_valid() &&
- search::MatchesOriginAndPath(entry->GetURL(), new_tab_url);
- }
-
- return IsInstantURL(entry->GetVirtualURL(), profile) &&
- GetSearchTermsImpl(contents, entry).empty();
+ GURL new_tab_url(GetNewTabPageURL(profile));
+ return new_tab_url.is_valid() &&
+ search::MatchesOriginAndPath(entry->GetURL(), new_tab_url);
}
bool IsSuggestPrefEnabled(Profile* profile) {
@@ -458,9 +446,6 @@ std::vector<GURL> GetSearchURLs(Profile* profile) {
}
GURL GetNewTabPageURL(Profile* profile) {
- if (!ShouldUseCacheableNTP())
- return GURL();
-
if (!profile || profile->IsOffTheRecord())
return GURL();
@@ -488,9 +473,6 @@ GURL GetSearchResultPrefetchBaseURL(Profile* profile) {
}
bool ShouldPrefetchSearchResults() {
- if (!ShouldUseCacheableNTP())
- return false;
-
FieldTrialFlags flags;
return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
kPrefetchSearchResultsFlagName, false, flags);
@@ -506,23 +488,6 @@ bool ShouldHideTopVerbatimMatch() {
kHideVerbatimFlagName, false, flags);
}
-bool ShouldUseCacheableNTP() {
- FieldTrialFlags flags;
- return !GetFieldTrialInfo(&flags) || GetBoolValueForFlagWithDefault(
- kUseCacheableNTP, true, flags);
-}
-
-bool ShouldShowInstantNTP() {
- // If using the cacheable NTP, load the NTP directly instead of preloading its
- // contents using InstantNTP.
- if (ShouldUseCacheableNTP())
- return false;
-
- FieldTrialFlags flags;
- return !GetFieldTrialInfo(&flags) ||
- GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags);
-}
-
DisplaySearchButtonConditions GetDisplaySearchButtonConditions() {
const CommandLine* cl = CommandLine::ForCurrentProcess();
if (cl->HasSwitch(switches::kDisableSearchButtonInOmnibox)) {
@@ -591,43 +556,6 @@ GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
return effective_url;
}
-int GetInstantLoaderStalenessTimeoutSec() {
- int timeout_sec = kStalePageTimeoutDefault;
- FieldTrialFlags flags;
- if (GetFieldTrialInfo(&flags)) {
- timeout_sec = GetUInt64ValueForFlagWithDefault(kStalePageTimeoutFlagName,
- kStalePageTimeoutDefault,
- flags);
- }
-
- // Require a minimum 5 minute timeout.
- if (timeout_sec < 0 || (timeout_sec > 0 && timeout_sec < 300))
- timeout_sec = kStalePageTimeoutDefault;
-
- // Randomize by upto 15% either side.
- timeout_sec = base::RandInt(timeout_sec * 0.85, timeout_sec * 1.15);
-
- return timeout_sec;
-}
-
-bool IsPreloadedInstantExtendedNTP(const content::WebContents* contents) {
- if (!IsInstantExtendedAPIEnabled())
- return false;
-
- ProfileManager* profile_manager = g_browser_process->profile_manager();
- if (!profile_manager)
- return false; // The profile manager can be NULL while testing.
-
- const std::vector<Profile*>& profiles = profile_manager->GetLoadedProfiles();
- for (size_t i = 0; i < profiles.size(); ++i) {
- const InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profiles[i]);
- if (instant_service && instant_service->GetNTPContents() == contents)
- return true;
- }
- return false;
-}
-
bool HandleNewTabURLRewrite(GURL* url,
content::BrowserContext* browser_context) {
if (!IsInstantExtendedAPIEnabled())
diff --git a/chrome/browser/search/search.h b/chrome/browser/search/search.h
index f76635b..ec51732 100644
--- a/chrome/browser/search/search.h
+++ b/chrome/browser/search/search.h
@@ -146,13 +146,6 @@ GURL GetLocalInstantURL(Profile* profile);
// match. See comments on ShouldHideTopMatch in autocomplete_result.h.
bool ShouldHideTopVerbatimMatch();
-// Returns true if the cacheable NTP should be shown and false if not.
-// Exposed for testing.
-bool ShouldUseCacheableNTP();
-
-// Returns true if the Instant NTP should be shown and false if not.
-bool ShouldShowInstantNTP();
-
// Returns when we should show a search button in the omnibox. This may be any
// of several values, some of which depend on whether the underlying state of
// the page would normally be to perform search term replacement; see also
@@ -182,13 +175,6 @@ bool ShouldDisplayOriginChip();
// and hence different processes.
GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile);
-// Returns the staleness timeout (in seconds) that should be used to refresh the
-// InstantLoader.
-int GetInstantLoaderStalenessTimeoutSec();
-
-// Returns true if |contents| corresponds to a preloaded instant extended NTP.
-bool IsPreloadedInstantExtendedNTP(const content::WebContents* contents);
-
// Rewrites |url| if
// 1. |url| is kChromeUINewTabURL,
// 2. InstantExtended is enabled, and
diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc
index 49d15da..a91b9f3 100644
--- a/chrome/browser/search/search_unittest.cc
+++ b/chrome/browser/search/search_unittest.cc
@@ -428,29 +428,28 @@ TEST_F(SearchTest, ProcessIsolation_RendererInitiated) {
}
const SearchTestCase kInstantNTPTestCases[] = {
- {"https://foo.com/instant?strk", true, "Valid Instant URL"},
- {"https://foo.com/instant#strk", true, "Valid Instant URL"},
- {"https://foo.com/url?strk", true, "Valid search URL"},
- {"https://foo.com/url#strk", true, "Valid search URL"},
- {"https://foo.com/alt?strk", true, "Valid alternative URL"},
- {"https://foo.com/alt#strk", true, "Valid alternative URL"},
- {"https://foo.com/url?strk&bar=", true, "No query terms"},
- {"https://foo.com/url?strk&q=abc", true, "No query terms key"},
- {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"},
+ {"https://foo.com/instant?strk", false, "Valid Instant URL"},
+ {"https://foo.com/instant#strk", false, "Valid Instant URL"},
+ {"https://foo.com/url?strk", false, "Valid search URL"},
+ {"https://foo.com/url#strk", false, "Valid search URL"},
+ {"https://foo.com/alt?strk", false, "Valid alternative URL"},
+ {"https://foo.com/alt#strk", false, "Valid alternative URL"},
+ {"https://foo.com/url?strk&bar=", false, "No query terms"},
+ {"https://foo.com/url?strk&q=abc", false, "No query terms key"},
+ {"https://foo.com/url?strk#bar=abc", false, "Query terms key in ref"},
{"https://foo.com/url?strk&bar=abc", false, "Has query terms"},
{"http://foo.com/instant?strk=1", false, "Insecure URL"},
{"https://foo.com/instant", false, "No search term replacement"},
{"chrome://blank/", false, "Chrome scheme"},
{"chrome-search://foo", false, "Chrome-search scheme"},
- {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"},
{"https://bar.com/instant?strk=1", false, "Random non-search page"},
+ {chrome::kChromeSearchLocalNtpUrl, true, "Local new tab page"},
+ {"https://foo.com/newtab?strk", true, "New tab URL"},
+ {"http://foo.com/newtab?strk", false, "Insecure New tab URL"},
};
TEST_F(SearchTest, InstantNTPExtendedEnabled) {
EnableQueryExtractionForTesting();
- // TODO(samarth): update test cases to use cacheable NTP URLs and remove this.
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "InstantExtended", "Group1 use_cacheable_ntp:0"));
AddTab(browser(), GURL("chrome://blank"));
for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
const SearchTestCase& test = kInstantNTPTestCases[i];
@@ -464,9 +463,6 @@ TEST_F(SearchTest, InstantNTPExtendedEnabled) {
TEST_F(SearchTest, InstantNTPCustomNavigationEntry) {
EnableQueryExtractionForTesting();
- // TODO(samarth): update test cases to use cacheable NTP URLs and remove this.
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "InstantExtended", "Group1 use_cacheable_ntp:0"));
AddTab(browser(), GURL("chrome://blank"));
for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) {
const SearchTestCase& test = kInstantNTPTestCases[i];
@@ -491,9 +487,6 @@ TEST_F(SearchTest, InstantNTPCustomNavigationEntry) {
}
TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
-
AddTab(browser(), GURL("chrome://blank"));
content::WebContents* contents =
browser()->tab_strip_model()->GetWebContentsAt(0);
@@ -514,8 +507,6 @@ TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) {
}
TEST_F(SearchTest, InstantCacheableNTPNavigationEntryNewProfile) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
SetSearchProvider(false, false);
AddTab(browser(), GURL(chrome::kChromeUINewTabURL));
content::WebContents* contents =
@@ -531,15 +522,11 @@ TEST_F(SearchTest, InstantCacheableNTPNavigationEntryNewProfile) {
}
TEST_F(SearchTest, UseLocalNTPInIncognito) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
EXPECT_EQ(GURL(), chrome::GetNewTabPageURL(
profile()->GetOffTheRecordProfile()));
}
TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
// Set an insecure new tab page URL and verify that it's ignored.
SetSearchProvider(true, true);
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
@@ -547,8 +534,6 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsInsecure) {
}
TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
// Set an insecure new tab page URL and verify that it's ignored.
SetSearchProvider(false, true);
EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
@@ -556,9 +541,6 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsNotSet) {
}
TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
-
// Block access to foo.com in the URL filter.
ManagedUserService* managed_user_service =
ManagedUserServiceFactory::GetForProfile(profile());
@@ -665,40 +647,10 @@ TEST_F(SearchTest, CommandLineOverrides) {
EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec());
}
-TEST_F(SearchTest, ShouldShowInstantNTP_Default) {
- EXPECT_FALSE(ShouldShowInstantNTP());
-}
-
-TEST_F(SearchTest, ShouldShowInstantNTP_DisabledViaFinch) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 show_ntp:0"));
- EXPECT_FALSE(ShouldShowInstantNTP());
-}
-
-TEST_F(SearchTest, ShouldShowInstantNTP_DisabledByUseCacheableNTPFinchFlag) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
- EXPECT_FALSE(ShouldShowInstantNTP());
-}
-
-TEST_F(SearchTest, ShouldUseCacheableNTP_Default) {
- EXPECT_TRUE(ShouldUseCacheableNTP());
-}
-
-TEST_F(SearchTest, ShouldUseCacheableNTP_EnabledViaFinch) {
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
- EXPECT_TRUE(ShouldUseCacheableNTP());
-}
-
-TEST_F(SearchTest, ShouldPrefetchSearchResults_Default) {
- EXPECT_FALSE(ShouldPrefetchSearchResults());
-}
-
TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch",
- "Group1 espv:2 use_cacheable_ntp:1 prefetch_results:1"));
+ "Group1 espv:2 prefetch_results:1"));
EXPECT_TRUE(ShouldPrefetchSearchResults());
#if defined(OS_IOS) || defined(OS_ANDROID)
EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
@@ -710,7 +662,7 @@ TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) {
TEST_F(SearchTest, ShouldPrefetchSearchResults_DisabledViaFinch) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch",
- "Group1 use_cacheable_ntp:1 espv:89 prefetch_results:0"));
+ "Group1 espv:89 prefetch_results:0"));
EXPECT_FALSE(ShouldPrefetchSearchResults());
EXPECT_EQ(89ul, EmbeddedSearchPageVersion());
}
@@ -718,7 +670,7 @@ TEST_F(SearchTest, ShouldPrefetchSearchResults_DisabledViaFinch) {
TEST_F(SearchTest, ShouldPrefetchSearchResults_EnabledViaFinch) {
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch",
- "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1"));
+ "Group1 espv:80 prefetch_results:1"));
EXPECT_TRUE(ShouldPrefetchSearchResults());
EXPECT_EQ(80ul, EmbeddedSearchPageVersion());
}
@@ -763,7 +715,7 @@ TEST_F(SearchTest, GetSearchResultPrefetchBaseURL) {
// "prefetch_results" flag is enabled via field trials.
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"EmbeddedSearch",
- "Group1 espv:80 use_cacheable_ntp:1 prefetch_results:1"));
+ "Group1 espv:80 prefetch_results:1"));
EXPECT_TRUE(ShouldPrefetchSearchResults());
EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"),
diff --git a/chrome/browser/task_manager/extension_process_resource_provider.cc b/chrome/browser/task_manager/extension_process_resource_provider.cc
index 1db73a1..570061a 100644
--- a/chrome/browser/task_manager/extension_process_resource_provider.cc
+++ b/chrome/browser/task_manager/extension_process_resource_provider.cc
@@ -98,7 +98,6 @@ ExtensionProcessResource::ExtensionProcessResource(
true, // is_extension
profile->IsOffTheRecord(),
false, // is_prerender
- false, // is_instant_overlay
IsBackground());
title_ = l10n_util::GetStringFUTF16(message_id, extension_name);
}
diff --git a/chrome/browser/task_manager/panel_resource_provider.cc b/chrome/browser/task_manager/panel_resource_provider.cc
index 18ea3b5..8f65207 100644
--- a/chrome/browser/task_manager/panel_resource_provider.cc
+++ b/chrome/browser/task_manager/panel_resource_provider.cc
@@ -62,7 +62,6 @@ PanelResource::PanelResource(Panel* panel)
true, // is_extension
panel->profile()->IsOffTheRecord(),
false, // is_prerender
- false, // is_instant_overlay
false); // is_background
}
diff --git a/chrome/browser/task_manager/tab_contents_resource_provider.cc b/chrome/browser/task_manager/tab_contents_resource_provider.cc
index 8bf392a..af7115d 100644
--- a/chrome/browser/task_manager/tab_contents_resource_provider.cc
+++ b/chrome/browser/task_manager/tab_contents_resource_provider.cc
@@ -13,8 +13,6 @@
#include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/search/instant_service.h"
-#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/task_manager/renderer_resource.h"
@@ -89,7 +87,6 @@ class TabContentsResource : public RendererResource {
static gfx::ImageSkia* prerender_icon_;
content::WebContents* web_contents_;
Profile* profile_;
- bool is_instant_ntp_;
DISALLOW_COPY_AND_ASSIGN(TabContentsResource);
};
@@ -101,8 +98,7 @@ TabContentsResource::TabContentsResource(
: RendererResource(web_contents->GetRenderProcessHost()->GetHandle(),
web_contents->GetRenderViewHost()),
web_contents_(web_contents),
- profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
- is_instant_ntp_(chrome::IsPreloadedInstantExtendedNTP(web_contents)) {
+ profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
if (!prerender_icon_) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER);
@@ -138,7 +134,6 @@ base::string16 TabContentsResource::GetTitle() const {
HostsExtension(),
profile_->IsOffTheRecord(),
IsContentsPrerendering(web_contents_),
- is_instant_ntp_,
false); // is_background
return l10n_util::GetStringFUTF16(message_id, tab_title);
}
@@ -237,14 +232,6 @@ void TabContentsResourceProvider::StartUpdating() {
}
}
- // Add all the Instant Extended prerendered NTPs.
- for (size_t i = 0; i < profiles.size(); ++i) {
- const InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profiles[i]);
- if (instant_service && instant_service->GetNTPContents())
- Add(instant_service->GetNTPContents());
- }
-
#if defined(ENABLE_FULL_PRINTING)
// Add all the pages being background printed.
printing::BackgroundPrintingManager* printing_manager =
@@ -300,7 +287,6 @@ void TabContentsResourceProvider::Add(WebContents* web_contents) {
// pages, prerender pages, and background printed pages.
if (!chrome::FindBrowserWithWebContents(web_contents) &&
!IsContentsPrerendering(web_contents) &&
- !chrome::IsPreloadedInstantExtendedNTP(web_contents) &&
!IsContentsBackgroundPrinted(web_contents) &&
!DevToolsWindow::IsDevToolsWindow(web_contents->GetRenderViewHost())) {
return;
diff --git a/chrome/browser/task_manager/task_manager_util.cc b/chrome/browser/task_manager/task_manager_util.cc
index d584f90..b755e12 100644
--- a/chrome/browser/task_manager/task_manager_util.cc
+++ b/chrome/browser/task_manager/task_manager_util.cc
@@ -23,7 +23,6 @@ int GetMessagePrefixID(bool is_app,
bool is_extension,
bool is_incognito,
bool is_prerender,
- bool is_instant_overlay,
bool is_background) {
if (is_app) {
if (is_background)
@@ -39,8 +38,6 @@ int GetMessagePrefixID(bool is_app,
}
if (is_prerender)
return IDS_TASK_MANAGER_PRERENDER_PREFIX;
- if (is_instant_overlay)
- return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX;
if (is_incognito)
return IDS_TASK_MANAGER_TAB_INCOGNITO_PREFIX;
diff --git a/chrome/browser/task_manager/task_manager_util.h b/chrome/browser/task_manager/task_manager_util.h
index 1b95c16..409043b 100644
--- a/chrome/browser/task_manager/task_manager_util.h
+++ b/chrome/browser/task_manager/task_manager_util.h
@@ -24,7 +24,6 @@ int GetMessagePrefixID(bool is_app,
bool is_extension,
bool is_incognito,
bool is_prerender,
- bool is_instant_overlay,
bool is_background);
// Returns the name of profle from InfoCache.
diff --git a/chrome/browser/task_manager/task_manager_util_unittest.cc b/chrome/browser/task_manager/task_manager_util_unittest.cc
index 1949df5..a1f9ccf 100644
--- a/chrome/browser/task_manager/task_manager_util_unittest.cc
+++ b/chrome/browser/task_manager/task_manager_util_unittest.cc
@@ -18,28 +18,25 @@ TEST(TaskManagerUtilTest, GetMessagePrefixID) {
bool is_extension;
bool is_incognito;
bool is_prerender;
- bool is_instant_overlay;
bool is_background;
int expected_result;
};
const Configuration configs[] = {
// Use implicit int->bool conversion to save space and keep alignment.
- {1, 0, 0, 0, 0, 1, IDS_TASK_MANAGER_BACKGROUND_PREFIX},
- {1, 0, 1, 0, 0, 0, IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX},
- {1, 0, 0, 0, 0, 0, IDS_TASK_MANAGER_APP_PREFIX},
- {0, 1, 1, 0, 0, 0, IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX},
- {0, 1, 0, 0, 0, 0, IDS_TASK_MANAGER_EXTENSION_PREFIX},
- {0, 0, 0, 1, 0, 0, IDS_TASK_MANAGER_PRERENDER_PREFIX},
- {0, 0, 0, 0, 1, 0, IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX},
- {0, 0, 1, 0, 0, 0, IDS_TASK_MANAGER_TAB_INCOGNITO_PREFIX},
- {0, 0, 0, 0, 0, 0, IDS_TASK_MANAGER_TAB_PREFIX}};
+ {1, 0, 0, 0, 1, IDS_TASK_MANAGER_BACKGROUND_PREFIX},
+ {1, 0, 1, 0, 0, IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX},
+ {1, 0, 0, 0, 0, IDS_TASK_MANAGER_APP_PREFIX},
+ {0, 1, 1, 0, 0, IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX},
+ {0, 1, 0, 0, 0, IDS_TASK_MANAGER_EXTENSION_PREFIX},
+ {0, 0, 0, 1, 0, IDS_TASK_MANAGER_PRERENDER_PREFIX},
+ {0, 0, 1, 0, 0, IDS_TASK_MANAGER_TAB_INCOGNITO_PREFIX},
+ {0, 0, 0, 0, 0, IDS_TASK_MANAGER_TAB_PREFIX}};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(configs); ++i) {
EXPECT_EQ(configs[i].expected_result,
GetMessagePrefixID(configs[i].is_app,
configs[i].is_extension,
configs[i].is_incognito,
configs[i].is_prerender,
- configs[i].is_instant_overlay,
configs[i].is_background));
}
}
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index 97862d2..6a2ef8f 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -16,7 +16,6 @@
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
-#include "chrome/browser/ui/search/instant_ntp.h"
#include "chrome/browser/ui/search/instant_search_prerenderer.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
@@ -46,13 +45,11 @@ InstantSearchPrerenderer* GetInstantSearchPrerenderer(Profile* profile) {
BrowserInstantController::BrowserInstantController(Browser* browser)
: browser_(browser),
- instant_(this),
- instant_unload_handler_(browser) {
+ instant_(this) {
browser_->search_model()->AddObserver(this);
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile());
- instant_service->OnBrowserInstantControllerCreated();
instant_service->AddObserver(this);
}
@@ -62,62 +59,6 @@ BrowserInstantController::~BrowserInstantController() {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile());
instant_service->RemoveObserver(this);
- instant_service->OnBrowserInstantControllerDestroyed();
-}
-
-bool BrowserInstantController::MaybeSwapInInstantNTPContents(
- const GURL& url,
- content::WebContents* source_contents,
- content::WebContents** target_contents) {
- if (url != GURL(chrome::kChromeUINewTabURL))
- return false;
-
- GURL extension_url(url);
- if (ExtensionWebUI::HandleChromeURLOverride(&extension_url, profile())) {
- // If there is an extension overriding the NTP do not use the Instant NTP.
- return false;
- }
-
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile());
- scoped_ptr<content::WebContents> instant_ntp =
- instant_service->ReleaseNTPContents();
- if (!instant_ntp)
- return false;
-
- *target_contents = instant_ntp.get();
- if (source_contents) {
- // If the Instant NTP hasn't yet committed an entry, we can't call
- // CopyStateFromAndPrune. Instead, load the Local NTP URL directly in the
- // source contents.
- // TODO(sreeram): Always using the local URL is wrong in the case of the
- // first tab in a window where we might want to use the remote URL. Fix.
- if (!instant_ntp->GetController().CanPruneAllButLastCommitted()) {
- source_contents->GetController().LoadURL(chrome::GetLocalInstantURL(
- profile()), content::Referrer(), content::PAGE_TRANSITION_GENERATED,
- std::string());
- *target_contents = source_contents;
- } else {
- instant_ntp->GetController().CopyStateFromAndPrune(
- &source_contents->GetController(), false);
- ReplaceWebContentsAt(
- browser_->tab_strip_model()->GetIndexOfWebContents(source_contents),
- instant_ntp.Pass());
- }
- } else {
- // If the Instant NTP hasn't yet committed an entry, we can't call
- // PruneAllButLastCommitted. In that case, there shouldn't be any entries
- // to prune anyway.
- if (instant_ntp->GetController().CanPruneAllButLastCommitted())
- instant_ntp->GetController().PruneAllButLastCommitted();
- else
- CHECK(!instant_ntp->GetController().GetLastCommittedEntry());
-
- // If |source_contents| is NULL, then the caller is responsible for
- // inserting instant_ntp into the tabstrip and will take ownership.
- ignore_result(instant_ntp.release());
- }
- return true;
}
bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition,
@@ -156,16 +97,6 @@ Profile* BrowserInstantController::profile() const {
return browser_->profile();
}
-void BrowserInstantController::ReplaceWebContentsAt(
- int index,
- scoped_ptr<content::WebContents> new_contents) {
- DCHECK_NE(TabStripModel::kNoTab, index);
- scoped_ptr<content::WebContents> old_contents(browser_->tab_strip_model()->
- ReplaceWebContentsAt(index, new_contents.release()));
- instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents.Pass(),
- index);
-}
-
content::WebContents* BrowserInstantController::GetActiveWebContents() const {
return browser_->tab_strip_model()->GetActiveWebContents();
}
diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h
index 06450fd..6af5d03 100644
--- a/chrome/browser/ui/browser_instant_controller.h
+++ b/chrome/browser/ui/browser_instant_controller.h
@@ -11,7 +11,6 @@
#include "base/compiler_specific.h"
#include "chrome/browser/search/instant_service_observer.h"
#include "chrome/browser/ui/search/instant_controller.h"
-#include "chrome/browser/ui/search/instant_unload_handler.h"
#include "chrome/browser/ui/search/search_model_observer.h"
class Browser;
@@ -32,18 +31,6 @@ class BrowserInstantController : public SearchModelObserver,
explicit BrowserInstantController(Browser* browser);
virtual ~BrowserInstantController();
- // If |url| is the new tab page URL, set |target_contents| to the preloaded
- // NTP contents from InstantController. If |source_contents| is not NULL, we
- // replace it with the new |target_contents| in the tabstrip and delete
- // |source_contents|. Otherwise, the caller owns |target_contents| and is
- // responsible for inserting it into the tabstrip.
- //
- // Returns true if and only if we update |target_contents|.
- bool MaybeSwapInInstantNTPContents(
- const GURL& url,
- content::WebContents* source_contents,
- content::WebContents** target_contents);
-
// Commits the current Instant, returning true on success. This is intended
// for use from OpenCurrentURL.
bool OpenInstant(WindowOpenDisposition disposition, const GURL& url);
@@ -88,7 +75,6 @@ class BrowserInstantController : public SearchModelObserver,
Browser* const browser_;
InstantController instant_;
- InstantUnloadHandler instant_unload_handler_;
DISALLOW_COPY_AND_ASSIGN(BrowserInstantController);
};
diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc
index 957d87a..141783a 100644
--- a/chrome/browser/ui/browser_navigator.cc
+++ b/chrome/browser/ui/browser_navigator.cc
@@ -378,14 +378,6 @@ bool SwapInPrerender(const GURL& url, chrome::NavigateParams* params) {
prerender_manager->MaybeUsePrerenderedPage(url, params);
}
-bool SwapInInstantNTP(chrome::NavigateParams* params,
- const GURL& url,
- content::WebContents* source_contents) {
- BrowserInstantController* instant = params->browser->instant_controller();
- return instant && instant->MaybeSwapInInstantNTPContents(
- url, source_contents, &params->target_contents);
-}
-
chrome::HostDesktopType GetHostDesktop(Browser* browser) {
if (browser)
return browser->host_desktop_type();
@@ -582,8 +574,8 @@ void Navigate(NavigateParams* params) {
// Check if this is a singleton tab that already exists
int singleton_index = chrome::GetIndexOfSingletonTab(params);
- // Did we use Instant's NTP contents or a prerender?
- bool swapped_in = false;
+ // Did we use a prerender?
+ bool swapped_in_prerender = false;
// If no target WebContents was specified, we need to construct one if
// we are supposed to target a new tab; unless it's a singleton that already
@@ -599,9 +591,7 @@ void Navigate(NavigateParams* params) {
}
if (params->disposition != CURRENT_TAB) {
- swapped_in = SwapInInstantNTP(params, url, NULL);
- if (!swapped_in)
- params->target_contents = CreateTargetContents(*params, url);
+ params->target_contents = CreateTargetContents(*params, url);
// This function takes ownership of |params->target_contents| until it
// is added to a TabStripModel.
@@ -610,9 +600,7 @@ void Navigate(NavigateParams* params) {
// ... otherwise if we're loading in the current tab, the target is the
// same as the source.
DCHECK(params->source_contents);
- swapped_in = SwapInInstantNTP(params, url, params->source_contents);
- if (!swapped_in)
- params->target_contents = params->source_contents;
+ params->target_contents = params->source_contents;
DCHECK(params->target_contents);
// Prerender expects |params->target_contents| to be attached to a browser
// window, so only call for CURRENT_TAB navigations. (Others are currently
@@ -625,14 +613,13 @@ void Navigate(NavigateParams* params) {
// Therefore, we should swap in regardless of CURRENT_TAB, and instead,
// check in the swapin function whether the WebContents is not in a
// TabStrip model, in which case we must not swap in.
- if (!swapped_in)
- swapped_in = SwapInPrerender(url, params);
+ swapped_in_prerender = SwapInPrerender(url, params);
}
if (user_initiated)
params->target_contents->UserGestureDone();
- if (!swapped_in) {
+ if (!swapped_in_prerender) {
// Try to handle non-navigational URLs that popup dialogs and such, these
// should not actually navigate.
if (!HandleNonNavigationAboutURL(url)) {
@@ -665,7 +652,7 @@ void Navigate(NavigateParams* params) {
params->source_contents->GetView()->Focus();
if (params->source_contents == params->target_contents ||
- (swapped_in && params->disposition == CURRENT_TAB)) {
+ (swapped_in_prerender && params->disposition == CURRENT_TAB)) {
// The navigation occurred in the source tab.
params->browser->UpdateUIForNavigationInTab(params->target_contents,
params->transition,
diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc
index dea6d08..a5db87a21 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -117,29 +117,6 @@ void InstantController::SetSuggestionToPrefetch(
}
}
-void InstantController::InstantPageLoadFailed(content::WebContents* contents) {
- DCHECK(IsContentsFrom(instant_tab(), contents));
-
- // Verify we're not already on a local page and that the URL precisely
- // equals the instant_url (minus the query params, as those will be filled
- // in by template values). This check is necessary to make sure we don't
- // inadvertently redirect to the local NTP if someone, say, reloads a SRP
- // while offline, as a committed results page still counts as an instant
- // url. We also check to make sure there's no forward history, as if
- // someone hits the back button a lot when offline and returns to a NTP
- // we don't want to redirect and nuke their forward history stack.
- const GURL& current_url = contents->GetURL();
- GURL instant_url = chrome::GetInstantURL(profile(),
- chrome::kDisableStartMargin, false);
- if (instant_tab_->IsLocal() ||
- !search::MatchesOriginAndPath(instant_url, current_url) ||
- !current_url.ref().empty() ||
- contents->GetController().CanGoForward())
- return;
- LOG_INSTANT_DEBUG_EVENT(this, "InstantPageLoadFailed: instant_tab");
- RedirectToLocalNTP(contents);
-}
-
bool InstantController::SubmitQuery(const base::string16& search_terms) {
if (instant_tab_ && instant_tab_->supports_instant() &&
search_mode_.is_origin_search()) {
@@ -296,17 +273,6 @@ bool InstantController::IsInputInProgress() const {
omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE;
}
-void InstantController::RedirectToLocalNTP(content::WebContents* contents) {
- contents->GetController().LoadURL(
- GURL(chrome::kChromeSearchLocalNtpUrl),
- content::Referrer(),
- content::PAGE_TRANSITION_SERVER_REDIRECT,
- std::string()); // No extra headers.
- // TODO(dcblack): Remove extraneous history entry caused by 404s.
- // Note that the base case of a 204 being returned doesn't push a history
- // entry.
-}
-
InstantService* InstantController::GetInstantService() const {
return InstantServiceFactory::GetForProfile(profile());
}
diff --git a/chrome/browser/ui/search/instant_controller.h b/chrome/browser/ui/search/instant_controller.h
index 866ad2c..613ee25 100644
--- a/chrome/browser/ui/search/instant_controller.h
+++ b/chrome/browser/ui/search/instant_controller.h
@@ -116,18 +116,9 @@ class InstantController : public InstantPage::Delegate {
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ExtendedModeIsOn);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, MostVisited);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, NTPIsPreloaded);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInNewTab);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPIsUsedInSameTab);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPForWrongProvider);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, PreloadedNTPRenderProcessGone);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest,
- PreloadedNTPDoesntSupportInstant);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, UnrelatedSiteInstance);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, OnDefaultSearchProviderChanged);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedNetworkTest,
- NTPReactsToNetworkChanges);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest,
AcceptingURLSearchDoesNotNavigate);
FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, AcceptingJSSearchDoesNotRunJS);
@@ -154,7 +145,6 @@ class InstantController : public InstantPage::Delegate {
virtual void InstantPageAboutToNavigateMainFrame(
const content::WebContents* contents,
const GURL& url) OVERRIDE;
- virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE;
// Helper function to navigate the given contents to the local fallback
// Instant URL and trim the history correctly.
diff --git a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
index 8375241..dfbba48 100644
--- a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
+++ b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
@@ -46,8 +46,6 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
-#include "chrome/browser/ui/search/instant_ntp.h"
-#include "chrome/browser/ui/search/instant_ntp_prerenderer.h"
#include "chrome/browser/ui/search/instant_tab.h"
#include "chrome/browser/ui/search/instant_test_utils.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
@@ -153,7 +151,9 @@ class InstantExtendedTest : public InProcessBrowserTest,
ASSERT_TRUE(https_test_server().Start());
GURL instant_url = https_test_server().GetURL(
"files/instant_extended.html?strk=1&");
- InstantTestBase::Init(instant_url, false);
+ GURL ntp_url = https_test_server().GetURL(
+ "files/instant_extended_ntp.html?strk=1&");
+ InstantTestBase::Init(instant_url, ntp_url, false);
}
int64 GetHistogramCount(const char* name) {
@@ -167,24 +167,6 @@ class InstantExtendedTest : public InProcessBrowserTest,
return histogram->SnapshotSamples()->TotalCount();
}
- void SendDownArrow() {
- omnibox()->model()->OnUpOrDownKeyPressed(1);
- // Wait for JavaScript to run the key handler by executing a blank script.
- EXPECT_TRUE(ExecuteScript(std::string()));
- }
-
- void SendUpArrow() {
- omnibox()->model()->OnUpOrDownKeyPressed(-1);
- // Wait for JavaScript to run the key handler by executing a blank script.
- EXPECT_TRUE(ExecuteScript(std::string()));
- }
-
- void SendEscape() {
- omnibox()->model()->OnEscapeKeyPressed();
- // Wait for JavaScript to run the key handler by executing a blank script.
- EXPECT_TRUE(ExecuteScript(std::string()));
- }
-
bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT {
return GetIntFromJS(contents, "onMostVisitedChangedCalls",
&on_most_visited_change_calls_) &&
@@ -279,13 +261,15 @@ class InstantExtendedPrefetchTest : public InstantExtendedTest {
ASSERT_TRUE(https_test_server().Start());
GURL instant_url = https_test_server().GetURL(
"files/instant_extended.html?strk=1&");
- InstantTestBase::Init(instant_url, true);
+ GURL ntp_url = https_test_server().GetURL(
+ "files/instant_extended_ntp.html?strk=1&");
+ InstantTestBase::Init(instant_url, ntp_url, true);
}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitchASCII(
switches::kForceFieldTrials,
- "EmbeddedSearch/Group11 prefetch_results_srp:1 use_cacheable_ntp:0/");
+ "EmbeddedSearch/Group11 prefetch_results_srp:1/");
}
net::FakeURLFetcherFactory* fake_factory() { return fake_factory_.get(); }
@@ -335,7 +319,9 @@ class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase {
ASSERT_TRUE(https_test_server().Start());
GURL instant_url = https_test_server().GetURL(
"files/instant_extended.html?strk=1&");
- InstantTestBase::Init(instant_url, false);
+ GURL ntp_url = https_test_server().GetURL(
+ "files/instant_extended_ntp.html?strk=1&");
+ InstantTestBase::Init(instant_url, ntp_url, false);
}
void InstallThemeSource() {
@@ -366,84 +352,9 @@ class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase {
DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest);
};
-IN_PROC_BROWSER_TEST_F(InstantExtendedNetworkTest, NTPReactsToNetworkChanges) {
- // Setup Instant.
- ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
-
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(browser()->profile());
- ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
-
- // The setup first initializes the platform specific NetworkChangeNotifier.
- // The InstantExtendedNetworkTest replaces it with a fake, but by the time,
- // InstantNTPPrerenderer has already registered itself. So the
- // InstantNTPPrerenderer needs to register itself as NetworkChangeObserver
- // again.
- net::NetworkChangeNotifier::AddNetworkChangeObserver(
- instant_service->ntp_prerenderer());
-
- // The fake network change notifier will provide the network state to be
- // offline, so the ntp will be local.
- ASSERT_NE(static_cast<InstantNTP*>(NULL),
- instant_service->ntp_prerenderer()->ntp());
- EXPECT_TRUE(instant_service->ntp_prerenderer()->ntp()->IsLocal());
-
- // Change the connect state, and wait for the notifications to be run, and NTP
- // support to be determined.
- SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET);
- FocusOmniboxAndWaitForInstantNTPSupport();
-
- // Verify the network state is fine, and InstantNTPPrerenderer doesn't want
- // to switch to local NTP anymore.
- EXPECT_FALSE(net::NetworkChangeNotifier::IsOffline());
- EXPECT_FALSE(instant_service->ntp_prerenderer()->ShouldSwitchToLocalNTP());
-
- // Open new tab.
- ui_test_utils::NavigateToURLWithDisposition(
- browser(),
- GURL(chrome::kChromeUINewTabURL),
- NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
- content::WebContents* active_tab =
- browser()->tab_strip_model()->GetActiveWebContents();
-
- // Verify new NTP is not local.
- EXPECT_TRUE(chrome::IsInstantNTP(active_tab));
- EXPECT_NE(instant_service->ntp_prerenderer()->GetLocalInstantURL(),
- active_tab->GetURL().spec());
- ASSERT_NE(static_cast<InstantNTP*>(NULL),
- instant_service->ntp_prerenderer()->ntp());
- EXPECT_FALSE(instant_service->ntp_prerenderer()->ntp()->IsLocal());
-
- SetConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE);
- FocusOmniboxAndWaitForInstantNTPSupport();
-
- // Verify the network state is fine, and InstantNTPPrerenderer doesn't want
- // to switch to local NTP anymore.
- EXPECT_TRUE(net::NetworkChangeNotifier::IsOffline());
- EXPECT_TRUE(instant_service->ntp_prerenderer()->ShouldSwitchToLocalNTP());
-
- // Open new tab. Preloaded NTP contents should have been used.
- ui_test_utils::NavigateToURLWithDisposition(
- browser(),
- GURL(chrome::kChromeUINewTabURL),
- NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
- active_tab = browser()->tab_strip_model()->GetActiveWebContents();
-
- // Verify new NTP is not local.
- EXPECT_TRUE(chrome::IsInstantNTP(active_tab));
- EXPECT_EQ(instant_service->ntp_prerenderer()->GetLocalInstantURL(),
- active_tab->GetURL().spec());
- ASSERT_NE(static_cast<InstantNTP*>(NULL),
- instant_service->ntp_prerenderer()->ntp());
- EXPECT_TRUE(instant_service->ntp_prerenderer()->ntp()->IsLocal());
-}
-
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
@@ -472,7 +383,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) {
IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
SearchDoesntReuseInstantTabWithoutSupport) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Don't wait for the navigation to complete.
SetOmniboxText("flowers");
@@ -490,7 +401,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
TypedSearchURLDoesntReuseInstantTab) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Create an observer to wait for the instant tab to support Instant.
content::WindowedNotificationObserver observer_1(
@@ -522,7 +433,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Create an observer to wait for the instant tab to support Instant.
content::WindowedNotificationObserver observer(
@@ -545,14 +456,14 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) {
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) {
// Initialize Instant.
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
- // Open new tab. Preloaded NTP contents should have been used.
+ // Open new tab.
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_EQ(2, browser()->tab_strip_model()->count());
// Make sure new tab received the onmostvisitedchanged event once.
@@ -577,7 +488,6 @@ IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) {
InstallThemeSource();
ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme"));
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
// The "Instant" New Tab should have access to chrome-search: scheme but not
// chrome: scheme.
@@ -585,7 +495,8 @@ IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) {
browser(),
GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_NONE);
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
content::RenderViewHost* rvh =
browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost();
@@ -604,18 +515,18 @@ IN_PROC_BROWSER_TEST_F(InstantPolicyTest,
NoThemeBackgroundChangeEventOnTabSwitch) {
InstallThemeSource();
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
// Install a theme.
ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme"));
EXPECT_EQ(1, browser()->tab_strip_model()->count());
- // Open new tab. Preloaded NTP contents should have been used.
+ // Open new tab.
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_NONE);
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_EQ(2, browser()->tab_strip_model()->count());
content::WebContents* active_tab =
@@ -653,17 +564,17 @@ IN_PROC_BROWSER_TEST_F(InstantPolicyTest,
MAYBE_SendThemeBackgroundChangedEvent) {
InstallThemeSource();
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
// Install a theme.
ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme"));
- // Open new tab. Preloaded NTP contents should have been used.
+ // Open new tab.
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_NONE);
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_EQ(2, browser()->tab_strip_model()->count());
// Make sure new tab received an onthemechanged event.
@@ -698,7 +609,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
// Focus omnibox and confirm overlay isn't shown.
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Create an observer to wait for the instant tab to support Instant.
content::WindowedNotificationObserver observer(
@@ -745,7 +656,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
// Focus omnibox and confirm overlay isn't shown.
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Create an observer to wait for the instant tab to support Instant.
content::WindowedNotificationObserver observer(
@@ -798,14 +709,15 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
// Flaky on all bots since re-enabled in r208032, crbug.com/253092
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_NavigateBackToNTP) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Open a new tab page.
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_EQ(2, browser()->tab_strip_model()->count());
content::WindowedNotificationObserver observer(
@@ -858,14 +770,15 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
DISABLED_DispatchMVChangeEventWhileNavigatingBackToNTP) {
// Setup Instant.
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
- // Open new tab. Preloaded NTP contents should have been used.
+ // Open new tab.
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL(chrome::kChromeUINewTabURL),
NEW_FOREGROUND_TAB,
- ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
content::WebContents* active_tab =
browser()->tab_strip_model()->GetActiveWebContents();
@@ -899,7 +812,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, SetPrefetchQuery) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
content::WindowedNotificationObserver new_tab_observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
@@ -959,7 +872,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, SetPrefetchQuery) {
IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, ClearPrefetchedResults) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
content::WindowedNotificationObserver new_tab_observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
@@ -1051,7 +964,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) {
GURL result_url =
test_server()->GetURL("files/referrer_policy/referrer-policy-log.html");
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Type a query and press enter to get results.
SetOmniboxText("query");
diff --git a/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc b/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc
index 29a6c81..aef6ca8 100644
--- a/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc
+++ b/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc
@@ -13,7 +13,6 @@
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
-#include "chrome/browser/ui/search/instant_ntp_prerenderer.h"
#include "chrome/browser/ui/search/instant_test_utils.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/omnibox_focus_state.h"
@@ -93,36 +92,10 @@ class InstantExtendedManualTest : public InProcessBrowserTest,
disable_network_change_notifier_;
};
-IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_ShowsGoogleNTP) {
- set_browser(browser());
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(browser()->profile());
- ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
- instant_service->ntp_prerenderer()->ReloadInstantNTP();
-
- FocusOmniboxAndWaitForInstantNTPSupport();
- content::WindowedNotificationObserver observer(
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources());
- ui_test_utils::NavigateToURLWithDisposition(
- browser(),
- GURL(chrome::kChromeUINewTabURL),
- CURRENT_TAB,
- ui_test_utils::BROWSER_TEST_NONE);
- observer.Wait();
- content::WebContents* active_tab =
- browser()->tab_strip_model()->GetActiveWebContents();
- EXPECT_TRUE(IsGooglePage(active_tab));
-}
-
IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_SearchesFromFakebox) {
set_browser(browser());
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(browser()->profile());
- ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
- instant_service->ntp_prerenderer()->ReloadInstantNTP();
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Open a new tab page.
content::WindowedNotificationObserver observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
diff --git a/chrome/browser/ui/search/instant_loader.cc b/chrome/browser/ui/search/instant_loader.cc
deleted file mode 100644
index 302a5ac..0000000
--- a/chrome/browser/ui/search/instant_loader.cc
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/search/instant_loader.h"
-
-#include "chrome/browser/content_settings/tab_specific_content_settings.h"
-#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
-#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
-#include "chrome/browser/search/search.h"
-#include "chrome/browser/tab_contents/tab_util.h"
-#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
-#include "chrome/browser/ui/search/search_tab_helper.h"
-#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/browser/notification_types.h"
-#include "content/public/browser/site_instance.h"
-#include "content/public/browser/web_contents_view.h"
-#include "grit/generated_resources.h"
-#include "ui/base/l10n/l10n_util.h"
-
-#if !defined(OS_ANDROID)
-#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
-#endif
-
-namespace {
-
-// This HTTP header and value are set on loads that originate from Instant.
-const char kInstantHeader[] = "X-Purpose: Instant";
-
-} // namespace
-
-InstantLoader::Delegate::~Delegate() {
-}
-
-InstantLoader::InstantLoader(Delegate* delegate)
- : delegate_(delegate), stale_page_timer_(false, false) {}
-
-InstantLoader::~InstantLoader() {
-}
-
-void InstantLoader::Init(const GURL& instant_url,
- Profile* profile,
- const base::Closure& on_stale_callback) {
- content::WebContents::CreateParams create_params(profile);
- create_params.site_instance = content::SiteInstance::CreateForURL(
- profile, instant_url);
- SetContents(scoped_ptr<content::WebContents>(
- content::WebContents::Create(create_params)));
- instant_url_ = instant_url;
- on_stale_callback_ = on_stale_callback;
-}
-
-void InstantLoader::Load() {
- DVLOG(1) << "LoadURL: " << instant_url_;
- contents_->GetController().LoadURL(
- instant_url_, content::Referrer(),
- content::PAGE_TRANSITION_GENERATED, kInstantHeader);
-
- // Explicitly set the new tab title and virtual URL.
- //
- // This ensures that the title is set even before we get a title from the
- // page, preventing a potential flicker of the URL, and also ensures that
- // (unless overridden by the page) the new tab title matches the browser UI
- // locale.
- content::NavigationEntry* entry =
- contents_->GetController().GetVisibleEntry();
- if (entry)
- entry->SetTitle(l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
-
- contents_->WasHidden();
-
- int staleness_timeout_ms = chrome::GetInstantLoaderStalenessTimeoutSec() *
- 1000;
- if (staleness_timeout_ms > 0) {
- stale_page_timer_.Start(
- FROM_HERE,
- base::TimeDelta::FromMilliseconds(staleness_timeout_ms),
- on_stale_callback_);
- }
-}
-
-void InstantLoader::SetContents(scoped_ptr<content::WebContents> new_contents) {
- contents_.reset(new_contents.release());
- contents_->SetDelegate(this);
-
- // Set up various tab helpers. The rest will get attached when (if) the
- // contents is added to the tab strip.
-
- // Bookmarks (Users can bookmark the Instant NTP. This ensures the bookmarked
- // state is correctly set when the contents are swapped into a tab.)
- BookmarkTabHelper::CreateForWebContents(contents());
-
- // A tab helper to catch prerender content swapping shenanigans.
- CoreTabHelper::CreateForWebContents(contents());
- CoreTabHelper::FromWebContents(contents())->set_delegate(this);
-
- SearchTabHelper::CreateForWebContents(contents());
-
-#if !defined(OS_ANDROID)
- // Observers.
- extensions::WebNavigationTabObserver::CreateForWebContents(contents());
-#endif // OS_ANDROID
-
- // Favicons, required by the Task Manager.
- FaviconTabHelper::CreateForWebContents(contents());
-
- // And some flat-out paranoia.
- safe_browsing::SafeBrowsingTabObserver::CreateForWebContents(contents());
-
- // When the WebContents finishes loading it should be checked to ensure that
- // it is in the instant process.
- registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
- content::Source<content::WebContents>(contents_.get()));
-}
-
-scoped_ptr<content::WebContents> InstantLoader::ReleaseContents() {
- stale_page_timer_.Stop();
- contents_->SetDelegate(NULL);
-
- // Undo tab helper work done in SetContents().
- CoreTabHelper::FromWebContents(contents())->set_delegate(NULL);
-
- registrar_.Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
- content::Source<content::WebContents>(contents_.get()));
- return contents_.Pass();
-}
-
-void InstantLoader::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
- const content::WebContents* web_contents =
- content::Source<content::WebContents>(source).ptr();
- DCHECK_EQ(contents_.get(), web_contents);
- delegate_->LoadCompletedMainFrame();
-}
-
-void InstantLoader::SwapTabContents(content::WebContents* old_contents,
- content::WebContents* new_contents) {
- DCHECK_EQ(old_contents, contents());
- // We release here without deleting since the caller has the responsibility
- // for deleting the old WebContents.
- ignore_result(ReleaseContents().release());
- SetContents(scoped_ptr<content::WebContents>(new_contents));
- delegate_->OnSwappedContents();
-}
-
-bool InstantLoader::ShouldSuppressDialogs() {
- // Messages shown during Instant cancel Instant, so we suppress them.
- return true;
-}
-
-bool InstantLoader::ShouldFocusPageAfterCrash() {
- return false;
-}
-
-void InstantLoader::CanDownload(content::RenderViewHost* /* render_view_host */,
- int /* request_id */,
- const std::string& /* request_method */,
- const base::Callback<void(bool)>& callback) {
- // Downloads are disabled.
- callback.Run(false);
-}
-
-bool InstantLoader::OnGoToEntryOffset(int /* offset */) {
- return false;
-}
-
-content::WebContents* InstantLoader::OpenURLFromTab(
- content::WebContents* source,
- const content::OpenURLParams& params) {
- return delegate_->OpenURLFromTab(source, params);
-}
diff --git a/chrome/browser/ui/search/instant_loader.h b/chrome/browser/ui/search/instant_loader.h
deleted file mode 100644
index f47bb9f..0000000
--- a/chrome/browser/ui/search/instant_loader.h
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_LOADER_H_
-#define CHROME_BROWSER_UI_SEARCH_INSTANT_LOADER_H_
-
-#include "base/basictypes.h"
-#include "base/callback.h"
-#include "base/compiler_specific.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/timer/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"
-
-class GURL;
-class Profile;
-
-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 InstantNTP to preload an Instant page.
-class InstantLoader : public content::NotificationObserver,
- public content::WebContentsDelegate,
- public CoreTabHelperDelegate {
- 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 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;
-
- // Called when a main frame load is complete.
- virtual void LoadCompletedMainFrame() = 0;
-
- protected:
- ~Delegate();
- };
-
- explicit InstantLoader(Delegate* delegate);
- 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. |on_stale_callback| will be called after kStalePageTimeoutMS
- // has elapsed after Load() being called.
- void Init(const GURL& instant_url,
- Profile* profile,
- const base::Closure& on_stale_callback);
-
- // Loads |instant_url_| in |contents_|.
- void Load();
-
- // 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();
-
- 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 CanDownload(content::RenderViewHost* render_view_host,
- int request_id,
- const std::string& request_method,
- const base::Callback<void(bool)>& callback) 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_;
-
- DISALLOW_COPY_AND_ASSIGN(InstantLoader);
-};
-
-#endif // CHROME_BROWSER_UI_SEARCH_INSTANT_LOADER_H_
diff --git a/chrome/browser/ui/search/instant_ntp.cc b/chrome/browser/ui/search/instant_ntp.cc
deleted file mode 100644
index 303fc33..0000000
--- a/chrome/browser/ui/search/instant_ntp.cc
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/search/instant_ntp.h"
-
-#include "base/metrics/histogram.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/search/instant_ntp_prerenderer.h"
-#include "chrome/browser/ui/search/search_tab_helper.h"
-#include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
-#include "content/public/browser/web_contents.h"
-#include "url/gurl.h"
-
-InstantNTP::InstantNTP(InstantNTPPrerenderer* ntp_prerenderer,
- const std::string& instant_url,
- Profile* profile)
- : InstantPage(ntp_prerenderer, instant_url, profile,
- profile->IsOffTheRecord()),
- loader_(this),
- ntp_prerenderer_(ntp_prerenderer) {
-}
-
-InstantNTP::~InstantNTP() {
- if (contents())
- ReleaseContents().reset();
-}
-
-void InstantNTP::InitContents(const base::Closure& on_stale_callback) {
- DCHECK(!contents());
- GURL instantNTP_url(instant_url());
- loader_.Init(instantNTP_url, profile(), on_stale_callback);
- SetContents(loader_.contents());
- content::WebContents* content = contents();
- SearchTabHelper::FromWebContents(content)->InitForPreloadedNTP();
-
- loader_.Load();
-}
-
-scoped_ptr<content::WebContents> InstantNTP::ReleaseContents() {
- SetContents(NULL);
- return loader_.ReleaseContents();
-}
-
-void InstantNTP::LoadCompletedMainFrame() {
- ntp_prerenderer_->LoadCompletedMainFrame();
-}
-
-void InstantNTP::RenderProcessGone(base::TerminationStatus /* status */) {
- ntp_prerenderer_->RenderProcessGone();
-}
-
-void InstantNTP::OnSwappedContents() {
- SetContents(loader_.contents());
-}
-
-content::WebContents* InstantNTP::OpenURLFromTab(
- content::WebContents* source,
- const content::OpenURLParams& params) {
- return NULL;
-}
diff --git a/chrome/browser/ui/search/instant_ntp.h b/chrome/browser/ui/search/instant_ntp.h
deleted file mode 100644
index e630d36..0000000
--- a/chrome/browser/ui/search/instant_ntp.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_H_
-#define CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/ui/search/instant_loader.h"
-#include "chrome/browser/ui/search/instant_page.h"
-
-class InstantNTPPrerenderer;
-class Profile;
-
-namespace content {
-class RenderViewHost;
-class WebContents;
-}
-
-// InstantNTP is used to preload an Instant page that will be swapped in when a
-// user navigates to a New Tab Page (NTP). The InstantNTP contents are never
-// shown in an un-committed state.
-class InstantNTP : public InstantPage,
- public InstantLoader::Delegate {
- public:
- InstantNTP(InstantNTPPrerenderer* delegate,
- const std::string& instant_url,
- Profile* profile);
- virtual ~InstantNTP();
-
- // Creates a new WebContents and loads |instant_url_| into it.
- // |on_stale_callback| will be called when |loader_| determines the page to
- // be stale.
- void InitContents(const base::Closure& on_stale_callback);
-
- // Releases the WebContents for the Instant page. This should be called when
- // the page is about to be committed.
- scoped_ptr<content::WebContents> ReleaseContents();
-
- private:
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedNetworkTest,
- NTPReactsToNetworkChanges);
-
- // Overridden from content::WebContentsObserver:
- virtual void RenderProcessGone(
- base::TerminationStatus status) OVERRIDE;
-
- // Overridden from InstantLoader::Delegate:
- virtual void OnSwappedContents() OVERRIDE;
- virtual content::WebContents* OpenURLFromTab(
- content::WebContents* source,
- const content::OpenURLParams& params) OVERRIDE;
- virtual void LoadCompletedMainFrame() OVERRIDE;
-
- InstantLoader loader_;
- InstantNTPPrerenderer* const ntp_prerenderer_;
-
- DISALLOW_COPY_AND_ASSIGN(InstantNTP);
-};
-
-#endif // CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_H_
diff --git a/chrome/browser/ui/search/instant_ntp_prerenderer.cc b/chrome/browser/ui/search/instant_ntp_prerenderer.cc
deleted file mode 100644
index ee698fb..0000000
--- a/chrome/browser/ui/search/instant_ntp_prerenderer.cc
+++ /dev/null
@@ -1,269 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/search/instant_ntp_prerenderer.h"
-
-#include "base/basictypes.h"
-#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
-#include "base/prefs/pref_service.h"
-#include "build/build_config.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/content_settings/content_settings_provider.h"
-#include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/search/instant_service.h"
-#include "chrome/browser/search/instant_service_factory.h"
-#include "chrome/browser/search/search.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_finder.h"
-#include "chrome/browser/ui/host_desktop.h"
-#include "chrome/browser/ui/search/instant_ntp.h"
-#include "chrome/browser/ui/tabs/tab_strip_model.h"
-#include "chrome/common/content_settings.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/common/search_urls.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/web_contents.h"
-#include "net/base/network_change_notifier.h"
-
-namespace {
-
-void DeleteNTPSoon(scoped_ptr<InstantNTP> ntp) {
- if (!ntp)
- return;
-
- if (ntp->contents()) {
- base::MessageLoop::current()->DeleteSoon(
- FROM_HERE, ntp->ReleaseContents().release());
- }
- base::MessageLoop::current()->DeleteSoon(FROM_HERE, ntp.release());
-}
-
-} // namespace
-
-
-InstantNTPPrerenderer::InstantNTPPrerenderer(Profile* profile,
- InstantService* instant_service,
- PrefService* prefs)
- : profile_(profile) {
- DCHECK(profile);
-
- // In unit tests, prefs may be NULL.
- if (prefs) {
- profile_pref_registrar_.Init(prefs);
- profile_pref_registrar_.Add(
- prefs::kSearchSuggestEnabled,
- base::Bind(&InstantNTPPrerenderer::ReloadInstantNTP,
- base::Unretained(this)));
- }
- net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
-
- // Allow instant_service to be null for unit tets.
- if (instant_service)
- instant_service->AddObserver(this);
-}
-
-InstantNTPPrerenderer::~InstantNTPPrerenderer() {
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile_);
- if (instant_service)
- instant_service->RemoveObserver(this);
- net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
-}
-
-void InstantNTPPrerenderer::ReloadInstantNTP() {
- ResetNTP(GetInstantURL());
-}
-
-scoped_ptr<content::WebContents> InstantNTPPrerenderer::ReleaseNTPContents() {
- if (!profile_ || profile_->IsOffTheRecord() ||
- !chrome::ShouldShowInstantNTP())
- return scoped_ptr<content::WebContents>();
-
- if (ShouldSwitchToLocalNTP())
- ResetNTP(GetLocalInstantURL());
-
- scoped_ptr<content::WebContents> ntp_contents = ntp_->ReleaseContents();
-
- // Preload a new InstantNTP.
- ReloadInstantNTP();
- return ntp_contents.Pass();
-}
-
-content::WebContents* InstantNTPPrerenderer::GetNTPContents() const {
- return ntp() ? ntp()->contents() : NULL;
-}
-
-void InstantNTPPrerenderer::DeleteNTPContents() {
- if (ntp_)
- ntp_.reset();
-}
-
-void InstantNTPPrerenderer::RenderProcessGone() {
- DeleteNTPSoon(ntp_.Pass());
-}
-
-void InstantNTPPrerenderer::LoadCompletedMainFrame() {
- if (!ntp_ || ntp_->supports_instant())
- return;
-
- content::WebContents* ntp_contents = ntp_->contents();
- DCHECK(ntp_contents);
-
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profile());
- if (instant_service &&
- instant_service->IsInstantProcess(
- ntp_contents->GetRenderProcessHost()->GetID())) {
- return;
- }
- InstantSupportDetermined(ntp_contents, false);
-}
-
-std::string InstantNTPPrerenderer::GetLocalInstantURL() const {
- return chrome::GetLocalInstantURL(profile_).spec();
-}
-
-std::string InstantNTPPrerenderer::GetInstantURL() const {
- if (net::NetworkChangeNotifier::IsOffline())
- return GetLocalInstantURL();
-
- // TODO(kmadhusu): Remove start margin param from chrome::GetInstantURL().
- const GURL instant_url = chrome::GetInstantURL(profile_,
- chrome::kDisableStartMargin,
- false);
- if (!instant_url.is_valid())
- return GetLocalInstantURL();
-
- return instant_url.spec();
-}
-
-bool InstantNTPPrerenderer::IsJavascriptEnabled() const {
- GURL instant_url(GetInstantURL());
- GURL origin(instant_url.GetOrigin());
- ContentSetting js_setting = profile_->GetHostContentSettingsMap()->
- GetContentSetting(origin, origin, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
- NO_RESOURCE_IDENTIFIER);
- // Javascript can be disabled either in content settings or via a WebKit
- // preference, so check both. Disabling it through the Settings page affects
- // content settings. I'm not sure how to disable the WebKit preference, but
- // it's theoretically possible some users have it off.
- bool js_content_enabled =
- js_setting == CONTENT_SETTING_DEFAULT ||
- js_setting == CONTENT_SETTING_ALLOW;
- bool js_webkit_enabled = profile_->GetPrefs()->GetBoolean(
- prefs::kWebKitJavascriptEnabled);
- return js_content_enabled && js_webkit_enabled;
-}
-
-bool InstantNTPPrerenderer::InStartup() const {
-#if !defined(OS_ANDROID)
- // TODO(kmadhusu): This is not completely reliable. Find a better way to
- // detect startup time.
- Browser* browser = chrome::FindBrowserWithProfile(profile_,
- chrome::GetActiveDesktop());
- return !browser || !browser->tab_strip_model()->GetActiveWebContents();
-#endif
- return false;
-}
-
-InstantNTP* InstantNTPPrerenderer::ntp() const {
- return ntp_.get();
-}
-
-void InstantNTPPrerenderer::OnNetworkChanged(
- net::NetworkChangeNotifier::ConnectionType type) {
- // Not interested in events conveying change to offline.
- if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
- return;
-
- if (!ntp() || ntp()->IsLocal())
- ReloadInstantNTP();
-}
-
-void InstantNTPPrerenderer::InstantSupportDetermined(
- const content::WebContents* contents,
- bool supports_instant) {
- DCHECK(ntp() && ntp()->contents() == contents);
-
- if (!supports_instant) {
- bool is_local = ntp()->IsLocal();
- DeleteNTPSoon(ntp_.Pass());
- if (!is_local)
- ResetNTP(GetLocalInstantURL());
- }
-
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED,
- content::Source<InstantNTPPrerenderer>(this),
- content::NotificationService::NoDetails());
-}
-
-void InstantNTPPrerenderer::InstantPageAboutToNavigateMainFrame(
- const content::WebContents* /* contents */,
- const GURL& /* url */) {
- NOTREACHED();
-}
-
-void InstantNTPPrerenderer::InstantPageLoadFailed(
- content::WebContents* contents) {
- DCHECK(ntp() && ntp()->contents() == contents);
-
- bool is_local = ntp()->IsLocal();
- DeleteNTPSoon(ntp_.Pass());
- if (!is_local)
- ResetNTP(GetLocalInstantURL());
-}
-
-void InstantNTPPrerenderer::ResetNTP(const std::string& instant_url) {
- // Instant NTP is only used in extended mode so we should always have a
- // non-empty URL to use.
- DCHECK(!instant_url.empty());
- if (!chrome::ShouldUseCacheableNTP()) {
- ntp_.reset(new InstantNTP(this, instant_url, profile_));
- ntp_->InitContents(base::Bind(&InstantNTPPrerenderer::ReloadInstantNTP,
- base::Unretained(this)));
- }
-}
-
-bool InstantNTPPrerenderer::PageIsCurrent() const {
- const std::string& instant_url = GetInstantURL();
- if (instant_url.empty() ||
- !search::MatchesOriginAndPath(GURL(ntp()->instant_url()),
- GURL(instant_url)))
- return false;
-
- return ntp()->supports_instant();
-}
-
-bool InstantNTPPrerenderer::ShouldSwitchToLocalNTP() const {
- if (!ntp())
- return true;
-
- // Assume users with Javascript disabled do not want the online experience.
- if (!IsJavascriptEnabled())
- return true;
-
- // Already a local page. Not calling IsLocal() because we want to distinguish
- // between the Google-specific and generic local NTP.
- if (ntp()->instant_url() == GetLocalInstantURL())
- return false;
-
- if (PageIsCurrent())
- return false;
-
- // The preloaded NTP does not support instant yet. If we're not in startup,
- // always fall back to the local NTP. If we are in startup, use the local NTP.
- return !InStartup();
-}
-
-void InstantNTPPrerenderer::DefaultSearchProviderChanged() {
- ReloadInstantNTP();
-}
-
-void InstantNTPPrerenderer::GoogleURLUpdated() {
- ReloadInstantNTP();
-}
diff --git a/chrome/browser/ui/search/instant_ntp_prerenderer.h b/chrome/browser/ui/search/instant_ntp_prerenderer.h
deleted file mode 100644
index d52f14c..0000000
--- a/chrome/browser/ui/search/instant_ntp_prerenderer.h
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_
-#define CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/prefs/pref_change_registrar.h"
-#include "chrome/browser/search/instant_service_observer.h"
-#include "chrome/browser/ui/search/instant_page.h"
-#include "content/public/browser/web_contents.h"
-#include "net/base/network_change_notifier.h"
-
-class InstantNTP;
-class InstantService;
-class PrefService;
-class Profile;
-
-// InstantNTPPrerenderer maintains a prerendered instance of InstantNTP.
-//
-// An InstantNTP instance is a preloaded search page that will be swapped-in the
-// next time when the user navigates to the New Tab Page. It is never shown to
-// the user in an uncommitted state. It is backed by a WebContents and that is
-// owned by InstantNTP.
-//
-// InstantNTPPrerenderer is owned by InstantService.
-class InstantNTPPrerenderer
- : public InstantPage::Delegate,
- public net::NetworkChangeNotifier::NetworkChangeObserver,
- public InstantServiceObserver {
- public:
- InstantNTPPrerenderer(Profile* profile, InstantService* instant_service,
- PrefService* prefs);
- virtual ~InstantNTPPrerenderer();
-
- // Preloads |ntp_| with a new InstantNTP.
- void ReloadInstantNTP();
-
- // Releases and returns the InstantNTP WebContents. May be NULL. Loads a new
- // WebContents for the InstantNTP.
- scoped_ptr<content::WebContents> ReleaseNTPContents() WARN_UNUSED_RESULT;
-
- // The NTP WebContents. May be NULL. InstantNTPPrerenderer retains ownership.
- content::WebContents* GetNTPContents() const;
-
- // Invoked to null out |ntp_|.
- void DeleteNTPContents();
-
- // Invoked when the InstantNTP renderer process crashes.
- void RenderProcessGone();
-
- // Invoked when the |ntp_| main frame load completes.
- void LoadCompletedMainFrame();
-
- protected:
- // Returns the local Instant URL. (Just a convenience wrapper to get the local
- // Instant URL from InstantService.)
- virtual std::string GetLocalInstantURL() const;
-
- // Returns the correct Instant URL to use from the following possibilities:
- // o The default search engine's Instant URL.
- // o The local page (see GetLocalInstantURL())
- // Returns an empty string if no valid Instant URL is available (this is only
- // possible in non-extended mode where we don't have a local page fall-back).
- virtual std::string GetInstantURL() const;
-
- // Returns true if Javascript is enabled and false otherwise.
- virtual bool IsJavascriptEnabled() const;
-
- // Returns true if the browser is in startup.
- virtual bool InStartup() const;
-
- // Accessors are made protected for testing purposes.
- virtual InstantNTP* ntp() const;
-
- Profile* profile() const {
- return profile_;
- }
-
- private:
- friend class InstantExtendedTest;
- friend class InstantNTPPrerendererTest;
- friend class InstantTestBase;
-
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedNetworkTest,
- NTPReactsToNetworkChanges);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- PrefersRemoteNTPOnStartup);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- SwitchesToLocalNTPIfNoInstantSupport);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- SwitchesToLocalNTPIfPathBad);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- DoesNotSwitchToLocalNTPIfOnCurrentNTP);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- DoesNotSwitchToLocalNTPIfOnLocalNTP);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- SwitchesToLocalNTPIfJSDisabled);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- SwitchesToLocalNTPIfNoNTPReady);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- IsJavascriptEnabled);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- IsJavascriptEnabledChecksContentSettings);
- FRIEND_TEST_ALL_PREFIXES(InstantNTPPrerendererTest,
- IsJavascriptEnabledChecksPrefs);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest, MANUAL_ShowsGoogleNTP);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedManualTest,
- MANUAL_SearchesFromFakebox);
- FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ProcessIsolation);
-
- // Overridden from net::NetworkChangeNotifier::NetworkChangeObserver:
- // If the network status changes, resets InstantNTP.
- virtual void OnNetworkChanged(net::NetworkChangeNotifier::ConnectionType type)
- OVERRIDE;
-
- // Overridden from InstantPage::Delegate:
- virtual void InstantSupportDetermined(const content::WebContents* contents,
- bool supports_instant) OVERRIDE;
- virtual void InstantPageAboutToNavigateMainFrame(
- const content::WebContents* contents,
- const GURL& url) OVERRIDE;
- virtual void InstantPageLoadFailed(content::WebContents* contents) OVERRIDE;
-
- // Overridden from InstantServiceObserver:
- virtual void DefaultSearchProviderChanged() OVERRIDE;
- virtual void GoogleURLUpdated() OVERRIDE;
-
- // Recreates |ntp_| using |instant_url|.
- void ResetNTP(const std::string& instant_url);
-
- // Returns true if |ntp_| has an up-to-date Instant URL and supports Instant.
- // Note that local URLs will not pass this check.
- bool PageIsCurrent() const;
-
- // Returns true if we should switch to using the local NTP.
- bool ShouldSwitchToLocalNTP() const;
-
- Profile* profile_;
-
- // Preloaded InstantNTP.
- scoped_ptr<InstantNTP> ntp_;
-
- PrefChangeRegistrar profile_pref_registrar_;
-
- DISALLOW_COPY_AND_ASSIGN(InstantNTPPrerenderer);
-};
-
-#endif // CHROME_BROWSER_UI_SEARCH_INSTANT_NTP_PRERENDERER_H_
diff --git a/chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc b/chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc
deleted file mode 100644
index ca9bdf2..0000000
--- a/chrome/browser/ui/search/instant_ntp_prerenderer_unittest.cc
+++ /dev/null
@@ -1,244 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/scoped_ptr.h"
-#include "base/prefs/pref_service.h"
-#include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/search/instant_service_factory.h"
-#include "chrome/browser/search/search.h"
-#include "chrome/browser/ui/search/instant_ntp.h"
-#include "chrome/browser/ui/search/instant_ntp_prerenderer.h"
-#include "chrome/common/content_settings.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread_bundle.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class TestableInstantNTP : public InstantNTP {
- public:
- TestableInstantNTP(InstantNTPPrerenderer* ntp_prerenderer,
- const std::string& instant_url,
- Profile* profile)
- : InstantNTP(ntp_prerenderer, "UNUSED", profile),
- test_instant_url_(instant_url),
- test_supports_instant_(true),
- test_is_local_(false) {
- }
-
- // Overrides from InstantPage
- virtual bool supports_instant() const OVERRIDE {
- return test_supports_instant_;
- }
-
- virtual bool IsLocal() const OVERRIDE {
- return test_is_local_;
- };
-
- virtual const std::string& instant_url() const OVERRIDE {
- return test_instant_url_;
- }
-
- void set_instant_url(const std::string& instant_url) {
- test_instant_url_ = instant_url;
- }
-
- void set_supports_instant(bool supports_instant) {
- test_supports_instant_ = supports_instant;
- }
-
- void set_is_local(bool is_local) {
- test_is_local_ = is_local;
- }
-
- private:
- std::string test_instant_url_;
- bool test_supports_instant_;
- bool test_is_local_;
-};
-
-class TestableInstantNTPPrerenderer : public InstantNTPPrerenderer {
- public:
- explicit TestableInstantNTPPrerenderer(TestingProfile* profile,
- InstantService* instant_service)
- : InstantNTPPrerenderer(profile, instant_service, NULL),
- test_instant_url_("http://test_url"),
- override_javascript_enabled_(true),
- test_javascript_enabled_(true),
- test_in_startup_(false),
- test_ntp_(NULL) {
- }
-
- // Overrides from InstantNTPPrerenderer
- virtual std::string GetInstantURL() const OVERRIDE {
- return test_instant_url_;
- }
-
- virtual std::string GetLocalInstantURL() const OVERRIDE {
- return "http://local_instant_url";
- }
-
- virtual InstantNTP* ntp() const OVERRIDE {
- return test_ntp_;
- }
-
- virtual bool IsJavascriptEnabled() const OVERRIDE {
- if (override_javascript_enabled_)
- return test_javascript_enabled_;
- else
- return InstantNTPPrerenderer::IsJavascriptEnabled();
- }
-
- virtual bool InStartup() const OVERRIDE {
- return test_in_startup_;
- }
-
- void set_instant_url(const std::string& instant_url) {
- test_instant_url_ = instant_url;
- }
-
- void set_ntp(InstantNTP* ntp) {
- test_ntp_ = ntp;
- }
-
- void set_javascript_enabled(bool javascript_enabled) {
- override_javascript_enabled_ = true;
- test_javascript_enabled_ = javascript_enabled;
- }
-
- void set_override_javascript_enabled(bool override_javascript_enabled) {
- override_javascript_enabled_ = override_javascript_enabled;
- }
-
- void set_in_startup(bool in_startup) {
- test_in_startup_ = in_startup;
- }
-
-private:
- std::string test_instant_url_;
- bool override_javascript_enabled_;
- bool test_javascript_enabled_;
- bool test_in_startup_;
- InstantNTP* test_ntp_;
-};
-
-class InstantNTPPrerendererTest : public testing::Test {
- public:
- virtual void SetUp() OVERRIDE {
- instant_service_ = InstantServiceFactory::GetForProfile(&profile_);
- instant_ntp_prerenderer_.reset(
- new TestableInstantNTPPrerenderer(&profile_, instant_service_));
- }
-
- virtual void TearDown() OVERRIDE {
- instant_ntp_prerenderer_.reset();
- }
-
- TestableInstantNTPPrerenderer* instant_ntp_prerenderer() {
- return instant_ntp_prerenderer_.get();
- }
-
- Profile* profile() {
- return instant_ntp_prerenderer()->profile();
- }
-
- private:
- content::TestBrowserThreadBundle thread_bundle_;
- scoped_ptr<TestableInstantNTPPrerenderer> instant_ntp_prerenderer_;
- InstantService* instant_service_;
- mutable TestingProfile profile_;
-};
-
-TEST_F(InstantNTPPrerendererTest, PrefersRemoteNTPOnStartup) {
- std::string instant_url("http://instant_url");
- scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP(
- instant_ntp_prerenderer(), instant_url, profile()));
- instant_ntp_prerenderer()->set_ntp(ntp.get());
- instant_ntp_prerenderer()->set_instant_url(instant_url);
- instant_ntp_prerenderer()->set_in_startup(true);
- EXPECT_FALSE(instant_ntp_prerenderer()->ShouldSwitchToLocalNTP());
-}
-
-TEST_F(InstantNTPPrerendererTest, SwitchesToLocalNTPIfNoInstantSupport) {
- std::string instant_url("http://instant_url");
- scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP(
- instant_ntp_prerenderer(), instant_url, profile()));
- instant_ntp_prerenderer()->set_ntp(ntp.get());
- instant_ntp_prerenderer()->set_instant_url(instant_url);
- ntp->set_supports_instant(false);
- EXPECT_TRUE(instant_ntp_prerenderer()->ShouldSwitchToLocalNTP());
-}
-
-TEST_F(InstantNTPPrerendererTest, SwitchesToLocalNTPIfPathBad) {
- std::string instant_url("http://instant_url");
- scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP(
- instant_ntp_prerenderer(), instant_url, profile()));
- instant_ntp_prerenderer()->set_ntp(ntp.get());
- instant_ntp_prerenderer()->set_instant_url("http://bogus_url");
- EXPECT_TRUE(instant_ntp_prerenderer()->ShouldSwitchToLocalNTP());
-}
-
-TEST_F(InstantNTPPrerendererTest, DoesNotSwitchToLocalNTPIfOnCurrentNTP) {
- std::string instant_url("http://instant_url");
- scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP(
- instant_ntp_prerenderer(), instant_url, profile()));
- instant_ntp_prerenderer()->set_ntp(ntp.get());
- instant_ntp_prerenderer()->set_instant_url(instant_url);
- EXPECT_FALSE(instant_ntp_prerenderer()->ShouldSwitchToLocalNTP());
-}
-
-TEST_F(InstantNTPPrerendererTest, DoesNotSwitchToLocalNTPIfOnLocalNTP) {
- std::string instant_url("http://instant_url");
- scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP(
- instant_ntp_prerenderer(), instant_url, profile()));
- instant_ntp_prerenderer()->set_ntp(ntp.get());
- instant_ntp_prerenderer()->set_instant_url(instant_url);
- ntp->set_instant_url("http://local_instant_url");
- EXPECT_FALSE(instant_ntp_prerenderer()->ShouldSwitchToLocalNTP());
-}
-
-TEST_F(InstantNTPPrerendererTest, SwitchesToLocalNTPIfJSDisabled) {
- std::string instant_url("http://instant_url");
- scoped_ptr<TestableInstantNTP> ntp(new TestableInstantNTP(
- instant_ntp_prerenderer(), instant_url, profile()));
- instant_ntp_prerenderer()->set_ntp(ntp.get());
- instant_ntp_prerenderer()->set_javascript_enabled(false);
- instant_ntp_prerenderer()->set_instant_url(instant_url);
- ntp->set_instant_url("http://local_instant_url");
- EXPECT_TRUE(instant_ntp_prerenderer()->ShouldSwitchToLocalNTP());
-}
-
-TEST_F(InstantNTPPrerendererTest, SwitchesToLocalNTPIfNoNTPReady) {
- EXPECT_TRUE(instant_ntp_prerenderer()->ShouldSwitchToLocalNTP());
-}
-
-TEST_F(InstantNTPPrerendererTest, IsJavascriptEnabled) {
- instant_ntp_prerenderer()->set_override_javascript_enabled(false);
- EXPECT_TRUE(instant_ntp_prerenderer()->IsJavascriptEnabled());
-}
-
-TEST_F(InstantNTPPrerendererTest, IsJavascriptEnabledChecksContentSettings) {
- instant_ntp_prerenderer()->set_override_javascript_enabled(false);
- instant_ntp_prerenderer()->profile()->GetHostContentSettingsMap()
- ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
- CONTENT_SETTING_DEFAULT);
- EXPECT_TRUE(instant_ntp_prerenderer()->IsJavascriptEnabled());
- instant_ntp_prerenderer()->profile()->GetHostContentSettingsMap()
- ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
- CONTENT_SETTING_ALLOW);
- EXPECT_TRUE(instant_ntp_prerenderer()->IsJavascriptEnabled());
- instant_ntp_prerenderer()->profile()->GetHostContentSettingsMap()
- ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
- CONTENT_SETTING_BLOCK);
- EXPECT_FALSE(instant_ntp_prerenderer()->IsJavascriptEnabled());
-}
-
-TEST_F(InstantNTPPrerendererTest, IsJavascriptEnabledChecksPrefs) {
- instant_ntp_prerenderer()->set_override_javascript_enabled(false);
- instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean(
- prefs::kWebKitJavascriptEnabled, true);
- EXPECT_TRUE(instant_ntp_prerenderer()->IsJavascriptEnabled());
- instant_ntp_prerenderer()->profile()->GetPrefs()->SetBoolean(
- prefs::kWebKitJavascriptEnabled, false);
- EXPECT_FALSE(instant_ntp_prerenderer()->IsJavascriptEnabled());
-}
diff --git a/chrome/browser/ui/search/instant_page.cc b/chrome/browser/ui/search/instant_page.cc
index 7e1bec7..0b4f692 100644
--- a/chrome/browser/ui/search/instant_page.cc
+++ b/chrome/browser/ui/search/instant_page.cc
@@ -80,28 +80,6 @@ void InstantPage::DidCommitProvisionalLoadForFrame(
delegate_->InstantPageAboutToNavigateMainFrame(contents(), url);
}
-void InstantPage::DidNavigateMainFrame(
- const content::LoadCommittedDetails& details,
- const content::FrameNavigateParams& /* params */) {
- // A 204 can be sent by the search provider as a lightweight signal
- // to fall back to the local page, and we obviously want to fall back
- // if we get any response code that indicates an error.
- if (details.http_status_code == 204 || details.http_status_code >= 400)
- delegate_->InstantPageLoadFailed(contents());
-}
-
-void InstantPage::DidFailProvisionalLoad(
- int64 /* frame_id */,
- const base::string16& frame_unique_name,
- bool is_main_frame,
- const GURL& /* validated_url */,
- int /* error_code */,
- const base::string16& /* error_description */,
- content::RenderViewHost* /* render_view_host */) {
- if (is_main_frame)
- delegate_->InstantPageLoadFailed(contents());
-}
-
void InstantPage::ModelChanged(const SearchModel::State& old_state,
const SearchModel::State& new_state) {
if (old_state.instant_support != new_state.instant_support)
diff --git a/chrome/browser/ui/search/instant_page.h b/chrome/browser/ui/search/instant_page.h
index 8967d91..a054cb4 100644
--- a/chrome/browser/ui/search/instant_page.h
+++ b/chrome/browser/ui/search/instant_page.h
@@ -52,9 +52,6 @@ class InstantPage : public content::WebContentsObserver,
const content::WebContents* contents,
const GURL& url) = 0;
- // Called when the page fails to load for whatever reason.
- virtual void InstantPageLoadFailed(content::WebContents* contents) = 0;
-
protected:
virtual ~Delegate();
};
@@ -119,17 +116,6 @@ class InstantPage : public content::WebContentsObserver,
const GURL& url,
content::PageTransition transition_type,
content::RenderViewHost* render_view_host) OVERRIDE;
- virtual void DidNavigateMainFrame(
- const content::LoadCommittedDetails& details,
- const content::FrameNavigateParams& params) OVERRIDE;
- virtual void DidFailProvisionalLoad(
- int64 frame_id,
- const base::string16& frame_unique_name,
- bool is_main_frame,
- const GURL& validated_url,
- int error_code,
- const base::string16& error_description,
- content::RenderViewHost* render_view_host) OVERRIDE;
// Overridden from SearchModelObserver:
virtual void ModelChanged(const SearchModel::State& old_state,
diff --git a/chrome/browser/ui/search/instant_page_unittest.cc b/chrome/browser/ui/search/instant_page_unittest.cc
index 836860e..7115da8 100644
--- a/chrome/browser/ui/search/instant_page_unittest.cc
+++ b/chrome/browser/ui/search/instant_page_unittest.cc
@@ -43,7 +43,6 @@ class FakePageDelegate : public InstantPage::Delegate {
content::PageTransition transition,
WindowOpenDisposition disposition,
bool is_search_type));
- MOCK_METHOD1(InstantPageLoadFailed, void(content::WebContents* contents));
};
} // namespace
diff --git a/chrome/browser/ui/search/instant_test_utils.cc b/chrome/browser/ui/search/instant_test_utils.cc
index cf4135b..cc3e96d 100644
--- a/chrome/browser/ui/search/instant_test_utils.cc
+++ b/chrome/browser/ui/search/instant_test_utils.cc
@@ -9,13 +9,9 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/search/instant_service.h"
-#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
-#include "chrome/browser/ui/search/instant_ntp.h"
-#include "chrome/browser/ui/search/instant_ntp_prerenderer.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/interactive_test_utils.h"
@@ -50,10 +46,6 @@ InstantTestBase::~InstantTestBase() {}
void InstantTestBase::SetupInstant(Browser* browser) {
browser_ = browser;
- // TODO(samarth): update tests to work with cacheable NTP and remove this.
- ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
- "InstantExtended", "Group1 use_cacheable_ntp:0"));
-
TemplateURLService* service =
TemplateURLServiceFactory::GetForProfile(browser_->profile());
ui_test_utils::WaitForTemplateURLServiceToLoad(service);
@@ -65,6 +57,7 @@ void InstantTestBase::SetupInstant(Browser* browser) {
data.SetURL(instant_url_.spec() +
"q={searchTerms}&is_search&{google:omniboxStartMarginParameter}");
data.instant_url = instant_url_.spec();
+ data.new_tab_url = ntp_url_.spec();
if (init_suggestions_url_)
data.suggestions_url = instant_url_.spec() + "#q={searchTerms}";
data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}");
@@ -73,11 +66,6 @@ void InstantTestBase::SetupInstant(Browser* browser) {
TemplateURL* template_url = new TemplateURL(browser_->profile(), data);
service->Add(template_url); // Takes ownership of |template_url|.
service->SetDefaultSearchProvider(template_url);
-
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(browser_->profile());
- ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
- instant_service->ntp_prerenderer()->ReloadInstantNTP();
}
void InstantTestBase::SetInstantURL(const std::string& url) {
@@ -95,8 +83,11 @@ void InstantTestBase::SetInstantURL(const std::string& url) {
service->SetDefaultSearchProvider(template_url);
}
-void InstantTestBase::Init(const GURL& instant_url, bool init_suggestions_url) {
+void InstantTestBase::Init(const GURL& instant_url,
+ const GURL& ntp_url,
+ bool init_suggestions_url) {
instant_url_ = instant_url;
+ ntp_url_ = ntp_url;
init_suggestions_url_ = init_suggestions_url;
}
@@ -110,20 +101,6 @@ void InstantTestBase::FocusOmnibox() {
}
}
-void InstantTestBase::FocusOmniboxAndWaitForInstantNTPSupport() {
- content::WindowedNotificationObserver ntp_observer(
- chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED,
- content::NotificationService::AllSources());
- FocusOmnibox();
-
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(browser_->profile());
- ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
- if (!instant_service->ntp_prerenderer()->ntp() ||
- !instant_service->ntp_prerenderer()->ntp()->supports_instant())
- ntp_observer.Wait();
-}
-
void InstantTestBase::SetOmniboxText(const std::string& text) {
FocusOmnibox();
omnibox()->SetUserText(base::UTF8ToUTF16(text));
@@ -158,14 +135,6 @@ bool InstantTestBase::GetStringFromJS(content::WebContents* contents,
contents, WrapScript(script), result);
}
-bool InstantTestBase::ExecuteScript(const std::string& script) {
- InstantService* instant_service =
- InstantServiceFactory::GetForProfile(browser_instant()->profile());
- if (!instant_service)
- return false;
- return content::ExecuteScript(instant_service->GetNTPContents(), script);
-}
-
bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents,
bool expected) {
bool actual = !expected; // Purposely start with a mis-match.
diff --git a/chrome/browser/ui/search/instant_test_utils.h b/chrome/browser/ui/search/instant_test_utils.h
index 1e3c7b5..c8e9336 100644
--- a/chrome/browser/ui/search/instant_test_utils.h
+++ b/chrome/browser/ui/search/instant_test_utils.h
@@ -39,7 +39,8 @@ class InstantTestBase {
protected:
void SetupInstant(Browser* browser);
- void Init(const GURL& instant_url, bool init_suggestions_url);
+ void Init(const GURL& instant_url, const GURL& ntp_url,
+ bool init_suggestions_url);
void SetInstantURL(const std::string& url);
@@ -66,7 +67,6 @@ class InstantTestBase {
void KillInstantRenderView();
void FocusOmnibox();
- void FocusOmniboxAndWaitForInstantNTPSupport();
void SetOmniboxText(const std::string& text);
@@ -81,7 +81,6 @@ class InstantTestBase {
bool GetStringFromJS(content::WebContents* contents,
const std::string& script,
std::string* result) WARN_UNUSED_RESULT;
- bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT;
bool CheckVisibilityIs(content::WebContents* contents,
bool expected) WARN_UNUSED_RESULT;
@@ -99,6 +98,7 @@ class InstantTestBase {
private:
GURL instant_url_;
+ GURL ntp_url_;
Browser* browser_;
diff --git a/chrome/browser/ui/search/instant_unload_handler.cc b/chrome/browser/ui/search/instant_unload_handler.cc
deleted file mode 100644
index 2f62eef..0000000
--- a/chrome/browser/ui/search/instant_unload_handler.cc
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/search/instant_unload_handler.h"
-
-#include <algorithm>
-
-#include "base/message_loop/message_loop.h"
-#include "chrome/browser/ui/browser_navigator.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
-
-class InstantUnloadHandler::WebContentsDelegateImpl
- : public content::WebContentsDelegate {
- public:
- WebContentsDelegateImpl(InstantUnloadHandler* handler,
- scoped_ptr<content::WebContents> contents,
- int index)
- : handler_(handler),
- contents_(contents.Pass()),
- index_(index) {
- contents_->SetDelegate(this);
- contents_->GetRenderViewHost()->FirePageBeforeUnload(false);
- }
-
- // Overridden from content::WebContentsDelegate:
- virtual void CloseContents(content::WebContents* source) OVERRIDE {
- DCHECK_EQ(contents_, source);
- // Remove ourselves as the delegate, so that CloseContents() won't be
- // called twice, leading to double deletion (http://crbug.com/155848).
- contents_->SetDelegate(NULL);
- handler_->Destroy(this);
- }
-
- virtual void WillRunBeforeUnloadConfirm() OVERRIDE {
- contents_->SetDelegate(NULL);
- handler_->Activate(this, contents_.Pass(), index_);
- }
-
- virtual bool ShouldSuppressDialogs() OVERRIDE {
- return true;
- }
-
- private:
- InstantUnloadHandler* const handler_;
- scoped_ptr<content::WebContents> contents_;
-
- // The tab strip index |contents_| was originally at. If we add the tab back
- // to the tabstrip, we add it at this index.
- const int index_;
-
- DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateImpl);
-};
-
-InstantUnloadHandler::InstantUnloadHandler(Browser* browser)
- : browser_(browser) {
-}
-
-InstantUnloadHandler::~InstantUnloadHandler() {
-}
-
-void InstantUnloadHandler::RunUnloadListenersOrDestroy(
- scoped_ptr<content::WebContents> contents,
- int index) {
- DCHECK(!contents->GetDelegate());
-
- if (!contents->NeedToFireBeforeUnload()) {
- // Tab doesn't have any beforeunload listeners and can be safely deleted.
- // However, the tab object should not be deleted immediately because when we
- // get here from BrowserInstantController::TabDeactivated, other tab
- // observers may still expect to interact with the tab before the event has
- // finished propagating.
- base::MessageLoop::current()->DeleteSoon(FROM_HERE, contents.release());
- return;
- }
-
- // Tab has beforeunload listeners. Install a delegate to run them.
- delegates_.push_back(
- new WebContentsDelegateImpl(this, contents.Pass(), index));
-}
-
-void InstantUnloadHandler::Activate(WebContentsDelegateImpl* delegate,
- scoped_ptr<content::WebContents> contents,
- int index) {
- // Remove (and delete) the delegate.
- Destroy(delegate);
-
- // Add the tab back in.
- chrome::NavigateParams params(browser_, contents.release());
- params.disposition = NEW_FOREGROUND_TAB;
- params.tabstrip_index = index;
- chrome::Navigate(&params);
-}
-
-void InstantUnloadHandler::Destroy(WebContentsDelegateImpl* delegate) {
- ScopedVector<WebContentsDelegateImpl>::iterator i =
- std::find(delegates_.begin(), delegates_.end(), delegate);
- DCHECK(i != delegates_.end());
-
- // The delegate's method is a caller on the stack, so schedule the deletion
- // for later.
- delegates_.weak_erase(i);
- base::MessageLoop::current()->DeleteSoon(FROM_HERE, delegate);
-}
diff --git a/chrome/browser/ui/search/instant_unload_handler.h b/chrome/browser/ui/search/instant_unload_handler.h
deleted file mode 100644
index fa6b264..0000000
--- a/chrome/browser/ui/search/instant_unload_handler.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_SEARCH_INSTANT_UNLOAD_HANDLER_H_
-#define CHROME_BROWSER_UI_SEARCH_INSTANT_UNLOAD_HANDLER_H_
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
-
-class Browser;
-
-namespace content {
-class WebContents;
-}
-
-// InstantUnloadHandler ensures that it runs the BeforeUnload/Unload Handlers
-// (BUH) of a page if the page is replaced by an Instant overlay.
-//
-// Why is this needed? Say the user is looking at a page P. They then try to
-// navigate to another page Q. Consider what happens with and without Instant:
-//
-// Without Instant: Before the navigation is committed, P's BUH are run. If P's
-// BUH return a string (instead of the default null), the user is prompted to
-// "Stay or Leave?". If the user clicks "Stay", the navigation is cancelled,
-// and the user remains on P.
-//
-// With Instant: The navigation to Q has already happened, since Q is being
-// shown as a preview (overlay). When the user "commits" the overlay, it's too
-// late to cancel Q based on P's BUH. So, Instant just replaces P with Q and
-// passes P to InstantUnloadHandler::RunUnloadListenersOrDestroy(). This class
-// runs P's BUH in the background. If the "Stay or Leave?" dialog needs to be
-// shown, it adds P back onto the tabstrip, next to Q. Otherwise, P is deleted.
-class InstantUnloadHandler {
- public:
- explicit InstantUnloadHandler(Browser* browser);
- ~InstantUnloadHandler();
-
- // See class description for details on what this does.
- void RunUnloadListenersOrDestroy(scoped_ptr<content::WebContents> contents,
- int index);
-
- private:
- class WebContentsDelegateImpl;
-
- // Invoked if the tab is to be shown, at |index| on the tab strip. This
- // happens if the beforeunload listener returns a string.
- void Activate(WebContentsDelegateImpl* delegate,
- scoped_ptr<content::WebContents> contents,
- int index);
-
- // Destroys the old tab. This is invoked if script tries to close the page.
- void Destroy(WebContentsDelegateImpl* delegate);
-
- // TODO(sky): Browser really needs to wait to close until there are no more
- // tabs managed by InstantUnloadHandler.
- Browser* const browser_;
-
- ScopedVector<WebContentsDelegateImpl> delegates_;
-
- DISALLOW_COPY_AND_ASSIGN(InstantUnloadHandler);
-};
-
-#endif // CHROME_BROWSER_UI_SEARCH_INSTANT_UNLOAD_HANDLER_H_
diff --git a/chrome/browser/ui/search/local_ntp_browsertest.cc b/chrome/browser/ui/search/local_ntp_browsertest.cc
index bc61e52..1e6af86 100644
--- a/chrome/browser/ui/search/local_ntp_browsertest.cc
+++ b/chrome/browser/ui/search/local_ntp_browsertest.cc
@@ -24,15 +24,17 @@ class LocalNTPTest : public InProcessBrowserTest,
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
ASSERT_TRUE(https_test_server().Start());
GURL instant_url = https_test_server().GetURL(
+ "files/instant_extended.html?strk=1&");
+ GURL ntp_url = https_test_server().GetURL(
"files/local_ntp_browsertest.html?strk=1&");
- InstantTestBase::Init(instant_url, false);
+ InstantTestBase::Init(instant_url, ntp_url, false);
}
};
// Flaky: crbug.com/267117
IN_PROC_BROWSER_TEST_F(LocalNTPTest, DISABLED_LocalNTPJavascriptTest) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
ui_test_utils::NavigateToURLWithDisposition(
browser(),
@@ -65,7 +67,7 @@ IN_PROC_BROWSER_TEST_F(LocalNTPTest,
// Setup Instant.
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
- FocusOmniboxAndWaitForInstantNTPSupport();
+ FocusOmnibox();
// Open a new tab.
ui_test_utils::NavigateToURLWithDisposition(
diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc
index 68b6cef..db00567 100644
--- a/chrome/browser/ui/search/search_tab_helper.cc
+++ b/chrome/browser/ui/search/search_tab_helper.cc
@@ -70,8 +70,7 @@ void RecordCacheableNTPLoadHistogram(bool succeeded) {
bool IsCacheableNTP(const content::WebContents* contents) {
const content::NavigationEntry* entry =
contents->GetController().GetLastCommittedEntry();
- return chrome::ShouldUseCacheableNTP() &&
- chrome::NavEntryIsInstantNTP(contents, entry) &&
+ return chrome::NavEntryIsInstantNTP(contents, entry) &&
entry->GetURL() != GURL(chrome::kChromeSearchLocalNtpUrl);
}
@@ -295,7 +294,6 @@ void SearchTabHelper::DidFailProvisionalLoad(
// navigation so it shouldn't be redirected.
if (is_main_frame &&
error_code != net::ERR_ABORTED &&
- chrome::ShouldUseCacheableNTP() &&
validated_url != GURL(chrome::kChromeSearchLocalNtpUrl) &&
chrome::IsNTPURL(validated_url, profile())) {
RedirectToLocalNTP();
diff --git a/chrome/browser/ui/webui/memory_internals/memory_internals_proxy.cc b/chrome/browser/ui/webui/memory_internals/memory_internals_proxy.cc
index d30dcf8..d7c6d97 100644
--- a/chrome/browser/ui/webui/memory_internals/memory_internals_proxy.cc
+++ b/chrome/browser/ui/webui/memory_internals/memory_internals_proxy.cc
@@ -20,12 +20,9 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
-#include "chrome/browser/search/instant_service.h"
-#include "chrome/browser/search/instant_service_factory.h"
#include "chrome/browser/ui/android/tab_model/tab_model.h"
#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_instant_controller.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
#include "chrome/browser/ui/webui/memory_internals/memory_internals_handler.h"
@@ -109,13 +106,6 @@ void GetAllWebContents(std::set<content::WebContents*>* web_contents) {
prerender_manager->GetAllPrerenderingContents();
web_contents->insert(contentses.begin(), contentses.end());
}
- // Add all the Instant Extended prerendered NTPs.
- for (size_t i = 0; i < profiles.size(); ++i) {
- const InstantService* instant_service =
- InstantServiceFactory::GetForProfile(profiles[i]);
- if (instant_service && instant_service->GetNTPContents())
- web_contents->insert(instant_service->GetNTPContents());
- }
#if defined(ENABLE_FULL_PRINTING)
// Add all the pages being background printed.
printing::BackgroundPrintingManager* printing_manager =
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 06f260a..4d08ae5 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -1515,20 +1515,12 @@
'browser/ui/search/instant_controller.h',
'browser/ui/search/instant_ipc_sender.cc',
'browser/ui/search/instant_ipc_sender.h',
- 'browser/ui/search/instant_loader.cc',
- 'browser/ui/search/instant_loader.h',
- 'browser/ui/search/instant_ntp.cc',
- 'browser/ui/search/instant_ntp.h',
- 'browser/ui/search/instant_ntp_prerenderer.cc',
- 'browser/ui/search/instant_ntp_prerenderer.h',
'browser/ui/search/instant_page.cc',
'browser/ui/search/instant_page.h',
'browser/ui/search/instant_search_prerenderer.cc',
'browser/ui/search/instant_search_prerenderer.h',
'browser/ui/search/instant_tab.cc',
'browser/ui/search/instant_tab.h',
- 'browser/ui/search/instant_unload_handler.cc',
- 'browser/ui/search/instant_unload_handler.h',
'browser/ui/search/search_delegate.cc',
'browser/ui/search/search_delegate.h',
'browser/ui/search/search_ipc_router.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 2a0a6f4..41e76ac 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1658,7 +1658,6 @@
'browser/ui/panels/panel_mouse_watcher_unittest.cc',
'browser/ui/passwords/password_manager_presenter_unittest.cc',
'browser/ui/search_engines/keyword_editor_controller_unittest.cc',
- 'browser/ui/search/instant_ntp_prerenderer_unittest.cc',
'browser/ui/search/instant_page_unittest.cc',
'browser/ui/search/instant_search_prerenderer_unittest.cc',
'browser/ui/search/search_delegate_unittest.cc',
@@ -2556,7 +2555,6 @@
'browser/ui/browser_iterator_unittest.cc',
'browser/ui/fullscreen/fullscreen_controller_state_unittest.cc',
'browser/ui/fullscreen/fullscreen_controller_unittest.cc',
- 'browser/ui/search/instant_ntp_prerenderer_unittest.cc',
'browser/ui/search/instant_page_unittest.cc',
'browser/ui/search/instant_search_prerenderer_unittest.cc',
'browser/ui/search/search_delegate_unittest.cc',
diff --git a/chrome/test/data/instant_extended_ntp.html b/chrome/test/data/instant_extended_ntp.html
new file mode 100644
index 0000000..da831f5
--- /dev/null
+++ b/chrome/test/data/instant_extended_ntp.html
@@ -0,0 +1,165 @@
+<html>
+ <head>
+ <script>
+
+var apiHandle;
+var newTabPageHandle;
+var savedUserText = null;
+var suggestionIndex = -1;
+var suggestions = ["result 1", "result 2", "http://www.google.com"];
+var suggestion;
+var suggestionType = 0; // INSTANT_SUGGESTION_SEARCH
+var behavior = 2; // INSTANT_COMPLETE_NEVER
+var onMostVisitedChangedCalls = 0;
+var mostVisitedItemsCount = 0;
+var firstMostVisitedItemId = 0;
+var onNativeSuggestionsCalls = 0;
+var onChangeCalls = 0;
+var submitCount = 0;
+var onEscKeyPressedCalls = 0;
+var onFocusChangedCalls = 0;
+var onToggleVoiceSearchCalls = 0;
+var prefetchQuery = '';
+var isFocused = false;
+var onvisibilitycalls = 0;
+var onThemeChangedCalls = 0;
+
+function getApiHandle() {
+ if (window.navigator && window.navigator.searchBox)
+ return window.navigator.searchBox;
+ if (window.chrome && window.chrome.searchBox)
+ return window.chrome.searchBox;
+ return null;
+}
+
+function getNewTabPageHandle() {
+ if (window.navigator && window.navigator.embeddedSearch &&
+ window.navigator.embeddedSearch.newTabPage)
+ return window.navigator.embeddedSearch.newTabPage;
+ if (window.chrome && window.chrome.embeddedSearch &&
+ window.chrome.embeddedSearch.newTabPage)
+ return window.chrome.embeddedSearch.newTabPage;
+ return null;
+}
+
+function handleNativeSuggestions() {
+ onNativeSuggestionsCalls++;
+ // Showing the loader at 100% height.
+ apiHandle.hideBars();
+ apiHandle.showOverlay();
+}
+
+function handleSubmit() {
+ location.hash = 'q=' + encodeURIComponent(apiHandle.value);
+ submitCount++;
+}
+
+function handleOnChange() {
+ onChangeCalls++;
+ savedUserText = apiHandle.value;
+ suggestionIndex = -1;
+ apiHandle.setAutocompleteText(suggestion, behavior);
+}
+
+function nextSuggestion() {
+ if (suggestionIndex < suggestions.length - 1) {
+ suggestionIndex++;
+ apiHandle.setValue(suggestions[suggestionIndex], suggestionType);
+ }
+}
+
+function previousSuggestion() {
+ if (suggestionIndex != -1) {
+ suggestionIndex--;
+ if (suggestionIndex == -1) {
+ apiHandle.setValue(savedUserText, suggestionType);
+ } else {
+ apiHandle.setValue(suggestions[suggestionIndex], suggestionType);
+ }
+ }
+}
+
+function handleKeyPress(event) {
+ var VKEY_ESCAPE = 0x1B;
+ var VKEY_UP = 0x26;
+ var VKEY_DOWN = 0x28;
+
+ if (event.keyCode == VKEY_ESCAPE) {
+ onEscKeyPressedCalls++;
+ if (suggestionIndex != -1) {
+ suggestionIndex = -1;
+ apiHandle.setAutocompleteText(suggestion, behavior);
+ }
+ } else if (event.keyCode == VKEY_DOWN) {
+ nextSuggestion();
+ } else if (event.keyCode == VKEY_UP) {
+ previousSuggestion();
+ }
+}
+
+function handleMostVisitedChange() {
+ onMostVisitedChangedCalls++;
+ var items = newTabPageHandle.mostVisited;
+ if (items) {
+ mostVisitedItemsCount = items.length;
+ firstMostVisitedItemId = items[0] ? items[0].rid : 0;
+ }
+}
+
+document.addEventListener("visibilitychange", function() {
+ onvisibilitycalls++;
+}, false);
+
+function handleFocusChange() {
+ onFocusChangedCalls++;
+ isFocused = apiHandle.isFocused;
+}
+
+function handleToggleVoiceSearch() {
+ onToggleVoiceSearchCalls++;
+}
+
+function handleSuggestionChange() {
+ prefetchQuery = getApiHandle().suggestion.text;
+}
+
+function handleThemeChange() {
+ onThemeChangedCalls++;
+}
+
+function setUp() {
+ apiHandle = getApiHandle();
+ if (!apiHandle)
+ return;
+
+ newTabPageHandle = getNewTabPageHandle();
+ apiHandle.onnativesuggestions = handleNativeSuggestions;
+ apiHandle.onsubmit = handleSubmit;
+ apiHandle.onchange = handleOnChange;
+ apiHandle.onkeypress = handleKeyPress;
+ apiHandle.onfocuschange = handleFocusChange;
+ apiHandle.ontogglevoicesearch = handleToggleVoiceSearch;
+ apiHandle.onsuggestionchange = handleSuggestionChange;
+ newTabPageHandle.onmostvisitedchange = handleMostVisitedChange;
+ newTabPageHandle.onthemechange = handleThemeChange;
+ if (apiHandle.value) {
+ handleNativeSuggestions();
+ handleOnChange();
+ }
+ if (newTabPageHandle.mostVisited && newTabPageHandle.mostVisited.length) {
+ handleMostVisitedChange();
+ }
+ handleFocusChange();
+}
+
+setUp();
+
+ </script>
+
+ <meta name="referrer" content="origin" />
+
+ </head>
+ <body>
+ <h1>Instant</h1>
+ </body>
+</html>