Chromium Code Reviews| 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..caf2df22a1f2102f32231ece3034a7f4e27de058 100644 |
| --- a/chrome/browser/permissions/permission_queue_controller.cc |
| +++ b/chrome/browser/permissions/permission_queue_controller.cc |
| @@ -7,6 +7,7 @@ |
| #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" |
| @@ -25,10 +26,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( |
| @@ -60,6 +66,7 @@ class PermissionQueueController::PendingInfobarRequest { |
| const PermissionRequestID& id() const { return id_; } |
| const GURL& requesting_frame() const { return requesting_frame_; } |
| + bool has_gesture() const { return user_gesture_; } |
| bool has_infobar() const { return !!infobar_; } |
| infobars::InfoBar* infobar() { return infobar_; } |
| @@ -94,7 +101,7 @@ PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( |
| user_gesture_(user_gesture), |
| profile_(profile), |
| callback_(callback), |
| - infobar_(NULL) {} |
| + infobar_(nullptr) {} |
| PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { |
| } |
| @@ -120,9 +127,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 (PermissionDialogDelegate::ShouldShowModalPrompt(user_gesture_)) { |
|
gone
2016/10/27 20:33:35
This is really, really weird as you mentioned. It
dominickn
2016/10/27 23:37:13
Done.
|
| + // 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 +239,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() || |
| + PermissionDialogDelegate::ShouldShowModalPrompt(i->has_gesture())) { |
| + // 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 +279,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 +348,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 (!PermissionDialogDelegate::ShouldShowModalPrompt(i->has_gesture())) |
| + RegisterForInfoBarNotifications(infobar_service); |
| + |
| i->CreateInfoBar(this); |
| return; |
| } |