diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-04 01:47:49 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-04 01:47:49 +0000 |
commit | bac33eb460f7c94be8d30613ea8ed8804d63d23d (patch) | |
tree | 4f78120f455c86ff734f018a67b542668a17e302 /content | |
parent | ec0800709c0aec729385fe4dce1f9ee578b061c8 (diff) | |
download | chromium_src-bac33eb460f7c94be8d30613ea8ed8804d63d23d.zip chromium_src-bac33eb460f7c94be8d30613ea8ed8804d63d23d.tar.gz chromium_src-bac33eb460f7c94be8d30613ea8ed8804d63d23d.tar.bz2 |
Chrome side to allow WebKit layer to use WebPermissionClient to check if access to local storage is allowed.
Review URL: http://codereview.chromium.org/6915017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
13 files changed, 49 insertions, 77 deletions
diff --git a/content/browser/in_process_webkit/dom_storage_area.cc b/content/browser/in_process_webkit/dom_storage_area.cc index 8d6c89f..ea0b3d9 100644 --- a/content/browser/in_process_webkit/dom_storage_area.cc +++ b/content/browser/in_process_webkit/dom_storage_area.cc @@ -5,7 +5,6 @@ #include "content/browser/in_process_webkit/dom_storage_area.h" #include "base/task.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" #include "content/browser/in_process_webkit/dom_storage_context.h" #include "content/browser/in_process_webkit/dom_storage_namespace.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" @@ -22,15 +21,12 @@ using WebKit::WebURL; DOMStorageArea::DOMStorageArea( const string16& origin, int64 id, - DOMStorageNamespace* owner, - HostContentSettingsMap* host_content_settings_map) + DOMStorageNamespace* owner) : origin_(origin), origin_url_(origin), id_(id), - owner_(owner), - host_content_settings_map_(host_content_settings_map) { + owner_(owner) { DCHECK(owner_); - DCHECK(host_content_settings_map_); } DOMStorageArea::~DOMStorageArea() { @@ -54,11 +50,6 @@ NullableString16 DOMStorageArea::GetItem(const string16& key) { NullableString16 DOMStorageArea::SetItem( const string16& key, const string16& value, WebStorageArea::Result* result) { - if (!CheckContentSetting(key, value)) { - *result = WebStorageArea::ResultBlockedByPolicy; - return NullableString16(true); // Ignored if the content was blocked. - } - CreateWebStorageAreaIfNecessary(); WebString old_value; storage_area_->setItem(key, value, WebURL(), *result, old_value); @@ -87,11 +78,3 @@ void DOMStorageArea::CreateWebStorageAreaIfNecessary() { if (!storage_area_.get()) storage_area_.reset(owner_->CreateWebStorageArea(origin_)); } - -bool DOMStorageArea::CheckContentSetting( - const string16& key, const string16& value) { - ContentSetting content_setting = - host_content_settings_map_->GetContentSetting( - origin_url_, CONTENT_SETTINGS_TYPE_COOKIES, ""); - return (content_setting != CONTENT_SETTING_BLOCK); -} diff --git a/content/browser/in_process_webkit/dom_storage_area.h b/content/browser/in_process_webkit/dom_storage_area.h index 00bb0db..a663ee0 100644 --- a/content/browser/in_process_webkit/dom_storage_area.h +++ b/content/browser/in_process_webkit/dom_storage_area.h @@ -16,16 +16,13 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" class DOMStorageNamespace; -class HostContentSettingsMap; - // Only use on the WebKit thread. DOMStorageNamespace manages our registration // with DOMStorageContext. class DOMStorageArea { public: DOMStorageArea(const string16& origin, int64 id, - DOMStorageNamespace* owner, - HostContentSettingsMap* host_content_settings_map); + DOMStorageNamespace* owner); ~DOMStorageArea(); unsigned Length(); @@ -46,9 +43,6 @@ class DOMStorageArea { // Creates the underlying WebStorageArea on demand. void CreateWebStorageAreaIfNecessary(); - // Used to see if setItem has permission to do its thing. - bool CheckContentSetting(const string16& key, const string16& value); - // The origin this storage area represents. string16 origin_; GURL origin_url_; @@ -62,8 +56,6 @@ class DOMStorageArea { // The DOMStorageNamespace that owns us. DOMStorageNamespace* owner_; - scoped_refptr<HostContentSettingsMap> host_content_settings_map_; - DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageArea); }; diff --git a/content/browser/in_process_webkit/dom_storage_message_filter.cc b/content/browser/in_process_webkit/dom_storage_message_filter.cc index 8cb1875..93a8828 100644 --- a/content/browser/in_process_webkit/dom_storage_message_filter.cc +++ b/content/browser/in_process_webkit/dom_storage_message_filter.cc @@ -9,7 +9,6 @@ #include "content/browser/in_process_webkit/dom_storage_area.h" #include "content/browser/in_process_webkit/dom_storage_context.h" #include "content/browser/in_process_webkit/dom_storage_namespace.h" -#include "content/browser/renderer_host/render_view_host_notification_task.h" #include "content/common/dom_storage_messages.h" #include "googleurl/src/gurl.h" @@ -41,11 +40,9 @@ ScopedStorageEventContext::~ScopedStorageEventContext() { } DOMStorageMessageFilter::DOMStorageMessageFilter( - int process_id, WebKitContext* webkit_context, - HostContentSettingsMap* host_content_settings_map) + int process_id, WebKitContext* webkit_context) : webkit_context_(webkit_context), - process_id_(process_id), - host_content_settings_map_(host_content_settings_map) { + process_id_(process_id) { } DOMStorageMessageFilter::~DOMStorageMessageFilter() { @@ -121,8 +118,7 @@ void DOMStorageMessageFilter::OnStorageAreaId(int64 namespace_id, *storage_area_id = DOMStorageContext::kInvalidStorageId; return; } - DOMStorageArea* storage_area = storage_namespace->GetStorageArea( - origin, host_content_settings_map_); + DOMStorageArea* storage_area = storage_namespace->GetStorageArea(origin); *storage_area_id = storage_area->id(); } @@ -174,17 +170,6 @@ void DOMStorageMessageFilter::OnSetItem( ScopedStorageEventContext scope(this, &url); *old_value = storage_area->SetItem(key, value, result); - - // If content was blocked, tell the UI to display the blocked content icon. - if (render_view_id == MSG_ROUTING_CONTROL) { - DLOG(WARNING) << "setItem was not given a proper routing id"; - } else { - CallRenderViewHostContentSettingsDelegate( - process_id_, render_view_id, - &RenderViewHostDelegate::ContentSettings::OnLocalStorageAccessed, - url, storage_area->owner()->dom_storage_type(), - *result == WebStorageArea::ResultBlockedByPolicy); - } } void DOMStorageMessageFilter::OnRemoveItem( diff --git a/content/browser/in_process_webkit/dom_storage_message_filter.h b/content/browser/in_process_webkit/dom_storage_message_filter.h index 3ccd1e40..e994d98 100644 --- a/content/browser/in_process_webkit/dom_storage_message_filter.h +++ b/content/browser/in_process_webkit/dom_storage_message_filter.h @@ -9,7 +9,6 @@ #include "base/memory/ref_counted.h" #include "base/process.h" #include "base/tracked.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" #include "content/browser/browser_message_filter.h" #include "content/browser/in_process_webkit/dom_storage_area.h" #include "content/browser/in_process_webkit/webkit_context.h" @@ -25,8 +24,7 @@ struct DOMStorageMsg_Event_Params; class DOMStorageMessageFilter : public BrowserMessageFilter { public: // Only call the constructor from the UI thread. - DOMStorageMessageFilter(int process_id, WebKitContext* webkit_context, - HostContentSettingsMap* host_content_settings_map); + DOMStorageMessageFilter(int process_id, WebKitContext* webkit_context); // BrowserMessageFilter implementation virtual void OnChannelConnected(int32 peer_pid); @@ -88,8 +86,6 @@ class DOMStorageMessageFilter : public BrowserMessageFilter { // Used to dispatch messages to the correct view host. int process_id_; - scoped_refptr<HostContentSettingsMap> host_content_settings_map_; - DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageMessageFilter); }; diff --git a/content/browser/in_process_webkit/dom_storage_namespace.cc b/content/browser/in_process_webkit/dom_storage_namespace.cc index 6cfccf8c..508786f 100644 --- a/content/browser/in_process_webkit/dom_storage_namespace.cc +++ b/content/browser/in_process_webkit/dom_storage_namespace.cc @@ -54,9 +54,7 @@ DOMStorageNamespace::~DOMStorageNamespace() { } } -DOMStorageArea* DOMStorageNamespace::GetStorageArea( - const string16& origin, - HostContentSettingsMap* host_content_settings_map) { +DOMStorageArea* DOMStorageNamespace::GetStorageArea(const string16& origin) { // We may have already created it for another dispatcher host. OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); if (iter != origin_to_storage_area_.end()) @@ -65,8 +63,7 @@ DOMStorageArea* DOMStorageNamespace::GetStorageArea( // We need to create a new one. int64 id = dom_storage_context_->AllocateStorageAreaId(); DCHECK(!dom_storage_context_->GetStorageArea(id)); - DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this, - host_content_settings_map); + DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); origin_to_storage_area_[origin] = storage_area; dom_storage_context_->RegisterStorageArea(storage_area); return storage_area; diff --git a/content/browser/in_process_webkit/dom_storage_namespace.h b/content/browser/in_process_webkit/dom_storage_namespace.h index a8142c7..1a6f124 100644 --- a/content/browser/in_process_webkit/dom_storage_namespace.h +++ b/content/browser/in_process_webkit/dom_storage_namespace.h @@ -15,7 +15,6 @@ class DOMStorageArea; class DOMStorageContext; class FilePath; -class HostContentSettingsMap; namespace WebKit { class WebStorageArea; @@ -32,8 +31,7 @@ class DOMStorageNamespace { ~DOMStorageNamespace(); - DOMStorageArea* GetStorageArea(const string16& origin, - HostContentSettingsMap* map); + DOMStorageArea* GetStorageArea(const string16& origin); DOMStorageNamespace* Copy(int64 clone_namespace_id); void PurgeMemory(); diff --git a/content/browser/renderer_host/browser_render_process_host.cc b/content/browser/renderer_host/browser_render_process_host.cc index 2c69680..d422775 100644 --- a/content/browser/renderer_host/browser_render_process_host.cc +++ b/content/browser/renderer_host/browser_render_process_host.cc @@ -357,8 +357,7 @@ void BrowserRenderProcessHost::CreateMessageFilters() { new AppCacheDispatcherHost(&profile()->GetResourceContext(), id())); channel_->AddFilter(new ClipboardMessageFilter()); channel_->AddFilter( - new DOMStorageMessageFilter(id(), profile()->GetWebKitContext(), - profile()->GetHostContentSettingsMap())); + new DOMStorageMessageFilter(id(), profile()->GetWebKitContext())); channel_->AddFilter( new IndexedDBDispatcherHost(id(), profile()->GetWebKitContext(), profile()->GetHostContentSettingsMap())); diff --git a/content/common/common_param_traits.h b/content/common/common_param_traits.h index 41e0326..077d734 100644 --- a/content/common/common_param_traits.h +++ b/content/common/common_param_traits.h @@ -16,6 +16,7 @@ #include "base/memory/ref_counted.h" #include "base/platform_file.h" +#include "content/common/dom_storage_common.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_message_utils.h" #include "net/base/ip_endpoint.h" @@ -109,11 +110,6 @@ struct ParamTraits<base::PlatformFileInfo> { }; template <> -struct SimilarTypeTraits<base::PlatformFileError> { - typedef int Type; -}; - -template <> struct ParamTraits<gfx::Point> { typedef gfx::Point param_type; static void Write(Message* m, const param_type& p); @@ -229,6 +225,16 @@ struct ParamTraits<SkBitmap> { static void Log(const param_type& p, std::string* l); }; +template <> +struct SimilarTypeTraits<base::PlatformFileError> { + typedef int Type; +}; + +template <> +struct SimilarTypeTraits<DOMStorageType> { + typedef int Type; +}; + } // namespace IPC #endif // CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ diff --git a/content/common/dom_storage_messages.h b/content/common/dom_storage_messages.h index 9d656f6..77169ce 100644 --- a/content/common/dom_storage_messages.h +++ b/content/common/dom_storage_messages.h @@ -3,7 +3,7 @@ // found in the LICENSE file. // Multiply-included message file, no traditional include guard. -#include "content/common/dom_storage_common.h" +#include "content/common/common_param_traits.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_param_traits.h" @@ -32,7 +32,6 @@ IPC_STRUCT_BEGIN(DOMStorageMsg_Event_Params) IPC_STRUCT_MEMBER(DOMStorageType, storage_type) IPC_STRUCT_END() -IPC_ENUM_TRAITS(DOMStorageType) IPC_ENUM_TRAITS(WebKit::WebStorageArea::Result) // DOM Storage messages sent from the browser to the renderer. diff --git a/content/renderer/DEPS b/content/renderer/DEPS index 4d577da..92d3df3 100644 --- a/content/renderer/DEPS +++ b/content/renderer/DEPS @@ -1,5 +1,6 @@ include_rules = [
"-chrome",
+ "+chrome/renderer/content_settings_observer.h", # TODO(jam): remove after merge!
"+chrome/test",
"+content/plugin", # For shared npruntime proxying code.
"+third_party/mach_override",
diff --git a/content/renderer/renderer_webstoragearea_impl.cc b/content/renderer/renderer_webstoragearea_impl.cc index 6ff0a70..4f9a5c6 100644 --- a/content/renderer/renderer_webstoragearea_impl.cc +++ b/content/renderer/renderer_webstoragearea_impl.cc @@ -4,6 +4,9 @@ #include "content/renderer/renderer_webstoragearea_impl.h" +// TODO(jam): temporary include until webkit merge +#include "chrome/renderer/content_settings_observer.h" + #include "content/common/dom_storage_messages.h" #include "content/renderer/render_thread.h" #include "content/renderer/render_view.h" @@ -17,7 +20,8 @@ using WebKit::WebURL; using WebKit::WebView; RendererWebStorageAreaImpl::RendererWebStorageAreaImpl( - int64 namespace_id, const WebString& origin) { + int64 namespace_id, const WebString& origin, DOMStorageType storage_type) + : storage_type_(storage_type) { RenderThread::current()->Send( new DOMStorageHostMsg_StorageAreaId(namespace_id, origin, &storage_area_id_)); @@ -54,17 +58,25 @@ void RendererWebStorageAreaImpl::setItem( int32 render_view_id = MSG_ROUTING_CONTROL; if (web_frame) { RenderView* render_view = RenderView::FromWebView(web_frame->view()); - if (render_view) + if (render_view) { render_view_id = render_view->routing_id(); + + // TODO(jam): remove after merge + ContentSettingsObserver* content_setting = + ContentSettingsObserver::Get(render_view); + if (!content_setting->AllowStorage( + web_frame, storage_type_ == DOM_STORAGE_LOCAL)) { + result = WebStorageArea::ResultBlockedByQuota; + old_value_webkit = NullableString16(); + return; + } + } } DCHECK(render_view_id != MSG_ROUTING_CONTROL); NullableString16 old_value; - IPC::SyncMessage* message = - new DOMStorageHostMsg_SetItem(render_view_id, storage_area_id_, key, - value, url, &result, &old_value); - // NOTE: This may pump events (see RenderThread::Send). - RenderThread::current()->Send(message); + RenderThread::current()->Send(new DOMStorageHostMsg_SetItem( + render_view_id, storage_area_id_, key, value, url, &result, &old_value)); old_value_webkit = old_value; } diff --git a/content/renderer/renderer_webstoragearea_impl.h b/content/renderer/renderer_webstoragearea_impl.h index dba539e..743f59a33 100644 --- a/content/renderer/renderer_webstoragearea_impl.h +++ b/content/renderer/renderer_webstoragearea_impl.h @@ -7,13 +7,15 @@ #pragma once #include "base/basictypes.h" +#include "content/common/dom_storage_common.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" class RendererWebStorageAreaImpl : public WebKit::WebStorageArea { public: RendererWebStorageAreaImpl(int64 namespace_id, - const WebKit::WebString& origin); + const WebKit::WebString& origin, + DOMStorageType storage_type); virtual ~RendererWebStorageAreaImpl(); // See WebStorageArea.h for documentation on these functions. @@ -32,6 +34,8 @@ class RendererWebStorageAreaImpl : public WebKit::WebStorageArea { private: // The ID we use for all IPC. int64 storage_area_id_; + + const DOMStorageType storage_type_; }; #endif // CONTENT_RENDERER_RENDERER_WEBSTORAGEAREA_IMPL_H_ diff --git a/content/renderer/renderer_webstoragenamespace_impl.cc b/content/renderer/renderer_webstoragenamespace_impl.cc index 25278be..c344c4a 100644 --- a/content/renderer/renderer_webstoragenamespace_impl.cc +++ b/content/renderer/renderer_webstoragenamespace_impl.cc @@ -34,7 +34,7 @@ WebStorageArea* RendererWebStorageNamespaceImpl::createStorageArea( // this doesn't seem practical because there's no good way to ref-count these // objects, and it'd be unclear who owned them. So, instead, we'll pay the // price in terms of wasted memory. - return new RendererWebStorageAreaImpl(namespace_id_, origin); + return new RendererWebStorageAreaImpl(namespace_id_, origin, storage_type_); } WebStorageNamespace* RendererWebStorageNamespaceImpl::copy() { |