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

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

Issue 78303005: ContentSettings API should not interact with <webview> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small cleanup/refactor Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 22
23 // Handles blocking content per content settings for each RenderView. 23 // Handles blocking content per content settings for each RenderView.
24 class ContentSettingsObserver 24 class ContentSettingsObserver
25 : public content::RenderViewObserver, 25 : public content::RenderViewObserver,
26 public content::RenderViewObserverTracker<ContentSettingsObserver> { 26 public content::RenderViewObserverTracker<ContentSettingsObserver> {
27 public: 27 public:
28 explicit ContentSettingsObserver(content::RenderView* render_view); 28 explicit ContentSettingsObserver(content::RenderView* render_view);
29 virtual ~ContentSettingsObserver(); 29 virtual ~ContentSettingsObserver();
30 30
31 // Sets the content setting rules which back |AllowImage()|, |AllowScript()|,
32 // and |AllowScriptFromSource()|. |content_setting_rules| must outlive this
33 // |ContentSettingsObserver|.
34 void SetContentSettingRules(
35 const RendererContentSettingRules* content_setting_rules);
36
37 bool IsPluginTemporarilyAllowed(const std::string& identifier); 31 bool IsPluginTemporarilyAllowed(const std::string& identifier);
38 32
39 // Sends an IPC notification that the specified content type was blocked. 33 // Sends an IPC notification that the specified content type was blocked.
40 // If the content type requires it, |resource_identifier| names the specific 34 // If the content type requires it, |resource_identifier| names the specific
41 // resource that was blocked (the plugin path in the case of plugins), 35 // resource that was blocked (the plugin path in the case of plugins),
42 // otherwise it's the empty string. 36 // otherwise it's the empty string.
43 void DidBlockContentType(ContentSettingsType settings_type, 37 void DidBlockContentType(ContentSettingsType settings_type,
44 const std::string& resource_identifier); 38 const std::string& resource_identifier);
45 39
46 // These correspond to blink::WebPermissionClient methods. 40 // These correspond to blink::WebPermissionClient methods.
(...skipping 19 matching lines...) Expand all
66 void DidNotAllowMixedScript(); 60 void DidNotAllowMixedScript();
67 61
68 // These two methods are not related to content settings, they are used 62 // These two methods are not related to content settings, they are used
69 // for cases when the NPAPI plugins malfunction if used. 63 // for cases when the NPAPI plugins malfunction if used.
70 void BlockNPAPIPlugins(); 64 void BlockNPAPIPlugins();
71 bool AreNPAPIPluginsBlocked() const; 65 bool AreNPAPIPluginsBlocked() const;
72 66
73 private: 67 private:
74 FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes); 68 FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes);
75 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, 69 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest,
70 ContentSettingsAllowScripts);
71 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest,
72 JSBlockSentAfterPageLoad);
73 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest,
74 ImagesBlockedByDefault);
75 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest,
76 ImagesAllowedByDefault);
77 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest,
78 ContentSettingsBlockScripts);
79 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest,
76 ContentSettingsInterstitialPages); 80 ContentSettingsInterstitialPages);
77 81
78 // RenderViewObserver implementation. 82 // RenderViewObserver implementation.
79 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 83 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
80 virtual void DidCommitProvisionalLoad(blink::WebFrame* frame, 84 virtual void DidCommitProvisionalLoad(blink::WebFrame* frame,
81 bool is_new_navigation) OVERRIDE; 85 bool is_new_navigation) OVERRIDE;
82 86
83 // Message handlers. 87 // Message handlers.
84 void OnLoadBlockedPlugins(const std::string& identifier); 88 void OnLoadBlockedPlugins(const std::string& identifier);
85 void OnSetAsInterstitial(); 89 void OnSetAsInterstitial();
90 void OnSetContentSettingRules(const RendererContentSettingRules& rules);
86 91
87 // Resets the |content_blocked_| array. 92 // Resets the |content_blocked_| array.
88 void ClearBlockedContentSettings(); 93 void ClearBlockedContentSettings();
89 94
90 // Helpers. 95 // Helpers.
91 // True if |frame| contains content that is white-listed for content settings. 96 // True if |frame| contains content that is white-listed for content settings.
92 static bool IsWhitelistedForContentSettings(blink::WebFrame* frame); 97 static bool IsWhitelistedForContentSettings(blink::WebFrame* frame);
93 static bool IsWhitelistedForContentSettings( 98 static bool IsWhitelistedForContentSettings(
94 const blink::WebSecurityOrigin& origin, 99 const blink::WebSecurityOrigin& origin,
95 const GURL& document_url); 100 const GURL& document_url);
96 101
97 // A pointer to content setting rules stored by the renderer. Normally, the 102 // A pointer to content setting rules stored by the renderer. Normally, the
98 // |RendererContentSettingRules| object is owned by 103 // |RendererContentSettingRules| object is owned by
99 // |ChromeRenderProcessObserver|. In the tests it is owned by the caller of 104 // |ChromeRenderProcessObserver|. In the tests it is owned by the caller of
100 // |SetContentSettingRules|. 105 // |SetContentSettingRules|.
101 const RendererContentSettingRules* content_setting_rules_; 106 scoped_ptr<RendererContentSettingRules> content_setting_rules_;
102 107
103 // Stores if images, scripts, and plugins have actually been blocked. 108 // Stores if images, scripts, and plugins have actually been blocked.
104 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES]; 109 bool content_blocked_[CONTENT_SETTINGS_NUM_TYPES];
105 110
106 // Caches the result of AllowStorage. 111 // Caches the result of AllowStorage.
107 typedef std::pair<GURL, bool> StoragePermissionsKey; 112 typedef std::pair<GURL, bool> StoragePermissionsKey;
108 std::map<StoragePermissionsKey, bool> cached_storage_permissions_; 113 std::map<StoragePermissionsKey, bool> cached_storage_permissions_;
109 114
110 // Caches the result of |AllowScript|. 115 // Caches the result of |AllowScript|.
111 std::map<blink::WebFrame*, bool> cached_script_permissions_; 116 std::map<blink::WebFrame*, bool> cached_script_permissions_;
112 117
113 std::set<std::string> temporarily_allowed_plugins_; 118 std::set<std::string> temporarily_allowed_plugins_;
114 bool is_interstitial_page_; 119 bool is_interstitial_page_;
115 bool npapi_plugins_blocked_; 120 bool npapi_plugins_blocked_;
116 121
117 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); 122 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver);
118 }; 123 };
119 124
120 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ 125 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698