| 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 ContentSettingsObserver(content::RenderView* render_view, |
| 28 const ContentSettingsForOneType* image_setting_rules); |
| 28 virtual ~ContentSettingsObserver(); | 29 virtual ~ContentSettingsObserver(); |
| 29 | 30 |
| 30 // Sets the content settings that back allowScripts(), allowImages(), and | 31 // Sets the content settings that back allowScripts() and allowPlugins(). |
| 31 // allowPlugins(). | |
| 32 void SetContentSettings(const ContentSettings& settings); | 32 void SetContentSettings(const ContentSettings& settings); |
| 33 | 33 |
| 34 // Sets the default content settings that back allowScripts(), | 34 // Sets the default content settings that back allowScripts() and |
| 35 // allowImages(), and allowPlugins(). | 35 // allowPlugins(). |
| 36 static void SetDefaultContentSettings(const ContentSettings& settings); | 36 static void SetDefaultContentSettings(const ContentSettings& settings); |
| 37 | 37 |
| 38 // Returns the setting for the given type. | 38 // Returns the setting for the given type. |
| 39 ContentSetting GetContentSetting(ContentSettingsType type); | 39 ContentSetting GetContentSetting(ContentSettingsType type); |
| 40 | 40 |
| 41 // Sends an IPC notification that the specified content type was blocked. | 41 // Sends an IPC notification that the specified content type was blocked. |
| 42 // If the content type requires it, |resource_identifier| names the specific | 42 // If the content type requires it, |resource_identifier| names the specific |
| 43 // resource that was blocked (the plugin path in the case of plugins), | 43 // resource that was blocked (the plugin path in the case of plugins), |
| 44 // otherwise it's the empty string. | 44 // otherwise it's the empty string. |
| 45 void DidBlockContentType(ContentSettingsType settings_type, | 45 void DidBlockContentType(ContentSettingsType settings_type, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // |content_type|. | 79 // |content_type|. |
| 80 bool AllowContentType(ContentSettingsType settings_type); | 80 bool AllowContentType(ContentSettingsType settings_type); |
| 81 | 81 |
| 82 // Resets the |content_blocked_| array. | 82 // Resets the |content_blocked_| array. |
| 83 void ClearBlockedContentSettings(); | 83 void ClearBlockedContentSettings(); |
| 84 | 84 |
| 85 typedef std::map<GURL, ContentSettings> HostContentSettings; | 85 typedef std::map<GURL, ContentSettings> HostContentSettings; |
| 86 HostContentSettings host_content_settings_; | 86 HostContentSettings host_content_settings_; |
| 87 | 87 |
| 88 // Stores our most up-to-date view of the default content settings. | 88 // Stores our most up-to-date view of the default content settings. |
| 89 // TODO(marja): Store default settings in |ChromeRenderProcessObserver|. |
| 89 static ContentSettings default_settings_; | 90 static ContentSettings default_settings_; |
| 90 | 91 |
| 91 // Stores if loading of images, scripts, and plugins is allowed. | 92 // Stores if loading of scripts and plugins is allowed. |
| 92 ContentSettings current_content_settings_; | 93 ContentSettings current_content_settings_; |
| 93 | 94 |
| 95 // Stores the rules for image content settings. Owned by |
| 96 // |ChromeRenderProcessObserver|. |
| 97 const ContentSettingsForOneType* image_setting_rules_; |
| 98 |
| 94 // Stores if images, scripts, and plugins have actually been blocked. | 99 // Stores if images, scripts, and plugins have actually been blocked. |
| 95 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; | 100 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; |
| 96 | 101 |
| 97 // Caches the result of AllowStorage. | 102 // Caches the result of AllowStorage. |
| 98 typedef std::pair<GURL, bool> StoragePermissionsKey; | 103 typedef std::pair<GURL, bool> StoragePermissionsKey; |
| 99 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; | 104 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; |
| 100 | 105 |
| 101 bool plugins_temporarily_allowed_; | 106 bool plugins_temporarily_allowed_; |
| 102 | 107 |
| 103 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); | 108 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); |
| 104 }; | 109 }; |
| 105 | 110 |
| 106 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ | 111 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ |
| OLD | NEW |