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

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: 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
« no previous file with comments | « no previous file | chrome/browser/notifications/message_center_settings_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // The content setting for notifications needs to clear when it changes to
319 // the default value or get explicitly set when it differs from the default.
320 bool differs_from_default_value =
321 (default_setting != CONTENT_SETTING_ALLOW && enabled) ||
322 (default_setting == CONTENT_SETTING_ALLOW && !enabled);
323
324 if (differs_from_default_value) {
319 if (notifier.notifier_id.url.is_valid()) { 325 if (notifier.notifier_id.url.is_valid()) {
320 if (enabled) 326 if (enabled) {
321 DesktopNotificationProfileUtil::GrantPermission( 327 DesktopNotificationProfileUtil::GrantPermission(
322 profile, notifier.notifier_id.url); 328 profile, notifier.notifier_id.url);
323 else 329 } else {
324 DesktopNotificationProfileUtil::DenyPermission( 330 DesktopNotificationProfileUtil::DenyPermission(
325 profile, notifier.notifier_id.url); 331 profile, notifier.notifier_id.url);
332 }
326 } else { 333 } else {
327 LOG(ERROR) << "Invalid url pattern: " 334 LOG(ERROR) << "Invalid url pattern: "
328 << notifier.notifier_id.url.spec(); 335 << notifier.notifier_id.url.spec();
329 } 336 }
330 } else { 337 } else {
331 std::map<base::string16, ContentSettingsPattern>::const_iterator iter = 338 ContentSettingsPattern pattern;
332 patterns_.find(notifier.name); 339
340 const auto& iter = patterns_.find(notifier.name);
333 if (iter != patterns_.end()) { 341 if (iter != patterns_.end()) {
334 DesktopNotificationProfileUtil::ClearSetting(profile, iter->second); 342 pattern = iter->second;
343 } else if (notifier.notifier_id.url.is_valid()) {
344 pattern =
345 ContentSettingsPattern::FromURLNoWildcard(notifier.notifier_id.url);
335 } else { 346 } else {
336 LOG(ERROR) << "Invalid url pattern: " 347 LOG(ERROR) << "Invalid url pattern: "
337 << notifier.notifier_id.url.spec(); 348 << notifier.notifier_id.url.spec();
338 } 349 }
350
351 if (pattern.IsValid())
352 DesktopNotificationProfileUtil::ClearSetting(profile, pattern);
339 } 353 }
340 } else { 354 } else {
341 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled); 355 notification_service->SetNotifierEnabled(notifier.notifier_id, enabled);
342 } 356 }
343 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 357 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
344 observers_, 358 observers_,
345 NotifierEnabledChanged(notifier.notifier_id, enabled)); 359 NotifierEnabledChanged(notifier.notifier_id, enabled));
346 } 360 }
347 361
348 void MessageCenterSettingsController::OnNotifierSettingsClosing() { 362 void MessageCenterSettingsController::OnNotifierSettingsClosing() {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 weak_factory_.GetWeakPtr())); 547 weak_factory_.GetWeakPtr()));
534 } 548 }
535 #endif 549 #endif
536 550
537 if (notify) { 551 if (notify) {
538 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 552 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
539 observers_, 553 observers_,
540 NotifierGroupChanged()); 554 NotifierGroupChanged());
541 } 555 }
542 } 556 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/notifications/message_center_settings_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698