OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/webui/settings/site_settings_handler.h" | 5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/i18n/number_formatting.h" | 13 #include "base/i18n/number_formatting.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
19 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" | 19 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" |
20 #include "chrome/browser/permissions/chooser_context_base.h" | 20 #include "chrome/browser/permissions/chooser_context_base.h" |
21 #include "chrome/browser/permissions/permission_manager.h" | |
22 #include "chrome/browser/permissions/permission_result.h" | |
21 #include "chrome/browser/permissions/permission_uma_util.h" | 23 #include "chrome/browser/permissions/permission_uma_util.h" |
22 #include "chrome/browser/permissions/permission_util.h" | 24 #include "chrome/browser/permissions/permission_util.h" |
23 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/webui/site_settings_helper.h" | 26 #include "chrome/browser/ui/webui/site_settings_helper.h" |
25 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 27 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
26 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
29 #include "components/content_settings/core/browser/content_settings_utils.h" | |
27 #include "components/content_settings/core/browser/host_content_settings_map.h" | 30 #include "components/content_settings/core/browser/host_content_settings_map.h" |
28 #include "components/content_settings/core/common/content_settings_types.h" | 31 #include "components/content_settings/core/common/content_settings_types.h" |
29 #include "components/crx_file/id_util.h" | 32 #include "components/crx_file/id_util.h" |
30 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/web_ui.h" | 35 #include "content/public/browser/web_ui.h" |
33 #include "content/public/common/page_zoom.h" | 36 #include "content/public/common/page_zoom.h" |
34 #include "content/public/common/url_constants.h" | 37 #include "content/public/common/url_constants.h" |
35 #include "extensions/browser/extension_registry.h" | 38 #include "extensions/browser/extension_registry.h" |
36 #include "extensions/common/permissions/api_permission.h" | 39 #include "extensions/common/permissions/api_permission.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 GURL launch_url = | 95 GURL launch_url = |
93 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get()); | 96 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get()); |
94 // Skip adding the launch URL if it is part of the web extent. | 97 // Skip adding the launch URL if it is part of the web extent. |
95 if (web_extent.MatchesURL(launch_url)) | 98 if (web_extent.MatchesURL(launch_url)) |
96 continue; | 99 continue; |
97 site_settings::AddExceptionForHostedApp( | 100 site_settings::AddExceptionForHostedApp( |
98 launch_url.spec(), *extension->get(), exceptions); | 101 launch_url.spec(), *extension->get(), exceptions); |
99 } | 102 } |
100 } | 103 } |
101 | 104 |
105 PermissionResult GetPermissionResultForOrigin(const GURL& requesting_origin, | |
106 const GURL& embedding_origin, | |
107 ContentSettingsType content_type, | |
108 Profile* profile) { | |
109 // TODO(patricialor): In future, PermissionManager should know about all | |
110 // content settings, not just the permissions, plus all the possible sources. | |
111 PermissionResult result(CONTENT_SETTING_DEFAULT, | |
112 PermissionStatusSource::UNSPECIFIED); | |
113 content_settings::SettingInfo info; | |
114 HostContentSettingsMap* map = | |
115 HostContentSettingsMapFactory::GetForProfile(profile); | |
116 std::unique_ptr<base::Value> value = map->GetWebsiteSetting( | |
117 requesting_origin, embedding_origin, content_type, std::string(), &info); | |
118 | |
119 // Retrieve the content setting. | |
120 if (PermissionUtil::IsPermission(content_type)) { | |
121 result = PermissionManager::Get(profile)->GetPermissionStatus( | |
122 content_type, requesting_origin, embedding_origin); | |
123 } else { | |
124 DCHECK(value.get()); | |
125 if (value->GetType() == base::Value::Type::INTEGER) | |
raymes
2017/06/19 04:13:12
Could this just be a DCHECK_EQ instead of a NOTREA
Patti Lor
2017/06/20 08:25:54
Done.
| |
126 result.content_setting = | |
127 content_settings::ValueToContentSetting(value.get()); | |
128 else | |
129 NOTREACHED(); | |
130 } | |
131 | |
132 // Retrieve the source of the content setting. The PermissionManager currently | |
133 // only knows about SAFE_BROWSING_BLACKLIST, KILL_SWITCH, MULTIPLE_DISMISSALS, | |
134 // and MULTIPLE_IGNORES, so overwrite the PermissionStatusSource if the source | |
135 // is none of those. | |
136 switch (result.source) { | |
137 case PermissionStatusSource::UNSPECIFIED: | |
138 break; | |
139 case PermissionStatusSource::SAFE_BROWSING_BLACKLIST: | |
140 case PermissionStatusSource::KILL_SWITCH: | |
141 case PermissionStatusSource::MULTIPLE_DISMISSALS: | |
142 case PermissionStatusSource::MULTIPLE_IGNORES: | |
143 return result; | |
144 case PermissionStatusSource::INSECURE_ORIGIN: | |
145 case PermissionStatusSource::ENTERPRISE_POLICY: | |
146 case PermissionStatusSource::EXTENSION: | |
raymes
2017/06/19 04:13:12
I think having the PermissionStatusSource's that a
Patti Lor
2017/06/20 08:25:54
Done (with the helper function approach). I realis
| |
147 // If these are now implemented, update this code to remove unnecessary | |
148 // calls to HostContentSettingsMap. | |
149 NOTREACHED(); | |
150 } | |
151 | |
152 result.source = | |
153 PermissionUtil::ConvertSettingSourceToPermissionStatusSource(info.source); | |
154 return result; | |
155 } | |
156 | |
102 } // namespace | 157 } // namespace |
103 | 158 |
104 | 159 |
105 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) | 160 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) |
106 : profile_(profile), observer_(this) { | 161 : profile_(profile), observer_(this) { |
107 } | 162 } |
108 | 163 |
109 SiteSettingsHandler::~SiteSettingsHandler() { | 164 SiteSettingsHandler::~SiteSettingsHandler() { |
110 } | 165 } |
111 | 166 |
(...skipping 24 matching lines...) Expand all Loading... | |
136 base::Unretained(this))); | 191 base::Unretained(this))); |
137 web_ui()->RegisterMessageCallback( | 192 web_ui()->RegisterMessageCallback( |
138 "getExceptionList", | 193 "getExceptionList", |
139 base::Bind(&SiteSettingsHandler::HandleGetExceptionList, | 194 base::Bind(&SiteSettingsHandler::HandleGetExceptionList, |
140 base::Unretained(this))); | 195 base::Unretained(this))); |
141 web_ui()->RegisterMessageCallback( | 196 web_ui()->RegisterMessageCallback( |
142 "resetCategoryPermissionForOrigin", | 197 "resetCategoryPermissionForOrigin", |
143 base::Bind(&SiteSettingsHandler::HandleResetCategoryPermissionForOrigin, | 198 base::Bind(&SiteSettingsHandler::HandleResetCategoryPermissionForOrigin, |
144 base::Unretained(this))); | 199 base::Unretained(this))); |
145 web_ui()->RegisterMessageCallback( | 200 web_ui()->RegisterMessageCallback( |
201 "getCategoryPermissionForOrigin", | |
202 base::Bind(&SiteSettingsHandler::HandleGetCategoryPermissionForOrigin, | |
203 base::Unretained(this))); | |
204 web_ui()->RegisterMessageCallback( | |
146 "setCategoryPermissionForOrigin", | 205 "setCategoryPermissionForOrigin", |
147 base::Bind(&SiteSettingsHandler::HandleSetCategoryPermissionForOrigin, | 206 base::Bind(&SiteSettingsHandler::HandleSetCategoryPermissionForOrigin, |
148 base::Unretained(this))); | 207 base::Unretained(this))); |
149 web_ui()->RegisterMessageCallback( | 208 web_ui()->RegisterMessageCallback( |
150 "getSiteDetails", | |
151 base::Bind(&SiteSettingsHandler::HandleGetSiteDetails, | |
152 base::Unretained(this))); | |
153 web_ui()->RegisterMessageCallback( | |
154 "isPatternValid", | 209 "isPatternValid", |
155 base::Bind(&SiteSettingsHandler::HandleIsPatternValid, | 210 base::Bind(&SiteSettingsHandler::HandleIsPatternValid, |
156 base::Unretained(this))); | 211 base::Unretained(this))); |
157 web_ui()->RegisterMessageCallback( | 212 web_ui()->RegisterMessageCallback( |
158 "updateIncognitoStatus", | 213 "updateIncognitoStatus", |
159 base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, | 214 base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, |
160 base::Unretained(this))); | 215 base::Unretained(this))); |
161 web_ui()->RegisterMessageCallback( | 216 web_ui()->RegisterMessageCallback( |
162 "fetchZoomLevels", | 217 "fetchZoomLevels", |
163 base::Bind(&SiteSettingsHandler::HandleFetchZoomLevels, | 218 base::Bind(&SiteSettingsHandler::HandleFetchZoomLevels, |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 profile, primary_pattern, secondary_pattern, content_type, | 549 profile, primary_pattern, secondary_pattern, content_type, |
495 PermissionSourceUI::SITE_SETTINGS); | 550 PermissionSourceUI::SITE_SETTINGS); |
496 | 551 |
497 map->SetContentSettingCustomScope(primary_pattern, secondary_pattern, | 552 map->SetContentSettingCustomScope(primary_pattern, secondary_pattern, |
498 content_type, "", CONTENT_SETTING_DEFAULT); | 553 content_type, "", CONTENT_SETTING_DEFAULT); |
499 | 554 |
500 WebSiteSettingsUmaUtil::LogPermissionChange( | 555 WebSiteSettingsUmaUtil::LogPermissionChange( |
501 content_type, ContentSetting::CONTENT_SETTING_DEFAULT); | 556 content_type, ContentSetting::CONTENT_SETTING_DEFAULT); |
502 } | 557 } |
503 | 558 |
559 void SiteSettingsHandler::HandleGetCategoryPermissionForOrigin( | |
560 const base::ListValue* args) { | |
561 AllowJavascript(); | |
562 | |
563 CHECK_EQ(4U, args->GetSize()); | |
564 const base::Value* callback_id; | |
565 CHECK(args->Get(0, &callback_id)); | |
566 std::string type; | |
567 CHECK(args->GetString(1, &type)); | |
568 std::string origin; | |
569 CHECK(args->GetString(2, &origin)); | |
570 std::string embedding_origin; | |
571 CHECK(args->GetString(3, &embedding_origin)); | |
572 | |
573 ContentSettingsType content_type = static_cast<ContentSettingsType>( | |
574 static_cast<int>(site_settings::ContentSettingsTypeFromGroupName(type))); | |
575 PermissionResult result = GetPermissionResultForOrigin( | |
576 GURL(origin), GURL(embedding_origin), content_type, profile_); | |
577 | |
578 std::string content_setting_string = | |
579 content_settings::ContentSettingToString(result.content_setting); | |
580 std::string source_string = ""; | |
581 switch (result.source) { | |
582 case PermissionStatusSource::UNSPECIFIED: | |
583 case PermissionStatusSource::SAFE_BROWSING_BLACKLIST: | |
584 case PermissionStatusSource::KILL_SWITCH: | |
585 case PermissionStatusSource::MULTIPLE_DISMISSALS: | |
586 case PermissionStatusSource::MULTIPLE_IGNORES: | |
587 case PermissionStatusSource::INSECURE_ORIGIN: | |
588 // TODO(patricialor): Plumb these sources through to the Web UI. | |
589 break; | |
590 case PermissionStatusSource::ENTERPRISE_POLICY: | |
591 source_string = site_settings::kPolicyProviderId; | |
592 break; | |
593 case PermissionStatusSource::EXTENSION: | |
594 source_string = site_settings::kExtensionProviderId; | |
595 break; | |
596 } | |
597 | |
598 auto raw_site_exception = base::MakeUnique<base::DictionaryValue>(); | |
raymes
2017/06/19 04:13:12
nit: what does raw mean here?
Patti Lor
2017/06/20 08:25:54
This method is supposed to return a RawSiteExcepti
raymes
2017/06/20 23:42:35
Thanks for explaining :)
Patti Lor
2017/06/21 06:36:37
Acknowledged :D
| |
599 raw_site_exception->SetString(site_settings::kEmbeddingOrigin, | |
600 embedding_origin); | |
601 raw_site_exception->SetBoolean(site_settings::kIncognito, | |
602 profile_->IsOffTheRecord()); | |
603 raw_site_exception->SetString(site_settings::kOrigin, origin); | |
604 raw_site_exception->SetString(site_settings::kDisplayName, origin); | |
605 raw_site_exception->SetString(site_settings::kSetting, | |
606 content_setting_string); | |
607 raw_site_exception->SetString(site_settings::kSource, source_string); | |
608 // The remaining "embeddingDisplayName" field is handled later in Javascript. | |
609 | |
610 ResolveJavascriptCallback(*callback_id, *raw_site_exception); | |
611 } | |
612 | |
504 void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( | 613 void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( |
505 const base::ListValue* args) { | 614 const base::ListValue* args) { |
506 CHECK_EQ(5U, args->GetSize()); | 615 CHECK_EQ(5U, args->GetSize()); |
507 std::string primary_pattern_string; | 616 std::string primary_pattern_string; |
508 CHECK(args->GetString(0, &primary_pattern_string)); | 617 CHECK(args->GetString(0, &primary_pattern_string)); |
509 // TODO(dschuyler): Review whether |secondary_pattern_string| should be used. | 618 // TODO(dschuyler): Review whether |secondary_pattern_string| should be used. |
510 std::string secondary_pattern_string; | 619 std::string secondary_pattern_string; |
511 CHECK(args->GetString(1, &secondary_pattern_string)); | 620 CHECK(args->GetString(1, &secondary_pattern_string)); |
512 std::string type; | 621 std::string type; |
513 CHECK(args->GetString(2, &type)); | 622 CHECK(args->GetString(2, &type)); |
(...skipping 30 matching lines...) Expand all Loading... | |
544 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( | 653 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
545 profile, primary_pattern, secondary_pattern, content_type, | 654 profile, primary_pattern, secondary_pattern, content_type, |
546 PermissionSourceUI::SITE_SETTINGS); | 655 PermissionSourceUI::SITE_SETTINGS); |
547 | 656 |
548 map->SetContentSettingCustomScope(primary_pattern, secondary_pattern, | 657 map->SetContentSettingCustomScope(primary_pattern, secondary_pattern, |
549 content_type, "", setting); | 658 content_type, "", setting); |
550 | 659 |
551 WebSiteSettingsUmaUtil::LogPermissionChange(content_type, setting); | 660 WebSiteSettingsUmaUtil::LogPermissionChange(content_type, setting); |
552 } | 661 } |
553 | 662 |
554 void SiteSettingsHandler::HandleGetSiteDetails( | |
555 const base::ListValue* args) { | |
556 AllowJavascript(); | |
557 | |
558 CHECK_EQ(2U, args->GetSize()); | |
559 const base::Value* callback_id; | |
560 CHECK(args->Get(0, &callback_id)); | |
561 std::string site; | |
562 CHECK(args->GetString(1, &site)); | |
563 | |
564 // A subset of the ContentSettingsType enum that we show in the settings UI. | |
565 const ContentSettingsType kSettingsDetailTypes[] = { | |
566 CONTENT_SETTINGS_TYPE_COOKIES, | |
567 CONTENT_SETTINGS_TYPE_IMAGES, | |
568 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
569 CONTENT_SETTINGS_TYPE_PLUGINS, | |
570 CONTENT_SETTINGS_TYPE_POPUPS, | |
571 CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
572 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
573 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | |
574 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | |
575 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, | |
576 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | |
577 CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC, | |
578 CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, | |
579 CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, | |
580 }; | |
581 | |
582 // Create a list to be consistent with existing API, we are expecting a single | |
583 // element (or none). | |
584 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); | |
585 for (size_t type = 0; type < arraysize(kSettingsDetailTypes); ++type) { | |
586 ContentSettingsType content_type = kSettingsDetailTypes[type]; | |
587 | |
588 HostContentSettingsMap* map = | |
589 HostContentSettingsMapFactory::GetForProfile(profile_); | |
590 const auto* extension_registry = | |
591 extensions::ExtensionRegistry::Get(profile_); | |
592 site_settings::GetExceptionsFromHostContentSettingsMap( | |
593 map, content_type, extension_registry, web_ui(), /*incognito=*/false, | |
594 /*filter=*/&site, exceptions.get()); | |
595 | |
596 if (profile_->HasOffTheRecordProfile()) { | |
597 Profile* incognito = profile_->GetOffTheRecordProfile(); | |
598 map = HostContentSettingsMapFactory::GetForProfile(incognito); | |
599 extension_registry = extensions::ExtensionRegistry::Get(incognito); | |
600 site_settings::GetExceptionsFromHostContentSettingsMap( | |
601 map, content_type, extension_registry, web_ui(), /*incognito=*/true, | |
602 /*filter=*/&site, exceptions.get()); | |
603 } | |
604 } | |
605 | |
606 if (!exceptions->GetSize()) { | |
607 RejectJavascriptCallback(*callback_id, base::Value()); | |
608 return; | |
609 } | |
610 | |
611 // We only need a single response element. | |
612 const base::DictionaryValue* exception = nullptr; | |
613 exceptions->GetDictionary(0, &exception); | |
614 ResolveJavascriptCallback(*callback_id, *exception); | |
615 } | |
616 | |
617 void SiteSettingsHandler::HandleIsPatternValid( | 663 void SiteSettingsHandler::HandleIsPatternValid( |
618 const base::ListValue* args) { | 664 const base::ListValue* args) { |
619 CHECK_EQ(2U, args->GetSize()); | 665 CHECK_EQ(2U, args->GetSize()); |
620 const base::Value* callback_id; | 666 const base::Value* callback_id; |
621 CHECK(args->Get(0, &callback_id)); | 667 CHECK(args->Get(0, &callback_id)); |
622 std::string pattern_string; | 668 std::string pattern_string; |
623 CHECK(args->GetString(1, &pattern_string)); | 669 CHECK(args->GetString(1, &pattern_string)); |
624 | 670 |
625 ContentSettingsPattern pattern = | 671 ContentSettingsPattern pattern = |
626 ContentSettingsPattern::FromString(pattern_string); | 672 ContentSettingsPattern::FromString(pattern_string); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 origin = content::kUnreachableWebDataURL; | 795 origin = content::kUnreachableWebDataURL; |
750 } | 796 } |
751 | 797 |
752 content::HostZoomMap* host_zoom_map; | 798 content::HostZoomMap* host_zoom_map; |
753 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); | 799 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); |
754 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 800 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
755 host_zoom_map->SetZoomLevelForHost(origin, default_level); | 801 host_zoom_map->SetZoomLevelForHost(origin, default_level); |
756 } | 802 } |
757 | 803 |
758 } // namespace settings | 804 } // namespace settings |
OLD | NEW |