Skip to content

Commit

Permalink
Revert "Use dialog for wayback machine instead of infobar" (uplift to…
Browse files Browse the repository at this point in the history
… 1.65.x) (#22588)

* Revert "Use dialog for wayback machine instead of infobar"

This reverts commit a5cd49e.

* Fixed presubmit check failure
  • Loading branch information
simonhong authored Mar 14, 2024
1 parent c44bf88 commit 506e7aa
Show file tree
Hide file tree
Showing 27 changed files with 223 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@

// Reflects enum items from chromium_src/components/infobars/core/infobar_delegate.h

@IntDef({BraveInfoBarIdentifier.INVALID, BraveInfoBarIdentifier.BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.SYNC_CANNOT_RUN_INFOBAR,
BraveInfoBarIdentifier.WEB_DISCOVERY_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR})

@IntDef({
BraveInfoBarIdentifier.INVALID,
BraveInfoBarIdentifier.BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.WAYBACK_MACHINE_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.SYNC_CANNOT_RUN_INFOBAR,
BraveInfoBarIdentifier.WEB_DISCOVERY_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR
})
@Retention(RetentionPolicy.SOURCE)
public @interface BraveInfoBarIdentifier {
int INVALID = -1;
int BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE = 500;
// int WAYBACK_MACHINE_INFOBAR_DELEGATE = 502; - deprecated
int WAYBACK_MACHINE_INFOBAR_DELEGATE = 502;
// int SYNC_V2_MIGRATE_INFOBAR_DELEGATE = 503; - deprecated
// int ANDROID_SYSTEM_SYNC_DISABLED_INFOBAR = 504; - deprecated
int SYNC_CANNOT_RUN_INFOBAR = 505;
Expand Down
6 changes: 0 additions & 6 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -928,12 +928,6 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_BRAVE_WAYBACK_MACHINE_DONT_ASK_AGAIN_TEXT" desc="Text to show for the don't ask again button.">
Don't ask me again
</message>
<message name="IDS_BRAVE_WAYBACK_MACHINE_NO_THANKS_BUTTON_TEXT" desc="Text to show for the no thanks button.">
No thanks
</message>
<message name="IDS_BRAVE_WAYBACK_MACHINE_CLOSE_BUTTON_TEXT" desc="Text to show for the close button.">
Close
</message>

<!-- Brave's copyright statement -->
<message name="IDS_BRAVE_VERSION_UI_LICENSE" desc="The label below the copyright message, containing the URLs.">
Expand Down
2 changes: 2 additions & 0 deletions app/theme/brave_theme_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<structure type="chrome_scaled_image" name="IDR_BRAVE_BOOKMARK_FOLDER_OPEN_LIN_LIGHT" file="common/brave_bookmark_folder_open_lin_light.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_BOOKMARK_FOLDER_OPEN_WIN_DARK" file="common/brave_bookmark_folder_open_win_dark.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_BOOKMARK_FOLDER_OPEN_WIN_LIGHT" file="common/brave_bookmark_folder_open_win_light.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_WAYBACK_INFOBAR" file="brave/brave_wayback_infobar.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_WAYBACK_INFOBAR_DARK" file="brave/brave_wayback_infobar_dark.png" />
</if>

<if expr="enable_ai_chat">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 9 additions & 5 deletions browser/infobars/brave_wayback_machine_delegate_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

#include "brave/browser/infobars/brave_wayback_machine_delegate_impl.h"

#include <memory>

#include "base/command_line.h"
#include "brave/browser/ui/browser_dialogs.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 "brave/components/constants/brave_switches.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/infobar.h"

// static
void BraveWaybackMachineDelegateImpl::AttachTabHelperIfNeeded(
Expand All @@ -28,7 +28,11 @@ void BraveWaybackMachineDelegateImpl::AttachTabHelperIfNeeded(
BraveWaybackMachineDelegateImpl::BraveWaybackMachineDelegateImpl() = default;
BraveWaybackMachineDelegateImpl::~BraveWaybackMachineDelegateImpl() = default;

void BraveWaybackMachineDelegateImpl::ShowWaybackMachineDialog(
void BraveWaybackMachineDelegateImpl::CreateInfoBar(
content::WebContents* web_contents) {
brave::ShowWaybackMachineWebModalDialog(web_contents);
infobars::ContentInfoBarManager::FromWebContents(web_contents)
->AddInfoBar(CreateInfoBarView(
std::make_unique<BraveWaybackMachineInfoBarDelegate>(),
web_contents),
true);
}
15 changes: 13 additions & 2 deletions browser/infobars/brave_wayback_machine_delegate_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
#ifndef BRAVE_BROWSER_INFOBARS_BRAVE_WAYBACK_MACHINE_DELEGATE_IMPL_H_
#define BRAVE_BROWSER_INFOBARS_BRAVE_WAYBACK_MACHINE_DELEGATE_IMPL_H_

#include <memory>

#include "brave/components/brave_wayback_machine/brave_wayback_machine_delegate.h"

namespace content {
class WebContents;
} // namespace content

// TODO(simonhong): Move this to //brave/browser/wayback_machine.
namespace infobars {
class InfoBar;
} // namespace infobars

class BraveWaybackMachineInfoBarDelegate;

class BraveWaybackMachineDelegateImpl : public BraveWaybackMachineDelegate {
public:
static void AttachTabHelperIfNeeded(content::WebContents* web_contents);
Expand All @@ -27,7 +34,11 @@ class BraveWaybackMachineDelegateImpl : public BraveWaybackMachineDelegate {

private:
// BraveWaybackMachineDelegate overrides:
void ShowWaybackMachineDialog(content::WebContents* web_contents) override;
void CreateInfoBar(content::WebContents* web_contents) override;

std::unique_ptr<infobars::InfoBar> CreateInfoBarView(
std::unique_ptr<BraveWaybackMachineInfoBarDelegate> delegate,
content::WebContents* contents);
};

#endif // BRAVE_BROWSER_INFOBARS_BRAVE_WAYBACK_MACHINE_DELEGATE_IMPL_H_
9 changes: 1 addition & 8 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,7 @@ source_set("ui") {
deps += [ "//brave/components/brave_wayback_machine" ]

if (toolkit_views) {
sources += [
"views/wayback_machine_dialog_view.cc",
"views/wayback_machine_dialog_view.h",
"views/wayback_machine_fetch_button.cc",
"views/wayback_machine_fetch_button.h",
"views/wayback_machine_throbber.cc",
"views/wayback_machine_throbber.h",
]
deps += [ "//brave/browser/ui/views/infobars:brave_wayback_machine" ]
}
}

Expand Down
3 changes: 0 additions & 3 deletions browser/ui/browser_dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ void ShowTextRecognitionDialog(content::WebContents* web_contents,
#if BUILDFLAG(ENABLE_BRAVE_VPN)
void ShowBraveVpnIKEv2FallbackDialog();
#endif

void ShowWaybackMachineWebModalDialog(content::WebContents* web_contents);

} // namespace brave

#endif // BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_
46 changes: 46 additions & 0 deletions browser/ui/views/infobars/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,52 @@ source_set("infobars") {
]
}

if (enable_brave_wayback_machine) {
source_set("brave_wayback_machine") {
# Remove when https://github.com/brave/brave-browser/issues/10652 is resolved
check_includes = false

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/theme:brave_theme_resources",
"//brave/app/vector_icons",
"//brave/browser/themes",
"//brave/components/brave_wayback_machine",
"//chrome/browser:theme_properties",
"//components/infobars/content",
"//components/infobars/core",
"//components/prefs:prefs",
"//components/resources",
"//components/user_prefs",
"//content/public/browser",
"//ui/base",
"//ui/gfx",
"//ui/native_theme",
"//ui/views",
"//url",
]

# Below dep list are indirectly used by brave_wayback_machine target.
# Only added to fix intermittent build failure.
# chrome/common/buildflags.h is included indirectly from
# brave_wayback_machine_infobar_contents_view.cc.
# However, this buildflags.h sometimes not generated when
# brave_wayback_machine_infobar_contents_view.cc is compiled.
deps += [ "//chrome/common:buildflags" ]
}
}

source_set("brave_sync_account_deleted_infobar") {
# Remove when https://github.com/brave/brave-browser/issues/10652 is resolved
check_includes = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/wayback_machine_fetch_button.h"
#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_button_container.h"

#include <memory>
#include <utility>

#include "brave/browser/ui/views/wayback_machine_throbber.h"
#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.h"
#include "brave/components/l10n/common/localization_util.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
Expand All @@ -21,27 +21,27 @@ constexpr int kThrobberDiameter = 16;
constexpr int kInsetOffsetsForThrobber = kThrobberDiameter;
} // namespace

WaybackMachineFetchButton::
WaybackMachineFetchButton(
BraveWaybackMachineInfoBarButtonContainer::
BraveWaybackMachineInfoBarButtonContainer(
views::Button::PressedCallback callback) {
auto button = std::make_unique<views::MdTextButton>(
std::move(callback), brave_l10n::GetLocalizedResourceUTF16String(
IDS_BRAVE_WAYBACK_MACHINE_CHECK_BUTTON_TEXT));
button_ = button.get();
button->SetKind(views::MdTextButton::Kind::kPrimary);
button->SetStyle(ui::ButtonStyle::kProminent);
button->SizeToPreferredSize();
AddChildView(button.release());

throbber_ = new WaybackMachineThrobber;
throbber_ = new BraveWaybackMachineInfoBarThrobber;
throbber_->SetSize(gfx::Size(kThrobberDiameter, kThrobberDiameter));
throbber_->SetVisible(false);
button_->AddChildView(throbber_.get());
}

WaybackMachineFetchButton::
~WaybackMachineFetchButton() = default;
BraveWaybackMachineInfoBarButtonContainer::
~BraveWaybackMachineInfoBarButtonContainer() = default;

void WaybackMachineFetchButton::Layout(PassKey) {
void BraveWaybackMachineInfoBarButtonContainer::Layout(PassKey) {
if (throbber_->GetVisible()) {
int x = button_->width() - throbber_->width() - kThrobberDiameter / 2;
int y = (button_->height() - throbber_->height()) / 2;
Expand All @@ -50,27 +50,27 @@ void WaybackMachineFetchButton::Layout(PassKey) {
}

gfx::Size
WaybackMachineFetchButton::CalculatePreferredSize() const {
BraveWaybackMachineInfoBarButtonContainer::CalculatePreferredSize() const {
// This container doesn't need more space than button because throbber is
// drawn over the button.
return button_->GetPreferredSize();
}

void WaybackMachineFetchButton::StartThrobber() {
void BraveWaybackMachineInfoBarButtonContainer::StartThrobber() {
AdjustButtonInsets(true);
throbber_->SetVisible(true);
throbber_->Start();
DeprecatedLayoutImmediately();
}

void WaybackMachineFetchButton::StopThrobber() {
void BraveWaybackMachineInfoBarButtonContainer::StopThrobber() {
AdjustButtonInsets(false);
throbber_->SetVisible(false);
throbber_->Stop();
DeprecatedLayoutImmediately();
}

void WaybackMachineFetchButton::AdjustButtonInsets(
void BraveWaybackMachineInfoBarButtonContainer::AdjustButtonInsets(
bool add_insets) {
const gfx::Insets insets_offset =
gfx::Insets::TLBR(0, 0, 0, kInsetOffsetsForThrobber);
Expand All @@ -81,5 +81,5 @@ void WaybackMachineFetchButton::AdjustButtonInsets(
button_->SizeToPreferredSize();
}

BEGIN_METADATA(WaybackMachineFetchButton)
BEGIN_METADATA(BraveWaybackMachineInfoBarButtonContainer)
END_METADATA
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_VIEWS_WAYBACK_MACHINE_FETCH_BUTTON_H_
#define BRAVE_BROWSER_UI_VIEWS_WAYBACK_MACHINE_FETCH_BUTTON_H_
#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 "base/memory/raw_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"

class WaybackMachineThrobber;
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 WaybackMachineFetchButton : public views::View {
METADATA_HEADER(WaybackMachineFetchButton, views::View)
class BraveWaybackMachineInfoBarButtonContainer : public views::View {
METADATA_HEADER(BraveWaybackMachineInfoBarButtonContainer, views::View)
public:
explicit WaybackMachineFetchButton(views::Button::PressedCallback callback);
~WaybackMachineFetchButton() override;
explicit BraveWaybackMachineInfoBarButtonContainer(
views::Button::PressedCallback callback);
~BraveWaybackMachineInfoBarButtonContainer() override;

WaybackMachineFetchButton(const WaybackMachineFetchButton&) = delete;
WaybackMachineFetchButton& operator=(const WaybackMachineFetchButton&) =
delete;
BraveWaybackMachineInfoBarButtonContainer(
const BraveWaybackMachineInfoBarButtonContainer&) = delete;
BraveWaybackMachineInfoBarButtonContainer& operator=(
const BraveWaybackMachineInfoBarButtonContainer&) = delete;

void StartThrobber();
void StopThrobber();
Expand All @@ -37,8 +39,8 @@ class WaybackMachineFetchButton : public views::View {
private:
void AdjustButtonInsets(bool add_insets);

raw_ptr<WaybackMachineThrobber> throbber_ = nullptr;
raw_ptr<BraveWaybackMachineInfoBarThrobber> throbber_ = nullptr;
raw_ptr<views::View> button_ = nullptr;
};

#endif // BRAVE_BROWSER_UI_VIEWS_WAYBACK_MACHINE_FETCH_BUTTON_H_
#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_WAYBACK_MACHINE_INFOBAR_BUTTON_CONTAINER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/wayback_machine_throbber.h"
#include "brave/browser/ui/views/infobars/brave_wayback_machine_infobar_throbber.h"

#include "base/functional/bind.h"
#include "base/location.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/paint_throbber.h"

WaybackMachineThrobber::WaybackMachineThrobber() =
BraveWaybackMachineInfoBarThrobber::BraveWaybackMachineInfoBarThrobber() =
default;

WaybackMachineThrobber::~WaybackMachineThrobber() {
BraveWaybackMachineInfoBarThrobber::~BraveWaybackMachineInfoBarThrobber() {
Stop();
}

void WaybackMachineThrobber::Start() {
void BraveWaybackMachineInfoBarThrobber::Start() {
if (IsRunning())
return;

start_time_ = base::TimeTicks::Now();
timer_.Start(
FROM_HERE, base::Milliseconds(30),
base::BindRepeating(&WaybackMachineThrobber::SchedulePaint,
base::BindRepeating(&BraveWaybackMachineInfoBarThrobber::SchedulePaint,
base::Unretained(this)));
SchedulePaint(); // paint right away
}

void WaybackMachineThrobber::Stop() {
void BraveWaybackMachineInfoBarThrobber::Stop() {
if (!IsRunning())
return;

timer_.Stop();
SchedulePaint();
}

void WaybackMachineThrobber::OnPaint(gfx::Canvas* canvas) {
void BraveWaybackMachineInfoBarThrobber::OnPaint(gfx::Canvas* canvas) {
if (!IsRunning())
return;

Expand All @@ -47,9 +47,9 @@ void WaybackMachineThrobber::OnPaint(gfx::Canvas* canvas) {
canvas, GetContentsBounds(), SK_ColorWHITE, elapsed_time);
}

bool WaybackMachineThrobber::IsRunning() const {
bool BraveWaybackMachineInfoBarThrobber::IsRunning() const {
return timer_.IsRunning();
}

BEGIN_METADATA(WaybackMachineThrobber)
BEGIN_METADATA(BraveWaybackMachineInfoBarThrobber)
END_METADATA
Loading

0 comments on commit 506e7aa

Please sign in to comment.