summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsamarth@chromium.org <samarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-13 02:53:27 +0000
committersamarth@chromium.org <samarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-13 02:53:27 +0000
commit07fd48ad182ab6655dbc35f5a687cf04d793acaa (patch)
tree6f14300345fcd9eec4226981f41020dc92b42daf
parent6117aaf0cab04616b7c3f6687466e8965ee30a10 (diff)
downloadchromium_src-07fd48ad182ab6655dbc35f5a687cf04d793acaa.zip
chromium_src-07fd48ad182ab6655dbc35f5a687cf04d793acaa.tar.gz
chromium_src-07fd48ad182ab6655dbc35f5a687cf04d793acaa.tar.bz2
InstantExtended: add support for turning on with only local resources.
This change adds a new command-line flag (--enable-local-instant-extended-api) and a new field trial (local_only:1), either of which will turn on InstantExtended using only the local NTP and omnibox popup. Either flag, if specified, will override the existing InstantExtended flags. Also, fixes two small bugs with the local NTP:\ (1) Don't "switch" to the local NTP if we're already using the local NTP. Otherwise in |local_overlay_only| mode, we unnecessarily reload the local NTP twice. (2) Explicitly check for incognito when deciding to wire up InstantTab instead of just inferring it from use_local_overlay_only_. Otherwise, the local NTP is not wired up as an InstantTab. (Besides fixing the bug, this seems generally safer since it makes the case when we don't want to wire up the InstantTab explicit.) BUG=none TESTED=InstantExtendedTest.*,InstantExtendedAPIEnabledTest.* Review URL: https://chromiumcodereview.appspot.com/14149004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194081 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/about_flags.cc8
-rw-r--r--chrome/browser/search/search.cc25
-rw-r--r--chrome/browser/search/search.h6
-rw-r--r--chrome/browser/search/search_unittest.cc104
-rw-r--r--chrome/browser/ui/browser_instant_controller.cc1
-rw-r--r--chrome/browser/ui/search/instant_controller.cc14
-rw-r--r--chrome/common/chrome_switches.cc8
-rw-r--r--chrome/common/chrome_switches.h2
9 files changed, 166 insertions, 8 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index a51315d..a52ce57 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -6471,6 +6471,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_ENABLE_INSTANT_EXTENDED_API_DESCRIPTION" desc="Description for the flag to enable the Instant extended API.">
Enable the Instant extended API.
</message>
+ <message name="IDS_FLAGS_ENABLE_LOCAL_ONLY_INSTANT_EXTENDED_API" desc="Title for the flag to enable the local-only Instant extended API.">
+ Enable local-only Instant extended API
+ </message>
+ <message name="IDS_FLAGS_ENABLE_LOCAL_ONLY_INSTANT_EXTENDED_API_DESCRIPTION" desc="Description for the flag to enable the Instant extended API.">
+ Enable the Instant extended API using only local resources.
+ </message>
<message name="IDS_FLAGS_ENABLE_GESTURE_TAP_HIGHLIGHTING_NAME" desc="Title for the flag to turn on gesture tap highlighting">
Gesture Tap Highlighting
</message>
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index ef30e28..b47583a 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -562,6 +562,14 @@ const Experiment kExperiments[] = {
switches::kDisableInstantExtendedAPI)
},
{
+ "enable-local-only-instant-extended-api",
+ IDS_FLAGS_ENABLE_LOCAL_ONLY_INSTANT_EXTENDED_API,
+ IDS_FLAGS_ENABLE_LOCAL_ONLY_INSTANT_EXTENDED_API_DESCRIPTION,
+ kOsDesktop,
+ ENABLE_DISABLE_VALUE_TYPE(switches::kEnableLocalOnlyInstantExtendedAPI,
+ switches::kDisableLocalOnlyInstantExtendedAPI)
+ },
+ {
"static-ip-config",
IDS_FLAGS_STATIC_IP_CONFIG_NAME,
IDS_FLAGS_STATIC_IP_CONFIG_DESCRIPTION,
diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc
index ece1477..4f5f715 100644
--- a/chrome/browser/search/search.cc
+++ b/chrome/browser/search/search.cc
@@ -55,6 +55,8 @@ const char kInstantExtendedActivationName[] = "instant";
const InstantExtendedDefault kInstantExtendedActivationDefault =
INSTANT_DEFAULT_ON;
+const char kLocalOnlyFlagName[] = "local_only";
+
// Key for specifying local NTP beahvior trials.
const char kLocalNTPFlagName[] = "local_ntp";
@@ -238,13 +240,17 @@ bool IsInstantExtendedAPIEnabled() {
#else
// On desktop, query extraction is part of Instant extended, so if one is
// enabled, the other is too.
- return IsQueryExtractionEnabled();
+ return IsQueryExtractionEnabled() || IsLocalOnlyInstantExtendedAPIEnabled();
#endif // defined(OS_IOS) || defined(OS_ANDROID)
}
// Determine what embedded search page version to request from the user's
// default search provider. If 0, the embedded search UI should not be enabled.
uint64 EmbeddedSearchPageVersion() {
+ // No server-side changes if the local-only Instant Extended is enabled.
+ if (IsLocalOnlyInstantExtendedAPIEnabled())
+ return kEmbeddedPageVersionDisabled;
+
// Check the command-line/about:flags setting first, which should have
// precedence and allows the trial to not be reported (if it's never queried).
const CommandLine* command_line = CommandLine::ForCurrentProcess();
@@ -275,6 +281,23 @@ bool IsQueryExtractionEnabled() {
return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled;
}
+bool IsLocalOnlyInstantExtendedAPIEnabled() {
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kDisableLocalOnlyInstantExtendedAPI) ||
+ command_line->HasSwitch(switches::kDisableInstantExtendedAPI))
+ return false;
+ if (command_line->HasSwitch(switches::kEnableLocalOnlyInstantExtendedAPI))
+ return true;
+
+ FieldTrialFlags flags;
+ if (GetFieldTrialInfo(
+ base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName),
+ &flags, NULL)) {
+ return GetBoolValueForFlagWithDefault(kLocalOnlyFlagName, false, flags);
+ }
+ return false;
+}
+
string16 GetSearchTermsFromNavigationEntry(
const content::NavigationEntry* entry) {
string16 search_terms;
diff --git a/chrome/browser/search/search.h b/chrome/browser/search/search.h
index 63e50d9..d51ae74 100644
--- a/chrome/browser/search/search.h
+++ b/chrome/browser/search/search.h
@@ -39,12 +39,16 @@ bool IsInstantExtendedAPIEnabled();
// Returns the value to pass to the &espv CGI parameter when loading the
// embedded search page from the user's default search provider. Will be
-// 0 if the Instant Extended API is not enabled.
+// 0 if the Instant Extended API is not enabled, or if the local-only Instant
+// Extended API is enabled.
uint64 EmbeddedSearchPageVersion();
// Returns whether query extraction is enabled.
bool IsQueryExtractionEnabled();
+// Returns whether the local-only version of Instant Extended API is enabled.
+bool IsLocalOnlyInstantExtendedAPIEnabled();
+
// Returns the search terms attached to a specific NavigationEntry, or empty
// string otherwise. Does not consider IsQueryExtractionEnabled(), so most
// callers should use GetSearchTerms() below instead.
diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc
index c3ceb25..e6035e2 100644
--- a/chrome/browser/search/search_unittest.cc
+++ b/chrome/browser/search/search_unittest.cc
@@ -3,12 +3,14 @@
// found in the LICENSE file.
#include "base/command_line.h"
+#include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/metrics/entropy_provider.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/browser_with_test_window_test.h"
@@ -75,6 +77,108 @@ TEST(EmbeddedSearchFieldTrialTest, GetFieldTrialInfo) {
EXPECT_EQ(ZERO, flags.size());
}
+class InstantExtendedAPIEnabledTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ field_trial_list_.reset(new base::FieldTrialList(
+ new metrics::SHA1EntropyProvider("42")));
+ }
+
+ virtual CommandLine* GetCommandLine() const {
+ return CommandLine::ForCurrentProcess();
+ }
+
+ private:
+ scoped_ptr<base::FieldTrialList> field_trial_list_;
+};
+
+TEST_F(InstantExtendedAPIEnabledTest, EnabledViaCommandLineFlag) {
+ GetCommandLine()->AppendSwitch(switches::kEnableInstantExtendedAPI);
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled());
+#if defined(OS_IOS) || defined(OS_ANDROID)
+ EXPECT_EQ(1ul, EmbeddedSearchPageVersion());
+#else
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+#endif
+}
+
+TEST_F(InstantExtendedAPIEnabledTest, EnabledViaFinchFlag) {
+ ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
+ "InstantExtended/Group1 espv:42/"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(42ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(InstantExtendedAPIEnabledTest, DisabledViaCommandLineFlag) {
+ GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI);
+ ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
+ "InstantExtended/Group1 espv:2/"));
+ EXPECT_FALSE(IsInstantExtendedAPIEnabled());
+ EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyEnabledViaCommandLineFlag) {
+ GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI);
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyEnabledViaFinch) {
+ ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
+ "InstantExtended/Group1 local_only:1/"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(InstantExtendedAPIEnabledTest,
+ LocalOnlyCommandLineTrumpedByCommandLine) {
+ GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI);
+ GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI);
+ EXPECT_FALSE(IsInstantExtendedAPIEnabled());
+ EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyCommandLineTrumpsFinch) {
+ GetCommandLine()->AppendSwitch(switches::kEnableLocalOnlyInstantExtendedAPI);
+ ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
+ "InstantExtended/Group1 espv:2/"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyFinchTrumpedByCommandLine) {
+ ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
+ "InstantExtended/Group1 local_only:1/"));
+ GetCommandLine()->AppendSwitch(switches::kDisableInstantExtendedAPI);
+ EXPECT_FALSE(IsInstantExtendedAPIEnabled());
+ EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyFinchTrumpsFinch) {
+ ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
+ "InstantExtended/Group1 espv:1 local_only:1/"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_TRUE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(0ul, EmbeddedSearchPageVersion());
+}
+
+TEST_F(InstantExtendedAPIEnabledTest, LocalOnlyDisabledViaCommandLineFlag) {
+ GetCommandLine()->AppendSwitch(switches::kDisableLocalOnlyInstantExtendedAPI);
+ ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
+ "InstantExtended/Group1 espv:2/"));
+ EXPECT_TRUE(IsInstantExtendedAPIEnabled());
+ EXPECT_FALSE(IsLocalOnlyInstantExtendedAPIEnabled());
+ EXPECT_EQ(2ul, EmbeddedSearchPageVersion());
+}
+
class SearchTest : public BrowserWithTestWindowTest {
protected:
virtual void SetUp() OVERRIDE {
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index f97fb03..93db0dc 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -231,6 +231,7 @@ void BrowserInstantController::ResetInstant(const std::string& pref_name) {
bool instant_pref_enabled = chrome::IsInstantPrefEnabled(profile());
bool use_local_overlay_only = profile()->IsOffTheRecord() ||
+ chrome::IsLocalOnlyInstantExtendedAPIEnabled() ||
(!instant_pref_enabled &&
!profile()->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled));
instant_.SetInstantEnabled(instant_pref_enabled, use_local_overlay_only);
diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc
index 3a555d1..83f1e34 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -489,7 +489,8 @@ scoped_ptr<content::WebContents> InstantController::ReleaseNTPContents() {
LOG_INSTANT_DEBUG_EVENT(this, "ReleaseNTPContents");
- if (ShouldSwitchToLocalNTP())
+ // Switch to the local NTP unless we're already using one.
+ if (!ntp_ || (ShouldSwitchToLocalNTP() && !ntp_->IsLocalNTP()))
ResetNTP(false, true);
scoped_ptr<content::WebContents> ntp_contents = ntp_->ReleaseContents();
@@ -1316,9 +1317,10 @@ void InstantController::MaybeSwitchToRemoteOverlay() {
}
void InstantController::ResetInstantTab() {
- // Do not wire up the InstantTab if Instant should only use local overlays, to
- // prevent it from sending data to the page.
- if (!search_mode_.is_origin_default() && !use_local_overlay_only_) {
+ // Do not wire up the InstantTab in Incognito, to prevent it from sending data
+ // to the page.
+ if (!search_mode_.is_origin_default() &&
+ !browser_->profile()->IsOffTheRecord()) {
content::WebContents* active_tab = browser_->GetActiveWebContents();
if (!instant_tab_ || active_tab != instant_tab_->contents()) {
instant_tab_.reset(new InstantTab(this));
@@ -1617,9 +1619,9 @@ bool InstantController::UseInstantTabToShowSuggestions() const {
}
bool InstantController::ShouldSwitchToLocalNTP() const {
- // If there is no NTP, or no Instant URL or the NTP is stale, switch.
+ // If there is no Instant URL or the NTP is stale, switch.
std::string instant_url;
- if (!ntp_ || !GetInstantURL(browser_->profile(), false, &instant_url) ||
+ if (!GetInstantURL(browser_->profile(), false, &instant_url) ||
!chrome::MatchesOriginAndPath(GURL(ntp_->instant_url()),
GURL(instant_url))) {
return true;
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 6ab1e01..e95d345 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -338,6 +338,10 @@ const char kDisableIPv6[] = "disable-ipv6";
// attempt to use the existing connection.
const char kDisableIPPooling[] = "disable-ip-pooling";
+// Disable local-only Instant extended API.
+const char kDisableLocalOnlyInstantExtendedAPI[] =
+ "disable-local-only-instant-extended-api";
+
// Disables the native Autofill UI, which is part of the browser process rather
// than part of the renderer process. http://crbug.com/51644
const char kDisableNativeAutofillUi[] = "disable-new-autofill-ui";
@@ -557,6 +561,10 @@ const char kEnableIPCFuzzing[] = "enable-ipc-fuzzing";
// attempt to use the existing connection.
const char kEnableIPPooling[] = "enable-ip-pooling";
+// Enable Instant extended API, but use only the local omnibox popup and NTP.
+const char kEnableLocalOnlyInstantExtendedAPI[] =
+ "enable-local-only-instant-extended-api";
+
// Enables support for user profiles that are managed by another user and can
// have restrictions applied.
const char kEnableManagedUsers[] = "enable-managed-users";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index f0c80fb..89bd156 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -103,6 +103,7 @@ extern const char kDisableImprovedDownloadProtection[];
extern const char kDisableInstantExtendedAPI[];
extern const char kDisableIPv6[];
extern const char kDisableIPPooling[];
+extern const char kDisableLocalOnlyInstantExtendedAPI[];
extern const char kDisableNativeAutofillUi[];
extern const char kDisableNTPOtherSessionsMenu[];
extern const char kDisablePopupBlocking[];
@@ -160,6 +161,7 @@ extern const char kEnableInteractiveAutocomplete[];
extern const char kEnableIPCFuzzing[];
extern const char kEnableIPPooling[];
extern const char kEnableIPv6[];
+extern const char kEnableLocalOnlyInstantExtendedAPI[];
extern const char kEnableManagedStorage[];
extern const char kEnableManagedUsers[];
extern const char kEnableMemoryInfo[];