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

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

Issue 7810017: Revert 98938 - Migrate Obsolete NotificationsSettings and remove content_settings::NotificationsP... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/desktop_notification_service.h" 5 #include "chrome/browser/notifications/desktop_notification_service.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/content_settings/content_settings_details.h"
11 #include "chrome/browser/content_settings/content_settings_pattern.h"
12 #include "chrome/browser/content_settings/content_settings_provider.h" 10 #include "chrome/browser/content_settings/content_settings_provider.h"
13 #include "chrome/browser/content_settings/host_content_settings_map.h" 11 #include "chrome/browser/content_settings/host_content_settings_map.h"
14 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 13 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
16 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
17 #include "chrome/browser/notifications/notification_object_proxy.h" 15 #include "chrome/browser/notifications/notification_object_proxy.h"
18 #include "chrome/browser/notifications/notification_ui_manager.h" 16 #include "chrome/browser/notifications/notification_ui_manager.h"
17 #include "chrome/browser/notifications/notifications_prefs_cache.h"
19 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/prefs/scoped_user_pref_update.h" 19 #include "chrome/browser/prefs/scoped_user_pref_update.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
23 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
25 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
28 #include "content/browser/browser_child_process_host.h" 27 #include "content/browser/browser_child_process_host.h"
(...skipping 10 matching lines...) Expand all
39 #include "grit/theme_resources.h" 38 #include "grit/theme_resources.h"
40 #include "net/base/escape.h" 39 #include "net/base/escape.h"
41 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
42 #include "ui/base/resource/resource_bundle.h" 41 #include "ui/base/resource/resource_bundle.h"
43 42
44 using WebKit::WebNotificationPresenter; 43 using WebKit::WebNotificationPresenter;
45 using WebKit::WebTextDirection; 44 using WebKit::WebTextDirection;
46 45
47 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; 46 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK;
48 47
48 namespace {
49
50 typedef content_settings::ProviderInterface::Rules Rules;
51
52 void GetOriginsWithSettingFromContentSettingsRules(
53 const Rules& content_setting_rules,
54 ContentSetting setting,
55 std::vector<GURL>* origins) {
56 origins->clear();
57
58 for (Rules::const_iterator rule = content_setting_rules.begin();
59 rule != content_setting_rules.end();
60 ++rule) {
61 if (setting == rule->content_setting) {
62 std::string url_str = rule->primary_pattern.ToString();
63 if (!rule->primary_pattern.IsValid()) {
64 // TODO(markusheintz): This will be removed in one of the next
65 // refactoring steps as this entire function will disapear.
66 LOG(DFATAL) << "Ignoring invalid content settings pattern: "
67 << url_str;
68 } else if (url_str.find(ContentSettingsPattern::kDomainWildcard) == 0) {
69 // TODO(markusheintz): This must be changed once the UI code is
70 // refactored and content_settings patterns are fully supported for
71 // notifications settings.
72 LOG(DFATAL) << "Ignoring unsupported content settings pattern: "
73 << url_str << ". Content settings patterns other than "
74 << "hostnames (e.g. wildcard patterns) are not supported "
75 << "for notification content settings yet.";
76 } else {
77 origins->push_back(
78 content_settings::NotificationProvider::ToGURL(
79 rule->primary_pattern));
80 }
81 }
82 }
83 }
84
85 } // namespace
86
49 // NotificationPermissionInfoBarDelegate -------------------------------------- 87 // NotificationPermissionInfoBarDelegate --------------------------------------
50 88
51 // The delegate for the infobar shown when an origin requests notification 89 // The delegate for the infobar shown when an origin requests notification
52 // permissions. 90 // permissions.
53 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { 91 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
54 public: 92 public:
55 NotificationPermissionInfoBarDelegate(TabContents* contents, 93 NotificationPermissionInfoBarDelegate(TabContents* contents,
56 const GURL& origin, 94 const GURL& origin,
57 const string16& display_name, 95 const string16& display_name,
58 int process_id, 96 int process_id,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 245
208 std::string data = ReplaceStringPlaceholders(template_html, subst, NULL); 246 std::string data = ReplaceStringPlaceholders(template_html, subst, NULL);
209 return UTF8ToUTF16("data:text/html;charset=utf-8," + 247 return UTF8ToUTF16("data:text/html;charset=utf-8," +
210 EscapeQueryParamValue(data, false)); 248 EscapeQueryParamValue(data, false));
211 } 249 }
212 250
213 DesktopNotificationService::DesktopNotificationService(Profile* profile, 251 DesktopNotificationService::DesktopNotificationService(Profile* profile,
214 NotificationUIManager* ui_manager) 252 NotificationUIManager* ui_manager)
215 : profile_(profile), 253 : profile_(profile),
216 ui_manager_(ui_manager) { 254 ui_manager_(ui_manager) {
255 prefs_registrar_.Init(profile_->GetPrefs());
256 InitPrefs();
217 StartObserving(); 257 StartObserving();
218 } 258 }
219 259
220 DesktopNotificationService::~DesktopNotificationService() { 260 DesktopNotificationService::~DesktopNotificationService() {
221 StopObserving(); 261 StopObserving();
222 } 262 }
223 263
264 void DesktopNotificationService::RegisterUserPrefs(PrefService* user_prefs) {
265 content_settings::NotificationProvider::RegisterUserPrefs(user_prefs);
266 }
267
268 // Initialize the cache with the allowed and denied origins, or
269 // create the preferences if they don't exist yet.
270 void DesktopNotificationService::InitPrefs() {
271 provider_.reset(new content_settings::NotificationProvider(profile_));
272
273 std::vector<GURL> allowed_origins;
274 std::vector<GURL> denied_origins;
275 ContentSetting default_content_setting = CONTENT_SETTING_DEFAULT;
276
277 if (!profile_->IsOffTheRecord()) {
278 default_content_setting =
279 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
280 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
281 allowed_origins = GetAllowedOrigins();
282 denied_origins = GetBlockedOrigins();
283 }
284
285 prefs_cache_ = new NotificationsPrefsCache();
286 prefs_cache_->SetCacheDefaultContentSetting(default_content_setting);
287 prefs_cache_->SetCacheAllowedOrigins(allowed_origins);
288 prefs_cache_->SetCacheDeniedOrigins(denied_origins);
289 prefs_cache_->set_is_initialized(true);
290 }
291
224 void DesktopNotificationService::StartObserving() { 292 void DesktopNotificationService::StartObserving() {
225 if (!profile_->IsOffTheRecord()) { 293 if (!profile_->IsOffTheRecord()) {
294 prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this);
295 prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this);
226 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 296 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
227 NotificationService::AllSources()); 297 NotificationService::AllSources());
298 notification_registrar_.Add(
299 this,
300 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
301 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()));
228 } 302 }
229 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 303 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
230 Source<Profile>(profile_)); 304 Source<Profile>(profile_));
231 } 305 }
232 306
233 void DesktopNotificationService::StopObserving() { 307 void DesktopNotificationService::StopObserving() {
308 if (!profile_->IsOffTheRecord()) {
309 prefs_registrar_.RemoveAll();
310 }
234 notification_registrar_.RemoveAll(); 311 notification_registrar_.RemoveAll();
235 } 312 }
236 313
237 void DesktopNotificationService::GrantPermission(const GURL& origin) { 314 void DesktopNotificationService::GrantPermission(const GURL& origin) {
238 ContentSettingsPattern primary_pattern = 315 ContentSettingsPattern pattern =
239 ContentSettingsPattern::FromURLNoWildcard(origin); 316 content_settings::NotificationProvider::ToContentSettingsPattern(origin);
240 profile_->GetHostContentSettingsMap()->SetContentSetting( 317 provider_->SetContentSetting(
241 primary_pattern, 318 pattern,
242 ContentSettingsPattern::Wildcard(), 319 pattern,
243 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 320 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
244 NO_RESOURCE_IDENTIFIER, 321 NO_RESOURCE_IDENTIFIER,
245 CONTENT_SETTING_ALLOW); 322 CONTENT_SETTING_ALLOW);
323
324 // Schedule a cache update on the IO thread.
325 BrowserThread::PostTask(
326 BrowserThread::IO, FROM_HERE,
327 NewRunnableMethod(
328 prefs_cache_.get(),
329 &NotificationsPrefsCache::CacheAllowedOrigin,
330 origin));
246 } 331 }
247 332
248 void DesktopNotificationService::DenyPermission(const GURL& origin) { 333 void DesktopNotificationService::DenyPermission(const GURL& origin) {
249 ContentSettingsPattern primary_pattern = 334 // Update content settings
250 ContentSettingsPattern::FromURLNoWildcard(origin); 335 ContentSettingsPattern pattern =
251 profile_->GetHostContentSettingsMap()->SetContentSetting( 336 content_settings::NotificationProvider::ToContentSettingsPattern(origin);
252 primary_pattern, 337 provider_->SetContentSetting(
253 ContentSettingsPattern::Wildcard(), 338 pattern,
339 pattern,
254 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 340 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
255 NO_RESOURCE_IDENTIFIER, 341 NO_RESOURCE_IDENTIFIER,
256 CONTENT_SETTING_BLOCK); 342 CONTENT_SETTING_BLOCK);
343
344 // Schedule a cache update on the IO thread.
345 BrowserThread::PostTask(
346 BrowserThread::IO, FROM_HERE,
347 NewRunnableMethod(
348 prefs_cache_.get(),
349 &NotificationsPrefsCache::CacheDeniedOrigin,
350 origin));
257 } 351 }
258 352
259 void DesktopNotificationService::Observe(int type, 353 void DesktopNotificationService::Observe(int type,
260 const NotificationSource& source, 354 const NotificationSource& source,
261 const NotificationDetails& details) { 355 const NotificationDetails& details) {
262 if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) { 356 if (chrome::NOTIFICATION_PREF_CHANGED == type) {
357 const std::string& name = *Details<std::string>(details).ptr();
358 OnPrefsChanged(name);
359 } else if (chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED == type) {
360 // TODO(markusheintz): Check if content settings type default was changed;
361 const ContentSetting default_content_setting =
362 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
363 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
364 // Schedule a cache update on the IO thread.
365 BrowserThread::PostTask(
366 BrowserThread::IO, FROM_HERE,
367 NewRunnableMethod(
368 prefs_cache_.get(),
369 &NotificationsPrefsCache::SetCacheDefaultContentSetting,
370 default_content_setting));
371 } else if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) {
263 // Remove all notifications currently shown or queued by the extension 372 // Remove all notifications currently shown or queued by the extension
264 // which was unloaded. 373 // which was unloaded.
265 const Extension* extension = 374 const Extension* extension =
266 Details<UnloadedExtensionInfo>(details)->extension; 375 Details<UnloadedExtensionInfo>(details)->extension;
267 if (extension) 376 if (extension)
268 ui_manager_->CancelAllBySourceOrigin(extension->url()); 377 ui_manager_->CancelAllBySourceOrigin(extension->url());
269 } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) { 378 } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) {
270 StopObserving(); 379 StopObserving();
271 } 380 }
272 } 381 }
273 382
383 void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) {
384 if (pref_name == prefs::kDesktopNotificationAllowedOrigins) {
385 // Schedule a cache update on the IO thread.
386 std::vector<GURL> allowed_origins(GetAllowedOrigins());
387 BrowserThread::PostTask(
388 BrowserThread::IO, FROM_HERE,
389 NewRunnableMethod(
390 prefs_cache_.get(),
391 &NotificationsPrefsCache::SetCacheAllowedOrigins,
392 allowed_origins));
393 } else if (pref_name == prefs::kDesktopNotificationDeniedOrigins) {
394 // Schedule a cache update on the IO thread.
395 std::vector<GURL> denied_origins(GetBlockedOrigins());
396 BrowserThread::PostTask(
397 BrowserThread::IO, FROM_HERE,
398 NewRunnableMethod(
399 prefs_cache_.get(),
400 &NotificationsPrefsCache::SetCacheDeniedOrigins,
401 denied_origins));
402 } else {
403 NOTREACHED();
404 }
405 }
406
274 ContentSetting DesktopNotificationService::GetDefaultContentSetting() { 407 ContentSetting DesktopNotificationService::GetDefaultContentSetting() {
275 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( 408 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
276 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 409 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
277 } 410 }
278 411
279 void DesktopNotificationService::SetDefaultContentSetting( 412 void DesktopNotificationService::SetDefaultContentSetting(
280 ContentSetting setting) { 413 ContentSetting setting) {
281 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( 414 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
282 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); 415 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting);
283 } 416 }
284 417
285 bool DesktopNotificationService::IsDefaultContentSettingManaged() const { 418 bool DesktopNotificationService::IsDefaultContentSettingManaged() const {
286 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( 419 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged(
287 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 420 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
288 } 421 }
289 422
290 void DesktopNotificationService::ResetToDefaultContentSetting() { 423 void DesktopNotificationService::ResetToDefaultContentSetting() {
291 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( 424 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
292 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_DEFAULT); 425 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_DEFAULT);
293 } 426 }
294 427
295 void DesktopNotificationService::GetNotificationsSettings( 428 std::vector<GURL> DesktopNotificationService::GetAllowedOrigins() {
296 HostContentSettingsMap::SettingsForOneType* settings) { 429 content_settings::ProviderInterface::Rules content_setting_rules;
297 profile_->GetHostContentSettingsMap()->GetSettingsForOneType( 430 provider_->GetAllContentSettingsRules(
298 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 431 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
299 NO_RESOURCE_IDENTIFIER, 432 NO_RESOURCE_IDENTIFIER,
300 settings); 433 &content_setting_rules);
434 std::vector<GURL> allowed_origins;
435
436 GetOriginsWithSettingFromContentSettingsRules(
437 content_setting_rules, CONTENT_SETTING_ALLOW, &allowed_origins);
438
439 return allowed_origins;
301 } 440 }
302 441
303 void DesktopNotificationService::ClearSetting( 442 std::vector<GURL> DesktopNotificationService::GetBlockedOrigins() {
304 const ContentSettingsPattern& pattern) { 443 content_settings::ProviderInterface::Rules content_settings_rules;
305 profile_->GetHostContentSettingsMap()->SetContentSetting( 444 provider_->GetAllContentSettingsRules(
445 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
446 NO_RESOURCE_IDENTIFIER,
447 &content_settings_rules);
448 std::vector<GURL> denied_origins;
449
450 GetOriginsWithSettingFromContentSettingsRules(
451 content_settings_rules, CONTENT_SETTING_BLOCK, &denied_origins);
452
453 return denied_origins;
454 }
455
456 void DesktopNotificationService::ResetAllowedOrigin(const GURL& origin) {
457 ContentSettingsPattern pattern =
458 ContentSettingsPattern::FromURLNoWildcard(origin);
459 provider_->SetContentSetting(
306 pattern, 460 pattern,
307 ContentSettingsPattern::Wildcard(), 461 pattern,
462 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
463 NO_RESOURCE_IDENTIFIER,
464 CONTENT_SETTING_DEFAULT);
465 }
466
467 void DesktopNotificationService::ResetBlockedOrigin(const GURL& origin) {
468 ContentSettingsPattern pattern =
469 ContentSettingsPattern::FromURLNoWildcard(origin);
470 provider_->SetContentSetting(
471 pattern,
472 pattern,
308 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 473 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
309 NO_RESOURCE_IDENTIFIER, 474 NO_RESOURCE_IDENTIFIER,
310 CONTENT_SETTING_DEFAULT); 475 CONTENT_SETTING_DEFAULT);
311 } 476 }
312 477
313 void DesktopNotificationService::ResetAllOrigins() { 478 void DesktopNotificationService::ResetAllOrigins() {
314 profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( 479 provider_->ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
315 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
316 } 480 }
317 481
318 ContentSetting DesktopNotificationService::GetContentSetting( 482 ContentSetting DesktopNotificationService::GetContentSetting(
319 const GURL& origin) { 483 const GURL& origin) {
320 return profile_->GetHostContentSettingsMap()->GetContentSetting( 484 ContentSetting provided_setting = provider_->GetContentSetting(
321 origin, 485 origin,
322 origin, 486 origin,
323 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 487 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
324 NO_RESOURCE_IDENTIFIER); 488 NO_RESOURCE_IDENTIFIER);
489 if (CONTENT_SETTING_DEFAULT == provided_setting)
490 return GetDefaultContentSetting();
491 return provided_setting;
325 } 492 }
326 493
327 void DesktopNotificationService::RequestPermission( 494 void DesktopNotificationService::RequestPermission(
328 const GURL& origin, int process_id, int route_id, int callback_context, 495 const GURL& origin, int process_id, int route_id, int callback_context,
329 TabContents* tab) { 496 TabContents* tab) {
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
331 if (!tab) { 498 if (!tab) {
332 Browser* browser = BrowserList::GetLastActive(); 499 Browser* browser = BrowserList::GetLastActive();
333 if (browser) 500 if (browser)
334 tab = browser->GetSelectedTabContents(); 501 tab = browser->GetSelectedTabContents();
(...skipping 30 matching lines...) Expand all
365 } 532 }
366 533
367 bool DesktopNotificationService::CancelDesktopNotification( 534 bool DesktopNotificationService::CancelDesktopNotification(
368 int process_id, int route_id, int notification_id) { 535 int process_id, int route_id, int notification_id) {
369 scoped_refptr<NotificationObjectProxy> proxy( 536 scoped_refptr<NotificationObjectProxy> proxy(
370 new NotificationObjectProxy(process_id, route_id, notification_id, 537 new NotificationObjectProxy(process_id, route_id, notification_id,
371 false)); 538 false));
372 return ui_manager_->CancelById(proxy->id()); 539 return ui_manager_->CancelById(proxy->id());
373 } 540 }
374 541
542
375 bool DesktopNotificationService::ShowDesktopNotification( 543 bool DesktopNotificationService::ShowDesktopNotification(
376 const DesktopNotificationHostMsg_Show_Params& params, 544 const DesktopNotificationHostMsg_Show_Params& params,
377 int process_id, int route_id, DesktopNotificationSource source) { 545 int process_id, int route_id, DesktopNotificationSource source) {
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
379 const GURL& origin = params.origin; 547 const GURL& origin = params.origin;
380 NotificationObjectProxy* proxy = 548 NotificationObjectProxy* proxy =
381 new NotificationObjectProxy(process_id, route_id, 549 new NotificationObjectProxy(process_id, route_id,
382 params.notification_id, 550 params.notification_id,
383 source == WorkerNotification); 551 source == WorkerNotification);
384 GURL contents; 552 GURL contents;
(...skipping 29 matching lines...) Expand all
414 void DesktopNotificationService::NotifySettingsChange() { 582 void DesktopNotificationService::NotifySettingsChange() {
415 NotificationService::current()->Notify( 583 NotificationService::current()->Notify(
416 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, 584 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
417 Source<DesktopNotificationService>(this), 585 Source<DesktopNotificationService>(this),
418 NotificationService::NoDetails()); 586 NotificationService::NoDetails());
419 } 587 }
420 588
421 WebKit::WebNotificationPresenter::Permission 589 WebKit::WebNotificationPresenter::Permission
422 DesktopNotificationService::HasPermission(const GURL& origin) { 590 DesktopNotificationService::HasPermission(const GURL& origin) {
423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
424 HostContentSettingsMap* host_content_settings_map = 592 return prefs_cache()->HasPermission(origin.GetOrigin());
425 profile_->GetHostContentSettingsMap();
426 ContentSetting setting = host_content_settings_map->GetContentSetting(
427 origin,
428 origin,
429 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
430 NO_RESOURCE_IDENTIFIER);
431
432 if (setting == CONTENT_SETTING_ALLOW)
433 return WebKit::WebNotificationPresenter::PermissionAllowed;
434 if (setting == CONTENT_SETTING_BLOCK)
435 return WebKit::WebNotificationPresenter::PermissionDenied;
436 if (setting == CONTENT_SETTING_ASK)
437 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
438 NOTREACHED() << "Invalid notifications settings value: " << setting;
439 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
440 } 593 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698