Commit ad6cb071 authored by Balazs Engedy's avatar Balazs Engedy Committed by Commit Bot

Experimental Mini-Infobar UI for Notifications Prompts

This CL adds the ability to display notification permission requests as
mini-infobars on Android by re-purposing dead code that had been earlier
used for "grouped permissions".

Java-side support is added for initially showing the infobar in the
compact form (i.e. as a mini-infobar), with a "Details" link that allows
toggling into a full infobar.

The full infobar has a "Manage" button that opens notification settings,
such that the infobar will still be visible after the user returns to
the tab requesting the permission.

Bug: 986737
Change-Id: Id25bf9bbb4e1d92082523a2557c10db2927d87c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760727Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Commit-Queue: Balazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693312}
parent fc8c6000
...@@ -139,12 +139,11 @@ public class InfoBarCompactLayout extends LinearLayout implements View.OnClickLi ...@@ -139,12 +139,11 @@ public class InfoBarCompactLayout extends LinearLayout implements View.OnClickLi
return this; return this;
} }
/** The link will be appended after the main message. */ /** Appends a link after the main message, its displayed text being the specified string. */
public MessageBuilder withLink(@StringRes int textResId, Callback<View> onTapCallback) { public MessageBuilder withLink(CharSequence label, Callback<View> onTapCallback) {
assert mLink == null; assert mLink == null;
final Resources resources = mLayout.getResources(); final Resources resources = mLayout.getResources();
String label = resources.getString(textResId);
SpannableString link = new SpannableString(label); SpannableString link = new SpannableString(label);
link.setSpan(new NoUnderlineClickableSpan(resources, onTapCallback), 0, label.length(), link.setSpan(new NoUnderlineClickableSpan(resources, onTapCallback), 0, label.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE); Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
...@@ -153,6 +152,16 @@ public class InfoBarCompactLayout extends LinearLayout implements View.OnClickLi ...@@ -153,6 +152,16 @@ public class InfoBarCompactLayout extends LinearLayout implements View.OnClickLi
return this; return this;
} }
/**
* Appends a link after the main message, its displayed text being constructed from the
* given resource ID.
*/
public MessageBuilder withLink(@StringRes int textResId, Callback<View> onTapCallback) {
final Resources resources = mLayout.getResources();
String label = resources.getString(textResId);
return withLink(label, onTapCallback);
}
/** Finalizes the message view as set up in the builder and inserts it into the layout. */ /** Finalizes the message view as set up in the builder and inserts it into the layout. */
public void buildAndInsert() { public void buildAndInsert() {
mLayout.addContent(build(), 1f); mLayout.addContent(build(), 1f);
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
package org.chromium.chrome.browser.infobar; package org.chromium.chrome.browser.infobar;
import android.graphics.Bitmap; import android.os.Bundle;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ResourceId; import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.permissions.AndroidPermissionRequester; import org.chromium.chrome.browser.permissions.AndroidPermissionRequester;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences;
import org.chromium.chrome.browser.preferences.website.SiteSettingsCategory;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
/** /**
...@@ -24,68 +27,136 @@ public class PermissionInfoBar ...@@ -24,68 +27,136 @@ public class PermissionInfoBar
/** The content settings types corresponding to the permission requested in this infobar. */ /** The content settings types corresponding to the permission requested in this infobar. */
protected int[] mContentSettingsTypes; protected int[] mContentSettingsTypes;
/** Whether the last clicked button was the "Manage" (secondary) button. */
protected boolean mManageButtonLastClicked;
/** Whether the infobar should be shown as a compact mini-infobar or a classic expanded one. */
private boolean mIsExpanded;
/** The text of the link shown in the compact state. */
private String mCompactLinkText;
/** The message text in the compact state. */
private String mCompactMessage;
/** The secondary text shown below the message in the expanded state. */
private String mDescription;
protected PermissionInfoBar(Tab tab, int[] contentSettingsTypes, int iconDrawableId, protected PermissionInfoBar(Tab tab, int[] contentSettingsTypes, int iconDrawableId,
Bitmap iconBitmap, String message, String linkText, String primaryButtonText, String compactMessage, String compactLinkText, String message, String description,
String secondaryButtonText) { String primaryButtonText, String secondaryButtonText) {
super(iconDrawableId, R.color.infobar_icon_drawable_color, iconBitmap, message, linkText, super(iconDrawableId, R.color.infobar_icon_drawable_color, null /* iconBitmap */, message,
primaryButtonText, secondaryButtonText); null /* linkText */, primaryButtonText, secondaryButtonText);
mTab = tab; mTab = tab;
mContentSettingsTypes = contentSettingsTypes; mContentSettingsTypes = contentSettingsTypes;
mManageButtonLastClicked = false;
mIsExpanded = false;
mCompactLinkText = compactLinkText;
mCompactMessage = compactMessage;
mDescription = description;
} }
@Override @Override
public void createContent(InfoBarLayout layout) { protected boolean usesCompactLayout() {
super.createContent(layout); return !mIsExpanded;
} }
@Override @Override
public void onAndroidPermissionAccepted() { protected void createCompactLayoutContent(InfoBarCompactLayout layout) {
onButtonClickedInternal(true); new InfoBarCompactLayout.MessageBuilder(layout)
.withText(mCompactMessage)
.withLink(mCompactLinkText, view -> onLinkClicked())
.buildAndInsert();
} }
@Override @Override
public void onAndroidPermissionCanceled() { public boolean areControlsEnabled() {
onCloseButtonClicked(); // The controls need to be enbled after the user clicks `manage` since they will return to
// the page and the infobar still needs to be kept active.
return super.areControlsEnabled() || mManageButtonLastClicked;
} }
@Override @Override
public void onButtonClicked(final boolean isPrimaryButton) { public void onButtonClicked(final boolean isPrimaryButton) {
// requestAndroidPermissions will call back into this class to finalize the action if it mManageButtonLastClicked = !isPrimaryButton;
// returns true. if (getContext() == null) {
if (!isPrimaryButton || getContext() == null
|| !AndroidPermissionRequester.requestAndroidPermissions(
mTab, mContentSettingsTypes.clone(), this)) {
onButtonClickedInternal(isPrimaryButton); onButtonClickedInternal(isPrimaryButton);
return; return;
} }
if (isPrimaryButton) {
// requestAndroidPermissions will call back into this class to finalize the action if it
// returns true.
if (AndroidPermissionRequester.requestAndroidPermissions(
mTab, mContentSettingsTypes.clone(), this)) {
return;
}
} else {
launchNotificationsSettingsPage();
}
onButtonClickedInternal(isPrimaryButton);
}
@Override
public void onLinkClicked() {
if (!mIsExpanded) {
mIsExpanded = true;
replaceView(createView());
}
super.onLinkClicked();
}
@Override
public void createContent(InfoBarLayout layout) {
super.createContent(layout);
layout.getMessageLayout().addDescription(mDescription);
}
@Override
public void onAndroidPermissionAccepted() {
onButtonClickedInternal(true);
}
@Override
public void onAndroidPermissionCanceled() {
onCloseButtonClicked();
} }
private void onButtonClickedInternal(boolean isPrimaryButton) { private void onButtonClickedInternal(boolean isPrimaryButton) {
super.onButtonClicked(isPrimaryButton); super.onButtonClicked(isPrimaryButton);
} }
private void launchNotificationsSettingsPage() {
Bundle fragmentArguments = new Bundle();
fragmentArguments.putString(SingleCategoryPreferences.EXTRA_CATEGORY,
SiteSettingsCategory.preferenceKey(SiteSettingsCategory.Type.NOTIFICATIONS));
PreferencesLauncher.launchSettingsPage(
getContext(), SingleCategoryPreferences.class, fragmentArguments);
}
/** /**
* Creates and begins the process for showing a PermissionInfoBar. * Creates and begins the process for showing a PermissionInfoBar.
* @param tab The owning tab for the infobar. * @param tab The owning tab for the infobar.
* @param contentSettingsTypes The list of ContentSettingTypes being requested by this infobar.
* @param enumeratedIconId ID corresponding to the icon that will be shown for the infobar. * @param enumeratedIconId ID corresponding to the icon that will be shown for the infobar.
* The ID must have been mapped using the ResourceMapper class * The ID must have been mapped using the ResourceMapper class
* before passing it to this function. * before passing it to this function.
* @param iconBitmap Bitmap to use if there is no equivalent Java resource for * @param compactMessage Message to show in the compact state.
* enumeratedIconId. * @param compactLinkText Text of link displayed right to the message in compact state.
* @param message Message to tell the user the purpose of the infobar. * @param message Primary message in the extended state.
* @param linkText Link text to display in addition to the message. * @param description Secondary message (description) in the expanded state.
* @param buttonOk String to display on the OK button. * @param buttonOk String to display on the OK button.
* @param buttonCancel String to display on the Cancel button. * @param buttonManage String to display on the Manage button.
* @param contentSettingsTypes The list of ContentSettingTypes being requested by this infobar.
*/ */
@CalledByNative @CalledByNative
private static PermissionInfoBar create(Tab tab, int enumeratedIconId, Bitmap iconBitmap, private static PermissionInfoBar create(Tab tab, int[] contentSettingsTypes,
String message, String linkText, String buttonOk, String buttonCancel, int enumeratedIconId, String compactMessage, String compactLinkText, String message,
int[] contentSettingsTypes) { String description, String buttonOk, String buttonManage) {
int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); int drawableId = ResourceId.mapToDrawableId(enumeratedIconId);
PermissionInfoBar infoBar = new PermissionInfoBar(tab, contentSettingsTypes, drawableId, PermissionInfoBar infoBar = new PermissionInfoBar(tab, contentSettingsTypes, drawableId,
iconBitmap, message, linkText, buttonOk, buttonCancel); compactMessage, compactLinkText, message, description, buttonOk, buttonManage);
return infoBar; return infoBar;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chrome/browser/android/android_theme_resources.h" #include "chrome/browser/android/android_theme_resources.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/permissions/permission_features.h"
#include "chrome/browser/permissions/permission_prompt_android.h" #include "chrome/browser/permissions/permission_prompt_android.h"
#include "chrome/browser/permissions/permission_request.h" #include "chrome/browser/permissions/permission_request.h"
#include "chrome/browser/permissions/permission_util.h" #include "chrome/browser/permissions/permission_util.h"
...@@ -23,9 +24,10 @@ GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} ...@@ -23,9 +24,10 @@ GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {}
infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create( infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create(
const base::WeakPtr<PermissionPromptAndroid>& permission_prompt, const base::WeakPtr<PermissionPromptAndroid>& permission_prompt,
InfoBarService* infobar_service) { InfoBarService* infobar_service) {
return infobar_service->AddInfoBar( // WrapUnique needs to be used because the constructor is private.
std::make_unique<GroupedPermissionInfoBar>(base::WrapUnique( return infobar_service->AddInfoBar(std::make_unique<GroupedPermissionInfoBar>(
new GroupedPermissionInfoBarDelegate(permission_prompt)))); base::WrapUnique(new GroupedPermissionInfoBarDelegate(permission_prompt,
infobar_service))));
} }
size_t GroupedPermissionInfoBarDelegate::PermissionCount() const { size_t GroupedPermissionInfoBarDelegate::PermissionCount() const {
...@@ -37,12 +39,28 @@ ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( ...@@ -37,12 +39,28 @@ ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType(
return permission_prompt_->GetContentSettingType(position); return permission_prompt_->GetContentSettingType(position);
} }
base::string16 GroupedPermissionInfoBarDelegate::GetCompactMessageText() const {
return l10n_util::GetStringUTF16(
IDS_NOTIFICATION_QUIET_PERMISSION_MINI_INFOBAR_MESSAGE);
}
base::string16 GroupedPermissionInfoBarDelegate::GetCompactLinkText() const {
return l10n_util::GetStringUTF16(
IDS_NOTIFICATION_QUIET_PERMISSION_MINI_INFOBAR_DETAILS_LINK);
}
base::string16 GroupedPermissionInfoBarDelegate::GetDescriptionText() const {
return l10n_util::GetStringUTF16(
IDS_NOTIFICATION_QUIET_PERMISSION_PROMPT_MESSAGE);
}
int GroupedPermissionInfoBarDelegate::GetIconId() const { int GroupedPermissionInfoBarDelegate::GetIconId() const {
return permission_prompt_->GetIconId(); return permission_prompt_->GetIconId();
} }
base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
return permission_prompt_->GetMessageText(); return l10n_util::GetStringUTF16(
IDS_NOTIFICATION_QUIET_PERMISSION_INFOBAR_TITLE);
} }
bool GroupedPermissionInfoBarDelegate::Accept() { bool GroupedPermissionInfoBarDelegate::Accept() {
...@@ -52,9 +70,8 @@ bool GroupedPermissionInfoBarDelegate::Accept() { ...@@ -52,9 +70,8 @@ bool GroupedPermissionInfoBarDelegate::Accept() {
} }
bool GroupedPermissionInfoBarDelegate::Cancel() { bool GroupedPermissionInfoBarDelegate::Cancel() {
if (permission_prompt_) // The infobar needs to be kept open after the "Manage" button is clicked.
permission_prompt_->Deny(); return false;
return true;
} }
void GroupedPermissionInfoBarDelegate::InfoBarDismissed() { void GroupedPermissionInfoBarDelegate::InfoBarDismissed() {
...@@ -62,10 +79,30 @@ void GroupedPermissionInfoBarDelegate::InfoBarDismissed() { ...@@ -62,10 +79,30 @@ void GroupedPermissionInfoBarDelegate::InfoBarDismissed() {
permission_prompt_->Closing(); permission_prompt_->Closing();
} }
bool GroupedPermissionInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
return false;
}
// static
bool GroupedPermissionInfoBarDelegate::ShouldShowMiniInfobar(
ContentSettingsType type) {
return QuietNotificationsPromptConfig::UIFlavorToUse() ==
QuietNotificationsPromptConfig::UIFlavor::MINI_INFOBAR &&
type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
}
GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate(
const base::WeakPtr<PermissionPromptAndroid>& permission_prompt) const base::WeakPtr<PermissionPromptAndroid>& permission_prompt,
: permission_prompt_(permission_prompt) { InfoBarService* infobar_service)
DCHECK(permission_prompt); : permission_prompt_(permission_prompt), infobar_service_(infobar_service) {
DCHECK(permission_prompt_);
DCHECK(infobar_service_);
// Infobars are only used for NOTIFICATIONS right now, therefore strings can
// be hardcoded for that type.
DCHECK_EQ(permission_prompt_->GetContentSettingType(0u),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
} }
infobars::InfoBarDelegate::InfoBarIdentifier infobars::InfoBarDelegate::InfoBarIdentifier
...@@ -79,8 +116,10 @@ int GroupedPermissionInfoBarDelegate::GetButtons() const { ...@@ -79,8 +116,10 @@ int GroupedPermissionInfoBarDelegate::GetButtons() const {
base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const { InfoBarButton button) const {
return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW return l10n_util::GetStringUTF16(
: IDS_PERMISSION_DENY); (button == BUTTON_OK)
? IDS_NOTIFICATIONS_QUIET_PERMISSION_BUBBLE_ALLOW_BUTTON
: IDS_NOTIFICATION_BUTTON_MANAGE);
} }
bool GroupedPermissionInfoBarDelegate::EqualsDelegate( bool GroupedPermissionInfoBarDelegate::EqualsDelegate(
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
class InfoBarService; class InfoBarService;
class PermissionPromptAndroid; class PermissionPromptAndroid;
// An InfoBar that displays a group of permission requests, each of which can be // An InfoBar that displays a permission request.
// allowed or blocked independently. //
// TODO(timloh): This is incorrectly named as we've removed grouped permissions, // TODO(crbug.com/986737): This class is only used for displaying notification
// rename it to PermissionInfoBarDelegate once crbug.com/606138 is done. // permission requests and has nothing to do with grouped permissions anymore.
class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
public: public:
// Public so we can have std::unique_ptr<GroupedPermissionInfoBarDelegate>. // Public so we can have std::unique_ptr<GroupedPermissionInfoBarDelegate>.
...@@ -31,6 +31,15 @@ class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -31,6 +31,15 @@ class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
ContentSettingsType GetContentSettingType(size_t position) const; ContentSettingsType GetContentSettingType(size_t position) const;
// Returns the string to show in the infobar in its compact state.
base::string16 GetCompactMessageText() const;
// Returns the title of the link to show in the infobar in its compact state.
base::string16 GetCompactLinkText() const;
// Returns the secondary string to show in the infobar in the expanded state.
base::string16 GetDescriptionText() const;
// InfoBarDelegate: // InfoBarDelegate:
int GetIconId() const override; int GetIconId() const override;
...@@ -39,10 +48,15 @@ class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -39,10 +48,15 @@ class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
void InfoBarDismissed() override; void InfoBarDismissed() override;
bool LinkClicked(WindowOpenDisposition disposition) override;
// Returns true if we should show the permission request as a mini-infobar.
static bool ShouldShowMiniInfobar(ContentSettingsType type);
private: private:
GroupedPermissionInfoBarDelegate( GroupedPermissionInfoBarDelegate(
const base::WeakPtr<PermissionPromptAndroid>& permission_prompt); const base::WeakPtr<PermissionPromptAndroid>& permission_prompt,
InfoBarService* infobar_service);
// ConfirmInfoBarDelegate: // ConfirmInfoBarDelegate:
InfoBarIdentifier GetIdentifier() const override; InfoBarIdentifier GetIdentifier() const override;
...@@ -53,6 +67,7 @@ class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -53,6 +67,7 @@ class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override; bool EqualsDelegate(infobars::InfoBarDelegate* delegate) const override;
base::WeakPtr<PermissionPromptAndroid> permission_prompt_; base::WeakPtr<PermissionPromptAndroid> permission_prompt_;
InfoBarService* infobar_service_;
DISALLOW_COPY_AND_ASSIGN(GroupedPermissionInfoBarDelegate); DISALLOW_COPY_AND_ASSIGN(GroupedPermissionInfoBarDelegate);
}; };
......
...@@ -26,6 +26,16 @@ PermissionPromptAndroid::PermissionPromptAndroid( ...@@ -26,6 +26,16 @@ PermissionPromptAndroid::PermissionPromptAndroid(
weak_factory_(this) { weak_factory_(this) {
DCHECK(web_contents); DCHECK(web_contents);
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents_);
if (infobar_service &&
GroupedPermissionInfoBarDelegate::ShouldShowMiniInfobar(
GetContentSettingType(0u /* position */))) {
GroupedPermissionInfoBarDelegate::Create(weak_factory_.GetWeakPtr(),
infobar_service);
return;
}
if (PermissionRequestNotificationAndroid::ShouldShowAsNotification( if (PermissionRequestNotificationAndroid::ShouldShowAsNotification(
GetContentSettingType(0u /* position */))) { GetContentSettingType(0u /* position */))) {
permission_request_notification_ = permission_request_notification_ =
...@@ -72,7 +82,7 @@ size_t PermissionPromptAndroid::PermissionCount() const { ...@@ -72,7 +82,7 @@ size_t PermissionPromptAndroid::PermissionCount() const {
ContentSettingsType PermissionPromptAndroid::GetContentSettingType( ContentSettingsType PermissionPromptAndroid::GetContentSettingType(
size_t position) const { size_t position) const {
const std::vector<PermissionRequest*>& requests = delegate_->Requests(); const std::vector<PermissionRequest*>& requests = delegate_->Requests();
DCHECK_LT(position, requests.size()); CHECK_LT(position, requests.size());
return requests[position]->GetContentSettingsType(); return requests[position]->GetContentSettingsType();
} }
......
...@@ -688,8 +688,6 @@ jumbo_split_static_library("ui") { ...@@ -688,8 +688,6 @@ jumbo_split_static_library("ui") {
"android/infobars/near_oom_infobar.h", "android/infobars/near_oom_infobar.h",
"android/infobars/near_oom_reduction_infobar.cc", "android/infobars/near_oom_reduction_infobar.cc",
"android/infobars/near_oom_reduction_infobar.h", "android/infobars/near_oom_reduction_infobar.h",
"android/infobars/permission_infobar.cc",
"android/infobars/permission_infobar.h",
"android/infobars/previews_lite_page_infobar.cc", "android/infobars/previews_lite_page_infobar.cc",
"android/infobars/previews_lite_page_infobar.h", "android/infobars/previews_lite_page_infobar.h",
"android/infobars/reader_mode_infobar.cc", "android/infobars/reader_mode_infobar.cc",
......
...@@ -4,27 +4,70 @@ ...@@ -4,27 +4,70 @@
#include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h"
#include <vector>
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_array.h" #include "base/android/jni_array.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "chrome/android/chrome_jni_headers/PermissionInfoBar_jni.h"
#include "chrome/browser/android/resource_mapper.h" #include "chrome/browser/android/resource_mapper.h"
#include "chrome/browser/android/tab_android.h" #include "chrome/browser/android/tab_android.h"
#include "chrome/browser/permissions/grouped_permission_infobar_delegate_android.h" #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android.h"
#include "chrome/browser/ui/android/infobars/permission_infobar.h"
namespace {
using base::android::JavaRef;
using base::android::ScopedJavaLocalRef;
ScopedJavaLocalRef<jobject> CreateRenderInfoBarHelper(
JNIEnv* env,
int enumerated_icon_id,
const JavaRef<jobject>& tab,
const base::string16& compact_message_text,
const base::string16& compact_link_text,
const base::string16& message_text,
const base::string16& description_text,
const base::string16& ok_button_text,
const base::string16& cancel_button_text,
const std::vector<int>& content_settings) {
ScopedJavaLocalRef<jstring> compact_message_text_java =
base::android::ConvertUTF16ToJavaString(env, compact_message_text);
ScopedJavaLocalRef<jstring> compact_link_text_java =
base::android::ConvertUTF16ToJavaString(env, compact_link_text);
ScopedJavaLocalRef<jstring> message_text_java =
base::android::ConvertUTF16ToJavaString(env, message_text);
ScopedJavaLocalRef<jstring> description_text_java =
base::android::ConvertUTF16ToJavaString(env, description_text);
ScopedJavaLocalRef<jstring> ok_button_text_java =
base::android::ConvertUTF16ToJavaString(env, ok_button_text);
ScopedJavaLocalRef<jstring> cancel_button_text_java =
base::android::ConvertUTF16ToJavaString(env, cancel_button_text);
ScopedJavaLocalRef<jintArray> content_settings_types =
base::android::ToJavaIntArray(env, content_settings);
return Java_PermissionInfoBar_create(
env, tab, content_settings_types, enumerated_icon_id,
compact_message_text_java, compact_link_text_java, message_text_java,
description_text_java, ok_button_text_java, cancel_button_text_java);
}
} // namespace
GroupedPermissionInfoBar::GroupedPermissionInfoBar( GroupedPermissionInfoBar::GroupedPermissionInfoBar(
std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate)
: ConfirmInfoBar(std::move(delegate)) {} : ConfirmInfoBar(std::move(delegate)) {}
GroupedPermissionInfoBar::~GroupedPermissionInfoBar() { GroupedPermissionInfoBar::~GroupedPermissionInfoBar() {}
}
base::android::ScopedJavaLocalRef<jobject> base::android::ScopedJavaLocalRef<jobject>
GroupedPermissionInfoBar::CreateRenderInfoBar(JNIEnv* env) { GroupedPermissionInfoBar::CreateRenderInfoBar(JNIEnv* env) {
GroupedPermissionInfoBarDelegate* delegate = GetDelegate(); GroupedPermissionInfoBarDelegate* delegate = GetDelegate();
base::string16 compact_message_text = delegate->GetCompactMessageText();
base::string16 compact_link_text = delegate->GetCompactLinkText();
base::string16 message_text = delegate->GetMessageText(); base::string16 message_text = delegate->GetMessageText();
base::string16 link_text = delegate->GetLinkText(); base::string16 description_text = delegate->GetDescriptionText();
base::string16 ok_button_text = GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK); base::string16 ok_button_text = GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK);
base::string16 cancel_button_text = base::string16 cancel_button_text =
GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL); GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL);
...@@ -37,9 +80,10 @@ GroupedPermissionInfoBar::CreateRenderInfoBar(JNIEnv* env) { ...@@ -37,9 +80,10 @@ GroupedPermissionInfoBar::CreateRenderInfoBar(JNIEnv* env) {
content_settings_types.push_back(delegate->GetContentSettingType(i)); content_settings_types.push_back(delegate->GetContentSettingType(i));
} }
return PermissionInfoBar::CreateRenderInfoBarHelper( return CreateRenderInfoBarHelper(
env, permission_icon, GetTab()->GetJavaObject(), nullptr, message_text, env, permission_icon, GetTab()->GetJavaObject(), compact_message_text,
link_text, ok_button_text, cancel_button_text, content_settings_types); compact_link_text, message_text, description_text, ok_button_text,
cancel_button_text, content_settings_types);
} }
GroupedPermissionInfoBarDelegate* GroupedPermissionInfoBar::GetDelegate() { GroupedPermissionInfoBarDelegate* GroupedPermissionInfoBar::GetDelegate() {
......
...@@ -5,15 +5,12 @@ ...@@ -5,15 +5,12 @@
#ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_GROUPED_PERMISSION_INFOBAR_H_ #ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_GROUPED_PERMISSION_INFOBAR_H_
#define CHROME_BROWSER_UI_ANDROID_INFOBARS_GROUPED_PERMISSION_INFOBAR_H_ #define CHROME_BROWSER_UI_ANDROID_INFOBARS_GROUPED_PERMISSION_INFOBAR_H_
#include <jni.h>
#include "base/android/scoped_java_ref.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h" #include "chrome/browser/ui/android/infobars/confirm_infobar.h"
class GroupedPermissionInfoBarDelegate; class GroupedPermissionInfoBarDelegate;
// TODO(timloh): This is incorrectly named as we've removed grouped permissions, // TODO(andypaicu): rename this to PermissionInfoBar, grouped permissions are
// rename it to PermissionInfoBar once crbug.com/606138 is done. // not a thing anymore.
class GroupedPermissionInfoBar : public ConfirmInfoBar { class GroupedPermissionInfoBar : public ConfirmInfoBar {
public: public:
explicit GroupedPermissionInfoBar( explicit GroupedPermissionInfoBar(
......
// Copyright 2016 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/permission_infobar.h"
#include <memory>
#include <utility>
#include <vector>
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "chrome/android/chrome_jni_headers/PermissionInfoBar_jni.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/image/image.h"
using base::android::JavaRef;
using base::android::ScopedJavaLocalRef;
ScopedJavaLocalRef<jobject> PermissionInfoBar::CreateRenderInfoBarHelper(
JNIEnv* env,
int enumerated_icon_id,
const JavaRef<jobject>& tab,
const ScopedJavaLocalRef<jobject>& icon_bitmap,
const base::string16& message_text,
const base::string16& link_text,
const base::string16& ok_button_text,
const base::string16& cancel_button_text,
std::vector<int>& content_settings) {
ScopedJavaLocalRef<jstring> message_text_java =
base::android::ConvertUTF16ToJavaString(env, message_text);
ScopedJavaLocalRef<jstring> link_text_java =
base::android::ConvertUTF16ToJavaString(env, link_text);
ScopedJavaLocalRef<jstring> ok_button_text_java =
base::android::ConvertUTF16ToJavaString(env, ok_button_text);
ScopedJavaLocalRef<jstring> cancel_button_text_java =
base::android::ConvertUTF16ToJavaString(env, cancel_button_text);
ScopedJavaLocalRef<jintArray> content_settings_types =
base::android::ToJavaIntArray(env, content_settings);
return Java_PermissionInfoBar_create(
env, tab, enumerated_icon_id, icon_bitmap, message_text_java,
link_text_java, ok_button_text_java, cancel_button_text_java,
content_settings_types);
}
// Copyright 2016 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_PERMISSION_INFOBAR_H_
#define CHROME_BROWSER_UI_ANDROID_INFOBARS_PERMISSION_INFOBAR_H_
#include <vector>
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
// TODO(timloh): Rename GroupedPermissionInfoBar to PermissionInfoBar and move
// these functions into it.
class PermissionInfoBar {
public:
static base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBarHelper(
JNIEnv* env,
int enumerated_icon_id,
const base::android::JavaRef<jobject>& tab,
const base::android::ScopedJavaLocalRef<jobject>& icon_bitmap,
const base::string16& message_text,
const base::string16& link_text,
const base::string16& ok_button_text,
const base::string16& cancel_button_text,
std::vector<int>& content_settings);
private:
DISALLOW_COPY_AND_ASSIGN(PermissionInfoBar);
};
#endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_PERMISSION_INFOBAR_H_
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