OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/options/website_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/website_settings_handler.h" |
6 | 6 |
7 #include "chrome/browser/content_settings/content_settings_utils.h" | 7 #include "chrome/browser/content_settings/content_settings_utils.h" |
8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_iterator.h" | 12 #include "chrome/browser/ui/browser_iterator.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "components/power/origin_power_map.h" | 15 #include "components/power/origin_power_map.h" |
16 #include "components/power/origin_power_map_factory.h" | 16 #include "components/power/origin_power_map_factory.h" |
17 #include "content/public/browser/dom_storage_context.h" | 17 #include "content/public/browser/dom_storage_context.h" |
18 #include "content/public/browser/storage_partition.h" | 18 #include "content/public/browser/storage_partition.h" |
19 #include "content/public/browser/user_metrics.h" | |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
21 #include "extensions/browser/app_window/app_window_registry.h" | 22 #include "extensions/browser/app_window/app_window_registry.h" |
22 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
24 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
25 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/base/l10n/time_format.h" | 28 #include "ui/base/l10n/time_format.h" |
28 #include "ui/base/text/bytes_formatting.h" | 29 #include "ui/base/text/bytes_formatting.h" |
29 | 30 |
31 using base::UserMetricsAction; | |
30 using power::OriginPowerMap; | 32 using power::OriginPowerMap; |
31 using power::OriginPowerMapFactory; | 33 using power::OriginPowerMapFactory; |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 const char kBattery[] = "battery"; | 37 const char kBattery[] = "battery"; |
36 const int kHttpPort = 80; | 38 const int kHttpPort = 80; |
37 const int kHttpsPort = 443; | 39 const int kHttpsPort = 443; |
38 const char kPreferencesSource[] = "preference"; | 40 const char kPreferencesSource[] = "preference"; |
39 const char kStorage[] = "storage"; | 41 const char kStorage[] = "storage"; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 | 153 |
152 web_ui()->RegisterMessageCallback( | 154 web_ui()->RegisterMessageCallback( |
153 "deleteLocalStorage", | 155 "deleteLocalStorage", |
154 base::Bind(&WebsiteSettingsHandler::HandleDeleteLocalStorage, | 156 base::Bind(&WebsiteSettingsHandler::HandleDeleteLocalStorage, |
155 base::Unretained(this))); | 157 base::Unretained(this))); |
156 | 158 |
157 web_ui()->RegisterMessageCallback( | 159 web_ui()->RegisterMessageCallback( |
158 "stopOrigin", | 160 "stopOrigin", |
159 base::Bind(&WebsiteSettingsHandler::HandleStopOrigin, | 161 base::Bind(&WebsiteSettingsHandler::HandleStopOrigin, |
160 base::Unretained(this))); | 162 base::Unretained(this))); |
163 | |
164 web_ui()->RegisterMessageCallback( | |
165 "updateDefaultSetting", | |
166 base::Bind(&WebsiteSettingsHandler::HandleUpdateDefaultSetting, | |
167 base::Unretained(this))); | |
168 | |
169 web_ui()->RegisterMessageCallback( | |
170 "setDefaultContentSetting", | |
171 base::Bind(&WebsiteSettingsHandler::HandleSetDefaultSetting, | |
172 base::Unretained(this))); | |
161 } | 173 } |
162 | 174 |
163 // content_settings::Observer implementation. | 175 // content_settings::Observer implementation. |
164 void WebsiteSettingsHandler::OnContentSettingChanged( | 176 void WebsiteSettingsHandler::OnContentSettingChanged( |
165 const ContentSettingsPattern& primary_pattern, | 177 const ContentSettingsPattern& primary_pattern, |
166 const ContentSettingsPattern& secondary_pattern, | 178 const ContentSettingsPattern& secondary_pattern, |
167 ContentSettingsType content_type, | 179 ContentSettingsType content_type, |
168 std::string resource_identifier) { | 180 std::string resource_identifier) { |
169 Update(); | 181 Update(); |
170 } | 182 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 const base::ListValue* args) { | 431 const base::ListValue* args) { |
420 DCHECK(!last_site_.is_empty()); | 432 DCHECK(!last_site_.is_empty()); |
421 DeleteLocalStorage(last_site_); | 433 DeleteLocalStorage(last_site_); |
422 } | 434 } |
423 | 435 |
424 void WebsiteSettingsHandler::HandleStopOrigin(const base::ListValue* args) { | 436 void WebsiteSettingsHandler::HandleStopOrigin(const base::ListValue* args) { |
425 DCHECK(!last_site_.is_empty()); | 437 DCHECK(!last_site_.is_empty()); |
426 StopOrigin(last_site_); | 438 StopOrigin(last_site_); |
427 } | 439 } |
428 | 440 |
441 // TODO(dhnishi): Remove default settings duplication from the | |
442 // WebsiteSettingsHandler and the ContentSettingsHandler. | |
443 void WebsiteSettingsHandler::HandleUpdateDefaultSetting( | |
444 const base::ListValue* args) { | |
445 base::DictionaryValue filter_settings; | |
446 std::string provider_id; | |
Bernhard Bauer
2014/09/09 08:56:21
Move this to right before it's used?
Daniel Nishi
2014/09/09 16:11:56
Done.
| |
447 ContentSettingsType last_setting; | |
448 content_settings::GetTypeFromName(last_setting_, &last_setting); | |
449 filter_settings.SetString( | |
450 "value", GetSettingDefaultFromModel(last_setting, &provider_id)); | |
451 filter_settings.SetString("managedBy", provider_id); | |
452 | |
453 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.updateDefault", | |
454 filter_settings); | |
455 } | |
456 | |
457 void WebsiteSettingsHandler::HandleSetDefaultSetting( | |
458 const base::ListValue* args) { | |
459 DCHECK_EQ(1U, args->GetSize()); | |
460 std::string setting; | |
461 if (!args->GetString(0, &setting)) { | |
462 NOTREACHED(); | |
463 return; | |
464 } | |
465 ContentSetting new_default = | |
466 content_settings::ContentSettingFromString(setting); | |
467 | |
468 ContentSettingsType last_setting; | |
469 content_settings::GetTypeFromName(last_setting_, &last_setting); | |
470 Profile* profile = Profile::FromWebUI(web_ui()); | |
471 | |
472 #if defined(OS_CHROMEOS) | |
473 // ChromeOS special case : in Guest mode settings are opened in Incognito | |
474 // mode, so we need original profile to actually modify settings. | |
475 if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) | |
476 profile = profile->GetOriginalProfile(); | |
477 #endif | |
478 | |
479 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | |
480 map->SetDefaultContentSetting(last_setting, new_default); | |
481 | |
482 switch (last_setting) { | |
483 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: | |
484 content::RecordAction( | |
485 UserMetricsAction("Options_DefaultMultipleAutomaticDLSettingChange")); | |
486 break; | |
487 case CONTENT_SETTINGS_TYPE_COOKIES: | |
488 content::RecordAction( | |
489 UserMetricsAction("Options_DefaultCookieSettingChanged")); | |
490 break; | |
491 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | |
492 content::RecordAction( | |
493 UserMetricsAction("Options_DefaultGeolocationSettingChanged")); | |
494 break; | |
495 case CONTENT_SETTINGS_TYPE_IMAGES: | |
496 content::RecordAction( | |
497 UserMetricsAction("Options_DefaultImagesSettingChanged")); | |
498 break; | |
499 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: | |
500 content::RecordAction( | |
501 UserMetricsAction("Options_DefaultJavaScriptSettingChanged")); | |
502 break; | |
503 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | |
504 content::RecordAction( | |
505 UserMetricsAction("Options_DefaultMediaStreamMicSettingChanged")); | |
506 break; | |
507 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | |
508 content::RecordAction( | |
509 UserMetricsAction("Options_DefaultNotificationsSettingChanged")); | |
510 break; | |
511 case CONTENT_SETTINGS_TYPE_PLUGINS: | |
512 content::RecordAction( | |
513 UserMetricsAction("Options_DefaultPluginsSettingChanged")); | |
514 break; | |
515 case CONTENT_SETTINGS_TYPE_POPUPS: | |
516 content::RecordAction( | |
517 UserMetricsAction("Options_DefaultPopupsSettingChanged")); | |
518 break; | |
519 default: | |
520 NOTREACHED(); | |
521 return; | |
522 } | |
523 } | |
524 | |
429 void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, | 525 void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, |
430 bool show_page) { | 526 bool show_page) { |
431 Profile* profile = Profile::FromWebUI(web_ui()); | 527 Profile* profile = Profile::FromWebUI(web_ui()); |
432 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 528 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
433 | 529 |
434 double storage = 0.0; | 530 double storage = 0.0; |
435 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); | 531 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); |
436 it != local_storage_list_.end(); | 532 it != local_storage_list_.end(); |
437 it++) { | 533 it++) { |
438 if (it->origin_url == site_url) { | 534 if (it->origin_url == site_url) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT, | 656 l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT, |
561 it->second)); | 657 it->second)); |
562 origin_entry->SetStringWithoutPathExpansion("readableName", | 658 origin_entry->SetStringWithoutPathExpansion("readableName", |
563 GetReadableName(it->first)); | 659 GetReadableName(it->first)); |
564 power_map.SetWithoutPathExpansion(origin, origin_entry); | 660 power_map.SetWithoutPathExpansion(origin, origin_entry); |
565 } | 661 } |
566 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", | 662 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", |
567 power_map); | 663 power_map); |
568 } | 664 } |
569 | 665 |
666 std::string WebsiteSettingsHandler::GetSettingDefaultFromModel( | |
667 ContentSettingsType type, | |
668 std::string* provider_id) { | |
669 Profile* profile = Profile::FromWebUI(web_ui()); | |
670 ContentSetting default_setting; | |
671 default_setting = | |
Bernhard Bauer
2014/09/09 08:56:21
Initialize the variable when it is declared.
Daniel Nishi
2014/09/09 16:11:56
Done.
| |
672 profile->GetHostContentSettingsMap()->GetDefaultContentSetting( | |
673 type, provider_id); | |
674 | |
675 return content_settings::ContentSettingToString(default_setting); | |
676 } | |
677 | |
570 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) { | 678 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) { |
571 Profile* profile = Profile::FromWebUI(web_ui()); | 679 Profile* profile = Profile::FromWebUI(web_ui()); |
572 if (site_url.SchemeIs(extensions::kExtensionScheme)) { | 680 if (site_url.SchemeIs(extensions::kExtensionScheme)) { |
573 const extensions::Extension* extension = | 681 const extensions::Extension* extension = |
574 extensions::ExtensionRegistry::Get(profile) | 682 extensions::ExtensionRegistry::Get(profile) |
575 ->enabled_extensions() | 683 ->enabled_extensions() |
576 .GetHostedAppByURL(site_url); | 684 .GetHostedAppByURL(site_url); |
577 if (extension) { | 685 if (extension) { |
578 extensions::AppWindowRegistry::Get(profile) | 686 extensions::AppWindowRegistry::Get(profile) |
579 ->CloseAllAppWindowsForApp(extension->id()); | 687 ->CloseAllAppWindowsForApp(extension->id()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 // If extension is NULL, it was removed and we cannot look up its name. | 735 // If extension is NULL, it was removed and we cannot look up its name. |
628 if (!extension) | 736 if (!extension) |
629 return site_url.spec(); | 737 return site_url.spec(); |
630 | 738 |
631 return extension->name(); | 739 return extension->name(); |
632 } | 740 } |
633 return site_url.spec(); | 741 return site_url.spec(); |
634 } | 742 } |
635 | 743 |
636 } // namespace options | 744 } // namespace options |
OLD | NEW |