summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-09 06:55:01 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-09 06:55:01 +0000
commit18e001a7c9575037eda35bed4a0e35984945323d (patch)
tree7536f72a9227e8bc1a53c5b5fad00534a38c6133
parent09a8baca4d9887ff96fae636cc6ed4c6fd2ae992 (diff)
downloadchromium_src-18e001a7c9575037eda35bed4a0e35984945323d.zip
chromium_src-18e001a7c9575037eda35bed4a0e35984945323d.tar.gz
chromium_src-18e001a7c9575037eda35bed4a0e35984945323d.tar.bz2
When blocking cookies, also show an icon in the location bar when cookies are accessed.
If the user choses to block cookies per default, this will grant access to the collected cookies dialog as soon as the page accesses cookies. Right now, the icon is only shown if cookies were actually blocked. BUG=45230 TEST=Canned*.*:ContentSettingImage*.*:TabSpecific*.* Review URL: http://codereview.chromium.org/3014056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55382 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd3
-rw-r--r--chrome/browser/browsing_data_appcache_helper.cc4
-rw-r--r--chrome/browser/browsing_data_appcache_helper.h3
-rw-r--r--chrome/browser/browsing_data_appcache_helper_unittest.cc15
-rw-r--r--chrome/browser/browsing_data_database_helper.cc4
-rw-r--r--chrome/browser/browsing_data_database_helper.h3
-rw-r--r--chrome/browser/browsing_data_database_helper_unittest.cc16
-rw-r--r--chrome/browser/browsing_data_local_storage_helper.cc4
-rw-r--r--chrome/browser/browsing_data_local_storage_helper.h3
-rw-r--r--chrome/browser/browsing_data_local_storage_helper_unittest.cc15
-rw-r--r--chrome/browser/content_setting_bubble_model.cc29
-rw-r--r--chrome/browser/content_setting_image_model.cc62
-rw-r--r--chrome/browser/content_setting_image_model_unittest.cc38
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc2
-rw-r--r--chrome/browser/tab_contents/tab_contents.h4
-rw-r--r--chrome/browser/tab_contents/tab_specific_content_settings.cc32
-rw-r--r--chrome/browser/tab_contents/tab_specific_content_settings.h15
-rw-r--r--chrome/browser/tab_contents/tab_specific_content_settings_unittest.cc42
18 files changed, 262 insertions, 32 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index b3d76cf..836c57e 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -2328,6 +2328,9 @@ each locale. -->
<message name="IDS_BLOCKED_COOKIES_TITLE" desc="Tooltip and bubble info header text when a page is not allowed to write cookies or other site data.">
This page was prevented from setting cookies.
</message>
+ <message name="IDS_ACCESSED_COOKIES_TITLE" desc="Tooltip and bubble info header text when a page wrote cookies or other site data.">
+ This page set cookies.
+ </message>
<message name="IDS_BLOCKED_COOKIES_LINK" desc="Link to cookie section of content blocking management dialog, displayed in bubble when a page tries to write cookies or other site data.">
Manage cookie blocking...
</message>
diff --git a/chrome/browser/browsing_data_appcache_helper.cc b/chrome/browser/browsing_data_appcache_helper.cc
index 2e58c6b..de330fe 100644
--- a/chrome/browser/browsing_data_appcache_helper.cc
+++ b/chrome/browser/browsing_data_appcache_helper.cc
@@ -127,6 +127,10 @@ void CannedBrowsingDataAppCacheHelper::Reset() {
info_collection_->infos_by_origin.clear();
}
+bool CannedBrowsingDataAppCacheHelper::empty() const {
+ return info_collection_->infos_by_origin.empty();
+}
+
void CannedBrowsingDataAppCacheHelper::StartFetching(
Callback0::Type* completion_callback) {
completion_callback->Run();
diff --git a/chrome/browser/browsing_data_appcache_helper.h b/chrome/browser/browsing_data_appcache_helper.h
index b89f7a2..2e57fd8 100644
--- a/chrome/browser/browsing_data_appcache_helper.h
+++ b/chrome/browser/browsing_data_appcache_helper.h
@@ -65,6 +65,9 @@ class CannedBrowsingDataAppCacheHelper : public BrowsingDataAppCacheHelper {
// Clears the list of canned caches.
void Reset();
+ // True if no appcaches are currently stored.
+ bool empty() const;
+
// BrowsingDataAppCacheHelper methods.
virtual void StartFetching(Callback0::Type* completion_callback);
virtual void CancelNotification() {}
diff --git a/chrome/browser/browsing_data_appcache_helper_unittest.cc b/chrome/browser/browsing_data_appcache_helper_unittest.cc
index e5631b1..32d928c 100644
--- a/chrome/browser/browsing_data_appcache_helper_unittest.cc
+++ b/chrome/browser/browsing_data_appcache_helper_unittest.cc
@@ -82,3 +82,18 @@ TEST(CannedBrowsingDataAppCacheHelperTest, Unique) {
ASSERT_EQ(1u, collection[manifest.GetOrigin()].size());
EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url);
}
+
+TEST(CannedBrowsingDataAppCacheHelperTest, Empty) {
+ TestingProfile profile;
+
+ GURL manifest("http://example.com/manifest.xml");
+
+ scoped_refptr<CannedBrowsingDataAppCacheHelper> helper =
+ new CannedBrowsingDataAppCacheHelper(&profile);
+
+ ASSERT_TRUE(helper->empty());
+ helper->AddAppCache(manifest);
+ ASSERT_FALSE(helper->empty());
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+}
diff --git a/chrome/browser/browsing_data_database_helper.cc b/chrome/browser/browsing_data_database_helper.cc
index 11e5e6b..5c00df1 100644
--- a/chrome/browser/browsing_data_database_helper.cc
+++ b/chrome/browser/browsing_data_database_helper.cc
@@ -147,6 +147,10 @@ void CannedBrowsingDataDatabaseHelper::Reset() {
database_info_.clear();
}
+bool CannedBrowsingDataDatabaseHelper::empty() const {
+ return database_info_.empty();
+}
+
void CannedBrowsingDataDatabaseHelper::StartFetching(
Callback1<const std::vector<DatabaseInfo>& >::Type* callback) {
callback->Run(database_info_);
diff --git a/chrome/browser/browsing_data_database_helper.h b/chrome/browser/browsing_data_database_helper.h
index fb73784..26210a7 100644
--- a/chrome/browser/browsing_data_database_helper.h
+++ b/chrome/browser/browsing_data_database_helper.h
@@ -128,6 +128,9 @@ class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper {
// Clear the list of canned databases.
void Reset();
+ // True if no databases are currently stored.
+ bool empty() const;
+
// BrowsingDataDatabaseHelper methods.
virtual void StartFetching(
Callback1<const std::vector<DatabaseInfo>& >::Type* callback);
diff --git a/chrome/browser/browsing_data_database_helper_unittest.cc b/chrome/browser/browsing_data_database_helper_unittest.cc
index b5368c4..9d313db 100644
--- a/chrome/browser/browsing_data_database_helper_unittest.cc
+++ b/chrome/browser/browsing_data_database_helper_unittest.cc
@@ -93,3 +93,19 @@ TEST(CannedBrowsingDataDatabaseTest, Unique) {
EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str());
EXPECT_STREQ(db, result[0].database_name.c_str());
}
+
+TEST(CannedBrowsingDataDatabaseTest, Empty) {
+ TestingProfile profile;
+
+ const GURL origin("http://host1:1/");
+ const char db[] = "db1";
+
+ scoped_refptr<CannedBrowsingDataDatabaseHelper> helper =
+ new CannedBrowsingDataDatabaseHelper(&profile);
+
+ ASSERT_TRUE(helper->empty());
+ helper->AddDatabase(origin, db, "");
+ ASSERT_FALSE(helper->empty());
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+}
diff --git a/chrome/browser/browsing_data_local_storage_helper.cc b/chrome/browser/browsing_data_local_storage_helper.cc
index 2193305..8aedc24 100644
--- a/chrome/browser/browsing_data_local_storage_helper.cc
+++ b/chrome/browser/browsing_data_local_storage_helper.cc
@@ -152,6 +152,10 @@ void CannedBrowsingDataLocalStorageHelper::Reset() {
local_storage_info_.clear();
}
+bool CannedBrowsingDataLocalStorageHelper::empty() const {
+ return local_storage_info_.empty();
+}
+
void CannedBrowsingDataLocalStorageHelper::StartFetching(
Callback1<const std::vector<LocalStorageInfo>& >::Type* callback) {
callback->Run(local_storage_info_);
diff --git a/chrome/browser/browsing_data_local_storage_helper.h b/chrome/browser/browsing_data_local_storage_helper.h
index bf09d08..1f61070 100644
--- a/chrome/browser/browsing_data_local_storage_helper.h
+++ b/chrome/browser/browsing_data_local_storage_helper.h
@@ -122,6 +122,9 @@ class CannedBrowsingDataLocalStorageHelper
// Clear the list of canned local storages.
void Reset();
+ // True if no local storages are currently stored.
+ bool empty() const;
+
// BrowsingDataLocalStorageHelper methods.
virtual void StartFetching(
Callback1<const std::vector<LocalStorageInfo>& >::Type* callback);
diff --git a/chrome/browser/browsing_data_local_storage_helper_unittest.cc b/chrome/browser/browsing_data_local_storage_helper_unittest.cc
index 37c3555..918dc92 100644
--- a/chrome/browser/browsing_data_local_storage_helper_unittest.cc
+++ b/chrome/browser/browsing_data_local_storage_helper_unittest.cc
@@ -87,3 +87,18 @@ TEST(CannedBrowsingDataLocalStorageTest, Unique) {
ASSERT_EQ(1u, result.size());
EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value());
}
+
+TEST(CannedBrowsingDataLocalStorageTest, Empty) {
+ TestingProfile profile;
+
+ const GURL origin("http://host1:1/");
+
+ scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper =
+ new CannedBrowsingDataLocalStorageHelper(&profile);
+
+ ASSERT_TRUE(helper->empty());
+ helper->AddLocalStorage(origin);
+ ASSERT_FALSE(helper->empty());
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+}
diff --git a/chrome/browser/content_setting_bubble_model.cc b/chrome/browser/content_setting_bubble_model.cc
index 6c1c13b..8f83f02 100644
--- a/chrome/browser/content_setting_bubble_model.cc
+++ b/chrome/browser/content_setting_bubble_model.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
+#include "chrome/browser/tab_contents/tab_specific_content_settings.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
@@ -33,7 +34,7 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel {
private:
void SetTitle() {
- static const int kTitleIDs[] = {
+ static const int kBlockedTitleIDs[] = {
IDS_BLOCKED_COOKIES_TITLE,
IDS_BLOCKED_IMAGES_TITLE,
IDS_BLOCKED_JAVASCRIPT_TITLE,
@@ -42,10 +43,30 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel {
0, // Geolocation does not have an overall title.
0, // Notifications do not have a bubble.
};
- COMPILE_ASSERT(arraysize(kTitleIDs) == CONTENT_SETTINGS_NUM_TYPES,
+ static const int kAccessedTitleIDs[] = {
+ IDS_ACCESSED_COOKIES_TITLE,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ };
+ COMPILE_ASSERT(arraysize(kAccessedTitleIDs) == CONTENT_SETTINGS_NUM_TYPES,
+ Need_a_setting_for_every_content_settings_type);
+ COMPILE_ASSERT(arraysize(kBlockedTitleIDs) == CONTENT_SETTINGS_NUM_TYPES,
Need_a_setting_for_every_content_settings_type);
- if (kTitleIDs[content_type()])
- set_title(l10n_util::GetStringUTF8(kTitleIDs[content_type()]));
+ const int *title_ids = kBlockedTitleIDs;
+ if (tab_contents() &&
+ tab_contents()->GetTabSpecificContentSettings()->IsContentAccessed(
+ content_type()) &&
+ !tab_contents()->GetTabSpecificContentSettings()->IsContentBlocked(
+ content_type()) &&
+ !CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableCookiePrompt))
+ title_ids = kAccessedTitleIDs;
+ if (title_ids[content_type()])
+ set_title(l10n_util::GetStringUTF8(title_ids[content_type()]));
}
void SetManageLink() {
diff --git a/chrome/browser/content_setting_image_model.cc b/chrome/browser/content_setting_image_model.cc
index 26e349ac..e45aead 100644
--- a/chrome/browser/content_setting_image_model.cc
+++ b/chrome/browser/content_setting_image_model.cc
@@ -5,7 +5,11 @@
#include "chrome/browser/content_setting_image_model.h"
#include "app/l10n_util.h"
+#include "base/command_line.h"
+#include "chrome/browser/host_content_settings_map.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_switches.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -17,8 +21,10 @@ class ContentSettingBlockedImageModel : public ContentSettingImageModel {
virtual void UpdateFromTabContents(const TabContents* tab_contents);
private:
+ static const int kAccessedIconIDs[];
static const int kBlockedIconIDs[];
- static const int kTooltipIDs[];
+ static const int kAccessedTooltipIDs[];
+ static const int kBlockedTooltipIDs[];
};
class ContentSettingGeolocationImageModel : public ContentSettingImageModel {
@@ -43,14 +49,29 @@ const int ContentSettingBlockedImageModel::kBlockedIconIDs[] = {
IDR_BLOCKED_POPUPS,
};
-const int ContentSettingBlockedImageModel::kTooltipIDs[] = {
- IDS_BLOCKED_COOKIES_TITLE,
- IDS_BLOCKED_IMAGES_TITLE,
- IDS_BLOCKED_JAVASCRIPT_TITLE,
- IDS_BLOCKED_PLUGINS_TITLE,
- IDS_BLOCKED_POPUPS_TOOLTIP,
+const int ContentSettingBlockedImageModel::kAccessedIconIDs[] = {
+ IDR_ACCESSED_COOKIES,
+ 0,
+ 0,
+ 0,
+ 0,
};
+const int ContentSettingBlockedImageModel::kBlockedTooltipIDs[] = {
+ IDS_BLOCKED_COOKIES_TITLE,
+ IDS_BLOCKED_IMAGES_TITLE,
+ IDS_BLOCKED_JAVASCRIPT_TITLE,
+ IDS_BLOCKED_PLUGINS_TITLE,
+ IDS_BLOCKED_POPUPS_TOOLTIP,
+};
+
+const int ContentSettingBlockedImageModel::kAccessedTooltipIDs[] = {
+ IDS_ACCESSED_COOKIES_TITLE,
+ 0,
+ 0,
+ 0,
+ 0,
+};
ContentSettingBlockedImageModel::ContentSettingBlockedImageModel(
ContentSettingsType content_settings_type)
@@ -61,14 +82,33 @@ void ContentSettingBlockedImageModel::UpdateFromTabContents(
const TabContents* tab_contents) {
TabSpecificContentSettings* content_settings = tab_contents ?
tab_contents->GetTabSpecificContentSettings() : NULL;
- if (!content_settings ||
- !content_settings->IsContentBlocked(get_content_settings_type())) {
+ const int* icon_ids;
+ const int* tooltip_ids;
+
+ if (!content_settings) {
+ set_visible(false);
+ return;
+ }
+ if (content_settings->IsContentBlocked(get_content_settings_type())) {
+ icon_ids = kBlockedIconIDs;
+ tooltip_ids = kBlockedTooltipIDs;
+ } else if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableCookiePrompt) &&
+ tab_contents->profile()->GetHostContentSettingsMap()->
+ GetDefaultContentSetting(get_content_settings_type()) ==
+ CONTENT_SETTING_BLOCK &&
+ content_settings->IsContentAccessed(get_content_settings_type())) {
+ // If a content type is blocked by default and was accessed, display the
+ // accessed icon.
+ icon_ids = kAccessedIconIDs;
+ tooltip_ids = kAccessedTooltipIDs;
+ } else {
set_visible(false);
return;
}
- set_icon(kBlockedIconIDs[get_content_settings_type()]);
+ set_icon(icon_ids[get_content_settings_type()]);
set_tooltip(
- l10n_util::GetStringUTF8(kTooltipIDs[get_content_settings_type()]));
+ l10n_util::GetStringUTF8(tooltip_ids[get_content_settings_type()]));
set_visible(true);
}
diff --git a/chrome/browser/content_setting_image_model_unittest.cc b/chrome/browser/content_setting_image_model_unittest.cc
index 02a5af3..32aed3e 100644
--- a/chrome/browser/content_setting_image_model_unittest.cc
+++ b/chrome/browser/content_setting_image_model_unittest.cc
@@ -4,13 +4,25 @@
#include "chrome/browser/content_setting_image_model.h"
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
#include "chrome/browser/tab_contents/test_tab_contents.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
-typedef RenderViewHostTestHarness ContentSettingImageModelTest;
+class ContentSettingImageModelTest : public RenderViewHostTestHarness {
+ public:
+ ContentSettingImageModelTest()
+ : RenderViewHostTestHarness(),
+ ui_thread_(ChromeThread::UI, &message_loop_) {}
+
+ private:
+ ChromeThread ui_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentSettingImageModelTest);
+};
TEST_F(ContentSettingImageModelTest, UpdateFromTabContents) {
TestTabContents tab_contents(profile_.get(), NULL);
@@ -21,12 +33,32 @@ TEST_F(ContentSettingImageModelTest, UpdateFromTabContents) {
CONTENT_SETTINGS_TYPE_IMAGES));
EXPECT_FALSE(content_setting_image_model->is_visible());
EXPECT_EQ(0, content_setting_image_model->get_icon());
- EXPECT_EQ("", content_setting_image_model->get_tooltip());
+ EXPECT_EQ(std::string(), content_setting_image_model->get_tooltip());
content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES);
content_setting_image_model->UpdateFromTabContents(&tab_contents);
EXPECT_TRUE(content_setting_image_model->is_visible());
EXPECT_NE(0, content_setting_image_model->get_icon());
- EXPECT_NE("", content_setting_image_model->get_tooltip());
+ EXPECT_NE(std::string(), content_setting_image_model->get_tooltip());
+}
+
+TEST_F(ContentSettingImageModelTest, CookieAccessed) {
+ TestTabContents tab_contents(profile_.get(), NULL);
+ TabSpecificContentSettings* content_settings =
+ tab_contents.GetTabSpecificContentSettings();
+ profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
+ scoped_ptr<ContentSettingImageModel> content_setting_image_model(
+ ContentSettingImageModel::CreateContentSettingImageModel(
+ CONTENT_SETTINGS_TYPE_COOKIES));
+ EXPECT_FALSE(content_setting_image_model->is_visible());
+ EXPECT_EQ(0, content_setting_image_model->get_icon());
+ EXPECT_EQ(std::string(), content_setting_image_model->get_tooltip());
+
+ content_settings->OnCookieAccessed(GURL("http://google.com"), "A=B", false);
+ content_setting_image_model->UpdateFromTabContents(&tab_contents);
+ EXPECT_TRUE(content_setting_image_model->is_visible());
+ EXPECT_NE(0, content_setting_image_model->get_icon());
+ EXPECT_NE(std::string(), content_setting_image_model->get_tooltip());
}
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 2992612..57e29e1 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -2133,7 +2133,7 @@ void TabContents::DocumentLoadedInFrame() {
controller_.DocumentLoadedInFrame();
}
-void TabContents::OnContentSettingsChange() {
+void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
if (delegate_)
delegate_->OnContentSettingsChange(this);
}
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 3511b7c..f909591 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -815,8 +815,8 @@ class TabContents : public PageNavigator,
void GenerateKeywordIfNecessary(
const ViewHostMsg_FrameNavigate_Params& params);
- // ContentBlockedDelegate::Delegate implementation.
- virtual void OnContentSettingsChange();
+ // TabSpecificContentSettings::Delegate implementation.
+ virtual void OnContentSettingsAccessed(bool content_was_blocked);
// RenderViewHostDelegate ----------------------------------------------------
diff --git a/chrome/browser/tab_contents/tab_specific_content_settings.cc b/chrome/browser/tab_contents/tab_specific_content_settings.cc
index b09992c..f110317 100644
--- a/chrome/browser/tab_contents/tab_specific_content_settings.cc
+++ b/chrome/browser/tab_contents/tab_specific_content_settings.cc
@@ -11,6 +11,13 @@
#include "chrome/browser/cookies_tree_model.h"
#include "net/base/cookie_monster.h"
+bool TabSpecificContentSettings::LocalSharedObjectsContainer::empty() const {
+ return cookies_->GetAllCookies().empty() &&
+ appcaches_->empty() &&
+ databases_->empty() &&
+ local_storages_->empty();
+}
+
bool TabSpecificContentSettings::IsContentBlocked(
ContentSettingsType content_type) const {
DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
@@ -30,12 +37,21 @@ bool TabSpecificContentSettings::IsContentBlocked(
return false;
}
+bool TabSpecificContentSettings::IsContentAccessed(
+ ContentSettingsType content_type) const {
+ if (content_type != CONTENT_SETTINGS_TYPE_COOKIES)
+ return false;
+
+ return !allowed_local_shared_objects_.empty() ||
+ IsContentBlocked(content_type);
+}
+
void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) {
DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
<< "Geolocation settings handled by OnGeolocationPermissionSet";
content_blocked_[type] = true;
if (delegate_)
- delegate_->OnContentSettingsChange();
+ delegate_->OnContentSettingsAccessed(true);
}
void TabSpecificContentSettings::OnCookieAccessed(
@@ -49,6 +65,8 @@ void TabSpecificContentSettings::OnCookieAccessed(
} else {
allowed_local_shared_objects_.cookies()->SetCookieWithOptions(
url, cookie_line, options);
+ if (delegate_)
+ delegate_->OnContentSettingsAccessed(false);
}
}
@@ -59,6 +77,8 @@ void TabSpecificContentSettings::OnLocalStorageAccessed(
OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
} else {
allowed_local_shared_objects_.local_storages()->AddLocalStorage(url);
+ if (delegate_)
+ delegate_->OnContentSettingsAccessed(false);
}
}
@@ -75,6 +95,8 @@ void TabSpecificContentSettings::OnWebDatabaseAccessed(
} else {
allowed_local_shared_objects_.databases()->AddDatabase(
url, UTF16ToUTF8(name), UTF16ToUTF8(display_name));
+ if (delegate_)
+ delegate_->OnContentSettingsAccessed(false);
}
}
@@ -85,6 +107,8 @@ void TabSpecificContentSettings::OnAppCacheAccessed(
OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
} else {
allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url);
+ if (delegate_)
+ delegate_->OnContentSettingsAccessed(false);
}
}
@@ -94,7 +118,7 @@ void TabSpecificContentSettings::OnGeolocationPermissionSet(
geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
allowed);
if (delegate_)
- delegate_->OnContentSettingsChange();
+ delegate_->OnContentSettingsAccessed(!allowed);
}
TabSpecificContentSettings::TabSpecificContentSettings(
@@ -115,13 +139,13 @@ void TabSpecificContentSettings::ClearBlockedContentSettings() {
blocked_local_shared_objects_.Reset();
allowed_local_shared_objects_.Reset();
if (delegate_)
- delegate_->OnContentSettingsChange();
+ delegate_->OnContentSettingsAccessed(false);
}
void TabSpecificContentSettings::SetPopupsBlocked(bool blocked) {
content_blocked_[CONTENT_SETTINGS_TYPE_POPUPS] = blocked;
if (delegate_)
- delegate_->OnContentSettingsChange();
+ delegate_->OnContentSettingsAccessed(blocked);
}
void TabSpecificContentSettings::GeolocationDidNavigate(
diff --git a/chrome/browser/tab_contents/tab_specific_content_settings.h b/chrome/browser/tab_contents/tab_specific_content_settings.h
index 157976b..5613335 100644
--- a/chrome/browser/tab_contents/tab_specific_content_settings.h
+++ b/chrome/browser/tab_contents/tab_specific_content_settings.h
@@ -28,9 +28,12 @@ class TabSpecificContentSettings
public:
class Delegate {
public:
- // Invoked when content settings managed by the TabSpecificContentSettings
- // object change.
- virtual void OnContentSettingsChange() = 0;
+ // Invoked when content settings for resources in the tab contents
+ // associated with this TabSpecificContentSettings object were accessed.
+ // |content_was_blocked| is true, if a content settings type was blocked
+ // (as opposed to just accessed). Currently, this parameter is checked in
+ // unit tests only.
+ virtual void OnContentSettingsAccessed(bool content_was_blocked) = 0;
virtual ~Delegate() {}
};
@@ -53,6 +56,10 @@ class TabSpecificContentSettings
// page.
bool IsContentBlocked(ContentSettingsType content_type) const;
+ // Returns whether a particular kind of content has been accessed. Currently
+ // only tracks cookies.
+ bool IsContentAccessed(ContentSettingsType content_type) const;
+
// Returns the GeolocationSettingsState that controls the
// geolocation API usage on this page.
const GeolocationSettingsState& geolocation_settings_state() const {
@@ -108,6 +115,8 @@ class TabSpecificContentSettings
CookiesTreeModel* GetCookiesTreeModel();
+ bool empty() const;
+
private:
DISALLOW_COPY_AND_ASSIGN(LocalSharedObjectsContainer);
diff --git a/chrome/browser/tab_contents/tab_specific_content_settings_unittest.cc b/chrome/browser/tab_contents/tab_specific_content_settings_unittest.cc
index b89d772..6129f7d 100644
--- a/chrome/browser/tab_contents/tab_specific_content_settings_unittest.cc
+++ b/chrome/browser/tab_contents/tab_specific_content_settings_unittest.cc
@@ -11,18 +11,25 @@ namespace {
class TestContentSettingsDelegate
: public TabSpecificContentSettings::Delegate {
public:
- TestContentSettingsDelegate() : settings_changed_(false) {}
+ TestContentSettingsDelegate()
+ : settings_changed_(false), content_blocked_(false) {}
virtual ~TestContentSettingsDelegate() {}
- void Reset() { settings_changed_ = false; }
+ void Reset() { settings_changed_ = content_blocked_ = false; }
bool SettingsChanged() { return settings_changed_; }
+ bool ContentBlocked() { return content_blocked_; }
+
// TabSpecificContentSettings::Delegate implementation.
- virtual void OnContentSettingsChange() { settings_changed_ = true; }
+ virtual void OnContentSettingsAccessed(bool content_was_blocked) {
+ settings_changed_ = true;
+ content_blocked_ = content_was_blocked;
+ }
private:
bool settings_changed_;
+ bool content_blocked_;
DISALLOW_COPY_AND_ASSIGN(TestContentSettingsDelegate);
};
@@ -45,13 +52,16 @@ TEST(TabSpecificContentSettingsTest, BlockedContent) {
// Set a cookie, block access to images, block a popup.
content_settings.OnCookieAccessed(GURL("http://google.com"), "A=B", false);
- EXPECT_FALSE(test_delegate.SettingsChanged());
+ EXPECT_TRUE(test_delegate.SettingsChanged());
+ EXPECT_FALSE(test_delegate.ContentBlocked());
test_delegate.Reset();
content_settings.OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES);
EXPECT_TRUE(test_delegate.SettingsChanged());
+ EXPECT_TRUE(test_delegate.ContentBlocked());
test_delegate.Reset();
content_settings.SetPopupsBlocked(true);
EXPECT_TRUE(test_delegate.SettingsChanged());
+ EXPECT_TRUE(test_delegate.ContentBlocked());
test_delegate.Reset();
// Check that only the respective content types are affected.
@@ -67,6 +77,7 @@ TEST(TabSpecificContentSettingsTest, BlockedContent) {
// Reset blocked content settings.
content_settings.ClearBlockedContentSettings();
EXPECT_TRUE(test_delegate.SettingsChanged());
+ EXPECT_FALSE(test_delegate.ContentBlocked());
EXPECT_FALSE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES));
EXPECT_FALSE(
content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT));
@@ -76,3 +87,26 @@ TEST(TabSpecificContentSettingsTest, BlockedContent) {
content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
EXPECT_FALSE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS));
}
+
+TEST(TabSpecificContentSettingsTest, AllowedContent) {
+ TestContentSettingsDelegate test_delegate;
+ TestingProfile profile;
+ TabSpecificContentSettings content_settings(&test_delegate, &profile);
+
+ ASSERT_FALSE(
+ content_settings.IsContentAccessed(CONTENT_SETTINGS_TYPE_IMAGES));
+ ASSERT_FALSE(
+ content_settings.IsContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES));
+ ASSERT_FALSE(
+ content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
+ content_settings.OnCookieAccessed(GURL("http://google.com"), "A=B", false);
+ ASSERT_TRUE(
+ content_settings.IsContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES));
+ ASSERT_FALSE(
+ content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
+ content_settings.OnCookieAccessed(GURL("http://google.com"), "C=D", true);
+ ASSERT_TRUE(
+ content_settings.IsContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES));
+ ASSERT_TRUE(
+ content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
+}