| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/notifications/message_center_settings_controller.h" | 5 #include "chrome/browser/notifications/message_center_settings_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/string_compare.h" | 10 #include "base/i18n/string_compare.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/task/cancelable_task_tracker.h" | 13 #include "base/task/cancelable_task_tracker.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 16 #include "chrome/browser/extensions/app_icon_loader_impl.h" | 17 #include "chrome/browser/extensions/app_icon_loader_impl.h" |
| 17 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
| 18 #include "chrome/browser/favicon/favicon_service.h" | 19 #include "chrome/browser/favicon/favicon_service.h" |
| 19 #include "chrome/browser/favicon/favicon_service_factory.h" | 20 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 20 #include "chrome/browser/history/history_types.h" | 21 #include "chrome/browser/history/history_types.h" |
| 22 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 21 #include "chrome/browser/notifications/desktop_notification_service.h" | 23 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 24 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 23 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 25 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 24 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" | 26 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_info_cache.h" | 28 #include "chrome/browser/profiles/profile_info_cache.h" |
| 27 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
| 28 #include "chrome/common/extensions/api/notifications.h" | 30 #include "chrome/common/extensions/api/notifications.h" |
| 29 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
| 30 #include "components/favicon_base/favicon_types.h" | 32 #include "components/favicon_base/favicon_types.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 notifiers->push_back(new Notifier( | 244 notifiers->push_back(new Notifier( |
| 243 notifier_id, | 245 notifier_id, |
| 244 base::UTF8ToUTF16(extension->name()), | 246 base::UTF8ToUTF16(extension->name()), |
| 245 notification_service->IsNotifierEnabled(notifier_id))); | 247 notification_service->IsNotifierEnabled(notifier_id))); |
| 246 app_icon_loader_->FetchImage(extension->id()); | 248 app_icon_loader_->FetchImage(extension->id()); |
| 247 } | 249 } |
| 248 | 250 |
| 249 int app_count = notifiers->size(); | 251 int app_count = notifiers->size(); |
| 250 | 252 |
| 251 ContentSettingsForOneType settings; | 253 ContentSettingsForOneType settings; |
| 252 notification_service->GetNotificationsSettings(&settings); | 254 DesktopNotificationProfileUtil::GetNotificationsSettings(profile, &settings); |
| 255 |
| 253 FaviconService* favicon_service = | 256 FaviconService* favicon_service = |
| 254 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 257 FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
| 255 favicon_tracker_.reset(new base::CancelableTaskTracker()); | 258 favicon_tracker_.reset(new base::CancelableTaskTracker()); |
| 256 patterns_.clear(); | 259 patterns_.clear(); |
| 257 for (ContentSettingsForOneType::const_iterator iter = settings.begin(); | 260 for (ContentSettingsForOneType::const_iterator iter = settings.begin(); |
| 258 iter != settings.end(); ++iter) { | 261 iter != settings.end(); ++iter) { |
| 259 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() && | 262 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() && |
| 260 iter->secondary_pattern == ContentSettingsPattern::Wildcard() && | 263 iter->secondary_pattern == ContentSettingsPattern::Wildcard() && |
| 261 iter->source != "preference") { | 264 iter->source != "preference") { |
| 262 continue; | 265 continue; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 Profile* profile = notifier_groups_[current_notifier_group_]->profile(); | 316 Profile* profile = notifier_groups_[current_notifier_group_]->profile(); |
| 314 | 317 |
| 315 DesktopNotificationService* notification_service = | 318 DesktopNotificationService* notification_service = |
| 316 DesktopNotificationServiceFactory::GetForProfile(profile); | 319 DesktopNotificationServiceFactory::GetForProfile(profile); |
| 317 | 320 |
| 318 if (notifier.notifier_id.type == NotifierId::WEB_PAGE) { | 321 if (notifier.notifier_id.type == NotifierId::WEB_PAGE) { |
| 319 // WEB_PAGE notifier cannot handle in DesktopNotificationService | 322 // WEB_PAGE notifier cannot handle in DesktopNotificationService |
| 320 // since it has the exact URL pattern. | 323 // since it has the exact URL pattern. |
| 321 // TODO(mukai): fix this. | 324 // TODO(mukai): fix this. |
| 322 ContentSetting default_setting = | 325 ContentSetting default_setting = |
| 323 notification_service->GetDefaultContentSetting(NULL); | 326 profile->GetHostContentSettingsMap()->GetDefaultContentSetting( |
| 327 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); |
| 328 |
| 324 DCHECK(default_setting == CONTENT_SETTING_ALLOW || | 329 DCHECK(default_setting == CONTENT_SETTING_ALLOW || |
| 325 default_setting == CONTENT_SETTING_BLOCK || | 330 default_setting == CONTENT_SETTING_BLOCK || |
| 326 default_setting == CONTENT_SETTING_ASK); | 331 default_setting == CONTENT_SETTING_ASK); |
| 327 if ((enabled && default_setting != CONTENT_SETTING_ALLOW) || | 332 if ((enabled && default_setting != CONTENT_SETTING_ALLOW) || |
| 328 (!enabled && default_setting == CONTENT_SETTING_ALLOW)) { | 333 (!enabled && default_setting == CONTENT_SETTING_ALLOW)) { |
| 329 if (notifier.notifier_id.url.is_valid()) { | 334 if (notifier.notifier_id.url.is_valid()) { |
| 330 if (enabled) | 335 if (enabled) |
| 331 notification_service->GrantPermission(notifier.notifier_id.url); | 336 DesktopNotificationProfileUtil::GrantPermission( |
| 337 profile, notifier.notifier_id.url); |
| 332 else | 338 else |
| 333 notification_service->DenyPermission(notifier.notifier_id.url); | 339 DesktopNotificationProfileUtil::DenyPermission( |
| 340 profile, notifier.notifier_id.url); |
| 334 } else { | 341 } else { |
| 335 LOG(ERROR) << "Invalid url pattern: " | 342 LOG(ERROR) << "Invalid url pattern: " |
| 336 << notifier.notifier_id.url.spec(); | 343 << notifier.notifier_id.url.spec(); |
| 337 } | 344 } |
| 338 } else { | 345 } else { |
| 339 std::map<base::string16, ContentSettingsPattern>::const_iterator iter = | 346 std::map<base::string16, ContentSettingsPattern>::const_iterator iter = |
| 340 patterns_.find(notifier.name); | 347 patterns_.find(notifier.name); |
| 341 if (iter != patterns_.end()) { | 348 if (iter != patterns_.end()) { |
| 342 notification_service->ClearSetting(iter->second); | 349 DesktopNotificationProfileUtil::ClearSetting(profile, iter->second); |
| 343 } else { | 350 } else { |
| 344 LOG(ERROR) << "Invalid url pattern: " | 351 LOG(ERROR) << "Invalid url pattern: " |
| 345 << notifier.notifier_id.url.spec(); | 352 << notifier.notifier_id.url.spec(); |
| 346 } | 353 } |
| 347 } | 354 } |
| 348 } else { | 355 } else { |
| 349 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled); | 356 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled); |
| 350 } | 357 } |
| 351 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 358 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
| 352 observers_, | 359 observers_, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 // another creating a primary profile, and causes an infinite loop. | 525 // another creating a primary profile, and causes an infinite loop. |
| 519 // Thus, it would be better to delay creating group for guest login. | 526 // Thus, it would be better to delay creating group for guest login. |
| 520 base::MessageLoopProxy::current()->PostTask( | 527 base::MessageLoopProxy::current()->PostTask( |
| 521 FROM_HERE, | 528 FROM_HERE, |
| 522 base::Bind( | 529 base::Bind( |
| 523 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, | 530 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, |
| 524 weak_factory_.GetWeakPtr())); | 531 weak_factory_.GetWeakPtr())); |
| 525 } | 532 } |
| 526 #endif | 533 #endif |
| 527 } | 534 } |
| OLD | NEW |