| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/content_settings/content_settings_details.h" | 12 #include "chrome/browser/content_settings/content_settings_details.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 14 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 14 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 15 #include "chrome/browser/notifications/desktop_notification_service.h" | 15 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 16 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/content_settings_helper.h" | 20 #include "chrome/common/content_settings_helper.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 22 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
| 23 #include "content/common/notification_source.h" | 24 #include "content/common/notification_source.h" |
| 24 #include "content/common/notification_type.h" | 25 #include "content/common/notification_type.h" |
| 25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 "ContentSettings.setContentFilterSettingsValue", filter_settings); | 369 "ContentSettings.setContentFilterSettingsValue", filter_settings); |
| 369 } | 370 } |
| 370 | 371 |
| 371 std::string ContentSettingsHandler::GetSettingDefaultFromModel( | 372 std::string ContentSettingsHandler::GetSettingDefaultFromModel( |
| 372 ContentSettingsType type) { | 373 ContentSettingsType type) { |
| 373 ContentSetting default_setting; | 374 ContentSetting default_setting; |
| 374 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 375 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 375 default_setting = web_ui_->GetProfile()-> | 376 default_setting = web_ui_->GetProfile()-> |
| 376 GetGeolocationContentSettingsMap()->GetDefaultContentSetting(); | 377 GetGeolocationContentSettingsMap()->GetDefaultContentSetting(); |
| 377 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 378 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
| 378 default_setting = web_ui_->GetProfile()-> | 379 default_setting = DesktopNotificationServiceFactory::GetForProfile( |
| 379 GetDesktopNotificationService()->GetDefaultContentSetting(); | 380 web_ui_->GetProfile())->GetDefaultContentSetting(); |
| 380 } else { | 381 } else { |
| 381 default_setting = GetContentSettingsMap()->GetDefaultContentSetting(type); | 382 default_setting = GetContentSettingsMap()->GetDefaultContentSetting(type); |
| 382 } | 383 } |
| 383 | 384 |
| 384 return ContentSettingToString(default_setting); | 385 return ContentSettingToString(default_setting); |
| 385 } | 386 } |
| 386 | 387 |
| 387 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( | 388 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( |
| 388 ContentSettingsType type) { | 389 ContentSettingsType type) { |
| 389 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 390 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 390 return web_ui_->GetProfile()-> | 391 return web_ui_->GetProfile()-> |
| 391 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged(); | 392 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged(); |
| 392 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 393 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
| 393 return web_ui_->GetProfile()-> | 394 return DesktopNotificationServiceFactory::GetForProfile( |
| 394 GetDesktopNotificationService()->IsDefaultContentSettingManaged(); | 395 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); |
| 395 } else { | 396 } else { |
| 396 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); | 397 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); |
| 397 } | 398 } |
| 398 } | 399 } |
| 399 | 400 |
| 400 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { | 401 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { |
| 401 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 402 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
| 402 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 403 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
| 403 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 404 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
| 404 } | 405 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", | 485 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", |
| 485 type_string, exceptions); | 486 type_string, exceptions); |
| 486 | 487 |
| 487 // This is mainly here to keep this function ideologically parallel to | 488 // This is mainly here to keep this function ideologically parallel to |
| 488 // UpdateExceptionsViewFromHostContentSettingsMap(). | 489 // UpdateExceptionsViewFromHostContentSettingsMap(). |
| 489 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 490 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 490 } | 491 } |
| 491 | 492 |
| 492 void ContentSettingsHandler::UpdateNotificationExceptionsView() { | 493 void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
| 493 DesktopNotificationService* service = | 494 DesktopNotificationService* service = |
| 494 web_ui_->GetProfile()->GetDesktopNotificationService(); | 495 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile()); |
| 495 | 496 |
| 496 std::vector<GURL> allowed(service->GetAllowedOrigins()); | 497 std::vector<GURL> allowed(service->GetAllowedOrigins()); |
| 497 std::vector<GURL> blocked(service->GetBlockedOrigins()); | 498 std::vector<GURL> blocked(service->GetBlockedOrigins()); |
| 498 | 499 |
| 499 ListValue exceptions; | 500 ListValue exceptions; |
| 500 for (size_t i = 0; i < allowed.size(); ++i) { | 501 for (size_t i = 0; i < allowed.size(); ++i) { |
| 501 exceptions.Append( | 502 exceptions.Append( |
| 502 GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW)); | 503 GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW)); |
| 503 } | 504 } |
| 504 for (size_t i = 0; i < blocked.size(); ++i) { | 505 for (size_t i = 0; i < blocked.size(); ++i) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 NOTREACHED(); | 584 NOTREACHED(); |
| 584 return; | 585 return; |
| 585 } | 586 } |
| 586 | 587 |
| 587 ContentSetting default_setting = ContentSettingFromString(setting); | 588 ContentSetting default_setting = ContentSettingFromString(setting); |
| 588 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); | 589 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); |
| 589 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 590 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 590 web_ui_->GetProfile()->GetGeolocationContentSettingsMap()-> | 591 web_ui_->GetProfile()->GetGeolocationContentSettingsMap()-> |
| 591 SetDefaultContentSetting(default_setting); | 592 SetDefaultContentSetting(default_setting); |
| 592 } else if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 593 } else if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
| 593 web_ui_->GetProfile()->GetDesktopNotificationService()-> | 594 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> |
| 594 SetDefaultContentSetting(default_setting); | 595 SetDefaultContentSetting(default_setting); |
| 595 } else { | 596 } else { |
| 596 GetContentSettingsMap()-> | 597 GetContentSettingsMap()-> |
| 597 SetDefaultContentSetting(content_type, default_setting); | 598 SetDefaultContentSetting(content_type, default_setting); |
| 598 } | 599 } |
| 599 } | 600 } |
| 600 | 601 |
| 601 void ContentSettingsHandler::SetAllowThirdPartyCookies(const ListValue* args) { | 602 void ContentSettingsHandler::SetAllowThirdPartyCookies(const ListValue* args) { |
| 602 string16 allow = ExtractStringValue(args); | 603 string16 allow = ExtractStringValue(args); |
| 603 | 604 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 625 CONTENT_SETTING_DEFAULT); | 626 CONTENT_SETTING_DEFAULT); |
| 626 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 627 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
| 627 std::string origin; | 628 std::string origin; |
| 628 std::string setting; | 629 std::string setting; |
| 629 bool rv = args->GetString(arg_i++, &origin); | 630 bool rv = args->GetString(arg_i++, &origin); |
| 630 DCHECK(rv); | 631 DCHECK(rv); |
| 631 rv = args->GetString(arg_i++, &setting); | 632 rv = args->GetString(arg_i++, &setting); |
| 632 DCHECK(rv); | 633 DCHECK(rv); |
| 633 ContentSetting content_setting = ContentSettingFromString(setting); | 634 ContentSetting content_setting = ContentSettingFromString(setting); |
| 634 if (content_setting == CONTENT_SETTING_ALLOW) { | 635 if (content_setting == CONTENT_SETTING_ALLOW) { |
| 635 web_ui_->GetProfile()->GetDesktopNotificationService()-> | 636 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> |
| 636 ResetAllowedOrigin(GURL(origin)); | 637 ResetAllowedOrigin(GURL(origin)); |
| 637 } else { | 638 } else { |
| 638 DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK); | 639 DCHECK_EQ(content_setting, CONTENT_SETTING_BLOCK); |
| 639 web_ui_->GetProfile()->GetDesktopNotificationService()-> | 640 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> |
| 640 ResetBlockedOrigin(GURL(origin)); | 641 ResetBlockedOrigin(GURL(origin)); |
| 641 } | 642 } |
| 642 } else { | 643 } else { |
| 643 std::string mode; | 644 std::string mode; |
| 644 bool rv = args->GetString(arg_i++, &mode); | 645 bool rv = args->GetString(arg_i++, &mode); |
| 645 DCHECK(rv); | 646 DCHECK(rv); |
| 646 | 647 |
| 647 std::string pattern; | 648 std::string pattern; |
| 648 rv = args->GetString(arg_i++, &pattern); | 649 rv = args->GetString(arg_i++, &pattern); |
| 649 DCHECK(rv); | 650 DCHECK(rv); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 return web_ui_->GetProfile()->GetHostContentSettingsMap(); | 736 return web_ui_->GetProfile()->GetHostContentSettingsMap(); |
| 736 } | 737 } |
| 737 | 738 |
| 738 HostContentSettingsMap* | 739 HostContentSettingsMap* |
| 739 ContentSettingsHandler::GetOTRContentSettingsMap() { | 740 ContentSettingsHandler::GetOTRContentSettingsMap() { |
| 740 Profile* profile = web_ui_->GetProfile(); | 741 Profile* profile = web_ui_->GetProfile(); |
| 741 if (profile->HasOffTheRecordProfile()) | 742 if (profile->HasOffTheRecordProfile()) |
| 742 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 743 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
| 743 return NULL; | 744 return NULL; |
| 744 } | 745 } |
| OLD | NEW |