Skip to content

Commit

Permalink
Launched additional confirmation dialog to the end of support (uplift…
Browse files Browse the repository at this point in the history
… to 1.47.x) (#16734)
  • Loading branch information
simonhong authored Jan 19, 2023
1 parent 4cfe575 commit 65a76a1
Show file tree
Hide file tree
Showing 19 changed files with 572 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,15 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_WEB_DISCOVERY_INFOBAR_NO_THANKS_LABEL" desc="The text for no thanks button in infobar">
No thanks
</message>
<!-- obsolete system InfoBar -->
<if expr="is_win">
<message name="IDS_OBSOLETE_SYSTEM_INFOBAR_DONT_SHOW_BUTTON" desc="The text for don't show again button">
Don't show again
</message>
<message name="IDS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_CONTENT" desc="The text for obsolete system confirm dialog">
By clicking OK, you acknowledge that your installation of Brave will NOT receive critical security fixes until you update to Windows 10 or later. This warning will NOT show again.
</message>
</if>
</if>

<!-- Brave Ads -->
Expand Down
10 changes: 10 additions & 0 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
#include "build/build_config.h"
#include "chrome/browser/component_updater/component_updater_utils.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/obsolete_system/obsolete_system.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "components/component_updater/component_updater_service.h"
#include "components/component_updater/timer_update_scheduler.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -153,6 +155,14 @@ void BraveBrowserProcessImpl::Init() {
#endif

InitSystemRequestHandlerCallback();

#if !BUILDFLAG(IS_ANDROID)
if (!ObsoleteSystem::IsObsoleteNowOrSoon()) {
// Clear to show unsupported warning infobar again even if user
// suppressed it from previous os.
local_state()->ClearPref(prefs::kSuppressUnsupportedOSWarning);
}
#endif
}

