| Index: chrome/browser/permissions/permission_queue_controller.cc
|
| diff --git a/chrome/browser/permissions/permission_queue_controller.cc b/chrome/browser/permissions/permission_queue_controller.cc
|
| index 2e272bdbee1349d1a024141d7fa6597d5c03264c..6252bbde4f7c77b95180bc40ab6bb72853802a75 100644
|
| --- a/chrome/browser/permissions/permission_queue_controller.cc
|
| +++ b/chrome/browser/permissions/permission_queue_controller.cc
|
| @@ -4,15 +4,18 @@
|
|
|
| #include "chrome/browser/permissions/permission_queue_controller.h"
|
|
|
| +#include "base/feature_list.h"
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
| #include "chrome/browser/infobars/infobar_service.h"
|
| +#include "chrome/browser/permissions/permission_dialog_delegate.h"
|
| #include "chrome/browser/permissions/permission_infobar_delegate.h"
|
| #include "chrome/browser/permissions/permission_request.h"
|
| #include "chrome/browser/permissions/permission_request_id.h"
|
| #include "chrome/browser/permissions/permission_uma_util.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/tab_contents/tab_util.h"
|
| +#include "chrome/common/chrome_features.h"
|
| #include "components/content_settings/core/browser/host_content_settings_map.h"
|
| #include "components/content_settings/core/common/content_settings.h"
|
| #include "components/infobars/core/infobar.h"
|
| @@ -25,10 +28,15 @@
|
|
|
| namespace {
|
|
|
| -InfoBarService* GetInfoBarService(const PermissionRequestID& id) {
|
| - content::WebContents* web_contents = tab_util::GetWebContentsByFrameID(
|
| +content::WebContents* GetWebContents(const PermissionRequestID& id) {
|
| + return tab_util::GetWebContentsByFrameID(
|
| id.render_process_id(), id.render_frame_id());
|
| - return web_contents ? InfoBarService::FromWebContents(web_contents) : NULL;
|
| +}
|
| +
|
| +
|
| +InfoBarService* GetInfoBarService(const PermissionRequestID& id) {
|
| + content::WebContents* web_contents = GetWebContents(id);
|
| + return web_contents ? InfoBarService::FromWebContents(web_contents) : nullptr;
|
| }
|
|
|
| bool ArePermissionRequestsForSameTab(
|
| @@ -94,7 +102,7 @@ PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest(
|
| user_gesture_(user_gesture),
|
| profile_(profile),
|
| callback_(callback),
|
| - infobar_(NULL) {}
|
| + infobar_(nullptr) {}
|
|
|
| PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() {
|
| }
|
| @@ -120,9 +128,20 @@ void PermissionQueueController::PendingInfobarRequest::CreateInfoBar(
|
| &PermissionQueueController::OnPermissionSet, base::Unretained(controller),
|
| id_, requesting_frame_, embedder_, user_gesture_);
|
|
|
| - infobar_ = PermissionInfoBarDelegate::Create(type_, GetInfoBarService(id_),
|
| - requesting_frame_, user_gesture_,
|
| - profile_, callback);
|
| + if (base::FeatureList::IsEnabled(features::kModalPermissionPrompts)) {
|
| + // Only one modal can be shown at a time. This method calls through to Java,
|
| + // which owns and manages the queue of modal prompts; the bookkeeping in
|
| + // this class will work as expected:
|
| + // i. no pending request will ever have an infobar created for it.
|
| + // ii. OnPermissionSet is still called when the user makes a decision.
|
| + PermissionDialogDelegate::Create(type_, GetWebContents(id_),
|
| + requesting_frame_, user_gesture_, profile_,
|
| + callback);
|
| + } else {
|
| + infobar_ = PermissionInfoBarDelegate::Create(
|
| + type_, GetInfoBarService(id_), requesting_frame_, user_gesture_,
|
| + profile_, callback);
|
| + }
|
| }
|
|
|
| PermissionQueueController::PermissionQueueController(
|
| @@ -221,9 +240,10 @@ void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id,
|
| if (!i->IsForPair(requesting_frame, embedder))
|
| continue;
|
| requests_to_notify.push_back(*i);
|
| - if (!i->has_infobar()) {
|
| - // We haven't created an infobar yet, just record the pending request
|
| - // index and remove it later.
|
| + if (!i->has_infobar() ||
|
| + base::FeatureList::IsEnabled(features::kModalPermissionPrompts)) {
|
| + // We haven't created an infobar yet, or no infobars are being created.
|
| + // Record the pending request index and remove it later.
|
| pending_requests_to_remove.push_back(i);
|
| continue;
|
| }
|
| @@ -260,8 +280,9 @@ void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id,
|
|
|
| // Send out the permission notifications.
|
| for (PendingInfobarRequests::iterator i = requests_to_notify.begin();
|
| - i != requests_to_notify.end(); ++i)
|
| + i != requests_to_notify.end(); ++i) {
|
| i->RunCallback(content_setting);
|
| + }
|
|
|
| // Remove the pending requests in reverse order.
|
| for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i)
|
| @@ -328,7 +349,11 @@ void PermissionQueueController::ShowQueuedInfoBarForTab(
|
| for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin();
|
| i != pending_infobar_requests_.end(); ++i) {
|
| if (ArePermissionRequestsForSameTab(i->id(), id) && !i->has_infobar()) {
|
| - RegisterForInfoBarNotifications(infobar_service);
|
| + // When using modal permission prompts, Java controls the display queue,
|
| + // so infobar notifications are not relevant.
|
| + if (!base::FeatureList::IsEnabled(features::kModalPermissionPrompts))
|
| + RegisterForInfoBarNotifications(infobar_service);
|
| +
|
| i->CreateInfoBar(this);
|
| return;
|
| }
|
|
|