| 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..13410430ec3ba5835de1ed94017b57d53c5e79ef 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,11 +66,13 @@ 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_; }
|
| + bool has_dialog() const { return has_dialog_; }
|
| infobars::InfoBar* infobar() { return infobar_; }
|
|
|
| void RunCallback(ContentSetting content_setting);
|
| - void CreateInfoBar(PermissionQueueController* controller);
|
| + void CreatePrompt(PermissionQueueController* controller, bool show_dialog);
|
|
|
| private:
|
| content::PermissionType type_;
|
| @@ -75,6 +83,7 @@ class PermissionQueueController::PendingInfobarRequest {
|
| Profile* profile_;
|
| PermissionDecidedCallback callback_;
|
| infobars::InfoBar* infobar_;
|
| + bool has_dialog_;
|
|
|
| // Purposefully do not disable copying, as this is stored in STL containers.
|
| };
|
| @@ -94,7 +103,8 @@ PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest(
|
| user_gesture_(user_gesture),
|
| profile_(profile),
|
| callback_(callback),
|
| - infobar_(NULL) {}
|
| + infobar_(nullptr),
|
| + has_dialog_(false) {}
|
|
|
| PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() {
|
| }
|
| @@ -110,8 +120,9 @@ void PermissionQueueController::PendingInfobarRequest::RunCallback(
|
| callback_.Run(content_setting);
|
| }
|
|
|
| -void PermissionQueueController::PendingInfobarRequest::CreateInfoBar(
|
| - PermissionQueueController* controller) {
|
| +void PermissionQueueController::PendingInfobarRequest::CreatePrompt(
|
| + PermissionQueueController* controller,
|
| + bool show_dialog) {
|
| // Controller can be Unretained because the lifetime of the infobar
|
| // is tied to that of the queue controller. Before QueueController
|
| // is destroyed, all requests will be cancelled and so all delegates
|
| @@ -120,9 +131,21 @@ 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 (show_dialog) {
|
| + // We should show a dialog prompt instead of an infobar. Since only one
|
| + // dialog can be shown at a time, the Java-side owns and manages the queue
|
| + // of 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.
|
| + has_dialog_ = true;
|
| + PermissionDialogDelegate::Create(GetWebContents(id_), type_,
|
| + requesting_frame_, user_gesture_, profile_,
|
| + callback);
|
| + } else {
|
| + infobar_ = PermissionInfoBarDelegate::Create(
|
| + GetInfoBarService(id_), type_, requesting_frame_, user_gesture_,
|
| + profile_, callback);
|
| + }
|
| }
|
|
|
| PermissionQueueController::PermissionQueueController(
|
| @@ -260,8 +283,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)
|
| @@ -300,8 +324,10 @@ bool PermissionQueueController::AlreadyShowingInfoBarForTab(
|
| for (PendingInfobarRequests::const_iterator i(
|
| pending_infobar_requests_.begin());
|
| i != pending_infobar_requests_.end(); ++i) {
|
| - if (ArePermissionRequestsForSameTab(i->id(), id) && i->has_infobar())
|
| + if (ArePermissionRequestsForSameTab(i->id(), id) &&
|
| + (i->has_infobar() || i->has_dialog())) {
|
| return true;
|
| + }
|
| }
|
| return false;
|
| }
|
| @@ -328,8 +354,14 @@ 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);
|
| - i->CreateInfoBar(this);
|
| + // When using modal permission prompts, Java controls the display queue,
|
| + // so infobar notifications are not relevant.
|
| + bool show_dialog =
|
| + PermissionDialogDelegate::ShouldShowDialog(i->has_gesture());
|
| + if (!show_dialog)
|
| + RegisterForInfoBarNotifications(infobar_service);
|
| +
|
| + i->CreatePrompt(this, show_dialog);
|
| return;
|
| }
|
| }
|
|
|