Limit offline content suggestions to dino page
Previously, offline content suggestions would show on
any net error page. Now they only show on the dino page, as intended.
As a beneficial side-effect, the error strings (available on page load) will
indicate whether offline content may be inserted to the page later. This is
important for implementing the final UI because, for instance, we need to hide
error help suggestions to make room for content.
I moved the feature flag from browser/ to chrome/common so that it is accessible
from the error page code.
This code was previously reviewed here: https://chromium-review.googlesource.com/c/chromium/src/+/1185282
and needed move to another issue for an OOO reviewer.
Bug: 852872
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I86392d2b10d1f243525f043e0627b04f41f83b96
Reviewed-on: https://chromium-review.googlesource.com/1194245
Reviewed-by: Shakti Sahu <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Reviewed-by: Carlos Knippschild <[email protected]>
Reviewed-by: Peter Lee <[email protected]>
Commit-Queue: Dan H <[email protected]>
Cr-Commit-Position: refs/heads/master@{#586781}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 37ac1734..4b21423 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -2120,8 +2120,6 @@
"android/download/items/offline_content_aggregator_factory_android.cc",
"android/download/local_media_data_source_factory.cc",
"android/download/local_media_data_source_factory.h",
- "android/download/new_net_error_page_feature.cc",
- "android/download/new_net_error_page_feature.h",
"android/download/service/download_background_task.cc",
"android/download/service/download_task_scheduler.cc",
"android/download/service/download_task_scheduler.h",
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 6c026bd..a35b486 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -144,7 +144,6 @@
#if defined(OS_ANDROID)
#include "chrome/browser/android/chrome_feature_list.h"
-#include "chrome/browser/android/download/new_net_error_page_feature.h"
#include "chrome/browser/android/explore_sites/explore_sites_feature.h"
#else // OS_ANDROID
#include "chrome/browser/media/router/media_router_feature.h"
@@ -1234,17 +1233,17 @@
#if defined(OS_ANDROID)
const FeatureEntry::FeatureParam kNewNetErrorPageUIContentList = {
- chrome::android::new_net_error_ui::kUIAlternateParameterName,
- chrome::android::new_net_error_ui::kUIAlternateContentList};
+ features::kNewNetErrorPageUIAlternateParameterName,
+ features::kNewNetErrorPageUIAlternateContentList};
const FeatureEntry::FeatureParam kNewNetErrorPageUIContentListAutoDL = {
- chrome::android::new_net_error_ui::kUIAlternateParameterName,
- chrome::android::new_net_error_ui::kUIAlternateContentListAutoDownload};
+ features::kNewNetErrorPageUIAlternateParameterName,
+ features::kNewNetErrorPageUIAlternateContentListAutoDownload};
const FeatureEntry::FeatureParam kNewNetErrorPageUIContentPreview = {
- chrome::android::new_net_error_ui::kUIAlternateParameterName,
- chrome::android::new_net_error_ui::kUIAlternateContentPreview};
+ features::kNewNetErrorPageUIAlternateParameterName,
+ features::kNewNetErrorPageUIAlternateContentPreview};
const FeatureEntry::FeatureParam kNewNetErrorPageUIContentPreviewAutoDL = {
- chrome::android::new_net_error_ui::kUIAlternateParameterName,
- chrome::android::new_net_error_ui::kUIAlternateContentPreviewAutoDownload};
+ features::kNewNetErrorPageUIAlternateParameterName,
+ features::kNewNetErrorPageUIAlternateContentPreviewAutoDownload};
const FeatureEntry::FeatureVariation kNewNetErrorPageUIVariations[] = {
{"Content List", &kNewNetErrorPageUIContentList, 1, nullptr},
@@ -3699,7 +3698,7 @@
#if defined(OS_ANDROID)
{"new-net-error-page-ui", flag_descriptions::kNewNetErrorPageUIName,
flag_descriptions::kNewNetErrorPageUIDescription, kOsAndroid,
- FEATURE_WITH_PARAMS_VALUE_TYPE(chrome::android::kNewNetErrorPageUI,
+ FEATURE_WITH_PARAMS_VALUE_TYPE(features::kNewNetErrorPageUI,
kNewNetErrorPageUIVariations,
"NewNetErrorPageUI")},
#endif // defined(OS_ANDROID)
diff --git a/chrome/browser/android/chrome_feature_list.cc b/chrome/browser/android/chrome_feature_list.cc
index 6611676..a850143 100644
--- a/chrome/browser/android/chrome_feature_list.cc
+++ b/chrome/browser/android/chrome_feature_list.cc
@@ -117,7 +117,6 @@
&kLongPressBackNewDesign,
&kModalPermissionDialogView,
&kNewContactsPicker,
- &kNewNetErrorPageUI,
&kNewPhotoPicker,
&kNoCreditCardAbort,
&kNTPButton,
@@ -340,9 +339,6 @@
const base::Feature kNewContactsPicker{"NewContactsPicker",
base::FEATURE_DISABLED_BY_DEFAULT};
-const base::Feature kNewNetErrorPageUI{"NewNetErrorPageUI",
- base::FEATURE_DISABLED_BY_DEFAULT};
-
const base::Feature kNewPhotoPicker{"NewPhotoPicker",
base::FEATURE_ENABLED_BY_DEFAULT};
diff --git a/chrome/browser/android/chrome_feature_list.h b/chrome/browser/android/chrome_feature_list.h
index 4bfb63c..c446c75 100644
--- a/chrome/browser/android/chrome_feature_list.h
+++ b/chrome/browser/android/chrome_feature_list.h
@@ -61,7 +61,6 @@
extern const base::Feature kModalPermissionDialogView;
extern const base::Feature kSearchEnginePromoExistingDevice;
extern const base::Feature kSearchEnginePromoNewDevice;
-extern const base::Feature kNewNetErrorPageUI;
extern const base::Feature kNewContactsPicker;
extern const base::Feature kNewPhotoPicker;
extern const base::Feature kNoCreditCardAbort;
diff --git a/chrome/browser/android/download/available_offline_content_provider.cc b/chrome/browser/android/download/available_offline_content_provider.cc
index bdf81923..ac2020d 100644
--- a/chrome/browser/android/download/available_offline_content_provider.cc
+++ b/chrome/browser/android/download/available_offline_content_provider.cc
@@ -8,9 +8,9 @@
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
-#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/android/download/download_manager_service.h"
#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
+#include "chrome/common/chrome_features.h"
#include "components/offline_items_collection/core/offline_content_aggregator.h"
#include "components/offline_items_collection/core/offline_item.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
@@ -214,7 +214,7 @@
AvailableOfflineContentProvider::~AvailableOfflineContentProvider() = default;
void AvailableOfflineContentProvider::List(ListCallback callback) {
- if (!base::FeatureList::IsEnabled(chrome::android::kNewNetErrorPageUI)) {
+ if (!base::FeatureList::IsEnabled(features::kNewNetErrorPageUI)) {
std::move(callback).Run({});
return;
}
diff --git a/chrome/browser/android/download/available_offline_content_provider_unittest.cc b/chrome/browser/android/download/available_offline_content_provider_unittest.cc
index c570e0b..61afd858 100644
--- a/chrome/browser/android/download/available_offline_content_provider_unittest.cc
+++ b/chrome/browser/android/download/available_offline_content_provider_unittest.cc
@@ -7,8 +7,8 @@
#include "base/strings/string_util.h"
#include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h"
-#include "chrome/browser/android/chrome_feature_list.h"
#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
+#include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_profile.h"
#include "components/offline_items_collection/core/offline_content_aggregator.h"
#include "components/offline_items_collection/core/offline_item.h"
@@ -131,8 +131,7 @@
}
TEST_F(AvailableOfflineContentTest, AllContentFilteredOut) {
- scoped_feature_list_.InitAndEnableFeature(
- chrome::android::kNewNetErrorPageUI);
+ scoped_feature_list_.InitAndEnableFeature(features::kNewNetErrorPageUI);
content_provider_.SetItems({UselessItem(), OldOfflinePage()});
std::vector<chrome::mojom::AvailableOfflineContentPtr> suggestions =
@@ -142,8 +141,7 @@
}
TEST_F(AvailableOfflineContentTest, ThreeItems) {
- scoped_feature_list_.InitAndEnableFeature(
- chrome::android::kNewNetErrorPageUI);
+ scoped_feature_list_.InitAndEnableFeature(features::kNewNetErrorPageUI);
content_provider_.SetItems({
UselessItem(), VideoItem(), SuggestedOfflinePageItem(), AudioItem(),
});
@@ -183,8 +181,7 @@
}
TEST_F(AvailableOfflineContentTest, NotEnabled) {
- scoped_feature_list_.InitAndDisableFeature(
- chrome::android::kNewNetErrorPageUI);
+ scoped_feature_list_.InitAndDisableFeature(features::kNewNetErrorPageUI);
content_provider_.SetItems({SuggestedOfflinePageItem()});
std::vector<chrome::mojom::AvailableOfflineContentPtr> suggestions =
diff --git a/chrome/browser/android/download/new_net_error_page_feature.cc b/chrome/browser/android/download/new_net_error_page_feature.cc
deleted file mode 100644
index fd261425..0000000
--- a/chrome/browser/android/download/new_net_error_page_feature.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2018 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/android/download/new_net_error_page_feature.h"
-
-namespace chrome {
-namespace android {
-namespace new_net_error_ui {
-
-const char kUIAlternateParameterName[] = "ui-alternate";
-
-const char kUIAlternateContentList[] = "content_list";
-const char kUIAlternateContentListAutoDownload[] = "content_list_auto_download";
-const char kUIAlternateContentPreview[] = "content_preview";
-const char kUIAlternateContentPreviewAutoDownload[] =
- "content_preview_auto_download";
-
-} // namespace new_net_error_ui
-} // namespace android
-} // namespace chrome
diff --git a/chrome/browser/android/download/new_net_error_page_feature.h b/chrome/browser/android/download/new_net_error_page_feature.h
deleted file mode 100644
index 23c518b..0000000
--- a/chrome/browser/android/download/new_net_error_page_feature.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) 2018 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_ANDROID_DOWNLOAD_NEW_NET_ERROR_PAGE_FEATURE_H_
-#define CHROME_BROWSER_ANDROID_DOWNLOAD_NEW_NET_ERROR_PAGE_FEATURE_H_
-
-namespace chrome {
-namespace android {
-namespace new_net_error_ui {
-
-extern const char kUIAlternateParameterName[];
-
-extern const char kUIAlternateContentList[];
-extern const char kUIAlternateContentListAutoDownload[];
-extern const char kUIAlternateContentPreview[];
-extern const char kUIAlternateContentPreviewAutoDownload[];
-} // namespace new_net_error_ui
-} // namespace android
-} // namespace chrome
-
-#endif // CHROME_BROWSER_ANDROID_DOWNLOAD_NEW_NET_ERROR_PAGE_FEATURE_H_
diff --git a/chrome/common/chrome_features.cc b/chrome/common/chrome_features.cc
index 98702a7..bd7f93a 100644
--- a/chrome/common/chrome_features.cc
+++ b/chrome/common/chrome_features.cc
@@ -391,6 +391,21 @@
base::FEATURE_ENABLED_BY_DEFAULT};
#endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
+#if defined(OS_ANDROID)
+// Changes the net error page UI by adding suggested offline content or
+// enabling automatic fetching of the page when online again.
+const base::Feature kNewNetErrorPageUI{"NewNetErrorPageUI",
+ base::FEATURE_DISABLED_BY_DEFAULT};
+const char kNewNetErrorPageUIAlternateParameterName[] = "ui-alternate";
+
+const char kNewNetErrorPageUIAlternateContentList[] = "content_list";
+const char kNewNetErrorPageUIAlternateContentListAutoDownload[] =
+ "content_list_auto_download";
+const char kNewNetErrorPageUIAlternateContentPreview[] = "content_preview";
+const char kNewNetErrorPageUIAlternateContentPreviewAutoDownload[] =
+ "content_preview_auto_download";
+#endif // OS_ANDROID
+
const base::Feature kNetworkPrediction{"NetworkPrediction",
base::FEATURE_ENABLED_BY_DEFAULT};
diff --git a/chrome/common/chrome_features.h b/chrome/common/chrome_features.h
index ca20606..3309569 100644
--- a/chrome/common/chrome_features.h
+++ b/chrome/common/chrome_features.h
@@ -259,6 +259,20 @@
COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kNetworkPrediction;
+#if defined(OS_ANDROID)
+COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kNewNetErrorPageUI;
+COMPONENT_EXPORT(CHROME_FEATURES)
+extern const char kNewNetErrorPageUIAlternateParameterName[];
+COMPONENT_EXPORT(CHROME_FEATURES)
+extern const char kNewNetErrorPageUIAlternateContentList[];
+COMPONENT_EXPORT(CHROME_FEATURES)
+extern const char kNewNetErrorPageUIAlternateContentListAutoDownload[];
+COMPONENT_EXPORT(CHROME_FEATURES)
+extern const char kNewNetErrorPageUIAlternateContentPreview[];
+COMPONENT_EXPORT(CHROME_FEATURES)
+extern const char kNewNetErrorPageUIAlternateContentPreviewAutoDownload[];
+#endif
+
#if defined(OS_POSIX)
COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kNtlmV2Enabled;
#endif
diff --git a/chrome/renderer/net/net_error_helper.cc b/chrome/renderer/net/net_error_helper.cc
index 827c059..71f9669 100644
--- a/chrome/renderer/net/net_error_helper.cc
+++ b/chrome/renderer/net/net_error_helper.cc
@@ -12,11 +12,13 @@
#include "base/feature_list.h"
#include "base/i18n/rtl.h"
#include "base/json/json_writer.h"
+#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
+#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/render_messages.h"
#include "chrome/renderer/chrome_render_thread_observer.h"
@@ -89,6 +91,26 @@
return NetErrorHelperCore::SUB_FRAME;
}
+#if defined(OS_ANDROID)
+LocalizedError::OfflineContentOnNetErrorFeatureState
+GetOfflineContentOnNetErrorFeatureState() {
+ if (!base::FeatureList::IsEnabled(features::kNewNetErrorPageUI))
+ return LocalizedError::OfflineContentOnNetErrorFeatureState::kDisabled;
+ const std::string alternate_ui_name = base::GetFieldTrialParamValueByFeature(
+ features::kNewNetErrorPageUI,
+ features::kNewNetErrorPageUIAlternateParameterName);
+ if (alternate_ui_name == features::kNewNetErrorPageUIAlternateContentList) {
+ return LocalizedError::OfflineContentOnNetErrorFeatureState::kEnabledList;
+ }
+ return LocalizedError::OfflineContentOnNetErrorFeatureState::kEnabledSummary;
+}
+#else // OS_ANDROID
+LocalizedError::OfflineContentOnNetErrorFeatureState
+GetOfflineContentOnNetErrorFeatureState() {
+ return LocalizedError::OfflineContentOnNetErrorFeatureState::kDisabled;
+}
+#endif // OS_ANDROID
+
const net::NetworkTrafficAnnotationTag& GetNetworkTrafficAnnotationTag() {
static const net::NetworkTrafficAnnotationTag network_traffic_annotation_tag =
net::DefineNetworkTrafficAnnotation("net_error_helper", R"(
@@ -328,6 +350,7 @@
bool* show_saved_copy_button_shown,
bool* show_cached_copy_button_shown,
bool* download_button_shown,
+ bool* offline_suggested_content_allowed,
std::string* error_html) const {
error_html->clear();
@@ -342,6 +365,7 @@
error.reason(), error.domain(), error.url(), is_failed_post,
error.stale_copy_in_cache(), can_show_network_diagnostics_dialog,
ChromeRenderThreadObserver::is_incognito_process(),
+ GetOfflineContentOnNetErrorFeatureState(),
RenderThread::Get()->GetLocale(), std::move(params), &error_strings);
*reload_button_shown = error_strings.Get("reloadButton", nullptr);
*show_saved_copy_button_shown =
@@ -350,6 +374,8 @@
error_strings.Get("cacheButton", nullptr);
*download_button_shown =
error_strings.Get("downloadButton", nullptr);
+ *offline_suggested_content_allowed =
+ error_strings.Get("suggestedOfflineContentPresentationMode", nullptr);
// "t" is the id of the template's root node.
*error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t");
}
@@ -386,6 +412,7 @@
error.reason(), error.domain(), error.url(), is_failed_post,
error.stale_copy_in_cache(), can_show_network_diagnostics_dialog,
ChromeRenderThreadObserver::is_incognito_process(),
+ GetOfflineContentOnNetErrorFeatureState(),
RenderThread::Get()->GetLocale(), std::unique_ptr<ErrorPageParams>(),
&error_strings);
diff --git a/chrome/renderer/net/net_error_helper.h b/chrome/renderer/net/net_error_helper.h
index 0f2b500d..52bf60d39 100644
--- a/chrome/renderer/net/net_error_helper.h
+++ b/chrome/renderer/net/net_error_helper.h
@@ -117,6 +117,7 @@
bool* show_saved_copy_button_shown,
bool* show_cached_copy_button_shown,
bool* download_button_shown,
+ bool* offline_suggested_content_allowed,
std::string* html) const override;
void LoadErrorPage(const std::string& html, const GURL& failed_url) override;
void EnablePageHelperFunctions(net::Error net_error) override;
diff --git a/chrome/renderer/net/net_error_helper_core.cc b/chrome/renderer/net/net_error_helper_core.cc
index 8cc4392..5e3b190 100644
--- a/chrome/renderer/net/net_error_helper_core.cc
+++ b/chrome/renderer/net/net_error_helper_core.cc
@@ -424,7 +424,8 @@
show_cached_copy_button_in_page(false),
download_button_in_page(false),
is_finished_loading(false),
- auto_reload_triggered(false) {}
+ auto_reload_triggered(false),
+ offline_content_suggestions_allowed(false) {}
// Information about the failed page load.
error_page::Error error;
@@ -466,6 +467,10 @@
// True if the auto-reload timer has fired and a reload is or has been in
// flight.
bool auto_reload_triggered;
+
+ // True if the error page is for an offline error and offline content
+ // suggestions are enabled.
+ bool offline_content_suggestions_allowed;
};
NetErrorHelperCore::NavigationCorrectionParams::NavigationCorrectionParams() {}
@@ -667,9 +672,10 @@
static_cast<net::Error>(committed_error_page_info_->error.reason()));
#if defined(OS_ANDROID)
- // TODO(https://crbug.com/852872): Only show for 'offline' error.
- available_content_helper_.FetchAvailableContent(base::BindOnce(
- &Delegate::OfflineContentAvailable, base::Unretained(delegate_)));
+ if (committed_error_page_info_->offline_content_suggestions_allowed) {
+ available_content_helper_.FetchAvailableContent(base::BindOnce(
+ &Delegate::OfflineContentAvailable, base::Unretained(delegate_)));
+ }
#endif
if (committed_error_page_info_->needs_load_navigation_corrections) {
@@ -717,13 +723,14 @@
bool show_saved_copy_button_in_page;
bool show_cached_copy_button_in_page;
bool download_button_in_page;
+ bool offline_content_suggestions_allowed;
if (error_html) {
delegate_->GenerateLocalizedErrorPage(
error, is_failed_post,
false /* No diagnostics dialogs allowed for subframes. */, nullptr,
&reload_button_in_page, &show_saved_copy_button_in_page,
&show_cached_copy_button_in_page, &download_button_in_page,
- error_html);
+ &offline_content_suggestions_allowed, error_html);
}
}
}
@@ -790,7 +797,9 @@
&pending_error_page_info->reload_button_in_page,
&pending_error_page_info->show_saved_copy_button_in_page,
&pending_error_page_info->show_cached_copy_button_in_page,
- &pending_error_page_info->download_button_in_page, error_html);
+ &pending_error_page_info->download_button_in_page,
+ &pending_error_page_info->offline_content_suggestions_allowed,
+ error_html);
}
}
@@ -851,7 +860,9 @@
&pending_error_page_info_->reload_button_in_page,
&pending_error_page_info_->show_saved_copy_button_in_page,
&pending_error_page_info_->show_cached_copy_button_in_page,
- &pending_error_page_info_->download_button_in_page, &error_html);
+ &pending_error_page_info_->download_button_in_page,
+ &pending_error_page_info_->offline_content_suggestions_allowed,
+ &error_html);
} else {
// Since |navigation_correction_params| in |pending_error_page_info_| is
// NULL, this won't trigger another attempt to load corrections.
diff --git a/chrome/renderer/net/net_error_helper_core.h b/chrome/renderer/net/net_error_helper_core.h
index 156ddab..f81589d 100644
--- a/chrome/renderer/net/net_error_helper_core.h
+++ b/chrome/renderer/net/net_error_helper_core.h
@@ -66,6 +66,7 @@
bool* show_saved_copy_button_shown,
bool* show_cached_copy_button_shown,
bool* download_button_shown,
+ bool* offline_content_suggestions_allowed,
std::string* html) const = 0;
// Loads the given HTML in the frame for use as an error page.
diff --git a/chrome/renderer/net/net_error_helper_core_unittest.cc b/chrome/renderer/net/net_error_helper_core_unittest.cc
index d799a27e1..dc5cbd2 100644
--- a/chrome/renderer/net/net_error_helper_core_unittest.cc
+++ b/chrome/renderer/net/net_error_helper_core_unittest.cc
@@ -240,6 +240,10 @@
}
int tracking_request_count() const { return tracking_request_count_; }
+ void set_offline_suggested_content_allowed(bool allowed) {
+ offline_suggested_content_allowed_ = allowed;
+ }
+
const std::string& offline_content_json() const {
return offline_content_json_;
}
@@ -346,6 +350,7 @@
bool* show_saved_copy_button_shown,
bool* show_cached_copy_button_shown,
bool* download_button_shown,
+ bool* offline_suggested_content_allowed,
std::string* html) const override {
last_can_show_network_diagnostics_dialog_ =
can_show_network_diagnostics_dialog;
@@ -354,6 +359,7 @@
*show_saved_copy_button_shown = false;
*show_cached_copy_button_shown = false;
*download_button_shown = false;
+ *offline_suggested_content_allowed = offline_suggested_content_allowed_;
*html = ErrorToString(error, is_failed_post);
}
@@ -487,6 +493,7 @@
GURL diagnose_error_url_;
int download_count_;
std::string offline_content_json_;
+ bool offline_suggested_content_allowed_ = false;
int enable_page_helper_functions_count_;
@@ -2655,9 +2662,12 @@
};
TEST_F(NetErrorHelperCoreAvailableOfflineContentTest, AvailableContent) {
+ set_offline_suggested_content_allowed(true);
fake_provider_.set_return_content(true);
+
DoErrorLoad(net::ERR_INTERNET_DISCONNECTED);
task_environment()->RunUntilIdle();
+
std::string want_json = R"([
{
"ID": "ID",
@@ -2683,7 +2693,19 @@
}
TEST_F(NetErrorHelperCoreAvailableOfflineContentTest, NoAvailableContent) {
+ set_offline_suggested_content_allowed(true);
fake_provider_.set_return_content(false);
+
+ DoErrorLoad(net::ERR_INTERNET_DISCONNECTED);
+ task_environment()->RunUntilIdle();
+
+ EXPECT_EQ("", offline_content_json());
+}
+
+TEST_F(NetErrorHelperCoreAvailableOfflineContentTest, NotAllowed) {
+ set_offline_suggested_content_allowed(false);
+ fake_provider_.set_return_content(true);
+
DoErrorLoad(net::ERR_INTERNET_DISCONNECTED);
task_environment()->RunUntilIdle();
diff --git a/components/error_page/common/localized_error.cc b/components/error_page/common/localized_error.cc
index 4aac78a6..7120def 100644
--- a/components/error_page/common/localized_error.cc
+++ b/components/error_page/common/localized_error.cc
@@ -494,16 +494,19 @@
return standard_menu_items_text;
}
+// Returns true if the error is due to a disconnected network.
+bool IsOfflineError(const std::string& error_domain, int error_code) {
+ return ((error_code == net::ERR_INTERNET_DISCONNECTED &&
+ error_domain == Error::kNetErrorDomain) ||
+ (error_code == error_page::DNS_PROBE_FINISHED_NO_INTERNET &&
+ error_domain == Error::kDnsProbeErrorDomain));
+}
+
// Gets the icon class for a given |error_domain| and |error_code|.
const char* GetIconClassForError(const std::string& error_domain,
int error_code) {
- if ((error_code == net::ERR_INTERNET_DISCONNECTED &&
- error_domain == Error::kNetErrorDomain) ||
- (error_code == error_page::DNS_PROBE_FINISHED_NO_INTERNET &&
- error_domain == Error::kDnsProbeErrorDomain))
- return "icon-offline";
-
- return "icon-generic";
+ return IsOfflineError(error_domain, error_code) ? "icon-offline"
+ : "icon-generic";
}
// If the first suggestion is for a Google cache copy link. Promote the
@@ -871,6 +874,7 @@
bool stale_copy_in_cache,
bool can_show_network_diagnostics_dialog,
bool is_incognito,
+ OfflineContentOnNetErrorFeatureState offline_content_feature_state,
const std::string& locale,
std::unique_ptr<error_page::ErrorPageParams> params,
base::DictionaryValue* error_strings) {
@@ -1072,7 +1076,7 @@
if (!is_post && !reload_visible && !show_saved_copy_visible &&
!is_incognito && failed_url.is_valid() &&
failed_url.SchemeIsHTTPOrHTTPS() &&
- IsSuggested(options.suggestions, SUGGEST_OFFLINE_CHECKS)) {
+ IsOfflineError(error_domain, error_code)) {
error_strings->SetPath(
{"downloadButton", "msg"},
base::Value(l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_DOWNLOAD)));
@@ -1080,6 +1084,21 @@
base::Value(l10n_util::GetStringUTF16(
IDS_ERRORPAGES_BUTTON_DOWNLOADING)));
}
+
+ if (IsOfflineError(error_domain, error_code) && !is_incognito) {
+ switch (offline_content_feature_state) {
+ case OfflineContentOnNetErrorFeatureState::kDisabled:
+ break;
+ case OfflineContentOnNetErrorFeatureState::kEnabledList:
+ error_strings->SetString("suggestedOfflineContentPresentationMode",
+ "list");
+ break;
+ case OfflineContentOnNetErrorFeatureState::kEnabledSummary:
+ error_strings->SetString("suggestedOfflineContentPresentationMode",
+ "summary");
+ break;
+ }
+ }
#endif // defined(OS_ANDROID)
}
diff --git a/components/error_page/common/localized_error.h b/components/error_page/common/localized_error.h
index 0126397..6639e4477 100644
--- a/components/error_page/common/localized_error.h
+++ b/components/error_page/common/localized_error.h
@@ -22,18 +22,26 @@
class LocalizedError {
public:
+ enum class OfflineContentOnNetErrorFeatureState {
+ kDisabled,
+ kEnabledSummary,
+ kEnabledList,
+ };
+
// Fills |error_strings| with values to be used to build an error page used
// on HTTP errors, like 404 or connection reset.
- static void GetStrings(int error_code,
- const std::string& error_domain,
- const GURL& failed_url,
- bool is_post,
- bool stale_copy_in_cache,
- bool can_show_network_diagnostics_dialog,
- bool is_incognito,
- const std::string& locale,
- std::unique_ptr<error_page::ErrorPageParams> params,
- base::DictionaryValue* strings);
+ static void GetStrings(
+ int error_code,
+ const std::string& error_domain,
+ const GURL& failed_url,
+ bool is_post,
+ bool stale_copy_in_cache,
+ bool can_show_network_diagnostics_dialog,
+ bool is_incognito,
+ OfflineContentOnNetErrorFeatureState offline_content_feature_state,
+ const std::string& locale,
+ std::unique_ptr<error_page::ErrorPageParams> params,
+ base::DictionaryValue* strings);
// Returns a description of the encountered error.
static base::string16 GetErrorDetails(const std::string& error_domain,
diff --git a/ios/chrome/browser/web/error_page_util.mm b/ios/chrome/browser/web/error_page_util.mm
index 7fbd2e54..b3cf9a7 100644
--- a/ios/chrome/browser/web/error_page_util.mm
+++ b/ios/chrome/browser/web/error_page_util.mm
@@ -47,6 +47,8 @@
GURL(base::SysNSStringToUTF16(url_spec)), is_post,
/*stale_copy_in_cache=*/false,
/*can_show_network_diagnostics_dialog=*/false, is_off_the_record,
+ error_page::LocalizedError::OfflineContentOnNetErrorFeatureState::
+ kDisabled,
GetApplicationContext()->GetApplicationLocale(),
/*params=*/nullptr, &error_strings);