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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/tab_specific_content_settings.cc
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc
index 4f3cebd152271ba631c9af344d0fe380fa4ae459..1638f4e1b2518480d6724339e79446c5b29575c7 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.cc
+++ b/chrome/browser/content_settings/tab_specific_content_settings.cc
@@ -106,8 +106,8 @@ TabSpecificContentSettings::TabSpecificContentSettings(WebContents* tab)
subresource_filter_enabled_(false),
subresource_filter_blockage_indicated_(false),
observer_(this) {
- ClearBlockedContentSettingsExceptForCookies();
- ClearCookieSpecificContentSettings();
+ ClearContentSettingsExceptForNavigationRelatedSettings();
+ ClearNavigationRelatedContentSettings();
observer_.Add(HostContentSettingsMapFactory::GetForProfile(
Profile::FromBrowserContext(tab->GetBrowserContext())));
@@ -217,15 +217,18 @@ void TabSpecificContentSettings::FileSystemAccessed(int render_process_id,
}
// static
-void TabSpecificContentSettings::ServiceWorkerAccessed(int render_process_id,
- int render_frame_id,
- const GURL& scope,
- bool blocked_by_policy) {
+void TabSpecificContentSettings::ServiceWorkerAccessed(
+ int render_process_id,
+ int render_frame_id,
+ const GURL& scope,
+ bool blocked_by_policy_javascript,
+ bool blocked_by_policy_cookie) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
TabSpecificContentSettings* settings =
GetForFrame(render_process_id, render_frame_id);
if (settings)
- settings->OnServiceWorkerAccessed(scope, blocked_by_policy);
+ settings->OnServiceWorkerAccessed(scope, blocked_by_policy_javascript,
+ blocked_by_policy_cookie);
}
bool TabSpecificContentSettings::IsContentBlocked(
@@ -470,15 +473,25 @@ void TabSpecificContentSettings::OnLocalStorageAccessed(
void TabSpecificContentSettings::OnServiceWorkerAccessed(
const GURL& scope,
- bool blocked_by_policy) {
+ bool blocked_by_policy_javascript,
+ bool blocked_by_policy_cookie) {
DCHECK(scope.is_valid());
- if (blocked_by_policy) {
+ if (blocked_by_policy_javascript || blocked_by_policy_cookie) {
blocked_local_shared_objects_.service_workers()->AddServiceWorker(
scope.GetOrigin(), std::vector<GURL>(1, scope));
- OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
} else {
allowed_local_shared_objects_.service_workers()->AddServiceWorker(
scope.GetOrigin(), std::vector<GURL>(1, scope));
+ }
+
+ if (blocked_by_policy_javascript) {
+ OnContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
+ } else {
+ OnContentAllowed(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
+ }
+ if (blocked_by_policy_cookie) {
+ OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
+ } else {
OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
}
}
@@ -651,9 +664,11 @@ void TabSpecificContentSettings::OnMidiSysExAccessBlocked(
OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
}
-void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() {
+void TabSpecificContentSettings::
+ClearContentSettingsExceptForNavigationRelatedSettings() {
for (auto& status : content_settings_status_) {
- if (status.first == CONTENT_SETTINGS_TYPE_COOKIES)
+ if (status.first == CONTENT_SETTINGS_TYPE_COOKIES ||
+ status.first == CONTENT_SETTINGS_TYPE_JAVASCRIPT)
continue;
status.second.blocked = false;
status.second.blockage_indicated_to_user = false;
@@ -667,14 +682,17 @@ void TabSpecificContentSettings::ClearBlockedContentSettingsExceptForCookies() {
content::NotificationService::NoDetails());
}
-void TabSpecificContentSettings::ClearCookieSpecificContentSettings() {
+void TabSpecificContentSettings::ClearNavigationRelatedContentSettings() {
blocked_local_shared_objects_.Reset();
allowed_local_shared_objects_.Reset();
- ContentSettingsStatus& status =
- content_settings_status_[CONTENT_SETTINGS_TYPE_COOKIES];
- status.blocked = false;
- status.blockage_indicated_to_user = false;
- status.allowed = false;
+ for (ContentSettingsType type :
+ {CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTINGS_TYPE_JAVASCRIPT}) {
+ ContentSettingsStatus& status =
+ content_settings_status_[type];
+ status.blocked = false;
+ status.blockage_indicated_to_user = false;
+ status.allowed = false;
+ }
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
content::Source<WebContents>(web_contents()),
@@ -791,7 +809,7 @@ void TabSpecificContentSettings::DidStartNavigation(
// settings delegate's cookies so the user has a chance to modify cookie
// settings.
if (!navigation_handle->IsErrorPage())
- ClearCookieSpecificContentSettings();
+ ClearNavigationRelatedContentSettings();
ClearGeolocationContentSettings();
ClearMidiContentSettings();
ClearPendingProtocolHandler();
@@ -806,7 +824,7 @@ void TabSpecificContentSettings::DidFinishNavigation(
}
// Clear "blocked" flags.
- ClearBlockedContentSettingsExceptForCookies();
+ ClearContentSettingsExceptForNavigationRelatedSettings();
blocked_plugin_names_.clear();
GeolocationDidNavigate(navigation_handle);
MidiDidNavigate(navigation_handle);

Powered by Google App Engine
This is Rietveld 408576698