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

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

Issue 1694923004: Use GURLs instead of patterns in SetContentSetting in notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scoping_set_content_setting
Patch Set: remove patterns_ Created 4 years, 9 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 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 app_icon_loader_->FetchImage(extension->id()); 240 app_icon_loader_->FetchImage(extension->id());
241 } 241 }
242 242
243 ContentSettingsForOneType settings; 243 ContentSettingsForOneType settings;
244 DesktopNotificationProfileUtil::GetNotificationsSettings(profile, &settings); 244 DesktopNotificationProfileUtil::GetNotificationsSettings(profile, &settings);
245 245
246 favicon::FaviconService* favicon_service = 246 favicon::FaviconService* favicon_service =
247 FaviconServiceFactory::GetForProfile(profile, 247 FaviconServiceFactory::GetForProfile(profile,
248 ServiceAccessType::EXPLICIT_ACCESS); 248 ServiceAccessType::EXPLICIT_ACCESS);
249 favicon_tracker_.reset(new base::CancelableTaskTracker()); 249 favicon_tracker_.reset(new base::CancelableTaskTracker());
250 patterns_.clear();
251 for (ContentSettingsForOneType::const_iterator iter = settings.begin(); 250 for (ContentSettingsForOneType::const_iterator iter = settings.begin();
252 iter != settings.end(); ++iter) { 251 iter != settings.end(); ++iter) {
253 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() && 252 if (iter->primary_pattern == ContentSettingsPattern::Wildcard() &&
254 iter->secondary_pattern == ContentSettingsPattern::Wildcard() && 253 iter->secondary_pattern == ContentSettingsPattern::Wildcard() &&
255 iter->source != "preference") { 254 iter->source != "preference") {
256 continue; 255 continue;
257 } 256 }
258 257
259 std::string url_pattern = iter->primary_pattern.ToString(); 258 std::string url_pattern = iter->primary_pattern.ToString();
260 base::string16 name = base::UTF8ToUTF16(url_pattern); 259 base::string16 name = base::UTF8ToUTF16(url_pattern);
261 GURL url(url_pattern); 260 GURL url(url_pattern);
262 NotifierId notifier_id(url); 261 NotifierId notifier_id(url);
263 notifiers->push_back(new Notifier( 262 notifiers->push_back(new Notifier(
264 notifier_id, 263 notifier_id,
265 name, 264 name,
266 notifier_state_tracker->IsNotifierEnabled(notifier_id))); 265 notifier_state_tracker->IsNotifierEnabled(notifier_id)));
267 patterns_[name] = iter->primary_pattern;
268 // Note that favicon service obtains the favicon from history. This means 266 // Note that favicon service obtains the favicon from history. This means
269 // that it will fail to obtain the image if there are no history data for 267 // that it will fail to obtain the image if there are no history data for
270 // that URL. 268 // that URL.
271 favicon_service->GetFaviconImageForPageURL( 269 favicon_service->GetFaviconImageForPageURL(
272 url, 270 url,
273 base::Bind(&MessageCenterSettingsController::OnFaviconLoaded, 271 base::Bind(&MessageCenterSettingsController::OnFaviconLoaded,
274 base::Unretained(this), 272 base::Unretained(this),
275 url), 273 url),
276 favicon_tracker_.get()); 274 favicon_tracker_.get());
277 } 275 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 DCHECK(default_setting == CONTENT_SETTING_ALLOW || 315 DCHECK(default_setting == CONTENT_SETTING_ALLOW ||
318 default_setting == CONTENT_SETTING_BLOCK || 316 default_setting == CONTENT_SETTING_BLOCK ||
319 default_setting == CONTENT_SETTING_ASK); 317 default_setting == CONTENT_SETTING_ASK);
320 318
321 // The content setting for notifications needs to clear when it changes to 319 // The content setting for notifications needs to clear when it changes to
322 // the default value or get explicitly set when it differs from the default. 320 // the default value or get explicitly set when it differs from the default.
323 bool differs_from_default_value = 321 bool differs_from_default_value =
324 (default_setting != CONTENT_SETTING_ALLOW && enabled) || 322 (default_setting != CONTENT_SETTING_ALLOW && enabled) ||
325 (default_setting == CONTENT_SETTING_ALLOW && !enabled); 323 (default_setting == CONTENT_SETTING_ALLOW && !enabled);
326 324
325 if (!notifier.notifier_id.url.is_valid()) {
326 LOG(ERROR) << "Invalid url pattern: " << notifier.notifier_id.url.spec();
327 }
328
327 if (differs_from_default_value) { 329 if (differs_from_default_value) {
328 if (notifier.notifier_id.url.is_valid()) {
329 if (enabled) { 330 if (enabled) {
330 DesktopNotificationProfileUtil::GrantPermission( 331 DesktopNotificationProfileUtil::GrantPermission(
331 profile, notifier.notifier_id.url); 332 profile, notifier.notifier_id.url);
332 } else { 333 } else {
333 DesktopNotificationProfileUtil::DenyPermission( 334 DesktopNotificationProfileUtil::DenyPermission(
334 profile, notifier.notifier_id.url); 335 profile, notifier.notifier_id.url);
335 } 336 }
336 } else {
337 LOG(ERROR) << "Invalid url pattern: "
338 << notifier.notifier_id.url.spec();
339 }
340 } else { 337 } else {
341 ContentSettingsPattern pattern; 338 DesktopNotificationProfileUtil::ClearSetting(profile,
342 339 notifier.notifier_id.url);
343 const auto& iter = patterns_.find(notifier.name);
344 if (iter != patterns_.end()) {
345 pattern = iter->second;
346 } else if (notifier.notifier_id.url.is_valid()) {
347 pattern =
348 ContentSettingsPattern::FromURLNoWildcard(notifier.notifier_id.url);
349 } else {
350 LOG(ERROR) << "Invalid url pattern: "
351 << notifier.notifier_id.url.spec();
352 }
353
354 if (pattern.IsValid())
355 DesktopNotificationProfileUtil::ClearSetting(profile, pattern);
raymes 2016/03/09 06:53:48 Hey Liu, I don't fully understand this code but it
356 } 340 }
357 } else { 341 } else {
358 NotifierStateTrackerFactory::GetForProfile(profile) 342 NotifierStateTrackerFactory::GetForProfile(profile)
359 ->SetNotifierEnabled(notifier.notifier_id, enabled); 343 ->SetNotifierEnabled(notifier.notifier_id, enabled);
360 } 344 }
361 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 345 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
362 observers_, 346 observers_,
363 NotifierEnabledChanged(notifier.notifier_id, enabled)); 347 NotifierEnabledChanged(notifier.notifier_id, enabled));
364 } 348 }
365 349
366 void MessageCenterSettingsController::OnNotifierSettingsClosing() { 350 void MessageCenterSettingsController::OnNotifierSettingsClosing() {
367 DCHECK(favicon_tracker_.get()); 351 DCHECK(favicon_tracker_.get());
368 favicon_tracker_->TryCancelAll(); 352 favicon_tracker_->TryCancelAll();
369 patterns_.clear();
370 } 353 }
371 354
372 bool MessageCenterSettingsController::NotifierHasAdvancedSettings( 355 bool MessageCenterSettingsController::NotifierHasAdvancedSettings(
373 const NotifierId& notifier_id) const { 356 const NotifierId& notifier_id) const {
374 // TODO(dewittj): Refactor this so that notifiers have a delegate that can 357 // TODO(dewittj): Refactor this so that notifiers have a delegate that can
375 // handle this in a more appropriate location. 358 // handle this in a more appropriate location.
376 if (notifier_id.type != NotifierId::APPLICATION) 359 if (notifier_id.type != NotifierId::APPLICATION)
377 return false; 360 return false;
378 361
379 const std::string& extension_id = notifier_id.id; 362 const std::string& extension_id = notifier_id.id;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 weak_factory_.GetWeakPtr())); 539 weak_factory_.GetWeakPtr()));
557 } 540 }
558 #endif 541 #endif
559 542
560 if (notify) { 543 if (notify) {
561 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, 544 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver,
562 observers_, 545 observers_,
563 NotifierGroupChanged()); 546 NotifierGroupChanged());
564 } 547 }
565 } 548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698