#ifndef CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_
#define CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_
#include <map>
#include <set>
#include "chrome/common/content_settings.h"
#include "content/public/renderer/render_view_observer.h"
#include "content/public/renderer/render_view_observer_tracker.h"
class GURL;
namespace WebKit {
class WebFrame;
class WebSecurityOrigin;
class WebURL;
}
class ContentSettingsObserver
: public content::RenderViewObserver,
public content::RenderViewObserverTracker<ContentSettingsObserver> {
public:
explicit ContentSettingsObserver(content::RenderView* render_view);
virtual ~ContentSettingsObserver();
void SetContentSettingRules(
const RendererContentSettingRules* content_setting_rules);
bool IsPluginTemporarilyAllowed(const std::string& identifier);
void DidBlockContentType(ContentSettingsType settings_type,
const std::string& resource_identifier);
bool AllowDatabase(WebKit::WebFrame* frame,
const WebKit::WebString& name,
const WebKit::WebString& display_name,
unsigned long estimated_size);
bool AllowFileSystem(WebKit::WebFrame* frame);
bool AllowImage(WebKit::WebFrame* frame,
bool enabled_per_settings,
const WebKit::WebURL& image_url);
bool AllowIndexedDB(WebKit::WebFrame* frame,
const WebKit::WebString& name,
const WebKit::WebSecurityOrigin& origin);
bool AllowPlugins(WebKit::WebFrame* frame, bool enabled_per_settings);
bool AllowScript(WebKit::WebFrame* frame, bool enabled_per_settings);
bool AllowScriptFromSource(WebKit::WebFrame* frame, bool enabled_per_settings,
const WebKit::WebURL& script_url);
bool AllowStorage(WebKit::WebFrame* frame, bool local);
void DidNotAllowPlugins();
void DidNotAllowScript();
void DidNotAllowMixedScript();
private:
FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes);
FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest,
ContentSettingsInterstitialPages);
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
bool is_new_navigation) OVERRIDE;
void OnLoadBlockedPlugins(const std::string& identifier);
void OnSetAsInterstitial();
void ClearBlockedContentSettings();
static bool IsWhitelistedForContentSettings(WebKit::WebFrame* frame);
static bool IsWhitelistedForContentSettings(
const WebKit::WebSecurityOrigin& origin,
const GURL& document_url);
const RendererContentSettingRules* content_setting_rules_;
bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
typedef std::pair<GURL, bool> StoragePermissionsKey;
std::map<StoragePermissionsKey, bool> cached_storage_permissions_;
std::map<WebKit::WebFrame*, bool> cached_script_permissions_;
std::set<std::string> temporarily_allowed_plugins_;
bool is_interstitial_page_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver);
};
#endif