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

Side by Side Diff: chrome/browser/ui/webui/settings/site_settings_handler.cc

Issue 2861793005: [MD settings] UMA and RevocationReporter in site settings (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/permissions/chooser_context_base.h" 20 #include "chrome/browser/permissions/chooser_context_base.h"
21 #include "chrome/browser/permissions/permission_uma_util.h"
22 #include "chrome/browser/permissions/permission_util.h"
20 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/webui/site_settings_helper.h" 24 #include "chrome/browser/ui/webui/site_settings_helper.h"
22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 25 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
23 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
24 #include "components/content_settings/core/browser/host_content_settings_map.h" 27 #include "components/content_settings/core/browser/host_content_settings_map.h"
25 #include "components/content_settings/core/common/content_settings_types.h" 28 #include "components/content_settings/core/common/content_settings_types.h"
26 #include "components/crx_file/id_util.h" 29 #include "components/crx_file/id_util.h"
27 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/web_ui.h" 32 #include "content/public/browser/web_ui.h"
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 map, content_type, extension_registry, web_ui(), /*incognito=*/true, 448 map, content_type, extension_registry, web_ui(), /*incognito=*/true,
446 /*filter=*/nullptr, exceptions.get()); 449 /*filter=*/nullptr, exceptions.get());
447 } 450 }
448 451
449 ResolveJavascriptCallback(*callback_id, *exceptions.get()); 452 ResolveJavascriptCallback(*callback_id, *exceptions.get());
450 } 453 }
451 454
452 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin( 455 void SiteSettingsHandler::HandleResetCategoryPermissionForOrigin(
453 const base::ListValue* args) { 456 const base::ListValue* args) {
454 CHECK_EQ(4U, args->GetSize()); 457 CHECK_EQ(4U, args->GetSize());
455 std::string primary_pattern; 458 std::string primary_pattern_string;
456 CHECK(args->GetString(0, &primary_pattern)); 459 CHECK(args->GetString(0, &primary_pattern_string));
457 std::string secondary_pattern; 460 std::string secondary_pattern_string;
458 CHECK(args->GetString(1, &secondary_pattern)); 461 CHECK(args->GetString(1, &secondary_pattern_string));
459 std::string type; 462 std::string type;
460 CHECK(args->GetString(2, &type)); 463 CHECK(args->GetString(2, &type));
461 bool incognito; 464 bool incognito;
462 CHECK(args->GetBoolean(3, &incognito)); 465 CHECK(args->GetBoolean(3, &incognito));
463 466
464 ContentSettingsType content_type = 467 ContentSettingsType content_type =
465 static_cast<ContentSettingsType>(static_cast<int>( 468 static_cast<ContentSettingsType>(static_cast<int>(
466 site_settings::ContentSettingsTypeFromGroupName(type))); 469 site_settings::ContentSettingsTypeFromGroupName(type)));
467 470
468 Profile* profile = nullptr; 471 Profile* profile = nullptr;
469 if (incognito) { 472 if (incognito) {
470 if (!profile_->HasOffTheRecordProfile()) 473 if (!profile_->HasOffTheRecordProfile())
471 return; 474 return;
472 profile = profile_->GetOffTheRecordProfile(); 475 profile = profile_->GetOffTheRecordProfile();
473 } else { 476 } else {
474 profile = profile_; 477 profile = profile_;
475 } 478 }
476 479
477 HostContentSettingsMap* map = 480 HostContentSettingsMap* map =
478 HostContentSettingsMapFactory::GetForProfile(profile); 481 HostContentSettingsMapFactory::GetForProfile(profile);
479 map->SetContentSettingCustomScope( 482
480 ContentSettingsPattern::FromString(primary_pattern), 483 ContentSettingsPattern primary_pattern =
481 secondary_pattern.empty() ? 484 ContentSettingsPattern::FromString(primary_pattern_string);
482 ContentSettingsPattern::Wildcard() : 485 ContentSettingsPattern secondary_pattern =
483 ContentSettingsPattern::FromString(secondary_pattern), 486 secondary_pattern_string.empty()
484 content_type, "", CONTENT_SETTING_DEFAULT); 487 ? ContentSettingsPattern::Wildcard()
488 : ContentSettingsPattern::FromString(secondary_pattern_string);
489 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
490 profile, primary_pattern, secondary_pattern, content_type,
491 PermissionSourceUI::SITE_SETTINGS);
492
493 map->SetContentSettingCustomScope(primary_pattern, secondary_pattern,
494 content_type, "", CONTENT_SETTING_DEFAULT);
495
496 WebSiteSettingsUmaUtil::LogPermissionChange(
497 content_type, ContentSetting::CONTENT_SETTING_DEFAULT);
485 } 498 }
486 499
487 void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin( 500 void SiteSettingsHandler::HandleSetCategoryPermissionForOrigin(
488 const base::ListValue* args) { 501 const base::ListValue* args) {
489 CHECK_EQ(5U, args->GetSize()); 502 CHECK_EQ(5U, args->GetSize());
490 std::string primary_pattern; 503 std::string primary_pattern_string;
491 CHECK(args->GetString(0, &primary_pattern)); 504 CHECK(args->GetString(0, &primary_pattern_string));
492 std::string secondary_pattern; 505 // TODO(dschuyler): |secondary_pattern_unused| is not used, remove it.
Dan Beam 2017/05/04 19:37:45 why did the old code use it but the new one doesn'
dschuyler 2017/05/04 21:09:21 The reasoning was based on the JS sending an empty
493 CHECK(args->GetString(1, &secondary_pattern)); 506 std::string secondary_pattern_unused;
507 CHECK(args->GetString(1, &secondary_pattern_unused));
494 std::string type; 508 std::string type;
495 CHECK(args->GetString(2, &type)); 509 CHECK(args->GetString(2, &type));
496 std::string value; 510 std::string value;
497 CHECK(args->GetString(3, &value)); 511 CHECK(args->GetString(3, &value));
498 bool incognito; 512 bool incognito;
499 CHECK(args->GetBoolean(4, &incognito)); 513 CHECK(args->GetBoolean(4, &incognito));
500 514
501 ContentSettingsType content_type = 515 ContentSettingsType content_type =
502 static_cast<ContentSettingsType>(static_cast<int>( 516 static_cast<ContentSettingsType>(static_cast<int>(
503 site_settings::ContentSettingsTypeFromGroupName(type))); 517 site_settings::ContentSettingsTypeFromGroupName(type)));
504 ContentSetting setting; 518 ContentSetting setting;
505 CHECK(content_settings::ContentSettingFromString(value, &setting)); 519 CHECK(content_settings::ContentSettingFromString(value, &setting));
506 520
507 Profile* profile = nullptr; 521 Profile* profile = nullptr;
508 if (incognito) { 522 if (incognito) {
509 if (!profile_->HasOffTheRecordProfile()) 523 if (!profile_->HasOffTheRecordProfile())
510 return; 524 return;
511 profile = profile_->GetOffTheRecordProfile(); 525 profile = profile_->GetOffTheRecordProfile();
512 } else { 526 } else {
513 profile = profile_; 527 profile = profile_;
514 } 528 }
515 529
516 HostContentSettingsMap* map = 530 HostContentSettingsMap* map =
517 HostContentSettingsMapFactory::GetForProfile(profile); 531 HostContentSettingsMapFactory::GetForProfile(profile);
518 map->SetContentSettingCustomScope( 532
519 ContentSettingsPattern::FromString(primary_pattern), 533 ContentSettingsPattern primary_pattern =
520 secondary_pattern.empty() ? 534 ContentSettingsPattern::FromString(primary_pattern_string);
521 ContentSettingsPattern::Wildcard() : 535
522 ContentSettingsPattern::FromString(secondary_pattern), 536 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
523 content_type, "", setting); 537 profile, primary_pattern, ContentSettingsPattern::Wildcard(),
538 content_type, PermissionSourceUI::SITE_SETTINGS);
539
540 map->SetContentSettingCustomScope(primary_pattern,
541 ContentSettingsPattern::Wildcard(),
542 content_type, "", setting);
543
544 WebSiteSettingsUmaUtil::LogPermissionChange(content_type, setting);
524 } 545 }
525 546
526 void SiteSettingsHandler::HandleGetSiteDetails( 547 void SiteSettingsHandler::HandleGetSiteDetails(
527 const base::ListValue* args) { 548 const base::ListValue* args) {
528 AllowJavascript(); 549 AllowJavascript();
529 550
530 CHECK_EQ(2U, args->GetSize()); 551 CHECK_EQ(2U, args->GetSize());
531 const base::Value* callback_id; 552 const base::Value* callback_id;
532 CHECK(args->Get(0, &callback_id)); 553 CHECK(args->Get(0, &callback_id));
533 std::string site; 554 std::string site;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 origin = content::kUnreachableWebDataURL; 746 origin = content::kUnreachableWebDataURL;
726 } 747 }
727 748
728 content::HostZoomMap* host_zoom_map; 749 content::HostZoomMap* host_zoom_map;
729 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_); 750 host_zoom_map = content::HostZoomMap::GetDefaultForBrowserContext(profile_);
730 double default_level = host_zoom_map->GetDefaultZoomLevel(); 751 double default_level = host_zoom_map->GetDefaultZoomLevel();
731 host_zoom_map->SetZoomLevelForHost(origin, default_level); 752 host_zoom_map->SetZoomLevelForHost(origin, default_level);
732 } 753 }
733 754
734 } // namespace settings 755 } // namespace settings
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698