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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 DCHECK(localized_strings); | 68 DCHECK(localized_strings); |
69 | 69 |
70 static OptionsStringResource resources[] = { | 70 static OptionsStringResource resources[] = { |
71 {"websitesOptionsPageTabTitle", IDS_WEBSITE_SETTINGS_TITLE}, | 71 {"websitesOptionsPageTabTitle", IDS_WEBSITE_SETTINGS_TITLE}, |
72 {"websitesSettingsEditPage", IDS_WEBSITE_SETTINGS_EDIT_TITLE}, | 72 {"websitesSettingsEditPage", IDS_WEBSITE_SETTINGS_EDIT_TITLE}, |
73 {"websitesManage", IDS_WEBSITE_SETTINGS_MANAGE}, | 73 {"websitesManage", IDS_WEBSITE_SETTINGS_MANAGE}, |
74 {"websitesSearch", IDS_WEBSITE_SETTINGS_SEARCH_ORIGINS}, | 74 {"websitesSearch", IDS_WEBSITE_SETTINGS_SEARCH_ORIGINS}, |
75 {"websitesLabelLocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, | 75 {"websitesLabelLocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, |
76 {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, | 76 {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, |
77 {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, | 77 {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, |
| 78 {"websitesLabelOn", IDS_WEBSITE_SETTINGS_CONTENT_SETTING_ENABLED}, |
78 {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, | 79 {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, |
79 {"websitesLabelBattery", IDS_WEBSITE_SETTINGS_TYPE_BATTERY}, | 80 {"websitesLabelBattery", IDS_WEBSITE_SETTINGS_TYPE_BATTERY}, |
80 {"websitesCookiesDescription", IDS_WEBSITE_SETTINGS_COOKIES_DESCRIPTION}, | 81 {"websitesCookiesDescription", IDS_WEBSITE_SETTINGS_COOKIES_DESCRIPTION}, |
81 {"websitesLocationDescription", | 82 {"websitesLocationDescription", |
82 IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION}, | 83 IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION}, |
83 {"websitesMediaStreamDescription", | 84 {"websitesMediaStreamDescription", |
84 IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION}, | 85 IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION}, |
85 {"websitesNotificationsDescription", | 86 {"websitesNotificationsDescription", |
86 IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, | 87 IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, |
87 {"websitesDownloadsDescription", | 88 {"websitesDownloadsDescription", |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 164 |
164 web_ui()->RegisterMessageCallback( | 165 web_ui()->RegisterMessageCallback( |
165 "updateDefaultSetting", | 166 "updateDefaultSetting", |
166 base::Bind(&WebsiteSettingsHandler::HandleUpdateDefaultSetting, | 167 base::Bind(&WebsiteSettingsHandler::HandleUpdateDefaultSetting, |
167 base::Unretained(this))); | 168 base::Unretained(this))); |
168 | 169 |
169 web_ui()->RegisterMessageCallback( | 170 web_ui()->RegisterMessageCallback( |
170 "setDefaultContentSetting", | 171 "setDefaultContentSetting", |
171 base::Bind(&WebsiteSettingsHandler::HandleSetDefaultSetting, | 172 base::Bind(&WebsiteSettingsHandler::HandleSetDefaultSetting, |
172 base::Unretained(this))); | 173 base::Unretained(this))); |
| 174 |
| 175 web_ui()->RegisterMessageCallback( |
| 176 "setGlobalEnabled", |
| 177 base::Bind(&WebsiteSettingsHandler::HandleSetGlobalToggle, |
| 178 base::Unretained(this))); |
173 } | 179 } |
174 | 180 |
175 // content_settings::Observer implementation. | 181 // content_settings::Observer implementation. |
176 void WebsiteSettingsHandler::OnContentSettingChanged( | 182 void WebsiteSettingsHandler::OnContentSettingChanged( |
177 const ContentSettingsPattern& primary_pattern, | 183 const ContentSettingsPattern& primary_pattern, |
178 const ContentSettingsPattern& secondary_pattern, | 184 const ContentSettingsPattern& secondary_pattern, |
179 ContentSettingsType content_type, | 185 ContentSettingsType content_type, |
180 std::string resource_identifier) { | 186 std::string resource_identifier) { |
181 Update(); | 187 Update(); |
182 } | 188 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 origin_url.IntPort() == kHttpPort) || | 298 origin_url.IntPort() == kHttpPort) || |
293 (origin_url.SchemeIs(url::kHttpsScheme) && | 299 (origin_url.SchemeIs(url::kHttpsScheme) && |
294 origin_url.IntPort() == kHttpsPort)) { | 300 origin_url.IntPort() == kHttpsPort)) { |
295 url::Replacements<char> replacements; | 301 url::Replacements<char> replacements; |
296 replacements.ClearPort(); | 302 replacements.ClearPort(); |
297 origin = origin_url.ReplaceComponents(replacements).spec(); | 303 origin = origin_url.ReplaceComponents(replacements).spec(); |
298 } | 304 } |
299 | 305 |
300 // Mediastream isn't set unless both mic and camera are set to the same. | 306 // Mediastream isn't set unless both mic and camera are set to the same. |
301 if (last_setting == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 307 if (last_setting == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
302 ContentSetting cam_setting = | 308 ContentSetting cam_setting = settings->GetContentSettingWithoutOverride( |
303 settings->GetContentSetting(origin_url, | 309 origin_url, |
304 origin_url, | 310 origin_url, |
305 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 311 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
306 std::string()); | 312 std::string()); |
307 if (it->setting != cam_setting) | 313 if (it->setting != cam_setting) |
308 continue; | 314 continue; |
309 } | 315 } |
310 | 316 |
311 if (origin.find(last_filter_) == base::string16::npos) | 317 if (origin.find(last_filter_) == base::string16::npos) |
312 continue; | 318 continue; |
313 | 319 |
314 base::Time last_usage = settings->GetLastUsageByPattern( | 320 base::Time last_usage = settings->GetLastUsageByPattern( |
315 it->primary_pattern, it->secondary_pattern, last_setting); | 321 it->primary_pattern, it->secondary_pattern, last_setting); |
316 | 322 |
317 base::DictionaryValue* origin_entry = new base::DictionaryValue(); | 323 base::DictionaryValue* origin_entry = new base::DictionaryValue(); |
318 origin_entry->SetDoubleWithoutPathExpansion("usage", | 324 origin_entry->SetDoubleWithoutPathExpansion("usage", |
319 last_usage.ToDoubleT()); | 325 last_usage.ToDoubleT()); |
320 base::string16 usage_string; | 326 base::string16 usage_string; |
321 if (last_usage.ToDoubleT()) { | 327 if (last_usage.ToDoubleT()) { |
322 usage_string = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, | 328 usage_string = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, |
323 ui::TimeFormat::LENGTH_SHORT, | 329 ui::TimeFormat::LENGTH_SHORT, |
324 base::Time::Now() - last_usage); | 330 base::Time::Now() - last_usage); |
325 } | 331 } |
326 origin_entry->SetStringWithoutPathExpansion("usageString", usage_string); | 332 origin_entry->SetStringWithoutPathExpansion("usageString", usage_string); |
327 origin_entry->SetStringWithoutPathExpansion("readableName", | 333 origin_entry->SetStringWithoutPathExpansion("readableName", |
328 GetReadableName(origin_url)); | 334 GetReadableName(origin_url)); |
329 | 335 |
330 if (it->setting == CONTENT_SETTING_BLOCK) | 336 if (it->setting == CONTENT_SETTING_BLOCK) |
331 blocked_origins.SetWithoutPathExpansion(origin, origin_entry); | 337 blocked_origins.SetWithoutPathExpansion(origin, origin_entry); |
332 else | 338 else |
333 allowed_origins.SetWithoutPathExpansion(origin, origin_entry); | 339 allowed_origins.SetWithoutPathExpansion(origin, origin_entry); |
334 } | 340 } |
335 | 341 |
| 342 bool is_globally_allowed = settings->GetContentSettingOverride(last_setting); |
336 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", | 343 web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", |
337 allowed_origins, | 344 allowed_origins, |
338 blocked_origins); | 345 blocked_origins, |
| 346 base::FundamentalValue(is_globally_allowed)); |
339 } | 347 } |
340 | 348 |
341 void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { | 349 void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { |
342 std::string url; | 350 std::string url; |
343 bool rv = args->GetString(0, &url); | 351 bool rv = args->GetString(0, &url); |
344 DCHECK(rv); | 352 DCHECK(rv); |
345 GURL origin(url); | 353 GURL origin(url); |
346 | 354 |
347 if (!origin.is_valid()) | 355 if (!origin.is_valid()) |
348 return; | 356 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 case CONTENT_SETTINGS_TYPE_POPUPS: | 412 case CONTENT_SETTINGS_TYPE_POPUPS: |
405 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); | 413 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); |
406 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); | 414 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(last_site_); |
407 break; | 415 break; |
408 default: | 416 default: |
409 NOTREACHED() << "Content settings type not yet supported."; | 417 NOTREACHED() << "Content settings type not yet supported."; |
410 return; | 418 return; |
411 } | 419 } |
412 | 420 |
413 content_settings::SettingInfo info; | 421 content_settings::SettingInfo info; |
414 scoped_ptr<base::Value> v(map->GetWebsiteSetting( | 422 scoped_ptr<base::Value> v(map->GetWebsiteSettingWithoutOverride( |
415 last_site_, last_site_, settings_type, std::string(), &info)); | 423 last_site_, last_site_, settings_type, std::string(), &info)); |
416 map->SetNarrowestWebsiteSetting(primary_pattern, | 424 map->SetNarrowestWebsiteSetting(primary_pattern, |
417 secondary_pattern, | 425 secondary_pattern, |
418 settings_type, | 426 settings_type, |
419 std::string(), | 427 std::string(), |
420 setting, | 428 setting, |
421 info); | 429 info); |
422 } | 430 } |
423 | 431 |
424 void WebsiteSettingsHandler::HandleUpdateBatteryUsage( | 432 void WebsiteSettingsHandler::HandleUpdateBatteryUsage( |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 case CONTENT_SETTINGS_TYPE_POPUPS: | 524 case CONTENT_SETTINGS_TYPE_POPUPS: |
517 content::RecordAction( | 525 content::RecordAction( |
518 UserMetricsAction("Options_DefaultPopupsSettingChanged")); | 526 UserMetricsAction("Options_DefaultPopupsSettingChanged")); |
519 break; | 527 break; |
520 default: | 528 default: |
521 NOTREACHED(); | 529 NOTREACHED(); |
522 return; | 530 return; |
523 } | 531 } |
524 } | 532 } |
525 | 533 |
| 534 void WebsiteSettingsHandler::HandleSetGlobalToggle( |
| 535 const base::ListValue* args) { |
| 536 DCHECK_EQ(1U, args->GetSize()); |
| 537 bool is_enabled; |
| 538 bool rv = args->GetBoolean(0, &is_enabled); |
| 539 DCHECK(rv); |
| 540 |
| 541 ContentSettingsType last_setting; |
| 542 rv = content_settings::GetTypeFromName(last_setting_, &last_setting); |
| 543 DCHECK(rv); |
| 544 |
| 545 Profile* profile = Profile::FromWebUI(web_ui()); |
| 546 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
| 547 map->SetContentSettingOverride(last_setting, is_enabled); |
| 548 } |
| 549 |
526 void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, | 550 void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, |
527 bool show_page) { | 551 bool show_page) { |
528 Profile* profile = Profile::FromWebUI(web_ui()); | 552 Profile* profile = Profile::FromWebUI(web_ui()); |
529 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 553 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
530 | 554 |
531 double storage = 0.0; | 555 double storage = 0.0; |
532 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); | 556 for (LocalStorageList::const_iterator it = local_storage_list_.begin(); |
533 it != local_storage_list_.end(); | 557 it != local_storage_list_.end(); |
534 it++) { | 558 it++) { |
535 if (it->origin_url == site_url) { | 559 if (it->origin_url == site_url) { |
(...skipping 24 matching lines...) Expand all Loading... |
560 options->AppendString( | 584 options->AppendString( |
561 content_settings::ContentSettingToString(CONTENT_SETTING_BLOCK)); | 585 content_settings::ContentSettingToString(CONTENT_SETTING_BLOCK)); |
562 if (permission_type == CONTENT_SETTINGS_TYPE_COOKIES) { | 586 if (permission_type == CONTENT_SETTINGS_TYPE_COOKIES) { |
563 options->AppendString(content_settings::ContentSettingToString( | 587 options->AppendString(content_settings::ContentSettingToString( |
564 CONTENT_SETTING_SESSION_ONLY)); | 588 CONTENT_SETTING_SESSION_ONLY)); |
565 } | 589 } |
566 | 590 |
567 ContentSetting permission; | 591 ContentSetting permission; |
568 content_settings::SettingInfo info; | 592 content_settings::SettingInfo info; |
569 if (permission_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) { | 593 if (permission_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) { |
570 scoped_ptr<base::Value> mic_value( | 594 scoped_ptr<base::Value> mic_value(map->GetWebsiteSettingWithoutOverride( |
571 map->GetWebsiteSetting(site_url, | 595 site_url, |
572 site_url, | 596 site_url, |
573 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 597 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
574 std::string(), | 598 std::string(), |
575 &info)); | 599 &info)); |
576 ContentSetting mic_setting = | 600 ContentSetting mic_setting = |
577 content_settings::ValueToContentSetting(mic_value.get()); | 601 content_settings::ValueToContentSetting(mic_value.get()); |
578 ContentSetting cam_setting = | 602 ContentSetting cam_setting = map->GetContentSettingWithoutOverride( |
579 map->GetContentSetting(site_url, | 603 site_url, |
580 site_url, | 604 site_url, |
581 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 605 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
582 std::string()); | 606 std::string()); |
583 | 607 |
584 if (mic_setting != cam_setting) | 608 if (mic_setting != cam_setting) |
585 permission = CONTENT_SETTING_ASK; | 609 permission = CONTENT_SETTING_ASK; |
586 else | 610 else |
587 permission = mic_setting; | 611 permission = mic_setting; |
588 } else { | 612 } else { |
589 scoped_ptr<base::Value> v(map->GetWebsiteSetting( | 613 scoped_ptr<base::Value> v(map->GetWebsiteSettingWithoutOverride( |
590 site_url, site_url, permission_type, std::string(), &info)); | 614 site_url, site_url, permission_type, std::string(), &info)); |
591 permission = content_settings::ValueToContentSetting(v.get()); | 615 permission = content_settings::ValueToContentSetting(v.get()); |
592 } | 616 } |
593 | 617 |
594 base::DictionaryValue* permission_info = new base::DictionaryValue; | 618 base::DictionaryValue* permission_info = new base::DictionaryValue; |
595 permission_info->SetStringWithoutPathExpansion( | 619 permission_info->SetStringWithoutPathExpansion( |
596 "setting", content_settings::ContentSettingToString(permission)); | 620 "setting", content_settings::ContentSettingToString(permission)); |
597 permission_info->SetWithoutPathExpansion("options", options); | 621 permission_info->SetWithoutPathExpansion("options", options); |
598 permission_info->SetBooleanWithoutPathExpansion( | 622 permission_info->SetBooleanWithoutPathExpansion( |
599 "editable", info.source == content_settings::SETTING_SOURCE_USER); | 623 "editable", info.source == content_settings::SETTING_SOURCE_USER); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 // If extension is NULL, it was removed and we cannot look up its name. | 759 // If extension is NULL, it was removed and we cannot look up its name. |
736 if (!extension) | 760 if (!extension) |
737 return site_url.spec(); | 761 return site_url.spec(); |
738 | 762 |
739 return extension->name(); | 763 return extension->name(); |
740 } | 764 } |
741 return site_url.spec(); | 765 return site_url.spec(); |
742 } | 766 } |
743 | 767 |
744 } // namespace options | 768 } // namespace options |
OLD | NEW |