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

Side by Side Diff: chrome/browser/ui/webui/options/website_settings_handler.cc

Issue 543983005: Add a dropdown to change the default content setting to the Website Settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix CrOS build error. Created 6 years, 3 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 | « chrome/browser/ui/webui/options/website_settings_handler.h ('k') | 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 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 #if defined(OS_CHROMEOS)
32 #include "components/user_manager/user_manager.h"
33 #endif
34
35 using base::UserMetricsAction;
30 using power::OriginPowerMap; 36 using power::OriginPowerMap;
31 using power::OriginPowerMapFactory; 37 using power::OriginPowerMapFactory;
32 38
33 namespace { 39 namespace {
34 40
35 const char kBattery[] = "battery"; 41 const char kBattery[] = "battery";
36 const int kHttpPort = 80; 42 const int kHttpPort = 80;
37 const int kHttpsPort = 443; 43 const int kHttpsPort = 443;
38 const char kPreferencesSource[] = "preference"; 44 const char kPreferencesSource[] = "preference";
39 const char kStorage[] = "storage"; 45 const char kStorage[] = "storage";
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 157
152 web_ui()->RegisterMessageCallback( 158 web_ui()->RegisterMessageCallback(
153 "deleteLocalStorage", 159 "deleteLocalStorage",
154 base::Bind(&WebsiteSettingsHandler::HandleDeleteLocalStorage, 160 base::Bind(&WebsiteSettingsHandler::HandleDeleteLocalStorage,
155 base::Unretained(this))); 161 base::Unretained(this)));
156 162
157 web_ui()->RegisterMessageCallback( 163 web_ui()->RegisterMessageCallback(
158 "stopOrigin", 164 "stopOrigin",
159 base::Bind(&WebsiteSettingsHandler::HandleStopOrigin, 165 base::Bind(&WebsiteSettingsHandler::HandleStopOrigin,
160 base::Unretained(this))); 166 base::Unretained(this)));
167
168 web_ui()->RegisterMessageCallback(
169 "updateDefaultSetting",
170 base::Bind(&WebsiteSettingsHandler::HandleUpdateDefaultSetting,
171 base::Unretained(this)));
172
173 web_ui()->RegisterMessageCallback(
174 "setDefaultContentSetting",
175 base::Bind(&WebsiteSettingsHandler::HandleSetDefaultSetting,
176 base::Unretained(this)));
161 } 177 }
162 178
163 // content_settings::Observer implementation. 179 // content_settings::Observer implementation.
164 void WebsiteSettingsHandler::OnContentSettingChanged( 180 void WebsiteSettingsHandler::OnContentSettingChanged(
165 const ContentSettingsPattern& primary_pattern, 181 const ContentSettingsPattern& primary_pattern,
166 const ContentSettingsPattern& secondary_pattern, 182 const ContentSettingsPattern& secondary_pattern,
167 ContentSettingsType content_type, 183 ContentSettingsType content_type,
168 std::string resource_identifier) { 184 std::string resource_identifier) {
169 Update(); 185 Update();
170 } 186 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 std::string site; 235 std::string site;
220 bool rv = args->GetString(0, &site); 236 bool rv = args->GetString(0, &site);
221 DCHECK(rv); 237 DCHECK(rv);
222 238
223 GURL last_site(site); 239 GURL last_site(site);
224 if (!last_site.is_valid()) 240 if (!last_site.is_valid())
225 return; 241 return;
226 242
227 last_site_ = last_site; 243 last_site_ = last_site;
228 base::StringValue site_value(site); 244 base::StringValue site_value(site);
229 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.showEditPage", 245 web_ui()->CallJavascriptFunction("WebsiteSettingsEditor.showEditPage",
230 site_value); 246 site_value);
231 } 247 }
232 248
233 void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list< 249 void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list<
234 BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) { 250 BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) {
235 local_storage_list_ = storage; 251 local_storage_list_ = storage;
236 Update(); 252 Update();
237 GetInfoForOrigin(last_site_, false); 253 GetInfoForOrigin(last_site_, false);
238 } 254 }
239 255
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 const base::ListValue* args) { 435 const base::ListValue* args) {
420 DCHECK(!last_site_.is_empty()); 436 DCHECK(!last_site_.is_empty());
421 DeleteLocalStorage(last_site_); 437 DeleteLocalStorage(last_site_);
422 } 438 }
423 439
424 void WebsiteSettingsHandler::HandleStopOrigin(const base::ListValue* args) { 440 void WebsiteSettingsHandler::HandleStopOrigin(const base::ListValue* args) {
425 DCHECK(!last_site_.is_empty()); 441 DCHECK(!last_site_.is_empty());
426 StopOrigin(last_site_); 442 StopOrigin(last_site_);
427 } 443 }
428 444
445 // TODO(dhnishi): Remove default settings duplication from the
446 // WebsiteSettingsHandler and the ContentSettingsHandler.
447 void WebsiteSettingsHandler::HandleUpdateDefaultSetting(
448 const base::ListValue* args) {
449 ContentSettingsType last_setting;
450 content_settings::GetTypeFromName(last_setting_, &last_setting);
451
452 base::DictionaryValue filter_settings;
453 std::string provider_id;
454 filter_settings.SetString(
455 "value", GetSettingDefaultFromModel(last_setting, &provider_id));
456 filter_settings.SetString("managedBy", provider_id);
457
458 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.updateDefault",
459 filter_settings);
460 }
461
462 void WebsiteSettingsHandler::HandleSetDefaultSetting(
463 const base::ListValue* args) {
464 DCHECK_EQ(1U, args->GetSize());
465 std::string setting;
466 if (!args->GetString(0, &setting)) {
467 NOTREACHED();
468 return;
469 }
470 ContentSetting new_default =
471 content_settings::ContentSettingFromString(setting);
472
473 ContentSettingsType last_setting;
474 content_settings::GetTypeFromName(last_setting_, &last_setting);
475 Profile* profile = Profile::FromWebUI(web_ui());
476
477 #if defined(OS_CHROMEOS)
478 // ChromeOS special case : in Guest mode settings are opened in Incognito
479 // mode, so we need original profile to actually modify settings.
480 if (user_manager::UserManager::Get()->IsLoggedInAsGuest())
481 profile = profile->GetOriginalProfile();
482 #endif
483
484 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
485 map->SetDefaultContentSetting(last_setting, new_default);
486
487 switch (last_setting) {
488 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
489 content::RecordAction(
490 UserMetricsAction("Options_DefaultMultipleAutomaticDLSettingChange"));
491 break;
492 case CONTENT_SETTINGS_TYPE_COOKIES:
493 content::RecordAction(
494 UserMetricsAction("Options_DefaultCookieSettingChanged"));
495 break;
496 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
497 content::RecordAction(
498 UserMetricsAction("Options_DefaultGeolocationSettingChanged"));
499 break;
500 case CONTENT_SETTINGS_TYPE_IMAGES:
501 content::RecordAction(
502 UserMetricsAction("Options_DefaultImagesSettingChanged"));
503 break;
504 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
505 content::RecordAction(
506 UserMetricsAction("Options_DefaultJavaScriptSettingChanged"));
507 break;
508 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
509 content::RecordAction(
510 UserMetricsAction("Options_DefaultMediaStreamMicSettingChanged"));
511 break;
512 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
513 content::RecordAction(
514 UserMetricsAction("Options_DefaultNotificationsSettingChanged"));
515 break;
516 case CONTENT_SETTINGS_TYPE_PLUGINS:
517 content::RecordAction(
518 UserMetricsAction("Options_DefaultPluginsSettingChanged"));
519 break;
520 case CONTENT_SETTINGS_TYPE_POPUPS:
521 content::RecordAction(
522 UserMetricsAction("Options_DefaultPopupsSettingChanged"));
523 break;
524 default:
525 NOTREACHED();
526 return;
527 }
528 }
529
429 void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, 530 void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url,
430 bool show_page) { 531 bool show_page) {
431 Profile* profile = Profile::FromWebUI(web_ui()); 532 Profile* profile = Profile::FromWebUI(web_ui());
432 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); 533 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
433 534
434 double storage = 0.0; 535 double storage = 0.0;
435 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); 536 for (LocalStorageList::const_iterator it = local_storage_list_.begin();
436 it != local_storage_list_.end(); 537 it != local_storage_list_.end();
437 it++) { 538 it++) {
438 if (it->origin_url == site_url) { 539 if (it->origin_url == site_url) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT, 661 l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT,
561 it->second)); 662 it->second));
562 origin_entry->SetStringWithoutPathExpansion("readableName", 663 origin_entry->SetStringWithoutPathExpansion("readableName",
563 GetReadableName(it->first)); 664 GetReadableName(it->first));
564 power_map.SetWithoutPathExpansion(origin, origin_entry); 665 power_map.SetWithoutPathExpansion(origin, origin_entry);
565 } 666 }
566 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", 667 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins",
567 power_map); 668 power_map);
568 } 669 }
569 670
671 std::string WebsiteSettingsHandler::GetSettingDefaultFromModel(
672 ContentSettingsType type,
673 std::string* provider_id) {
674 Profile* profile = Profile::FromWebUI(web_ui());
675 ContentSetting default_setting =
676 profile->GetHostContentSettingsMap()->GetDefaultContentSetting(
677 type, provider_id);
678
679 return content_settings::ContentSettingToString(default_setting);
680 }
681
570 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) { 682 void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) {
571 Profile* profile = Profile::FromWebUI(web_ui()); 683 Profile* profile = Profile::FromWebUI(web_ui());
572 if (site_url.SchemeIs(extensions::kExtensionScheme)) { 684 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
573 const extensions::Extension* extension = 685 const extensions::Extension* extension =
574 extensions::ExtensionRegistry::Get(profile) 686 extensions::ExtensionRegistry::Get(profile)
575 ->enabled_extensions() 687 ->enabled_extensions()
576 .GetHostedAppByURL(site_url); 688 .GetHostedAppByURL(site_url);
577 if (extension) { 689 if (extension) {
578 extensions::AppWindowRegistry::Get(profile) 690 extensions::AppWindowRegistry::Get(profile)
579 ->CloseAllAppWindowsForApp(extension->id()); 691 ->CloseAllAppWindowsForApp(extension->id());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 // If extension is NULL, it was removed and we cannot look up its name. 739 // If extension is NULL, it was removed and we cannot look up its name.
628 if (!extension) 740 if (!extension)
629 return site_url.spec(); 741 return site_url.spec();
630 742
631 return extension->name(); 743 return extension->name();
632 } 744 }
633 return site_url.spec(); 745 return site_url.spec();
634 } 746 }
635 747
636 } // namespace options 748 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/website_settings_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698