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 <memory> | 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/i18n/number_formatting.h" | 13 #include "base/i18n/number_formatting.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 base::Unretained(this))); | 151 base::Unretained(this))); |
151 web_ui()->RegisterMessageCallback( | 152 web_ui()->RegisterMessageCallback( |
152 "resetCategoryPermissionForOrigin", | 153 "resetCategoryPermissionForOrigin", |
153 base::Bind(&SiteSettingsHandler::HandleResetCategoryPermissionForOrigin, | 154 base::Bind(&SiteSettingsHandler::HandleResetCategoryPermissionForOrigin, |
154 base::Unretained(this))); | 155 base::Unretained(this))); |
155 web_ui()->RegisterMessageCallback( | 156 web_ui()->RegisterMessageCallback( |
156 "setCategoryPermissionForOrigin", | 157 "setCategoryPermissionForOrigin", |
157 base::Bind(&SiteSettingsHandler::HandleSetCategoryPermissionForOrigin, | 158 base::Bind(&SiteSettingsHandler::HandleSetCategoryPermissionForOrigin, |
158 base::Unretained(this))); | 159 base::Unretained(this))); |
159 web_ui()->RegisterMessageCallback( | 160 web_ui()->RegisterMessageCallback( |
| 161 "getSiteDetails", |
| 162 base::Bind(&SiteSettingsHandler::HandleGetSiteDetails, |
| 163 base::Unretained(this))); |
| 164 web_ui()->RegisterMessageCallback( |
160 "isPatternValid", | 165 "isPatternValid", |
161 base::Bind(&SiteSettingsHandler::HandleIsPatternValid, | 166 base::Bind(&SiteSettingsHandler::HandleIsPatternValid, |
162 base::Unretained(this))); | 167 base::Unretained(this))); |
163 web_ui()->RegisterMessageCallback( | 168 web_ui()->RegisterMessageCallback( |
164 "updateIncognitoStatus", | 169 "updateIncognitoStatus", |
165 base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, | 170 base::Bind(&SiteSettingsHandler::HandleUpdateIncognitoStatus, |
166 base::Unretained(this))); | 171 base::Unretained(this))); |
167 web_ui()->RegisterMessageCallback( | 172 web_ui()->RegisterMessageCallback( |
168 "fetchZoomLevels", | 173 "fetchZoomLevels", |
169 base::Bind(&SiteSettingsHandler::HandleFetchZoomLevels, | 174 base::Bind(&SiteSettingsHandler::HandleFetchZoomLevels, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 static_cast<ContentSettingsType>(static_cast<int>( | 434 static_cast<ContentSettingsType>(static_cast<int>( |
430 site_settings::ContentSettingsTypeFromGroupName(type))); | 435 site_settings::ContentSettingsTypeFromGroupName(type))); |
431 | 436 |
432 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); | 437 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); |
433 | 438 |
434 HostContentSettingsMap* map = | 439 HostContentSettingsMap* map = |
435 HostContentSettingsMapFactory::GetForProfile(profile_); | 440 HostContentSettingsMapFactory::GetForProfile(profile_); |
436 AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type), | 441 AddExceptionsGrantedByHostedApps(profile_, APIPermissionFromGroupName(type), |
437 exceptions.get()); | 442 exceptions.get()); |
438 site_settings::GetExceptionsFromHostContentSettingsMap( | 443 site_settings::GetExceptionsFromHostContentSettingsMap( |
439 map, content_type, web_ui(), false, exceptions.get()); | 444 map, content_type, web_ui(), /*incognito=*/false, /*filter=*/nullptr, |
| 445 exceptions.get()); |
440 | 446 |
441 if (profile_->HasOffTheRecordProfile()) { | 447 if (profile_->HasOffTheRecordProfile()) { |
442 Profile* incognito = profile_->GetOffTheRecordProfile(); | 448 Profile* incognito = profile_->GetOffTheRecordProfile(); |
443 map = HostContentSettingsMapFactory::GetForProfile(incognito); | 449 map = HostContentSettingsMapFactory::GetForProfile(incognito); |
444 site_settings::GetExceptionsFromHostContentSettingsMap( | 450 site_settings::GetExceptionsFromHostContentSettingsMap( |
445 map, content_type, web_ui(), true, exceptions.get()); | 451 map, content_type, web_ui(), /*incognito=*/true, /*filter=*/nullptr, |
| 452 exceptions.get()); |
446 } | 453 } |
447 | 454 |
448 ResolveJavascriptCallback(*callback_id, *exceptions.get()); | 455 ResolveJavascriptCallback(*callback_id, *exceptions.get()); |
449 } | 456 } |
450 | 457 |
451 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( | 458 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( |
452 const base::ListValue* args) { | 459 const base::ListValue* args) { |
453 CHECK_EQ(4U, args->GetSize()); | 460 CHECK_EQ(4U, args->GetSize()); |
454 std::string primary_pattern; | 461 std::string primary_pattern; |
455 CHECK(args->GetString(0, &primary_pattern)); | 462 CHECK(args->GetString(0, &primary_pattern)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 HostContentSettingsMap* map = | 522 HostContentSettingsMap* map = |
516 HostContentSettingsMapFactory::GetForProfile(profile); | 523 HostContentSettingsMapFactory::GetForProfile(profile); |
517 map->SetContentSettingCustomScope( | 524 map->SetContentSettingCustomScope( |
518 ContentSettingsPattern::FromString(primary_pattern), | 525 ContentSettingsPattern::FromString(primary_pattern), |
519 secondary_pattern.empty() ? | 526 secondary_pattern.empty() ? |
520 ContentSettingsPattern::Wildcard() : | 527 ContentSettingsPattern::Wildcard() : |
521 ContentSettingsPattern::FromString(secondary_pattern), | 528 ContentSettingsPattern::FromString(secondary_pattern), |
522 content_type, "", setting); | 529 content_type, "", setting); |
523 } | 530 } |
524 | 531 |
| 532 void SiteSettingsHandler::HandleGetSiteDetails( |
| 533 const base::ListValue* args) { |
| 534 AllowJavascript(); |
| 535 |
| 536 CHECK_EQ(2U, args->GetSize()); |
| 537 const base::Value* callback_id; |
| 538 CHECK(args->Get(0, &callback_id)); |
| 539 std::string site; |
| 540 CHECK(args->GetString(1, &site)); |
| 541 |
| 542 // A subset of the ContentSettingsType enum that we show in the settings UI. |
| 543 const ContentSettingsType kSettingsDetailTypes[] = { |
| 544 CONTENT_SETTINGS_TYPE_COOKIES, |
| 545 CONTENT_SETTINGS_TYPE_IMAGES, |
| 546 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 547 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 548 CONTENT_SETTINGS_TYPE_POPUPS, |
| 549 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 550 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 551 CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| 552 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 553 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 554 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, |
| 555 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 556 CONTENT_SETTINGS_TYPE_KEYGEN, |
| 557 CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC, |
| 558 CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, |
| 559 CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, |
| 560 }; |
| 561 |
| 562 // Create a list to be consistent with existing API, we are expecting a single |
| 563 // element (or none). |
| 564 std::unique_ptr<base::ListValue> exceptions(new base::ListValue); |
| 565 for (size_t type = 0; type < arraysize(kSettingsDetailTypes); ++type) { |
| 566 ContentSettingsType content_type = kSettingsDetailTypes[type]; |
| 567 |
| 568 HostContentSettingsMap* map = |
| 569 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 570 site_settings::GetExceptionsFromHostContentSettingsMap( |
| 571 map, content_type, web_ui(), /*incognito=*/false, /*filter=*/&site, |
| 572 exceptions.get()); |
| 573 |
| 574 if (profile_->HasOffTheRecordProfile()) { |
| 575 Profile* incognito = profile_->GetOffTheRecordProfile(); |
| 576 map = HostContentSettingsMapFactory::GetForProfile(incognito); |
| 577 site_settings::GetExceptionsFromHostContentSettingsMap( |
| 578 map, content_type, web_ui(), /*incognito=*/true, /*filter=*/&site, |
| 579 exceptions.get()); |
| 580 } |
| 581 } |
| 582 |
| 583 if (!exceptions->GetSize()) { |
| 584 RejectJavascriptCallback(*callback_id, *base::Value::CreateNullValue()); |
| 585 return; |
| 586 } |
| 587 |
| 588 // We only need a single response element. |
| 589 const base::DictionaryValue* exception = nullptr; |
| 590 exceptions->GetDictionary(0, &exception); |
| 591 ResolveJavascriptCallback(*callback_id, *exception); |
| 592 } |
| 593 |
525 void SiteSettingsHandler::HandleIsPatternValid( | 594 void SiteSettingsHandler::HandleIsPatternValid( |
526 const base::ListValue* args) { | 595 const base::ListValue* args) { |
527 CHECK_EQ(2U, args->GetSize()); | 596 CHECK_EQ(2U, args->GetSize()); |
528 const base::Value* callback_id; | 597 const base::Value* callback_id; |
529 CHECK(args->Get(0, &callback_id)); | 598 CHECK(args->Get(0, &callback_id)); |
530 std::string pattern_string; | 599 std::string pattern_string; |
531 CHECK(args->GetString(1, &pattern_string)); | 600 CHECK(args->GetString(1, &pattern_string)); |
532 | 601 |
533 ContentSettingsPattern pattern = | 602 ContentSettingsPattern pattern = |
534 ContentSettingsPattern::FromString(pattern_string); | 603 ContentSettingsPattern::FromString(pattern_string); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 origin = content::kUnreachableWebDataURL; | 709 origin = content::kUnreachableWebDataURL; |
641 } | 710 } |
642 | 711 |
643 content::HostZoomMap* host_zoom_map; | 712 content::HostZoomMap* host_zoom_map; |
644 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); | 713 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); |
645 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 714 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
646 host_zoom_map->SetZoomLevelForHost(origin, default_level); | 715 host_zoom_map->SetZoomLevelForHost(origin, default_level); |
647 } | 716 } |
648 | 717 |
649 } // namespace settings | 718 } // namespace settings |
OLD | NEW |