| OLD | NEW |
| 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 |
| 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_frame_observer.h" |
| 13 #include "content/public/renderer/render_view_observer_tracker.h" | 13 #include "content/public/renderer/render_frame_observer_tracker.h" |
| 14 #include "extensions/common/permissions/api_permission.h" | 14 #include "extensions/common/permissions/api_permission.h" |
| 15 #include "third_party/WebKit/public/web/WebPermissionClient.h" | 15 #include "third_party/WebKit/public/web/WebPermissionClient.h" |
| 16 | 16 |
| 17 class GURL; | 17 class GURL; |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 class WebFrame; | 20 class WebFrame; |
| 21 class WebSecurityOrigin; | 21 class WebSecurityOrigin; |
| 22 class WebURL; | 22 class WebURL; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 class Dispatcher; | 26 class Dispatcher; |
| 27 class Extension; | 27 class Extension; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Handles blocking content per content settings for each RenderView. | 30 // Handles blocking content per content settings for each RenderFrame. |
| 31 class ContentSettingsObserver | 31 class ContentSettingsObserver |
| 32 : public content::RenderViewObserver, | 32 : public content::RenderFrameObserver, |
| 33 public content::RenderViewObserverTracker<ContentSettingsObserver>, | 33 public content::RenderFrameObserverTracker<ContentSettingsObserver>, |
| 34 public blink::WebPermissionClient { | 34 public blink::WebPermissionClient { |
| 35 public: | 35 public: |
| 36 ContentSettingsObserver(content::RenderView* render_view, | 36 ContentSettingsObserver(content::RenderFrame* render_frame, |
| 37 extensions::Dispatcher* extension_dispatcher); | 37 extensions::Dispatcher* extension_dispatcher); |
| 38 virtual ~ContentSettingsObserver(); | 38 virtual ~ContentSettingsObserver(); |
| 39 | 39 |
| 40 // Sets the content setting rules which back |AllowImage()|, |AllowScript()|, | 40 // Sets the content setting rules which back |AllowImage()|, |AllowScript()|, |
| 41 // and |AllowScriptFromSource()|. |content_setting_rules| must outlive this | 41 // and |AllowScriptFromSource()|. |content_setting_rules| must outlive this |
| 42 // |ContentSettingsObserver|. | 42 // |ContentSettingsObserver|. |
| 43 void SetContentSettingRules( | 43 void SetContentSettingRules( |
| 44 const RendererContentSettingRules* content_setting_rules); | 44 const RendererContentSettingRules* content_setting_rules); |
| 45 | 45 |
| 46 bool IsPluginTemporarilyAllowed(const std::string& identifier); | 46 bool IsPluginTemporarilyAllowed(const std::string& identifier); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const blink::WebSecurityOrigin& context, | 90 const blink::WebSecurityOrigin& context, |
| 91 const blink::WebURL& url); | 91 const blink::WebURL& url); |
| 92 | 92 |
| 93 // This is used for cases when the NPAPI plugins malfunction if used. | 93 // This is used for cases when the NPAPI plugins malfunction if used. |
| 94 bool AreNPAPIPluginsBlocked() const; | 94 bool AreNPAPIPluginsBlocked() const; |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes); | 97 FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes); |
| 98 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, | 98 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, |
| 99 ContentSettingsInterstitialPages); | 99 ContentSettingsInterstitialPages); |
| 100 FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, PluginsTemporarilyAllowed); |
| 100 | 101 |
| 101 // RenderViewObserver implementation. | 102 // RenderFrameObserver implementation. |
| 103 virtual void WebFrameCreated(blink::WebFrame* frame) OVERRIDE; |
| 102 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 104 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 103 virtual void DidCommitProvisionalLoad(blink::WebFrame* frame, | 105 virtual void DidCommitProvisionalLoad(blink::WebFrame* frame, |
| 104 bool is_new_navigation) OVERRIDE; | 106 bool is_new_navigation) OVERRIDE; |
| 105 | 107 |
| 106 // Message handlers. | 108 // Message handlers. |
| 107 void OnLoadBlockedPlugins(const std::string& identifier); | 109 void OnLoadBlockedPlugins(const std::string& identifier); |
| 108 void OnSetAsInterstitial(); | 110 void OnSetAsInterstitial(); |
| 109 void OnNPAPINotSupported(); | 111 void OnNPAPINotSupported(); |
| 110 void OnSetAllowDisplayingInsecureContent(bool allow); | 112 void OnSetAllowDisplayingInsecureContent(bool allow); |
| 111 void OnSetAllowRunningInsecureContent(bool allow); | 113 void OnSetAllowRunningInsecureContent(bool allow); |
| 114 void OnReloadFrame(); |
| 112 | 115 |
| 113 // Resets the |content_blocked_| array. | 116 // Resets the |content_blocked_| array. |
| 114 void ClearBlockedContentSettings(); | 117 void ClearBlockedContentSettings(); |
| 115 | 118 |
| 116 // If |origin| corresponds to an installed extension, returns that extension. | 119 // If |origin| corresponds to an installed extension, returns that extension. |
| 117 // Otherwise returns NULL. | 120 // Otherwise returns NULL. |
| 118 const extensions::Extension* GetExtension( | 121 const extensions::Extension* GetExtension( |
| 119 const blink::WebSecurityOrigin& origin) const; | 122 const blink::WebSecurityOrigin& origin) const; |
| 120 | 123 |
| 121 // Helpers. | 124 // Helpers. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 149 std::map<blink::WebFrame*, bool> cached_script_permissions_; | 152 std::map<blink::WebFrame*, bool> cached_script_permissions_; |
| 150 | 153 |
| 151 std::set<std::string> temporarily_allowed_plugins_; | 154 std::set<std::string> temporarily_allowed_plugins_; |
| 152 bool is_interstitial_page_; | 155 bool is_interstitial_page_; |
| 153 bool npapi_plugins_blocked_; | 156 bool npapi_plugins_blocked_; |
| 154 | 157 |
| 155 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); | 158 DISALLOW_COPY_AND_ASSIGN(ContentSettingsObserver); |
| 156 }; | 159 }; |
| 157 | 160 |
| 158 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ | 161 #endif // CHROME_RENDERER_CONTENT_SETTINGS_OBSERVER_H_ |
| OLD | NEW |