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

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

Issue 7831075: Delegating the "are images allowed" decision to renderer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Transmit image settings to the renderer. Draft. Created 9 years, 3 months 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/common/database_messages.h" 9 #include "content/common/database_messages.h"
10 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 document_url.ExtractFileName().empty(); 45 document_url.ExtractFileName().empty();
46 } 46 }
47 } 47 }
48 48
49 return false; 49 return false;
50 } 50 }
51 51
52 } // namespace 52 } // namespace
53 53
54 ContentSettings ContentSettingsObserver::default_settings_; 54 ContentSettings ContentSettingsObserver::default_settings_;
55 ContentSettingRules ContentSettingsObserver::image_setting_rules_;
55 56
56 ContentSettingsObserver::ContentSettingsObserver(RenderView* render_view) 57 ContentSettingsObserver::ContentSettingsObserver(RenderView* render_view)
57 : RenderViewObserver(render_view), 58 : RenderViewObserver(render_view),
58 RenderViewObserverTracker<ContentSettingsObserver>(render_view), 59 RenderViewObserverTracker<ContentSettingsObserver>(render_view),
59 plugins_temporarily_allowed_(false) { 60 plugins_temporarily_allowed_(false) {
60 ClearBlockedContentSettings(); 61 ClearBlockedContentSettings();
61 } 62 }
62 63
63 ContentSettingsObserver::~ContentSettingsObserver() { 64 ContentSettingsObserver::~ContentSettingsObserver() {
64 } 65 }
65 66
66 void ContentSettingsObserver::SetContentSettings( 67 void ContentSettingsObserver::SetContentSettings(
67 const ContentSettings& settings) { 68 const ContentSettings& settings) {
68 current_content_settings_ = settings; 69 current_content_settings_ = settings;
69 } 70 }
70 71
71 void ContentSettingsObserver::SetDefaultContentSettings( 72 void ContentSettingsObserver::SetDefaultContentSettings(
72 const ContentSettings& settings) { 73 const ContentSettings& settings) {
73 default_settings_ = settings; 74 default_settings_ = settings;
74 } 75 }
75 76
77 // static
78 void ContentSettingsObserver::SetImageSettingRules(
79 const ContentSettingRules& rules) {
80 image_setting_rules_ = rules;
81 }
82
76 ContentSetting ContentSettingsObserver::GetContentSetting( 83 ContentSetting ContentSettingsObserver::GetContentSetting(
77 ContentSettingsType type) { 84 ContentSettingsType type) {
78 if (type == CONTENT_SETTINGS_TYPE_PLUGINS && 85 if (type == CONTENT_SETTINGS_TYPE_PLUGINS &&
79 plugins_temporarily_allowed_) { 86 plugins_temporarily_allowed_) {
80 return CONTENT_SETTING_ALLOW; 87 return CONTENT_SETTING_ALLOW;
81 } 88 }
82 return current_content_settings_.settings[type]; 89 return current_content_settings_.settings[type];
83 } 90 }
84 91
85 void ContentSettingsObserver::DidBlockContentType( 92 void ContentSettingsObserver::DidBlockContentType(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 196
190 bool result = false; 197 bool result = false;
191 Send(new ChromeViewHostMsg_AllowFileSystem( 198 Send(new ChromeViewHostMsg_AllowFileSystem(
192 routing_id(), GURL(frame->document().securityOrigin().toString()), 199 routing_id(), GURL(frame->document().securityOrigin().toString()),
193 GURL(frame->top()->document().securityOrigin().toString()), &result)); 200 GURL(frame->top()->document().securityOrigin().toString()), &result));
194 return result; 201 return result;
195 } 202 }
196 203
197 bool ContentSettingsObserver::AllowImages(WebFrame* frame, 204 bool ContentSettingsObserver::AllowImages(WebFrame* frame,
198 bool enabled_per_settings) { 205 bool enabled_per_settings) {
199 if (enabled_per_settings && 206 if (frame->document().securityOrigin().isEmpty() ||
200 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) { 207 frame->top()->document().securityOrigin().isEmpty())
201 return true; 208 return false; // Uninitialized document.
Bernhard Bauer 2011/09/13 17:38:11 Does this change the behavior?
marja 2011/09/15 12:02:00 I moved the IsWhiteListedForContentSettings up, th
209
210 if (enabled_per_settings) {
211 ContentSettingRules::const_iterator it;
212 for (it = image_setting_rules_.begin();
213 it != image_setting_rules_.end(); ++it) {
214 if (it->a.Matches(GURL(frame->document().securityOrigin().toString())) &&
215 it->b.Matches(
216 GURL(frame->top()->document().securityOrigin().toString()))) {
217 return (it->c != CONTENT_SETTING_BLOCK);
Bernhard Bauer 2011/09/13 17:38:11 This simply returns |false| when the setting is BL
marja 2011/09/15 12:02:00 Ahh, true! I added the DidBlockContentType here an
218 }
219 }
202 } 220 }
203 221
204 if (IsWhitelistedForContentSettings(frame)) 222 if (IsWhitelistedForContentSettings(frame))
205 return true; 223 return true;
206 224
207 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); 225 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
208 return false; // Other protocols fall through here. 226 return false; // Other protocols fall through here.
209 } 227 }
210 228
211 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame, 229 bool ContentSettingsObserver::AllowIndexedDB(WebFrame* frame,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // CONTENT_SETTING_ASK is only valid for cookies. 304 // CONTENT_SETTING_ASK is only valid for cookies.
287 return current_content_settings_.settings[settings_type] != 305 return current_content_settings_.settings[settings_type] !=
288 CONTENT_SETTING_BLOCK; 306 CONTENT_SETTING_BLOCK;
289 } 307 }
290 308
291 void ContentSettingsObserver::ClearBlockedContentSettings() { 309 void ContentSettingsObserver::ClearBlockedContentSettings() {
292 for (size_t i = 0; i < arraysize(content_blocked_); ++i) 310 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
293 content_blocked_[i] = false; 311 content_blocked_[i] = false;
294 cached_storage_permissions_.clear(); 312 cached_storage_permissions_.clear();
295 } 313 }
OLDNEW
« chrome/renderer/content_settings_observer.h ('K') | « chrome/renderer/content_settings_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698