Commit b6c64fce authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[Infobars] Prepare Android's C++ ConfirmInfobar for componentization

In preparation for componentization of this class for sharing with
WebLayer, this CL cleans it of //chrome dependencies. We do so by
introducing a simple ChromeConfirmInfoBar convenience subclass that
glues ConfirmInfobar to //chrome, which will then enable ConfirmInfobar
itself to be componentized and reused by WebLayer. Note that any
//chrome-level subclasses of ChromeConfirmInfoBar could still easily
be componentized if desired in the future by simply changing them to
subclass from ConfirmInfoBar directly and take in the needed additional
parameters in *their* constructors for supplying by the embedder.

Bug: 1099169
Change-Id: I20b57b37eec57ed9932c6a3610f64e3860ac2900
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2272323
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#783855}
parent 96034ad8
......@@ -26,7 +26,7 @@ SafetyTipInfoBar::~SafetyTipInfoBar() {}
SafetyTipInfoBar::SafetyTipInfoBar(
std::unique_ptr<SafetyTipInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
ScopedJavaLocalRef<jobject> SafetyTipInfoBar::CreateRenderInfoBar(JNIEnv* env) {
ScopedJavaLocalRef<jstring> ok_button_text =
......
......@@ -7,13 +7,13 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
class SafetyTipInfoBarDelegate;
// SafetyTipInfoBar is a thin vineer over ConfirmInfoBar that adds a discrete
// description (instead of just having a title).
class SafetyTipInfoBar : public ConfirmInfoBar {
class SafetyTipInfoBar : public ChromeConfirmInfoBar {
public:
static std::unique_ptr<infobars::InfoBar> CreateInfoBar(
std::unique_ptr<SafetyTipInfoBarDelegate> delegate);
......
......@@ -27,7 +27,7 @@ KnownInterceptionDisclosureInfoBar::CreateInfoBar(
KnownInterceptionDisclosureInfoBar::KnownInterceptionDisclosureInfoBar(
std::unique_ptr<KnownInterceptionDisclosureInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
ScopedJavaLocalRef<jobject>
KnownInterceptionDisclosureInfoBar::CreateRenderInfoBar(JNIEnv* env) {
......
......@@ -10,14 +10,14 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
#include "components/infobars/core/infobar.h"
class KnownInterceptionDisclosureInfoBarDelegate;
// KnownInterceptionDisclosureInfoBar is a thin veneer over ConfirmInfoBar that
// adds a discrete description (instead of just having a title).
class KnownInterceptionDisclosureInfoBar : public ConfirmInfoBar {
class KnownInterceptionDisclosureInfoBar : public ChromeConfirmInfoBar {
public:
static std::unique_ptr<infobars::InfoBar> CreateInfoBar(
std::unique_ptr<KnownInterceptionDisclosureInfoBarDelegate> delegate);
......
......@@ -681,6 +681,8 @@ static_library("ui") {
"android/infobars/autofill_credit_card_filling_infobar.h",
"android/infobars/autofill_save_card_infobar.cc",
"android/infobars/autofill_save_card_infobar.h",
"android/infobars/chrome_confirm_infobar.cc",
"android/infobars/chrome_confirm_infobar.h",
"android/infobars/confirm_infobar.cc",
"android/infobars/confirm_infobar.h",
"android/infobars/data_reduction_promo_infobar.cc",
......
......@@ -14,7 +14,7 @@ using base::android::JavaParamRef;
AdsBlockedInfoBar::AdsBlockedInfoBar(
std::unique_ptr<AdsBlockedInfobarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
AdsBlockedInfoBar::~AdsBlockedInfoBar() {}
......
......@@ -7,9 +7,9 @@
#include "base/macros.h"
#include "chrome/browser/ui/android/content_settings/ads_blocked_infobar_delegate.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
class AdsBlockedInfoBar : public ConfirmInfoBar {
class AdsBlockedInfoBar : public ChromeConfirmInfoBar {
public:
explicit AdsBlockedInfoBar(
std::unique_ptr<AdsBlockedInfobarDelegate> delegate);
......
......@@ -21,7 +21,7 @@ using base::android::ScopedJavaLocalRef;
AutofillCreditCardFillingInfoBar::AutofillCreditCardFillingInfoBar(
std::unique_ptr<autofill::AutofillCreditCardFillingInfoBarDelegateMobile>
delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
AutofillCreditCardFillingInfoBar::~AutofillCreditCardFillingInfoBar() {}
......
......@@ -10,7 +10,7 @@
#include <memory>
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
namespace autofill {
class AutofillCreditCardFillingInfoBarDelegateMobile;
......@@ -20,7 +20,7 @@ class AutofillCreditCardFillingInfoBarDelegateMobile;
// proposes to autofill user data into the detected credit card form in the
// page. Upon accepting the infobar, the form is filled automatically. If
// the infobar is dismissed, nothing happens.
class AutofillCreditCardFillingInfoBar : public ConfirmInfoBar {
class AutofillCreditCardFillingInfoBar : public ChromeConfirmInfoBar {
public:
explicit AutofillCreditCardFillingInfoBar(
std::unique_ptr<autofill::AutofillCreditCardFillingInfoBarDelegateMobile>
......
......@@ -32,7 +32,7 @@ std::unique_ptr<infobars::InfoBar> CreateSaveCardInfoBarMobile(
AutofillSaveCardInfoBar::AutofillSaveCardInfoBar(
std::unique_ptr<autofill::AutofillSaveCardInfoBarDelegateMobile> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
AutofillSaveCardInfoBar::~AutofillSaveCardInfoBar() {}
......
......@@ -10,14 +10,14 @@
#include <memory>
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
namespace autofill {
class AutofillSaveCardInfoBarDelegateMobile;
}
// Android implementation of the infobar for saving credit card information.
class AutofillSaveCardInfoBar : public ConfirmInfoBar {
class AutofillSaveCardInfoBar : public ChromeConfirmInfoBar {
public:
explicit AutofillSaveCardInfoBar(
std::unique_ptr<autofill::AutofillSaveCardInfoBarDelegateMobile>
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "chrome/browser/android/resource_mapper.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "content/public/browser/web_contents.h"
// InfoBarService -------------------------------------------------------------
std::unique_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate> delegate) {
return std::make_unique<ChromeConfirmInfoBar>(std::move(delegate));
}
// ChromeConfirmInfoBar
// -------------------------------------------------------------
ChromeConfirmInfoBar::ChromeConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate> delegate)
: ConfirmInfoBar(
std::move(delegate),
base::BindRepeating(&ResourceMapper::MapToJavaDrawableId)) {}
ChromeConfirmInfoBar::~ChromeConfirmInfoBar() {}
TabAndroid* ChromeConfirmInfoBar::GetTab() {
content::WebContents* web_contents =
InfoBarService::WebContentsFromInfoBar(this);
DCHECK(web_contents);
TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
DCHECK(tab);
return tab;
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_CHROME_CONFIRM_INFOBAR_H_
#define CHROME_BROWSER_UI_ANDROID_INFOBARS_CHROME_CONFIRM_INFOBAR_H_
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
class TabAndroid;
// Chrome-specific convenience specialization of ConfirmInfoBar that supplies
// Chrome-level parameters.
class ChromeConfirmInfoBar : public ConfirmInfoBar {
public:
explicit ChromeConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate> delegate);
~ChromeConfirmInfoBar() override;
ChromeConfirmInfoBar(const ChromeConfirmInfoBar&) = delete;
ChromeConfirmInfoBar& operator=(const ChromeConfirmInfoBar&) = delete;
protected:
TabAndroid* GetTab();
};
#endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_CHROME_CONFIRM_INFOBAR_H_
......@@ -8,34 +8,17 @@
#include <utility>
#include "base/android/jni_string.h"
#include "base/bind.h"
#include "chrome/browser/android/resource_mapper.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/ui/messages/android/jni_headers/ConfirmInfoBar_jni.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "content/public/browser/web_contents.h"
#include "ui/android/window_android.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/image/image.h"
using base::android::JavaParamRef;
using base::android::ScopedJavaLocalRef;
// InfoBarService -------------------------------------------------------------
std::unique_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate> delegate) {
return std::make_unique<ConfirmInfoBar>(std::move(delegate));
}
// ConfirmInfoBar -------------------------------------------------------------
ConfirmInfoBar::ConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate> delegate)
: InfoBarAndroid(
std::move(delegate),
base::BindRepeating(&ResourceMapper::MapToJavaDrawableId)) {}
ConfirmInfoBar::ConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate> delegate,
const ResourceIdMapper& resource_id_mapper)
: InfoBarAndroid(std::move(delegate), resource_id_mapper) {}
ConfirmInfoBar::~ConfirmInfoBar() {
}
......@@ -51,16 +34,6 @@ ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() {
return delegate()->AsConfirmInfoBarDelegate();
}
TabAndroid* ConfirmInfoBar::GetTab() {
content::WebContents* web_contents =
InfoBarService::WebContentsFromInfoBar(this);
DCHECK(web_contents);
TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
DCHECK(tab);
return tab;
}
ScopedJavaLocalRef<jobject> ConfirmInfoBar::CreateRenderInfoBar(JNIEnv* env) {
ScopedJavaLocalRef<jstring> ok_button_text =
base::android::ConvertUTF16ToJavaString(
......
......@@ -11,16 +11,14 @@
#include "components/infobars/android/infobar_android.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
class TabAndroid;
class ConfirmInfoBar : public InfoBarAndroid {
public:
explicit ConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate> delegate);
ConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate> delegate,
const ResourceIdMapper& resource_id_mapper);
~ConfirmInfoBar() override;
protected:
ConfirmInfoBarDelegate* GetDelegate();
TabAndroid* GetTab();
base::string16 GetTextFor(ConfirmInfoBarDelegate::InfoBarButton button);
// InfoBarAndroid overrides.
......
......@@ -17,7 +17,7 @@
DataReductionPromoInfoBar::DataReductionPromoInfoBar(
std::unique_ptr<DataReductionPromoInfoBarDelegateAndroid> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
DataReductionPromoInfoBar::~DataReductionPromoInfoBar() {
}
......
......@@ -7,9 +7,9 @@
#include "base/macros.h"
#include "chrome/browser/data_reduction_proxy/data_reduction_promo_infobar_delegate_android.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
class DataReductionPromoInfoBar : public ConfirmInfoBar {
class DataReductionPromoInfoBar : public ChromeConfirmInfoBar {
public:
explicit DataReductionPromoInfoBar(
std::unique_ptr<DataReductionPromoInfoBarDelegateAndroid> delegate);
......
......@@ -25,7 +25,7 @@ DuplicateDownloadInfoBar::~DuplicateDownloadInfoBar() {
DuplicateDownloadInfoBar::DuplicateDownloadInfoBar(
std::unique_ptr<DuplicateDownloadInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
base::android::ScopedJavaLocalRef<jobject>
DuplicateDownloadInfoBar::CreateRenderInfoBar(JNIEnv* env) {
......
......@@ -7,7 +7,7 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
namespace android {
class DuplicateDownloadInfoBarDelegate;
......@@ -15,7 +15,7 @@ class DuplicateDownloadInfoBarDelegate;
// A native-side implementation of an infobar to ask whether to continue
// downloading if target file already exists.
class DuplicateDownloadInfoBar : public ConfirmInfoBar {
class DuplicateDownloadInfoBar : public ChromeConfirmInfoBar {
public:
static std::unique_ptr<infobars::InfoBar> CreateInfoBar(
std::unique_ptr<android::DuplicateDownloadInfoBarDelegate> delegate);
......
......@@ -64,7 +64,7 @@ ScopedJavaLocalRef<jobject> CreateRenderInfoBarHelper(
GroupedPermissionInfoBar::GroupedPermissionInfoBar(
std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
GroupedPermissionInfoBar::~GroupedPermissionInfoBar() {}
......
......@@ -5,13 +5,13 @@
#ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_GROUPED_PERMISSION_INFOBAR_H_
#define CHROME_BROWSER_UI_ANDROID_INFOBARS_GROUPED_PERMISSION_INFOBAR_H_
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
class GroupedPermissionInfoBarDelegate;
// TODO(andypaicu): rename this to PermissionInfoBar, grouped permissions are
// not a thing anymore.
class GroupedPermissionInfoBar : public ConfirmInfoBar {
class GroupedPermissionInfoBar : public ChromeConfirmInfoBar {
public:
explicit GroupedPermissionInfoBar(
std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate);
......
......@@ -12,7 +12,7 @@
InstantAppsInfoBar::InstantAppsInfoBar(
std::unique_ptr<InstantAppsInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
InstantAppsInfoBar::~InstantAppsInfoBar() {}
......
......@@ -8,9 +8,9 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/android/instantapps/instant_apps_infobar_delegate.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
class InstantAppsInfoBar : public ConfirmInfoBar {
class InstantAppsInfoBar : public ChromeConfirmInfoBar {
public:
InstantAppsInfoBar(
std::unique_ptr<InstantAppsInfoBarDelegate> delegate);
......
......@@ -12,7 +12,7 @@
PreviewsLitePageInfoBar::PreviewsLitePageInfoBar(
std::unique_ptr<PreviewsLitePageInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
PreviewsLitePageInfoBar::~PreviewsLitePageInfoBar() {}
......
......@@ -10,11 +10,11 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/previews/previews_lite_page_infobar_delegate.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
// This InfoBar notifies the user that Data Saver now also applies to HTTPS
// pages.
class PreviewsLitePageInfoBar : public ConfirmInfoBar {
class PreviewsLitePageInfoBar : public ChromeConfirmInfoBar {
public:
explicit PreviewsLitePageInfoBar(
std::unique_ptr<PreviewsLitePageInfoBarDelegate> delegate);
......
......@@ -17,7 +17,7 @@ using base::android::JavaParamRef;
SavePasswordInfoBar::SavePasswordInfoBar(
std::unique_ptr<SavePasswordInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
SavePasswordInfoBar::~SavePasswordInfoBar() {}
......
......@@ -7,12 +7,12 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
class SavePasswordInfoBarDelegate;
// The infobar to be used with SavePasswordInfoBarDelegate.
class SavePasswordInfoBar : public ConfirmInfoBar {
class SavePasswordInfoBar : public ChromeConfirmInfoBar {
public:
explicit SavePasswordInfoBar(
std::unique_ptr<SavePasswordInfoBarDelegate> delegate);
......
......@@ -6,7 +6,7 @@
SyncErrorInfoBar::SyncErrorInfoBar(
std::unique_ptr<SyncErrorInfoBarDelegateAndroid> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
SyncErrorInfoBar::~SyncErrorInfoBar() {}
......
......@@ -8,9 +8,9 @@
#include "base/android/jni_android.h"
#include "base/macros.h"
#include "chrome/browser/sync/sync_error_infobar_delegate_android.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
class SyncErrorInfoBar : public ConfirmInfoBar {
class SyncErrorInfoBar : public ChromeConfirmInfoBar {
public:
explicit SyncErrorInfoBar(
std::unique_ptr<SyncErrorInfoBarDelegateAndroid> delegate);
......
......@@ -19,7 +19,7 @@ using base::android::JavaParamRef;
UpdatePasswordInfoBar::UpdatePasswordInfoBar(
std::unique_ptr<UpdatePasswordInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {}
: ChromeConfirmInfoBar(std::move(delegate)) {}
UpdatePasswordInfoBar::~UpdatePasswordInfoBar() {}
......
......@@ -7,12 +7,12 @@
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
class UpdatePasswordInfoBarDelegate;
// The infobar to be used with UpdatePasswordInfoBarDelegate.
class UpdatePasswordInfoBar : public ConfirmInfoBar {
class UpdatePasswordInfoBar : public ChromeConfirmInfoBar {
public:
explicit UpdatePasswordInfoBar(
std::unique_ptr<UpdatePasswordInfoBarDelegate> delegate);
......
......@@ -32,7 +32,7 @@ void SmsInfoBar::Create(content::WebContents* web_contents,
SmsInfoBar::SmsInfoBar(content::WebContents* web_contents,
std::unique_ptr<SmsInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)), web_contents_(web_contents) {}
: ChromeConfirmInfoBar(std::move(delegate)), web_contents_(web_contents) {}
SmsInfoBar::~SmsInfoBar() = default;
......
......@@ -9,7 +9,7 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "chrome/browser/ui/android/infobars/chrome_confirm_infobar.h"
namespace content {
class WebContents;
......@@ -21,7 +21,7 @@ class Origin;
class SmsInfoBarDelegate;
class SmsInfoBar : public ConfirmInfoBar {
class SmsInfoBar : public ChromeConfirmInfoBar {
public:
SmsInfoBar(content::WebContents* web_contents,
std::unique_ptr<SmsInfoBarDelegate> delegate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment