| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 bool ContentSettingsObserver::allowWebComponents(WebFrame* frame, | 396 bool ContentSettingsObserver::allowWebComponents(WebFrame* frame, |
| 393 bool defaultValue) { | 397 bool defaultValue) { |
| 394 if (defaultValue) | 398 if (defaultValue) |
| 395 return true; | 399 return true; |
| 396 | 400 |
| 397 WebSecurityOrigin origin = frame->document().securityOrigin(); | 401 WebSecurityOrigin origin = frame->document().securityOrigin(); |
| 398 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) | 402 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 DidBlockContentType(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT); | 548 DidBlockContentType(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT); |
| 545 return false; | 549 return false; |
| 546 } | 550 } |
| 547 | 551 |
| 548 return true; | 552 return true; |
| 549 } | 553 } |
| 550 | 554 |
| 551 bool ContentSettingsObserver::allowWebGLDebugRendererInfo(WebFrame* frame) { | 555 bool ContentSettingsObserver::allowWebGLDebugRendererInfo(WebFrame* frame) { |
| 552 bool allowed = false; | 556 bool allowed = false; |
| 553 Send(new ChromeViewHostMsg_IsWebGLDebugRendererInfoAllowed( | 557 Send(new ChromeViewHostMsg_IsWebGLDebugRendererInfoAllowed( |
| 554 routing_id(), | |
| 555 GURL(frame->top()->document().securityOrigin().toString().utf8()), | 558 GURL(frame->top()->document().securityOrigin().toString().utf8()), |
| 556 &allowed)); | 559 &allowed)); |
| 557 return allowed; | 560 return allowed; |
| 558 } | 561 } |
| 559 | 562 |
| 560 void ContentSettingsObserver::didNotAllowPlugins(WebFrame* frame) { | 563 void ContentSettingsObserver::didNotAllowPlugins(WebFrame* frame) { |
| 561 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS); | 564 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 562 } | 565 } |
| 563 | 566 |
| 564 void ContentSettingsObserver::didNotAllowScript(WebFrame* frame) { | 567 void ContentSettingsObserver::didNotAllowScript(WebFrame* frame) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 577 void ContentSettingsObserver::OnSetAsInterstitial() { | 580 void ContentSettingsObserver::OnSetAsInterstitial() { |
| 578 is_interstitial_page_ = true; | 581 is_interstitial_page_ = true; |
| 579 } | 582 } |
| 580 | 583 |
| 581 void ContentSettingsObserver::OnNPAPINotSupported() { | 584 void ContentSettingsObserver::OnNPAPINotSupported() { |
| 582 npapi_plugins_blocked_ = true; | 585 npapi_plugins_blocked_ = true; |
| 583 } | 586 } |
| 584 | 587 |
| 585 void ContentSettingsObserver::OnSetAllowDisplayingInsecureContent(bool allow) { | 588 void ContentSettingsObserver::OnSetAllowDisplayingInsecureContent(bool allow) { |
| 586 allow_displaying_insecure_content_ = allow; | 589 allow_displaying_insecure_content_ = allow; |
| 587 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | |
| 588 if (main_frame) | |
| 589 main_frame->reload(); | |
| 590 } | 590 } |
| 591 | 591 |
| 592 void ContentSettingsObserver::OnSetAllowRunningInsecureContent(bool allow) { | 592 void ContentSettingsObserver::OnSetAllowRunningInsecureContent(bool allow) { |
| 593 allow_running_insecure_content_ = allow; | 593 allow_running_insecure_content_ = allow; |
| 594 OnSetAllowDisplayingInsecureContent(allow); | 594 OnSetAllowDisplayingInsecureContent(allow); |
| 595 } | 595 } |
| 596 | 596 |
| 597 void ContentSettingsObserver::OnReloadFrame() { |
| 598 // TODO(jam): once --site-per-process is default this will just be |
| 599 // render_frame()->GetWebFrame()->reload(). |
| 600 WebFrame* main_frame = |
| 601 render_frame()->GetRenderView()->GetWebView()->mainFrame(); |
| 602 if (main_frame) |
| 603 main_frame->reload(); |
| 604 } |
| 597 | 605 |
| 598 void ContentSettingsObserver::ClearBlockedContentSettings() { | 606 void ContentSettingsObserver::ClearBlockedContentSettings() { |
| 599 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 607 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 600 content_blocked_[i] = false; | 608 content_blocked_[i] = false; |
| 601 cached_storage_permissions_.clear(); | 609 cached_storage_permissions_.clear(); |
| 602 cached_script_permissions_.clear(); | 610 cached_script_permissions_.clear(); |
| 603 } | 611 } |
| 604 | 612 |
| 605 const extensions::Extension* ContentSettingsObserver::GetExtension( | 613 const extensions::Extension* ContentSettingsObserver::GetExtension( |
| 606 const WebSecurityOrigin& origin) const { | 614 const WebSecurityOrigin& origin) const { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) | 650 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| 643 return true; // Browser UI elements should still work. | 651 return true; // Browser UI elements should still work. |
| 644 | 652 |
| 645 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme)) | 653 if (EqualsASCII(origin.protocol(), chrome::kChromeDevToolsScheme)) |
| 646 return true; // DevTools UI elements should still work. | 654 return true; // DevTools UI elements should still work. |
| 647 | 655 |
| 648 if (EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) | 656 if (EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) |
| 649 return true; | 657 return true; |
| 650 | 658 |
| 651 // TODO(creis, fsamuel): Remove this once the concept of swapped out | 659 // TODO(creis, fsamuel): Remove this once the concept of swapped out |
| 652 // RenderViews goes away. | 660 // RenderFrames goes away. |
| 653 if (document_url == GURL(content::kSwappedOutURL)) | 661 if (document_url == GURL(content::kSwappedOutURL)) |
| 654 return true; | 662 return true; |
| 655 | 663 |
| 656 // If the scheme is file:, an empty file name indicates a directory listing, | 664 // If the scheme is file:, an empty file name indicates a directory listing, |
| 657 // which requires JavaScript to function properly. | 665 // which requires JavaScript to function properly. |
| 658 if (EqualsASCII(origin.protocol(), chrome::kFileScheme)) { | 666 if (EqualsASCII(origin.protocol(), chrome::kFileScheme)) { |
| 659 return document_url.SchemeIs(chrome::kFileScheme) && | 667 return document_url.SchemeIs(chrome::kFileScheme) && |
| 660 document_url.ExtractFileName().empty(); | 668 document_url.ExtractFileName().empty(); |
| 661 } | 669 } |
| 662 | 670 |
| 663 return false; | 671 return false; |
| 664 } | 672 } |
| OLD | NEW |