summaryrefslogtreecommitdiffstats
path: root/chrome/browser/content_settings
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-13 07:29:32 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-13 07:29:32 +0000
commit8093a5439afecec131b78422abdeb7038de6f7a3 (patch)
treea2f7dc196c51970186615d10d0a884e18c2b7ae9 /chrome/browser/content_settings
parent697a650a1084ef9c77f9c5675f891d6157f36e99 (diff)
downloadchromium_src-8093a5439afecec131b78422abdeb7038de6f7a3.zip
chromium_src-8093a5439afecec131b78422abdeb7038de6f7a3.tar.gz
chromium_src-8093a5439afecec131b78422abdeb7038de6f7a3.tar.bz2
Get rid of the remaining content settings code in the content module.
Add user data to content::ResourceContext that points to chrome's ProfileIOData. That way when the embedder code is called by content, it can get back to its profile specific data structures like HostContentSettingsMap. BUG=76793 Review URL: http://codereview.chromium.org/7014025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/content_settings')
-rw-r--r--chrome/browser/content_settings/tab_specific_content_settings.cc83
-rw-r--r--chrome/browser/content_settings/tab_specific_content_settings.h103
2 files changed, 147 insertions, 39 deletions
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc
index 5a3d49b..720bb60 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.cc
+++ b/chrome/browser/content_settings/tab_specific_content_settings.cc
@@ -12,12 +12,17 @@
#include "chrome/browser/browsing_data_database_helper.h"
#include "chrome/browser/browsing_data_indexed_db_helper.h"
#include "chrome/browser/browsing_data_local_storage_helper.h"
+#include "chrome/browser/content_settings/content_settings_details.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/cookies_tree_model.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/common/render_messages.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/tab_contents/tab_contents_delegate.h"
+#include "content/common/notification_service.h"
+#include "content/common/view_messages.h"
#include "net/base/cookie_monster.h"
namespace {
@@ -44,6 +49,9 @@ TabSpecificContentSettings::TabSpecificContentSettings(TabContents* tab)
ClearBlockedContentSettingsExceptForCookies();
ClearCookieSpecificContentSettings();
g_tab_specific.Get().push_back(this);
+
+ registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
+ NotificationService::AllSources());
}
TabSpecificContentSettings::~TabSpecificContentSettings() {
@@ -53,18 +61,44 @@ TabSpecificContentSettings::~TabSpecificContentSettings() {
TabSpecificContentSettings* TabSpecificContentSettings::Get(
int render_process_id, int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ RenderViewHost* view = RenderViewHost::FromID(
+ render_process_id, render_view_id);
+ if (!view)
+ return NULL;
+ // We loop through the tab contents and compare them with |view|, instead of
+ // getting the RVH from each tab contents and comparing its IDs because the
+ // latter will miss provisional RenderViewHosts.
for (TabSpecificList::iterator i = g_tab_specific.Get().begin();
i != g_tab_specific.Get().end(); ++i) {
- RenderViewHost* view = (*i)->tab_contents()->render_view_host();
- if (view->process()->id() == render_process_id &&
- view->routing_id() == render_view_id) {
- return (*i);
- }
+ if (view->delegate() == (*i)->tab_contents())
+ return (*i);
}
return NULL;
}
+void TabSpecificContentSettings::CookiesRead(int render_process_id,
+ int render_view_id,
+ const GURL& url,
+ const net::CookieList& cookie_list,
+ bool blocked_by_policy) {
+ TabSpecificContentSettings* settings = Get(render_process_id, render_view_id);
+ if (settings)
+ settings->OnCookiesRead(url, cookie_list, blocked_by_policy);
+}
+
+void TabSpecificContentSettings::CookieChanged(
+ int render_process_id,
+ int render_view_id,
+ const GURL& url,
+ const std::string& cookie_line,
+ const net::CookieOptions& options,
+ bool blocked_by_policy) {
+ TabSpecificContentSettings* settings = Get(render_process_id, render_view_id);
+ if (settings)
+ settings->OnCookieChanged(url, cookie_line, options, blocked_by_policy);
+}
+
void TabSpecificContentSettings::WebDatabaseAccessed(
int render_process_id,
int render_view_id,
@@ -338,6 +372,17 @@ CookiesTreeModel* TabSpecificContentSettings::GetBlockedCookiesTreeModel() {
return blocked_local_shared_objects_.GetCookiesTreeModel();
}
+bool TabSpecificContentSettings::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
void TabSpecificContentSettings::DidNavigateMainFramePostCommit(
const NavigationController::LoadCommittedDetails& details,
const ViewHostMsg_FrameNavigate_Params& params) {
@@ -352,7 +397,8 @@ void TabSpecificContentSettings::DidStartProvisionalLoadForFrame(
int64 frame_id,
bool is_main_frame,
const GURL& validated_url,
- bool is_error_page) {
+ bool is_error_page,
+ RenderViewHost* render_view_host) {
if (!is_main_frame)
return;
@@ -362,6 +408,31 @@ void TabSpecificContentSettings::DidStartProvisionalLoadForFrame(
if (!is_error_page)
ClearCookieSpecificContentSettings();
ClearGeolocationContentSettings();
+
+ HostContentSettingsMap* map =
+ tab_contents()->profile()->GetHostContentSettingsMap();
+ render_view_host->Send(new ViewMsg_SetContentSettingsForLoadingURL(
+ render_view_host->routing_id(), validated_url,
+ map->GetContentSettings(validated_url)));
+}
+
+void TabSpecificContentSettings::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type.value == NotificationType::CONTENT_SETTINGS_CHANGED);
+
+ Details<const ContentSettingsDetails> settings_details(details);
+ const NavigationController& controller = tab_contents()->controller();
+ NavigationEntry* entry = controller.GetActiveEntry();
+ GURL entry_url;
+ if (entry)
+ entry_url = entry->url();
+ if (settings_details.ptr()->update_all() ||
+ settings_details.ptr()->pattern().Matches(entry_url)) {
+ Send(new ViewMsg_SetContentSettingsForCurrentURL(
+ entry_url, tab_contents()->profile()->GetHostContentSettingsMap()->
+ GetContentSettings(entry_url)));
+ }
}
TabSpecificContentSettings::LocalSharedObjectsContainer::
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.h b/chrome/browser/content_settings/tab_specific_content_settings.h
index ddeaf58..f8924ea 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.h
+++ b/chrome/browser/content_settings/tab_specific_content_settings.h
@@ -10,9 +10,11 @@
#include "chrome/browser/geolocation/geolocation_settings_state.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"
-#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/tab_contents/navigation_controller.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
+#include "content/common/dom_storage_common.h"
+#include "content/common/notification_observer.h"
+#include "content/common/notification_registrar.h"
class CannedBrowsingDataAppCacheHelper;
class CannedBrowsingDataDatabaseHelper;
@@ -21,14 +23,16 @@ class CannedBrowsingDataLocalStorageHelper;
class CookiesTreeModel;
class TabContents;
class Profile;
+struct ContentSettings;
namespace net {
+class CookieList;
class CookieMonster;
+class CookieOptions;
}
-class TabSpecificContentSettings
- : public RenderViewHostDelegate::ContentSettings,
- public TabContentsObserver {
+class TabSpecificContentSettings : public TabContentsObserver,
+ public NotificationObserver {
public:
TabSpecificContentSettings(TabContents* tab);
@@ -39,6 +43,27 @@ class TabSpecificContentSettings
int render_view_id);
// Static methods called on the UI threads.
+ // Called when cookies for the given URL were read either from within the
+ // current page or while loading it. |blocked_by_policy| should be true, if
+ // reading cookies was blocked due to the user's content settings. In that
+ // case, this function should invoke OnContentBlocked.
+ static void CookiesRead(int render_process_id,
+ int render_view_id,
+ const GURL& url,
+ const net::CookieList& cookie_list,
+ bool blocked_by_policy);
+
+ // Called when a specific cookie in the current page was changed.
+ // |blocked_by_policy| should be true, if the cookie was blocked due to the
+ // user's content settings. In that case, this function should invoke
+ // OnContentBlocked.
+ static void CookieChanged(int render_process_id,
+ int render_view_id,
+ const GURL& url,
+ const std::string& cookie_line,
+ const net::CookieOptions& options,
+ bool blocked_by_policy);
+
// Called when a specific Web database in the current page was accessed. If
// access was blocked due to the user's content settings,
// |blocked_by_policy| should be true, and this function should invoke
@@ -120,39 +145,44 @@ class TabSpecificContentSettings
load_plugins_link_enabled_ = enabled;
}
- // RenderViewHostDelegate::ContentSettings implementation.
- virtual void OnContentBlocked(ContentSettingsType type,
- const std::string& resource_identifier);
- virtual void OnCookiesRead(const GURL& url,
- const net::CookieList& cookie_list,
- bool blocked_by_policy);
- virtual void OnCookieChanged(const GURL& url,
- const std::string& cookie_line,
- const net::CookieOptions& options,
- bool blocked_by_policy);
- virtual void OnIndexedDBAccessed(const GURL& url,
- const string16& description,
- bool blocked_by_policy);
- virtual void OnLocalStorageAccessed(const GURL& url,
- DOMStorageType storage_type,
- bool blocked_by_policy);
- virtual void OnWebDatabaseAccessed(const GURL& url,
- const string16& name,
- const string16& display_name,
- bool blocked_by_policy);
- virtual void OnAppCacheAccessed(const GURL& manifest_url,
- bool blocked_by_policy);
- virtual void OnGeolocationPermissionSet(const GURL& requesting_frame,
- bool allowed);
-
// TabContentsObserver overrides.
+ virtual bool OnMessageReceived(const IPC::Message& message);
virtual void DidNavigateMainFramePostCommit(
const NavigationController::LoadCommittedDetails& details,
const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE;
- virtual void DidStartProvisionalLoadForFrame(int64 frame_id,
- bool is_main_frame,
- const GURL& validated_url,
- bool is_error_page) OVERRIDE;
+ virtual void DidStartProvisionalLoadForFrame(
+ int64 frame_id,
+ bool is_main_frame,
+ const GURL& validated_url,
+ bool is_error_page,
+ RenderViewHost* render_view_host) OVERRIDE;
+
+ // Message handlers. Public for testing.
+ void OnContentBlocked(ContentSettingsType type,
+ const std::string& resource_identifier);
+ void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy);
+
+ // These methods are invoked on the UI thread by the static functions above.
+ // Public for testing.
+ void OnCookiesRead(const GURL& url,
+ const net::CookieList& cookie_list,
+ bool blocked_by_policy);
+ void OnCookieChanged(const GURL& url,
+ const std::string& cookie_line,
+ const net::CookieOptions& options,
+ bool blocked_by_policy);
+ void OnIndexedDBAccessed(const GURL& url,
+ const string16& description,
+ bool blocked_by_policy);
+ void OnLocalStorageAccessed(const GURL& url,
+ DOMStorageType storage_type,
+ bool blocked_by_policy);
+ void OnWebDatabaseAccessed(const GURL& url,
+ const string16& name,
+ const string16& display_name,
+ bool blocked_by_policy);
+ void OnGeolocationPermissionSet(const GURL& requesting_frame,
+ bool allowed);
private:
class LocalSharedObjectsContainer {
@@ -200,6 +230,11 @@ class TabSpecificContentSettings
void OnContentAccessed(ContentSettingsType type);
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
// Stores which content setting types actually have blocked content.
bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
@@ -224,6 +259,8 @@ class TabSpecificContentSettings
// Stores whether the user can load blocked plugins on this page.
bool load_plugins_link_enabled_;
+ NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettings);
};