| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/permission_infobar_delegate.h" | 5 #include "chrome/browser/permissions/permission_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" | 10 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" | 12 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" |
| 13 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro
id.h" | 13 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro
id.h" |
| 14 #include "chrome/browser/notifications/notification_permission_infobar_delegate.
h" | 14 #include "chrome/browser/notifications/notification_permission_infobar_delegate.
h" |
| 15 #include "chrome/browser/permissions/permission_request.h" | 15 #include "chrome/browser/permissions/permission_request.h" |
| 16 #include "chrome/browser/permissions/permission_uma_util.h" | 16 #include "chrome/browser/permissions/permission_uma_util.h" |
| 17 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 18 #include "components/infobars/core/infobar.h" | 18 #include "components/infobars/core/infobar.h" |
| 19 #include "components/url_formatter/elide_url.h" | 19 #include "components/url_formatter/elide_url.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 infobars::InfoBar* PermissionInfoBarDelegate::Create( | 24 infobars::InfoBar* PermissionInfoBarDelegate::Create( |
| 25 InfoBarService* infobar_service, | 25 InfoBarService* infobar_service, |
| 26 content::PermissionType type, | 26 ContentSettingsType type, |
| 27 const GURL& requesting_frame, | 27 const GURL& requesting_frame, |
| 28 bool user_gesture, | 28 bool user_gesture, |
| 29 Profile* profile, | 29 Profile* profile, |
| 30 const PermissionSetCallback& callback) { | 30 const PermissionSetCallback& callback) { |
| 31 std::unique_ptr<PermissionInfoBarDelegate> delegate = | 31 std::unique_ptr<PermissionInfoBarDelegate> delegate = |
| 32 PermissionInfoBarDelegate::CreateDelegate( | 32 PermissionInfoBarDelegate::CreateDelegate( |
| 33 type, requesting_frame, user_gesture, profile, callback); | 33 type, requesting_frame, user_gesture, profile, callback); |
| 34 | 34 |
| 35 if (!delegate) | 35 if (!delegate) |
| 36 return nullptr; | 36 return nullptr; |
| 37 | 37 |
| 38 return infobar_service->AddInfoBar( | 38 return infobar_service->AddInfoBar( |
| 39 CreatePermissionInfoBar(std::move(delegate))); | 39 CreatePermissionInfoBar(std::move(delegate))); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // static | 42 // static |
| 43 std::unique_ptr<PermissionInfoBarDelegate> | 43 std::unique_ptr<PermissionInfoBarDelegate> |
| 44 PermissionInfoBarDelegate::CreateDelegate( | 44 PermissionInfoBarDelegate::CreateDelegate( |
| 45 content::PermissionType type, | 45 ContentSettingsType type, |
| 46 const GURL& requesting_frame, | 46 const GURL& requesting_frame, |
| 47 bool user_gesture, | 47 bool user_gesture, |
| 48 Profile* profile, | 48 Profile* profile, |
| 49 const PermissionSetCallback& callback) { | 49 const PermissionSetCallback& callback) { |
| 50 switch (type) { | 50 switch (type) { |
| 51 case content::PermissionType::GEOLOCATION: | 51 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 52 return std::unique_ptr<PermissionInfoBarDelegate>( | 52 return std::unique_ptr<PermissionInfoBarDelegate>( |
| 53 new GeolocationInfoBarDelegateAndroid( | 53 new GeolocationInfoBarDelegateAndroid( |
| 54 requesting_frame, user_gesture, profile, callback)); | 54 requesting_frame, user_gesture, profile, callback)); |
| 55 case content::PermissionType::NOTIFICATIONS: | 55 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 56 case content::PermissionType::PUSH_MESSAGING: | 56 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
| 57 return std::unique_ptr<PermissionInfoBarDelegate>( | 57 return std::unique_ptr<PermissionInfoBarDelegate>( |
| 58 new NotificationPermissionInfoBarDelegate( | 58 new NotificationPermissionInfoBarDelegate( |
| 59 type, requesting_frame, user_gesture, profile, callback)); | 59 type, requesting_frame, user_gesture, profile, callback)); |
| 60 case content::PermissionType::MIDI_SYSEX: | 60 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 61 return std::unique_ptr<PermissionInfoBarDelegate>( | 61 return std::unique_ptr<PermissionInfoBarDelegate>( |
| 62 new MidiPermissionInfoBarDelegateAndroid( | 62 new MidiPermissionInfoBarDelegateAndroid( |
| 63 requesting_frame, user_gesture, profile, callback)); | 63 requesting_frame, user_gesture, profile, callback)); |
| 64 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 64 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| 65 return std::unique_ptr<PermissionInfoBarDelegate>( | 65 return std::unique_ptr<PermissionInfoBarDelegate>( |
| 66 new ProtectedMediaIdentifierInfoBarDelegateAndroid( | 66 new ProtectedMediaIdentifierInfoBarDelegateAndroid( |
| 67 requesting_frame, user_gesture, profile, callback)); | 67 requesting_frame, user_gesture, profile, callback)); |
| 68 default: | 68 default: |
| 69 NOTREACHED(); | 69 NOTREACHED(); |
| 70 return nullptr; | 70 return nullptr; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 PermissionInfoBarDelegate::~PermissionInfoBarDelegate() { | 74 PermissionInfoBarDelegate::~PermissionInfoBarDelegate() { |
| 75 if (!action_taken_) { | 75 if (!action_taken_) { |
| 76 PermissionUmaUtil::PermissionIgnored( | 76 PermissionUmaUtil::PermissionIgnored( |
| 77 permission_type_, | 77 content_settings_type_, |
| 78 user_gesture_ ? PermissionRequestGestureType::GESTURE | 78 user_gesture_ ? PermissionRequestGestureType::GESTURE |
| 79 : PermissionRequestGestureType::NO_GESTURE, | 79 : PermissionRequestGestureType::NO_GESTURE, |
| 80 requesting_origin_, profile_); | 80 requesting_origin_, profile_); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 std::vector<int> PermissionInfoBarDelegate::content_settings_types() const { | 84 std::vector<int> PermissionInfoBarDelegate::content_settings_types() const { |
| 85 return std::vector<int>{content_settings_type_}; | 85 return std::vector<int>{content_settings_type_}; |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool PermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { | 88 bool PermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { |
| 89 return (permission_type_ == content::PermissionType::GEOLOCATION || | 89 return (content_settings_type_ == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
| 90 permission_type_ == content::PermissionType::AUDIO_CAPTURE || | 90 content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 91 permission_type_ == content::PermissionType::VIDEO_CAPTURE) && | 91 content_settings_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) && |
| 92 PermissionUtil::ShouldShowPersistenceToggle(); | 92 PermissionUtil::ShouldShowPersistenceToggle(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool PermissionInfoBarDelegate::Accept() { | 95 bool PermissionInfoBarDelegate::Accept() { |
| 96 bool update_content_setting = true; | 96 bool update_content_setting = true; |
| 97 if (ShouldShowPersistenceToggle()) { | 97 if (ShouldShowPersistenceToggle()) { |
| 98 update_content_setting = persist_; | 98 update_content_setting = persist_; |
| 99 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( | 99 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( |
| 100 permission_type_, persist_); | 100 content_settings_type_, persist_); |
| 101 } | 101 } |
| 102 | 102 |
| 103 SetPermission(update_content_setting, GRANTED); | 103 SetPermission(update_content_setting, GRANTED); |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool PermissionInfoBarDelegate::Cancel() { | 107 bool PermissionInfoBarDelegate::Cancel() { |
| 108 bool update_content_setting = true; | 108 bool update_content_setting = true; |
| 109 if (ShouldShowPersistenceToggle()) { | 109 if (ShouldShowPersistenceToggle()) { |
| 110 update_content_setting = persist_; | 110 update_content_setting = persist_; |
| 111 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( | 111 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( |
| 112 permission_type_, persist_); | 112 content_settings_type_, persist_); |
| 113 } | 113 } |
| 114 | 114 |
| 115 SetPermission(update_content_setting, DENIED); | 115 SetPermission(update_content_setting, DENIED); |
| 116 return true; | 116 return true; |
| 117 } | 117 } |
| 118 | 118 |
| 119 void PermissionInfoBarDelegate::InfoBarDismissed() { | 119 void PermissionInfoBarDelegate::InfoBarDismissed() { |
| 120 SetPermission(false, DISMISSED); | 120 SetPermission(false, DISMISSED); |
| 121 } | 121 } |
| 122 | 122 |
| 123 base::string16 PermissionInfoBarDelegate::GetButtonLabel( | 123 base::string16 PermissionInfoBarDelegate::GetButtonLabel( |
| 124 InfoBarButton button) const { | 124 InfoBarButton button) const { |
| 125 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW | 125 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW |
| 126 : IDS_PERMISSION_DENY); | 126 : IDS_PERMISSION_DENY); |
| 127 } | 127 } |
| 128 | 128 |
| 129 base::string16 PermissionInfoBarDelegate::GetMessageText() const { | 129 base::string16 PermissionInfoBarDelegate::GetMessageText() const { |
| 130 return l10n_util::GetStringFUTF16( | 130 return l10n_util::GetStringFUTF16( |
| 131 GetMessageResourceId(), | 131 GetMessageResourceId(), |
| 132 url_formatter::FormatUrlForSecurityDisplay( | 132 url_formatter::FormatUrlForSecurityDisplay( |
| 133 requesting_origin_, | 133 requesting_origin_, |
| 134 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 134 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 PermissionInfoBarDelegate::PermissionInfoBarDelegate( | 137 PermissionInfoBarDelegate::PermissionInfoBarDelegate( |
| 138 const GURL& requesting_origin, | 138 const GURL& requesting_origin, |
| 139 content::PermissionType permission_type, | |
| 140 ContentSettingsType content_settings_type, | 139 ContentSettingsType content_settings_type, |
| 141 bool user_gesture, | 140 bool user_gesture, |
| 142 Profile* profile, | 141 Profile* profile, |
| 143 const PermissionSetCallback& callback) | 142 const PermissionSetCallback& callback) |
| 144 : requesting_origin_(requesting_origin), | 143 : requesting_origin_(requesting_origin), |
| 145 permission_type_(permission_type), | |
| 146 content_settings_type_(content_settings_type), | 144 content_settings_type_(content_settings_type), |
| 147 profile_(profile), | 145 profile_(profile), |
| 148 callback_(callback), | 146 callback_(callback), |
| 149 action_taken_(false), | 147 action_taken_(false), |
| 150 user_gesture_(user_gesture), | 148 user_gesture_(user_gesture), |
| 151 persist_(true) {} | 149 persist_(true) {} |
| 152 | 150 |
| 153 infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType() | 151 infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType() |
| 154 const { | 152 const { |
| 155 return PAGE_ACTION_TYPE; | 153 return PAGE_ACTION_TYPE; |
| 156 } | 154 } |
| 157 | 155 |
| 158 PermissionInfoBarDelegate* | 156 PermissionInfoBarDelegate* |
| 159 PermissionInfoBarDelegate::AsPermissionInfoBarDelegate() { | 157 PermissionInfoBarDelegate::AsPermissionInfoBarDelegate() { |
| 160 return this; | 158 return this; |
| 161 } | 159 } |
| 162 | 160 |
| 163 void PermissionInfoBarDelegate::SetPermission(bool update_content_setting, | 161 void PermissionInfoBarDelegate::SetPermission(bool update_content_setting, |
| 164 PermissionAction decision) { | 162 PermissionAction decision) { |
| 165 action_taken_ = true; | 163 action_taken_ = true; |
| 166 callback_.Run(update_content_setting, decision); | 164 callback_.Run(update_content_setting, decision); |
| 167 } | 165 } |
| OLD | NEW |