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

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

Issue 1103203002: Allow resetting Notification permission from the toast's context menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a test Created 5 years, 7 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
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"
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // WEB_PAGE notifier cannot handle in DesktopNotificationService 307 // WEB_PAGE notifier cannot handle in DesktopNotificationService
308 // since it has the exact URL pattern. 308 // since it has the exact URL pattern.
309 // TODO(mukai): fix this. 309 // TODO(mukai): fix this.
310 ContentSetting default_setting = 310 ContentSetting default_setting =
311 profile->GetHostContentSettingsMap()->GetDefaultContentSetting( 311 profile->GetHostContentSettingsMap()->GetDefaultContentSetting(
312 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); 312 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL);
313 313
314 DCHECK(default_setting == CONTENT_SETTING_ALLOW || 314 DCHECK(default_setting == CONTENT_SETTING_ALLOW ||
315 default_setting == CONTENT_SETTING_BLOCK || 315 default_setting == CONTENT_SETTING_BLOCK ||
316 default_setting == CONTENT_SETTING_ASK); 316 default_setting == CONTENT_SETTING_ASK);
317 if ((enabled && default_setting != CONTENT_SETTING_ALLOW) || 317
318 (!enabled && default_setting == CONTENT_SETTING_ALLOW)) { 318 bool derive_from_default_value =
dewittj 2015/04/27 16:48:51 nit: derive isn't completely clear here.. Possibl
Peter Beverloo 2015/04/28 12:14:44 Done.
319 (default_setting != CONTENT_SETTING_ALLOW && enabled) ||
320 (default_setting == CONTENT_SETTING_ALLOW && !enabled);
321
322 if (derive_from_default_value) {
319 if (notifier.notifier_id.url.is_valid()) { 323 if (notifier.notifier_id.url.is_valid()) {
320 if (enabled) 324 if (enabled)
dewittj 2015/04/27 16:48:51 nit: please add braces to this if/else since they
Peter Beverloo 2015/04/28 12:14:45 Done.
321 DesktopNotificationProfileUtil::GrantPermission( 325 DesktopNotificationProfileUtil::GrantPermission(
322 profile, notifier.notifier_id.url); 326 profile, notifier.notifier_id.url);
323 else 327 else
324 DesktopNotificationProfileUtil::DenyPermission( 328 DesktopNotificationProfileUtil::DenyPermission(
325 profile, notifier.notifier_id.url); 329 profile, notifier.notifier_id.url);
326 } else { 330 } else {
327 LOG(ERROR) << "Invalid url pattern: " 331 LOG(ERROR) << "Invalid url pattern: "
328 << notifier.notifier_id.url.spec(); 332 << notifier.notifier_id.url.spec();
329 } 333 }
330 } else { 334 } else {
331 std::map<base::string16, ContentSettingsPattern>::const_iterator iter = 335 ContentSettingsPattern pattern;
332 patterns_.find(notifier.name); 336
337 const auto& iter = patterns_.find(notifier.name);
333 if (iter != patterns_.end()) { 338 if (iter != patterns_.end()) {
334 DesktopNotificationProfileUtil::ClearSetting(profile, iter->second); 339 pattern = iter->second;
340 } else if (notifier.notifier_id.url.is_valid()) {
341 pattern =
342 ContentSettingsPattern::FromURLNoWildcard(notifier.notifier_id.url);
335 } else { 343 } else {
336 LOG(ERROR) << "Invalid url pattern: " 344 LOG(ERROR) << "Invalid url pattern: "
337 << notifier.notifier_id.url.spec(); 345 << notifier.notifier_id.url.spec();
338 } 346 }
347
348 if (pattern.IsValid())
349 DesktopNotificationProfileUtil::ClearSetting(profile, pattern);
339 } 350 }
340 } else { 351 } else {
341 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled); 352 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled);
342 } 353 }
343 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 354 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
344 observers_, 355 observers_,
345 NotifierEnabledChanged(notifier.notifier_id, enabled)); 356 NotifierEnabledChanged(notifier.notifier_id, enabled));
346 } 357 }
347 358
348 void MessageCenterSettingsController::OnNotifierSettingsClosing() { 359 void MessageCenterSettingsController::OnNotifierSettingsClosing() {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 weak_factory_.GetWeakPtr())); 544 weak_factory_.GetWeakPtr()));
534 } 545 }
535 #endif 546 #endif
536 547
537 if (notify) { 548 if (notify) {
538 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 549 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
539 observers_, 550 observers_,
540 NotifierGroupChanged()); 551 NotifierGroupChanged());
541 } 552 }
542 } 553 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698