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