Commit 1b6a1c23 authored by gbillock@chromium.org's avatar gbillock@chromium.org

[Media,Geolocation] Add permission bubble cancellation.

BUG=332115,342562

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273068 0039d316-1c4b-4281-b951-d872f2087c98
parent e65accc9
......@@ -114,11 +114,11 @@ void GeolocationPermissionRequest::PermissionDenied() {
}
void GeolocationPermissionRequest::Cancelled() {
context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
}
void GeolocationPermissionRequest::RequestFinished() {
delete this;
// Deletes 'this'.
context_->RequestFinished(this);
}
......@@ -210,7 +210,6 @@ void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest(
guest->CancelGeolocationPermissionRequest(bridge_id);
return;
}
// TODO(gbillock): cancel permission bubble request.
int render_process_id = web_contents->GetRenderProcessHost()->GetID();
int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
CancelPendingInfobarRequest(PermissionRequestID(
......@@ -243,9 +242,13 @@ void ChromeGeolocationPermissionContext::DecidePermission(
PermissionBubbleManager* mgr =
PermissionBubbleManager::FromWebContents(web_contents);
if (mgr) {
mgr->AddRequest(new GeolocationPermissionRequest(
scoped_ptr<GeolocationPermissionRequest> request_ptr(
new GeolocationPermissionRequest(
this, id, requesting_frame, user_gesture, callback,
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)));
GeolocationPermissionRequest* request = request_ptr.get();
pending_requests_.add(id.ToString(), request_ptr.Pass());
mgr->AddRequest(request);
}
} else {
// setting == ask. Prompt the user.
......@@ -270,6 +273,19 @@ void ChromeGeolocationPermissionContext::CreateInfoBarRequest(
base::Unretained(this), id, requesting_frame, callback));
}
void ChromeGeolocationPermissionContext::RequestFinished(
GeolocationPermissionRequest* request) {
base::ScopedPtrHashMap<std::string,
GeolocationPermissionRequest>::iterator it;
for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) {
if (it->second == request) {
pending_requests_.take_and_erase(it);
return;
}
}
}
void ChromeGeolocationPermissionContext::ShutdownOnUIThread() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
permission_queue_controller_.reset();
......@@ -326,6 +342,18 @@ void ChromeGeolocationPermissionContext::CancelPendingInfobarRequest(
if (shutting_down_)
return;
// TODO(gbillock): handle permission bubble cancellation.
if (PermissionBubbleManager::Enabled()) {
GeolocationPermissionRequest* cancelling =
pending_requests_.get(id.ToString());
content::WebContents* web_contents = tab_util::GetWebContentsByID(
id.render_process_id(), id.render_view_id());
if (cancelling != NULL && web_contents != NULL &&
PermissionBubbleManager::FromWebContents(web_contents) != NULL) {
PermissionBubbleManager::FromWebContents(web_contents)->
CancelRequest(cancelling);
}
return;
}
QueueController()->CancelInfoBarRequest(id);
}
......@@ -5,8 +5,10 @@
#ifndef CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_
#define CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_H_
#include <map>
#include <string>
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/content_settings/permission_queue_controller.h"
#include "content/public/browser/geolocation_permission_context.h"
......@@ -15,6 +17,7 @@ namespace content {
class WebContents;
}
class GeolocationPermissionRequest;
class PermissionRequestID;
class Profile;
......@@ -87,6 +90,8 @@ class ChromeGeolocationPermissionContext
virtual PermissionQueueController* CreateQueueController();
private:
friend class GeolocationPermissionRequest;
// Removes any pending InfoBar request.
void CancelPendingInfobarRequest(const PermissionRequestID& id);
......@@ -97,11 +102,17 @@ class ChromeGeolocationPermissionContext
const std::string accept_button_label,
base::Callback<void(bool)> callback);
// Notify the context that a particular request object is no longer needed.
void RequestFinished(GeolocationPermissionRequest* request);
// These must only be accessed from the UI thread.
Profile* const profile_;
bool shutting_down_;
scoped_ptr<PermissionQueueController> permission_queue_controller_;
base::ScopedPtrHashMap<std::string, GeolocationPermissionRequest>
pending_requests_;
DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContext);
};
......
......@@ -50,6 +50,7 @@ class MidiPermissionRequest : public PermissionBubbleRequest {
bool user_gesture_;
std::string display_languages_;
const content::BrowserContext::MidiSysExPermissionCallback& callback_;
bool is_finished_;
DISALLOW_COPY_AND_ASSIGN(MidiPermissionRequest);
};
......@@ -66,9 +67,12 @@ MidiPermissionRequest::MidiPermissionRequest(
requesting_frame_(requesting_frame),
user_gesture_(user_gesture),
display_languages_(display_languages),
callback_(callback) {}
callback_(callback),
is_finished_(false) {}
MidiPermissionRequest::~MidiPermissionRequest() {}
MidiPermissionRequest::~MidiPermissionRequest() {
DCHECK(is_finished_);
}
int MidiPermissionRequest::GetIconID() const {
return IDR_ALLOWED_MIDI_SYSEX;
......@@ -101,11 +105,12 @@ void MidiPermissionRequest::PermissionDenied() {
}
void MidiPermissionRequest::Cancelled() {
context_->NotifyPermissionSet(id_, requesting_frame_, callback_, false);
}
void MidiPermissionRequest::RequestFinished() {
delete this;
is_finished_ = true;
// Deletes 'this'.
context_->RequestFinished(this);
}
ChromeMidiPermissionContext::ChromeMidiPermissionContext(Profile* profile)
......@@ -116,6 +121,7 @@ ChromeMidiPermissionContext::ChromeMidiPermissionContext(Profile* profile)
ChromeMidiPermissionContext::~ChromeMidiPermissionContext() {
DCHECK(!permission_queue_controller_);
DCHECK(pending_requests_.empty());
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
}
......@@ -200,10 +206,16 @@ void ChromeMidiPermissionContext::DecidePermission(
PermissionBubbleManager* bubble_manager =
PermissionBubbleManager::FromWebContents(web_contents);
if (bubble_manager) {
bubble_manager->AddRequest(new MidiPermissionRequest(
this, id, requesting_frame, user_gesture,
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
callback));
scoped_ptr<MidiPermissionRequest> request_ptr(
new MidiPermissionRequest(
this, id, requesting_frame, user_gesture,
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
callback));
MidiPermissionRequest* request = request_ptr.get();
bool inserted = pending_requests_.add(
id.ToString(), request_ptr.Pass()).second;
DCHECK(inserted) << "Duplicate id " << id.ToString();
bubble_manager->AddRequest(request);
}
return;
}
......@@ -256,11 +268,36 @@ PermissionQueueController* ChromeMidiPermissionContext::GetQueueController() {
return permission_queue_controller_.get();
}
void ChromeMidiPermissionContext::RequestFinished(
MidiPermissionRequest* request) {
base::ScopedPtrHashMap<std::string, MidiPermissionRequest>::iterator it;
for (it = pending_requests_.begin(); it != pending_requests_.end(); it++) {
if (it->second == request) {
pending_requests_.take_and_erase(it);
return;
}
}
NOTREACHED() << "Missing request";
}
void ChromeMidiPermissionContext::CancelPendingInfobarRequest(
const PermissionRequestID& id) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (shutting_down_)
return;
// TODO(gbillock): Add support for cancellation to permission bubbles.
if (PermissionBubbleManager::Enabled()) {
MidiPermissionRequest* cancelling = pending_requests_.get(id.ToString());
content::WebContents* web_contents = tab_util::GetWebContentsByID(
id.render_process_id(), id.render_view_id());
if (cancelling != NULL && web_contents != NULL &&
PermissionBubbleManager::FromWebContents(web_contents) != NULL) {
PermissionBubbleManager::FromWebContents(web_contents)->
CancelRequest(cancelling);
}
return;
}
GetQueueController()->CancelInfoBarRequest(id);
}
......@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_
#define CHROME_BROWSER_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/memory/scoped_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/browser_context.h"
......@@ -14,6 +15,7 @@ class WebContents;
}
class GURL;
class MidiPermissionRequest;
class PermissionQueueController;
class PermissionRequestID;
class Profile;
......@@ -52,6 +54,8 @@ class ChromeMidiPermissionContext : public KeyedService {
bool allowed);
private:
friend class MidiPermissionRequest;
// Decide whether the permission should be granted.
// Calls PermissionDecided if permission can be decided non-interactively,
// or NotifyPermissionSet if permission decided by presenting an infobar.
......@@ -77,10 +81,15 @@ class ChromeMidiPermissionContext : public KeyedService {
// Removes any pending InfoBar request.
void CancelPendingInfobarRequest(const PermissionRequestID& id);
// Notify the context that a particular request object is no longer needed.
void RequestFinished(MidiPermissionRequest* request);
Profile* const profile_;
bool shutting_down_;
scoped_ptr<PermissionQueueController> permission_queue_controller_;
base::ScopedPtrHashMap<std::string, MidiPermissionRequest> pending_requests_;
DISALLOW_COPY_AND_ASSIGN(ChromeMidiPermissionContext);
};
......
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