#if !BUILDFLAG(IS_ANDROID)
Expand Down
1 change: 1 addition & 0 deletions browser/infobars/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source_set("infobars") {
# Remove when https://github.com/brave/brave-browser/issues/10649 is resolved
check_includes = false
sources = [
"brave_confirm_infobar_creator.h",
"brave_confirm_p3a_infobar_delegate.cc",
"brave_confirm_p3a_infobar_delegate.h",
"sync_cannot_run_infobar_delegate.cc",
Expand Down
20 changes: 20 additions & 0 deletions browser/infobars/brave_confirm_infobar_creator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_
#define BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_

#include <memory>

class BraveConfirmInfoBarDelegate;

namespace infobars {
class InfoBar;
} // namespace infobars

std::unique_ptr<infobars::InfoBar> CreateBraveConfirmInfoBar(
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate);

#endif // BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_
15 changes: 15 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,21 @@ source_set("ui") {
]
}

# brave's obsolete infobar is only used on Windows now.
if (is_win) {
sources += [
"startup/brave_obsolete_system_infobar_delegate.cc",
"startup/brave_obsolete_system_infobar_delegate.h",
]

if (toolkit_views) {
sources += [
"views/obsolete_system_confirm_dialog_view.cc",
"views/obsolete_system_confirm_dialog_view.h",
]
}
}

if (is_linux) {
sources += [
"views/brave_views_delegate_linux.cc",
Expand Down
5 changes: 5 additions & 0 deletions browser/ui/browser_dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
#ifndef BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_
#define BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_

#include "base/callback_forward.h"

class Browser;

namespace brave {

// Tab restore dialog will be launched after ask dialog is closed.
void ShowCrashReportPermissionAskDialog(Browser* browser);

// Run |callback| when dialog closed.
void ShowObsoleteSystemConfirmDialog(base::OnceCallback<void(bool)> callback);

} // namespace brave

#endif // BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_
100 changes: 100 additions & 0 deletions browser/ui/startup/brave_obsolete_system_infobar_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* Copyright (c) 2022 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 https://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/startup/brave_obsolete_system_infobar_delegate.h"

#include <memory>

#include "base/bind.h"
#include "brave/browser/infobars/brave_confirm_infobar_creator.h"
#include "brave/browser/ui/browser_dialogs.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/infobars/confirm_infobar_creator.h"
#include "chrome/browser/obsolete_system/obsolete_system.h"
#include "chrome/common/pref_names.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/infobar.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"

// static
void BraveObsoleteSystemInfoBarDelegate::Create(
infobars::ContentInfoBarManager* infobar_manager) {
infobar_manager->AddInfoBar(
CreateBraveConfirmInfoBar(std::unique_ptr<BraveConfirmInfoBarDelegate>(
new BraveObsoleteSystemInfoBarDelegate())));
}

BraveObsoleteSystemInfoBarDelegate::BraveObsoleteSystemInfoBarDelegate() =
default;
BraveObsoleteSystemInfoBarDelegate::~BraveObsoleteSystemInfoBarDelegate() =
default;

bool BraveObsoleteSystemInfoBarDelegate::HasCheckbox() const {
return true;
}

std::u16string BraveObsoleteSystemInfoBarDelegate::GetCheckboxText() const {
return l10n_util::GetStringUTF16(
IDS_OBSOLETE_SYSTEM_INFOBAR_DONT_SHOW_BUTTON);
}

void BraveObsoleteSystemInfoBarDelegate::SetCheckboxChecked(bool checked) {
launch_confirmation_dialog_ = checked;
}

bool BraveObsoleteSystemInfoBarDelegate::InterceptClosing() {
if (!launch_confirmation_dialog_)
return false;

// This infobar will be destroyed after confirmation dialog closed.
brave::ShowObsoleteSystemConfirmDialog(base::BindOnce(
&BraveObsoleteSystemInfoBarDelegate::OnConfirmDialogClosing,
weak_factory_.GetWeakPtr()));
return true;
}

int BraveObsoleteSystemInfoBarDelegate::GetButtons() const {
return BUTTON_NONE;
}

void BraveObsoleteSystemInfoBarDelegate::OnConfirmDialogClosing(bool suppress) {
if (suppress) {
if (PrefService* local_state = g_browser_process->local_state()) {
local_state->SetBoolean(prefs::kSuppressUnsupportedOSWarning, true);
}
}

// infobar()->RemoveSelf() will destroy this also.
// Do not refer anything after this.
infobar()->RemoveSelf();
}

infobars::InfoBarDelegate::InfoBarIdentifier
BraveObsoleteSystemInfoBarDelegate::GetIdentifier() const {
return OBSOLETE_SYSTEM_INFOBAR_DELEGATE;
}

std::u16string BraveObsoleteSystemInfoBarDelegate::GetLinkText() const {
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
}

GURL BraveObsoleteSystemInfoBarDelegate::GetLinkURL() const {
return GURL(ObsoleteSystem::GetLinkURL());
}

std::u16string BraveObsoleteSystemInfoBarDelegate::GetMessageText() const {
return ObsoleteSystem::LocalizedObsoleteString();
}

bool BraveObsoleteSystemInfoBarDelegate::ShouldExpire(
const NavigationDetails& details) const {
// Since the obsolete system infobar communicates critical state ("your system
// is no longer receiving updates") it should persist until explicitly
// dismissed.
return false;
}
50 changes: 50 additions & 0 deletions browser/ui/startup/brave_obsolete_system_infobar_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright (c) 2022 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 https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_STARTUP_BRAVE_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_
#define BRAVE_BROWSER_UI_STARTUP_BRAVE_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_

#include <string>

#include "base/memory/weak_ptr.h"
#include "brave/components/infobars/core/brave_confirm_infobar_delegate.h"

namespace infobars {
class ContentInfoBarManager;
} // namespace infobars

class BraveObsoleteSystemInfoBarDelegate : public BraveConfirmInfoBarDelegate {
public:
static void Create(infobars::ContentInfoBarManager* infobar_manager);

BraveObsoleteSystemInfoBarDelegate(
const BraveObsoleteSystemInfoBarDelegate&) = delete;
BraveObsoleteSystemInfoBarDelegate& operator=(
const BraveObsoleteSystemInfoBarDelegate&) = delete;

private:
BraveObsoleteSystemInfoBarDelegate();
~BraveObsoleteSystemInfoBarDelegate() override;

// BraveConfirmInfoBarDelegate overrides:
bool HasCheckbox() const override;
std::u16string GetCheckboxText() const override;
void SetCheckboxChecked(bool checked) override;
bool InterceptClosing() override;
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
std::u16string GetLinkText() const override;
GURL GetLinkURL() const override;
std::u16string GetMessageText() const override;
int GetButtons() const override;
bool ShouldExpire(const NavigationDetails& details) const override;

void OnConfirmDialogClosing(bool suppress);

bool launch_confirmation_dialog_ = false;

base::WeakPtrFactory<BraveObsoleteSystemInfoBarDelegate> weak_factory_{this};
};

#endif // BRAVE_BROWSER_UI_STARTUP_BRAVE_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_
3 changes: 3 additions & 0 deletions browser/ui/views/infobars/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source_set("brave_wayback_machine") {
# Remove when https://github.com/brave/brave-browser/issues/10652 is resolved
check_includes = false
sources = [
"brave_confirm_infobar.cc",
"brave_confirm_infobar.h",
"brave_infobar_container_view.cc",
"brave_infobar_container_view.h",
"brave_wayback_machine_infobar_button_container.cc",
Expand All @@ -26,6 +28,7 @@ source_set("brave_wayback_machine") {
"//brave/app/vector_icons",
"//brave/browser/themes",
"//brave/components/brave_wayback_machine",
"//brave/components/infobars/core",
"//chrome/browser:theme_properties",
"//components/infobars/content",
"//components/infobars/core",
Expand Down
88 changes: 88 additions & 0 deletions browser/ui/views/infobars/brave_confirm_infobar.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/infobars/brave_confirm_infobar.h"

#include <memory>
#include <utility>

#include "base/bind.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/views/controls/button/checkbox.h"

namespace {

constexpr int kCheckboxSpacing = 20;

} // namespace

std::unique_ptr<infobars::InfoBar> CreateBraveConfirmInfoBar(
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate) {
return std::make_unique<BraveConfirmInfoBar>(std::move(delegate));
}

BraveConfirmInfoBar::BraveConfirmInfoBar(
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {
auto* delegate_ptr = GetBraveDelegate();
DCHECK(delegate_ptr);

if (delegate_ptr->HasCheckbox()) {
// We don't consider case where ok/cancel button and check box exist
// together.
DCHECK(!ok_button_ && !cancel_button_);
checkbox_ = AddChildView(std::make_unique<views::Checkbox>(
delegate_ptr->GetCheckboxText(),
base::BindRepeating(&BraveConfirmInfoBar::CheckboxPressed,
base::Unretained(this))));
}
}

BraveConfirmInfoBar::~BraveConfirmInfoBar() = default;

void BraveConfirmInfoBar::Layout() {
ConfirmInfoBar::Layout();

// Early return when checkbox is not used.
// This class is only valid when this infobar has checkbox now.
// NOTE: Revisit when we want to use other buttons together with checkbox.
if (!checkbox_)
return;

checkbox_->SizeToPreferredSize();

const int x = label_->bounds().right() + kCheckboxSpacing;
checkbox_->SetPosition(gfx::Point(x, OffsetY(checkbox_)));
}

BraveConfirmInfoBarDelegate* BraveConfirmInfoBar::GetBraveDelegate() {
return static_cast<BraveConfirmInfoBarDelegate*>(
ConfirmInfoBar::GetDelegate());
}

void BraveConfirmInfoBar::CheckboxPressed() {
GetBraveDelegate()->SetCheckboxChecked(checkbox_->GetChecked());
}

int BraveConfirmInfoBar::NonLabelWidth() const {
const int width = ConfirmInfoBar::NonLabelWidth();

// Early return when checkbox is not used.
// This class is only valid when this infobar has checkbox now.
if (!checkbox_)
return width;

return width + checkbox_->width() + kCheckboxSpacing;
}

void BraveConfirmInfoBar::CloseButtonPressed() {
if (GetBraveDelegate()->InterceptClosing())
return;

ConfirmInfoBar::CloseButtonPressed();
}

BEGIN_METADATA(BraveConfirmInfoBar, ConfirmInfoBar)
END_METADATA
Loading

0 comments on commit 65a76a1

Please sign in to comment.