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

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 is_interstitial_page_(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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 bool result = false; 182 bool result = false;
182 Send(new ChromeViewHostMsg_AllowFileSystem( 183 Send(new ChromeViewHostMsg_AllowFileSystem(
183 routing_id(), GURL(frame->document().securityOrigin().toString()), 184 routing_id(), GURL(frame->document().securityOrigin().toString()),
184 GURL(frame->top()->document().securityOrigin().toString()), &result)); 185 GURL(frame->top()->document().securityOrigin().toString()), &result));
185 return result; 186 return result;
186 } 187 }
187 188
188 bool ContentSettingsObserver::AllowImage(WebFrame* frame, 189 bool ContentSettingsObserver::AllowImage(WebFrame* frame,
189 bool enabled_per_settings, 190 bool enabled_per_settings,
190 const WebURL& image_url) { 191 const WebURL& image_url) {
192 if (is_interstitial_page_)
193 return true;
191 if (IsWhitelistedForContentSettings(frame)) 194 if (IsWhitelistedForContentSettings(frame))
192 return true; 195 return true;
193 196
194 bool allow = enabled_per_settings; 197 bool allow = enabled_per_settings;
195 if (content_setting_rules_ && enabled_per_settings) { 198 if (content_setting_rules_ && enabled_per_settings) {
196 GURL secondary_url(image_url); 199 GURL secondary_url(image_url);
197 allow = GetContentSettingFromRules( 200 allow = GetContentSettingFromRules(
198 content_setting_rules_->image_rules, 201 content_setting_rules_->image_rules,
199 frame, secondary_url) != CONTENT_SETTING_BLOCK; 202 frame, secondary_url) != CONTENT_SETTING_BLOCK;
200 } 203 }
(...skipping 18 matching lines...) Expand all
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 23 matching lines...) Expand all
291 } 298 }
292 299
293 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) { 300 void ContentSettingsObserver::DidNotAllowPlugins(WebFrame* frame) {
294 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); 301 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
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
308 void ContentSettingsObserver::SetAsInterstitialPage() {
309 is_interstitial_page_ = true;
310 }
311
301 void ContentSettingsObserver::OnLoadBlockedPlugins() { 312 void ContentSettingsObserver::OnLoadBlockedPlugins() {
302 plugins_temporarily_allowed_ = true; 313 plugins_temporarily_allowed_ = true;
303 } 314 }
304 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698