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 "content/public/renderer/document_state.h" | 12 #include "content/public/renderer/document_state.h" |
13 #include "content/public/renderer/navigation_state.h" | 13 #include "content/public/renderer/navigation_state.h" |
14 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
16 #include "extensions/common/constants.h" | |
17 #include "extensions/common/extension.h" | |
18 #include "extensions/common/permissions/permissions_data.h" | |
19 #include "extensions/renderer/dispatcher.h" | |
20 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h" | 16 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h" |
21 #include "third_party/WebKit/public/platform/WebURL.h" | 17 #include "third_party/WebKit/public/platform/WebURL.h" |
22 #include "third_party/WebKit/public/web/WebDataSource.h" | 18 #include "third_party/WebKit/public/web/WebDataSource.h" |
23 #include "third_party/WebKit/public/web/WebDocument.h" | 19 #include "third_party/WebKit/public/web/WebDocument.h" |
24 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
25 #include "third_party/WebKit/public/web/WebFrameClient.h" | 21 #include "third_party/WebKit/public/web/WebFrameClient.h" |
26 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 22 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
27 #include "third_party/WebKit/public/web/WebView.h" | 23 #include "third_party/WebKit/public/web/WebView.h" |
28 | 24 |
29 #if defined(ENABLE_EXTENSIONS) | 25 #if defined(ENABLE_EXTENSIONS) |
30 #include "chrome/common/extensions/chrome_extension_messages.h" | 26 #include "chrome/common/extensions/chrome_extension_messages.h" |
27 #include "extensions/common/constants.h" | |
28 #include "extensions/common/extension.h" | |
29 #include "extensions/common/permissions/permissions_data.h" | |
Devlin
2014/08/12 15:34:59
Doesn't actually look like we use this at first gl
Lei Zhang
2014/08/12 23:03:17
deleted
| |
30 #include "extensions/renderer/dispatcher.h" | |
31 #endif | 31 #endif |
32 | 32 |
33 using blink::WebDataSource; | 33 using blink::WebDataSource; |
34 using blink::WebDocument; | 34 using blink::WebDocument; |
35 using blink::WebFrame; | 35 using blink::WebFrame; |
36 using blink::WebPermissionCallbacks; | 36 using blink::WebPermissionCallbacks; |
37 using blink::WebSecurityOrigin; | 37 using blink::WebSecurityOrigin; |
38 using blink::WebString; | 38 using blink::WebString; |
39 using blink::WebURL; | 39 using blink::WebURL; |
40 using blink::WebView; | 40 using blink::WebView; |
41 using content::DocumentState; | 41 using content::DocumentState; |
42 using content::NavigationState; | 42 using content::NavigationState; |
43 using extensions::APIPermission; | |
44 | 43 |
45 namespace { | 44 namespace { |
46 | 45 |
47 enum { | 46 enum { |
48 INSECURE_CONTENT_DISPLAY = 0, | 47 INSECURE_CONTENT_DISPLAY = 0, |
49 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE, | 48 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE, |
50 INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE, | 49 INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE, |
51 INSECURE_CONTENT_DISPLAY_HTML, | 50 INSECURE_CONTENT_DISPLAY_HTML, |
52 INSECURE_CONTENT_RUN, | 51 INSECURE_CONTENT_RUN, |
53 INSECURE_CONTENT_RUN_HOST_GOOGLE, | 52 INSECURE_CONTENT_RUN_HOST_GOOGLE, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 } | 146 } |
148 | 147 |
149 } // namespace | 148 } // namespace |
150 | 149 |
151 ContentSettingsObserver::ContentSettingsObserver( | 150 ContentSettingsObserver::ContentSettingsObserver( |
152 content::RenderFrame* render_frame, | 151 content::RenderFrame* render_frame, |
153 extensions::Dispatcher* extension_dispatcher) | 152 extensions::Dispatcher* extension_dispatcher) |
154 : content::RenderFrameObserver(render_frame), | 153 : content::RenderFrameObserver(render_frame), |
155 content::RenderFrameObserverTracker<ContentSettingsObserver>( | 154 content::RenderFrameObserverTracker<ContentSettingsObserver>( |
156 render_frame), | 155 render_frame), |
156 #if defined(ENABLE_EXTENSIONS) | |
157 extension_dispatcher_(extension_dispatcher), | 157 extension_dispatcher_(extension_dispatcher), |
158 #endif | |
158 allow_displaying_insecure_content_(false), | 159 allow_displaying_insecure_content_(false), |
159 allow_running_insecure_content_(false), | 160 allow_running_insecure_content_(false), |
160 content_setting_rules_(NULL), | 161 content_setting_rules_(NULL), |
161 is_interstitial_page_(false), | 162 is_interstitial_page_(false), |
162 npapi_plugins_blocked_(false), | 163 npapi_plugins_blocked_(false), |
163 current_request_id_(0) { | 164 current_request_id_(0) { |
164 ClearBlockedContentSettings(); | 165 ClearBlockedContentSettings(); |
165 render_frame->GetWebFrame()->setPermissionClient(this); | 166 render_frame->GetWebFrame()->setPermissionClient(this); |
166 | 167 |
167 if (render_frame->GetRenderView()->GetMainRenderFrame() != render_frame) { | 168 if (render_frame->GetRenderView()->GetMainRenderFrame() != render_frame) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 bool allowed = false; | 423 bool allowed = false; |
423 #if defined(ENABLE_EXTENSIONS) | 424 #if defined(ENABLE_EXTENSIONS) |
424 WebFrame* frame = render_frame()->GetWebFrame(); | 425 WebFrame* frame = render_frame()->GetWebFrame(); |
425 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite( | 426 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite( |
426 GURL(frame->document().securityOrigin().toString()), &allowed)); | 427 GURL(frame->document().securityOrigin().toString()), &allowed)); |
427 #endif | 428 #endif |
428 return allowed; | 429 return allowed; |
429 } | 430 } |
430 | 431 |
431 bool ContentSettingsObserver::allowMutationEvents(bool default_value) { | 432 bool ContentSettingsObserver::allowMutationEvents(bool default_value) { |
433 #if defined(ENABLE_EXTENSIONS) | |
432 WebFrame* frame = render_frame()->GetWebFrame(); | 434 WebFrame* frame = render_frame()->GetWebFrame(); |
433 WebSecurityOrigin origin = frame->document().securityOrigin(); | 435 WebSecurityOrigin origin = frame->document().securityOrigin(); |
434 const extensions::Extension* extension = GetExtension(origin); | 436 const extensions::Extension* extension = GetExtension(origin); |
435 if (extension && extension->is_platform_app()) | 437 if (extension && extension->is_platform_app()) |
436 return false; | 438 return false; |
439 #endif | |
437 return default_value; | 440 return default_value; |
438 } | 441 } |
439 | 442 |
440 bool ContentSettingsObserver::allowPushState() { | 443 bool ContentSettingsObserver::allowPushState() { |
444 #if defined(ENABLE_EXTENSIONS) | |
441 WebFrame* frame = render_frame()->GetWebFrame(); | 445 WebFrame* frame = render_frame()->GetWebFrame(); |
Devlin
2014/08/12 15:34:59
This and the code in allowMutationEvents looks ver
Lei Zhang
2014/08/12 23:03:17
[fry_squint] These two functions look similar.[/fr
Devlin
2014/08/12 23:16:12
:D
| |
442 WebSecurityOrigin origin = frame->document().securityOrigin(); | 446 WebSecurityOrigin origin = frame->document().securityOrigin(); |
443 const extensions::Extension* extension = GetExtension(origin); | 447 const extensions::Extension* extension = GetExtension(origin); |
444 return !extension || !extension->is_platform_app(); | 448 return !extension || !extension->is_platform_app(); |
449 #else | |
450 return true; | |
451 #endif | |
445 } | 452 } |
446 | 453 |
447 static void SendInsecureContentSignal(int signal) { | 454 static void SendInsecureContentSignal(int signal) { |
448 UMA_HISTOGRAM_ENUMERATION("SSL.InsecureContent", signal, | 455 UMA_HISTOGRAM_ENUMERATION("SSL.InsecureContent", signal, |
449 INSECURE_CONTENT_NUM_EVENTS); | 456 INSECURE_CONTENT_NUM_EVENTS); |
450 } | 457 } |
451 | 458 |
452 bool ContentSettingsObserver::allowDisplayingInsecureContent( | 459 bool ContentSettingsObserver::allowDisplayingInsecureContent( |
453 bool allowed_per_settings, | 460 bool allowed_per_settings, |
454 const blink::WebSecurityOrigin& origin, | 461 const blink::WebSecurityOrigin& origin, |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 callbacks.doDeny(); | 635 callbacks.doDeny(); |
629 } | 636 } |
630 | 637 |
631 void ContentSettingsObserver::ClearBlockedContentSettings() { | 638 void ContentSettingsObserver::ClearBlockedContentSettings() { |
632 for (size_t i = 0; i < arraysize(content_blocked_); ++i) | 639 for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
633 content_blocked_[i] = false; | 640 content_blocked_[i] = false; |
634 cached_storage_permissions_.clear(); | 641 cached_storage_permissions_.clear(); |
635 cached_script_permissions_.clear(); | 642 cached_script_permissions_.clear(); |
636 } | 643 } |
637 | 644 |
645 #if defined(ENABLE_EXTENSIONS) | |
638 const extensions::Extension* ContentSettingsObserver::GetExtension( | 646 const extensions::Extension* ContentSettingsObserver::GetExtension( |
639 const WebSecurityOrigin& origin) const { | 647 const WebSecurityOrigin& origin) const { |
640 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) | 648 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) |
641 return NULL; | 649 return NULL; |
642 | 650 |
643 const std::string extension_id = origin.host().utf8().data(); | 651 const std::string extension_id = origin.host().utf8().data(); |
644 if (!extension_dispatcher_->IsExtensionActive(extension_id)) | 652 if (!extension_dispatcher_->IsExtensionActive(extension_id)) |
645 return NULL; | 653 return NULL; |
646 | 654 |
647 return extension_dispatcher_->extensions()->GetByID(extension_id); | 655 return extension_dispatcher_->extensions()->GetByID(extension_id); |
648 } | 656 } |
657 #endif | |
649 | 658 |
650 bool ContentSettingsObserver::IsWhitelistedForContentSettings( | 659 bool ContentSettingsObserver::IsWhitelistedForContentSettings( |
651 content::RenderFrame* frame) { | 660 content::RenderFrame* frame) { |
652 // Whitelist Instant processes. | 661 // Whitelist Instant processes. |
653 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess)) | 662 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess)) |
654 return true; | 663 return true; |
655 | 664 |
656 // Whitelist ftp directory listings, as they require JavaScript to function | 665 // Whitelist ftp directory listings, as they require JavaScript to function |
657 // properly. | 666 // properly. |
658 if (frame->IsFTPDirectoryListing()) | 667 if (frame->IsFTPDirectoryListing()) |
(...skipping 12 matching lines...) Expand all Loading... | |
671 | 680 |
672 if (origin.isUnique()) | 681 if (origin.isUnique()) |
673 return false; // Uninitialized document? | 682 return false; // Uninitialized document? |
674 | 683 |
675 if (EqualsASCII(origin.protocol(), content::kChromeUIScheme)) | 684 if (EqualsASCII(origin.protocol(), content::kChromeUIScheme)) |
676 return true; // Browser UI elements should still work. | 685 return true; // Browser UI elements should still work. |
677 | 686 |
678 if (EqualsASCII(origin.protocol(), content::kChromeDevToolsScheme)) | 687 if (EqualsASCII(origin.protocol(), content::kChromeDevToolsScheme)) |
679 return true; // DevTools UI elements should still work. | 688 return true; // DevTools UI elements should still work. |
680 | 689 |
690 #if defined(ENABLE_EXTENSIONS) | |
681 if (EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) | 691 if (EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) |
682 return true; | 692 return true; |
693 #endif | |
683 | 694 |
684 // TODO(creis, fsamuel): Remove this once the concept of swapped out | 695 // TODO(creis, fsamuel): Remove this once the concept of swapped out |
685 // RenderFrames goes away. | 696 // RenderFrames goes away. |
686 if (document_url == GURL(content::kSwappedOutURL)) | 697 if (document_url == GURL(content::kSwappedOutURL)) |
687 return true; | 698 return true; |
688 | 699 |
689 // If the scheme is file:, an empty file name indicates a directory listing, | 700 // If the scheme is file:, an empty file name indicates a directory listing, |
690 // which requires JavaScript to function properly. | 701 // which requires JavaScript to function properly. |
691 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { | 702 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { |
692 return document_url.SchemeIs(url::kFileScheme) && | 703 return document_url.SchemeIs(url::kFileScheme) && |
693 document_url.ExtractFileName().empty(); | 704 document_url.ExtractFileName().empty(); |
694 } | 705 } |
695 | 706 |
696 return false; | 707 return false; |
697 } | 708 } |
OLD | NEW |