Skip to content

Commit

Permalink
Added don't show again button to obsolete system infobar
Browse files Browse the repository at this point in the history
fix brave/brave-browser#27122

W/o this, user will see this infobar whenever brave is launched.
  • Loading branch information
simonhong authored and sangwoo108 committed Apr 4, 2023
1 parent 9fb9faa commit 8b1a90f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ 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 -->
<message name="IDS_OBSOLERE_SYSTEM_INFOBAR_DONT_SHOW_BUTTON" desc="The text for don't show again button">
Don't show again
</message>
</if>

<!-- Brave Ads -->
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ source_set("ui") {
"omnibox/brave_omnibox_client_impl.cc",
"omnibox/brave_omnibox_client_impl.h",
"session_crashed_bubble_brave.cc",
"startup/brave_obsolete_system_infobar_delegate.cc",
"startup/brave_obsolete_system_infobar_delegate.h",
"toolbar/brave_app_menu_model.cc",
"toolbar/brave_app_menu_model.h",
"toolbar/brave_recent_tabs_sub_menu_model.h",
Expand Down
46 changes: 46 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,46 @@
/* 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 <memory>

#include "brave/browser/ui/startup/brave_obsolete_system_infobar_delegate.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/infobars/confirm_infobar_creator.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 "ui/base/l10n/l10n_util.h"

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

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

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

std::u16string BraveObsoleteSystemInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
return l10n_util::GetStringUTF16(
IDS_OBSOLERE_SYSTEM_INFOBAR_DONT_SHOW_BUTTON);
}

bool BraveObsoleteSystemInfoBarDelegate::Accept() {
if (PrefService* local_state = g_browser_process->local_state()) {
local_state->SetBoolean(prefs::kSuppressUnsupportedOSWarning, true);
}
return true;
}
39 changes: 39 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,39 @@
/* 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 "chrome/browser/ui/startup/obsolete_system_infobar_delegate.h"

namespace infobars {
class ContentInfoBarManager;
} // namespace infobars

// Subclassed for showing "Don't show again" button.
// W/o this button, user will see this infobar whenever launched.
class BraveObsoleteSystemInfoBarDelegate
: public ObsoleteSystemInfoBarDelegate {
public:
static void Create(infobars::ContentInfoBarManager* infobar_manager);

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

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

// ObsoleteSystemInfoBarDelegate overrides:
int GetButtons() const override;
std::u16string GetButtonLabel(InfoBarButton button) const override;
bool Accept() override;
};

#endif // BRAVE_BROWSER_UI_STARTUP_BRAVE_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_
6 changes: 5 additions & 1 deletion chromium_src/chrome/browser/ui/startup/infobar_utils.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* Copyright (c) 2021 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/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/startup/brave_obsolete_system_infobar_delegate.h"
#include "chrome/browser/ui/session_crashed_bubble.h"
#include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h"
#include "components/infobars/content/content_infobar_manager.h"
Expand All @@ -16,7 +17,10 @@ class BraveGoogleKeysInfoBarDelegate {

#define ShowIfNotOffTheRecordProfile ShowIfNotOffTheRecordProfileBrave
#define GoogleApiKeysInfoBarDelegate BraveGoogleKeysInfoBarDelegate
#define ObsoleteSystemInfoBarDelegate BraveObsoleteSystemInfoBarDelegate

#include "src/chrome/browser/ui/startup/infobar_utils.cc"

#undef ObsoleteSystemInfoBarDelegate
#undef GoogleApiKeysInfoBarDelegate
#undef ShowIfNotOffTheRecordProfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* 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_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_

#include "components/infobars/core/confirm_infobar_delegate.h"

#define Create \
Create_UnUsed() {} \
friend class BraveObsoleteSystemInfoBarDelegate; \
static void Create

#include "src/chrome/browser/ui/startup/obsolete_system_infobar_delegate.h"

#undef Create

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_

0 comments on commit 8b1a90f

Please sign in to comment.