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 "chrome/renderer/permission_request_map.h" | |
| 13 #include "content/public/renderer/document_state.h" | 14 #include "content/public/renderer/document_state.h" |
| 14 #include "content/public/renderer/navigation_state.h" | 15 #include "content/public/renderer/navigation_state.h" |
| 15 #include "content/public/renderer/render_frame.h" | 16 #include "content/public/renderer/render_frame.h" |
| 16 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
| 17 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
| 19 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h" | |
| 18 #include "third_party/WebKit/public/platform/WebURL.h" | 20 #include "third_party/WebKit/public/platform/WebURL.h" |
| 19 #include "third_party/WebKit/public/web/WebDataSource.h" | 21 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 20 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
| 21 #include "third_party/WebKit/public/web/WebFrame.h" | 23 #include "third_party/WebKit/public/web/WebFrame.h" |
| 22 #include "third_party/WebKit/public/web/WebFrameClient.h" | 24 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 23 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 25 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 24 #include "third_party/WebKit/public/web/WebView.h" | 26 #include "third_party/WebKit/public/web/WebView.h" |
| 25 #include "webkit/child/weburlresponse_extradata_impl.h" | 27 #include "webkit/child/weburlresponse_extradata_impl.h" |
| 26 | 28 |
| 27 using blink::WebDataSource; | 29 using blink::WebDataSource; |
| 28 using blink::WebDocument; | 30 using blink::WebDocument; |
| 29 using blink::WebFrame; | 31 using blink::WebFrame; |
| 30 using blink::WebFrameClient; | 32 using blink::WebFrameClient; |
| 33 using blink::WebPermissionCallbacks; | |
| 31 using blink::WebSecurityOrigin; | 34 using blink::WebSecurityOrigin; |
| 32 using blink::WebString; | 35 using blink::WebString; |
| 33 using blink::WebURL; | 36 using blink::WebURL; |
| 34 using blink::WebView; | 37 using blink::WebView; |
| 35 using content::DocumentState; | 38 using content::DocumentState; |
| 36 using content::NavigationState; | 39 using content::NavigationState; |
| 37 using extensions::APIPermission; | 40 using extensions::APIPermission; |
| 38 | 41 |
| 39 namespace { | 42 namespace { |
| 40 | 43 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after 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_RequestFileSystemAccess_ACK, | |
| 201 OnRequestFileSystemAccessACK) | |
| 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 int request_id = | |
| 272 content::PermissionRequestMap::GetOrCreate()-> | |
| 273 RegisterPermissionCallbacks(callbacks); | |
|
kinuko
2014/03/05 08:35:44
If you don't call this on worker thread you don't
Fady Samuel
2014/03/06 18:38:25
Done.
| |
| 274 | |
| 275 Send(new ChromeViewHostMsg_RequestFileSystemAccess( | |
| 276 routing_id(), | |
| 277 request_id, | |
| 278 GURL(frame->document().securityOrigin().toString()), | |
| 279 GURL(frame->top()->document().securityOrigin().toString()))); | |
| 280 } | |
| 281 | |
| 264 bool ContentSettingsObserver::allowImage(WebFrame* frame, | 282 bool ContentSettingsObserver::allowImage(WebFrame* frame, |
| 265 bool enabled_per_settings, | 283 bool enabled_per_settings, |
| 266 const WebURL& image_url) { | 284 const WebURL& image_url) { |
| 267 bool allow = enabled_per_settings; | 285 bool allow = enabled_per_settings; |
| 268 if (enabled_per_settings) { | 286 if (enabled_per_settings) { |
| 269 if (is_interstitial_page_) | 287 if (is_interstitial_page_) |
| 270 return true; | 288 return true; |
| 271 if (IsWhitelistedForContentSettings(frame)) | 289 if (IsWhitelistedForContentSettings(frame)) |
| 272 return true; | 290 return true; |
| 273 | 291 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 allow_running_insecure_content_ = allow; | 600 allow_running_insecure_content_ = allow; |
| 583 OnSetAllowDisplayingInsecureContent(allow); | 601 OnSetAllowDisplayingInsecureContent(allow); |
| 584 } | 602 } |
| 585 | 603 |
| 586 void ContentSettingsObserver::OnReloadFrame() { | 604 void ContentSettingsObserver::OnReloadFrame() { |
| 587 DCHECK(!render_frame()->GetWebFrame()->parent()) << | 605 DCHECK(!render_frame()->GetWebFrame()->parent()) << |
| 588 "Should only be called on the main frame"; | 606 "Should only be called on the main frame"; |
| 589 render_frame()->GetWebFrame()->reload(); | 607 render_frame()->GetWebFrame()->reload(); |
| 590 } | 608 } |
| 591 | 609 |
| 610 void ContentSettingsObserver::OnRequestFileSystemAccessACK(int request_id, | |
| 611 bool allowed) { | |
| 612 scoped_ptr<WebPermissionCallbacks> callbacks( | |
| 613 content::PermissionRequestMap::Get()->GetAndUnregisterCallbacks( | |
| 614 request_id)); | |
| 615 if (allowed) { | |
| 616 callbacks->doAllow(); | |
| 617 } else { | |
| 618 callbacks->doDeny(); | |
| 619 } | |
|
kinuko
2014/03/05 08:35:44
nit: no need of { } for one-line body
Fady Samuel
2014/03/06 18:38:25
I prefer having them when the if statement has an
| |
| 620 } | |
| 621 | |
| 592 void ContentSettingsObserver::ClearBlockedContentSettings() { | 622 void ContentSettingsObserver::ClearBlockedContentSettings() { |
| 593 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 623 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 594 content_blocked_[i] = false; | 624 content_blocked_[i] = false; |
| 595 cached_storage_permissions_.clear(); | 625 cached_storage_permissions_.clear(); |
| 596 cached_script_permissions_.clear(); | 626 cached_script_permissions_.clear(); |
| 597 } | 627 } |
| 598 | 628 |
| 599 const extensions::Extension* ContentSettingsObserver::GetExtension( | 629 const extensions::Extension* ContentSettingsObserver::GetExtension( |
| 600 const WebSecurityOrigin& origin) const { | 630 const WebSecurityOrigin& origin) const { |
| 601 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) | 631 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 | 679 |
| 650 // If the scheme is file:, an empty file name indicates a directory listing, | 680 // If the scheme is file:, an empty file name indicates a directory listing, |
| 651 // which requires JavaScript to function properly. | 681 // which requires JavaScript to function properly. |
| 652 if (EqualsASCII(origin.protocol(), content::kFileScheme)) { | 682 if (EqualsASCII(origin.protocol(), content::kFileScheme)) { |
| 653 return document_url.SchemeIs(content::kFileScheme) && | 683 return document_url.SchemeIs(content::kFileScheme) && |
| 654 document_url.ExtractFileName().empty(); | 684 document_url.ExtractFileName().empty(); |
| 655 } | 685 } |
| 656 | 686 |
| 657 return false; | 687 return false; |
| 658 } | 688 } |
| OLD | NEW |