Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/browser/notifications/message_center_settings_controller.cc

Issue 376253005: Migrate the notification permission to the new common permission classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
21 #include "chrome/browser/notifications/desktop_notification_service.h" 22 #include "chrome/browser/notifications/desktop_notification_service.h"
22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 23 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
23 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" 24 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
24 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac tory.h" 25 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac tory.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 #endif 304 #endif
304 305
305 if (comparator) { 306 if (comparator) {
306 std::sort(notifiers->begin() + app_count, notifiers->end(), *comparator); 307 std::sort(notifiers->begin() + app_count, notifiers->end(), *comparator);
307 } else { 308 } else {
308 std::sort(notifiers->begin() + app_count, notifiers->end(), 309 std::sort(notifiers->begin() + app_count, notifiers->end(),
309 SimpleCompareNotifiers); 310 SimpleCompareNotifiers);
310 } 311 }
311 } 312 }
312 313
313 void MessageCenterSettingsController::SetNotifierEnabled( 314 void MessageCenterSettingsController::SetNotifierEnabled(
Peter Beverloo 2014/07/10 11:29:39 The MessageCenterSettingsController is the setting
Miguel Garcia 2014/07/17 17:24:48 Let's talk about this one offline ok? I think it d
314 const Notifier& notifier, 315 const Notifier& notifier,
315 bool enabled) { 316 bool enabled) {
316 DCHECK_LT(current_notifier_group_, notifier_groups_.size()); 317 DCHECK_LT(current_notifier_group_, notifier_groups_.size());
317 Profile* profile = notifier_groups_[current_notifier_group_]->profile(); 318 Profile* profile = notifier_groups_[current_notifier_group_]->profile();
318 319
319 DesktopNotificationService* notification_service = 320 DesktopNotificationService* notification_service =
320 DesktopNotificationServiceFactory::GetForProfile(profile); 321 DesktopNotificationServiceFactory::GetForProfile(profile);
321 322
322 if (notifier.notifier_id.type == NotifierId::WEB_PAGE) { 323 if (notifier.notifier_id.type == NotifierId::WEB_PAGE) {
323 // WEB_PAGE notifier cannot handle in DesktopNotificationService 324 // WEB_PAGE notifier cannot handle in DesktopNotificationService
324 // since it has the exact URL pattern. 325 // since it has the exact URL pattern.
325 // TODO(mukai): fix this. 326 // TODO(mukai): fix this.
326 ContentSetting default_setting = 327 ContentSetting default_setting =
327 notification_service->GetDefaultContentSetting(NULL); 328 profile->GetHostContentSettingsMap()->GetDefaultContentSetting(
329 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL);
330
328 DCHECK(default_setting == CONTENT_SETTING_ALLOW || 331 DCHECK(default_setting == CONTENT_SETTING_ALLOW ||
329 default_setting == CONTENT_SETTING_BLOCK || 332 default_setting == CONTENT_SETTING_BLOCK ||
330 default_setting == CONTENT_SETTING_ASK); 333 default_setting == CONTENT_SETTING_ASK);
331 if ((enabled && default_setting != CONTENT_SETTING_ALLOW) || 334 if ((enabled && default_setting != CONTENT_SETTING_ALLOW) ||
332 (!enabled && default_setting == CONTENT_SETTING_ALLOW)) { 335 (!enabled && default_setting == CONTENT_SETTING_ALLOW)) {
333 if (notifier.notifier_id.url.is_valid()) { 336 if (notifier.notifier_id.url.is_valid()) {
334 if (enabled) 337 ContentSettingsPattern primary_pattern =
335 notification_service->GrantPermission(notifier.notifier_id.url); 338 ContentSettingsPattern::FromURLNoWildcard(notifier.notifier_id.url);
336 else 339 profile->GetHostContentSettingsMap()->SetContentSetting(
337 notification_service->DenyPermission(notifier.notifier_id.url); 340 primary_pattern,
341 ContentSettingsPattern::Wildcard(),
342 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
343 NO_RESOURCE_IDENTIFIER,
344 enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
338 } else { 345 } else {
339 LOG(ERROR) << "Invalid url pattern: " 346 LOG(ERROR) << "Invalid url pattern: "
340 << notifier.notifier_id.url.spec(); 347 << notifier.notifier_id.url.spec();
341 } 348 }
342 } else { 349 } else {
343 std::map<base::string16, ContentSettingsPattern>::const_iterator iter = 350 std::map<base::string16, ContentSettingsPattern>::const_iterator iter =
344 patterns_.find(notifier.name); 351 patterns_.find(notifier.name);
345 if (iter != patterns_.end()) { 352 if (iter != patterns_.end()) {
346 notification_service->ClearSetting(iter->second); 353 profile->GetHostContentSettingsMap()->SetContentSetting(
354 iter->second,
355 ContentSettingsPattern::Wildcard(),
356 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
357 NO_RESOURCE_IDENTIFIER,
358 CONTENT_SETTING_DEFAULT);
347 } else { 359 } else {
348 LOG(ERROR) << "Invalid url pattern: " 360 LOG(ERROR) << "Invalid url pattern: "
349 << notifier.notifier_id.url.spec(); 361 << notifier.notifier_id.url.spec();
350 } 362 }
351 } 363 }
352 } else { 364 } else {
353 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled); 365 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled);
354 } 366 }
355 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 367 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
356 observers_, 368 observers_,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // another creating a primary profile, and causes an infinite loop. 534 // another creating a primary profile, and causes an infinite loop.
523 // Thus, it would be better to delay creating group for guest login. 535 // Thus, it would be better to delay creating group for guest login.
524 base::MessageLoopProxy::current()->PostTask( 536 base::MessageLoopProxy::current()->PostTask(
525 FROM_HERE, 537 FROM_HERE,
526 base::Bind( 538 base::Bind(
527 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin, 539 &MessageCenterSettingsController::CreateNotifierGroupForGuestLogin,
528 weak_factory_.GetWeakPtr())); 540 weak_factory_.GetWeakPtr()));
529 } 541 }
530 #endif 542 #endif
531 } 543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698