diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-18 17:00:15 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-18 17:00:15 +0000 |
commit | 5e56df8fb10f7aca72c51184ea66e4d5462d31e3 (patch) | |
tree | d49606d0e1af4ec568dfa8f03c778c7ae0780d06 /chrome/renderer/content_settings_observer.h | |
parent | f3f4d7fc63d2e686208de341e01c559a2f0a4487 (diff) | |
download | chromium_src-5e56df8fb10f7aca72c51184ea66e4d5462d31e3.zip chromium_src-5e56df8fb10f7aca72c51184ea66e4d5462d31e3.tar.gz chromium_src-5e56df8fb10f7aca72c51184ea66e4d5462d31e3.tar.bz2 |
Move the content settings code out of RenderView, since it belongs in the Chrome layer.
BUG=76793
Review URL: http://codereview.chromium.org/6873040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81955 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/content_settings_observer.h')
-rw-r--r-- | chrome/renderer/content_settings_observer.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/chrome/renderer/content_settings_observer.h b/chrome/renderer/content_settings_observer.h new file mode 100644 index 0000000..52d89f5 --- /dev/null +++ b/chrome/renderer/content_settings_observer.h @@ -0,0 +1,74 @@ +// 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_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ +#define CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ +#pragma once + +#include <map> + +#include "chrome/common/content_settings.h" +#include "content/renderer/render_view_observer.h" +#include "content/renderer/render_view_observer_tracker.h" + +class GURL; + +// Handles blocking content per content settings for each RenderView. +class ContentSettingsObserver + : public RenderViewObserver, + public RenderViewObserverTracker<ContentSettingsObserver> { + public: + explicit ContentSettingsObserver(RenderView* render_view); + virtual ~ContentSettingsObserver(); + + // Sets the content settings that back allowScripts(), allowImages(), and + // allowPlugins(). + void SetContentSettings(const ContentSettings& settings); + + // Returns the setting for the given type. + ContentSetting GetContentSetting(ContentSettingsType type); + + // Sends an IPC notification that the specified content type was blocked. + // If the content type requires it, |resource_identifier| names the specific + // resource that was blocked (the plugin path in the case of plugins), + // otherwise it's the empty string. + void DidBlockContentType(ContentSettingsType settings_type, + const std::string& resource_identifier); + + private: + // RenderViewObserver implementation. + virtual bool OnMessageReceived(const IPC::Message& message); + virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, + bool is_new_navigation); + virtual bool AllowImages(WebKit::WebFrame* frame, bool enabled_per_settings); + virtual bool AllowPlugins(WebKit::WebFrame* frame, bool enabled_per_settings); + virtual bool AllowScript(WebKit::WebFrame* frame, bool enabled_per_settings); + virtual void DidNotAllowPlugins(WebKit::WebFrame* frame); + virtual void DidNotAllowScript(WebKit::WebFrame* frame); + + // Message handlers. + void OnSetContentSettingsForLoadingURL( + const GURL& url, + const ContentSettings& content_settings); + + // Helper method that returns if the user wants to block content of type + // |content_type|. + bool AllowContentType(ContentSettingsType settings_type); + + // Resets the |content_blocked_| array. + void ClearBlockedContentSettings(); + + typedef std::map<GURL, ContentSettings> HostContentSettings; + HostContentSettings host_content_settings_; + + // Stores if loading of images, scripts, and plugins is allowed. + ContentSettings current_content_settings_; + + // Stores if images, scripts, and plugins have actually been blocked. + bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; + + DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); +}; + +#endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ |