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

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

Issue 78303005: ContentSettings API should not interact with <webview> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits + Added missing file Created 7 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
OLDNEW
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 #include "chrome/renderer/content_settings_observer.h" 5 #include "chrome/renderer/content_settings_observer.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 NOTREACHED(); 64 NOTREACHED();
65 return CONTENT_SETTING_DEFAULT; 65 return CONTENT_SETTING_DEFAULT;
66 } 66 }
67 67
68 } // namespace 68 } // namespace
69 69
70 ContentSettingsObserver::ContentSettingsObserver( 70 ContentSettingsObserver::ContentSettingsObserver(
71 content::RenderView* render_view) 71 content::RenderView* render_view)
72 : content::RenderViewObserver(render_view), 72 : content::RenderViewObserver(render_view),
73 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), 73 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view),
74 content_setting_rules_(NULL),
75 is_interstitial_page_(false), 74 is_interstitial_page_(false),
76 npapi_plugins_blocked_(false) { 75 npapi_plugins_blocked_(false) {
77 ClearBlockedContentSettings(); 76 ClearBlockedContentSettings();
78 } 77 }
79 78
80 ContentSettingsObserver::~ContentSettingsObserver() { 79 ContentSettingsObserver::~ContentSettingsObserver() {
81 } 80 }
82 81
83 void ContentSettingsObserver::SetContentSettingRules(
84 const RendererContentSettingRules* content_setting_rules) {
85 content_setting_rules_ = content_setting_rules;
86 }
87
88 bool ContentSettingsObserver::IsPluginTemporarilyAllowed( 82 bool ContentSettingsObserver::IsPluginTemporarilyAllowed(
89 const std::string& identifier) { 83 const std::string& identifier) {
90 // If the empty string is in here, it means all plug-ins are allowed. 84 // If the empty string is in here, it means all plug-ins are allowed.
91 // TODO(bauerb): Remove this once we only pass in explicit identifiers. 85 // TODO(bauerb): Remove this once we only pass in explicit identifiers.
92 return (temporarily_allowed_plugins_.find(identifier) != 86 return (temporarily_allowed_plugins_.find(identifier) !=
93 temporarily_allowed_plugins_.end()) || 87 temporarily_allowed_plugins_.end()) ||
94 (temporarily_allowed_plugins_.find(std::string()) != 88 (temporarily_allowed_plugins_.find(std::string()) !=
95 temporarily_allowed_plugins_.end()); 89 temporarily_allowed_plugins_.end());
96 } 90 }
97 91
98 void ContentSettingsObserver::DidBlockContentType( 92 void ContentSettingsObserver::DidBlockContentType(
99 ContentSettingsType settings_type, 93 ContentSettingsType settings_type,
100 const std::string& resource_identifier) { 94 const std::string& resource_identifier) {
101 // Always send a message when |resource_identifier| is not empty, to tell the 95 // Always send a message when |resource_identifier| is not empty, to tell the
102 // browser which resource was blocked (otherwise the browser will only show 96 // browser which resource was blocked (otherwise the browser will only show
103 // the first resource to be blocked, and none that are blocked at a later 97 // the first resource to be blocked, and none that are blocked at a later
104 // time). 98 // time).
105 if (!content_blocked_[settings_type] || !resource_identifier.empty()) { 99 if (!content_blocked_[settings_type] || !resource_identifier.empty()) {
106 content_blocked_[settings_type] = true; 100 content_blocked_[settings_type] = true;
107 Send(new ChromeViewHostMsg_ContentBlocked(routing_id(), settings_type, 101 Send(new ChromeViewHostMsg_ContentBlocked(routing_id(), settings_type,
108 resource_identifier)); 102 resource_identifier));
109 } 103 }
110 } 104 }
111 105
112 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { 106 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) {
113 bool handled = true; 107 bool handled = true;
114 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) 108 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
115 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) 109 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial)
110 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetContentSettingRules,
111 OnSetContentSettingRules)
116 IPC_MESSAGE_UNHANDLED(handled = false) 112 IPC_MESSAGE_UNHANDLED(handled = false)
117 IPC_END_MESSAGE_MAP() 113 IPC_END_MESSAGE_MAP()
118 if (handled) 114 if (handled)
119 return true; 115 return true;
120 116
121 // Don't swallow LoadBlockedPlugins messages, as they're sent to every 117 // Don't swallow LoadBlockedPlugins messages, as they're sent to every
122 // blocked plugin. 118 // blocked plugin.
123 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) 119 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
124 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) 120 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
125 IPC_END_MESSAGE_MAP() 121 IPC_END_MESSAGE_MAP()
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 310
315 void ContentSettingsObserver::OnLoadBlockedPlugins( 311 void ContentSettingsObserver::OnLoadBlockedPlugins(
316 const std::string& identifier) { 312 const std::string& identifier) {
317 temporarily_allowed_plugins_.insert(identifier); 313 temporarily_allowed_plugins_.insert(identifier);
318 } 314 }
319 315
320 void ContentSettingsObserver::OnSetAsInterstitial() { 316 void ContentSettingsObserver::OnSetAsInterstitial() {
321 is_interstitial_page_ = true; 317 is_interstitial_page_ = true;
322 } 318 }
323 319
320 void ContentSettingsObserver::OnSetContentSettingRules(
321 const RendererContentSettingRules& rules) {
322 if (!content_setting_rules_)
323 content_setting_rules_.reset(new RendererContentSettingRules());
324 *content_setting_rules_ = rules;
325 }
326
324 void ContentSettingsObserver::ClearBlockedContentSettings() { 327 void ContentSettingsObserver::ClearBlockedContentSettings() {
325 for (size_t i = 0; i < arraysize(content_blocked_); ++i) 328 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
326 content_blocked_[i] = false; 329 content_blocked_[i] = false;
327 cached_storage_permissions_.clear(); 330 cached_storage_permissions_.clear();
328 cached_script_permissions_.clear(); 331 cached_script_permissions_.clear();
329 } 332 }
330 333
331 bool ContentSettingsObserver::IsWhitelistedForContentSettings(WebFrame* frame) { 334 bool ContentSettingsObserver::IsWhitelistedForContentSettings(WebFrame* frame) {
332 // Whitelist Instant processes. 335 // Whitelist Instant processes.
333 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess)) 336 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess))
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 370
368 // If the scheme is file:, an empty file name indicates a directory listing, 371 // If the scheme is file:, an empty file name indicates a directory listing,
369 // which requires JavaScript to function properly. 372 // which requires JavaScript to function properly.
370 if (EqualsASCII(origin.protocol(), chrome::kFileScheme)) { 373 if (EqualsASCII(origin.protocol(), chrome::kFileScheme)) {
371 return document_url.SchemeIs(chrome::kFileScheme) && 374 return document_url.SchemeIs(chrome::kFileScheme) &&
372 document_url.ExtractFileName().empty(); 375 document_url.ExtractFileName().empty();
373 } 376 }
374 377
375 return false; 378 return false;
376 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698