#include "chrome/renderer/net/net_error_helper.h"
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.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/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_resource_request_blocked_reason.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/renderer/process_state.h"
#include "components/error_page/common/error.h"
#include "components/error_page/common/localized_error.h"
#include "components/error_page/common/net_error_info.h"
#include "components/grit/components_resources.h"
#include "components/offline_pages/buildflags/buildflags.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/security_interstitials/content/renderer/security_interstitial_page_controller.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/common/url_constants.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "skia/ext/skia_utils_base.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-shared.h"
#include "third_party/blink/public/platform/web_data.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_frame.h"
#include "third_party/blink/public/web/web_history_item.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/web_ui_util.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_ANDROID)
#include "chrome/common/offline_page_auto_fetcher.mojom.h"
#endif
JSONWriter;
kUnreachableWebDataURL;
RenderFrame;
RenderFrameObserver;
RenderThread;
DnsProbeStatus;
DnsProbeStatusToString;
LocalizedError;
namespace {
NetErrorHelperCore::FrameType GetFrameType(RenderFrame* render_frame) { … }
bool IsExtensionExtendedErrorCode(int extended_error_code) { … }
#if BUILDFLAG(IS_ANDROID)
bool IsOfflineContentOnNetErrorFeatureEnabled() {
return base::FeatureList::IsEnabled(features::kOfflineContentOnNetError);
}
#else
bool IsOfflineContentOnNetErrorFeatureEnabled() { … }
#endif
#if BUILDFLAG(IS_ANDROID)
bool IsAutoFetchFeatureEnabled() {
return base::FeatureList::IsEnabled(features::kOfflineAutoFetch);
}
#else
bool IsAutoFetchFeatureEnabled() { … }
#endif
bool IsRunningInForcedAppMode() { … }
}
NetErrorHelper::NetErrorHelper(RenderFrame* render_frame)
: … { … }
NetErrorHelper::~NetErrorHelper() = default;
void NetErrorHelper::ButtonPressed(NetErrorHelperCore::Button button) { … }
void NetErrorHelper::LaunchOfflineItem(const std::string& id,
const std::string& name_space) { … }
void NetErrorHelper::LaunchDownloadsPage() { … }
void NetErrorHelper::SavePageForLater() { … }
void NetErrorHelper::CancelSavePage() { … }
void NetErrorHelper::ListVisibilityChanged(bool is_visible) { … }
content::RenderFrame* NetErrorHelper::GetRenderFrame() { … }
void NetErrorHelper::DidCommitProvisionalLoad(ui::PageTransition transition) { … }
void NetErrorHelper::DidFinishLoad() { … }
void NetErrorHelper::OnDestruct() { … }
void NetErrorHelper::PrepareErrorPage(
const error_page::Error& error,
bool is_failed_post,
content::mojom::AlternativeErrorPageOverrideInfoPtr
alternative_error_page_info,
std::string* error_html) { … }
chrome::mojom::NetworkDiagnostics*
NetErrorHelper::GetRemoteNetworkDiagnostics() { … }
chrome::mojom::NetworkEasterEgg* NetErrorHelper::GetRemoteNetworkEasterEgg() { … }
chrome::mojom::NetErrorPageSupport*
NetErrorHelper::GetRemoteNetErrorPageSupport() { … }
LocalizedError::PageState NetErrorHelper::GenerateLocalizedErrorPage(
const error_page::Error& error,
bool is_failed_post,
bool can_show_network_diagnostics_dialog,
content::mojom::AlternativeErrorPageOverrideInfoPtr
alternative_error_page_info,
std::string* error_html) { … }
void NetErrorHelper::EnablePageHelperFunctions() { … }
LocalizedError::PageState NetErrorHelper::UpdateErrorPage(
const error_page::Error& error,
bool is_failed_post,
bool can_show_network_diagnostics_dialog) { … }
void NetErrorHelper::InitializeErrorPageEasterEggHighScore(int high_score) { … }
void NetErrorHelper::RequestEasterEggHighScore() { … }
void NetErrorHelper::UpdateEasterEggHighScore(int high_score) { … }
void NetErrorHelper::ResetEasterEggHighScore() { … }
void NetErrorHelper::ReloadFrame() { … }
void NetErrorHelper::DiagnoseError(const GURL& page_url) { … }
void NetErrorHelper::PortalSignin() { … }
void NetErrorHelper::DownloadPageLater() { … }
void NetErrorHelper::SetIsShowingDownloadButton(bool show) { … }
void NetErrorHelper::OfflineContentAvailable(
bool list_visible_by_prefs,
const std::string& offline_content_json) { … }
#if BUILDFLAG(IS_ANDROID)
void NetErrorHelper::SetAutoFetchState(
chrome::mojom::OfflinePageAutoFetcherScheduleResult result) {
const char* scheduled = "false";
const char* can_schedule = "false";
switch (result) {
case chrome::mojom::OfflinePageAutoFetcherScheduleResult::kAlreadyScheduled:
case chrome::mojom::OfflinePageAutoFetcherScheduleResult::kScheduled:
scheduled = "true";
can_schedule = "true";
break;
case chrome::mojom::OfflinePageAutoFetcherScheduleResult::kOtherError:
break;
case chrome::mojom::OfflinePageAutoFetcherScheduleResult::kNotEnoughQuota:
can_schedule = "true";
break;
}
render_frame()->ExecuteJavaScript(base::UTF8ToUTF16(base::StrCat(
{"setAutoFetchState(", scheduled, ", ", can_schedule, ");"})));
}
#endif
void NetErrorHelper::DNSProbeStatus(int32_t status_num) { … }
void NetErrorHelper::OnNetworkDiagnosticsClientRequest(
mojo::PendingAssociatedReceiver<chrome::mojom::NetworkDiagnosticsClient>
receiver) { … }
void NetErrorHelper::SetCanShowNetworkDiagnosticsDialog(bool can_show) { … }