diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index ac5891acb7c2..3cf0f6b3c2ea 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -34,6 +34,10 @@ browser/net/ @iefremov
# Widevine
browser/widevine @simonhong
+# Wayback machine
+browser/ui/views/infobars/brave_wayback_machine_* @simonhong
+components/brave_wayback_machine @simonhong
+
# Licensing of third-party components
common/licenses/ @fmarier
components/brave_new_tab_ui/data/backgrounds.ts @fmarier
diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd
index 39eaa20de33c..40635c57456a 100644
--- a/app/brave_generated_resources.grd
+++ b/app/brave_generated_resources.grd
@@ -416,6 +416,13 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
Access Sync via
+
+
+ Help Tips
+
+
+ Show Wayback Machine prompt on 404 pages
+
Light
@@ -665,6 +672,19 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
SETUP
+
+
+ Sorry, that page is missing.
+
+
+ Do you want to check if a saved version is available on the Wayback Machine?
+
+
+ Sorry, there is no saved version available.
+
+
+ Check for saved version
+
Brave is made available to you under the <a target="_blank" href="$1">Mozilla Public License 2.0</a> (MPL) and includes <a target="_blank" href="$2">open source software</a> under a variety of other licenses.
diff --git a/app/theme/brave_theme_resources.grd b/app/theme/brave_theme_resources.grd
index 549afeb570aa..8754433d62ef 100644
--- a/app/theme/brave_theme_resources.grd
+++ b/app/theme/brave_theme_resources.grd
@@ -15,6 +15,7 @@
+
diff --git a/app/theme/default_100_percent/brave/brave_wayback_infobar.png b/app/theme/default_100_percent/brave/brave_wayback_infobar.png
new file mode 100644
index 000000000000..653a4343d290
Binary files /dev/null and b/app/theme/default_100_percent/brave/brave_wayback_infobar.png differ
diff --git a/app/theme/default_200_percent/brave/brave_wayback_infobar.png b/app/theme/default_200_percent/brave/brave_wayback_infobar.png
new file mode 100644
index 000000000000..26d35775fa36
Binary files /dev/null and b/app/theme/default_200_percent/brave/brave_wayback_infobar.png differ
diff --git a/app/vector_icons/BUILD.gn b/app/vector_icons/BUILD.gn
index d41e704de078..a51b6430dd0b 100644
--- a/app/vector_icons/BUILD.gn
+++ b/app/vector_icons/BUILD.gn
@@ -10,6 +10,7 @@ aggregate_vector_icons("brave_vector_icons") {
icons = [
"autoplay_status.icon",
"download_unlock.icon",
+ "sad_folder.icon",
"tor_profile.icon",
]
}
@@ -23,4 +24,4 @@ source_set("vector_icons") {
"//skia",
"//ui/gfx",
]
-}
\ No newline at end of file
+}
diff --git a/app/vector_icons/sad_folder.icon b/app/vector_icons/sad_folder.icon
new file mode 100644
index 000000000000..feb23d8803f5
--- /dev/null
+++ b/app/vector_icons/sad_folder.icon
@@ -0,0 +1,51 @@
+// Copyright (c) 2019 The Brave Authors. All rights reserved.
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// You can obtain one at http://mozilla.org/MPL/2.0/.
+
+CANVAS_DIMENSIONS, 22,
+MOVE_TO, 8.77f, 2.75f,
+R_CUBIC_TO, 0.15f, 0, 0.29f, 0.04f, 0.41f, 0.13f,
+LINE_TO, 11.23f, 4.26f,
+R_H_LINE_TO, 7.22f,
+R_CUBIC_TO, 0.82f, 0, 1.49f, 0.68f, 1.49f, 1.51f,
+R_V_LINE_TO, 10.59f,
+R_CUBIC_TO, 0, 0.83f, -0.67f, 1.51f, -1.49f, 1.51f,
+H_LINE_TO, 3.55f,
+R_CUBIC_TO, -0.82f, 0, -1.49f, -0.68f, -1.49f, -1.51f,
+R_V_LINE_TO, -12.1f,
+R_CUBIC_TO, 0, -0.83f, 0.67f, -1.51f, 1.49f, -1.51f,
+H_LINE_TO, 8.77f,
+CLOSE,
+R_MOVE_TO, -0.23f, 1.51f,
+R_H_LINE_TO, -4.99f,
+R_V_LINE_TO, 12.1f,
+H_LINE_TO, 18.45f,
+V_LINE_TO, 5.78f,
+R_H_LINE_TO, -7.44f,
+R_CUBIC_TO, -0.07f, 0, -0.15f, -0.01f, -0.22f, -0.03f,
+R_CUBIC_TO, -0.08f, -0.02f, -0.15f, -0.06f, -0.21f, -0.1f,
+LINE_TO, 8.54f, 4.26f,
+CLOSE,
+MOVE_TO, 11, 11.07f,
+R_CUBIC_TO, 1.18f, 0, 2.34f, 0.49f, 3.46f, 1.43f,
+R_CUBIC_TO, 0.32f, 0.27f, 0.36f, 0.74f, 0.1f, 1.07f,
+R_CUBIC_TO, -0.26f, 0.32f, -0.73f, 0.36f, -1.05f, 0.1f,
+CUBIC_TO, 12.64f, 12.93f, 11.81f, 12.58f, 11, 12.58f,
+R_CUBIC_TO, -0.81f, 0, -1.64f, 0.35f, -2.5f, 1.08f,
+R_CUBIC_TO, -0.32f, 0.27f, -0.79f, 0.22f, -1.05f, -0.1f,
+R_CUBIC_TO, -0.26f, -0.32f, -0.22f, -0.8f, 0.1f, -1.07f,
+CUBIC_TO, 8.66f, 11.56f, 9.82f, 11.07f, 11, 11.07f,
+CLOSE,
+R_MOVE_TO, -2.23f, -3.02f,
+R_CUBIC_TO, 0.41f, 0, 0.74f, 0.34f, 0.74f, 0.76f,
+R_CUBIC_TO, 0, 0.42f, -0.33f, 0.76f, -0.74f, 0.76f,
+R_CUBIC_TO, -0.41f, 0, -0.74f, -0.34f, -0.74f, -0.76f,
+R_CUBIC_TO, 0, -0.42f, 0.33f, -0.76f, 0.74f, -0.76f,
+CLOSE,
+R_MOVE_TO, 4.47f, 0,
+R_CUBIC_TO, 0.41f, 0, 0.74f, 0.34f, 0.74f, 0.76f,
+R_CUBIC_TO, 0, 0.42f, -0.33f, 0.76f, -0.74f, 0.76f,
+R_CUBIC_TO, -0.41f, 0, -0.74f, -0.34f, -0.74f, -0.76f,
+R_CUBIC_TO, 0, -0.42f, 0.33f, -0.76f, 0.74f, -0.76f,
+CLOSE
diff --git a/browser/BUILD.gn b/browser/BUILD.gn
index e310365042f3..e8bc52b4f6ec 100644
--- a/browser/BUILD.gn
+++ b/browser/BUILD.gn
@@ -3,6 +3,7 @@ import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/brave_ads/browser/buildflags/buildflags.gni")
import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
+import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni")
import("//brave/components/greaselion/browser/buildflags/buildflags.gni")
import("//build/buildflag_header.gni")
@@ -118,9 +119,9 @@ source_set("browser_process") {
"renderer_host",
"ui",
"//base",
+ "//brave/browser/notifications",
"//brave/browser/tor:buildflags",
"//brave/browser/translate/buildflags",
- "//brave/browser/notifications",
"//brave/common",
"//brave/common:pref_names",
"//brave/components/brave_ads/browser",
@@ -130,6 +131,7 @@ source_set("browser_process") {
"//brave/components/brave_rewards/browser",
"//brave/components/brave_shields/browser",
"//brave/components/brave_wallet/browser",
+ "//brave/components/brave_wayback_machine:buildflags",
"//brave/components/brave_webtorrent/browser/buildflags",
"//brave/components/content_settings/core/browser",
"//brave/components/greaselion/browser/buildflags",
@@ -263,6 +265,12 @@ source_set("browser_process") {
]
}
+ if (enable_brave_wayback_machine) {
+ deps += [
+ "//brave/components/brave_wayback_machine",
+ ]
+ }
+
if (enable_widevine) {
sources += [
"brave_drm_tab_helper.cc",
diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc
index 7835ce2baaa7..02f8f6f23c5f 100644
--- a/browser/brave_profile_prefs.cc
+++ b/browser/brave_profile_prefs.cc
@@ -8,6 +8,7 @@
#include "brave/common/pref_names.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
+#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/prefs/session_startup_pref.h"
@@ -38,6 +39,10 @@
#include "brave/browser/widevine/widevine_utils.h"
#endif
+#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
+#include "brave/components/brave_wayback_machine/pref_names.h"
+#endif
+
using extensions::FeatureSwitch;
namespace brave {
@@ -96,6 +101,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
webtorrent::RegisterProfilePrefs(registry);
#endif
+ // wayback machine
+#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
+ registry->RegisterBooleanPref(kBraveWaybackMachineEnabled, true);
+#endif
+
#if defined(OS_ANDROID)
registry->RegisterBooleanPref(kDesktopModeEnabled, false);
registry->RegisterBooleanPref(kPlayYTVideoInBrowserEnabled, true);
diff --git a/browser/brave_profile_prefs_browsertest.cc b/browser/brave_profile_prefs_browsertest.cc
index 32bb2efa05bb..74d7babe6711 100644
--- a/browser/brave_profile_prefs_browsertest.cc
+++ b/browser/brave_profile_prefs_browsertest.cc
@@ -4,6 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "brave/common/pref_names.h"
+#include "brave/components/brave_wayback_machine/buildflags.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
@@ -20,6 +21,10 @@
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#endif
+#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
+#include "brave/components/brave_wayback_machine/pref_names.h"
+#endif
+
using BraveProfilePrefsBrowserTest = InProcessBrowserTest;
// Check download prompt preference is set to true by default.
@@ -45,6 +50,10 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
browser()->profile()->GetPrefs()->GetBoolean(kLinkedInEmbedControlType));
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(kWebTorrentEnabled));
+#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
+ EXPECT_TRUE(browser()->profile()->GetPrefs()->
+ GetBoolean(kBraveWaybackMachineEnabled));
+#endif
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(kHangoutsEnabled));
EXPECT_FALSE(
diff --git a/browser/brave_tab_helpers.cc b/browser/brave_tab_helpers.cc
index cd7b808e16ad..d26758d091be 100644
--- a/browser/brave_tab_helpers.cc
+++ b/browser/brave_tab_helpers.cc
@@ -10,6 +10,7 @@
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP
+#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "content/public/browser/web_contents.h"
#include "third_party/widevine/cdm/buildflags.h"
@@ -36,6 +37,10 @@
#include "brave/browser/brave_drm_tab_helper.h"
#endif
+#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
+#include "brave/browser/infobars/brave_wayback_machine_delegate_impl.h"
+#endif
+
namespace brave {
void AttachTabHelpers(content::WebContents* web_contents) {
@@ -67,6 +72,10 @@ void AttachTabHelpers(content::WebContents* web_contents) {
BraveDrmTabHelper::CreateForWebContents(web_contents);
#endif
+#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
+ BraveWaybackMachineDelegateImpl::AttachTabHelperIfNeeded(web_contents);
+#endif
+
brave_ads::AdsTabHelper::CreateForWebContents(web_contents);
}
diff --git a/browser/extensions/BUILD.gn b/browser/extensions/BUILD.gn
index a82b196fc2fd..0fad533b7e0b 100644
--- a/browser/extensions/BUILD.gn
+++ b/browser/extensions/BUILD.gn
@@ -2,6 +2,7 @@ import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
+import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni")
import("//build/config/features.gni")
import("//components/gcm_driver/config.gni")
@@ -61,6 +62,7 @@ source_set("extensions") {
deps = [
"//base",
"//brave/app:brave_generated_resources_grit",
+ "//brave/browser/tor:buildflags",
"//brave/browser/webcompat_reporter",
"//brave/common",
"//brave/common:pref_names",
@@ -68,6 +70,7 @@ source_set("extensions") {
"//brave/components/brave_component_updater/browser",
"//brave/components/brave_extension:generated_resources",
"//brave/components/brave_extension:static_resources",
+ "//brave/components/brave_wayback_machine:buildflags",
"//chrome/browser/extensions",
"//components/gcm_driver:gcm_driver",
"//components/gcm_driver:gcm_buildflags",
@@ -115,9 +118,9 @@ source_set("extensions") {
"brave_webtorrent_navigation_throttle.h",
]
}
- if (enable_tor) {
+ if (enable_brave_wayback_machine) {
deps += [
- "//brave/browser/tor:buildflags",
+ "//brave/components/brave_wayback_machine",
]
}
}
diff --git a/browser/extensions/api/brave_wallet_api_browsertest.cc b/browser/extensions/api/brave_wallet_api_browsertest.cc
index f8df5e3b8830..bb4b2d1bfd9b 100644
--- a/browser/extensions/api/brave_wallet_api_browsertest.cc
+++ b/browser/extensions/api/brave_wallet_api_browsertest.cc
@@ -101,8 +101,8 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest,
for (size_t i = 0; i < infobar_service->infobar_count(); i++) {
InfoBarDelegate* delegate =
infobar_service->infobar_at(i)->delegate();
- if (delegate->GetIdentifier() == (InfoBarDelegate::InfoBarIdentifier)
- CRYPTO_WALLETS_INFOBAR_DELEGATE) {
+ if (delegate->GetIdentifier() ==
+ InfoBarDelegate::CRYPTO_WALLETS_INFOBAR_DELEGATE) {
ConfirmInfoBarDelegate* confirm_delegate =
delegate->AsConfirmInfoBarDelegate();
// Only the OK button should be present
@@ -118,8 +118,8 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest,
for (size_t i = 0; i < infobar_service->infobar_count(); i++) {
InfoBarDelegate* delegate =
infobar_service->infobar_at(i)->delegate();
- if (delegate->GetIdentifier() == (InfoBarDelegate::InfoBarIdentifier)
- CRYPTO_WALLETS_INFOBAR_DELEGATE) {
+ if (delegate->GetIdentifier() ==
+ InfoBarDelegate::CRYPTO_WALLETS_INFOBAR_DELEGATE) {
ConfirmInfoBarDelegate* confirm_delegate =
delegate->AsConfirmInfoBarDelegate();
// Only the OK button should be present
@@ -148,8 +148,7 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest,
void OnInfoBarAdded(InfoBar* infobar) override {
if (infobar_added_run_loop_ &&
infobar->delegate()->GetIdentifier() ==
- (InfoBarDelegate::InfoBarIdentifier)
- CRYPTO_WALLETS_INFOBAR_DELEGATE) {
+ InfoBarDelegate::CRYPTO_WALLETS_INFOBAR_DELEGATE) {
infobar_added_ = true;
infobar_added_run_loop_->Quit();
}
diff --git a/browser/extensions/api/settings_private/brave_prefs_util.cc b/browser/extensions/api/settings_private/brave_prefs_util.cc
index fe1f33027aef..fd28f976cbf7 100644
--- a/browser/extensions/api/settings_private/brave_prefs_util.cc
+++ b/browser/extensions/api/settings_private/brave_prefs_util.cc
@@ -6,6 +6,7 @@
#include "brave/browser/extensions/api/settings_private/brave_prefs_util.h"
#include "brave/common/pref_names.h"
+#include "brave/components/brave_wayback_machine/buildflags.h"
#include "chrome/browser/extensions/api/settings_private/prefs_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/extensions/api/settings_private.h"
@@ -16,6 +17,10 @@
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#endif
+#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
+#include "brave/components/brave_wayback_machine/pref_names.h"
+#endif
+
namespace extensions {
namespace settings_api = api::settings_private;
@@ -90,6 +95,10 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
// WebTorrent pref
(*s_brave_whitelist)[kWebTorrentEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
+#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
+ (*s_brave_whitelist)[kBraveWaybackMachineEnabled] =
+ settings_api::PrefType::PREF_TYPE_BOOLEAN;
+#endif
// Hangouts pref
(*s_brave_whitelist)[kHangoutsEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
diff --git a/browser/infobars/BUILD.gn b/browser/infobars/BUILD.gn
index 7f5225f69af4..3d31e8aa8b88 100644
--- a/browser/infobars/BUILD.gn
+++ b/browser/infobars/BUILD.gn
@@ -1,10 +1,10 @@
import("//build/config/features.gni")
+import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
source_set("infobars") {
sources = [
"brave_confirm_p3a_infobar_delegate.cc",
"brave_confirm_p3a_infobar_delegate.h",
- "brave_infobar_delegate.h",
"crypto_wallets_infobar_delegate.cc",
"crypto_wallets_infobar_delegate.h",
]
@@ -23,4 +23,15 @@ source_set("infobars") {
"//ui/views",
"//url",
]
+
+ if (enable_brave_wayback_machine) {
+ sources += [
+ "brave_wayback_machine_delegate_impl.cc",
+ "brave_wayback_machine_delegate_impl.h",
+ ]
+
+ deps += [
+ "//brave/components/brave_wayback_machine",
+ ]
+ }
}
diff --git a/browser/infobars/brave_confirm_p3a_infobar_delegate.cc b/browser/infobars/brave_confirm_p3a_infobar_delegate.cc
index fc283a19796b..9e469a3b5816 100644
--- a/browser/infobars/brave_confirm_p3a_infobar_delegate.cc
+++ b/browser/infobars/brave_confirm_p3a_infobar_delegate.cc
@@ -47,7 +47,7 @@ BraveConfirmP3AInfoBarDelegate::~BraveConfirmP3AInfoBarDelegate() {}
infobars::InfoBarDelegate::InfoBarIdentifier
BraveConfirmP3AInfoBarDelegate::GetIdentifier() const {
- return (InfoBarIdentifier)BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE;
+ return BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE;
}
const gfx::VectorIcon& BraveConfirmP3AInfoBarDelegate::GetVectorIcon() const {
diff --git a/browser/infobars/brave_confirm_p3a_infobar_delegate.h b/browser/infobars/brave_confirm_p3a_infobar_delegate.h
index bef966ec6166..218a57d3b795 100644
--- a/browser/infobars/brave_confirm_p3a_infobar_delegate.h
+++ b/browser/infobars/brave_confirm_p3a_infobar_delegate.h
@@ -12,8 +12,6 @@
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "url/gurl.h"
-#include "brave/browser/infobars/brave_infobar_delegate.h"
-
class InfoBarService;
class PrefService;
diff --git a/browser/infobars/brave_infobar_delegate.h b/browser/infobars/brave_infobar_delegate.h
deleted file mode 100644
index 2cdebe285b05..000000000000
--- a/browser/infobars/brave_infobar_delegate.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Copyright (c) 2019 The Brave Authors. All rights reserved.
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef BRAVE_BROWSER_INFOBARS_BRAVE_INFOBAR_DELEGATE_H_
-#define BRAVE_BROWSER_INFOBARS_BRAVE_INFOBAR_DELEGATE_H_
-
-#include "components/infobars/core/infobar_delegate.h"
-
-enum BraveInfoBarIdentifier {
- BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE = 500,
- CRYPTO_WALLETS_INFOBAR_DELEGATE = 501,
-};
-
-#endif // BRAVE_BROWSER_INFOBARS_BRAVE_INFOBAR_DELEGATE_H_
diff --git a/browser/infobars/brave_wayback_machine_delegate_impl.cc b/browser/infobars/brave_wayback_machine_delegate_impl.cc
new file mode 100644
index 000000000000..2614a3411ade
--- /dev/null
+++ b/browser/infobars/brave_wayback_machine_delegate_impl.cc
@@ -0,0 +1,39 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/browser/infobars/brave_wayback_machine_delegate_impl.h"
+
+#include "base/command_line.h"
+#include "brave/common/brave_switches.h"
+#include "brave/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.h"
+#include "brave/components/brave_wayback_machine/brave_wayback_machine_tab_helper.h"
+#include "components/infobars/core/infobar.h"
+#include "chrome/browser/infobars/infobar_service.h"
+
+// static
+void BraveWaybackMachineDelegateImpl::AttachTabHelperIfNeeded(
+ content::WebContents* web_contents) {
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableBraveWaybackMachineExtension)) {
+ BraveWaybackMachineTabHelper::CreateForWebContents(web_contents);
+ auto* tab_helper =
+ BraveWaybackMachineTabHelper::FromWebContents(web_contents);
+ tab_helper->set_delegate(
+ std::make_unique());
+ }
+}
+
+BraveWaybackMachineDelegateImpl::BraveWaybackMachineDelegateImpl() = default;
+BraveWaybackMachineDelegateImpl::~BraveWaybackMachineDelegateImpl() = default;
+
+
+void BraveWaybackMachineDelegateImpl::CreateInfoBar(
+ content::WebContents* web_contents) {
+ InfoBarService::FromWebContents(web_contents)->AddInfoBar(
+ CreateInfoBarView(
+ std::make_unique(),
+ web_contents),
+ true);
+}
diff --git a/browser/infobars/brave_wayback_machine_delegate_impl.h b/browser/infobars/brave_wayback_machine_delegate_impl.h
new file mode 100644
index 000000000000..f05295a43a09
--- /dev/null
+++ b/browser/infobars/brave_wayback_machine_delegate_impl.h
@@ -0,0 +1,42 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_BROWSER_INFOBARS_BRAVE_WAYBACK_MACHINE_DELEGATE_IMPL_H_
+#define BRAVE_BROWSER_INFOBARS_BRAVE_WAYBACK_MACHINE_DELEGATE_IMPL_H_
+
+#include
+
+#include "brave/components/brave_wayback_machine/brave_wayback_machine_delegate.h"
+
+namespace content {
+class WebContents;
+} // namespace content
+
+namespace infobars {
+class InfoBar;
+} // namespace infobars
+
+class BraveWaybackMachineDelegateImpl : public BraveWaybackMachineDelegate {
+ public:
+ static void AttachTabHelperIfNeeded(content::WebContents* web_contents);
+
+ BraveWaybackMachineDelegateImpl();
+ ~BraveWaybackMachineDelegateImpl() override;
+
+ BraveWaybackMachineDelegateImpl(
+ const BraveWaybackMachineDelegateImpl&) = delete;
+ BraveWaybackMachineDelegateImpl& operator=(
+ const BraveWaybackMachineDelegateImpl&) = delete;
+
+ private:
+ // BraveWaybackMachineDelegate overrides:
+ void CreateInfoBar(content::WebContents* web_contents) override;
+
+ std::unique_ptr CreateInfoBarView(
+ std::unique_ptr delegate,
+ content::WebContents* contents);
+};
+
+#endif // BRAVE_BROWSER_INFOBARS_BRAVE_WAYBACK_MACHINE_DELEGATE_IMPL_H_
diff --git a/browser/infobars/crypto_wallets_infobar_delegate.cc b/browser/infobars/crypto_wallets_infobar_delegate.cc
index c22af3c821e8..a7f98a211091 100644
--- a/browser/infobars/crypto_wallets_infobar_delegate.cc
+++ b/browser/infobars/crypto_wallets_infobar_delegate.cc
@@ -40,7 +40,7 @@ CryptoWalletsInfoBarDelegate::~CryptoWalletsInfoBarDelegate() {}
infobars::InfoBarDelegate::InfoBarIdentifier
CryptoWalletsInfoBarDelegate::GetIdentifier() const {
- return (InfoBarIdentifier)CRYPTO_WALLETS_INFOBAR_DELEGATE;
+ return CRYPTO_WALLETS_INFOBAR_DELEGATE;
}
const gfx::VectorIcon& CryptoWalletsInfoBarDelegate::GetVectorIcon() const {
diff --git a/browser/infobars/crypto_wallets_infobar_delegate.h b/browser/infobars/crypto_wallets_infobar_delegate.h
index db1b20e3ae54..db79e053a6c2 100644
--- a/browser/infobars/crypto_wallets_infobar_delegate.h
+++ b/browser/infobars/crypto_wallets_infobar_delegate.h
@@ -12,8 +12,6 @@
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "url/gurl.h"
-#include "brave/browser/infobars/brave_infobar_delegate.h"
-
class InfoBarService;
class PrefService;
diff --git a/browser/resources/settings/BUILD.gn b/browser/resources/settings/BUILD.gn
index e86705b5669f..3cda4e79901b 100644
--- a/browser/resources/settings/BUILD.gn
+++ b/browser/resources/settings/BUILD.gn
@@ -1,5 +1,6 @@
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/build/config.gni")
+import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//chrome/browser/resources/optimize_webui.gni")
import("//chrome/common/features.gni")
import("//tools/grit/grit_rule.gni")
@@ -10,6 +11,7 @@ grit("resources") {
defines = [
"is_release_channel=$is_release_channel",
"enable_tor=$enable_tor",
+ "enable_brave_wayback_machine=$enable_brave_wayback_machine",
]
source_is_generated = optimize_webui
diff --git a/browser/resources/settings/brave_help_tips_page/brave_help_tips_browser_proxy.html b/browser/resources/settings/brave_help_tips_page/brave_help_tips_browser_proxy.html
new file mode 100644
index 000000000000..215820238cdf
--- /dev/null
+++ b/browser/resources/settings/brave_help_tips_page/brave_help_tips_browser_proxy.html
@@ -0,0 +1,2 @@
+
+
diff --git a/browser/resources/settings/brave_help_tips_page/brave_help_tips_browser_proxy.js b/browser/resources/settings/brave_help_tips_page/brave_help_tips_browser_proxy.js
new file mode 100644
index 000000000000..bb0b1cfd1018
--- /dev/null
+++ b/browser/resources/settings/brave_help_tips_page/brave_help_tips_browser_proxy.js
@@ -0,0 +1,21 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+ cr.define('settings', function() {
+ /** @interface */
+ class BraveHelpTipsBrowserProxy {}
+
+ /**
+ * @implements {settings.BraveHelpTipsBrowserProxy}
+ */
+ class BraveHelpTipsBrowserProxyImpl {}
+
+ cr.addSingletonGetter(BraveHelpTipsBrowserProxyImpl);
+
+ return {
+ BraveHelpTipsBrowserProxy,
+ BraveHelpTipsBrowserProxyImpl
+ };
+});
diff --git a/browser/resources/settings/brave_help_tips_page/brave_help_tips_page.html b/browser/resources/settings/brave_help_tips_page/brave_help_tips_page.html
new file mode 100644
index 000000000000..4b6a9fbde246
--- /dev/null
+++ b/browser/resources/settings/brave_help_tips_page/brave_help_tips_page.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/browser/resources/settings/brave_help_tips_page/brave_help_tips_page.js b/browser/resources/settings/brave_help_tips_page/brave_help_tips_page.js
new file mode 100644
index 000000000000..cf67cb71eef7
--- /dev/null
+++ b/browser/resources/settings/brave_help_tips_page/brave_help_tips_page.js
@@ -0,0 +1,24 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+(function() {
+ 'use strict';
+
+ /**
+ * 'settings-brave-help-tips-page' is the settings page containing
+ * brave's help tips features.
+ */
+ Polymer({
+ is: 'settings-brave-help-tips-page',
+
+ /** @private {?settings.BraveHelpTipsBrowserProxy} */
+ browserProxy_: null,
+
+ /** @override */
+ created: function() {
+ this.browserProxy_ = settings.BraveHelpTipsBrowserProxyImpl.getInstance();
+ },
+ });
+})();
diff --git a/browser/resources/settings/brave_icons.html b/browser/resources/settings/brave_icons.html
index 0dc185cb72d3..e2fc474264d4 100644
--- a/browser/resources/settings/brave_icons.html
+++ b/browser/resources/settings/brave_icons.html
@@ -63,6 +63,10 @@
+
+
+
diff --git a/browser/resources/settings/brave_settings_overrides.html b/browser/resources/settings/brave_settings_overrides.html
index 807b585071b8..3c3549ad4f18 100644
--- a/browser/resources/settings/brave_settings_overrides.html
+++ b/browser/resources/settings/brave_settings_overrides.html
@@ -7,6 +7,7 @@
+
diff --git a/browser/resources/settings/brave_settings_overrides.js b/browser/resources/settings/brave_settings_overrides.js
index e62ea211fb84..db54a8b0bc99 100644
--- a/browser/resources/settings/brave_settings_overrides.js
+++ b/browser/resources/settings/brave_settings_overrides.js
@@ -156,9 +156,12 @@ BravePatching.RegisterPolymerTemplateModifications({
// Add Sync item
const syncEl = createMenuElement(loadTimeData.getString('braveSync'), '/braveSync', 'brave_settings:sync')
appearanceBrowserEl.insertAdjacentElement('afterend', syncEl)
+ // Add Help Tips item
+ const helpTipsEl = createMenuElement(loadTimeData.getString('braveHelpTips'), '/braveHelpTips', 'brave_settings:help')
+ syncEl.insertAdjacentElement('afterend', helpTipsEl)
// Add Shields item
const shieldsEl = createMenuElement(loadTimeData.getString('braveShieldsTitle'), '/shields', 'brave_settings:shields')
- syncEl.insertAdjacentElement('afterend', shieldsEl)
+ helpTipsEl.insertAdjacentElement('afterend', shieldsEl)
// Add Embed Blocking item
const embedEl = createMenuElement(loadTimeData.getString('socialBlocking'), '/socialBlocking', 'brave_settings:social-permissions')
shieldsEl.insertAdjacentElement('afterend', embedEl)
@@ -181,6 +184,9 @@ BravePatching.RegisterPolymerTemplateModifications({
const autofillEl = getMenuElement(templateContent, '/autofill')
const privacyEl = getMenuElement(templateContent, '/privacy')
privacyEl.insertAdjacentElement('afterend', autofillEl)
+ // Move helptips to advanced
+ const printingEl = getMenuElement(templateContent, '/printing')
+ printingEl.insertAdjacentElement('afterend', helpTipsEl)
// Remove extensions link
const extensionsLinkEl = templateContent.querySelector('#extensionsLink')
if (!extensionsLinkEl) {
@@ -216,6 +222,7 @@ BravePatching.RegisterPolymerTemplateModifications({
r.SOCIAL_BLOCKING = r.BASIC.createSection('/socialBlocking', 'socialBlocking')
r.EXTENSIONS = r.BASIC.createSection('/extensions', 'extensions')
r.BRAVE_SYNC = r.BASIC.createSection('/braveSync', 'braveSync')
+ r.BRAVE_HELP_TIPS = r.BASIC.createSection('/braveHelpTips', 'braveHelpTips')
if (!r.SITE_SETTINGS) {
console.error('[Brave Settings Overrides] Routes: could not find SITE_SETTINGS page')
}
@@ -285,6 +292,15 @@ BravePatching.RegisterPolymerTemplateModifications({
`
+ const sectionHelpTips = document.createElement('template')
+ sectionHelpTips.setAttribute('is', 'dom-if')
+ sectionHelpTips.setAttribute('restamp', true)
+ sectionHelpTips.setAttribute('if', '[[showPage_(pageVisibility.braveHelpTips)]]')
+ sectionHelpTips.innerHTML = `
+
+
+
+ `
// Get Started at top
basicPageEl.insertAdjacentElement('afterbegin', sectionGetStarted)
// Move Appearance item
@@ -326,6 +342,9 @@ BravePatching.RegisterPolymerTemplateModifications({
const sectionAutofill = getSectionElement(actualTemplate.content, 'autofill')
const sectionPrivacy = getSectionElement(advancedSubSectionsTemplate.content, 'privacy')
sectionPrivacy.insertAdjacentElement('afterend', sectionAutofill)
+ // Move help tips after printing
+ const sectionPrinting = getSectionElement(advancedSubSectionsTemplate.content, 'printing')
+ sectionPrinting.insertAdjacentElement('afterend', sectionHelpTips)
}
},
'settings-default-browser-page': (templateContent) => {
diff --git a/browser/resources/settings/settings_resources.grd b/browser/resources/settings/settings_resources.grd
index a996f40c6a86..49ebaa0a3f09 100644
--- a/browser/resources/settings/settings_resources.grd
+++ b/browser/resources/settings/settings_resources.grd
@@ -41,6 +41,12 @@
+
+
+
+
+
+
diff --git a/browser/themes/theme_properties.cc b/browser/themes/theme_properties.cc
index 42b6d47ea01f..2a9b59a7399c 100644
--- a/browser/themes/theme_properties.cc
+++ b/browser/themes/theme_properties.cc
@@ -5,8 +5,8 @@
#include "brave/browser/themes/theme_properties.h"
-#include "brave/browser/themes/brave_theme_service.h"
#include "chrome/browser/themes/theme_properties.h"
+#include "ui/gfx/color_palette.h"
namespace {
@@ -40,6 +40,10 @@ base::Optional MaybeGetDefaultColorForBraveLightUi(int id) {
return kLightToolbarIcon;
case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE:
return color_utils::AlphaBlend(kLightToolbarIcon, kLightToolbar, 0.3f);
+ case BraveThemeProperties::COLOR_WAYBACK_INFOBAR_SEPARATOR:
+ return gfx::kBraveNeutral300;
+ case BraveThemeProperties::COLOR_WAYBACK_INFOBAR_SAD_FOLDER:
+ return gfx::kBraveGrey700;
case BraveThemeProperties::COLOR_FOR_TEST:
return BraveThemeProperties::kLightColorForTest;
default:
@@ -79,6 +83,10 @@ base::Optional MaybeGetDefaultColorForBraveDarkUi(int id) {
return kDarkToolbarIcon;
case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE:
return color_utils::AlphaBlend(kDarkToolbarIcon, kDarkToolbar, 0.3f);
+ case BraveThemeProperties::COLOR_WAYBACK_INFOBAR_SEPARATOR:
+ return gfx::kBraveNeutral800;
+ case BraveThemeProperties::COLOR_WAYBACK_INFOBAR_SAD_FOLDER:
+ return SK_ColorWHITE;
case BraveThemeProperties::COLOR_FOR_TEST:
return BraveThemeProperties::kDarkColorForTest;
default:
diff --git a/browser/themes/theme_properties.h b/browser/themes/theme_properties.h
index 0df4f62f4a6a..7d4185d843b9 100644
--- a/browser/themes/theme_properties.h
+++ b/browser/themes/theme_properties.h
@@ -1,26 +1,34 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
+// Copyright (c) 2019 The Brave Authors. All rights reserved.
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// you can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef BRAVE_BROWSER_THEMES_THEME_PROPERTIES_H_
#define BRAVE_BROWSER_THEMES_THEME_PROPERTIES_H_
#include "base/optional.h"
-#include "third_party/skia/include/core/SkColor.h"
#include "brave/browser/themes/brave_theme_service.h"
+#include "third_party/skia/include/core/SkColor.h"
namespace BraveThemeProperties {
- const SkColor kPrivateColorForTest = SkColorSetRGB(0xFF, 0x00, 0x00);
- const SkColor kLightColorForTest = SkColorSetRGB(0xFF, 0xFF, 0xFF);
- const SkColor kDarkColorForTest = SkColorSetRGB(0x00, 0x00, 0x00);
+const SkColor kPrivateColorForTest = SkColorSetRGB(0xFF, 0x00, 0x00);
+const SkColor kLightColorForTest = SkColorSetRGB(0xFF, 0xFF, 0xFF);
+const SkColor kDarkColorForTest = SkColorSetRGB(0x00, 0x00, 0x00);
+
+enum TestProperty {
+ COLOR_FOR_TEST = 9000
+};
- enum TestProperty {
- COLOR_FOR_TEST = 9000
- };
+enum ThemeProperties {
+ BRAVE_THEME_PROPERTIES_START = 10000,
+ COLOR_WAYBACK_INFOBAR_SEPARATOR = BRAVE_THEME_PROPERTIES_START,
+ COLOR_WAYBACK_INFOBAR_SAD_FOLDER,
+};
-}
+} // namespace BraveThemeProperties
-base::Optional MaybeGetDefaultColorForBraveUi(int id, bool incognito, BraveThemeType theme);
+base::Optional MaybeGetDefaultColorForBraveUi(
+ int id, bool incognito, BraveThemeType theme);
#endif // BRAVE_BROWSER_THEMES_THEME_PROPERTIES_H_
diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn
index 583135da0578..1b2dd737afbe 100644
--- a/browser/ui/BUILD.gn
+++ b/browser/ui/BUILD.gn
@@ -3,6 +3,7 @@ import("//brave/build/config.gni")
import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
+import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//build/config/features.gni")
import("//components/gcm_driver/config.gni")
import("//chrome/common/features.gni")
@@ -168,6 +169,7 @@ source_set("ui") {
"//brave/browser/profiles",
"//brave/browser/resources/settings:resources",
"//brave/browser/tor",
+ "//brave/components/brave_wayback_machine:buildflags",
"//brave/components/webcompat_reporter/browser",
"//brave/common",
"//brave/common:pref_names",
@@ -207,6 +209,14 @@ source_set("ui") {
]
}
+ if (enable_brave_wayback_machine) {
+ deps += [ "//brave/components/brave_wayback_machine" ]
+
+ if (toolkit_views) {
+ deps += [ "//brave/browser/ui/views/infobars:brave_wayback_machine" ]
+ }
+ }
+
if (!is_android) {
deps += [
"//brave/app:brave_generated_resources_grit",
diff --git a/browser/ui/views/infobars/BUILD.gn b/browser/ui/views/infobars/BUILD.gn
new file mode 100644
index 000000000000..4ec2665404e2
--- /dev/null
+++ b/browser/ui/views/infobars/BUILD.gn
@@ -0,0 +1,24 @@
+source_set("brave_wayback_machine") {
+ sources = [
+ "brave_wayback_machine_infobar_button_container.cc",
+ "brave_wayback_machine_infobar_button_container.h",
+ "brave_wayback_machine_infobar_contents_view.cc",
+ "brave_wayback_machine_infobar_contents_view.h",
+ "brave_wayback_machine_infobar_throbber.cc",
+ "brave_wayback_machine_infobar_throbber.h",
+ "brave_wayback_machine_infobar_view.cc",
+ "brave_wayback_machine_infobar_view.h",
+ ]
+
+ deps = [
+ "//brave/app:brave_generated_resources_grit",
+ "//brave/app/vector_icons",
+ "//brave/components/brave_wayback_machine",
+ "//components/resources",
+ "//content/public/browser",
+ "//ui/base",
+ "//ui/gfx",
+ "//ui/views",
+ "//url",
+ ]
+}
diff --git a/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.cc b/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.cc
new file mode 100644
index 000000000000..66f21f935335
--- /dev/null
+++ b/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.cc
@@ -0,0 +1,77 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.h"
+
+#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.h"
+#include "brave/grit/brave_generated_resources.h"
+#include "chrome/browser/ui/views/chrome_layout_provider.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/controls/button/md_text_button.h"
+#include "ui/views/view_class_properties.h"
+
+namespace {
+constexpr int kThrobberDiameter = 16;
+constexpr int kInsetOffsetsForThrobber = kThrobberDiameter;
+} // namespace
+
+BraveWaybackMachineInfoBarButtonContainer::
+BraveWaybackMachineInfoBarButtonContainer(views::ButtonListener* listener) {
+ auto button = views::MdTextButton::CreateSecondaryUiBlueButton(
+ listener,
+ l10n_util::GetStringUTF16(IDS_BRAVE_WAYBACK_MACHINE_CHECK_BUTTON_TEXT));
+ button_ = button.get();
+ button->SizeToPreferredSize();
+ AddChildView(button.release());
+
+ throbber_ = new BraveWaybackMachineInfoBarThrobber;
+ throbber_->SetSize(gfx::Size(kThrobberDiameter, kThrobberDiameter));
+ throbber_->SetVisible(false);
+ button_->AddChildView(throbber_);
+}
+
+BraveWaybackMachineInfoBarButtonContainer::
+~BraveWaybackMachineInfoBarButtonContainer() {
+}
+
+void BraveWaybackMachineInfoBarButtonContainer::Layout() {
+ if (throbber_->GetVisible()) {
+ int x = button_->width() - throbber_->width() - kThrobberDiameter / 2;
+ int y = (button_->height() - throbber_->height()) / 2;
+ throbber_->SetPosition(gfx::Point(x, y));
+ }
+}
+
+gfx::Size
+BraveWaybackMachineInfoBarButtonContainer::CalculatePreferredSize() const {
+ // This container doesn't need more space than button because throbber is
+ // drawn over the button.
+ return button_->GetPreferredSize();
+}
+
+void BraveWaybackMachineInfoBarButtonContainer::StartThrobber() {
+ AdjustButtonInsets(true);
+ throbber_->SetVisible(true);
+ throbber_->Start();
+ Layout();
+}
+
+void BraveWaybackMachineInfoBarButtonContainer::StopThrobber() {
+ AdjustButtonInsets(false);
+ throbber_->SetVisible(false);
+ throbber_->Stop();
+ Layout();
+}
+
+void BraveWaybackMachineInfoBarButtonContainer::AdjustButtonInsets(
+ bool add_insets) {
+ const gfx::Insets insets_offset =
+ gfx::Insets(0, 0, 0, kInsetOffsetsForThrobber);
+ const gfx::Insets button_insets =
+ add_insets ? button_->GetInsets() + insets_offset
+ : button_->GetInsets() - insets_offset;
+ button_->SetBorder(views::CreateEmptyBorder(button_insets));
+ button_->SizeToPreferredSize();
+}
diff --git a/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.h b/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.h
new file mode 100644
index 000000000000..8d7b00599430
--- /dev/null
+++ b/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.h
@@ -0,0 +1,46 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_BUTTON_CONTAINER_H_
+#define BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_BUTTON_CONTAINER_H_
+
+#include "ui/views/view.h"
+
+namespace views {
+class ButtonListener;
+} // namespace views
+
+class BraveWaybackMachineInfoBarThrobber;
+
+// This manages button and throbber controls.
+// buttons occupies all this containers area and throbber runs over the button.
+// When throbbing is requested, button extends its right inset and throbber runs
+// on that area.
+class BraveWaybackMachineInfoBarButtonContainer : public views::View {
+ public:
+ explicit BraveWaybackMachineInfoBarButtonContainer(
+ views::ButtonListener* listener);
+ ~BraveWaybackMachineInfoBarButtonContainer() override;
+
+ BraveWaybackMachineInfoBarButtonContainer(
+ const BraveWaybackMachineInfoBarButtonContainer&) = delete;
+ BraveWaybackMachineInfoBarButtonContainer& operator=(
+ const BraveWaybackMachineInfoBarButtonContainer&) = delete;
+
+ void StartThrobber();
+ void StopThrobber();
+
+ // views::View overrides:
+ void Layout() override;
+ gfx::Size CalculatePreferredSize() const override;
+
+ private:
+ void AdjustButtonInsets(bool add_insets);
+
+ BraveWaybackMachineInfoBarThrobber* throbber_ = nullptr;
+ views::View* button_ = nullptr;
+};
+
+#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_BUTTON_CONTAINER_H_
diff --git a/browser/ui/views/infobars/brave_wayback_machine_infobar_contents_view.cc b/browser/ui/views/infobars/brave_wayback_machine_infobar_contents_view.cc
new file mode 100644
index 000000000000..d382604e0cba
--- /dev/null
+++ b/browser/ui/views/infobars/brave_wayback_machine_infobar_contents_view.cc
@@ -0,0 +1,229 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_contents_view.h"
+
+#include
+#include
+#include
+
+#include "brave/app/vector_icons/vector_icons.h"
+#include "brave/browser/themes/theme_properties.h"
+#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.h"
+#include "brave/components/brave_wayback_machine/wayback_machine_url_fetcher.h"
+#include "brave/grit/brave_generated_resources.h"
+#include "brave/grit/brave_theme_resources.h"
+#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/net/system_network_context_manager.h"
+#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/ui/views/chrome_layout_provider.h"
+#include "chrome/browser/ui/views/chrome_typography.h"
+#include "components/grit/components_scaled_resources.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/theme_provider.h"
+#include "ui/gfx/color_palette.h"
+#include "ui/gfx/paint_vector_icon.h"
+#include "ui/views/controls/button/md_text_button.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/controls/separator.h"
+#include "ui/views/layout/flex_layout.h"
+#include "ui/views/view_class_properties.h"
+#include "url/gurl.h"
+
+namespace {
+// IDs of the colors to use for infobar elements.
+constexpr int kInfoBarLabelBackgroundColor = ThemeProperties::COLOR_INFOBAR;
+constexpr int kInfoBarLabelTextColor = ThemeProperties::COLOR_BOOKMARK_TEXT;
+constexpr int kInfoBarSeparatorColor =
+ BraveThemeProperties::COLOR_WAYBACK_INFOBAR_SEPARATOR;
+constexpr int kInfoBarSadFolderColor =
+ BraveThemeProperties::COLOR_WAYBACK_INFOBAR_SAD_FOLDER;
+
+constexpr int kSadFolderSize = 22;
+} // namespace
+
+BraveWaybackMachineInfoBarContentsView::BraveWaybackMachineInfoBarContentsView(
+ infobars::InfoBar* infobar,
+ content::WebContents* contents)
+ : infobar_(infobar),
+ contents_(contents),
+ wayback_machine_url_fetcher_(
+ this,
+ SystemNetworkContextManager::GetInstance()->
+ GetSharedURLLoaderFactory()) {
+ SetLayoutManager(std::make_unique());
+ InitializeChildren();
+}
+
+BraveWaybackMachineInfoBarContentsView::
+~BraveWaybackMachineInfoBarContentsView() {}
+
+void BraveWaybackMachineInfoBarContentsView::OnThemeChanged() {
+ const SkColor background_color = GetColor(kInfoBarLabelBackgroundColor);
+ const SkColor text_color = GetColor(kInfoBarLabelTextColor);
+ for (auto* label : labels_) {
+ label->SetBackgroundColor(background_color);
+ label->SetEnabledColor(text_color);
+ }
+ separator_->SetColor(GetColor(kInfoBarSeparatorColor));
+ sad_folder_->SetImage(
+ gfx::CreateVectorIcon(kSadFolderIcon, GetColor(kInfoBarSadFolderColor)));
+}
+
+void BraveWaybackMachineInfoBarContentsView::ButtonPressed(
+ views::Button* sender,
+ const ui::Event& event) {
+ if (wayback_url_fetch_requested_)
+ return;
+ wayback_url_fetch_requested_ = true;
+
+ FetchWaybackURL();
+}
+
+void BraveWaybackMachineInfoBarContentsView::OnWaybackURLFetched(
+ const GURL& latest_wayback_url) {
+ DCHECK(wayback_url_fetch_requested_);
+ wayback_url_fetch_requested_ = false;
+
+ button_->StopThrobber();
+ Layout();
+
+ if (latest_wayback_url.is_empty()) {
+ UpdateChildrenVisibility(false);
+ return;
+ }
+
+ LoadURL(latest_wayback_url);
+ // After loading to archived url, don't need to show infobar anymore.
+ InfoBarService::FromWebContents(contents_)->RemoveInfoBar(infobar_);
+}
+
+void BraveWaybackMachineInfoBarContentsView::InitializeChildren() {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ views::ImageView* wayback_spot_graphic = new views::ImageView();
+ wayback_spot_graphic->SetImage(
+ rb.GetImageSkiaNamed(IDR_BRAVE_WAYBACK_INFOBAR));
+ wayback_spot_graphic->SetProperty(views::kMarginsKey,
+ gfx::Insets(6, 20, 6, 20));
+ AddChildView(wayback_spot_graphic);
+
+ separator_ = new views::Separator;
+ separator_->SetProperty(views::kMarginsKey,
+ gfx::Insets(12, 0, 12, 20));
+ AddChildView(separator_);
+
+ const views::FlexSpecification label_flex_rule =
+ views::FlexSpecification::ForSizeRule(
+ views::MinimumFlexSizeRule::kScaleToMinimum,
+ views::MaximumFlexSizeRule::kPreferred);
+ auto* label = CreateLabel(
+ l10n_util::GetStringUTF16(
+ IDS_BRAVE_WAYBACK_MACHINE_INFOBAR_PAGE_MISSING_TEXT));
+ label->SetFontList(
+ label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD));
+ views_visible_before_checking_.push_back(label);
+ label->SetProperty(views::kFlexBehaviorKey, label_flex_rule.WithOrder(1));
+ label->SetProperty(
+ views::kMarginsKey,
+ gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
+ DISTANCE_TOAST_LABEL_VERTICAL),
+ 0));
+ AddChildView(label);
+
+ label = CreateLabel(l10n_util::GetStringUTF16(
+ IDS_BRAVE_WAYBACK_MACHINE_INFOBAR_ASK_ABOUT_CHECK_TEXT));
+ views_visible_before_checking_.push_back(label);
+ label->SetProperty(
+ views::kMarginsKey,
+ gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
+ DISTANCE_TOAST_LABEL_VERTICAL),
+ 5));
+ label->SetElideBehavior(gfx::ELIDE_TAIL);
+ label->SetProperty(views::kFlexBehaviorKey, label_flex_rule.WithOrder(2));
+ AddChildView(label);
+
+ // Add empty view to locate button to last.
+ auto* place_holder_view = new views::View;
+ views_visible_before_checking_.push_back(place_holder_view);
+ place_holder_view->SetProperty(views::kMarginsKey, gfx::Insets(12, 0));
+ place_holder_view->SetProperty(
+ views::kFlexBehaviorKey,
+ views::FlexSpecification::ForSizeRule(
+ views::MinimumFlexSizeRule::kScaleToZero,
+ views::MaximumFlexSizeRule::kUnbounded).WithOrder(3));
+ AddChildView(place_holder_view);
+
+ label = CreateLabel(
+ l10n_util::GetStringUTF16(
+ IDS_BRAVE_WAYBACK_MACHINE_INFOBAR_NOT_AVAILABLE_TEXT));
+ views_visible_after_checking_.push_back(label);
+ label->SetProperty(views::kFlexBehaviorKey, label_flex_rule);
+ label->SetProperty(
+ views::kMarginsKey,
+ gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
+ DISTANCE_TOAST_LABEL_VERTICAL),
+ 0));
+ AddChildView(label);
+
+ sad_folder_ = new views::ImageView();
+ sad_folder_->SetPreferredSize(gfx::Size(kSadFolderSize, kSadFolderSize));
+ sad_folder_->SizeToPreferredSize();
+ views_visible_after_checking_.push_back(sad_folder_);
+ sad_folder_->SetProperty(views::kMarginsKey, gfx::Insets(12, 10));
+ AddChildView(sad_folder_);
+
+ button_ = new BraveWaybackMachineInfoBarButtonContainer(this);
+ views_visible_before_checking_.push_back(button_);
+ button_->SetProperty(
+ views::kMarginsKey,
+ gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
+ DISTANCE_TOAST_CONTROL_VERTICAL),
+ 0));
+ button_->SizeToPreferredSize();
+ AddChildView(button_);
+
+ UpdateChildrenVisibility(true);
+}
+
+views::Label* BraveWaybackMachineInfoBarContentsView::CreateLabel(
+ const base::string16& text) {
+ views::Label* label = new views::Label(text, CONTEXT_BODY_TEXT_LARGE);
+ labels_.push_back(label);
+ label->SetBackgroundColor(GetColor(kInfoBarLabelBackgroundColor));
+ label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ label->SetEnabledColor(GetColor(kInfoBarLabelTextColor));
+ return label;
+}
+
+void BraveWaybackMachineInfoBarContentsView::UpdateChildrenVisibility(
+ bool show_before_checking_views) {
+ for (auto* view : views_visible_before_checking_)
+ view->SetVisible(show_before_checking_views);
+ for (auto* view : views_visible_after_checking_)
+ view->SetVisible(!show_before_checking_views);
+}
+
+SkColor BraveWaybackMachineInfoBarContentsView::GetColor(int id) const {
+ const auto* theme_provider = GetThemeProvider();
+ return theme_provider ? theme_provider->GetColor(id)
+ : gfx::kPlaceholderColor;
+}
+
+void BraveWaybackMachineInfoBarContentsView::FetchWaybackURL() {
+ button_->StartThrobber();
+ wayback_machine_url_fetcher_.Fetch(contents_->GetVisibleURL());
+ Layout();
+}
+
+void BraveWaybackMachineInfoBarContentsView::LoadURL(const GURL& url) {
+ contents_->GetController().LoadURL(url,
+ content::Referrer(),
+ ui::PAGE_TRANSITION_LINK,
+ std::string());
+}
diff --git a/browser/ui/views/infobars/brave_wayback_machine_infobar_contents_view.h b/browser/ui/views/infobars/brave_wayback_machine_infobar_contents_view.h
new file mode 100644
index 000000000000..24c0f4fec047
--- /dev/null
+++ b/browser/ui/views/infobars/brave_wayback_machine_infobar_contents_view.h
@@ -0,0 +1,79 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_CONTENTS_VIEW_H_
+#define BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_CONTENTS_VIEW_H_
+
+#include
+
+#include "brave/components/brave_wayback_machine/wayback_machine_url_fetcher.h"
+#include "ui/views/controls/button/button.h"
+
+namespace content {
+class WebContents;
+} // namespace content
+
+namespace infobars {
+class InfoBar;
+} // namespace infobars
+
+namespace views {
+class ImageView;
+class Label;
+class Separator;
+} // namespace views
+
+class BraveWaybackMachineInfoBarButtonContainer;
+class GURL;
+
+// Includes all view controls except close button that managed by InfoBarView.
+class BraveWaybackMachineInfoBarContentsView
+ : public views::View,
+ public views::ButtonListener,
+ public WaybackMachineURLFetcher::Client {
+ public:
+ BraveWaybackMachineInfoBarContentsView(
+ infobars::InfoBar* infobar,
+ content::WebContents* contents);
+ ~BraveWaybackMachineInfoBarContentsView() override;
+
+ BraveWaybackMachineInfoBarContentsView(
+ const BraveWaybackMachineInfoBarContentsView&) = delete;
+ BraveWaybackMachineInfoBarContentsView& operator=(
+ const BraveWaybackMachineInfoBarContentsView&) = delete;
+
+ private:
+ using Labels = std::vector;
+ using Views = std::vector;
+
+ // views::View overrides:
+ void OnThemeChanged() override;
+ void ButtonPressed(views::Button* sender, const ui::Event& event) override;
+
+ // WaybackMachineURLFetcher::Client overrides:
+ void OnWaybackURLFetched(const GURL& latest_wayback_url) override;
+
+ void InitializeChildren();
+ views::Label* CreateLabel(const base::string16& text);
+ SkColor GetColor(int id) const;
+ void UpdateChildrenVisibility(bool show_before_checking_views);
+ void FetchWaybackURL();
+ void LoadURL(const GURL& url);
+
+ // Used for labels theme changing all together.
+ Labels labels_;
+ Views views_visible_before_checking_;
+ Views views_visible_after_checking_;
+ infobars::InfoBar* infobar_;
+ content::WebContents* contents_;
+ WaybackMachineURLFetcher wayback_machine_url_fetcher_;
+
+ views::Separator* separator_ = nullptr;
+ BraveWaybackMachineInfoBarButtonContainer* button_ = nullptr;
+ views::ImageView* sad_folder_ = nullptr;
+ bool wayback_url_fetch_requested_ = false;
+};
+
+#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_CONTENTS_VIEW_H_
diff --git a/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.cc b/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.cc
new file mode 100644
index 000000000000..1f47587981a0
--- /dev/null
+++ b/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.cc
@@ -0,0 +1,51 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/paint_throbber.h"
+
+BraveWaybackMachineInfoBarThrobber::BraveWaybackMachineInfoBarThrobber() {
+}
+
+BraveWaybackMachineInfoBarThrobber::~BraveWaybackMachineInfoBarThrobber() {
+ Stop();
+}
+
+void BraveWaybackMachineInfoBarThrobber::Start() {
+ if (IsRunning())
+ return;
+
+ start_time_ = base::TimeTicks::Now();
+ timer_.Start(
+ FROM_HERE, base::TimeDelta::FromMilliseconds(30),
+ base::BindRepeating(&BraveWaybackMachineInfoBarThrobber::SchedulePaint,
+ base::Unretained(this)));
+ SchedulePaint(); // paint right away
+}
+
+void BraveWaybackMachineInfoBarThrobber::Stop() {
+ if (!IsRunning())
+ return;
+
+ timer_.Stop();
+ SchedulePaint();
+}
+
+void BraveWaybackMachineInfoBarThrobber::OnPaint(gfx::Canvas* canvas) {
+ if (!IsRunning())
+ return;
+
+ base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_;
+ gfx::PaintThrobberSpinning(
+ canvas, GetContentsBounds(), SK_ColorWHITE, elapsed_time);
+}
+
+bool BraveWaybackMachineInfoBarThrobber::IsRunning() const {
+ return timer_.IsRunning();
+}
diff --git a/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.h b/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.h
new file mode 100644
index 000000000000..cfd60213a223
--- /dev/null
+++ b/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.h
@@ -0,0 +1,39 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_THROBBER_H_
+#define BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_THROBBER_H_
+
+#include "base/time/time.h"
+#include "base/timer/timer.h"
+#include "ui/views/view.h"
+
+// White throbber. Most of codes are copied from views::Throbber.
+class BraveWaybackMachineInfoBarThrobber : public views::View {
+ public:
+ BraveWaybackMachineInfoBarThrobber();
+ ~BraveWaybackMachineInfoBarThrobber() override;
+
+ BraveWaybackMachineInfoBarThrobber(
+ const BraveWaybackMachineInfoBarThrobber&) = delete;
+ BraveWaybackMachineInfoBarThrobber& operator=(
+ const BraveWaybackMachineInfoBarThrobber&) = delete;
+
+ // Start and stop the throbber animation.
+ void Start();
+ void Stop();
+
+ private:
+ // Overridden from View:
+ void OnPaint(gfx::Canvas* canvas) override;
+
+ // Specifies whether the throbber is currently animating or not
+ bool IsRunning() const;
+
+ base::TimeTicks start_time_; // Time when Start was called.
+ base::RepeatingTimer timer_; // Used to schedule Run calls.
+};
+
+#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_THROBBER_H_
diff --git a/browser/ui/views/infobars/brave_wayback_machine_infobar_view.cc b/browser/ui/views/infobars/brave_wayback_machine_infobar_view.cc
new file mode 100644
index 000000000000..486aa8572e3a
--- /dev/null
+++ b/browser/ui/views/infobars/brave_wayback_machine_infobar_view.cc
@@ -0,0 +1,43 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_view.h"
+
+#include
+#include
+
+#include "brave/browser/infobars/brave_wayback_machine_delegate_impl.h"
+#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_contents_view.h"
+#include "brave/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.h"
+
+// static
+std::unique_ptr
+BraveWaybackMachineDelegateImpl::CreateInfoBarView(
+ std::unique_ptr delegate,
+ content::WebContents* contents) {
+ return std::make_unique(std::move(delegate),
+ contents);
+}
+
+BraveWaybackMachineInfoBarView::BraveWaybackMachineInfoBarView(
+ std::unique_ptr delegate,
+ content::WebContents* contents)
+ : InfoBarView(std::move(delegate)) {
+ sub_views_ = new BraveWaybackMachineInfoBarContentsView(this, contents);
+ sub_views_->SizeToPreferredSize();
+ AddChildView(sub_views_);
+}
+
+BraveWaybackMachineInfoBarView::~BraveWaybackMachineInfoBarView() {
+}
+
+void BraveWaybackMachineInfoBarView::Layout() {
+ InfoBarView::Layout();
+ // |sub_views_| occupies from the beginning.
+ // Don't adjust child view's height. Just use their preferred height.
+ // It can cause infinite Layout loop because of infobar's height
+ // re-calculation during the animation.
+ sub_views_->SetBounds(0, OffsetY(sub_views_), EndX(), sub_views_->height());
+}
diff --git a/browser/ui/views/infobars/brave_wayback_machine_infobar_view.h b/browser/ui/views/infobars/brave_wayback_machine_infobar_view.h
new file mode 100644
index 000000000000..916218f876d7
--- /dev/null
+++ b/browser/ui/views/infobars/brave_wayback_machine_infobar_view.h
@@ -0,0 +1,38 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_VIEW_H_
+#define BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_VIEW_H_
+
+#include
+
+#include "chrome/browser/ui/views/infobars/infobar_view.h"
+
+namespace content {
+class WebContents;
+}
+
+class BraveWaybackMachineInfoBarDelegate;
+
+class BraveWaybackMachineInfoBarView : public InfoBarView {
+ public:
+ BraveWaybackMachineInfoBarView(
+ std::unique_ptr delegate,
+ content::WebContents* contents);
+ ~BraveWaybackMachineInfoBarView() override;
+
+ BraveWaybackMachineInfoBarView(
+ const BraveWaybackMachineInfoBarView&) = delete;
+ BraveWaybackMachineInfoBarView& operator=(
+ const BraveWaybackMachineInfoBarView&) = delete;
+
+ private:
+ // InfoBarView overrides:
+ void Layout() override;
+
+ views::View* sub_views_ = nullptr;
+};
+
+#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_VIEW_H_
diff --git a/chromium_src/chrome/browser/ui/tab_helpers.cc b/chromium_src/chrome/browser/ui/tab_helpers.cc
new file mode 100644
index 000000000000..276c3abc4949
--- /dev/null
+++ b/chromium_src/chrome/browser/ui/tab_helpers.cc
@@ -0,0 +1,8 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/browser/brave_tab_helpers.h"
+
+#include "../../../../../chrome/browser/ui/tab_helpers.cc" // NOLINT
diff --git a/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc b/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
index 0c22dd11a897..5c9774fdcd0f 100644
--- a/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
+++ b/chromium_src/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
@@ -137,6 +137,10 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_BRAVE_SYNC_TITLE},
{"braveSyncLabel",
IDS_SETTINGS_BRAVE_SYNC_LINK_LABEL},
+ {"braveHelpTips",
+ IDS_SETTINGS_HELP_TIPS},
+ {"braveHelpTipsWaybackMachineLabel",
+ IDS_SETTINGS_HELP_TIPS_SHOW_BRAVE_WAYBACK_MACHINE_PROMPT},
{"onExitPageTitle",
IDS_SETTINGS_BRAVE_ON_EXIT},
{"braveDefaultExtensions",
diff --git a/chromium_src/components/infobars/core/infobar_delegate.h b/chromium_src/components/infobars/core/infobar_delegate.h
new file mode 100644
index 000000000000..ae0126b8fae0
--- /dev/null
+++ b/chromium_src/components/infobars/core/infobar_delegate.h
@@ -0,0 +1,18 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_
+#define BRAVE_CHROMIUM_SRC_COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_
+
+#define BRAVE_INFOBAR_DELEGATE_IDENTIFIERS \
+ BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE = 500, \
+ CRYPTO_WALLETS_INFOBAR_DELEGATE = 501, \
+ WAYBACK_MACHINE_INFOBAR_DELEGATE = 502,
+
+#include "../../../../../components/infobars/core/infobar_delegate.h"
+
+#undef BRAVE_INFOBAR_DELEGATE_IDENTIFIERS
+
+#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_INFOBARS_CORE_INFOBAR_DELEGATE_H_
diff --git a/chromium_src/ui/gfx/color_palette.h b/chromium_src/ui/gfx/color_palette.h
new file mode 100644
index 000000000000..afef46474edd
--- /dev/null
+++ b/chromium_src/ui/gfx/color_palette.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2019 The Brave Authors. All rights reserved.
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// you can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef BRAVE_CHROMIUM_SRC_UI_GFX_COLOR_PALETTE_H_
+#define BRAVE_CHROMIUM_SRC_UI_GFX_COLOR_PALETTE_H_
+
+#include "../../../../ui/gfx/color_palette.h"
+
+namespace gfx {
+
+constexpr SkColor kBraveGrey700 = SkColorSetRGB(0x4A, 0x4A, 0x4A);
+constexpr SkColor kBraveNeutral300 = SkColorSetRGB(0xDE, 0xE2, 0xE6);
+constexpr SkColor kBraveNeutral800 = SkColorSetRGB(0x34, 0x3A, 0x40);
+
+} // namespace gfx
+
+#endif // BRAVE_CHROMIUM_SRC_UI_GFX_COLOR_PALETTE_H_
diff --git a/common/brave_switches.cc b/common/brave_switches.cc
index 324f6ee130ab..85c6de5b6972 100644
--- a/common/brave_switches.cc
+++ b/common/brave_switches.cc
@@ -27,6 +27,10 @@ const char kDisableTorClientUpdaterExtension[] =
// Allows disabling the WebTorrent extension.
const char kDisableWebTorrentExtension[] = "disable-webtorrent-extension";
+// Allows disabling the Wayback Machine extension.
+const char kDisableBraveWaybackMachineExtension[] =
+ "disable-brave-wayback-machine-extension";
+
// Specifies overriding the built-in theme setting.
// Valid values are: "dark" | "light".
const char kUiMode[] = "ui-mode";
diff --git a/common/brave_switches.h b/common/brave_switches.h
index fdc2ccf27c30..c100e1e8c844 100644
--- a/common/brave_switches.h
+++ b/common/brave_switches.h
@@ -20,6 +20,8 @@ extern const char kDisableTorClientUpdaterExtension[];
extern const char kDisableWebTorrentExtension[];
+extern const char kDisableBraveWaybackMachineExtension[];
+
extern const char kRewards[];
extern const char kUiMode[];
diff --git a/common/url_constants.cc b/common/url_constants.cc
index 20378d44e836..7fe15bcbb954 100644
--- a/common/url_constants.cc
+++ b/common/url_constants.cc
@@ -15,3 +15,4 @@ const char kWidevineTOS[] = "https://policies.google.com/terms";
const char kRewardsUpholdSupport[] = "https://uphold.com/en/brave/support";
const char kP3ALearnMoreURL[] = "https://brave.com/P3A";
const char kP3ASettingsLink[] = "chrome://settings/privacy";
+const char kWaybackQueryURL[] = "https://archive.org/wayback/available?url=";
diff --git a/common/url_constants.h b/common/url_constants.h
index 9ac085155ff4..f546deb9eeaf 100644
--- a/common/url_constants.h
+++ b/common/url_constants.h
@@ -16,6 +16,7 @@ extern const char kWidevineTOS[];
extern const char kRewardsUpholdSupport[];
extern const char kP3ALearnMoreURL[];
extern const char kP3ASettingsLink[];
+extern const char kWaybackQueryURL[];
// This is introduced to replace |kDownloadChromeUrl| in
// outdated_upgrade_bubble_view.cc"
diff --git a/components/brave_wayback_machine/BUILD.gn b/components/brave_wayback_machine/BUILD.gn
new file mode 100644
index 000000000000..b4551353c5a1
--- /dev/null
+++ b/components/brave_wayback_machine/BUILD.gn
@@ -0,0 +1,38 @@
+import("//build/buildflag_header.gni")
+import("buildflags/buildflags.gni")
+
+buildflag_header("buildflags") {
+ header = "buildflags.h"
+ flags = [ "ENABLE_BRAVE_WAYBACK_MACHINE=$enable_brave_wayback_machine" ]
+}
+
+source_set("brave_wayback_machine") {
+ assert_no_deps = [ "//chrome/*" ]
+
+ sources = [
+ "brave_wayback_machine_delegate.h",
+ "brave_wayback_machine_infobar_delegate.cc",
+ "brave_wayback_machine_infobar_delegate.h",
+ "brave_wayback_machine_tab_helper.cc",
+ "brave_wayback_machine_tab_helper.h",
+ "pref_names.cc",
+ "pref_names.h",
+ "wayback_machine_url_fetcher.cc",
+ "wayback_machine_url_fetcher.h",
+ ]
+
+ deps = [
+ "//base",
+ "//components/infobars/core",
+ "//components/prefs",
+ "//components/user_prefs",
+ "//content/public/browser",
+ "//net",
+ "//services/network/public/cpp",
+ "//url",
+ ]
+
+ public_deps = [
+ ":buildflags",
+ ]
+}
diff --git a/components/brave_wayback_machine/brave_wayback_machine_browsertest.cc b/components/brave_wayback_machine/brave_wayback_machine_browsertest.cc
new file mode 100644
index 000000000000..4a569000155f
--- /dev/null
+++ b/components/brave_wayback_machine/brave_wayback_machine_browsertest.cc
@@ -0,0 +1,41 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/components/brave_wayback_machine/brave_wayback_machine_tab_helper.h"
+#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "components/infobars/core/infobar_manager.h"
+#include "content/public/browser/web_contents.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+using BraveWaybackMachineTest = InProcessBrowserTest;
+using ::testing::_;
+
+namespace {
+
+class TestObserver : public infobars::InfoBarManager::Observer {
+ public:
+ TestObserver() = default;
+ ~TestObserver() override = default;
+ MOCK_METHOD1(OnInfoBarAdded, void(infobars::InfoBar* infobar));
+};
+
+} // namespace
+
+IN_PROC_BROWSER_TEST_F(BraveWaybackMachineTest, InfobarAddTest) {
+ auto* model = browser()->tab_strip_model();
+ auto* contents = model->GetActiveWebContents();
+ auto* tab_helper = BraveWaybackMachineTabHelper::FromWebContents(contents);
+ auto* infobar_service = InfoBarService::FromWebContents(contents);
+
+ TestObserver observer;
+ EXPECT_CALL(observer, OnInfoBarAdded(_)).Times(1);
+ infobar_service->AddObserver(&observer);
+ tab_helper->CreateInfoBar();
+ infobar_service->RemoveObserver(&observer);
+}
diff --git a/components/brave_wayback_machine/brave_wayback_machine_delegate.h b/components/brave_wayback_machine/brave_wayback_machine_delegate.h
new file mode 100644
index 000000000000..553a5ad8a205
--- /dev/null
+++ b/components/brave_wayback_machine/brave_wayback_machine_delegate.h
@@ -0,0 +1,23 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_DELEGATE_H_
+#define BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_DELEGATE_H_
+
+
+namespace content {
+class WebContents;
+} // namespace content
+
+class BraveWaybackMachineInfoBarDelegate;
+
+class BraveWaybackMachineDelegate {
+ public:
+ virtual ~BraveWaybackMachineDelegate() = default;
+
+ virtual void CreateInfoBar(content::WebContents* web_contents) = 0;
+};
+
+#endif // BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_DELEGATE_H_
diff --git a/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.cc b/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.cc
new file mode 100644
index 000000000000..0294643e2cf2
--- /dev/null
+++ b/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.cc
@@ -0,0 +1,23 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.h"
+
+using InfoBarIdentifier = infobars::InfoBarDelegate::InfoBarIdentifier;
+
+BraveWaybackMachineInfoBarDelegate::
+BraveWaybackMachineInfoBarDelegate() = default;
+
+BraveWaybackMachineInfoBarDelegate::
+~BraveWaybackMachineInfoBarDelegate() = default;
+
+InfoBarIdentifier BraveWaybackMachineInfoBarDelegate::GetIdentifier() const {
+ return WAYBACK_MACHINE_INFOBAR_DELEGATE;
+}
+
+bool BraveWaybackMachineInfoBarDelegate::EqualsDelegate(
+ infobars::InfoBarDelegate* delegate) const {
+ return delegate->GetIdentifier() == GetIdentifier();
+}
diff --git a/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.h b/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.h
new file mode 100644
index 000000000000..2e2d1846769f
--- /dev/null
+++ b/components/brave_wayback_machine/brave_wayback_machine_infobar_delegate.h
@@ -0,0 +1,30 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_INFOBAR_DELEGATE_H_
+#define BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_INFOBAR_DELEGATE_H_
+
+#include
+
+#include "components/infobars/core/infobar_delegate.h"
+
+class BraveWaybackMachineInfoBarDelegate : public infobars::InfoBarDelegate {
+ public:
+ BraveWaybackMachineInfoBarDelegate();
+ ~BraveWaybackMachineInfoBarDelegate() override;
+
+ BraveWaybackMachineInfoBarDelegate(
+ const BraveWaybackMachineInfoBarDelegate&) = delete;
+ BraveWaybackMachineInfoBarDelegate& operator=(
+ const BraveWaybackMachineInfoBarDelegate&) = delete;
+
+ private:
+ // infobars::InfoBarDelegate overrides:
+ InfoBarIdentifier GetIdentifier() const override;
+ bool EqualsDelegate(
+ infobars::InfoBarDelegate* delegate) const override;
+};
+
+#endif // BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_INFOBAR_DELEGATE_H_
diff --git a/components/brave_wayback_machine/brave_wayback_machine_tab_helper.cc b/components/brave_wayback_machine/brave_wayback_machine_tab_helper.cc
new file mode 100644
index 000000000000..1b284ffe25c1
--- /dev/null
+++ b/components/brave_wayback_machine/brave_wayback_machine_tab_helper.cc
@@ -0,0 +1,96 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/components/brave_wayback_machine/brave_wayback_machine_tab_helper.h"
+
+#include
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/containers/flat_set.h"
+#include "base/task/post_task.h"
+#include "base/task/task_traits.h"
+#include "brave/components/brave_wayback_machine/brave_wayback_machine_delegate.h"
+#include "brave/components/brave_wayback_machine/pref_names.h"
+#include "components/prefs/pref_service.h"
+#include "components/user_prefs/user_prefs.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/web_contents.h"
+#include "net/http/http_response_headers.h"
+#include "net/http/http_status_code.h"
+
+BraveWaybackMachineTabHelper::BraveWaybackMachineTabHelper(
+ content::WebContents* contents)
+ : WebContentsObserver(contents),
+ weak_factory_(this) {
+ pref_service_ = user_prefs::UserPrefs::Get(contents->GetBrowserContext());
+}
+
+BraveWaybackMachineTabHelper::~BraveWaybackMachineTabHelper() = default;
+
+void BraveWaybackMachineTabHelper::set_delegate(
+ std::unique_ptr delegate) {
+ DCHECK(delegate);
+ delegate_ = std::move(delegate);
+}
+
+void BraveWaybackMachineTabHelper::DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) {
+ DCHECK(delegate_);
+ if (!IsWaybackMachineEnabled())
+ return;
+
+ if (!navigation_handle->IsInMainFrame() ||
+ navigation_handle->IsSameDocument()) {
+ return;
+ }
+
+ if (const net::HttpResponseHeaders* header =
+ navigation_handle->GetResponseHeaders()) {
+ if (!ShouldAttachWaybackMachineInfoBar(header->response_code()))
+ return;
+
+ // Create infobar in the next loop for not blocking navigation.
+ PostTask(FROM_HERE,
+ { base::CurrentThread(), base::TaskPriority::BEST_EFFORT },
+ base::BindOnce(&BraveWaybackMachineTabHelper::CreateInfoBar,
+ weak_factory_.GetWeakPtr()));
+ }
+}
+
+void BraveWaybackMachineTabHelper::CreateInfoBar() {
+ DCHECK(delegate_);
+ delegate_->CreateInfoBar(web_contents());
+}
+
+bool BraveWaybackMachineTabHelper::IsWaybackMachineEnabled() const {
+ return pref_service_->GetBoolean(kBraveWaybackMachineEnabled);
+}
+
+bool BraveWaybackMachineTabHelper::ShouldAttachWaybackMachineInfoBar(
+ int response_code) const {
+ static base::flat_set responses = {
+ net::HTTP_NOT_FOUND, // 404
+ net::HTTP_REQUEST_TIMEOUT, // 408
+ net::HTTP_GONE, // 410
+ 451, // Unavailable For Legal Reasons
+ net::HTTP_INTERNAL_SERVER_ERROR, // 500
+ net::HTTP_BAD_GATEWAY, // 502,
+ net::HTTP_SERVICE_UNAVAILABLE, // 503,
+ net::HTTP_GATEWAY_TIMEOUT, // 504,
+ 509, // Bandwidth Limit Exceeded
+ 520, // Web Server Returned an Unknown Error
+ 521, // Web Server Is Down
+ 523, // Origin Is Unreachable
+ 524, // A Timeout Occurred
+ 525, // SSL Handshake Failed
+ 526 // Invalid SSL Certificate
+ };
+
+ return responses.find(response_code) != responses.end();
+}
+
+WEB_CONTENTS_USER_DATA_KEY_IMPL(BraveWaybackMachineTabHelper)
diff --git a/components/brave_wayback_machine/brave_wayback_machine_tab_helper.h b/components/brave_wayback_machine/brave_wayback_machine_tab_helper.h
new file mode 100644
index 000000000000..138c14707ac7
--- /dev/null
+++ b/components/brave_wayback_machine/brave_wayback_machine_tab_helper.h
@@ -0,0 +1,51 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_TAB_HELPER_H_
+#define BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_TAB_HELPER_H_
+
+#include
+
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+class BraveWaybackMachineDelegate;
+class PrefService;
+
+class BraveWaybackMachineTabHelper
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData {
+ public:
+ explicit BraveWaybackMachineTabHelper(content::WebContents* contents);
+ ~BraveWaybackMachineTabHelper() override;
+
+ BraveWaybackMachineTabHelper(const BraveWaybackMachineTabHelper&) = delete;
+ BraveWaybackMachineTabHelper& operator=(
+ const BraveWaybackMachineTabHelper&) = delete;
+
+ void set_delegate(std::unique_ptr delegate);
+
+ WEB_CONTENTS_USER_DATA_KEY_DECL();
+ private:
+ FRIEND_TEST_ALL_PREFIXES(BraveWaybackMachineTest, InfobarAddTest);
+
+ // content::WebContentsObserver overrides:
+ void DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) override;
+
+ void CreateInfoBar();
+ bool IsWaybackMachineEnabled() const;
+
+ // virtual for test.
+ virtual bool ShouldAttachWaybackMachineInfoBar(int response_code) const;
+
+ PrefService* pref_service_ = nullptr;
+ std::unique_ptr delegate_;
+
+ base::WeakPtrFactory weak_factory_;
+};
+
+#endif // BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_BRAVE_WAYBACK_MACHINE_TAB_HELPER_H_
diff --git a/components/brave_wayback_machine/buildflags/buildflags.gni b/components/brave_wayback_machine/buildflags/buildflags.gni
new file mode 100644
index 000000000000..ff51d2517557
--- /dev/null
+++ b/components/brave_wayback_machine/buildflags/buildflags.gni
@@ -0,0 +1,3 @@
+declare_args() {
+ enable_brave_wayback_machine = is_win || is_mac || is_desktop_linux
+}
diff --git a/components/brave_wayback_machine/pref_names.cc b/components/brave_wayback_machine/pref_names.cc
new file mode 100644
index 000000000000..a184322fc9f5
--- /dev/null
+++ b/components/brave_wayback_machine/pref_names.cc
@@ -0,0 +1,8 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/components/brave_wayback_machine/pref_names.h"
+
+const char kBraveWaybackMachineEnabled[] = "brave.wayback_machine_enabled";
diff --git a/components/brave_wayback_machine/pref_names.h b/components/brave_wayback_machine/pref_names.h
new file mode 100644
index 000000000000..0713c1f3711e
--- /dev/null
+++ b/components/brave_wayback_machine/pref_names.h
@@ -0,0 +1,11 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_PREF_NAMES_H_
+#define BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_PREF_NAMES_H_
+
+extern const char kBraveWaybackMachineEnabled[];
+
+#endif // BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_PREF_NAMES_H_
diff --git a/components/brave_wayback_machine/wayback_machine_url_fetcher.cc b/components/brave_wayback_machine/wayback_machine_url_fetcher.cc
new file mode 100644
index 000000000000..7d83bce3da72
--- /dev/null
+++ b/components/brave_wayback_machine/wayback_machine_url_fetcher.cc
@@ -0,0 +1,89 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "brave/components/brave_wayback_machine/wayback_machine_url_fetcher.h"
+
+#include
+
+#include "base/bind.h"
+#include "base/json/json_reader.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 "url/gurl.h"
+
+namespace {
+
+constexpr int kMaxBodySize = 1024 * 1024;
+constexpr char kWaybackQueryURL[] =
+ "https://archive.org/wayback/available?url=";
+
+const net::NetworkTrafficAnnotationTag& GetNetworkTrafficAnnotationTag() {
+ static const net::NetworkTrafficAnnotationTag network_traffic_annotation_tag =
+ net::DefineNetworkTrafficAnnotation("wayback_machine_infobar", R"(
+ semantics {
+ sender:
+ "Brave Wayback Machine"
+ description:
+ "Download wayback url"
+ trigger:
+ "When user gets 404 page"
+ data: "current tab's url"
+ destination: WEBSITE
+ }
+ policy {
+ cookies_allowed: NO
+ policy_exception_justification:
+ "Not implemented."
+ })");
+ return network_traffic_annotation_tag;
+}
+
+} // namespace
+
+WaybackMachineURLFetcher::WaybackMachineURLFetcher(
+ Client* client,
+ scoped_refptr url_loader_factory)
+ : client_(client),
+ url_loader_factory_(std::move(url_loader_factory)) {
+}
+
+WaybackMachineURLFetcher::~WaybackMachineURLFetcher() {
+}
+
+void WaybackMachineURLFetcher::Fetch(const GURL& url) {
+ auto request = std::make_unique();
+ std::string wayback_fetch_url =
+ std::string(kWaybackQueryURL) + url.spec();
+ request->url = GURL(wayback_fetch_url);
+ wayback_url_loader_ = network::SimpleURLLoader::Create(
+ std::move(request), GetNetworkTrafficAnnotationTag());
+ wayback_url_loader_->DownloadToString(
+ url_loader_factory_.get(),
+ base::BindOnce(&WaybackMachineURLFetcher::OnWaybackURLFetched,
+ base::Unretained(this),
+ url),
+ kMaxBodySize);
+}
+
+void WaybackMachineURLFetcher::OnWaybackURLFetched(
+ const GURL& original_url,
+ std::unique_ptr response_body) {
+ if (!response_body) {
+ client_->OnWaybackURLFetched(GURL::EmptyGURL());
+ return;
+ }
+
+ std::string wayback_response_json = std::move(*response_body);
+ const auto result = base::JSONReader::Read(wayback_response_json);
+ if (!result || !result->FindPath("archived_snapshots.closest.url")) {
+ client_->OnWaybackURLFetched(GURL::EmptyGURL());
+ return;
+ }
+
+ client_->OnWaybackURLFetched(
+ GURL(result->FindPath("archived_snapshots.closest.url")->GetString()));
+}
diff --git a/components/brave_wayback_machine/wayback_machine_url_fetcher.h b/components/brave_wayback_machine/wayback_machine_url_fetcher.h
new file mode 100644
index 000000000000..88750b1ae9ea
--- /dev/null
+++ b/components/brave_wayback_machine/wayback_machine_url_fetcher.h
@@ -0,0 +1,52 @@
+/* Copyright (c) 2019 The Brave Authors. All rights reserved.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_WAYBACK_MACHINE_URL_FETCHER_H_
+#define BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_WAYBACK_MACHINE_URL_FETCHER_H_
+
+#include
+#include
+
+#include "base/memory/scoped_refptr.h"
+
+namespace network {
+class SharedURLLoaderFactory;
+class SimpleURLLoader;
+} // network
+
+class GURL;
+
+// This only tries to fetch one wayback url at once.
+// If client calls Fetch() before OnWaybackURLFetched is called, previous fetch
+// request is dropped.
+class WaybackMachineURLFetcher final {
+ public:
+ class Client {
+ public:
+ virtual void OnWaybackURLFetched(const GURL& lastest_wayback_url) = 0;
+ protected:
+ virtual ~Client() = default;
+ };
+
+ WaybackMachineURLFetcher(
+ Client* client,
+ scoped_refptr url_loader_factory);
+ virtual ~WaybackMachineURLFetcher();
+
+ WaybackMachineURLFetcher(const WaybackMachineURLFetcher&) = delete;
+ WaybackMachineURLFetcher& operator=(const WaybackMachineURLFetcher&) = delete;
+
+ void Fetch(const GURL& url);
+
+ private:
+ void OnWaybackURLFetched(const GURL& orignal_url,
+ std::unique_ptr response_body);
+
+ Client* client_;
+ scoped_refptr url_loader_factory_;
+ std::unique_ptr wayback_url_loader_;
+};
+
+#endif // BRAVE_COMPONENTS_BRAVE_WAYBACK_MACHINE_WAYBACK_MACHINE_URL_FETCHER_H_
diff --git a/patches/chrome-browser-ui-tab_helpers.cc.patch b/patches/chrome-browser-ui-tab_helpers.cc.patch
index efefc874f534..a9dac86dc84c 100644
--- a/patches/chrome-browser-ui-tab_helpers.cc.patch
+++ b/patches/chrome-browser-ui-tab_helpers.cc.patch
@@ -1,20 +1,10 @@
diff --git a/chrome/browser/ui/tab_helpers.cc b/chrome/browser/ui/tab_helpers.cc
-index 12af72905098faf0c10b9deafd41017f874035df..614d803ecf1df897bf07fc203eedcedae52a7e51 100644
+index 12af72905098faf0c10b9deafd41017f874035df..d3787db96587353e7bd151a97f5407dd2d17e487 100644
--- a/chrome/browser/ui/tab_helpers.cc
+++ b/chrome/browser/ui/tab_helpers.cc
-@@ -11,6 +11,7 @@
- #include "base/feature_list.h"
- #include "base/time/default_tick_clock.h"
- #include "base/trace_event/trace_event.h"
-+#include "brave/browser/brave_tab_helpers.h"
- #include "build/build_config.h"
- #include "chrome/browser/bookmarks/bookmark_model_factory.h"
- #include "chrome/browser/browser_process.h"
-@@ -199,6 +200,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
- autofill::ChromeAutofillClient::FromWebContents(web_contents),
- g_browser_process->GetApplicationLocale(),
- autofill::AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
+@@ -378,4 +378,5 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
+ // See https://crbug.com/910288.
+ resource_coordinator::ResourceCoordinatorTabHelper::CreateForWebContents(
+ web_contents);
+ brave::AttachTabHelpers(web_contents);
- chrome_browser_net::NetErrorTabHelper::CreateForWebContents(web_contents);
- ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
- web_contents,
+ }
diff --git a/patches/components-infobars-core-infobar_delegate.h.patch b/patches/components-infobars-core-infobar_delegate.h.patch
new file mode 100644
index 000000000000..7e99fcbfa1ad
--- /dev/null
+++ b/patches/components-infobars-core-infobar_delegate.h.patch
@@ -0,0 +1,12 @@
+diff --git a/components/infobars/core/infobar_delegate.h b/components/infobars/core/infobar_delegate.h
+index aeb127a573768ea92c5687e649c3a61c9e731fce..3b29bdc60ab77cede7a88ac2f6db42392dc328e1 100644
+--- a/components/infobars/core/infobar_delegate.h
++++ b/components/infobars/core/infobar_delegate.h
+@@ -159,6 +159,7 @@ class InfoBarDelegate {
+ TAB_SHARING_INFOBAR_DELEGATE = 93,
+ SAFETY_TIP_INFOBAR_DELEGATE = 94,
+ SMS_RECEIVER_INFOBAR_DELEGATE = 95,
++ BRAVE_INFOBAR_DELEGATE_IDENTIFIERS
+ };
+
+ // Describes navigation events, used to decide whether infobars should be
diff --git a/test/BUILD.gn b/test/BUILD.gn
index e1ceaaf212ec..495f759fd0d9 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -6,6 +6,7 @@ import("//brave/components/brave_referrals/buildflags/buildflags.gni")
import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni")
import("//brave/components/brave_sync/buildflags/buildflags.gni")
import("//brave/components/brave_wallet/browser/buildflags/buildflags.gni")
+import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni")
import("//brave/components/greaselion/browser/buildflags/buildflags.gni")
import("//components/gcm_driver/config.gni")
@@ -621,6 +622,12 @@ test("brave_browser_tests") {
]
}
+ if (enable_brave_wayback_machine) {
+ sources += [
+ "//brave/components/brave_wayback_machine/brave_wayback_machine_browsertest.cc",
+ ]
+ }
+
if (is_win || is_linux) {
sources += [
"//brave/browser/renderer_context_menu/brave_spelling_options_submenu_observer_browsertest.cc",