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

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: Cleanup + rebase. 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 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(). 30 // Sets the content setting rules which back |AllowImage()|, |AllowScript()|,
31 void SetContentSettings(const ContentSettings& settings); 31 // 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|. 32 // |ContentSettingsObserver|.
40 void SetImageSettingRules( 33 void SetContentSettingRules(
41 const ContentSettingsForOneType* image_setting_rules); 34 const RendererContentSettingRules* content_setting_rules);
42
43 // Returns the setting for the given type.
44 ContentSetting GetContentSetting(ContentSettingsType type);
45 35
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);
56 46
57 // These correspond to WebKit::WebPermissionClient methods. 47 // These correspond to WebKit::WebPermissionClient methods.
58 bool AllowDatabase(WebKit::WebFrame* frame, 48 bool AllowDatabase(WebKit::WebFrame* frame,
59 const WebKit::WebString& name, 49 const WebKit::WebString& name,
60 const WebKit::WebString& display_name, 50 const WebKit::WebString& display_name,
61 unsigned long estimated_size); 51 unsigned long estimated_size);
62 bool AllowFileSystem(WebKit::WebFrame* frame); 52 bool AllowFileSystem(WebKit::WebFrame* frame);
63 bool AllowImage(WebKit::WebFrame* frame, 53 bool AllowImage(WebKit::WebFrame* frame,
64 bool enabled_per_settings, 54 bool enabled_per_settings,
65 const WebKit::WebURL& image_url); 55 const WebKit::WebURL& image_url);
66 bool AllowIndexedDB(WebKit::WebFrame* frame, 56 bool AllowIndexedDB(WebKit::WebFrame* frame,
67 const WebKit::WebString& name, 57 const WebKit::WebString& name,
68 const WebKit::WebSecurityOrigin& origin); 58 const WebKit::WebSecurityOrigin& origin);
69 bool AllowPlugins(WebKit::WebFrame* frame, bool enabled_per_settings); 59 bool AllowPlugins(WebKit::WebFrame* frame, bool enabled_per_settings);
70 bool AllowScript(WebKit::WebFrame* frame, bool enabled_per_settings); 60 bool AllowScript(WebKit::WebFrame* frame, bool enabled_per_settings);
61 bool AllowScriptFromSource(WebKit::WebFrame* frame, bool enabled_per_settings,
62 const WebKit::WebURL& script_url);
71 bool AllowStorage(WebKit::WebFrame* frame, bool local); 63 bool AllowStorage(WebKit::WebFrame* frame, bool local);
72 void DidNotAllowPlugins(WebKit::WebFrame* frame); 64 void DidNotAllowPlugins(WebKit::WebFrame* frame);
73 void DidNotAllowScript(WebKit::WebFrame* frame); 65 void DidNotAllowScript(WebKit::WebFrame* frame);
74 66
75 private: 67 private:
76 // RenderViewObserver implementation. 68 // RenderViewObserver implementation.
77 virtual bool OnMessageReceived(const IPC::Message& message); 69 virtual bool OnMessageReceived(const IPC::Message& message);
78 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, 70 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
79 bool is_new_navigation); 71 bool is_new_navigation);
80 72
81 // Message handlers. 73 // Message handlers.
82 void OnSetContentSettingsForLoadingURL(
83 const GURL& url,
84 const ContentSettings& content_settings);
85 void OnLoadBlockedPlugins(); 74 void OnLoadBlockedPlugins();
86 75
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. 76 // Resets the |content_blocked_| array.
92 void ClearBlockedContentSettings(); 77 void ClearBlockedContentSettings();
93 78
94 typedef std::map<GURL, ContentSettings> HostContentSettings; 79 // A pointer to content setting rules stored by the renderer. Normally, the
95 HostContentSettings host_content_settings_; 80 // |RendererContentSettingRules| object is owned by
96 81 // |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 82 // |SetContentSettingRules|.
98 // settings. Normally, they are owned by |ChromeRenderProcessObserver|. In the 83 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 84
110 // Stores if images, scripts, and plugins have actually been blocked. 85 // Stores if images, scripts, and plugins have actually been blocked.
111 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; 86 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
112 87
113 // Caches the result of AllowStorage. 88 // Caches the result of AllowStorage.
114 typedef std::pair<GURL, bool> StoragePermissionsKey; 89 typedef std::pair<GURL, bool> StoragePermissionsKey;
115 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; 90 std::map<StoragePermissionsKey, bool> cached_storage_permissions_;
116 91
117 bool plugins_temporarily_allowed_; 92 bool plugins_temporarily_allowed_;
118 93
119 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); 94 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver);
120 }; 95 };
121 96
122 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ 97 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698