Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: chrome/renderer/content_settings_observer.h

Issue 8538004: Take script URLs into account when applying script content settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 WebFrame;
18 class WebSecurityOrigin; 19 class WebSecurityOrigin;
19 class WebURL; 20 class WebURL;
20 } 21 }
21 22
22 // Handles blocking content per content settings for each RenderView. 23 // Handles blocking content per content settings for each RenderView.
23 class ContentSettingsObserver 24 class ContentSettingsObserver
24 : public content::RenderViewObserver, 25 : public content::RenderViewObserver,
25 public content::RenderViewObserverTracker<ContentSettingsObserver> { 26 public content::RenderViewObserverTracker<ContentSettingsObserver> {
26 public: 27 public:
27 explicit ContentSettingsObserver(content::RenderView* render_view); 28 explicit ContentSettingsObserver(content::RenderView* render_view);
28 virtual ~ContentSettingsObserver(); 29 virtual ~ContentSettingsObserver();
29 30
30 // Sets the content settings that back allowScripts() and allowPlugins(). 31 // Sets the content setting rules which back |AllowImage()|, |AllowScript()|,
31 void SetContentSettings(const ContentSettings& settings); 32 // and |AllowScriptFromSource()|. |content_setting_rules| must outlive this
32
33 // Sets the default content settings that back allowScripts() and
34 // allowPlugins().
35 void SetDefaultContentSettings(const ContentSettings* settings);
36
37 // Sets the image setting rules which back |allowImage()|. The
38 // |ContentSettingsForOneType| object must outlive this
39 // |ContentSettingsObserver|. 33 // |ContentSettingsObserver|.
40 void SetImageSettingRules( 34 void SetContentSettingRules(
41 const ContentSettingsForOneType* image_setting_rules); 35 const RendererContentSettingRules* content_setting_rules);
42
43 // Returns the setting for the given type.
44 ContentSetting GetContentSetting(ContentSettingsType type);
45 36
46 bool plugins_temporarily_allowed() { 37 bool plugins_temporarily_allowed() {
47 return plugins_temporarily_allowed_; 38 return plugins_temporarily_allowed_;
48 } 39 }
49 40
50 // Sends an IPC notification that the specified content type was blocked. 41 // Sends an IPC notification that the specified content type was blocked.
51 // If the content type requires it, |resource_identifier| names the specific 42 // If the content type requires it, |resource_identifier| names the specific
52 // 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),
53 // otherwise it's the empty string. 44 // otherwise it's the empty string.
54 void DidBlockContentType(ContentSettingsType settings_type, 45 void DidBlockContentType(ContentSettingsType settings_type,
55 const std::string& resource_identifier); 46 const std::string& resource_identifier);
56 47
57 // These correspond to WebKit::WebPermissionClient methods. 48 // These correspond to WebKit::WebPermissionClient methods.
58 bool AllowDatabase(WebKit::WebFrame* frame, 49 bool AllowDatabase(WebKit::WebFrame* frame,
59 const WebKit::WebString& name, 50 const WebKit::WebString& name,
60 const WebKit::WebString& display_name, 51 const WebKit::WebString& display_name,
61 unsigned long estimated_size); 52 unsigned long estimated_size);
62 bool AllowFileSystem(WebKit::WebFrame* frame); 53 bool AllowFileSystem(WebKit::WebFrame* frame);
63 bool AllowImage(WebKit::WebFrame* frame, 54 bool AllowImage(WebKit::WebFrame* frame,
64 bool enabled_per_settings, 55 bool enabled_per_settings,
65 const WebKit::WebURL& image_url); 56 const WebKit::WebURL& image_url);
66 bool AllowIndexedDB(WebKit::WebFrame* frame, 57 bool AllowIndexedDB(WebKit::WebFrame* frame,
67 const WebKit::WebString& name, 58 const WebKit::WebString& name,
68 const WebKit::WebSecurityOrigin& origin); 59 const WebKit::WebSecurityOrigin& origin);
69 bool AllowPlugins(WebKit::WebFrame* frame, bool enabled_per_settings); 60 bool AllowPlugins(WebKit::WebFrame* frame, bool enabled_per_settings);
70 bool AllowScript(WebKit::WebFrame* frame, bool enabled_per_settings); 61 bool AllowScript(WebKit::WebFrame* frame, bool enabled_per_settings);
62 bool AllowScriptFromSource(WebKit::WebFrame* frame, bool enabled_per_settings,
63 const WebKit::WebURL& script_url);
71 bool AllowStorage(WebKit::WebFrame* frame, bool local); 64 bool AllowStorage(WebKit::WebFrame* frame, bool local);
72 void DidNotAllowPlugins(WebKit::WebFrame* frame); 65 void DidNotAllowPlugins(WebKit::WebFrame* frame);
73 void DidNotAllowScript(WebKit::WebFrame* frame); 66 void DidNotAllowScript(WebKit::WebFrame* frame);
74 67
75 private: 68 private:
76 // RenderViewObserver implementation. 69 // RenderViewObserver implementation.
77 virtual bool OnMessageReceived(const IPC::Message& message); 70 virtual bool OnMessageReceived(const IPC::Message& message);
78 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, 71 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
79 bool is_new_navigation); 72 bool is_new_navigation);
80 73
81 // Message handlers. 74 // Message handlers.
82 void OnSetContentSettingsForLoadingURL(
83 const GURL& url,
84 const ContentSettings& content_settings);
85 void OnLoadBlockedPlugins(); 75 void OnLoadBlockedPlugins();
86 76
87 // Helper method that returns if the user wants to block content of type
88 // |content_type|.
89 bool AllowContentType(ContentSettingsType settings_type);
90
91 // Resets the |content_blocked_| array. 77 // Resets the |content_blocked_| array.
92 void ClearBlockedContentSettings(); 78 void ClearBlockedContentSettings();
93 79
94 typedef std::map<GURL, ContentSettings> HostContentSettings; 80 // A pointer to content setting rules stored by the renderer. Normally, the
95 HostContentSettings host_content_settings_; 81 // |RendererContentSettingRules| object is owned by
96 82 // |ChromeRenderProcessObserver|. In the tests it is owned by the caller of
97 // A pointer to the most up-to-date view of the default content 83 // |SetContentSettingRules|.
98 // settings. Normally, they are owned by |ChromeRenderProcessObserver|. In the 84 const RendererContentSettingRules* content_setting_rules_;
99 // tests they are owned by the caller of |SetDefaultContentSettings|.
100 const ContentSettings* default_content_settings_;
101
102 // Stores if loading of scripts and plugins is allowed.
103 ContentSettings current_content_settings_;
104
105 // Stores the rules for image content settings. Normally, they are owned by
106 // |ChromeRenderProcessObserver|. In the tests they are owned by the caller of
107 // |SetImageSettingRules|.
108 const ContentSettingsForOneType* image_setting_rules_;
109 85
110 // Stores if images, scripts, and plugins have actually been blocked. 86 // Stores if images, scripts, and plugins have actually been blocked.
111 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; 87 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
112 88
113 // Caches the result of AllowStorage. 89 // Caches the result of AllowStorage.
114 typedef std::pair<GURL, bool> StoragePermissionsKey; 90 typedef std::pair<GURL, bool> StoragePermissionsKey;
115 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; 91 std::map<StoragePermissionsKey, bool> cached_storage_permissions_;
116 92
93 // Caches the result of |AllowScript|.
94 std::map<WebKit::WebFrame*, bool> cached_script_permissions_;
95
117 bool plugins_temporarily_allowed_; 96 bool plugins_temporarily_allowed_;
118 97
119 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); 98 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver);
120 }; 99 };
121 100
122 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ 101 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_render_view_observer.cc ('k') | chrome/renderer/content_settings_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698