summaryrefslogtreecommitdiffstats
path: root/chrome/browser/content_settings
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/content_settings')
-rw-r--r--chrome/browser/content_settings/permission_bubble_request_impl.cc8
-rw-r--r--chrome/browser/content_settings/permission_bubble_request_impl.h7
-rw-r--r--chrome/browser/content_settings/permission_context_base.cc59
-rw-r--r--chrome/browser/content_settings/permission_context_base.h8
-rw-r--r--chrome/browser/content_settings/permission_context_base_unittest.cc4
-rw-r--r--chrome/browser/content_settings/permission_queue_controller.cc24
-rw-r--r--chrome/browser/content_settings/permission_queue_controller.h5
-rw-r--r--chrome/browser/content_settings/permission_queue_controller_unittest.cc8
8 files changed, 71 insertions, 52 deletions
diff --git a/chrome/browser/content_settings/permission_bubble_request_impl.cc b/chrome/browser/content_settings/permission_bubble_request_impl.cc
index 5d7e6be..3fc8bed 100644
--- a/chrome/browser/content_settings/permission_bubble_request_impl.cc
+++ b/chrome/browser/content_settings/permission_bubble_request_impl.cc
@@ -16,7 +16,7 @@ PermissionBubbleRequestImpl::PermissionBubbleRequestImpl(
bool user_gesture,
ContentSettingsType type,
const std::string& display_languages,
- const base::Callback<void(bool, bool)> permission_decided_callback,
+ const PermissionDecidedCallback& permission_decided_callback,
const base::Closure delete_callback)
: request_origin_(request_origin),
user_gesture_(user_gesture),
@@ -136,17 +136,17 @@ GURL PermissionBubbleRequestImpl::GetRequestingHostname() const {
void PermissionBubbleRequestImpl::PermissionGranted() {
RegisterActionTaken();
- permission_decided_callback_.Run(true, true);
+ permission_decided_callback_.Run(true, CONTENT_SETTING_ALLOW);
}
void PermissionBubbleRequestImpl::PermissionDenied() {
RegisterActionTaken();
- permission_decided_callback_.Run(true, false);
+ permission_decided_callback_.Run(true, CONTENT_SETTING_BLOCK);
}
void PermissionBubbleRequestImpl::Cancelled() {
RegisterActionTaken();
- permission_decided_callback_.Run(false, false);
+ permission_decided_callback_.Run(false, CONTENT_SETTING_DEFAULT);
}
void PermissionBubbleRequestImpl::RequestFinished() {
diff --git a/chrome/browser/content_settings/permission_bubble_request_impl.h b/chrome/browser/content_settings/permission_bubble_request_impl.h
index caf05b7..985c9d0 100644
--- a/chrome/browser/content_settings/permission_bubble_request_impl.h
+++ b/chrome/browser/content_settings/permission_bubble_request_impl.h
@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "chrome/browser/ui/website_settings/permission_bubble_request.h"
+#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/permission_request_id.h"
@@ -19,16 +20,14 @@ class PermissionContextBase;
// is executed.
class PermissionBubbleRequestImpl : public PermissionBubbleRequest {
public:
-
- typedef base::Callback<void(bool persist_permission, bool grant_permission)>
- PermissionDecidedCallback;
+ using PermissionDecidedCallback = base::Callback<void(bool, ContentSetting)>;
PermissionBubbleRequestImpl(
const GURL& request_origin,
bool user_gesture,
ContentSettingsType type,
const std::string& display_languages,
- const PermissionDecidedCallback permission_decided_callback,
+ const PermissionDecidedCallback& permission_decided_callback,
const base::Closure delete_callback);
~PermissionBubbleRequestImpl() override;
diff --git a/chrome/browser/content_settings/permission_context_base.cc b/chrome/browser/content_settings/permission_context_base.cc
index c188377..711dbe5 100644
--- a/chrome/browser/content_settings/permission_context_base.cc
+++ b/chrome/browser/content_settings/permission_context_base.cc
@@ -99,8 +99,8 @@ void PermissionContextBase::DecidePermission(
<< "," << embedding_origin
<< " (" << content_settings::GetTypeName(permission_type_)
<< " is not supported in popups)";
- NotifyPermissionSet(id, requesting_origin, embedding_origin,
- callback, false /* persist */, false /* granted */);
+ NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
+ false /* persist */, CONTENT_SETTING_BLOCK);
return;
}
@@ -110,17 +110,11 @@ void PermissionContextBase::DecidePermission(
requesting_origin, embedding_origin, permission_type_,
std::string());
- switch (content_setting) {
- case CONTENT_SETTING_BLOCK:
- NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
- false /* persist */, false /* granted */);
- return;
- case CONTENT_SETTING_ALLOW:
- NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
- false /* persist */, true /* granted */);
- return;
- default:
- break;
+ if (content_setting == CONTENT_SETTING_ALLOW ||
+ content_setting == CONTENT_SETTING_BLOCK) {
+ NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
+ false /* persist */, content_setting);
+ return;
}
PermissionContextUmaUtil::PermissionRequested(
@@ -168,25 +162,28 @@ void PermissionContextBase::PermissionDecided(
const GURL& embedding_origin,
const BrowserPermissionCallback& callback,
bool persist,
- bool allowed) {
+ ContentSetting content_setting) {
// Infobar persistance and its related UMA is tracked on the infobar
// controller directly.
if (PermissionBubbleManager::Enabled()) {
if (persist) {
- if (allowed)
+ DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
+ content_setting == CONTENT_SETTING_BLOCK);
+ if (CONTENT_SETTING_ALLOW)
PermissionContextUmaUtil::PermissionGranted(permission_type_,
requesting_origin);
else
PermissionContextUmaUtil::PermissionDenied(permission_type_,
requesting_origin);
} else {
+ DCHECK_EQ(content_setting, CONTENT_SETTING_DEFAULT);
PermissionContextUmaUtil::PermissionDismissed(permission_type_,
requesting_origin);
}
}
NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
- persist, allowed);
+ persist, content_setting);
}
PermissionQueueController* PermissionContextBase::GetQueueController() {
@@ -203,13 +200,23 @@ void PermissionContextBase::NotifyPermissionSet(
const GURL& embedding_origin,
const BrowserPermissionCallback& callback,
bool persist,
- bool allowed) {
+ ContentSetting content_setting) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
if (persist)
- UpdateContentSetting(requesting_origin, embedding_origin, allowed);
+ UpdateContentSetting(requesting_origin, embedding_origin, content_setting);
+
+ UpdateTabContext(id, requesting_origin,
+ content_setting == CONTENT_SETTING_ALLOW);
- UpdateTabContext(id, requesting_origin, allowed);
- callback.Run(allowed);
+ if (content_setting == CONTENT_SETTING_DEFAULT) {
+ content_setting =
+ profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
+ permission_type_, nullptr);
+ }
+
+ DCHECK_NE(content_setting, CONTENT_SETTING_DEFAULT);
+ callback.Run(content_setting);
}
void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) {
@@ -217,13 +224,15 @@ void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) {
DCHECK(success == 1) << "Missing request " << id.ToString();
}
-void PermissionContextBase::UpdateContentSetting(const GURL& requesting_origin,
- const GURL& embedding_origin,
- bool allowed) {
+void PermissionContextBase::UpdateContentSetting(
+ const GURL& requesting_origin,
+ const GURL& embedding_origin,
+ ContentSetting content_setting) {
DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin());
DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin());
- ContentSetting content_setting =
- allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
+ DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
+ content_setting == CONTENT_SETTING_BLOCK);
+
profile_->GetHostContentSettingsMap()->SetContentSetting(
ContentSettingsPattern::FromURLNoWildcard(requesting_origin),
ContentSettingsPattern::FromURLNoWildcard(embedding_origin),
diff --git a/chrome/browser/content_settings/permission_context_base.h b/chrome/browser/content_settings/permission_context_base.h
index 740aa8f..e727ce9 100644
--- a/chrome/browser/content_settings/permission_context_base.h
+++ b/chrome/browser/content_settings/permission_context_base.h
@@ -23,7 +23,7 @@ namespace content {
class WebContents;
}
-typedef base::Callback<void(bool)> BrowserPermissionCallback;
+using BrowserPermissionCallback = base::Callback<void(ContentSetting)>;
// This base class contains common operations for granting permissions.
// It offers the following functionality:
@@ -95,14 +95,14 @@ class PermissionContextBase : public KeyedService {
const GURL& embedding_origin,
const BrowserPermissionCallback& callback,
bool persist,
- bool allowed);
+ ContentSetting content_setting);
virtual void NotifyPermissionSet(const PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
const BrowserPermissionCallback& callback,
bool persist,
- bool allowed);
+ ContentSetting content_setting);
// Implementors can override this method to update the icons on the
// url bar with the result of the new permission.
@@ -121,7 +121,7 @@ class PermissionContextBase : public KeyedService {
// (for example for desktop notifications).
virtual void UpdateContentSetting(const GURL& requesting_origin,
const GURL& embedding_origin,
- bool allowed);
+ ContentSetting content_setting);
private:
// Called when a bubble is no longer used so it can be cleaned up.
diff --git a/chrome/browser/content_settings/permission_context_base_unittest.cc b/chrome/browser/content_settings/permission_context_base_unittest.cc
index 01cd4e1..d43250d 100644
--- a/chrome/browser/content_settings/permission_context_base_unittest.cc
+++ b/chrome/browser/content_settings/permission_context_base_unittest.cc
@@ -48,9 +48,9 @@ class TestPermissionContext : public PermissionContextBase {
return tab_context_updated_;
}
- void TrackPermissionDecision(bool granted) {
+ void TrackPermissionDecision(ContentSetting content_setting) {
permission_set_ = true;
- permission_granted_ = granted;
+ permission_granted_ = content_setting == CONTENT_SETTING_ALLOW;
}
protected:
diff --git a/chrome/browser/content_settings/permission_queue_controller.cc b/chrome/browser/content_settings/permission_queue_controller.cc
index 9747ce7..c0a6531 100644
--- a/chrome/browser/content_settings/permission_queue_controller.cc
+++ b/chrome/browser/content_settings/permission_queue_controller.cc
@@ -45,7 +45,7 @@ class PermissionQueueController::PendingInfobarRequest {
const PermissionRequestID& id,
const GURL& requesting_frame,
const GURL& embedder,
- PermissionDecidedCallback callback);
+ const PermissionDecidedCallback& callback);
~PendingInfobarRequest();
bool IsForPair(const GURL& requesting_frame,
@@ -56,7 +56,7 @@ class PermissionQueueController::PendingInfobarRequest {
bool has_infobar() const { return !!infobar_; }
infobars::InfoBar* infobar() { return infobar_; }
- void RunCallback(bool allowed);
+ void RunCallback(ContentSetting content_setting);
void CreateInfoBar(PermissionQueueController* controller,
const std::string& display_languages);
@@ -76,7 +76,7 @@ PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest(
const PermissionRequestID& id,
const GURL& requesting_frame,
const GURL& embedder,
- PermissionDecidedCallback callback)
+ const PermissionDecidedCallback& callback)
: type_(type),
id_(id),
requesting_frame_(requesting_frame),
@@ -95,8 +95,8 @@ bool PermissionQueueController::PendingInfobarRequest::IsForPair(
}
void PermissionQueueController::PendingInfobarRequest::RunCallback(
- bool allowed) {
- callback_.Run(allowed);
+ ContentSetting content_setting) {
+ callback_.Run(content_setting);
}
void PermissionQueueController::PendingInfobarRequest::CreateInfoBar(
@@ -152,7 +152,7 @@ void PermissionQueueController::CreateInfoBarRequest(
const PermissionRequestID& id,
const GURL& requesting_frame,
const GURL& embedder,
- PermissionDecidedCallback callback) {
+ const PermissionDecidedCallback& callback) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (requesting_frame.SchemeIs(content::kChromeUIScheme) ||
@@ -235,10 +235,20 @@ void PermissionQueueController::OnPermissionSet(
i != infobars_to_remove.end(); ++i)
GetInfoBarService(i->id())->RemoveInfoBar(i->infobar());
+ // PermissionContextBase needs to know about the new ContentSetting value,
+ // CONTENT_SETTING_DEFAULT being the value for nothing happened. The callers
+ // of ::OnPermissionSet passes { true, true } for allow, { true, false } for
+ // block and { false, * } for dismissed. The tuple being
+ // { update_content_setting, allowed }.
+ ContentSetting content_setting = CONTENT_SETTING_DEFAULT;
+ if (update_content_setting) {
+ content_setting = allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
+ }
+
// Send out the permission notifications.
for (PendingInfobarRequests::iterator i = requests_to_notify.begin();
i != requests_to_notify.end(); ++i)
- i->RunCallback(allowed);
+ i->RunCallback(content_setting);
// Remove the pending requests in reverse order.
for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i)
diff --git a/chrome/browser/content_settings/permission_queue_controller.h b/chrome/browser/content_settings/permission_queue_controller.h
index ba2dbd4..3e856b6 100644
--- a/chrome/browser/content_settings/permission_queue_controller.h
+++ b/chrome/browser/content_settings/permission_queue_controller.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_CONTENT_SETTINGS_PERMISSION_QUEUE_CONTROLLER_H_
#include "base/bind.h"
+#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -25,7 +26,7 @@ class Profile;
// the notification infrastructure would simplify.
class PermissionQueueController : public content::NotificationObserver {
public:
- typedef base::Callback<void(bool /* allowed */)> PermissionDecidedCallback;
+ using PermissionDecidedCallback = base::Callback<void(ContentSetting)>;
PermissionQueueController(Profile* profile, ContentSettingsType type);
~PermissionQueueController() override;
@@ -35,7 +36,7 @@ class PermissionQueueController : public content::NotificationObserver {
void CreateInfoBarRequest(const PermissionRequestID& id,
const GURL& requesting_frame,
const GURL& embedder,
- PermissionDecidedCallback callback);
+ const PermissionDecidedCallback& callback);
// Cancels a specific infobar request.
void CancelInfoBarRequest(const PermissionRequestID& id);
diff --git a/chrome/browser/content_settings/permission_queue_controller_unittest.cc b/chrome/browser/content_settings/permission_queue_controller_unittest.cc
index d21cd9b..4cc3eac 100644
--- a/chrome/browser/content_settings/permission_queue_controller_unittest.cc
+++ b/chrome/browser/content_settings/permission_queue_controller_unittest.cc
@@ -95,21 +95,21 @@ TEST_F(PermissionQueueControllerTests, OneObservationPerInfoBarCancelled) {
// for notifications, it gets notified exactly once."
ObservationCountingQueueController queue_controller(profile());
GURL url("http://www.example.com/geolocation");
- base::Callback<void(bool)> callback;
+ base::Callback<void(ContentSetting)> callback;
queue_controller.CreateInfoBarRequest(
RequestID(0), url, url, callback);
queue_controller.CreateInfoBarRequest(
RequestID(1), url, url, callback);
queue_controller.CancelInfoBarRequest(RequestID(0));
EXPECT_EQ(1, queue_controller.call_count());
-};
+}
TEST_F(PermissionQueueControllerTests, FailOnBadPattern) {
ObservationCountingQueueController queue_controller(profile());
GURL url("chrome://settings");
- base::Callback<void(bool)> callback;
+ base::Callback<void(ContentSetting)> callback;
queue_controller.CreateInfoBarRequest(
RequestID(0), url, url, callback);
queue_controller.CancelInfoBarRequest(RequestID(0));
EXPECT_EQ(0, queue_controller.call_count());
-};
+}