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