Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix#8497 - Added 'Don't ask me again' button to Wayback Machine infobar #9030

Merged
merged 3 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_BRAVE_WAYBACK_MACHINE_CHECK_BUTTON_TEXT" desc="The label for check button on wayback infobar">
Check for saved version
</message>
<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>
<!-- Brave's copyright statement -->
<message name="IDS_BRAVE_VERSION_UI_LICENSE" desc="The label below the copyright message, containing the URLs.">
Brave is made available to you under the <ph name="BEGIN_LINK_MPL">&lt;a target="_blank" rel="noopener noreferrer" href="$1"&gt;</ph>Mozilla Public License 2.0<ph name="END_LINK_MPL">&lt;/a&gt;</ph> (MPL) and includes <ph name="BEGIN_LINK_OSS">&lt;a target="_blank" rel="noopener noreferrer" href="$2"&gt;</ph>open source software<ph name="END_LINK_OSS">&lt;/a&gt;</ph> under a variety of other licenses.
Expand Down
6 changes: 3 additions & 3 deletions browser/ui/views/infobars/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ source_set("brave_wayback_machine") {
"//brave/app:brave_generated_resources_grit",
"//brave/app/vector_icons",
"//brave/components/brave_wayback_machine",
"//components/prefs:prefs",
"//components/resources",
"//components/user_prefs",
"//content/public/browser",
"//ui/base",
"//ui/gfx",
Expand All @@ -31,7 +33,5 @@ source_set("brave_wayback_machine") {
# 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",
]
deps += [ "//chrome/common:buildflags" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#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/brave_wayback_machine_infobar_delegate.h"
#include "brave/components/brave_wayback_machine/pref_names.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"
Expand All @@ -22,6 +23,8 @@
#include "chrome/browser/ui/views/chrome_typography.h"
#include "components/grit/components_scaled_resources.h"
#include "components/infobars/core/infobar.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
simonhong marked this conversation as resolved.
Show resolved Hide resolved
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/storage_partition.h"
Expand All @@ -36,6 +39,7 @@
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/style/platform_style.h"
#include "ui/views/view_class_properties.h"
#include "url/gurl.h"

Expand All @@ -53,6 +57,7 @@ BraveWaybackMachineInfoBarContentsView::BraveWaybackMachineInfoBarContentsView(
content::BrowserContext::GetDefaultStoragePartition(
contents->GetBrowserContext())->
GetURLLoaderFactoryForBrowserProcess()) {
pref_service_ = user_prefs::UserPrefs::Get(contents_->GetBrowserContext());
SetLayoutManager(std::make_unique<views::FlexLayout>());
InitializeChildren();
}
Expand Down Expand Up @@ -82,7 +87,7 @@ void BraveWaybackMachineInfoBarContentsView::OnWaybackURLFetched(
DCHECK(wayback_url_fetch_requested_);
wayback_url_fetch_requested_ = false;

button_->StopThrobber();
fetch_url_button_->StopThrobber();
Layout();

if (latest_wayback_url.is_empty()) {
Expand Down Expand Up @@ -110,14 +115,19 @@ void BraveWaybackMachineInfoBarContentsView::HideInfobar() {
}
}

void BraveWaybackMachineInfoBarContentsView::ButtonPressed() {
void BraveWaybackMachineInfoBarContentsView::FetchURLButtonPressed() {
if (wayback_url_fetch_requested_)
return;
wayback_url_fetch_requested_ = true;

dont_ask_button_->SetVisible(false);
FetchWaybackURL();
}

void BraveWaybackMachineInfoBarContentsView::DontAskButtonPressed() {
pref_service_->SetBoolean(kBraveWaybackMachineEnabled, false);
HideInfobar();
}

void BraveWaybackMachineInfoBarContentsView::InitializeChildren() {
wayback_spot_graphic_ = new views::ImageView();
wayback_spot_graphic_->SetProperty(views::kMarginsKey,
Expand Down Expand Up @@ -176,17 +186,41 @@ void BraveWaybackMachineInfoBarContentsView::InitializeChildren() {
0));
AddChildView(label);

button_ = new BraveWaybackMachineInfoBarButtonContainer(base::BindRepeating(
&BraveWaybackMachineInfoBarContentsView::ButtonPressed,
base::Unretained(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_);
dont_ask_button_ = AddChildView(std::make_unique<views::MdTextButton>(
base::BindRepeating(
&BraveWaybackMachineInfoBarContentsView::DontAskButtonPressed,
base::Unretained(this)),
l10n_util::GetStringUTF16(
IDS_BRAVE_WAYBACK_MACHINE_DONT_ASK_AGAIN_TEXT)));
views_visible_before_checking_.push_back(dont_ask_button_);

fetch_url_button_ =
AddChildView(std::make_unique<BraveWaybackMachineInfoBarButtonContainer>(
base::BindRepeating(
&BraveWaybackMachineInfoBarContentsView::FetchURLButtonPressed,
base::Unretained(this))));
views_visible_before_checking_.push_back(fetch_url_button_);

const gfx::Insets first_button_margin(
ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TOAST_CONTROL_VERTICAL),
ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_RELATED_CONTROL_HORIZONTAL_SMALL));

const gfx::Insets second_button_margin(
ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TOAST_CONTROL_VERTICAL),
0);

if (views::PlatformStyle::kIsOkButtonLeading) {
// Move |dont_ask_button_| at the end.
ReorderChildView(dont_ask_button_, -1);
fetch_url_button_->SetProperty(views::kMarginsKey, first_button_margin);
dont_ask_button_->SetProperty(views::kMarginsKey, second_button_margin);
} else {
dont_ask_button_->SetProperty(views::kMarginsKey, first_button_margin);
fetch_url_button_->SetProperty(views::kMarginsKey, second_button_margin);
}

UpdateChildrenVisibility(true);
}
Expand Down Expand Up @@ -217,7 +251,7 @@ SkColor BraveWaybackMachineInfoBarContentsView::GetColor(int id) const {
}

void BraveWaybackMachineInfoBarContentsView::FetchWaybackURL() {
button_->StartThrobber();
fetch_url_button_->StartThrobber();
wayback_machine_url_fetcher_.Fetch(contents_->GetVisibleURL());
Layout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Label;

class BraveWaybackMachineInfoBarButtonContainer;
class GURL;
class PrefService;

// Includes all view controls except close button that managed by InfoBarView.
class BraveWaybackMachineInfoBarContentsView
Expand Down Expand Up @@ -55,7 +56,8 @@ class BraveWaybackMachineInfoBarContentsView
void LoadURL(const GURL& url);
void HideInfobar();

void ButtonPressed();
void FetchURLButtonPressed();
void DontAskButtonPressed();

// Used for labels theme changing all together.
Labels labels_;
Expand All @@ -64,7 +66,9 @@ class BraveWaybackMachineInfoBarContentsView
content::WebContents* contents_;
WaybackMachineURLFetcher wayback_machine_url_fetcher_;

BraveWaybackMachineInfoBarButtonContainer* button_ = nullptr;
BraveWaybackMachineInfoBarButtonContainer* fetch_url_button_ = nullptr;
views::View* dont_ask_button_ = nullptr;
PrefService* pref_service_ = nullptr;
views::ImageView* wayback_spot_graphic_ = nullptr;
bool wayback_url_fetch_requested_ = false;
};
Expand Down