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(), allowImages(), and | 30 // Sets the content settings that back allowScripts() and allowPlugins(). |
31 // allowPlugins(). | |
32 void SetContentSettings(const ContentSettings& settings); | 31 void SetContentSettings(const ContentSettings& settings); |
33 | 32 |
34 // Sets the default content settings that back allowScripts(), | 33 // Sets the default content settings that back allowScripts() and |
35 // allowImages(), and allowPlugins(). | 34 // allowPlugins(). |
36 static void SetDefaultContentSettings(const ContentSettings& settings); | 35 static void SetDefaultContentSettings(const ContentSettings& settings); |
37 | 36 |
37 // Sets the image setting rules which back |allowImage()|. | |
38 // |ContentSettingObserver| does not take the ownership of the | |
Bernhard Bauer
2011/10/20 09:21:53
Nit: Can you add a comment that state that callers
marja
2011/10/20 11:44:22
Done.
| |
39 // pointer. | |
40 void SetImageSettingRules( | |
41 const ContentSettingsForOneType* image_setting_rules); | |
42 | |
38 // Returns the setting for the given type. | 43 // Returns the setting for the given type. |
39 ContentSetting GetContentSetting(ContentSettingsType type); | 44 ContentSetting GetContentSetting(ContentSettingsType type); |
40 | 45 |
41 bool plugins_temporarily_allowed() { | 46 bool plugins_temporarily_allowed() { |
42 return plugins_temporarily_allowed_; | 47 return plugins_temporarily_allowed_; |
43 } | 48 } |
44 | 49 |
45 // Sends an IPC notification that the specified content type was blocked. | 50 // Sends an IPC notification that the specified content type was blocked. |
46 // If the content type requires it, |resource_identifier| names the specific | 51 // If the content type requires it, |resource_identifier| names the specific |
47 // resource that was blocked (the plugin path in the case of plugins), | 52 // resource that was blocked (the plugin path in the case of plugins), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 // |content_type|. | 88 // |content_type|. |
84 bool AllowContentType(ContentSettingsType settings_type); | 89 bool AllowContentType(ContentSettingsType settings_type); |
85 | 90 |
86 // Resets the |content_blocked_| array. | 91 // Resets the |content_blocked_| array. |
87 void ClearBlockedContentSettings(); | 92 void ClearBlockedContentSettings(); |
88 | 93 |
89 typedef std::map<GURL, ContentSettings> HostContentSettings; | 94 typedef std::map<GURL, ContentSettings> HostContentSettings; |
90 HostContentSettings host_content_settings_; | 95 HostContentSettings host_content_settings_; |
91 | 96 |
92 // Stores our most up-to-date view of the default content settings. | 97 // Stores our most up-to-date view of the default content settings. |
98 // TODO(marja): Store default settings in |ChromeRenderProcessObserver|. | |
93 static ContentSettings default_settings_; | 99 static ContentSettings default_settings_; |
94 | 100 |
95 // Stores if loading of images, scripts, and plugins is allowed. | 101 // Stores if loading of scripts and plugins is allowed. |
96 ContentSettings current_content_settings_; | 102 ContentSettings current_content_settings_; |
97 | 103 |
104 // Stores the rules for image content settings. Normally, they are owned by | |
105 // |ChromeRenderProcessObserver|; in the tests they are owned by the caller of | |
106 // |SetImageSettingRules|. | |
107 const ContentSettingsForOneType* image_setting_rules_; | |
108 | |
98 // Stores if images, scripts, and plugins have actually been blocked. | 109 // Stores if images, scripts, and plugins have actually been blocked. |
99 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; | 110 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; |
100 | 111 |
101 // Caches the result of AllowStorage. | 112 // Caches the result of AllowStorage. |
102 typedef std::pair<GURL, bool> StoragePermissionsKey; | 113 typedef std::pair<GURL, bool> StoragePermissionsKey; |
103 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; | 114 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; |
104 | 115 |
105 bool plugins_temporarily_allowed_; | 116 bool plugins_temporarily_allowed_; |
106 | 117 |
107 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); | 118 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); |
108 }; | 119 }; |
109 | 120 |
110 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ | 121 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ |
OLD | NEW |