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

Side by Side Diff: chrome/browser/content_settings/tab_specific_content_settings.cc

Issue 2377603002: Disable ServiceWorker when JS is disabled (Closed)
Patch Set: Updated comments, removed the mock headers and renamed the function Created 4 years, 2 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
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/browser/content_settings/tab_specific_content_settings.h" 5 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 Profile::FromBrowserContext(tab->GetBrowserContext())), 99 Profile::FromBrowserContext(tab->GetBrowserContext())),
100 CONTENT_SETTINGS_TYPE_MIDI_SYSEX), 100 CONTENT_SETTINGS_TYPE_MIDI_SYSEX),
101 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), 101 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()),
102 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), 102 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()),
103 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), 103 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT),
104 load_plugins_link_enabled_(true), 104 load_plugins_link_enabled_(true),
105 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), 105 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED),
106 subresource_filter_enabled_(false), 106 subresource_filter_enabled_(false),
107 subresource_filter_blockage_indicated_(false), 107 subresource_filter_blockage_indicated_(false),
108 observer_(this) { 108 observer_(this) {
109 ClearBlockedContentSettingsExceptForCookies(); 109 ClearContentSettingsExceptForNavigationRelatedSettings();
110 ClearCookieSpecificContentSettings(); 110 ClearNavigationRelatedContentSettings();
111 111
112 observer_.Add(HostContentSettingsMapFactory::GetForProfile( 112 observer_.Add(HostContentSettingsMapFactory::GetForProfile(
113 Profile::FromBrowserContext(tab->GetBrowserContext()))); 113 Profile::FromBrowserContext(tab->GetBrowserContext())));
114 } 114 }
115 115
116 TabSpecificContentSettings::~TabSpecificContentSettings() { 116 TabSpecificContentSettings::~TabSpecificContentSettings() {
117 FOR_EACH_OBSERVER( 117 FOR_EACH_OBSERVER(
118 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); 118 SiteDataObserver, observer_list_, ContentSettingsDestroyed());
119 } 119 }
120 120
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const GURL& url, 210 const GURL& url,
211 bool blocked_by_policy) { 211 bool blocked_by_policy) {
212 DCHECK_CURRENTLY_ON(BrowserThread::UI); 212 DCHECK_CURRENTLY_ON(BrowserThread::UI);
213 TabSpecificContentSettings* settings = GetForFrame( 213 TabSpecificContentSettings* settings = GetForFrame(
214 render_process_id, render_frame_id); 214 render_process_id, render_frame_id);
215 if (settings) 215 if (settings)
216 settings->OnFileSystemAccessed(url, blocked_by_policy); 216 settings->OnFileSystemAccessed(url, blocked_by_policy);
217 } 217 }
218 218
219 // static 219 // static
220 void TabSpecificContentSettings::ServiceWorkerAccessed(int render_process_id, 220 void TabSpecificContentSettings::ServiceWorkerAccessed(
221 int render_frame_id, 221 int render_process_id,
222 const GURL& scope, 222 int render_frame_id,
223 bool blocked_by_policy) { 223 const GURL& scope,
224 bool blocked_by_policy_javascript,
225 bool blocked_by_policy_cookie) {
224 DCHECK_CURRENTLY_ON(BrowserThread::UI); 226 DCHECK_CURRENTLY_ON(BrowserThread::UI);
225 TabSpecificContentSettings* settings = 227 TabSpecificContentSettings* settings =
226 GetForFrame(render_process_id, render_frame_id); 228 GetForFrame(render_process_id, render_frame_id);
227 if (settings) 229 if (settings)
228 settings->OnServiceWorkerAccessed(scope, blocked_by_policy); 230 settings->OnServiceWorkerAccessed(scope, blocked_by_policy_javascript,
231 blocked_by_policy_cookie);
229 } 232 }
230 233
231 bool TabSpecificContentSettings::IsContentBlocked( 234 bool TabSpecificContentSettings::IsContentBlocked(
232 ContentSettingsType content_type) const { 235 ContentSettingsType content_type) const {
233 DCHECK_NE(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type) 236 DCHECK_NE(CONTENT_SETTINGS_TYPE_GEOLOCATION, content_type)
234 << "Geolocation settings handled by ContentSettingGeolocationImageModel"; 237 << "Geolocation settings handled by ContentSettingGeolocationImageModel";
235 DCHECK_NE(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, content_type) 238 DCHECK_NE(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, content_type)
236 << "Notifications settings handled by " 239 << "Notifications settings handled by "
237 << "ContentSettingsNotificationsImageModel"; 240 << "ContentSettingsNotificationsImageModel";
238 241
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (blocked_by_policy) 466 if (blocked_by_policy)
464 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); 467 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
465 else 468 else
466 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); 469 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
467 470
468 NotifySiteDataObservers(); 471 NotifySiteDataObservers();
469 } 472 }
470 473
471 void TabSpecificContentSettings::OnServiceWorkerAccessed( 474 void TabSpecificContentSettings::OnServiceWorkerAccessed(
472 const GURL& scope, 475 const GURL& scope,
473 bool blocked_by_policy) { 476 bool blocked_by_policy_javascript,
477 bool blocked_by_policy_cookie) {
474 DCHECK(scope.is_valid()); 478 DCHECK(scope.is_valid());
475 if (blocked_by_policy) { 479 if (blocked_by_policy_javascript || blocked_by_policy_cookie) {
476 blocked_local_shared_objects_.service_workers()->AddServiceWorker( 480 blocked_local_shared_objects_.service_workers()->AddServiceWorker(
477 scope.GetOrigin(), std::vector<GURL>(1, scope)); 481 scope.GetOrigin(), std::vector<GURL>(1, scope));
478 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
479 } else { 482 } else {
480 allowed_local_shared_objects_.service_workers()->AddServiceWorker( 483 allowed_local_shared_objects_.service_workers()->AddServiceWorker(
481 scope.GetOrigin(), std::vector<GURL>(1, scope)); 484 scope.GetOrigin(), std::vector<GURL>(1, scope));
485 }
486
487 if (blocked_by_policy_javascript) {
488 OnContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
489 } else {
490 OnContentAllowed(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
491 }
492 if (blocked_by_policy_cookie) {
493 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
494 } else {
482 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); 495 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
483 } 496 }
484 } 497 }
485 498
486 void TabSpecificContentSettings::OnWebDatabaseAccessed( 499 void TabSpecificContentSettings::OnWebDatabaseAccessed(
487 const GURL& url, 500 const GURL& url,
488 const base::string16& name, 501 const base::string16& name,
489 const base::string16& display_name, 502 const base::string16& display_name,
490 bool blocked_by_policy) { 503 bool blocked_by_policy) {
491 if (blocked_by_policy) { 504 if (blocked_by_policy) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 midi_usages_state_.OnPermissionSet(requesting_origin, true); 657 midi_usages_state_.OnPermissionSet(requesting_origin, true);
645 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 658 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
646 } 659 }
647 660
648 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( 661 void TabSpecificContentSettings::OnMidiSysExAccessBlocked(
649 const GURL& requesting_origin) { 662 const GURL& requesting_origin) {
650 midi_usages_state_.OnPermissionSet(requesting_origin, false); 663 midi_usages_state_.OnPermissionSet(requesting_origin, false);
651 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 664 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
652 } 665 }
653 666
654 void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() { 667 void TabSpecificContentSettings::
668 ClearContentSettingsExceptForNavigationRelatedSettings() {
655 for (auto& status : content_settings_status_) { 669 for (auto& status : content_settings_status_) {
656 if (status.first == CONTENT_SETTINGS_TYPE_COOKIES) 670 if (status.first == CONTENT_SETTINGS_TYPE_COOKIES ||
671 status.first == CONTENT_SETTINGS_TYPE_JAVASCRIPT)
657 continue; 672 continue;
658 status.second.blocked = false; 673 status.second.blocked = false;
659 status.second.blockage_indicated_to_user = false; 674 status.second.blockage_indicated_to_user = false;
660 status.second.allowed = false; 675 status.second.allowed = false;
661 } 676 }
662 microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED; 677 microphone_camera_state_ = MICROPHONE_CAMERA_NOT_ACCESSED;
663 load_plugins_link_enabled_ = true; 678 load_plugins_link_enabled_ = true;
664 content::NotificationService::current()->Notify( 679 content::NotificationService::current()->Notify(
665 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 680 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
666 content::Source<WebContents>(web_contents()), 681 content::Source<WebContents>(web_contents()),
667 content::NotificationService::NoDetails()); 682 content::NotificationService::NoDetails());
668 } 683 }
669 684
670 void TabSpecificContentSettings::ClearCookieSpecificContentSettings() { 685 void TabSpecificContentSettings::ClearNavigationRelatedContentSettings() {
671 blocked_local_shared_objects_.Reset(); 686 blocked_local_shared_objects_.Reset();
672 allowed_local_shared_objects_.Reset(); 687 allowed_local_shared_objects_.Reset();
673 ContentSettingsStatus& status = 688 for (ContentSettingsType type :
674 content_settings_status_[CONTENT_SETTINGS_TYPE_COOKIES]; 689 {CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTINGS_TYPE_JAVASCRIPT}) {
675 status.blocked = false; 690 ContentSettingsStatus& status =
676 status.blockage_indicated_to_user = false; 691 content_settings_status_[type];
677 status.allowed = false; 692 status.blocked = false;
693 status.blockage_indicated_to_user = false;
694 status.allowed = false;
695 }
678 content::NotificationService::current()->Notify( 696 content::NotificationService::current()->Notify(
679 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 697 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
680 content::Source<WebContents>(web_contents()), 698 content::Source<WebContents>(web_contents()),
681 content::NotificationService::NoDetails()); 699 content::NotificationService::NoDetails());
682 } 700 }
683 701
684 void TabSpecificContentSettings::SetDownloadsBlocked(bool blocked) { 702 void TabSpecificContentSettings::SetDownloadsBlocked(bool blocked) {
685 ContentSettingsStatus& status = 703 ContentSettingsStatus& status =
686 content_settings_status_[CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS]; 704 content_settings_status_[CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS];
687 status.blocked = blocked; 705 status.blocked = blocked;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 web_contents()->GetController(); 802 web_contents()->GetController();
785 content::NavigationEntry* last_committed_entry = 803 content::NavigationEntry* last_committed_entry =
786 controller.GetLastCommittedEntry(); 804 controller.GetLastCommittedEntry();
787 if (last_committed_entry) 805 if (last_committed_entry)
788 previous_url_ = last_committed_entry->GetURL(); 806 previous_url_ = last_committed_entry->GetURL();
789 807
790 // If we're displaying a network error page do not reset the content 808 // If we're displaying a network error page do not reset the content
791 // settings delegate's cookies so the user has a chance to modify cookie 809 // settings delegate's cookies so the user has a chance to modify cookie
792 // settings. 810 // settings.
793 if (!navigation_handle->IsErrorPage()) 811 if (!navigation_handle->IsErrorPage())
794 ClearCookieSpecificContentSettings(); 812 ClearNavigationRelatedContentSettings();
795 ClearGeolocationContentSettings(); 813 ClearGeolocationContentSettings();
796 ClearMidiContentSettings(); 814 ClearMidiContentSettings();
797 ClearPendingProtocolHandler(); 815 ClearPendingProtocolHandler();
798 } 816 }
799 817
800 void TabSpecificContentSettings::DidFinishNavigation( 818 void TabSpecificContentSettings::DidFinishNavigation(
801 content::NavigationHandle* navigation_handle) { 819 content::NavigationHandle* navigation_handle) {
802 if (!navigation_handle->IsInMainFrame() || 820 if (!navigation_handle->IsInMainFrame() ||
803 !navigation_handle->HasCommitted() || 821 !navigation_handle->HasCommitted() ||
804 navigation_handle->IsSamePage()) { 822 navigation_handle->IsSamePage()) {
805 return; 823 return;
806 } 824 }
807 825
808 // Clear "blocked" flags. 826 // Clear "blocked" flags.
809 ClearBlockedContentSettingsExceptForCookies(); 827 ClearContentSettingsExceptForNavigationRelatedSettings();
810 blocked_plugin_names_.clear(); 828 blocked_plugin_names_.clear();
811 GeolocationDidNavigate(navigation_handle); 829 GeolocationDidNavigate(navigation_handle);
812 MidiDidNavigate(navigation_handle); 830 MidiDidNavigate(navigation_handle);
813 831
814 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) { 832 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) {
815 content_settings::RecordPluginsAction( 833 content_settings::RecordPluginsAction(
816 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS); 834 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS);
817 } 835 }
818 } 836 }
819 837
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 static_cast<MicrophoneCameraStateFlags>( 904 static_cast<MicrophoneCameraStateFlags>(
887 TabSpecificContentSettings::MICROPHONE_ACCESSED | 905 TabSpecificContentSettings::MICROPHONE_ACCESSED |
888 TabSpecificContentSettings::MICROPHONE_BLOCKED | 906 TabSpecificContentSettings::MICROPHONE_BLOCKED |
889 TabSpecificContentSettings::CAMERA_ACCESSED | 907 TabSpecificContentSettings::CAMERA_ACCESSED |
890 TabSpecificContentSettings::CAMERA_BLOCKED); 908 TabSpecificContentSettings::CAMERA_BLOCKED);
891 OnMediaStreamPermissionSet( 909 OnMediaStreamPermissionSet(
892 web_contents()->GetLastCommittedURL(), 910 web_contents()->GetLastCommittedURL(),
893 media_blocked, 911 media_blocked,
894 std::string(), std::string(), std::string(), std::string()); 912 std::string(), std::string(), std::string(), std::string());
895 } 913 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698