Commit 67e6efd2 authored by dominickn's avatar dominickn Committed by Commit bot

Remove PermissionInfoBarDelegate from desktop builds.

This CL compiles PermissionInfoBarDelegate only on Android. It also
refactors the delegate subclasses to move their Create methods to
PermissionInfoBarDelegate, simplifying the PermissionsQueueController.

This refactor simplifies the work necessary to allow infobars to be
switched out for modal permission prompt dialogs by centralising the
delegate creation logic.

BUG=658125

Review-Url: https://codereview.chromium.org/2443463003
Cr-Commit-Position: refs/heads/master@{#427202}
parent 64a8a9fa
...@@ -754,8 +754,6 @@ split_static_library("browser") { ...@@ -754,8 +754,6 @@ split_static_library("browser") {
"permissions/permission_context_base.h", "permissions/permission_context_base.h",
"permissions/permission_decision_auto_blocker.cc", "permissions/permission_decision_auto_blocker.cc",
"permissions/permission_decision_auto_blocker.h", "permissions/permission_decision_auto_blocker.h",
"permissions/permission_infobar_delegate.cc",
"permissions/permission_infobar_delegate.h",
"permissions/permission_manager.cc", "permissions/permission_manager.cc",
"permissions/permission_manager.h", "permissions/permission_manager.h",
"permissions/permission_manager_factory.cc", "permissions/permission_manager_factory.cc",
...@@ -3305,6 +3303,8 @@ split_static_library("browser") { ...@@ -3305,6 +3303,8 @@ split_static_library("browser") {
"password_manager/update_password_infobar_delegate_android.h", "password_manager/update_password_infobar_delegate_android.h",
"permissions/grouped_permission_infobar_delegate_android.cc", "permissions/grouped_permission_infobar_delegate_android.cc",
"permissions/grouped_permission_infobar_delegate_android.h", "permissions/grouped_permission_infobar_delegate_android.h",
"permissions/permission_infobar_delegate.cc",
"permissions/permission_infobar_delegate.h",
"permissions/permission_queue_controller.cc", "permissions/permission_queue_controller.cc",
"permissions/permission_queue_controller.h", "permissions/permission_queue_controller.h",
"permissions/permission_update_infobar_delegate_android.cc", "permissions/permission_update_infobar_delegate_android.cc",
......
...@@ -5,22 +5,7 @@ ...@@ -5,22 +5,7 @@
#include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.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/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
// static
infobars::InfoBar* GeolocationInfoBarDelegateAndroid::Create(
InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback) {
return infobar_service->AddInfoBar(
CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
new GeolocationInfoBarDelegateAndroid(requesting_frame, user_gesture,
profile, callback))));
}
GeolocationInfoBarDelegateAndroid::GeolocationInfoBarDelegateAndroid( GeolocationInfoBarDelegateAndroid::GeolocationInfoBarDelegateAndroid(
const GURL& requesting_frame, const GURL& requesting_frame,
......
...@@ -10,26 +10,17 @@ ...@@ -10,26 +10,17 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/permissions/permission_infobar_delegate.h" #include "chrome/browser/permissions/permission_infobar_delegate.h"
class InfoBarService;
// GeolocationInfoBarDelegateAndroids are created by the // GeolocationInfoBarDelegateAndroids are created by the
// PermissionQueueController to control the display // PermissionQueueController to control the display
// and handling of geolocation permission infobars to the user. // and handling of geolocation permission infobars to the user.
class GeolocationInfoBarDelegateAndroid : public PermissionInfoBarDelegate { class GeolocationInfoBarDelegateAndroid : public PermissionInfoBarDelegate {
public: public:
// Creates a geolocation infobar and delegate and adds the infobar to
// |infobar_service|. Returns the infobar if it was successfully added.
static infobars::InfoBar* Create(InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback);
private:
GeolocationInfoBarDelegateAndroid(const GURL& requesting_frame, GeolocationInfoBarDelegateAndroid(const GURL& requesting_frame,
bool user_gesture, bool user_gesture,
Profile* profile, Profile* profile,
const PermissionSetCallback& callback); const PermissionSetCallback& callback);
private:
~GeolocationInfoBarDelegateAndroid() override; ~GeolocationInfoBarDelegateAndroid() override;
// PermissionInfoBarDelegate: // PermissionInfoBarDelegate:
......
...@@ -5,22 +5,7 @@ ...@@ -5,22 +5,7 @@
#include "chrome/browser/media/midi_permission_infobar_delegate_android.h" #include "chrome/browser/media/midi_permission_infobar_delegate_android.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/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
// static
infobars::InfoBar* MidiPermissionInfoBarDelegateAndroid::Create(
InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback) {
return infobar_service->AddInfoBar(
CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
new MidiPermissionInfoBarDelegateAndroid(
requesting_frame, user_gesture, profile, callback))));
}
MidiPermissionInfoBarDelegateAndroid::MidiPermissionInfoBarDelegateAndroid( MidiPermissionInfoBarDelegateAndroid::MidiPermissionInfoBarDelegateAndroid(
const GURL& requesting_frame, const GURL& requesting_frame,
......
...@@ -10,27 +10,17 @@ ...@@ -10,27 +10,17 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/permissions/permission_infobar_delegate.h" #include "chrome/browser/permissions/permission_infobar_delegate.h"
class GURL;
class InfoBarService;
// MidiPermissionInfoBarDelegateAndroids are created by the // MidiPermissionInfoBarDelegateAndroids are created by the
// MidiPermissionContext to control the display and handling of MIDI permission // MidiPermissionContext to control the display and handling of MIDI permission
// infobars to the user. // infobars to the user.
class MidiPermissionInfoBarDelegateAndroid : public PermissionInfoBarDelegate { class MidiPermissionInfoBarDelegateAndroid : public PermissionInfoBarDelegate {
public: public:
// Creates a MIDI permission infobar and delegate and adds the infobar to
// |infobar_service|. Returns the infobar if it was successfully added.
static infobars::InfoBar* Create(InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback);
private:
MidiPermissionInfoBarDelegateAndroid(const GURL& requesting_frame, MidiPermissionInfoBarDelegateAndroid(const GURL& requesting_frame,
bool user_gesture, bool user_gesture,
Profile* profile, Profile* profile,
const PermissionSetCallback& callback); const PermissionSetCallback& callback);
private:
~MidiPermissionInfoBarDelegateAndroid() override; ~MidiPermissionInfoBarDelegateAndroid() override;
// ConfirmInfoBarDelegate: // ConfirmInfoBarDelegate:
......
...@@ -5,26 +5,11 @@ ...@@ -5,26 +5,11 @@
#include "chrome/browser/media/protected_media_identifier_infobar_delegate_android.h" #include "chrome/browser/media/protected_media_identifier_infobar_delegate_android.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/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
// static
infobars::InfoBar* ProtectedMediaIdentifierInfoBarDelegateAndroid::Create(
InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback) {
return infobar_service->AddInfoBar(
CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
new ProtectedMediaIdentifierInfoBarDelegateAndroid(
requesting_frame, user_gesture, profile, callback))));
}
ProtectedMediaIdentifierInfoBarDelegateAndroid:: ProtectedMediaIdentifierInfoBarDelegateAndroid::
ProtectedMediaIdentifierInfoBarDelegateAndroid( ProtectedMediaIdentifierInfoBarDelegateAndroid(
const GURL& requesting_frame, const GURL& requesting_frame,
......
...@@ -10,29 +10,18 @@ ...@@ -10,29 +10,18 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/permissions/permission_infobar_delegate.h" #include "chrome/browser/permissions/permission_infobar_delegate.h"
class InfoBarService;
class ProtectedMediaIdentifierInfoBarDelegateAndroid class ProtectedMediaIdentifierInfoBarDelegateAndroid
: public PermissionInfoBarDelegate { : public PermissionInfoBarDelegate {
public: public:
// Creates a protected media identifier infobar and delegate and adds the
// infobar to |infobar_service|. Returns the infobar if it was successfully
// added.
static infobars::InfoBar* Create(InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback);
protected:
ProtectedMediaIdentifierInfoBarDelegateAndroid( ProtectedMediaIdentifierInfoBarDelegateAndroid(
const GURL& requesting_frame, const GURL& requesting_frame,
bool user_gesture, bool user_gesture,
Profile* profile, Profile* profile,
const PermissionSetCallback& callback); const PermissionSetCallback& callback);
~ProtectedMediaIdentifierInfoBarDelegateAndroid() override;
private: private:
~ProtectedMediaIdentifierInfoBarDelegateAndroid() override;
// PermissionInfoBarDelegate: // PermissionInfoBarDelegate:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
int GetIconId() const override; int GetIconId() const override;
......
...@@ -5,22 +5,7 @@ ...@@ -5,22 +5,7 @@
#include "chrome/browser/notifications/notification_permission_infobar_delegate.h" #include "chrome/browser/notifications/notification_permission_infobar_delegate.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/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
// static
infobars::InfoBar* NotificationPermissionInfoBarDelegate::Create(
InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback) {
return infobar_service->AddInfoBar(
CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
new NotificationPermissionInfoBarDelegate(
requesting_frame, user_gesture, profile, callback))));
}
NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate( NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate(
const GURL& requesting_frame, const GURL& requesting_frame,
......
...@@ -10,24 +10,14 @@ ...@@ -10,24 +10,14 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/permissions/permission_infobar_delegate.h" #include "chrome/browser/permissions/permission_infobar_delegate.h"
class InfoBarService;
class NotificationPermissionInfoBarDelegate : public PermissionInfoBarDelegate { class NotificationPermissionInfoBarDelegate : public PermissionInfoBarDelegate {
public: public:
// Creates a Notification permission infobar and delegate and adds the
// infobar to |infobar_service|. Returns the infobar if it was successfully
// added.
static infobars::InfoBar* Create(InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback);
private:
NotificationPermissionInfoBarDelegate(const GURL& requesting_frame, NotificationPermissionInfoBarDelegate(const GURL& requesting_frame,
bool user_gesture, bool user_gesture,
Profile* profile, Profile* profile,
const PermissionSetCallback& callback); const PermissionSetCallback& callback);
private:
~NotificationPermissionInfoBarDelegate() override; ~NotificationPermissionInfoBarDelegate() override;
// PermissionInfoBarDelegate: // PermissionInfoBarDelegate:
......
...@@ -4,13 +4,57 @@ ...@@ -4,13 +4,57 @@
#include "chrome/browser/permissions/permission_infobar_delegate.h" #include "chrome/browser/permissions/permission_infobar_delegate.h"
#include "chrome/browser/permissions/permission_decision_auto_blocker.h" #include "build/build_config.h"
#include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/media/midi_permission_infobar_delegate_android.h"
#include "chrome/browser/media/protected_media_identifier_infobar_delegate_android.h"
#include "chrome/browser/notifications/notification_permission_infobar_delegate.h"
#include "chrome/browser/permissions/permission_request.h" #include "chrome/browser/permissions/permission_request.h"
#include "chrome/browser/permissions/permission_uma_util.h" #include "chrome/browser/permissions/permission_uma_util.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
#include "components/url_formatter/elide_url.h" #include "components/url_formatter/elide_url.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
// static
infobars::InfoBar* PermissionInfoBarDelegate::Create(
content::PermissionType type,
InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback) {
switch (type) {
case content::PermissionType::GEOLOCATION:
return infobar_service->AddInfoBar(
CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
new GeolocationInfoBarDelegateAndroid(
requesting_frame, user_gesture, profile, callback))));
#if defined(ENABLE_NOTIFICATIONS)
case content::PermissionType::NOTIFICATIONS:
case content::PermissionType::PUSH_MESSAGING:
return infobar_service->AddInfoBar(
CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
new NotificationPermissionInfoBarDelegate(
requesting_frame, user_gesture, profile, callback))));
#endif // ENABLE_NOTIFICATIONS
case content::PermissionType::MIDI_SYSEX:
return infobar_service->AddInfoBar(
CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
new MidiPermissionInfoBarDelegateAndroid(
requesting_frame, user_gesture, profile, callback))));
case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
return infobar_service->AddInfoBar(
CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
new ProtectedMediaIdentifierInfoBarDelegateAndroid(
requesting_frame, user_gesture, profile, callback))));
default:
NOTREACHED();
return nullptr;
}
}
PermissionInfoBarDelegate::~PermissionInfoBarDelegate() { PermissionInfoBarDelegate::~PermissionInfoBarDelegate() {
if (!action_taken_) { if (!action_taken_) {
PermissionUmaUtil::PermissionIgnored( PermissionUmaUtil::PermissionIgnored(
...@@ -21,22 +65,6 @@ PermissionInfoBarDelegate::~PermissionInfoBarDelegate() { ...@@ -21,22 +65,6 @@ PermissionInfoBarDelegate::~PermissionInfoBarDelegate() {
} }
} }
PermissionInfoBarDelegate::PermissionInfoBarDelegate(
const GURL& requesting_origin,
content::PermissionType permission_type,
ContentSettingsType content_settings_type,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback)
: requesting_origin_(requesting_origin),
permission_type_(permission_type),
content_settings_type_(content_settings_type),
profile_(profile),
callback_(callback),
action_taken_(false),
user_gesture_(user_gesture),
persist_(true) {}
std::vector<int> PermissionInfoBarDelegate::content_settings() const { std::vector<int> PermissionInfoBarDelegate::content_settings() const {
return std::vector<int>{content_settings_type_}; return std::vector<int>{content_settings_type_};
} }
...@@ -56,6 +84,22 @@ base::string16 PermissionInfoBarDelegate::GetMessageText() const { ...@@ -56,6 +84,22 @@ base::string16 PermissionInfoBarDelegate::GetMessageText() const {
url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
} }
PermissionInfoBarDelegate::PermissionInfoBarDelegate(
const GURL& requesting_origin,
content::PermissionType permission_type,
ContentSettingsType content_settings_type,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback)
: requesting_origin_(requesting_origin),
permission_type_(permission_type),
content_settings_type_(content_settings_type),
profile_(profile),
callback_(callback),
action_taken_(false),
user_gesture_(user_gesture),
persist_(true) {}
infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType() infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType()
const { const {
return PAGE_ACTION_TYPE; return PAGE_ACTION_TYPE;
......
...@@ -14,7 +14,13 @@ ...@@ -14,7 +14,13 @@
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
#include "components/infobars/core/confirm_infobar_delegate.h" #include "components/infobars/core/confirm_infobar_delegate.h"
#include "content/public/browser/permission_type.h" #include "content/public/browser/permission_type.h"
#include "url/gurl.h"
namespace infobars {
class InfoBar;
}
class InfoBarService;
class Profile; class Profile;
// Base class for permission infobars, it implements the default behavior // Base class for permission infobars, it implements the default behavior
...@@ -26,6 +32,16 @@ class PermissionInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -26,6 +32,16 @@ class PermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
public: public:
using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>;
// Creates an infobar for |type|. The returned pointer is owned by
// |infobar_service| and manages its own lifetime; callers must only use it
// for calls to |infobar_service|.
static infobars::InfoBar* Create(content::PermissionType type,
InfoBarService* infobar_service,
const GURL& requesting_frame,
bool user_gesture,
Profile* profile,
const PermissionSetCallback& callback);
~PermissionInfoBarDelegate() override; ~PermissionInfoBarDelegate() override;
virtual std::vector<int> content_settings() const; virtual std::vector<int> content_settings() const;
......
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/media/midi_permission_infobar_delegate_android.h"
#include "chrome/browser/media/protected_media_identifier_infobar_delegate_android.h"
#include "chrome/browser/notifications/notification_permission_infobar_delegate.h"
#include "chrome/browser/permissions/permission_infobar_delegate.h" #include "chrome/browser/permissions/permission_infobar_delegate.h"
#include "chrome/browser/permissions/permission_request.h" #include "chrome/browser/permissions/permission_request.h"
#include "chrome/browser/permissions/permission_request_id.h" #include "chrome/browser/permissions/permission_request_id.h"
...@@ -123,34 +119,10 @@ void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( ...@@ -123,34 +119,10 @@ void PermissionQueueController::PendingInfobarRequest::CreateInfoBar(
PermissionInfoBarDelegate::PermissionSetCallback callback = base::Bind( PermissionInfoBarDelegate::PermissionSetCallback callback = base::Bind(
&PermissionQueueController::OnPermissionSet, base::Unretained(controller), &PermissionQueueController::OnPermissionSet, base::Unretained(controller),
id_, requesting_frame_, embedder_, user_gesture_); id_, requesting_frame_, embedder_, user_gesture_);
switch (type_) {
case content::PermissionType::GEOLOCATION: infobar_ = PermissionInfoBarDelegate::Create(type_, GetInfoBarService(id_),
infobar_ = GeolocationInfoBarDelegateAndroid::Create( requesting_frame_, user_gesture_,
GetInfoBarService(id_), requesting_frame_, user_gesture_, profile_, profile_, callback);
callback);
break;
#if defined(ENABLE_NOTIFICATIONS)
case content::PermissionType::NOTIFICATIONS:
case content::PermissionType::PUSH_MESSAGING:
infobar_ = NotificationPermissionInfoBarDelegate::Create(
GetInfoBarService(id_), requesting_frame_, user_gesture_, profile_,
callback);
break;
#endif // ENABLE_NOTIFICATIONS
case content::PermissionType::MIDI_SYSEX:
infobar_ = MidiPermissionInfoBarDelegateAndroid::Create(
GetInfoBarService(id_), requesting_frame_, user_gesture_, profile_,
callback);
break;
case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
infobar_ = ProtectedMediaIdentifierInfoBarDelegateAndroid::Create(
GetInfoBarService(id_), requesting_frame_, user_gesture_, profile_,
callback);
break;
default:
NOTREACHED();
break;
}
} }
PermissionQueueController::PermissionQueueController( PermissionQueueController::PermissionQueueController(
......
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