| 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 // Retrieves the corresponding string, according to the following precedence |
| 106 // order from highest to lowest priority: |
| 107 // 1. Kill-switch. |
| 108 // 2. Enterprise policy. |
| 109 // 3. Extensions. |
| 110 // 4. User-set per-origin setting. |
| 111 // 5. Embargo. |
| 112 // 6. User-set patterns. |
| 113 // 7. User-set global default for a ContentSettingsType. |
| 114 // 8. Chrome's built-in default. |
| 115 std::string ConvertContentSettingSourceToString( |
| 116 content_settings::SettingSource content_settings_source, |
| 117 PermissionStatusSource permission_status_source) { |
| 118 // TODO(patricialor): Do some plumbing for sources #1, #2, #3, and #5 through |
| 119 // to the Web UI. Currently there aren't strings to represent these sources. |
| 120 if (permission_status_source == PermissionStatusSource::KILL_SWITCH) |
| 121 return site_settings::kPreferencesSource; // Source #1. |
| 122 |
| 123 if (content_settings_source == content_settings::SETTING_SOURCE_POLICY || |
| 124 content_settings_source == content_settings::SETTING_SOURCE_SUPERVISED) { |
| 125 return site_settings::kPolicyProviderId; // Source #2. |
| 126 } |
| 127 |
| 128 if (content_settings_source == content_settings::SETTING_SOURCE_EXTENSION) |
| 129 return site_settings::kExtensionProviderId; // Source #3. |
| 130 |
| 131 DCHECK_NE(content_settings::SETTING_SOURCE_NONE, content_settings_source); |
| 132 if (content_settings_source == content_settings::SETTING_SOURCE_USER) { |
| 133 if (permission_status_source == |
| 134 PermissionStatusSource::SAFE_BROWSING_BLACKLIST || |
| 135 permission_status_source == |
| 136 PermissionStatusSource::MULTIPLE_DISMISSALS || |
| 137 permission_status_source == PermissionStatusSource::MULTIPLE_IGNORES) { |
| 138 return site_settings::kPreferencesSource; // Source #5. |
| 139 } |
| 140 // Source #4, #6, #7, #8. When #4 is the source, |permission_status_source| |
| 141 // won't be set to any of the source #5 enum values, as PermissionManager is |
| 142 // aware of the difference between these two sources internally. The |
| 143 // subtlety here should go away when PermissionManager can handle all |
| 144 // content settings and all possible sources. |
| 145 return site_settings::kPreferencesSource; |
| 146 } |
| 147 |
| 148 NOTREACHED(); |
| 149 return site_settings::kPreferencesSource; |
| 150 } |
| 151 |
| 152 ContentSetting GetContentSettingForOrigin(const GURL& origin, |
| 153 ContentSettingsType content_type, |
| 154 Profile* profile, |
| 155 std::string* source_string) { |
| 156 // TODO(patricialor): In future, PermissionManager should know about all |
| 157 // content settings, not just the permissions, plus all the possible sources, |
| 158 // and the calls to HostContentSettingsMap should be removed. |
| 159 content_settings::SettingInfo info; |
| 160 HostContentSettingsMap* map = |
| 161 HostContentSettingsMapFactory::GetForProfile(profile); |
| 162 std::unique_ptr<base::Value> value = map->GetWebsiteSetting( |
| 163 origin, origin, content_type, std::string(), &info); |
| 164 |
| 165 // Retrieve the content setting. |
| 166 PermissionResult result(CONTENT_SETTING_DEFAULT, |
| 167 PermissionStatusSource::UNSPECIFIED); |
| 168 if (PermissionUtil::IsPermission(content_type)) { |
| 169 result = PermissionManager::Get(profile)->GetPermissionStatus( |
| 170 content_type, origin, origin); |
| 171 } else { |
| 172 DCHECK(value.get()); |
| 173 DCHECK_EQ(base::Value::Type::INTEGER, value->GetType()); |
| 174 result.content_setting = |
| 175 content_settings::ValueToContentSetting(value.get()); |
| 176 } |
| 177 |
| 178 // Retrieve the source of the content setting. |
| 179 *source_string = |
| 180 ConvertContentSettingSourceToString(info.source, result.source); |
| 181 return result.content_setting; |
| 182 } |
| 183 |
| 102 } // namespace | 184 } // namespace |
| 103 | 185 |
| 104 | 186 |
| 105 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) | 187 SiteSettingsHandler::SiteSettingsHandler(Profile* profile) |
| 106 : profile_(profile), observer_(this) { | 188 : profile_(profile), observer_(this) { |
| 107 } | 189 } |
| 108 | 190 |
| 109 SiteSettingsHandler::~SiteSettingsHandler() { | 191 SiteSettingsHandler::~SiteSettingsHandler() { |
| 110 } | 192 } |
| 111 | 193 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 132 base::Unretained(this))); | 214 base::Unretained(this))); |
| 133 web_ui()->RegisterMessageCallback( | 215 web_ui()->RegisterMessageCallback( |
| 134 "getDefaultValueForContentType", | 216 "getDefaultValueForContentType", |
| 135 base::Bind(&SiteSettingsHandler::HandleGetDefaultValueForContentType, | 217 base::Bind(&SiteSettingsHandler::HandleGetDefaultValueForContentType, |
| 136 base::Unretained(this))); | 218 base::Unretained(this))); |
| 137 web_ui()->RegisterMessageCallback( | 219 web_ui()->RegisterMessageCallback( |
| 138 "getExceptionList", | 220 "getExceptionList", |
| 139 base::Bind(&SiteSettingsHandler::HandleGetExceptionList, | 221 base::Bind(&SiteSettingsHandler::HandleGetExceptionList, |
| 140 base::Unretained(this))); | 222 base::Unretained(this))); |
| 141 web_ui()->RegisterMessageCallback( | 223 web_ui()->RegisterMessageCallback( |
| 224 "getOriginPermissions", |
| 225 base::Bind(&SiteSettingsHandler::HandleGetOriginPermissions, |
| 226 base::Unretained(this))); |
| 227 web_ui()->RegisterMessageCallback( |
| 142 "resetCategoryPermissionForOrigin", | 228 "resetCategoryPermissionForOrigin", |
| 143 base::Bind(&SiteSettingsHandler::HandleResetCategoryPermissionForOrigin, | 229 base::Bind(&SiteSettingsHandler::HandleResetCategoryPermissionForOrigin, |
| 144 base::Unretained(this))); | 230 base::Unretained(this))); |
| 145 web_ui()->RegisterMessageCallback( | 231 web_ui()->RegisterMessageCallback( |
| 146 "setCategoryPermissionForOrigin", | 232 "setCategoryPermissionForOrigin", |
| 147 base::Bind(&SiteSettingsHandler::HandleSetCategoryPermissionForOrigin, | 233 base::Bind(&SiteSettingsHandler::HandleSetCategoryPermissionForOrigin, |
| 148 base::Unretained(this))); | 234 base::Unretained(this))); |
| 149 web_ui()->RegisterMessageCallback( | 235 web_ui()->RegisterMessageCallback( |
| 150 "getSiteDetails", | |
| 151 base::Bind(&SiteSettingsHandler::HandleGetSiteDetails, | |
| 152 base::Unretained(this))); | |
| 153 web_ui()->RegisterMessageCallback( | |
| 154 "isPatternValid", | 236 "isPatternValid", |
| 155 base::Bind(&SiteSettingsHandler::HandleIsPatternValid, | 237 base::Bind(&SiteSettingsHandler::HandleIsPatternValid, |
| 156 base::Unretained(this))); | 238 base::Unretained(this))); |
| 157 web_ui()->RegisterMessageCallback( | 239 web_ui()->RegisterMessageCallback( |
| 158 "updateIncognitoStatus", | 240 "updateIncognitoStatus", |
| 159 base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, | 241 base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, |
| 160 base::Unretained(this))); | 242 base::Unretained(this))); |
| 161 web_ui()->RegisterMessageCallback( | 243 web_ui()->RegisterMessageCallback( |
| 162 "fetchZoomLevels", | 244 "fetchZoomLevels", |
| 163 base::Bind(&SiteSettingsHandler::HandleFetchZoomLevels, | 245 base::Bind(&SiteSettingsHandler::HandleFetchZoomLevels, |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 Profile* profile = profile_; | 466 Profile* profile = profile_; |
| 385 #if defined(OS_CHROMEOS) | 467 #if defined(OS_CHROMEOS) |
| 386 // ChromeOS special case: in Guest mode, settings are opened in Incognito | 468 // ChromeOS special case: in Guest mode, settings are opened in Incognito |
| 387 // mode so we need the original profile to actually modify settings. | 469 // mode so we need the original profile to actually modify settings. |
| 388 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) | 470 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) |
| 389 profile = profile->GetOriginalProfile(); | 471 profile = profile->GetOriginalProfile(); |
| 390 #endif | 472 #endif |
| 391 HostContentSettingsMap* map = | 473 HostContentSettingsMap* map = |
| 392 HostContentSettingsMapFactory::GetForProfile(profile); | 474 HostContentSettingsMapFactory::GetForProfile(profile); |
| 393 map->SetDefaultContentSetting( | 475 map->SetDefaultContentSetting( |
| 394 static_cast<ContentSettingsType>(static_cast<int>( | 476 site_settings::ContentSettingsTypeFromGroupName(content_type), |
| 395 site_settings::ContentSettingsTypeFromGroupName(content_type))), | |
| 396 default_setting); | 477 default_setting); |
| 397 } | 478 } |
| 398 | 479 |
| 399 void SiteSettingsHandler::HandleGetDefaultValueForContentType( | 480 void SiteSettingsHandler::HandleGetDefaultValueForContentType( |
| 400 const base::ListValue* args) { | 481 const base::ListValue* args) { |
| 401 AllowJavascript(); | 482 AllowJavascript(); |
| 402 | 483 |
| 403 CHECK_EQ(2U, args->GetSize()); | 484 CHECK_EQ(2U, args->GetSize()); |
| 404 const base::Value* callback_id; | 485 const base::Value* callback_id; |
| 405 CHECK(args->Get(0, &callback_id)); | 486 CHECK(args->Get(0, &callback_id)); |
| 406 std::string type; | 487 std::string type; |
| 407 CHECK(args->GetString(1, &type)); | 488 CHECK(args->GetString(1, &type)); |
| 408 | 489 |
| 409 ContentSettingsType content_type = | 490 ContentSettingsType content_type = |
| 410 static_cast<ContentSettingsType>(static_cast<int>( | 491 site_settings::ContentSettingsTypeFromGroupName(type); |
| 411 site_settings::ContentSettingsTypeFromGroupName(type))); | |
| 412 HostContentSettingsMap* map = | 492 HostContentSettingsMap* map = |
| 413 HostContentSettingsMapFactory::GetForProfile(profile_); | 493 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 414 | 494 |
| 415 base::DictionaryValue category; | 495 base::DictionaryValue category; |
| 416 site_settings::GetContentCategorySetting(map, content_type, &category); | 496 site_settings::GetContentCategorySetting(map, content_type, &category); |
| 417 ResolveJavascriptCallback(*callback_id, category); | 497 ResolveJavascriptCallback(*callback_id, category); |
| 418 } | 498 } |
| 419 | 499 |
| 420 void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) { | 500 void SiteSettingsHandler::HandleGetExceptionList(const base::ListValue* args) { |
| 421 AllowJavascript(); | 501 AllowJavascript(); |
| 422 | 502 |
| 423 CHECK_EQ(2U, args->GetSize()); | 503 CHECK_EQ(2U, args->GetSize()); |
| 424 const base::Value* callback_id; | 504 const base::Value* callback_id; |
| 425 CHECK(args->Get(0, &callback_id)); | 505 CHECK(args->Get(0, &callback_id)); |
| 426 std::string type; | 506 std::string type; |
| 427 CHECK(args->GetString(1, &type)); | 507 CHECK(args->GetString(1, &type)); |
| 428 ContentSettingsType content_type = | 508 ContentSettingsType content_type = |
| 429 static_cast<ContentSettingsType>(static_cast<int>( | 509 site_settings::ContentSettingsTypeFromGroupName(type); |
| 430 site_settings::ContentSettingsTypeFromGroupName(type))); | |
| 431 | 510 |
| 432 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); | 511 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); |
| 433 | 512 |
| 434 HostContentSettingsMap* map = | 513 HostContentSettingsMap* map = |
| 435 HostContentSettingsMapFactory::GetForProfile(profile_); | 514 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 436 const auto* extension_registry = extensions::ExtensionRegistry::Get(profile_); | 515 const auto* extension_registry = extensions::ExtensionRegistry::Get(profile_); |
| 437 AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type), | 516 AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type), |
| 438 exceptions.get()); | 517 exceptions.get()); |
| 439 site_settings::GetExceptionsFromHostContentSettingsMap( | 518 site_settings::GetExceptionsFromHostContentSettingsMap( |
| 440 map, content_type, extension_registry, web_ui(), /*incognito=*/false, | 519 map, content_type, extension_registry, web_ui(), /*incognito=*/false, |
| 441 /*filter=*/nullptr, exceptions.get()); | 520 /*filter=*/nullptr, exceptions.get()); |
| 442 | 521 |
| 443 Profile* incognito = profile_->HasOffTheRecordProfile() | 522 Profile* incognito = profile_->HasOffTheRecordProfile() |
| 444 ? profile_->GetOffTheRecordProfile() | 523 ? profile_->GetOffTheRecordProfile() |
| 445 : nullptr; | 524 : nullptr; |
| 446 // On Chrome OS in Guest mode the incognito profile is the primary profile, | 525 // On Chrome OS in Guest mode the incognito profile is the primary profile, |
| 447 // so do not fetch an extra copy of the same exceptions. | 526 // so do not fetch an extra copy of the same exceptions. |
| 448 if (incognito && incognito != profile_) { | 527 if (incognito && incognito != profile_) { |
| 449 map = HostContentSettingsMapFactory::GetForProfile(incognito); | 528 map = HostContentSettingsMapFactory::GetForProfile(incognito); |
| 450 extension_registry = extensions::ExtensionRegistry::Get(incognito); | 529 extension_registry = extensions::ExtensionRegistry::Get(incognito); |
| 451 site_settings::GetExceptionsFromHostContentSettingsMap( | 530 site_settings::GetExceptionsFromHostContentSettingsMap( |
| 452 map, content_type, extension_registry, web_ui(), /*incognito=*/true, | 531 map, content_type, extension_registry, web_ui(), /*incognito=*/true, |
| 453 /*filter=*/nullptr, exceptions.get()); | 532 /*filter=*/nullptr, exceptions.get()); |
| 454 } | 533 } |
| 455 | 534 |
| 456 ResolveJavascriptCallback(*callback_id, *exceptions.get()); | 535 ResolveJavascriptCallback(*callback_id, *exceptions.get()); |
| 457 } | 536 } |
| 458 | 537 |
| 538 void SiteSettingsHandler::HandleGetOriginPermissions( |
| 539 const base::ListValue* args) { |
| 540 AllowJavascript(); |
| 541 |
| 542 CHECK_EQ(3U, args->GetSize()); |
| 543 const base::Value* callback_id; |
| 544 CHECK(args->Get(0, &callback_id)); |
| 545 std::string origin; |
| 546 CHECK(args->GetString(1, &origin)); |
| 547 const base::ListValue* types; |
| 548 CHECK(args->GetList(2, &types)); |
| 549 |
| 550 // Note: Invalid URLs will just result in default settings being shown. |
| 551 const GURL origin_url(origin); |
| 552 auto exceptions = base::MakeUnique<base::ListValue>(); |
| 553 for (size_t i = 0; i < types->GetSize(); ++i) { |
| 554 std::string type; |
| 555 types->GetString(i, &type); |
| 556 ContentSettingsType content_type = |
| 557 site_settings::ContentSettingsTypeFromGroupName(type); |
| 558 |
| 559 std::string source_string; |
| 560 ContentSetting content_setting = GetContentSettingForOrigin( |
| 561 origin_url, content_type, profile_, &source_string); |
| 562 std::string content_setting_string = |
| 563 content_settings::ContentSettingToString(content_setting); |
| 564 |
| 565 auto raw_site_exception = base::MakeUnique<base::DictionaryValue>(); |
| 566 raw_site_exception->SetString(site_settings::kEmbeddingOrigin, origin); |
| 567 raw_site_exception->SetBoolean(site_settings::kIncognito, |
| 568 profile_->IsOffTheRecord()); |
| 569 raw_site_exception->SetString(site_settings::kOrigin, origin); |
| 570 raw_site_exception->SetString(site_settings::kDisplayName, origin); |
| 571 raw_site_exception->SetString(site_settings::kSetting, |
| 572 content_setting_string); |
| 573 raw_site_exception->SetString(site_settings::kSource, source_string); |
| 574 exceptions->Append(std::move(raw_site_exception)); |
| 575 } |
| 576 |
| 577 ResolveJavascriptCallback(*callback_id, *exceptions); |
| 578 } |
| 579 |
| 459 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( | 580 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( |
| 460 const base::ListValue* args) { | 581 const base::ListValue* args) { |
| 461 CHECK_EQ(4U, args->GetSize()); | 582 CHECK_EQ(4U, args->GetSize()); |
| 462 std::string primary_pattern_string; | 583 std::string primary_pattern_string; |
| 463 CHECK(args->GetString(0, &primary_pattern_string)); | 584 CHECK(args->GetString(0, &primary_pattern_string)); |
| 464 std::string secondary_pattern_string; | 585 std::string secondary_pattern_string; |
| 465 CHECK(args->GetString(1, &secondary_pattern_string)); | 586 CHECK(args->GetString(1, &secondary_pattern_string)); |
| 466 std::string type; | 587 std::string type; |
| 467 CHECK(args->GetString(2, &type)); | 588 CHECK(args->GetString(2, &type)); |
| 468 bool incognito; | 589 bool incognito; |
| 469 CHECK(args->GetBoolean(3, &incognito)); | 590 CHECK(args->GetBoolean(3, &incognito)); |
| 470 | 591 |
| 471 ContentSettingsType content_type = | 592 ContentSettingsType content_type = |
| 472 static_cast<ContentSettingsType>(static_cast<int>( | 593 site_settings::ContentSettingsTypeFromGroupName(type); |
| 473 site_settings::ContentSettingsTypeFromGroupName(type))); | |
| 474 | 594 |
| 475 Profile* profile = nullptr; | 595 Profile* profile = nullptr; |
| 476 if (incognito) { | 596 if (incognito) { |
| 477 if (!profile_->HasOffTheRecordProfile()) | 597 if (!profile_->HasOffTheRecordProfile()) |
| 478 return; | 598 return; |
| 479 profile = profile_->GetOffTheRecordProfile(); | 599 profile = profile_->GetOffTheRecordProfile(); |
| 480 } else { | 600 } else { |
| 481 profile = profile_; | 601 profile = profile_; |
| 482 } | 602 } |
| 483 | 603 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 510 std::string secondary_pattern_string; | 630 std::string secondary_pattern_string; |
| 511 CHECK(args->GetString(1, &secondary_pattern_string)); | 631 CHECK(args->GetString(1, &secondary_pattern_string)); |
| 512 std::string type; | 632 std::string type; |
| 513 CHECK(args->GetString(2, &type)); | 633 CHECK(args->GetString(2, &type)); |
| 514 std::string value; | 634 std::string value; |
| 515 CHECK(args->GetString(3, &value)); | 635 CHECK(args->GetString(3, &value)); |
| 516 bool incognito; | 636 bool incognito; |
| 517 CHECK(args->GetBoolean(4, &incognito)); | 637 CHECK(args->GetBoolean(4, &incognito)); |
| 518 | 638 |
| 519 ContentSettingsType content_type = | 639 ContentSettingsType content_type = |
| 520 static_cast<ContentSettingsType>(static_cast<int>( | 640 site_settings::ContentSettingsTypeFromGroupName(type); |
| 521 site_settings::ContentSettingsTypeFromGroupName(type))); | |
| 522 ContentSetting setting; | 641 ContentSetting setting; |
| 523 CHECK(content_settings::ContentSettingFromString(value, &setting)); | 642 CHECK(content_settings::ContentSettingFromString(value, &setting)); |
| 524 | 643 |
| 525 Profile* profile = nullptr; | 644 Profile* profile = nullptr; |
| 526 if (incognito) { | 645 if (incognito) { |
| 527 if (!profile_->HasOffTheRecordProfile()) | 646 if (!profile_->HasOffTheRecordProfile()) |
| 528 return; | 647 return; |
| 529 profile = profile_->GetOffTheRecordProfile(); | 648 profile = profile_->GetOffTheRecordProfile(); |
| 530 } else { | 649 } else { |
| 531 profile = profile_; | 650 profile = profile_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 544 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( | 663 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 545 profile, primary_pattern, secondary_pattern, content_type, | 664 profile, primary_pattern, secondary_pattern, content_type, |
| 546 PermissionSourceUI::SITE_SETTINGS); | 665 PermissionSourceUI::SITE_SETTINGS); |
| 547 | 666 |
| 548 map->SetContentSettingCustomScope(primary_pattern, secondary_pattern, | 667 map->SetContentSettingCustomScope(primary_pattern, secondary_pattern, |
| 549 content_type, "", setting); | 668 content_type, "", setting); |
| 550 | 669 |
| 551 WebSiteSettingsUmaUtil::LogPermissionChange(content_type, setting); | 670 WebSiteSettingsUmaUtil::LogPermissionChange(content_type, setting); |
| 552 } | 671 } |
| 553 | 672 |
| 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( | 673 void SiteSettingsHandler::HandleIsPatternValid( |
| 618 const base::ListValue* args) { | 674 const base::ListValue* args) { |
| 619 CHECK_EQ(2U, args->GetSize()); | 675 CHECK_EQ(2U, args->GetSize()); |
| 620 const base::Value* callback_id; | 676 const base::Value* callback_id; |
| 621 CHECK(args->Get(0, &callback_id)); | 677 CHECK(args->Get(0, &callback_id)); |
| 622 std::string pattern_string; | 678 std::string pattern_string; |
| 623 CHECK(args->GetString(1, &pattern_string)); | 679 CHECK(args->GetString(1, &pattern_string)); |
| 624 | 680 |
| 625 ContentSettingsPattern pattern = | 681 ContentSettingsPattern pattern = |
| 626 ContentSettingsPattern::FromString(pattern_string); | 682 ContentSettingsPattern::FromString(pattern_string); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 origin = content::kUnreachableWebDataURL; | 805 origin = content::kUnreachableWebDataURL; |
| 750 } | 806 } |
| 751 | 807 |
| 752 content::HostZoomMap* host_zoom_map; | 808 content::HostZoomMap* host_zoom_map; |
| 753 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); | 809 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); |
| 754 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 810 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
| 755 host_zoom_map->SetZoomLevelForHost(origin, default_level); | 811 host_zoom_map->SetZoomLevelForHost(origin, default_level); |
| 756 } | 812 } |
| 757 | 813 |
| 758 } // namespace settings | 814 } // namespace settings |
| OLD | NEW |