Commit ab6a39ea authored by qinmin@chromium.org's avatar qinmin@chromium.org

Allow duplicate infobar requests

There can be duplicate infobar requests.
For example, the same EME video might issue multiple key requests, and that will cause several duplicate infobar requests.
We need to remember these requests, and once the first request's permission is set, send notification for the other requests.
When OnPermissionSet(), it is always called on the request has has_infobar() is true.
As a result, we can remove those duplicate requests that doesn't have infobar.

BUG=373641

Review URL: https://codereview.chromium.org/322203003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276630 0039d316-1c4b-4281-b951-d872f2087c98
parent 7e7593b0
...@@ -153,12 +153,6 @@ void PermissionQueueController::CreateInfoBarRequest( ...@@ -153,12 +153,6 @@ void PermissionQueueController::CreateInfoBarRequest(
PermissionDecidedCallback callback) { PermissionDecidedCallback callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// We shouldn't get duplicate requests.
for (PendingInfobarRequests::const_iterator i(
pending_infobar_requests_.begin());
i != pending_infobar_requests_.end(); ++i)
DCHECK(!i->id().Equals(id));
pending_infobar_requests_.push_back(PendingInfobarRequest( pending_infobar_requests_.push_back(PendingInfobarRequest(
type_, id, requesting_frame, embedder, type_, id, requesting_frame, embedder,
accept_button_label, callback)); accept_button_label, callback));
...@@ -189,7 +183,6 @@ void PermissionQueueController::OnPermissionSet( ...@@ -189,7 +183,6 @@ void PermissionQueueController::OnPermissionSet(
bool update_content_setting, bool update_content_setting,
bool allowed) { bool allowed) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (update_content_setting) if (update_content_setting)
UpdateContentSetting(requesting_frame, embedder, allowed); UpdateContentSetting(requesting_frame, embedder, allowed);
...@@ -197,28 +190,29 @@ void PermissionQueueController::OnPermissionSet( ...@@ -197,28 +190,29 @@ void PermissionQueueController::OnPermissionSet(
// is this order important? // is this order important?
PendingInfobarRequests requests_to_notify; PendingInfobarRequests requests_to_notify;
PendingInfobarRequests infobars_to_remove; PendingInfobarRequests infobars_to_remove;
std::vector<PendingInfobarRequests::iterator> pending_requests_to_remove;
for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin();
i != pending_infobar_requests_.end(); ) { i != pending_infobar_requests_.end(); ++i) {
if (i->IsForPair(requesting_frame, embedder)) { if (!i->IsForPair(requesting_frame, embedder))
continue;
requests_to_notify.push_back(*i); 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.
pending_requests_to_remove.push_back(i);
continue;
}
if (i->id().Equals(id)) { if (i->id().Equals(id)) {
// The infobar that called us is i->infobar(), and its delegate is // The infobar that called us is i->infobar(), and its delegate is
// currently in either Accept() or Cancel(). This means that // currently in either Accept() or Cancel(). This means that
// RemoveInfoBar() will be called later on, and that will trigger a // RemoveInfoBar() will be called later on, and that will trigger a
// notification we're observing. // notification we're observing.
++i; continue;
} else if (i->has_infobar()) { }
// This infobar is for the same frame/embedder pair, but in a different // This infobar is for the same frame/embedder pair, but in a different
// tab. We should remove it now that we've got an answer for it. // tab. We should remove it now that we've got an answer for it.
infobars_to_remove.push_back(*i); infobars_to_remove.push_back(*i);
++i;
} else {
// We haven't created an infobar yet, just remove the pending request.
i = pending_infobar_requests_.erase(i);
}
} else {
++i;
}
} }
// Remove all infobars for the same |requesting_frame| and |embedder|. // Remove all infobars for the same |requesting_frame| and |embedder|.
...@@ -230,6 +224,10 @@ void PermissionQueueController::OnPermissionSet( ...@@ -230,6 +224,10 @@ void PermissionQueueController::OnPermissionSet(
for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); for (PendingInfobarRequests::iterator i = requests_to_notify.begin();
i != requests_to_notify.end(); ++i) i != requests_to_notify.end(); ++i)
i->RunCallback(allowed); i->RunCallback(allowed);
// Remove the pending requests in reverse order.
for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i)
pending_infobar_requests_.erase(pending_requests_to_remove[i]);
} }
void PermissionQueueController::Observe( void PermissionQueueController::Observe(
......
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