| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ | 5 #ifndef CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ |
| 6 #define CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ | 6 #define CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "chrome/common/content_settings.h" | 11 #include "chrome/common/content_settings.h" |
| 12 #include "content/public/renderer/render_view_observer.h" | 12 #include "content/public/renderer/render_view_observer.h" |
| 13 #include "content/public/renderer/render_view_observer_tracker.h" | 13 #include "content/public/renderer/render_view_observer_tracker.h" |
| 14 | 14 |
| 15 class GURL; | 15 class GURL; |
| 16 | 16 |
| 17 namespace WebKit { | 17 namespace WebKit { |
| 18 class WebSecurityOrigin; | 18 class WebSecurityOrigin; |
| 19 class WebURL; | 19 class WebURL; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // Handles blocking content per content settings for each RenderView. | 22 // Handles blocking content per content settings for each RenderView. |
| 23 class ContentSettingsObserver | 23 class ContentSettingsObserver |
| 24 : public content::RenderViewObserver, | 24 : public content::RenderViewObserver, |
| 25 public content::RenderViewObserverTracker<ContentSettingsObserver> { | 25 public content::RenderViewObserverTracker<ContentSettingsObserver> { |
| 26 public: | 26 public: |
| 27 explicit ContentSettingsObserver(content::RenderView* render_view); | 27 explicit ContentSettingsObserver(content::RenderView* render_view); |
| 28 virtual ~ContentSettingsObserver(); | 28 virtual ~ContentSettingsObserver(); |
| 29 | 29 |
| 30 // Sets the content settings that back allowScripts() and allowPlugins(). | |
| 31 void SetContentSettings(const ContentSettings& settings); | |
| 32 | |
| 33 // Sets the default content settings that back allowScripts() and | |
| 34 // allowPlugins(). | |
| 35 void SetDefaultContentSettings(const ContentSettings* settings); | |
| 36 | |
| 37 // Sets the content setting rules which back |AllowImage()|, |AllowScript()|, | 30 // Sets the content setting rules which back |AllowImage()|, |AllowScript()|, |
| 38 // and |AllowScriptFromSource()|. |content_setting_rules| must outlive this | 31 // and |AllowScriptFromSource()|. |content_setting_rules| must outlive this |
| 39 // |ContentSettingsObserver|. | 32 // |ContentSettingsObserver|. |
| 40 void SetContentSettingRules( | 33 void SetContentSettingRules( |
| 41 const RendererContentSettingRules* content_setting_rules); | 34 const RendererContentSettingRules* content_setting_rules); |
| 42 | 35 |
| 43 // Returns the setting for the given type. | |
| 44 ContentSetting GetContentSetting(ContentSettingsType type); | |
| 45 | |
| 46 bool plugins_temporarily_allowed() { | 36 bool plugins_temporarily_allowed() { |
| 47 return plugins_temporarily_allowed_; | 37 return plugins_temporarily_allowed_; |
| 48 } | 38 } |
| 49 | 39 |
| 50 // Sends an IPC notification that the specified content type was blocked. | 40 // Sends an IPC notification that the specified content type was blocked. |
| 51 // If the content type requires it, |resource_identifier| names the specific | 41 // If the content type requires it, |resource_identifier| names the specific |
| 52 // resource that was blocked (the plugin path in the case of plugins), | 42 // resource that was blocked (the plugin path in the case of plugins), |
| 53 // otherwise it's the empty string. | 43 // otherwise it's the empty string. |
| 54 void DidBlockContentType(ContentSettingsType settings_type, | 44 void DidBlockContentType(ContentSettingsType settings_type, |
| 55 const std::string& resource_identifier); | 45 const std::string& resource_identifier); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 void DidNotAllowPlugins(WebKit::WebFrame* frame); | 64 void DidNotAllowPlugins(WebKit::WebFrame* frame); |
| 75 void DidNotAllowScript(WebKit::WebFrame* frame); | 65 void DidNotAllowScript(WebKit::WebFrame* frame); |
| 76 | 66 |
| 77 private: | 67 private: |
| 78 // RenderViewObserver implementation. | 68 // RenderViewObserver implementation. |
| 79 virtual bool OnMessageReceived(const IPC::Message& message); | 69 virtual bool OnMessageReceived(const IPC::Message& message); |
| 80 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, | 70 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, |
| 81 bool is_new_navigation); | 71 bool is_new_navigation); |
| 82 | 72 |
| 83 // Message handlers. | 73 // Message handlers. |
| 84 void OnSetContentSettingsForLoadingURL( | |
| 85 const GURL& url, | |
| 86 const ContentSettings& content_settings); | |
| 87 void OnLoadBlockedPlugins(); | 74 void OnLoadBlockedPlugins(); |
| 88 | 75 |
| 89 // Helper method that returns if the user wants to block content of type | |
| 90 // |content_type|. | |
| 91 bool AllowContentType(ContentSettingsType settings_type); | |
| 92 | |
| 93 // Resets the |content_blocked_| array. | 76 // Resets the |content_blocked_| array. |
| 94 void ClearBlockedContentSettings(); | 77 void ClearBlockedContentSettings(); |
| 95 | 78 |
| 96 typedef std::map<GURL, ContentSettings> HostContentSettings; | |
| 97 HostContentSettings host_content_settings_; | |
| 98 | |
| 99 // A pointer to the most up-to-date view of the default content | |
| 100 // settings. Normally, they are owned by |ChromeRenderProcessObserver|. In the | |
| 101 // tests they are owned by the caller of |SetDefaultContentSettings|. | |
| 102 const ContentSettings* default_content_settings_; | |
| 103 | |
| 104 // Stores if loading of scripts and plugins is allowed. | |
| 105 ContentSettings current_content_settings_; | |
| 106 | |
| 107 // A pointer to content setting rules stored by the renderer. Normally, the | 79 // A pointer to content setting rules stored by the renderer. Normally, the |
| 108 // |RendererContentSettingRules| object is owned by | 80 // |RendererContentSettingRules| object is owned by |
| 109 // |ChromeRenderProcessObserver|. In the tests it is owned by the caller of | 81 // |ChromeRenderProcessObserver|. In the tests it is owned by the caller of |
| 110 // |SetContentSettingRules|. | 82 // |SetContentSettingRules|. |
| 111 const RendererContentSettingRules* content_setting_rules_; | 83 const RendererContentSettingRules* content_setting_rules_; |
| 112 | 84 |
| 113 // Stores if images, scripts, and plugins have actually been blocked. | 85 // Stores if images, scripts, and plugins have actually been blocked. |
| 114 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; | 86 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; |
| 115 | 87 |
| 116 // Caches the result of AllowStorage. | 88 // Caches the result of AllowStorage. |
| 117 typedef std::pair<GURL, bool> StoragePermissionsKey; | 89 typedef std::pair<GURL, bool> StoragePermissionsKey; |
| 118 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; | 90 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; |
| 119 | 91 |
| 120 bool plugins_temporarily_allowed_; | 92 bool plugins_temporarily_allowed_; |
| 121 | 93 |
| 122 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); | 94 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); |
| 123 }; | 95 }; |
| 124 | 96 |
| 125 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ | 97 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ |
| OLD | NEW |