diff options
26 files changed, 280 insertions, 230 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index e0a0899..5f3a3ab 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -8,6 +8,7 @@ #include "chrome/app/breakpad_mac.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/character_encoding.h" +#include "chrome/browser/chrome_worker_message_filter.h" #include "chrome/browser/debugger/devtools_handler.h" #include "chrome/browser/desktop_notification_handler.h" #include "chrome/browser/extensions/extension_message_handler.h" @@ -28,6 +29,7 @@ #include "content/browser/renderer_host/browser_render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/worker_host/worker_process_host.h" #if defined(OS_LINUX) #include "base/linux_util.h" @@ -77,6 +79,11 @@ void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( #endif } +void ChromeContentBrowserClient::WorkerProcessHostCreated( + WorkerProcessHost* host) { + host->AddFilter(new ChromeWorkerMessageFilter(host)); +} + content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() { return ChromeWebUIFactory::GetInstance(); } diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index faac34e..48ea5ab 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -17,6 +17,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { Profile* profile, const GURL& url); virtual void BrowserRenderProcessHostCreated(BrowserRenderProcessHost* host); + virtual void WorkerProcessHostCreated(WorkerProcessHost* host); virtual content::WebUIFactory* GetWebUIFactory(); virtual GURL GetEffectiveURL(Profile* profile, const GURL& url); virtual GURL GetAlternateErrorPageURL(const TabContents* tab); diff --git a/chrome/browser/chrome_worker_message_filter.cc b/chrome/browser/chrome_worker_message_filter.cc new file mode 100644 index 0000000..9e047ad --- /dev/null +++ b/chrome/browser/chrome_worker_message_filter.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chrome_worker_message_filter.h" + +#include "chrome/browser/content_settings/host_content_settings_map.h" +#include "content/browser/renderer_host/render_view_host_notification_task.h" +#include "content/browser/resource_context.h" +#include "content/browser/worker_host/worker_process_host.h" +#include "content/common/worker_messages.h" + +ChromeWorkerMessageFilter::ChromeWorkerMessageFilter(WorkerProcessHost* process) + : process_(process) { + host_content_settings_map_ = + process->resource_context()->host_content_settings_map(); +} + +ChromeWorkerMessageFilter::~ChromeWorkerMessageFilter() { +} + +bool ChromeWorkerMessageFilter::OnMessageReceived( + const IPC::Message& message, bool* message_was_ok) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(ChromeWorkerMessageFilter, message, *message_was_ok) + IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_AllowDatabase, OnAllowDatabase) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; +} + +bool ChromeWorkerMessageFilter::Send(IPC::Message* message) { + return process_->Send(message); +} + +void ChromeWorkerMessageFilter::OnAllowDatabase(int worker_route_id, + const GURL& url, + const string16& name, + const string16& display_name, + unsigned long estimated_size, + bool* result) { + ContentSetting content_setting = + host_content_settings_map_->GetContentSetting( + url, CONTENT_SETTINGS_TYPE_COOKIES, ""); + + *result = content_setting != CONTENT_SETTING_BLOCK; + + // Find the worker instance and forward the message to all attached documents. + WorkerProcessHost::Instances::const_iterator i; + for (i = process_->instances().begin(); i != process_->instances().end(); + ++i) { + if (i->worker_route_id() != worker_route_id) + continue; + const WorkerDocumentSet::DocumentInfoSet& documents = + i->worker_document_set()->documents(); + for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = + documents.begin(); doc != documents.end(); ++doc) { + CallRenderViewHostContentSettingsDelegate( + doc->render_process_id(), doc->render_view_id(), + &RenderViewHostDelegate::ContentSettings::OnWebDatabaseAccessed, + url, name, display_name, estimated_size, !*result); + } + break; + } +} diff --git a/chrome/browser/chrome_worker_message_filter.h b/chrome/browser/chrome_worker_message_filter.h new file mode 100644 index 0000000..a85231f --- /dev/null +++ b/chrome/browser/chrome_worker_message_filter.h @@ -0,0 +1,46 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROME_WORKER_MESSAGE_FILTER_H_ +#define CHROME_BROWSER_CHROME_WORKER_MESSAGE_FILTER_H_ +#pragma once + +#include "base/string16.h" +#include "ipc/ipc_channel_proxy.h" + +class GURL; +class HostContentSettingsMap; +class WorkerProcessHost; + +// This class filters out incoming Chrome-specific IPC messages for the renderer +// process on the IPC thread. +class ChromeWorkerMessageFilter : public IPC::ChannelProxy::MessageFilter, + public IPC::Message::Sender { + public: + explicit ChromeWorkerMessageFilter(WorkerProcessHost* process); + + // BrowserMessageFilter methods: + virtual bool OnMessageReceived(const IPC::Message& message, + bool* message_was_ok); + + // IPC::Message::Sender methods: + virtual bool Send(IPC::Message* message); + + private: + virtual ~ChromeWorkerMessageFilter(); + + void OnAllowDatabase(int worker_route_id, + const GURL& url, + const string16& name, + const string16& display_name, + unsigned long estimated_size, + bool* result); + + WorkerProcessHost* process_; + scoped_refptr<HostContentSettingsMap> host_content_settings_map_; + + DISALLOW_COPY_AND_ASSIGN(ChromeWorkerMessageFilter); +}; + +#endif // CHROME_BROWSER_CHROME_WORKER_MESSAGE_FILTER_H_ diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc index f628fa3..6a90556 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.cc +++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc @@ -7,6 +7,7 @@ #include "base/file_path.h" #include "base/metrics/histogram.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/extensions/extension_event_router.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/metrics/histogram_synchronizer.h" @@ -43,6 +44,7 @@ ChromeRenderMessageFilter::ChromeRenderMessageFilter( always_authorize_plugins_.Init(prefs::kPluginsAlwaysAuthorize, profile_->GetPrefs(), NULL); always_authorize_plugins_.MoveToThread(BrowserThread::IO); + host_content_settings_map_ = profile->GetHostContentSettingsMap(); } ChromeRenderMessageFilter::~ChromeRenderMessageFilter() { @@ -71,6 +73,7 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message, #endif IPC_MESSAGE_HANDLER(ViewHostMsg_GetPluginPolicies, OnGetPluginPolicies) + IPC_MESSAGE_HANDLER(ViewHostMsg_AllowDatabase, OnAllowDatabase) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -294,3 +297,18 @@ void ChromeRenderMessageFilter::OnGetPluginPolicies( *authorize_policy = always_authorize_plugins_.GetValue() ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_ASK; } + +void ChromeRenderMessageFilter::OnAllowDatabase(const std::string& origin_url, + const string16& name, + const string16& display_name, + unsigned long estimated_size, + bool* result) { + GURL url(origin_url); + ContentSetting content_setting = + host_content_settings_map_->GetContentSetting( + url, CONTENT_SETTINGS_TYPE_COOKIES, ""); + DCHECK((content_setting == CONTENT_SETTING_ALLOW) || + (content_setting == CONTENT_SETTING_BLOCK) || + (content_setting == CONTENT_SETTING_SESSION_ONLY)); + *result = content_setting != CONTENT_SETTING_BLOCK; +} diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h index c07ee00..68fb08c 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.h +++ b/chrome/browser/renderer_host/chrome_render_message_filter.h @@ -12,6 +12,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" class FilePath; +class HostContentSettingsMap; class Profile; namespace net { @@ -81,6 +82,11 @@ class ChromeRenderMessageFilter : public BrowserMessageFilter { #endif void OnGetPluginPolicies(ContentSetting* outdated_policy, ContentSetting* authorize_policy); + void OnAllowDatabase(const std::string& origin_url, + const string16& name, + const string16& display_name, + unsigned long estimated_size, + bool* result); int render_process_id_; @@ -88,6 +94,8 @@ class ChromeRenderMessageFilter : public BrowserMessageFilter { // accessed on the UI thread! Profile* profile_; scoped_refptr<net::URLRequestContextGetter> request_context_; + // Used to look up permissions at database creation time. + scoped_refptr<HostContentSettingsMap> host_content_settings_map_; BooleanPrefMember allow_outdated_plugins_; BooleanPrefMember always_authorize_plugins_; diff --git a/chrome/browser/tab_contents/tab_specific_content_settings.cc b/chrome/browser/tab_contents/tab_specific_content_settings.cc index 113d528..623f9ac 100644 --- a/chrome/browser/tab_contents/tab_specific_content_settings.cc +++ b/chrome/browser/tab_contents/tab_specific_content_settings.cc @@ -10,6 +10,9 @@ #include "chrome/browser/browsing_data_indexed_db_helper.h" #include "chrome/browser/browsing_data_local_storage_helper.h" #include "chrome/browser/cookies_tree_model.h" +#include "chrome/common/render_messages.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_delegate.h" #include "net/base/cookie_monster.h" bool TabSpecificContentSettings::LocalSharedObjectsContainer::empty() const { @@ -88,8 +91,9 @@ void TabSpecificContentSettings::OnContentBlocked( AddBlockedResource(type, resource_identifier); if (!content_blocked_[type]) { content_blocked_[type] = true; - if (delegate_) - delegate_->OnContentSettingsAccessed(true); + // TODO: it would be nice to have a way of mocking this in tests. + if (tab_contents()->delegate()) + tab_contents()->delegate()->OnContentSettingsChange(tab_contents()); } } @@ -98,8 +102,8 @@ void TabSpecificContentSettings::OnContentAccessed(ContentSettingsType type) { << "Geolocation settings handled by OnGeolocationPermissionSet"; if (!content_accessed_[type]) { content_accessed_[type] = true; - if (delegate_) - delegate_->OnContentSettingsAccessed(false); + if (tab_contents()->delegate()) + tab_contents()->delegate()->OnContentSettingsChange(tab_contents()); } } @@ -210,20 +214,18 @@ void TabSpecificContentSettings::OnGeolocationPermissionSet( bool allowed) { geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin, allowed); - if (delegate_) - delegate_->OnContentSettingsAccessed(!allowed); + if (tab_contents()->delegate()) + tab_contents()->delegate()->OnContentSettingsChange(tab_contents()); } -TabSpecificContentSettings::TabSpecificContentSettings( - Delegate* delegate, Profile* profile) - : allowed_local_shared_objects_(profile), - blocked_local_shared_objects_(profile), - geolocation_settings_state_(profile), - load_plugins_link_enabled_(true), - delegate_(NULL) { +TabSpecificContentSettings::TabSpecificContentSettings(TabContents* tab) + : TabContentsObserver(tab), + allowed_local_shared_objects_(tab->profile()), + blocked_local_shared_objects_(tab->profile()), + geolocation_settings_state_(tab->profile()), + load_plugins_link_enabled_(true) { ClearBlockedContentSettingsExceptForCookies(); ClearCookieSpecificContentSettings(); - delegate_ = delegate; } void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { @@ -236,8 +238,8 @@ void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { content_blockage_indicated_to_user_[i] = false; } load_plugins_link_enabled_ = true; - if (delegate_) - delegate_->OnContentSettingsAccessed(false); + if (tab_contents()->delegate()) + tab_contents()->delegate()->OnContentSettingsChange(tab_contents()); } void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { @@ -246,15 +248,15 @@ void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { content_blocked_[CONTENT_SETTINGS_TYPE_COOKIES] = false; content_accessed_[CONTENT_SETTINGS_TYPE_COOKIES] = false; content_blockage_indicated_to_user_[CONTENT_SETTINGS_TYPE_COOKIES] = false; - if (delegate_) - delegate_->OnContentSettingsAccessed(false); + if (tab_contents()->delegate()) + tab_contents()->delegate()->OnContentSettingsChange(tab_contents()); } void TabSpecificContentSettings::SetPopupsBlocked(bool blocked) { content_blocked_[CONTENT_SETTINGS_TYPE_POPUPS] = blocked; content_blockage_indicated_to_user_[CONTENT_SETTINGS_TYPE_POPUPS] = false; - if (delegate_) - delegate_->OnContentSettingsAccessed(blocked); + if (tab_contents()->delegate()) + tab_contents()->delegate()->OnContentSettingsChange(tab_contents()); } void TabSpecificContentSettings::GeolocationDidNavigate( @@ -274,6 +276,43 @@ 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_WebDatabaseAccessed, OnWebDatabaseAccessed) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; +} + +void TabSpecificContentSettings::DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { + if (!details.is_in_page) { + // Clear "blocked" flags. + ClearBlockedContentSettingsExceptForCookies(); + GeolocationDidNavigate(details); + } +} + +void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( + int64 frame_id, + bool is_main_frame, + const GURL& validated_url, + bool is_error_page) { + if (!is_main_frame) + return; + + // If we're displaying a network error page do not reset the content + // settings delegate's cookies so the user has a chance to modify cookie + // settings. + if (!is_error_page) + ClearCookieSpecificContentSettings(); + ClearGeolocationContentSettings(); +} + TabSpecificContentSettings::LocalSharedObjectsContainer:: LocalSharedObjectsContainer(Profile* profile) : cookies_(new net::CookieMonster(NULL, NULL)), diff --git a/chrome/browser/tab_contents/tab_specific_content_settings.h b/chrome/browser/tab_contents/tab_specific_content_settings.h index 24337bd..82d0631 100644 --- a/chrome/browser/tab_contents/tab_specific_content_settings.h +++ b/chrome/browser/tab_contents/tab_specific_content_settings.h @@ -12,12 +12,14 @@ #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" class CannedBrowsingDataAppCacheHelper; class CannedBrowsingDataDatabaseHelper; class CannedBrowsingDataIndexedDBHelper; class CannedBrowsingDataLocalStorageHelper; class CookiesTreeModel; +class TabContents; class Profile; namespace net { @@ -25,21 +27,10 @@ class CookieMonster; } class TabSpecificContentSettings - : public RenderViewHostDelegate::ContentSettings { + : public RenderViewHostDelegate::ContentSettings, + public TabContentsObserver { public: - class Delegate { - public: - // 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() {} - }; - - TabSpecificContentSettings(Delegate* delegate, Profile* profile); + TabSpecificContentSettings(TabContents* tab); virtual ~TabSpecificContentSettings() {} @@ -119,6 +110,16 @@ class TabSpecificContentSettings virtual void OnGeolocationPermissionSet(const GURL& requesting_frame, bool allowed); + // TabContentsObserver overrides. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + 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; + private: class LocalSharedObjectsContainer { public: @@ -189,8 +190,6 @@ class TabSpecificContentSettings // Stores whether the user can load blocked plugins on this page. bool load_plugins_link_enabled_; - Delegate* delegate_; - DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettings); }; 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 61fdcfe..967567a 100644 --- a/chrome/browser/tab_contents/tab_specific_content_settings_unittest.cc +++ b/chrome/browser/tab_contents/tab_specific_content_settings_unittest.cc @@ -3,43 +3,22 @@ // found in the LICENSE file. #include "chrome/browser/tab_contents/tab_specific_content_settings.h" - #include "chrome/test/testing_profile.h" +#include "content/browser/renderer_host/test_render_view_host.h" +#include "content/browser/tab_contents/test_tab_contents.h" #include "net/base/cookie_monster.h" #include "testing/gtest/include/gtest/gtest.h" -namespace { -class TestContentSettingsDelegate - : public TabSpecificContentSettings::Delegate { +class TabSpecificContentSettingsTest : public RenderViewHostTestHarness { public: - TestContentSettingsDelegate() - : settings_changed_(false), content_blocked_(false) {} - virtual ~TestContentSettingsDelegate() {} - - void Reset() { settings_changed_ = content_blocked_ = false; } - - bool SettingsChanged() { return settings_changed_; } - - bool ContentBlocked() { return content_blocked_; } - - // TabSpecificContentSettings::Delegate implementation. - virtual void OnContentSettingsAccessed(bool content_was_blocked) { - settings_changed_ = true; - content_blocked_ = content_was_blocked; - } + TabSpecificContentSettingsTest() : RenderViewHostTestHarness() {} private: - bool settings_changed_; - bool content_blocked_; - - DISALLOW_COPY_AND_ASSIGN(TestContentSettingsDelegate); + DISALLOW_COPY_AND_ASSIGN(TabSpecificContentSettingsTest); }; -} // namespace -TEST(TabSpecificContentSettingsTest, BlockedContent) { - TestContentSettingsDelegate test_delegate; - TestingProfile profile; - TabSpecificContentSettings content_settings(&test_delegate, &profile); +TEST_F(TabSpecificContentSettingsTest, BlockedContent) { + TabSpecificContentSettings content_settings(contents()); net::CookieOptions options; // Check that after initializing, nothing is blocked. @@ -55,18 +34,9 @@ TEST(TabSpecificContentSettingsTest, BlockedContent) { // Set a cookie, block access to images, block a popup. content_settings.OnCookieChanged( GURL("http://google.com"), "A=B", options, false); - EXPECT_TRUE(test_delegate.SettingsChanged()); - EXPECT_FALSE(test_delegate.ContentBlocked()); - test_delegate.Reset(); content_settings.OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); - 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. EXPECT_TRUE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); @@ -88,8 +58,6 @@ TEST(TabSpecificContentSettingsTest, BlockedContent) { // Reset blocked content settings. content_settings.ClearBlockedContentSettingsExceptForCookies(); - 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)); @@ -100,8 +68,6 @@ TEST(TabSpecificContentSettingsTest, BlockedContent) { EXPECT_FALSE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS)); content_settings.ClearCookieSpecificContentSettings(); - 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)); @@ -112,10 +78,8 @@ TEST(TabSpecificContentSettingsTest, BlockedContent) { EXPECT_FALSE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS)); } -TEST(TabSpecificContentSettingsTest, AllowedContent) { - TestContentSettingsDelegate test_delegate; - TestingProfile profile; - TabSpecificContentSettings content_settings(&test_delegate, &profile); +TEST_F(TabSpecificContentSettingsTest, AllowedContent) { + TabSpecificContentSettings content_settings(contents()); net::CookieOptions options; ASSERT_FALSE( @@ -138,10 +102,8 @@ TEST(TabSpecificContentSettingsTest, AllowedContent) { content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); } -TEST(TabSpecificContentSettingsTest, EmptyCookieList) { - TestContentSettingsDelegate test_delegate; - TestingProfile profile; - TabSpecificContentSettings content_settings(&test_delegate, &profile); +TEST_F(TabSpecificContentSettingsTest, EmptyCookieList) { + TabSpecificContentSettings content_settings(contents()); ASSERT_FALSE( content_settings.IsContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES)); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ec3c1d7..83cf57a 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -340,6 +340,8 @@ 'browser/chrome_browser_application_mac.mm', 'browser/chrome_content_browser_client.cc', 'browser/chrome_content_browser_client.h', + 'browser/chrome_worker_message_filter.cc', + 'browser/chrome_worker_message_filter.h', 'browser/chromeos/audio_handler.cc', 'browser/chromeos/audio_handler.h', 'browser/chromeos/audio_mixer.h', diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 50c0c1d..5416fed 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -296,6 +296,24 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_ContentBlocked, ContentSettingsType, /* type of blocked content */ std::string /* resource identifier */) +// Sent by the renderer process to check whether access to web databases is +// granted by content settings. This may block and trigger a cookie prompt. +IPC_SYNC_MESSAGE_ROUTED4_1(ViewHostMsg_AllowDatabase, + std::string /* origin_url */, + string16 /* database name */, + string16 /* database display name */, + unsigned long /* estimated size */, + bool /* result */) + +// Tells the browser that a specific Web database in the current page was +// accessed. +IPC_MESSAGE_ROUTED5(ViewHostMsg_WebDatabaseAccessed, + GURL /* origin url */, + string16 /* database name */, + string16 /* database display name */, + unsigned long /* estimated size */, + bool /* blocked by policy */) + // Specifies the URL as the first parameter (a wstring) and thumbnail as // binary data as the second parameter. IPC_MESSAGE_ROUTED3(ViewHostMsg_Thumbnail, diff --git a/chrome/renderer/content_settings_observer.cc b/chrome/renderer/content_settings_observer.cc index d81c1f9..f8769e2 100644 --- a/chrome/renderer/content_settings_observer.cc +++ b/chrome/renderer/content_settings_observer.cc @@ -140,7 +140,7 @@ bool ContentSettingsObserver::AllowDatabase(WebFrame* frame, return false; // Uninitialized document? bool result; - if (!Send(new DatabaseHostMsg_Allow(routing_id(), + if (!Send(new ViewHostMsg_AllowDatabase(routing_id(), origin.toString().utf8(), name, display_name, estimated_size, &result))) return false; Send(new ViewHostMsg_WebDatabaseAccessed(routing_id(), diff --git a/content/browser/content_browser_client.cc b/content/browser/content_browser_client.cc index 973dc02..9cb40e8 100644 --- a/content/browser/content_browser_client.cc +++ b/content/browser/content_browser_client.cc @@ -22,6 +22,10 @@ void ContentBrowserClient::PreCreateRenderView(RenderViewHost* render_view_host, void ContentBrowserClient::BrowserRenderProcessHostCreated( BrowserRenderProcessHost* host) { } + +void ContentBrowserClient::WorkerProcessHostCreated(WorkerProcessHost* host) { +} + WebUIFactory* ContentBrowserClient::GetWebUIFactory() { // Return an empty factory so callsites don't have to check for NULL. return EmptyWebUIFactory::Get(); diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h index abb654f..2bc9537 100644 --- a/content/browser/content_browser_client.h +++ b/content/browser/content_browser_client.h @@ -16,6 +16,7 @@ class GURL; class Profile; class RenderViewHost; class TabContents; +class WorkerProcessHost; namespace content { @@ -35,6 +36,9 @@ class ContentBrowserClient { // Notifies that a BrowserRenderProcessHost has been created. virtual void BrowserRenderProcessHostCreated(BrowserRenderProcessHost* host); + // Notifies that a WorkerProcessHost has been created. + virtual void WorkerProcessHostCreated(WorkerProcessHost* host); + // Gets the WebUIFactory which will be responsible for generating WebUIs. virtual WebUIFactory* GetWebUIFactory(); diff --git a/content/browser/renderer_host/browser_render_process_host.cc b/content/browser/renderer_host/browser_render_process_host.cc index 406e7fd..93d1817 100644 --- a/content/browser/renderer_host/browser_render_process_host.cc +++ b/content/browser/renderer_host/browser_render_process_host.cc @@ -379,7 +379,7 @@ void BrowserRenderProcessHost::CreateMessageFilters() { channel_->AddFilter(new FileUtilitiesMessageFilter(id())); channel_->AddFilter(new MimeRegistryMessageFilter()); channel_->AddFilter(new DatabaseMessageFilter( - profile()->GetDatabaseTracker(), profile()->GetHostContentSettingsMap())); + profile()->GetDatabaseTracker())); SocketStreamDispatcherHost* socket_stream_dispatcher_host = new SocketStreamDispatcherHost( diff --git a/content/browser/renderer_host/database_message_filter.cc b/content/browser/renderer_host/database_message_filter.cc index edb3839..fe0c9a0 100644 --- a/content/browser/renderer_host/database_message_filter.cc +++ b/content/browser/renderer_host/database_message_filter.cc @@ -8,7 +8,6 @@ #include "base/string_util.h" #include "base/threading/thread.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" #include "content/browser/user_metrics.h" #include "content/common/database_messages.h" #include "content/common/result_codes.h" @@ -31,11 +30,9 @@ const int kNumDeleteRetries = 2; const int kDelayDeleteRetryMs = 100; DatabaseMessageFilter::DatabaseMessageFilter( - webkit_database::DatabaseTracker* db_tracker, - HostContentSettingsMap *host_content_settings_map) + webkit_database::DatabaseTracker* db_tracker) : db_tracker_(db_tracker), - observer_added_(false), - host_content_settings_map_(host_content_settings_map) { + observer_added_(false) { DCHECK(db_tracker_); } @@ -68,10 +65,8 @@ void DatabaseMessageFilter::RemoveObserver() { void DatabaseMessageFilter::OverrideThreadForMessage( const IPC::Message& message, BrowserThread::ID* thread) { - if (IPC_MESSAGE_CLASS(message) == DatabaseMsgStart && - message.type() != DatabaseHostMsg_Allow::ID) { + if (IPC_MESSAGE_CLASS(message) == DatabaseMsgStart) *thread = BrowserThread::FILE; - } if (message.type() == DatabaseHostMsg_OpenFile::ID && !observer_added_) { observer_added_ = true; @@ -97,7 +92,6 @@ bool DatabaseMessageFilter::OnMessageReceived( IPC_MESSAGE_HANDLER(DatabaseHostMsg_Opened, OnDatabaseOpened) IPC_MESSAGE_HANDLER(DatabaseHostMsg_Modified, OnDatabaseModified) IPC_MESSAGE_HANDLER(DatabaseHostMsg_Closed, OnDatabaseClosed) - IPC_MESSAGE_HANDLER(DatabaseHostMsg_Allow, OnAllowDatabase) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() return handled; @@ -280,21 +274,6 @@ void DatabaseMessageFilter::OnDatabaseClosed(const string16& origin_identifier, database_connections_.RemoveConnection(origin_identifier, database_name); } -void DatabaseMessageFilter::OnAllowDatabase(const std::string& origin_url, - const string16& name, - const string16& display_name, - unsigned long estimated_size, - bool* result) { - GURL url = GURL(origin_url); - ContentSetting content_setting = - host_content_settings_map_->GetContentSetting( - url, CONTENT_SETTINGS_TYPE_COOKIES, ""); - DCHECK((content_setting == CONTENT_SETTING_ALLOW) || - (content_setting == CONTENT_SETTING_BLOCK) || - (content_setting == CONTENT_SETTING_SESSION_ONLY)); - *result = content_setting != CONTENT_SETTING_BLOCK;; -} - void DatabaseMessageFilter::OnDatabaseSizeChanged( const string16& origin_identifier, const string16& database_name, diff --git a/content/browser/renderer_host/database_message_filter.h b/content/browser/renderer_host/database_message_filter.h index 59731cf..9d14d32 100644 --- a/content/browser/renderer_host/database_message_filter.h +++ b/content/browser/renderer_host/database_message_filter.h @@ -13,15 +13,11 @@ #include "webkit/database/database_connections.h" #include "webkit/database/database_tracker.h" -class HostContentSettingsMap; - class DatabaseMessageFilter : public BrowserMessageFilter, public webkit_database::DatabaseTracker::Observer { public: - DatabaseMessageFilter( - webkit_database::DatabaseTracker* db_tracker, - HostContentSettingsMap *host_content_settings_map); + explicit DatabaseMessageFilter(webkit_database::DatabaseTracker* db_tracker); // BrowserMessageFilter implementation. virtual void OnChannelClosing(); @@ -63,11 +59,6 @@ class DatabaseMessageFilter const string16& database_name); void OnDatabaseClosed(const string16& origin_identifier, const string16& database_name); - void OnAllowDatabase(const std::string& origin_url, - const string16& name, - const string16& display_name, - unsigned long estimated_size, - bool* result); // DatabaseTracker::Observer callbacks (file thread) virtual void OnDatabaseSizeChanged(const string16& origin_identifier, @@ -91,9 +82,6 @@ class DatabaseMessageFilter // Keeps track of all DB connections opened by this renderer webkit_database::DatabaseConnections database_connections_; - - // Used to look up permissions at database creation time. - scoped_refptr<HostContentSettingsMap> host_content_settings_map_; }; #endif // CONTENT_BROWSER_RENDERER_HOST_DATABASE_MESSAGE_FILTER_H_ diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index 216cedb..47e5457 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -734,7 +734,6 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted) IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked) IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) - IPC_MESSAGE_HANDLER(ViewHostMsg_WebDatabaseAccessed, OnWebDatabaseAccessed) IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnMsgFocusedNodeChanged) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptEvalResponse, OnScriptEvalResponse) @@ -1376,18 +1375,6 @@ void RenderViewHost::OnAppCacheAccessed(const GURL& manifest_url, blocked_by_policy); } -void RenderViewHost::OnWebDatabaseAccessed(const GURL& url, - const string16& name, - const string16& display_name, - unsigned long estimated_size, - bool blocked_by_policy) { - RenderViewHostDelegate::ContentSettings* content_settings_delegate = - delegate_->GetContentSettingsDelegate(); - if (content_settings_delegate) - content_settings_delegate->OnWebDatabaseAccessed( - url, name, display_name, estimated_size, blocked_by_policy); -} - void RenderViewHost::OnUpdateZoomLimits(int minimum_percent, int maximum_percent, bool remember) { diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h index e383c14..bfd7bf85 100644 --- a/content/browser/renderer_host/render_view_host.h +++ b/content/browser/renderer_host/render_view_host.h @@ -523,11 +523,6 @@ class RenderViewHost : public RenderWidgetHost { void OnContentBlocked(ContentSettingsType type, const std::string& resource_identifier); void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy); - void OnWebDatabaseAccessed(const GURL& url, - const string16& name, - const string16& display_name, - unsigned long estimated_size, - bool blocked_by_policy); void OnUpdateZoomLimits(int minimum_percent, int maximum_percent, bool remember); diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 18da991..ef94e78 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -245,9 +245,6 @@ TabContents::TabContents(Profile* profile, renderer_preferences_util::UpdateFromSystemSettings( &renderer_preferences_, profile); - content_settings_delegate_.reset( - new TabSpecificContentSettings(this, profile)); - render_manager_.Init(profile, site_instance, routing_id); // We have the initial size of the view be based on the size of the passed in @@ -345,6 +342,7 @@ TabContents::~TabContents() { } void TabContents::AddObservers() { + content_settings_delegate_.reset(new TabSpecificContentSettings(this)); favicon_tab_helper_.reset(new FaviconTabHelper(this)); plugin_observer_.reset(new PluginObserver(this)); net::NetworkChangeNotifier::AddOnlineStateObserver(this); @@ -1105,13 +1103,6 @@ void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, validated_url, is_error_page)); if (is_main_frame) { - // If we're displaying a network error page do not reset the content - // settings delegate's cookies so the user has a chance to modify cookie - // settings. - if (!is_error_page) - content_settings_delegate_->ClearCookieSpecificContentSettings(); - content_settings_delegate_->ClearGeolocationContentSettings(); - // Notify observers about the provisional change in the main frame URL. FOR_EACH_OBSERVER(TabContentsObserver, observers_, ProvisionalChangeToMainFrameUrl(url)); @@ -1384,13 +1375,7 @@ void TabContents::DidNavigateMainFramePostCommit( // Get the favicon, either from history or request it from the net. favicon_tab_helper_->FetchFavicon(details.entry->url()); - // Clear all page actions, blocked content notifications and browser actions - // for this tab, unless this is an in-page navigation. if (!details.is_in_page) { - // Clear "blocked" flags. - content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies(); - content_settings_delegate_->GeolocationDidNavigate(details); - // Once the main frame is navigated, we're no longer considered to have // displayed insecure content. displayed_insecure_content_ = false; @@ -1580,11 +1565,6 @@ void TabContents::OnGoToEntryAtOffset(int offset) { } } -void TabContents::OnContentSettingsAccessed(bool content_was_blocked) { - if (delegate_) - delegate_->OnContentSettingsChange(this); -} - RenderViewHostDelegate::View* TabContents::GetViewDelegate() { return view_.get(); } diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index f49ddc7..9dc47a6 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -75,7 +75,6 @@ class TabContents : public PageNavigator, public RenderViewHostDelegate, public RenderViewHostManager::Delegate, public JavaScriptAppModalDialogDelegate, - public TabSpecificContentSettings::Delegate, public net::NetworkChangeNotifier::OnlineStateObserver { public: // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it @@ -738,9 +737,6 @@ class TabContents : public PageNavigator, void NotifyConnected(); void NotifyDisconnected(); - // TabSpecificContentSettings::Delegate implementation. - virtual void OnContentSettingsAccessed(bool content_was_blocked); - // RenderViewHostDelegate ---------------------------------------------------- // RenderViewHostDelegate implementation. diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc index 27a45178..f6a805a 100644 --- a/content/browser/worker_host/worker_process_host.cc +++ b/content/browser/worker_host/worker_process_host.cc @@ -12,11 +12,11 @@ #include "base/message_loop.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/extensions/extension_info_map.h" #include "content/browser/appcache/appcache_dispatcher_host.h" #include "content/browser/browser_thread.h" #include "content/browser/child_process_security_policy.h" +#include "content/browser/content_browser_client.h" #include "content/browser/file_system/file_system_dispatcher_host.h" #include "content/browser/mime_registry_message_filter.h" #include "content/browser/renderer_host/blob_message_filter.h" @@ -24,7 +24,6 @@ #include "content/browser/renderer_host/file_utilities_message_filter.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_view_host_delegate.h" -#include "content/browser/renderer_host/render_view_host_notification_task.h" #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" #include "content/browser/resource_context.h" #include "content/browser/user_metrics.h" @@ -204,6 +203,8 @@ bool WorkerProcessHost::Init(int render_process_id) { CreateMessageFilters(render_process_id); + content::GetContentClient()->browser()->WorkerProcessHostCreated(this); + return true; } @@ -235,8 +236,7 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) { new BlobMessageFilter(id(), resource_context_->blob_storage_context())); AddFilter(new MimeRegistryMessageFilter()); AddFilter(new DatabaseMessageFilter( - resource_context_->database_tracker(), - resource_context_->host_content_settings_map())); + resource_context_->database_tracker())); SocketStreamDispatcherHost* socket_stream_dispatcher_host = new SocketStreamDispatcherHost( @@ -293,7 +293,6 @@ bool WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) IPC_MESSAGE_HANDLER(WorkerHostMsg_WorkerContextClosed, OnWorkerContextClosed) - IPC_MESSAGE_HANDLER(WorkerProcessHostMsg_AllowDatabase, OnAllowDatabase) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() @@ -339,35 +338,6 @@ void WorkerProcessHost::OnWorkerContextClosed(int worker_route_id) { } } -void WorkerProcessHost::OnAllowDatabase(int worker_route_id, - const GURL& url, - const string16& name, - const string16& display_name, - unsigned long estimated_size, - bool* result) { - ContentSetting content_setting = resource_context_-> - host_content_settings_map()->GetContentSetting( - url, CONTENT_SETTINGS_TYPE_COOKIES, ""); - - *result = content_setting != CONTENT_SETTING_BLOCK; - - // Find the worker instance and forward the message to all attached documents. - for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { - if (i->worker_route_id() != worker_route_id) - continue; - const WorkerDocumentSet::DocumentInfoSet& documents = - i->worker_document_set()->documents(); - for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = - documents.begin(); doc != documents.end(); ++doc) { - CallRenderViewHostContentSettingsDelegate( - doc->render_process_id(), doc->render_view_id(), - &RenderViewHostDelegate::ContentSettings::OnWebDatabaseAccessed, - url, name, display_name, estimated_size, !*result); - } - break; - } -} - void WorkerProcessHost::RelayMessage( const IPC::Message& message, WorkerMessageFilter* filter, diff --git a/content/browser/worker_host/worker_process_host.h b/content/browser/worker_host/worker_process_host.h index 00005aa..720e217 100644 --- a/content/browser/worker_host/worker_process_host.h +++ b/content/browser/worker_host/worker_process_host.h @@ -138,11 +138,16 @@ class WorkerProcessHost : public BrowserChildProcessHost { void DocumentDetached(WorkerMessageFilter* filter, unsigned long long document_id); + typedef std::list<WorkerInstance> Instances; + const Instances& instances() const { return instances_; } + + const content::ResourceContext* resource_context() const { + return resource_context_; + } + protected: friend class WorkerService; - typedef std::list<WorkerInstance> Instances; - const Instances& instances() const { return instances_; } Instances& mutable_instances() { return instances_; } private: @@ -157,12 +162,6 @@ class WorkerProcessHost : public BrowserChildProcessHost { virtual bool OnMessageReceived(const IPC::Message& message); void OnWorkerContextClosed(int worker_route_id); - void OnAllowDatabase(int worker_route_id, - const GURL& url, - const string16& name, - const string16& display_name, - unsigned long estimated_size, - bool* result); // Relays a message to the given endpoint. Takes care of parsing the message // if it contains a message port and sending it a valid route id. diff --git a/content/common/child_process_host.h b/content/common/child_process_host.h index bb15134..8faf0e6 100644 --- a/content/common/child_process_host.h +++ b/content/common/child_process_host.h @@ -60,12 +60,12 @@ class ChildProcessHost : public IPC::Channel::Listener, // IPC::Message::Sender implementation. virtual bool Send(IPC::Message* message); - protected: - ChildProcessHost(); - // Adds an IPC message filter. A reference will be kept to the filter. void AddFilter(IPC::ChannelProxy::MessageFilter* filter); + protected: + ChildProcessHost(); + // Derived classes return true if it's ok to shut down the child process. virtual bool CanShutdown() = 0; diff --git a/content/common/database_messages.h b/content/common/database_messages.h index 4645b7a..f8d2d18 100644 --- a/content/common/database_messages.h +++ b/content/common/database_messages.h @@ -26,15 +26,6 @@ IPC_MESSAGE_CONTROL2(DatabaseMsg_CloseImmediately, // Database messages sent from the renderer to the browser. -// Sent by the renderer process to check whether access to web databases is -// granted by content settings. This may block and trigger a cookie prompt. -IPC_SYNC_MESSAGE_ROUTED4_1(DatabaseHostMsg_Allow, - std::string /* origin_url */, - string16 /* database name */, - string16 /* database display name */, - unsigned long /* estimated size */, - bool /* result */) - // Asks the browser process to open a DB file with the given name. IPC_SYNC_MESSAGE_CONTROL2_1(DatabaseHostMsg_OpenFile, string16 /* vfs file name */, diff --git a/content/common/view_messages.h b/content/common/view_messages.h index ea324b7..6953964 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -1572,15 +1572,6 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_AppCacheAccessed, GURL /* manifest url */, bool /* blocked by policy */) -// Tells the browser that a specific Web database in the current page was -// accessed. -IPC_MESSAGE_ROUTED5(ViewHostMsg_WebDatabaseAccessed, - GURL /* origin url */, - string16 /* database name */, - string16 /* database display name */, - unsigned long /* estimated size */, - bool /* blocked by policy */) - // Initiates a download based on user actions like 'ALT+click'. IPC_MESSAGE_ROUTED2(ViewHostMsg_DownloadUrl, GURL /* url */, |