summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-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.cc53
-rw-r--r--chrome/browser/tab_contents/tab_specific_content_settings.h20
-rw-r--r--chrome/browser/tab_contents/tab_specific_content_settings_unittest.cc42
18 files changed, 283 insertions, 37 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 7ff3689..6205b0a 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 66f9b79..f898318 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 f66e8d3..8373485 100644
--- a/chrome/browser/browsing_data_appcache_helper_unittest.cc
+++ b/chrome/browser/browsing_data_appcache_helper_unittest.cc
@@ -85,3 +85,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 fee1e0f..9b95ca5 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 051738a..5280dd8 100644
--- a/chrome/browser/browsing_data_database_helper_unittest.cc
+++ b/chrome/browser/browsing_data_database_helper_unittest.cc
@@ -92,3 +92,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 71c038c..23d68d3 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 8f3a9c6..fe110c3 100644
--- a/chrome/browser/browsing_data_local_storage_helper_unittest.cc
+++ b/chrome/browser/browsing_data_local_storage_helper_unittest.cc
@@ -86,3 +86,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 e73b37a..7fc7462 100644
--- a/chrome/browser/content_setting_bubble_model.cc
+++ b/chrome/browser/content_setting_bubble_model.cc
@@ -15,6 +15,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"
@@ -34,7 +35,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,
@@ -43,10 +44,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 076ced4..42f63db 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -2204,7 +2204,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 ac73e96..cba7367 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -819,8 +819,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 3447bcc..14a921e 100644
--- a/chrome/browser/tab_contents/tab_specific_content_settings.cc
+++ b/chrome/browser/tab_contents/tab_specific_content_settings.cc
@@ -11,6 +11,14 @@
#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() &&
+ session_storages_->empty();
+}
+
bool TabSpecificContentSettings::IsContentBlocked(
ContentSettingsType content_type) const {
DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
@@ -30,12 +38,34 @@ bool TabSpecificContentSettings::IsContentBlocked(
return false;
}
+bool TabSpecificContentSettings::IsContentAccessed(
+ ContentSettingsType content_type) const {
+ // This method currently only returns meaningful values for cookies.
+ if (content_type != CONTENT_SETTINGS_TYPE_COOKIES)
+ return false;
+
+ return content_accessed_[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();
+ content_accessed_[type] = true;
+ if (!content_blocked_[type]) {
+ content_blocked_[type] = true;
+ if (delegate_)
+ delegate_->OnContentSettingsAccessed(true);
+ }
+}
+
+void TabSpecificContentSettings::OnContentAccessed(ContentSettingsType type) {
+ DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
+ << "Geolocation settings handled by OnGeolocationPermissionSet";
+ if (!content_accessed_[type]) {
+ content_accessed_[type] = true;
+ if (delegate_)
+ delegate_->OnContentSettingsAccessed(false);
+ }
}
void TabSpecificContentSettings::OnCookieAccessed(
@@ -49,6 +79,7 @@ void TabSpecificContentSettings::OnCookieAccessed(
} else {
allowed_local_shared_objects_.cookies()->SetCookieWithOptions(
url, cookie_line, options);
+ OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
}
}
@@ -65,8 +96,8 @@ void TabSpecificContentSettings::OnLocalStorageAccessed(
if (blocked_by_policy)
OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
- else if (delegate_)
- delegate_->OnContentSettingsChange();
+ else
+ OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
}
void TabSpecificContentSettings::OnWebDatabaseAccessed(
@@ -82,6 +113,7 @@ void TabSpecificContentSettings::OnWebDatabaseAccessed(
} else {
allowed_local_shared_objects_.databases()->AddDatabase(
url, UTF16ToUTF8(name), UTF16ToUTF8(display_name));
+ OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
}
}
@@ -92,6 +124,7 @@ void TabSpecificContentSettings::OnAppCacheAccessed(
OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
} else {
allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url);
+ OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES);
}
}
@@ -101,7 +134,7 @@ void TabSpecificContentSettings::OnGeolocationPermissionSet(
geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
allowed);
if (delegate_)
- delegate_->OnContentSettingsChange();
+ delegate_->OnContentSettingsAccessed(!allowed);
}
TabSpecificContentSettings::TabSpecificContentSettings(
@@ -116,19 +149,21 @@ TabSpecificContentSettings::TabSpecificContentSettings(
}
void TabSpecificContentSettings::ClearBlockedContentSettings() {
- for (size_t i = 0; i < arraysize(content_blocked_); ++i)
+ for (size_t i = 0; i < arraysize(content_blocked_); ++i) {
content_blocked_[i] = false;
+ content_accessed_[i] = false;
+ }
load_plugins_link_enabled_ = true;
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 d1b77457..82976c4 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 {
@@ -113,6 +120,8 @@ class TabSpecificContentSettings
CookiesTreeModel* GetCookiesTreeModel();
+ bool empty() const;
+
private:
DISALLOW_COPY_AND_ASSIGN(LocalSharedObjectsContainer);
@@ -123,9 +132,14 @@ class TabSpecificContentSettings
scoped_refptr<CannedBrowsingDataLocalStorageHelper> session_storages_;
};
+ void OnContentAccessed(ContentSettingsType type);
+
// Stores which content setting types actually have blocked content.
bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
+ // Stores which content setting types actually were accessed.
+ bool content_accessed_[CONTENT_SETTINGS_NUM_TYPES];
+
// Stores the blocked/allowed cookies.
LocalSharedObjectsContainer allowed_local_shared_objects_;
LocalSharedObjectsContainer blocked_local_shared_objects_;
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));
+}