Chromium Code Reviews| 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_frame.h" |
| 16 #include "content/public/renderer/render_view.h" | 16 #include "content/public/renderer/render_view.h" |
| 17 #include "extensions/common/constants.h" | 17 #include "extensions/common/constants.h" |
| 18 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h" | |
| 18 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
| 19 #include "third_party/WebKit/public/web/WebDataSource.h" | 20 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 20 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
| 21 #include "third_party/WebKit/public/web/WebFrame.h" | 22 #include "third_party/WebKit/public/web/WebFrame.h" |
| 22 #include "third_party/WebKit/public/web/WebFrameClient.h" | 23 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 23 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 24 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 24 #include "third_party/WebKit/public/web/WebView.h" | 25 #include "third_party/WebKit/public/web/WebView.h" |
| 25 #include "webkit/child/weburlresponse_extradata_impl.h" | 26 #include "webkit/child/weburlresponse_extradata_impl.h" |
| 26 | 27 |
| 27 using blink::WebDataSource; | 28 using blink::WebDataSource; |
| 28 using blink::WebDocument; | 29 using blink::WebDocument; |
| 29 using blink::WebFrame; | 30 using blink::WebFrame; |
| 30 using blink::WebFrameClient; | 31 using blink::WebFrameClient; |
| 32 using blink::WebPermissionCallbacks; | |
| 31 using blink::WebSecurityOrigin; | 33 using blink::WebSecurityOrigin; |
| 32 using blink::WebString; | 34 using blink::WebString; |
| 33 using blink::WebURL; | 35 using blink::WebURL; |
| 34 using blink::WebView; | 36 using blink::WebView; |
| 35 using content::DocumentState; | 37 using content::DocumentState; |
| 36 using content::NavigationState; | 38 using content::NavigationState; |
| 37 using extensions::APIPermission; | 39 using extensions::APIPermission; |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 content::RenderFrame* render_frame, | 148 content::RenderFrame* render_frame, |
| 147 extensions::Dispatcher* extension_dispatcher) | 149 extensions::Dispatcher* extension_dispatcher) |
| 148 : content::RenderFrameObserver(render_frame), | 150 : content::RenderFrameObserver(render_frame), |
| 149 content::RenderFrameObserverTracker<ContentSettingsObserver>( | 151 content::RenderFrameObserverTracker<ContentSettingsObserver>( |
| 150 render_frame), | 152 render_frame), |
| 151 extension_dispatcher_(extension_dispatcher), | 153 extension_dispatcher_(extension_dispatcher), |
| 152 allow_displaying_insecure_content_(false), | 154 allow_displaying_insecure_content_(false), |
| 153 allow_running_insecure_content_(false), | 155 allow_running_insecure_content_(false), |
| 154 content_setting_rules_(NULL), | 156 content_setting_rules_(NULL), |
| 155 is_interstitial_page_(false), | 157 is_interstitial_page_(false), |
| 156 npapi_plugins_blocked_(false) { | 158 npapi_plugins_blocked_(false), |
| 159 current_request_id_(0) { | |
| 157 ClearBlockedContentSettings(); | 160 ClearBlockedContentSettings(); |
| 158 render_frame->GetWebFrame()->setPermissionClient(this); | 161 render_frame->GetWebFrame()->setPermissionClient(this); |
| 159 } | 162 } |
| 160 | 163 |
| 161 ContentSettingsObserver::~ContentSettingsObserver() { | 164 ContentSettingsObserver::~ContentSettingsObserver() { |
| 162 } | 165 } |
| 163 | 166 |
| 164 void ContentSettingsObserver::SetContentSettingRules( | 167 void ContentSettingsObserver::SetContentSettingRules( |
| 165 const RendererContentSettingRules* content_setting_rules) { | 168 const RendererContentSettingRules* content_setting_rules) { |
| 166 content_setting_rules_ = content_setting_rules; | 169 content_setting_rules_ = content_setting_rules; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 187 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { | 190 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message& message) { |
| 188 bool handled = true; | 191 bool handled = true; |
| 189 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) | 192 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) |
| 190 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) | 193 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial, OnSetAsInterstitial) |
| 191 IPC_MESSAGE_HANDLER(ChromeViewMsg_NPAPINotSupported, OnNPAPINotSupported) | 194 IPC_MESSAGE_HANDLER(ChromeViewMsg_NPAPINotSupported, OnNPAPINotSupported) |
| 192 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, | 195 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent, |
| 193 OnSetAllowDisplayingInsecureContent) | 196 OnSetAllowDisplayingInsecureContent) |
| 194 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, | 197 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent, |
| 195 OnSetAllowRunningInsecureContent) | 198 OnSetAllowRunningInsecureContent) |
| 196 IPC_MESSAGE_HANDLER(ChromeViewMsg_ReloadFrame, OnReloadFrame); | 199 IPC_MESSAGE_HANDLER(ChromeViewMsg_ReloadFrame, OnReloadFrame); |
| 200 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestFileSystemAccessResponse, | |
| 201 OnRequestFileSystemAccessResponse) | |
| 197 IPC_MESSAGE_UNHANDLED(handled = false) | 202 IPC_MESSAGE_UNHANDLED(handled = false) |
| 198 IPC_END_MESSAGE_MAP() | 203 IPC_END_MESSAGE_MAP() |
| 199 if (handled) | 204 if (handled) |
| 200 return true; | 205 return true; |
| 201 | 206 |
| 202 // Don't swallow LoadBlockedPlugins messages, as they're sent to every | 207 // Don't swallow LoadBlockedPlugins messages, as they're sent to every |
| 203 // blocked plugin. | 208 // blocked plugin. |
| 204 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) | 209 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) |
| 205 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) | 210 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) |
| 206 IPC_END_MESSAGE_MAP() | 211 IPC_END_MESSAGE_MAP() |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 frame->top()->document().securityOrigin().isUnique()) | 259 frame->top()->document().securityOrigin().isUnique()) |
| 255 return false; | 260 return false; |
| 256 | 261 |
| 257 bool result = false; | 262 bool result = false; |
| 258 Send(new ChromeViewHostMsg_AllowFileSystem( | 263 Send(new ChromeViewHostMsg_AllowFileSystem( |
| 259 routing_id(), GURL(frame->document().securityOrigin().toString()), | 264 routing_id(), GURL(frame->document().securityOrigin().toString()), |
| 260 GURL(frame->top()->document().securityOrigin().toString()), &result)); | 265 GURL(frame->top()->document().securityOrigin().toString()), &result)); |
| 261 return result; | 266 return result; |
| 262 } | 267 } |
| 263 | 268 |
| 269 void ContentSettingsObserver::requestFileSystemAccess( | |
| 270 WebFrame* frame, const WebPermissionCallbacks& callbacks) { | |
| 271 ++current_request_id_; | |
| 272 std::pair<PermissionRequestMap::iterator, bool> insert_result = | |
| 273 permission_requests_.insert( | |
| 274 std::make_pair(current_request_id_, callbacks)); | |
| 275 | |
| 276 // Verify there are no duplicate insertions. | |
| 277 DCHECK(insert_result.second); | |
| 278 | |
| 279 if (frame->document().securityOrigin().isUnique() || | |
| 280 frame->top()->document().securityOrigin().isUnique()) { | |
| 281 insert_result.first->second.doDeny(); | |
| 282 permission_requests_.erase(insert_result.first); | |
|
kinuko
2014/03/07 08:22:29
I feel this could be checked before you insert the
| |
| 283 return; | |
| 284 } | |
| 285 | |
| 286 Send(new ChromeViewHostMsg_RequestFileSystemAccess( | |
| 287 routing_id(), | |
| 288 current_request_id_, | |
| 289 GURL(frame->document().securityOrigin().toString()), | |
| 290 GURL(frame->top()->document().securityOrigin().toString()))); | |
| 291 } | |
| 292 | |
| 264 bool ContentSettingsObserver::allowImage(WebFrame* frame, | 293 bool ContentSettingsObserver::allowImage(WebFrame* frame, |
| 265 bool enabled_per_settings, | 294 bool enabled_per_settings, |
| 266 const WebURL& image_url) { | 295 const WebURL& image_url) { |
| 267 bool allow = enabled_per_settings; | 296 bool allow = enabled_per_settings; |
| 268 if (enabled_per_settings) { | 297 if (enabled_per_settings) { |
| 269 if (is_interstitial_page_) | 298 if (is_interstitial_page_) |
| 270 return true; | 299 return true; |
| 271 if (IsWhitelistedForContentSettings(frame)) | 300 if (IsWhitelistedForContentSettings(frame)) |
| 272 return true; | 301 return true; |
| 273 | 302 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 allow_running_insecure_content_ = allow; | 611 allow_running_insecure_content_ = allow; |
| 583 OnSetAllowDisplayingInsecureContent(allow); | 612 OnSetAllowDisplayingInsecureContent(allow); |
| 584 } | 613 } |
| 585 | 614 |
| 586 void ContentSettingsObserver::OnReloadFrame() { | 615 void ContentSettingsObserver::OnReloadFrame() { |
| 587 DCHECK(!render_frame()->GetWebFrame()->parent()) << | 616 DCHECK(!render_frame()->GetWebFrame()->parent()) << |
| 588 "Should only be called on the main frame"; | 617 "Should only be called on the main frame"; |
| 589 render_frame()->GetWebFrame()->reload(); | 618 render_frame()->GetWebFrame()->reload(); |
| 590 } | 619 } |
| 591 | 620 |
| 621 void ContentSettingsObserver::OnRequestFileSystemAccessResponse(int request_id, | |
| 622 bool allowed) { | |
| 623 PermissionRequestMap::iterator it = permission_requests_.find(request_id); | |
| 624 if (it == permission_requests_.end()) | |
| 625 return; | |
| 626 | |
| 627 WebPermissionCallbacks callbacks = it->second; | |
| 628 permission_requests_.erase(it); | |
| 629 | |
| 630 if (allowed) { | |
| 631 callbacks.doAllow(); | |
| 632 return; | |
| 633 } | |
| 634 callbacks.doDeny(); | |
| 635 } | |
| 636 | |
| 592 void ContentSettingsObserver::ClearBlockedContentSettings() { | 637 void ContentSettingsObserver::ClearBlockedContentSettings() { |
| 593 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 638 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 594 content_blocked_[i] = false; | 639 content_blocked_[i] = false; |
| 595 cached_storage_permissions_.clear(); | 640 cached_storage_permissions_.clear(); |
| 596 cached_script_permissions_.clear(); | 641 cached_script_permissions_.clear(); |
| 597 } | 642 } |
| 598 | 643 |
| 599 const extensions::Extension* ContentSettingsObserver::GetExtension( | 644 const extensions::Extension* ContentSettingsObserver::GetExtension( |
| 600 const WebSecurityOrigin& origin) const { | 645 const WebSecurityOrigin& origin) const { |
| 601 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) | 646 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 | 694 |
| 650 // If the scheme is file:, an empty file name indicates a directory listing, | 695 // If the scheme is file:, an empty file name indicates a directory listing, |
| 651 // which requires JavaScript to function properly. | 696 // which requires JavaScript to function properly. |
| 652 if (EqualsASCII(origin.protocol(), content::kFileScheme)) { | 697 if (EqualsASCII(origin.protocol(), content::kFileScheme)) { |
| 653 return document_url.SchemeIs(content::kFileScheme) && | 698 return document_url.SchemeIs(content::kFileScheme) && |
| 654 document_url.ExtractFileName().empty(); | 699 document_url.ExtractFileName().empty(); |
| 655 } | 700 } |
| 656 | 701 |
| 657 return false; | 702 return false; |
| 658 } | 703 } |
| OLD | NEW |