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