Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1529)

Unified Diff: chrome/browser/permissions/grouped_permission_infobar_delegate_android.cc

Issue 2319443002: Add InfoBarIdentifier to GroupedPermissionInfoBarDelegate (Closed)
Patch Set: address review comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/permissions/grouped_permission_infobar_delegate_android.cc
diff --git a/chrome/browser/permissions/grouped_permission_infobar_delegate.cc b/chrome/browser/permissions/grouped_permission_infobar_delegate_android.cc
similarity index 60%
rename from chrome/browser/permissions/grouped_permission_infobar_delegate.cc
rename to chrome/browser/permissions/grouped_permission_infobar_delegate_android.cc
index 6ea8084bb31673e93eb5b64aec9129488334cd86..4ffad0ac368909a3e82e517b6fb36611859dda57 100644
--- a/chrome/browser/permissions/grouped_permission_infobar_delegate.cc
+++ b/chrome/browser/permissions/grouped_permission_infobar_delegate_android.cc
@@ -2,67 +2,41 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/permissions/grouped_permission_infobar_delegate.h"
+#include "chrome/browser/permissions/grouped_permission_infobar_delegate_android.h"
+
+#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/permissions/permission_util.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
+#include "components/infobars/core/infobar.h"
#include "components/url_formatter/elide_url.h"
#include "ui/base/l10n/l10n_util.h"
-GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate(
- const GURL& requesting_origin,
- const std::vector<ContentSettingsType>& types)
- : requesting_origin_(requesting_origin),
- types_(types),
- accept_states_(types_.size(), true),
- persist_(true) {}
-
GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {}
-infobars::InfoBarDelegate::Type
-GroupedPermissionInfoBarDelegate::GetInfoBarType() const {
- return PAGE_ACTION_TYPE;
+// static
+infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create(
+ InfoBarService* infobar_service,
+ const GURL& requesting_origin,
+ const std::vector<ContentSettingsType>& types) {
+ return infobar_service->AddInfoBar(CreateGroupedPermissionInfoBar(
+ std::unique_ptr<GroupedPermissionInfoBarDelegate>(
+ new GroupedPermissionInfoBarDelegate(requesting_origin, types))));
}
bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const {
return PermissionUtil::ShouldShowPersistenceToggle();
}
-int GroupedPermissionInfoBarDelegate::GetButtons() const {
- if (GetPermissionCount() >= 2)
- return ConfirmInfoBarDelegate::InfoBarButton::BUTTON_OK;
- else
- return ConfirmInfoBarDelegate::GetButtons();
-}
-
-base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel(
- InfoBarButton button) const {
- if (GetPermissionCount() >= 2) {
- return ConfirmInfoBarDelegate::GetButtonLabel(button);
- } else {
- return l10n_util::GetStringUTF16(
- (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
- }
-}
-
-base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
- return l10n_util::GetStringFUTF16(
- IDS_PERMISSIONS_BUBBLE_PROMPT,
- url_formatter::FormatUrlForSecurityDisplay(requesting_origin_));
-}
-
-int GroupedPermissionInfoBarDelegate::GetPermissionCount() const {
- return types_.size();
-}
-
ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType(
- int index) const {
- DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
+ size_t index) const {
+ DCHECK_LT(index, types_.size());
return types_[index];
}
-int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const {
- DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
+int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(
+ size_t index) const {
+ DCHECK_LT(index, types_.size());
ContentSettingsType type = types_[index];
if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
Peter Kasting 2016/09/21 18:44:39 Nit: {} not necessary
lshang 2016/09/22 02:11:30 Done.
return IDR_INFOBAR_MEDIA_STREAM_MIC;
@@ -72,29 +46,66 @@ int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const {
return IDR_INFOBAR_WARNING;
}
+base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetStringFUTF16(
+ IDS_PERMISSIONS_BUBBLE_PROMPT,
+ url_formatter::FormatUrlForSecurityDisplay(requesting_origin_));
+}
+
base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment(
- int index) const {
- DCHECK(index >= 0 && index < static_cast<int>(types_.size()));
+ size_t index) const {
+ DCHECK_LT(index, types_.size());
ContentSettingsType type = types_[index];
- int message_id;
- if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
- message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT;
- } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
- message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT;
- } else {
- NOTREACHED();
- return base::string16();
- }
- return l10n_util::GetStringUTF16(message_id);
+
+ const bool is_mic = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
+ DCHECK(is_mic || (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
+ return l10n_util::GetStringUTF16(
+ is_mic ? IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT
+ : IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT);
}
-void GroupedPermissionInfoBarDelegate::ToggleAccept(int position,
+void GroupedPermissionInfoBarDelegate::ToggleAccept(size_t position,
bool new_value) {
- DCHECK(position >= 0 && position < static_cast<int>(types_.size()));
+ DCHECK_LT(position, types_.size());
accept_states_[position] = new_value;
}
-bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) {
- DCHECK(position >= 0 && position < static_cast<int>(types_.size()));
+bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) {
+ DCHECK_LT(position, types_.size());
return accept_states_[position];
}
+
+GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate(
+ const GURL& requesting_origin,
+ const std::vector<ContentSettingsType>& types)
+ : requesting_origin_(requesting_origin),
+ types_(types),
+ accept_states_(types_.size(), true),
+ persist_(true) {}
+
+infobars::InfoBarDelegate::InfoBarIdentifier
+GroupedPermissionInfoBarDelegate::GetIdentifier() const {
+ return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID;
+}
+
+infobars::InfoBarDelegate::Type
+GroupedPermissionInfoBarDelegate::GetInfoBarType() const {
+ return PAGE_ACTION_TYPE;
+}
+
+int GroupedPermissionInfoBarDelegate::GetButtons() const {
+ if (GetPermissionCount() > 1)
+ return ConfirmInfoBarDelegate::InfoBarButton::BUTTON_OK;
+
+ return ConfirmInfoBarDelegate::GetButtons();
Peter Kasting 2016/09/21 18:44:39 Nit: I still think it's strange for these two meth
lshang 2016/09/22 02:11:30 Done.
+}
+
+base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ if (GetPermissionCount() > 1) {
+ return ConfirmInfoBarDelegate::GetButtonLabel(button);
+ } else {
Peter Kasting 2016/09/21 18:44:39 Nit: No else after return
lshang 2016/09/22 02:11:30 Done.
+ return l10n_util::GetStringUTF16(
+ (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698