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

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

Issue 464693002: ifdef extensions bits in ContentSettingsObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 4 months 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 "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/renderer/dispatcher.h"
31 #endif 30 #endif
32 31
33 using blink::WebDataSource; 32 using blink::WebDataSource;
34 using blink::WebDocument; 33 using blink::WebDocument;
35 using blink::WebFrame; 34 using blink::WebFrame;
36 using blink::WebPermissionCallbacks; 35 using blink::WebPermissionCallbacks;
37 using blink::WebSecurityOrigin; 36 using blink::WebSecurityOrigin;
38 using blink::WebString; 37 using blink::WebString;
39 using blink::WebURL; 38 using blink::WebURL;
40 using blink::WebView; 39 using blink::WebView;
41 using content::DocumentState; 40 using content::DocumentState;
42 using content::NavigationState; 41 using content::NavigationState;
43 using extensions::APIPermission;
44 42
45 namespace { 43 namespace {
46 44
47 enum { 45 enum {
48 INSECURE_CONTENT_DISPLAY = 0, 46 INSECURE_CONTENT_DISPLAY = 0,
49 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE, 47 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE,
50 INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE, 48 INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE,
51 INSECURE_CONTENT_DISPLAY_HTML, 49 INSECURE_CONTENT_DISPLAY_HTML,
52 INSECURE_CONTENT_RUN, 50 INSECURE_CONTENT_RUN,
53 INSECURE_CONTENT_RUN_HOST_GOOGLE, 51 INSECURE_CONTENT_RUN_HOST_GOOGLE,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 145 }
148 146
149 } // namespace 147 } // namespace
150 148
151 ContentSettingsObserver::ContentSettingsObserver( 149 ContentSettingsObserver::ContentSettingsObserver(
152 content::RenderFrame* render_frame, 150 content::RenderFrame* render_frame,
153 extensions::Dispatcher* extension_dispatcher) 151 extensions::Dispatcher* extension_dispatcher)
154 : content::RenderFrameObserver(render_frame), 152 : content::RenderFrameObserver(render_frame),
155 content::RenderFrameObserverTracker<ContentSettingsObserver>( 153 content::RenderFrameObserverTracker<ContentSettingsObserver>(
156 render_frame), 154 render_frame),
155 #if defined(ENABLE_EXTENSIONS)
157 extension_dispatcher_(extension_dispatcher), 156 extension_dispatcher_(extension_dispatcher),
157 #endif
158 allow_displaying_insecure_content_(false), 158 allow_displaying_insecure_content_(false),
159 allow_running_insecure_content_(false), 159 allow_running_insecure_content_(false),
160 content_setting_rules_(NULL), 160 content_setting_rules_(NULL),
161 is_interstitial_page_(false), 161 is_interstitial_page_(false),
162 npapi_plugins_blocked_(false), 162 npapi_plugins_blocked_(false),
163 current_request_id_(0) { 163 current_request_id_(0) {
164 ClearBlockedContentSettings(); 164 ClearBlockedContentSettings();
165 render_frame->GetWebFrame()->setPermissionClient(this); 165 render_frame->GetWebFrame()->setPermissionClient(this);
166 166
167 if (render_frame->GetRenderView()->GetMainRenderFrame() != render_frame) { 167 if (render_frame->GetRenderView()->GetMainRenderFrame() != render_frame) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 bool allowed = false; 422 bool allowed = false;
423 #if defined(ENABLE_EXTENSIONS) 423 #if defined(ENABLE_EXTENSIONS)
424 WebFrame* frame = render_frame()->GetWebFrame(); 424 WebFrame* frame = render_frame()->GetWebFrame();
425 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite( 425 Send(new ChromeViewHostMsg_CanTriggerClipboardWrite(
426 GURL(frame->document().securityOrigin().toString()), &allowed)); 426 GURL(frame->document().securityOrigin().toString()), &allowed));
427 #endif 427 #endif
428 return allowed; 428 return allowed;
429 } 429 }
430 430
431 bool ContentSettingsObserver::allowMutationEvents(bool default_value) { 431 bool ContentSettingsObserver::allowMutationEvents(bool default_value) {
432 WebFrame* frame = render_frame()->GetWebFrame(); 432 return IsPlatformApp() ? false : default_value;
433 WebSecurityOrigin origin = frame->document().securityOrigin();
434 const extensions::Extension* extension = GetExtension(origin);
435 if (extension && extension->is_platform_app())
436 return false;
437 return default_value;
438 } 433 }
439 434
440 bool ContentSettingsObserver::allowPushState() { 435 bool ContentSettingsObserver::allowPushState() {
441 WebFrame* frame = render_frame()->GetWebFrame(); 436 return !IsPlatformApp();
442 WebSecurityOrigin origin = frame->document().securityOrigin();
443 const extensions::Extension* extension = GetExtension(origin);
444 return !extension || !extension->is_platform_app();
445 } 437 }
446 438
447 static void SendInsecureContentSignal(int signal) { 439 static void SendInsecureContentSignal(int signal) {
448 UMA_HISTOGRAM_ENUMERATION("SSL.InsecureContent", signal, 440 UMA_HISTOGRAM_ENUMERATION("SSL.InsecureContent", signal,
449 INSECURE_CONTENT_NUM_EVENTS); 441 INSECURE_CONTENT_NUM_EVENTS);
450 } 442 }
451 443
452 bool ContentSettingsObserver::allowDisplayingInsecureContent( 444 bool ContentSettingsObserver::allowDisplayingInsecureContent(
453 bool allowed_per_settings, 445 bool allowed_per_settings,
454 const blink::WebSecurityOrigin& origin, 446 const blink::WebSecurityOrigin& origin,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 callbacks.doDeny(); 620 callbacks.doDeny();
629 } 621 }
630 622
631 void ContentSettingsObserver::ClearBlockedContentSettings() { 623 void ContentSettingsObserver::ClearBlockedContentSettings() {
632 for (size_t i = 0; i < arraysize(content_blocked_); ++i) 624 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
633 content_blocked_[i] = false; 625 content_blocked_[i] = false;
634 cached_storage_permissions_.clear(); 626 cached_storage_permissions_.clear();
635 cached_script_permissions_.clear(); 627 cached_script_permissions_.clear();
636 } 628 }
637 629
630 bool ContentSettingsObserver::IsPlatformApp() {
631 #if defined(ENABLE_EXTENSIONS)
632 WebFrame* frame = render_frame()->GetWebFrame();
633 WebSecurityOrigin origin = frame->document().securityOrigin();
634 const extensions::Extension* extension = GetExtension(origin);
Devlin 2014/08/12 23:16:12 Any reason to not save a couple ifdefs and just in
Lei Zhang 2014/08/12 23:18:06 It's already there and it's very obvious what it d
Devlin 2014/08/12 23:20:47 Yeah. I just think that ifdefs in general make co
635 return extension && extension->is_platform_app();
636 #else
637 return false;
638 #endif
639 }
640
641 #if defined(ENABLE_EXTENSIONS)
638 const extensions::Extension* ContentSettingsObserver::GetExtension( 642 const extensions::Extension* ContentSettingsObserver::GetExtension(
639 const WebSecurityOrigin& origin) const { 643 const WebSecurityOrigin& origin) const {
640 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) 644 if (!EqualsASCII(origin.protocol(), extensions::kExtensionScheme))
641 return NULL; 645 return NULL;
642 646
643 const std::string extension_id = origin.host().utf8().data(); 647 const std::string extension_id = origin.host().utf8().data();
644 if (!extension_dispatcher_->IsExtensionActive(extension_id)) 648 if (!extension_dispatcher_->IsExtensionActive(extension_id))
645 return NULL; 649 return NULL;
646 650
647 return extension_dispatcher_->extensions()->GetByID(extension_id); 651 return extension_dispatcher_->extensions()->GetByID(extension_id);
648 } 652 }
653 #endif
649 654
650 bool ContentSettingsObserver::IsWhitelistedForContentSettings( 655 bool ContentSettingsObserver::IsWhitelistedForContentSettings(
651 content::RenderFrame* frame) { 656 content::RenderFrame* frame) {
652 // Whitelist Instant processes. 657 // Whitelist Instant processes.
653 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess)) 658 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInstantProcess))
654 return true; 659 return true;
655 660
656 // Whitelist ftp directory listings, as they require JavaScript to function 661 // Whitelist ftp directory listings, as they require JavaScript to function
657 // properly. 662 // properly.
658 if (frame->IsFTPDirectoryListing()) 663 if (frame->IsFTPDirectoryListing())
(...skipping 12 matching lines...) Expand all
671 676
672 if (origin.isUnique()) 677 if (origin.isUnique())
673 return false; // Uninitialized document? 678 return false; // Uninitialized document?
674 679
675 if (EqualsASCII(origin.protocol(), content::kChromeUIScheme)) 680 if (EqualsASCII(origin.protocol(), content::kChromeUIScheme))
676 return true; // Browser UI elements should still work. 681 return true; // Browser UI elements should still work.
677 682
678 if (EqualsASCII(origin.protocol(), content::kChromeDevToolsScheme)) 683 if (EqualsASCII(origin.protocol(), content::kChromeDevToolsScheme))
679 return true; // DevTools UI elements should still work. 684 return true; // DevTools UI elements should still work.
680 685
686 #if defined(ENABLE_EXTENSIONS)
681 if (EqualsASCII(origin.protocol(), extensions::kExtensionScheme)) 687 if (EqualsASCII(origin.protocol(), extensions::kExtensionScheme))
682 return true; 688 return true;
689 #endif
683 690
684 // TODO(creis, fsamuel): Remove this once the concept of swapped out 691 // TODO(creis, fsamuel): Remove this once the concept of swapped out
685 // RenderFrames goes away. 692 // RenderFrames goes away.
686 if (document_url == GURL(content::kSwappedOutURL)) 693 if (document_url == GURL(content::kSwappedOutURL))
687 return true; 694 return true;
688 695
689 // If the scheme is file:, an empty file name indicates a directory listing, 696 // If the scheme is file:, an empty file name indicates a directory listing,
690 // which requires JavaScript to function properly. 697 // which requires JavaScript to function properly.
691 if (EqualsASCII(origin.protocol(), url::kFileScheme)) { 698 if (EqualsASCII(origin.protocol(), url::kFileScheme)) {
692 return document_url.SchemeIs(url::kFileScheme) && 699 return document_url.SchemeIs(url::kFileScheme) &&
693 document_url.ExtractFileName().empty(); 700 document_url.ExtractFileName().empty();
694 } 701 }
695 702
696 return false; 703 return false;
697 } 704 }
OLDNEW
« no previous file with comments | « chrome/renderer/content_settings_observer.h ('k') | chrome/renderer/content_settings_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698