| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/permissions/grouped_permission_infobar_delegate.h" | 5 #include "chrome/browser/permissions/grouped_permission_infobar_delegate.h" |
| 6 #include "chrome/browser/permissions/permission_request.h" |
| 6 #include "chrome/browser/permissions/permission_util.h" | 7 #include "chrome/browser/permissions/permission_util.h" |
| 7 #include "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 8 #include "chrome/grit/theme_resources.h" | 9 #include "chrome/grit/theme_resources.h" |
| 9 #include "components/url_formatter/elide_url.h" | 10 #include "components/url_formatter/elide_url.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 11 | 12 |
| 12 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( | 13 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( |
| 13 const GURL& requesting_origin, | 14 const GURL& requesting_origin, |
| 14 const std::vector<ContentSettingsType>& types) | 15 const std::vector<PermissionRequest*>& requests) |
| 15 : requesting_origin_(requesting_origin), | 16 : requesting_origin_(requesting_origin), |
| 16 types_(types), | 17 requests_(requests), |
| 17 accept_states_(types_.size(), true), | 18 accept_states_(requests_.size(), true), |
| 18 persist_(true) {} | 19 persist_(true) {} |
| 19 | 20 |
| 20 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} | 21 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} |
| 21 | 22 |
| 22 infobars::InfoBarDelegate::Type | 23 infobars::InfoBarDelegate::Type |
| 23 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { | 24 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { |
| 24 return PAGE_ACTION_TYPE; | 25 return PAGE_ACTION_TYPE; |
| 25 } | 26 } |
| 26 | 27 |
| 27 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { | 28 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { | 49 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { |
| 49 return l10n_util::GetStringFUTF16( | 50 return l10n_util::GetStringFUTF16( |
| 50 IDS_PERMISSIONS_BUBBLE_PROMPT, | 51 IDS_PERMISSIONS_BUBBLE_PROMPT, |
| 51 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); | 52 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); |
| 52 } | 53 } |
| 53 | 54 |
| 54 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const { | 55 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const { |
| 55 return types_.size(); | 56 return requests_.size(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( | 59 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( |
| 59 int index) const { | 60 int index) const { |
| 60 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); | 61 DCHECK(index >= 0 && index < static_cast<int>(requests_.size())); |
| 61 return types_[index]; | 62 return requests_[index]->GetContentSettingsType(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const { | 65 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const { |
| 65 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); | 66 DCHECK(index >= 0 && index < static_cast<int>(requests_.size())); |
| 66 ContentSettingsType type = types_[index]; | 67 return requests_[index]->GetIconId(); |
| 67 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | |
| 68 return IDR_INFOBAR_MEDIA_STREAM_MIC; | |
| 69 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | |
| 70 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; | |
| 71 } | |
| 72 return IDR_INFOBAR_WARNING; | |
| 73 } | 68 } |
| 74 | 69 |
| 75 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( | 70 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( |
| 76 int index) const { | 71 int index) const { |
| 77 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); | 72 DCHECK(index >= 0 && index < static_cast<int>(requests_.size())); |
| 78 ContentSettingsType type = types_[index]; | 73 return requests_[index]->GetMessageTextFragment(); |
| 79 int message_id; | |
| 80 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | |
| 81 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; | |
| 82 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | |
| 83 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT; | |
| 84 } else { | |
| 85 NOTREACHED(); | |
| 86 return base::string16(); | |
| 87 } | |
| 88 return l10n_util::GetStringUTF16(message_id); | |
| 89 } | 74 } |
| 90 | 75 |
| 91 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position, | 76 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position, |
| 92 bool new_value) { | 77 bool new_value) { |
| 93 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); | 78 DCHECK(position >= 0 && position < static_cast<int>(requests_.size())); |
| 94 accept_states_[position] = new_value; | 79 accept_states_[position] = new_value; |
| 95 } | 80 } |
| 96 | 81 |
| 97 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) { | 82 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) { |
| 98 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); | 83 DCHECK(position >= 0 && position < static_cast<int>(requests_.size())); |
| 99 return accept_states_[position]; | 84 return accept_states_[position]; |
| 100 } | 85 } |
| OLD | NEW |