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 #include "chrome/renderer/content_settings_observer.h" | 5 #include "chrome/renderer/content_settings_observer.h" |
6 | 6 |
7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
8 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
9 #include "content/common/view_messages.h" | |
9 #include "content/public/renderer/document_state.h" | 10 #include "content/public/renderer/document_state.h" |
10 #include "content/public/renderer/navigation_state.h" | 11 #include "content/public/renderer/navigation_state.h" |
11 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 return CONTENT_SETTING_DEFAULT; | 88 return CONTENT_SETTING_DEFAULT; |
88 } | 89 } |
89 | 90 |
90 } // namespace | 91 } // namespace |
91 | 92 |
92 ContentSettingsObserver::ContentSettingsObserver( | 93 ContentSettingsObserver::ContentSettingsObserver( |
93 content::RenderView* render_view) | 94 content::RenderView* render_view) |
94 : content::RenderViewObserver(render_view), | 95 : content::RenderViewObserver(render_view), |
95 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), | 96 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), |
96 content_setting_rules_(NULL), | 97 content_setting_rules_(NULL), |
97 plugins_temporarily_allowed_(false) { | 98 plugins_temporarily_allowed_(false), |
99 is_interstitial_page_(false) { | |
98 ClearBlockedContentSettings(); | 100 ClearBlockedContentSettings(); |
99 } | 101 } |
100 | 102 |
101 ContentSettingsObserver::~ContentSettingsObserver() { | 103 ContentSettingsObserver::~ContentSettingsObserver() { |
102 } | 104 } |
103 | 105 |
104 void ContentSettingsObserver::SetContentSettingRules( | 106 void ContentSettingsObserver::SetContentSettingRules( |
105 const RendererContentSettingRules* content_setting_rules) { | 107 const RendererContentSettingRules* content_setting_rules) { |
106 content_setting_rules_ = content_setting_rules; | 108 content_setting_rules_ = content_setting_rules; |
107 } | 109 } |
(...skipping 12 matching lines...) Expand all Loading... | |
120 } | 122 } |
121 } | 123 } |
122 | 124 |
123 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { | 125 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { |
124 bool handled = true; | 126 bool handled = true; |
125 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) | 127 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) |
126 // Don't swallow LoadBlockedPlugins messages, as they're sent to every | 128 // Don't swallow LoadBlockedPlugins messages, as they're sent to every |
127 // blocked plugin. | 129 // blocked plugin. |
128 IPC_MESSAGE_HANDLER_GENERIC(ChromeViewMsg_LoadBlockedPlugins, | 130 IPC_MESSAGE_HANDLER_GENERIC(ChromeViewMsg_LoadBlockedPlugins, |
129 OnLoadBlockedPlugins(); handled = false) | 131 OnLoadBlockedPlugins(); handled = false) |
132 IPC_MESSAGE_HANDLER(ViewMsg_SetAsInterstitial, OnSetAsInterstitial) | |
jochen (gone - plz use gerrit)
2011/12/02 12:38:08
I think the render view impl should handle the mes
marja
2011/12/02 14:39:34
Done.
| |
130 IPC_MESSAGE_UNHANDLED(handled = false) | 133 IPC_MESSAGE_UNHANDLED(handled = false) |
131 IPC_END_MESSAGE_MAP() | 134 IPC_END_MESSAGE_MAP() |
132 return handled; | 135 return handled; |
133 } | 136 } |
134 | 137 |
135 void ContentSettingsObserver::DidCommitProvisionalLoad( | 138 void ContentSettingsObserver::DidCommitProvisionalLoad( |
136 WebFrame* frame, bool is_new_navigation) { | 139 WebFrame* frame, bool is_new_navigation) { |
137 if (frame->parent()) | 140 if (frame->parent()) |
138 return; // Not a top-level navigation. | 141 return; // Not a top-level navigation. |
139 | 142 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 return result; | 222 return result; |
220 } | 223 } |
221 | 224 |
222 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, | 225 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, |
223 bool enabled_per_settings) { | 226 bool enabled_per_settings) { |
224 return enabled_per_settings; | 227 return enabled_per_settings; |
225 } | 228 } |
226 | 229 |
227 bool ContentSettingsObserver::AllowScript(WebFrame* frame, | 230 bool ContentSettingsObserver::AllowScript(WebFrame* frame, |
228 bool enabled_per_settings) { | 231 bool enabled_per_settings) { |
232 if (is_interstitial_page_) | |
233 return true; | |
229 if (!enabled_per_settings) | 234 if (!enabled_per_settings) |
230 return false; | 235 return false; |
231 | 236 |
232 std::map<WebFrame*, bool>::const_iterator it = | 237 std::map<WebFrame*, bool>::const_iterator it = |
233 cached_script_permissions_.find(frame); | 238 cached_script_permissions_.find(frame); |
234 if (it != cached_script_permissions_.end()) | 239 if (it != cached_script_permissions_.end()) |
235 return it->second; | 240 return it->second; |
236 | 241 |
237 // Evaluate the content setting rules before | 242 // Evaluate the content setting rules before |
238 // |IsWhitelistedForContentSettings|; if there is only the default rule | 243 // |IsWhitelistedForContentSettings|; if there is only the default rule |
239 // allowing all scripts, it's quicker this way. | 244 // allowing all scripts, it's quicker this way. |
240 bool allow = true; | 245 bool allow = true; |
241 if (content_setting_rules_) { | 246 if (content_setting_rules_) { |
242 ContentSetting setting = GetContentSettingFromRules( | 247 ContentSetting setting = GetContentSettingFromRules( |
243 content_setting_rules_->script_rules, | 248 content_setting_rules_->script_rules, |
244 frame, | 249 frame, |
245 GURL(frame->document().securityOrigin().toString())); | 250 GURL(frame->document().securityOrigin().toString())); |
246 allow = setting != CONTENT_SETTING_BLOCK; | 251 allow = setting != CONTENT_SETTING_BLOCK; |
247 } | 252 } |
248 allow = allow || IsWhitelistedForContentSettings(frame); | 253 allow = allow || IsWhitelistedForContentSettings(frame); |
249 | 254 |
250 cached_script_permissions_[frame] = allow; | 255 cached_script_permissions_[frame] = allow; |
251 return allow; | 256 return allow; |
252 } | 257 } |
253 | 258 |
254 bool ContentSettingsObserver::AllowScriptFromSource( | 259 bool ContentSettingsObserver::AllowScriptFromSource( |
255 WebFrame* frame, | 260 WebFrame* frame, |
256 bool enabled_per_settings, | 261 bool enabled_per_settings, |
257 const WebKit::WebURL& script_url) { | 262 const WebKit::WebURL& script_url) { |
263 if (is_interstitial_page_) | |
264 return true; | |
258 if (!enabled_per_settings) | 265 if (!enabled_per_settings) |
259 return false; | 266 return false; |
260 | 267 |
261 bool allow = true; | 268 bool allow = true; |
262 if (content_setting_rules_) { | 269 if (content_setting_rules_) { |
263 ContentSetting setting = GetContentSettingFromRules( | 270 ContentSetting setting = GetContentSettingFromRules( |
264 content_setting_rules_->script_rules, | 271 content_setting_rules_->script_rules, |
265 frame, | 272 frame, |
266 GURL(script_url)); | 273 GURL(script_url)); |
267 allow = setting != CONTENT_SETTING_BLOCK; | 274 allow = setting != CONTENT_SETTING_BLOCK; |
(...skipping 27 matching lines...) Expand all Loading... | |
295 } | 302 } |
296 | 303 |
297 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { | 304 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { |
298 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); | 305 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); |
299 } | 306 } |
300 | 307 |
301 void ContentSettingsObserver::OnLoadBlockedPlugins() { | 308 void ContentSettingsObserver::OnLoadBlockedPlugins() { |
302 plugins_temporarily_allowed_ = true; | 309 plugins_temporarily_allowed_ = true; |
303 } | 310 } |
304 | 311 |
312 void ContentSettingsObserver::OnSetAsInterstitial() { | |
313 is_interstitial_page_ = true; | |
314 } | |
315 | |
305 void ContentSettingsObserver::ClearBlockedContentSettings() { | 316 void ContentSettingsObserver::ClearBlockedContentSettings() { |
306 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 317 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
307 content_blocked_[i] = false; | 318 content_blocked_[i] = false; |
308 cached_storage_permissions_.clear(); | 319 cached_storage_permissions_.clear(); |
309 cached_script_permissions_.clear(); | 320 cached_script_permissions_.clear(); |
310 } | 321 } |
OLD | NEW |