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

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

Issue 8773035: Content settings: allow scripts on interstitial pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 9 years 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 #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/public/renderer/document_state.h" 9 #include "content/public/renderer/document_state.h"
10 #include "content/public/renderer/navigation_state.h" 10 #include "content/public/renderer/navigation_state.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 return CONTENT_SETTING_DEFAULT; 87 return CONTENT_SETTING_DEFAULT;
88 } 88 }
89 89
90 } // namespace 90 } // namespace
91 91
92 ContentSettingsObserver::ContentSettingsObserver( 92 ContentSettingsObserver::ContentSettingsObserver(
93 content::RenderView* render_view) 93 content::RenderView* render_view)
94 : content::RenderViewObserver(render_view), 94 : content::RenderViewObserver(render_view),
95 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), 95 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view),
96 content_setting_rules_(NULL), 96 content_setting_rules_(NULL),
97 plugins_temporarily_allowed_(false) { 97 plugins_temporarily_allowed_(false),
98 all_scripts_allowed_(false) {
98 ClearBlockedContentSettings(); 99 ClearBlockedContentSettings();
99 } 100 }
100 101
101 ContentSettingsObserver::~ContentSettingsObserver() { 102 ContentSettingsObserver::~ContentSettingsObserver() {
102 } 103 }
103 104
104 void ContentSettingsObserver::SetContentSettingRules( 105 void ContentSettingsObserver::SetContentSettingRules(
105 const RendererContentSettingRules* content_setting_rules) { 106 const RendererContentSettingRules* content_setting_rules) {
106 content_setting_rules_ = content_setting_rules; 107 content_setting_rules_ = content_setting_rules;
107 } 108 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return result; 220 return result;
220 } 221 }
221 222
222 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame, 223 bool ContentSettingsObserver::AllowPlugins(WebFrame* frame,
223 bool enabled_per_settings) { 224 bool enabled_per_settings) {
224 return enabled_per_settings; 225 return enabled_per_settings;
225 } 226 }
226 227
227 bool ContentSettingsObserver::AllowScript(WebFrame* frame, 228 bool ContentSettingsObserver::AllowScript(WebFrame* frame,
228 bool enabled_per_settings) { 229 bool enabled_per_settings) {
230 if (all_scripts_allowed_)
231 return true;
229 if (!enabled_per_settings) 232 if (!enabled_per_settings)
230 return false; 233 return false;
231 234
232 std::map<WebFrame*, bool>::const_iterator it = 235 std::map<WebFrame*, bool>::const_iterator it =
233 cached_script_permissions_.find(frame); 236 cached_script_permissions_.find(frame);
234 if (it != cached_script_permissions_.end()) 237 if (it != cached_script_permissions_.end())
235 return it->second; 238 return it->second;
236 239
237 // Evaluate the content setting rules before 240 // Evaluate the content setting rules before
238 // |IsWhitelistedForContentSettings|; if there is only the default rule 241 // |IsWhitelistedForContentSettings|; if there is only the default rule
239 // allowing all scripts, it's quicker this way. 242 // allowing all scripts, it's quicker this way.
240 bool allow = true; 243 bool allow = true;
241 if (content_setting_rules_) { 244 if (content_setting_rules_) {
242 ContentSetting setting = GetContentSettingFromRules( 245 ContentSetting setting = GetContentSettingFromRules(
243 content_setting_rules_->script_rules, 246 content_setting_rules_->script_rules,
244 frame, 247 frame,
245 GURL(frame->document().securityOrigin().toString())); 248 GURL(frame->document().securityOrigin().toString()));
246 allow = setting != CONTENT_SETTING_BLOCK; 249 allow = setting != CONTENT_SETTING_BLOCK;
247 } 250 }
248 allow = allow || IsWhitelistedForContentSettings(frame); 251 allow = allow || IsWhitelistedForContentSettings(frame);
249 252
250 cached_script_permissions_[frame] = allow; 253 cached_script_permissions_[frame] = allow;
251 return allow; 254 return allow;
252 } 255 }
253 256
254 bool ContentSettingsObserver::AllowScriptFromSource( 257 bool ContentSettingsObserver::AllowScriptFromSource(
255 WebFrame* frame, 258 WebFrame* frame,
256 bool enabled_per_settings, 259 bool enabled_per_settings,
257 const WebKit::WebURL& script_url) { 260 const WebKit::WebURL& script_url) {
261 if (all_scripts_allowed_)
262 return true;
258 if (!enabled_per_settings) 263 if (!enabled_per_settings)
259 return false; 264 return false;
260 265
261 bool allow = true; 266 bool allow = true;
262 if (content_setting_rules_) { 267 if (content_setting_rules_) {
263 ContentSetting setting = GetContentSettingFromRules( 268 ContentSetting setting = GetContentSettingFromRules(
264 content_setting_rules_->script_rules, 269 content_setting_rules_->script_rules,
265 frame, 270 frame,
266 GURL(script_url)); 271 GURL(script_url));
267 allow = setting != CONTENT_SETTING_BLOCK; 272 allow = setting != CONTENT_SETTING_BLOCK;
(...skipping 23 matching lines...) Expand all
291 } 296 }
292 297
293 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) { 298 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) {
294 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); 299 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
295 } 300 }
296 301
297 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) { 302 void ContentSettingsObserver::DidNotAllowScript(WebFrame* frame) {
298 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); 303 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
299 } 304 }
300 305
306 void ContentSettingsObserver::AllowAllScripts() {
307 all_scripts_allowed_ = true;
308 }
309
301 void ContentSettingsObserver::OnLoadBlockedPlugins() { 310 void ContentSettingsObserver::OnLoadBlockedPlugins() {
302 plugins_temporarily_allowed_ = true; 311 plugins_temporarily_allowed_ = true;
303 } 312 }
304 313
305 void ContentSettingsObserver::ClearBlockedContentSettings() { 314 void ContentSettingsObserver::ClearBlockedContentSettings() {
306 for (size_t i = 0; i < arraysize(content_blocked_); ++i) 315 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
307 content_blocked_[i] = false; 316 content_blocked_[i] = false;
308 cached_storage_permissions_.clear(); 317 cached_storage_permissions_.clear();
309 cached_script_permissions_.clear(); 318 cached_script_permissions_.clear();
310 } 319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698