OLD | NEW |
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/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "content/browser/site_instance.h" | 33 #include "content/browser/site_instance.h" |
34 #include "content/browser/worker_host/worker_process_host.h" | 34 #include "content/browser/worker_host/worker_process_host.h" |
35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
37 #include "content/public/common/show_desktop_notification_params.h" | 37 #include "content/public/common/show_desktop_notification_params.h" |
38 #include "grit/browser_resources.h" | 38 #include "grit/browser_resources.h" |
39 #include "grit/chromium_strings.h" | 39 #include "grit/chromium_strings.h" |
40 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
41 #include "grit/theme_resources_standard.h" | 41 #include "grit/theme_resources_standard.h" |
42 #include "net/base/escape.h" | 42 #include "net/base/escape.h" |
| 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
44 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
45 | 46 |
46 using content::BrowserThread; | 47 using content::BrowserThread; |
47 using WebKit::WebNotificationPresenter; | 48 using WebKit::WebNotificationPresenter; |
48 using WebKit::WebTextDirection; | 49 using WebKit::WebTextDirection; |
| 50 using WebKit::WebSecurityOrigin; |
49 | 51 |
50 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; | 52 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; |
51 | 53 |
52 // NotificationPermissionInfoBarDelegate -------------------------------------- | 54 // NotificationPermissionInfoBarDelegate -------------------------------------- |
53 | 55 |
54 // The delegate for the infobar shown when an origin requests notification | 56 // The delegate for the infobar shown when an origin requests notification |
55 // permissions. | 57 // permissions. |
56 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | 58 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
57 public: | 59 public: |
58 NotificationPermissionInfoBarDelegate( | 60 NotificationPermissionInfoBarDelegate( |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 origin, contents, DisplayNameForOrigin(origin), | 401 origin, contents, DisplayNameForOrigin(origin), |
400 params.replace_id, proxy); | 402 params.replace_id, proxy); |
401 ShowNotification(notification); | 403 ShowNotification(notification); |
402 return true; | 404 return true; |
403 } | 405 } |
404 | 406 |
405 string16 DesktopNotificationService::DisplayNameForOrigin( | 407 string16 DesktopNotificationService::DisplayNameForOrigin( |
406 const GURL& origin) { | 408 const GURL& origin) { |
407 // If the source is an extension, lookup the display name. | 409 // If the source is an extension, lookup the display name. |
408 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 410 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
409 ExtensionService* ext_service = profile_->GetExtensionService(); | 411 ExtensionService* extension_service = profile_->GetExtensionService(); |
410 if (ext_service) { | 412 if (extension_service) { |
411 const Extension* extension = ext_service->GetExtensionByURL(origin); | 413 const Extension* extension = |
| 414 extension_service->extensions()->GetExtensionOrAppByURL( |
| 415 ExtensionURLInfo( |
| 416 WebSecurityOrigin::createFromString( |
| 417 UTF8ToUTF16(origin.spec())), |
| 418 origin)); |
412 if (extension) | 419 if (extension) |
413 return UTF8ToUTF16(extension->name()); | 420 return UTF8ToUTF16(extension->name()); |
414 } | 421 } |
415 } | 422 } |
416 return UTF8ToUTF16(origin.host()); | 423 return UTF8ToUTF16(origin.host()); |
417 } | 424 } |
418 | 425 |
419 void DesktopNotificationService::NotifySettingsChange() { | 426 void DesktopNotificationService::NotifySettingsChange() { |
420 content::NotificationService::current()->Notify( | 427 content::NotificationService::current()->Notify( |
421 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 428 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
(...skipping 22 matching lines...) Expand all Loading... |
444 | 451 |
445 if (setting == CONTENT_SETTING_ALLOW) | 452 if (setting == CONTENT_SETTING_ALLOW) |
446 return WebKit::WebNotificationPresenter::PermissionAllowed; | 453 return WebKit::WebNotificationPresenter::PermissionAllowed; |
447 if (setting == CONTENT_SETTING_BLOCK) | 454 if (setting == CONTENT_SETTING_BLOCK) |
448 return WebKit::WebNotificationPresenter::PermissionDenied; | 455 return WebKit::WebNotificationPresenter::PermissionDenied; |
449 if (setting == CONTENT_SETTING_ASK) | 456 if (setting == CONTENT_SETTING_ASK) |
450 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 457 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
451 NOTREACHED() << "Invalid notifications settings value: " << setting; | 458 NOTREACHED() << "Invalid notifications settings value: " << setting; |
452 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 459 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
453 } | 460 } |
OLD | NEW |