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

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

Issue 104833006: Switch ContentSettingsObserver to be a RenderFrameObserver instead of a RenderViewObserver (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
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 "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "chrome/renderer/extensions/dispatcher.h" 12 #include "chrome/renderer/extensions/dispatcher.h"
13 #include "content/public/renderer/document_state.h" 13 #include "content/public/renderer/document_state.h"
14 #include "content/public/renderer/navigation_state.h" 14 #include "content/public/renderer/navigation_state.h"
15 #include "content/public/renderer/render_frame.h"
15 #include "content/public/renderer/render_view.h" 16 #include "content/public/renderer/render_view.h"
16 #include "extensions/common/constants.h" 17 #include "extensions/common/constants.h"
17 #include "third_party/WebKit/public/platform/WebURL.h" 18 #include "third_party/WebKit/public/platform/WebURL.h"
18 #include "third_party/WebKit/public/web/WebDataSource.h" 19 #include "third_party/WebKit/public/web/WebDataSource.h"
19 #include "third_party/WebKit/public/web/WebDocument.h" 20 #include "third_party/WebKit/public/web/WebDocument.h"
20 #include "third_party/WebKit/public/web/WebFrame.h" 21 #include "third_party/WebKit/public/web/WebFrame.h"
21 #include "third_party/WebKit/public/web/WebFrameClient.h" 22 #include "third_party/WebKit/public/web/WebFrameClient.h"
22 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 23 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
23 #include "third_party/WebKit/public/web/WebView.h" 24 #include "third_party/WebKit/public/web/WebView.h"
24 #include "webkit/child/weburlresponse_extradata_impl.h" 25 #include "webkit/child/weburlresponse_extradata_impl.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 return it->setting; 136 return it->setting;
136 } 137 }
137 } 138 }
138 NOTREACHED(); 139 NOTREACHED();
139 return CONTENT_SETTING_DEFAULT; 140 return CONTENT_SETTING_DEFAULT;
140 } 141 }
141 142
142 } // namespace 143 } // namespace
143 144
144 ContentSettingsObserver::ContentSettingsObserver( 145 ContentSettingsObserver::ContentSettingsObserver(
145 content::RenderView* render_view, 146 content::RenderFrame* render_frame,
146 extensions::Dispatcher* extension_dispatcher) 147 extensions::Dispatcher* extension_dispatcher)
147 : content::RenderViewObserver(render_view), 148 : content::RenderFrameObserver(render_frame),
148 content::RenderViewObserverTracker<ContentSettingsObserver>(render_view), 149 content::RenderFrameObserverTracker<ContentSettingsObserver>(
150 render_frame),
149 extension_dispatcher_(extension_dispatcher), 151 extension_dispatcher_(extension_dispatcher),
150 allow_displaying_insecure_content_(false), 152 allow_displaying_insecure_content_(false),
151 allow_running_insecure_content_(false), 153 allow_running_insecure_content_(false),
152 content_setting_rules_(NULL), 154 content_setting_rules_(NULL),
153 is_interstitial_page_(false), 155 is_interstitial_page_(false),
154 npapi_plugins_blocked_(false) { 156 npapi_plugins_blocked_(false) {
155 ClearBlockedContentSettings(); 157 ClearBlockedContentSettings();
156 render_view->GetWebView()->setPermissionClient(this);
157 } 158 }
158 159
159 ContentSettingsObserver::~ContentSettingsObserver() { 160 ContentSettingsObserver::~ContentSettingsObserver() {
160 } 161 }
161 162
162 void ContentSettingsObserver::SetContentSettingRules( 163 void ContentSettingsObserver::SetContentSettingRules(
163 const RendererContentSettingRules* content_setting_rules) { 164 const RendererContentSettingRules* content_setting_rules) {
164 content_setting_rules_ = content_setting_rules; 165 content_setting_rules_ = content_setting_rules;
165 } 166 }
166 167
167 bool ContentSettingsObserver::IsPluginTemporarilyAllowed( 168 bool ContentSettingsObserver::IsPluginTemporarilyAllowed(
168 const std::string& identifier) { 169 const std::string& identifier) {
169 // If the empty string is in here, it means all plug-ins are allowed. 170 // If the empty string is in here, it means all plug-ins are allowed.
170 // TODO(bauerb): Remove this once we only pass in explicit identifiers. 171 // TODO(bauerb): Remove this once we only pass in explicit identifiers.
171 return (temporarily_allowed_plugins_.find(identifier) != 172 return (temporarily_allowed_plugins_.find(identifier) !=
172 temporarily_allowed_plugins_.end()) || 173 temporarily_allowed_plugins_.end()) ||
173 (temporarily_allowed_plugins_.find(std::string()) != 174 (temporarily_allowed_plugins_.find(std::string()) !=
174 temporarily_allowed_plugins_.end()); 175 temporarily_allowed_plugins_.end());
175 } 176 }
176 177
177 void ContentSettingsObserver::DidBlockContentType( 178 void ContentSettingsObserver::DidBlockContentType(
178 ContentSettingsType settings_type) { 179 ContentSettingsType settings_type) {
179 if (!content_blocked_[settings_type]) { 180 if (!content_blocked_[settings_type]) {
180 content_blocked_[settings_type] = true; 181 content_blocked_[settings_type] = true;
181 Send(new ChromeViewHostMsg_ContentBlocked(routing_id(), settings_type)); 182 Send(new ChromeViewHostMsg_ContentBlocked(routing_id(), settings_type));
182 } 183 }
183 } 184 }
184 185
186 void ContentSettingsObserver::WebFrameCreated(blink::WebFrame* frame) {
187 frame->setPermissionClient(this);
188 }
189
185 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { 190 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) {
186 bool handled = true; 191 bool handled = true;
187 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) 192 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
188 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) 193 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial)
189 IPC_MESSAGE_HANDLER(ChromeViewMsg_NPAPINotSupported, OnNPAPINotSupported) 194 IPC_MESSAGE_HANDLER(ChromeViewMsg_NPAPINotSupported, OnNPAPINotSupported)
190 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, 195 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent,
191 OnSetAllowDisplayingInsecureContent) 196 OnSetAllowDisplayingInsecureContent)
192 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, 197 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent,
193 OnSetAllowRunningInsecureContent) 198 OnSetAllowRunningInsecureContent)
199 IPC_MESSAGE_HANDLER(ChromeViewMsg_ReloadFrame, OnReloadFrame);
194 IPC_MESSAGE_UNHANDLED(handled = false) 200 IPC_MESSAGE_UNHANDLED(handled = false)
195 IPC_END_MESSAGE_MAP() 201 IPC_END_MESSAGE_MAP()
196 if (handled) 202 if (handled)
197 return true; 203 return true;
198 204
199 // Don't swallow LoadBlockedPlugins messages, as they're sent to every 205 // Don't swallow LoadBlockedPlugins messages, as they're sent to every
200 // blocked plugin. 206 // blocked plugin.
201 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) 207 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
202 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) 208 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
203 IPC_END_MESSAGE_MAP() 209 IPC_END_MESSAGE_MAP()
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 local, &result)); 374 local, &result));
369 cached_storage_permissions_[key] = result; 375 cached_storage_permissions_[key] = result;
370 return result; 376 return result;
371 } 377 }
372 378
373 bool ContentSettingsObserver::allowReadFromClipboard(WebFrame* frame, 379 bool ContentSettingsObserver::allowReadFromClipboard(WebFrame* frame,
374 bool default_value) { 380 bool default_value) {
375 bool allowed = false; 381 bool allowed = false;
376 // TODO(dcheng): Should we consider a toURL() method on WebSecurityOrigin? 382 // TODO(dcheng): Should we consider a toURL() method on WebSecurityOrigin?
377 Send(new ChromeViewHostMsg_CanTriggerClipboardRead( 383 Send(new ChromeViewHostMsg_CanTriggerClipboardRead(
378 routing_id(), GURL(frame->document().securityOrigin().toString().utf8()), 384 GURL(frame->document().securityOrigin().toString().utf8()), &allowed));
379 &allowed));
380 return allowed; 385 return allowed;
381 } 386 }
382 387
383 bool ContentSettingsObserver::allowWriteToClipboard(WebFrame* frame, 388 bool ContentSettingsObserver::allowWriteToClipboard(WebFrame* frame,
384 bool default_value) { 389 bool default_value) {
385 bool allowed = false; 390 bool allowed = false;
386 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite( 391 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite(
387 routing_id(), GURL(frame->document().securityOrigin().toString().utf8()), 392 GURL(frame->document().securityOrigin().toString().utf8()), &allowed));
388 &allowed));
389 return allowed; 393 return allowed;
390 } 394 }
391 395
392 #if defined(WEBPERMISSIONCLIENT_USES_FRAME_FOR_ALL_METHODS) 396 #if defined(WEBPERMISSIONCLIENT_USES_FRAME_FOR_ALL_METHODS)
393 bool ContentSettingsObserver::allowWebComponents(WebFrame* frame, 397 bool ContentSettingsObserver::allowWebComponents(WebFrame* frame,
394 bool defaultValue) { 398 bool defaultValue) {
395 if (defaultValue) 399 if (defaultValue)
396 return true; 400 return true;
397 401
398 WebSecurityOrigin origin = frame->document().securityOrigin(); 402 WebSecurityOrigin origin = frame->document().securityOrigin();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 DidBlockContentType(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT); 582 DidBlockContentType(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT);
579 return false; 583 return false;
580 } 584 }
581 585
582 return true; 586 return true;
583 } 587 }
584 588
585 bool ContentSettingsObserver::allowWebGLDebugRendererInfo(WebFrame* frame) { 589 bool ContentSettingsObserver::allowWebGLDebugRendererInfo(WebFrame* frame) {
586 bool allowed = false; 590 bool allowed = false;
587 Send(new ChromeViewHostMsg_IsWebGLDebugRendererInfoAllowed( 591 Send(new ChromeViewHostMsg_IsWebGLDebugRendererInfoAllowed(
588 routing_id(),
589 GURL(frame->top()->document().securityOrigin().toString().utf8()), 592 GURL(frame->top()->document().securityOrigin().toString().utf8()),
590 &allowed)); 593 &allowed));
591 return allowed; 594 return allowed;
592 } 595 }
593 596
594 void ContentSettingsObserver::didNotAllowPlugins(WebFrame* frame) { 597 void ContentSettingsObserver::didNotAllowPlugins(WebFrame* frame) {
595 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS); 598 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
596 } 599 }
597 600
598 void ContentSettingsObserver::didNotAllowScript(WebFrame* frame) { 601 void ContentSettingsObserver::didNotAllowScript(WebFrame* frame) {
(...skipping 12 matching lines...) Expand all
611 void ContentSettingsObserver::OnSetAsInterstitial() { 614 void ContentSettingsObserver::OnSetAsInterstitial() {
612 is_interstitial_page_ = true; 615 is_interstitial_page_ = true;
613 } 616 }
614 617
615 void ContentSettingsObserver::OnNPAPINotSupported() { 618 void ContentSettingsObserver::OnNPAPINotSupported() {
616 npapi_plugins_blocked_ = true; 619 npapi_plugins_blocked_ = true;
617 } 620 }
618 621
619 void ContentSettingsObserver::OnSetAllowDisplayingInsecureContent(bool allow) { 622 void ContentSettingsObserver::OnSetAllowDisplayingInsecureContent(bool allow) {
620 allow_displaying_insecure_content_ = allow; 623 allow_displaying_insecure_content_ = allow;
621 WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
622 if (main_frame)
623 main_frame->reload();
624 } 624 }
625 625
626 void ContentSettingsObserver::OnSetAllowRunningInsecureContent(bool allow) { 626 void ContentSettingsObserver::OnSetAllowRunningInsecureContent(bool allow) {
627 allow_running_insecure_content_ = allow; 627 allow_running_insecure_content_ = allow;
628 OnSetAllowDisplayingInsecureContent(allow); 628 OnSetAllowDisplayingInsecureContent(allow);
629 } 629 }
630 630
631 void ContentSettingsObserver::OnReloadFrame() {
632 // TODO(jam): once --site-per-process is default this will just be
633 // render_frame()->GetWebFrame()->reload().
634 WebFrame* main_frame =
635 render_frame()->GetRenderView()->GetWebView()->mainFrame();
636 if (main_frame)
637 main_frame->reload();
638 }
631 639
632 void ContentSettingsObserver::ClearBlockedContentSettings() { 640 void ContentSettingsObserver::ClearBlockedContentSettings() {
633 for (size_t i = 0; i < arraysize(content_blocked_); ++i) 641 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
634 content_blocked_[i] = false; 642 content_blocked_[i] = false;
635 cached_storage_permissions_.clear(); 643 cached_storage_permissions_.clear();
636 cached_script_permissions_.clear(); 644 cached_script_permissions_.clear();
637 } 645 }
638 646
639 const extensions::Extension* ContentSettingsObserver::GetExtension( 647 const extensions::Extension* ContentSettingsObserver::GetExtension(
640 const WebSecurityOrigin& origin) const { 648 const WebSecurityOrigin& origin) const {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) 684 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
677 return true; // Browser UI elements should still work. 685 return true; // Browser UI elements should still work.
678 686
679 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme)) 687 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme))
680 return true; // DevTools UI elements should still work. 688 return true; // DevTools UI elements should still work.
681 689
682 if (EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) 690 if (EqualsASCII(origin.protocol(), extensions::kExtensionScheme))
683 return true; 691 return true;
684 692
685 // TODO(creis, fsamuel): Remove this once the concept of swapped out 693 // TODO(creis, fsamuel): Remove this once the concept of swapped out
686 // RenderViews goes away. 694 // RenderFrames goes away.
687 if (document_url == GURL(content::kSwappedOutURL)) 695 if (document_url == GURL(content::kSwappedOutURL))
688 return true; 696 return true;
689 697
690 // If the scheme is file:, an empty file name indicates a directory listing, 698 // If the scheme is file:, an empty file name indicates a directory listing,
691 // which requires JavaScript to function properly. 699 // which requires JavaScript to function properly.
692 if (EqualsASCII(origin.protocol(), chrome::kFileScheme)) { 700 if (EqualsASCII(origin.protocol(), chrome::kFileScheme)) {
693 return document_url.SchemeIs(chrome::kFileScheme) && 701 return document_url.SchemeIs(chrome::kFileScheme) &&
694 document_url.ExtractFileName().empty(); 702 document_url.ExtractFileName().empty();
695 } 703 }
696 704
697 return false; 705 return false;
698 } 706 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698