| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/content_settings/content_settings_details.h" | 14 #include "chrome/browser/content_settings/content_settings_details.h" |
| 15 #include "chrome/browser/content_settings/content_settings_provider.h" | 15 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 16 #include "chrome/browser/content_settings/host_content_settings_map.h" | 16 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | |
| 18 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 17 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 19 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
| 20 #include "chrome/browser/notifications/notification_object_proxy.h" | 19 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 21 #include "chrome/browser/notifications/notification_ui_manager.h" | 20 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 22 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 21 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 23 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" | 22 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 27 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | |
| 28 #include "chrome/common/content_settings.h" | |
| 29 #include "chrome/common/content_settings_pattern.h" | |
| 30 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 32 #include "components/infobars/core/confirm_infobar_delegate.h" | |
| 33 #include "components/infobars/core/infobar.h" | |
| 34 #include "components/pref_registry/pref_registry_syncable.h" | 27 #include "components/pref_registry/pref_registry_syncable.h" |
| 35 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
| 38 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 39 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/common/show_desktop_notification_params.h" | 34 #include "content/public/common/show_desktop_notification_params.h" |
| 42 #include "grit/browser_resources.h" | 35 #include "grit/browser_resources.h" |
| 43 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 using blink::WebTextDirection; | 58 using blink::WebTextDirection; |
| 66 using content::BrowserThread; | 59 using content::BrowserThread; |
| 67 using content::RenderViewHost; | 60 using content::RenderViewHost; |
| 68 using content::WebContents; | 61 using content::WebContents; |
| 69 using message_center::NotifierId; | 62 using message_center::NotifierId; |
| 70 | 63 |
| 71 namespace { | 64 namespace { |
| 72 | 65 |
| 73 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; | 66 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; |
| 74 | 67 |
| 75 // NotificationPermissionRequest --------------------------------------- | |
| 76 | |
| 77 class NotificationPermissionRequest : public PermissionBubbleRequest { | |
| 78 public: | |
| 79 NotificationPermissionRequest( | |
| 80 DesktopNotificationService* notification_service, | |
| 81 const GURL& origin, | |
| 82 base::string16 display_name, | |
| 83 const base::Closure& callback); | |
| 84 virtual ~NotificationPermissionRequest(); | |
| 85 | |
| 86 // PermissionBubbleDelegate: | |
| 87 virtual int GetIconID() const OVERRIDE; | |
| 88 virtual base::string16 GetMessageText() const OVERRIDE; | |
| 89 virtual base::string16 GetMessageTextFragment() const OVERRIDE; | |
| 90 virtual bool HasUserGesture() const OVERRIDE; | |
| 91 virtual GURL GetRequestingHostname() const OVERRIDE; | |
| 92 virtual void PermissionGranted() OVERRIDE; | |
| 93 virtual void PermissionDenied() OVERRIDE; | |
| 94 virtual void Cancelled() OVERRIDE; | |
| 95 virtual void RequestFinished() OVERRIDE; | |
| 96 | |
| 97 private: | |
| 98 // The notification service to be used. | |
| 99 DesktopNotificationService* notification_service_; | |
| 100 | |
| 101 // The origin we are asking for permissions on. | |
| 102 GURL origin_; | |
| 103 | |
| 104 // The display name for the origin to be displayed. Will be different from | |
| 105 // origin_ for extensions. | |
| 106 base::string16 display_name_; | |
| 107 | |
| 108 // The callback information that tells us how to respond to javascript. | |
| 109 base::Closure callback_; | |
| 110 | |
| 111 // Whether the user clicked one of the buttons. | |
| 112 bool action_taken_; | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN(NotificationPermissionRequest); | |
| 115 }; | |
| 116 | |
| 117 NotificationPermissionRequest::NotificationPermissionRequest( | |
| 118 DesktopNotificationService* notification_service, | |
| 119 const GURL& origin, | |
| 120 base::string16 display_name, | |
| 121 const base::Closure& callback) | |
| 122 : notification_service_(notification_service), | |
| 123 origin_(origin), | |
| 124 display_name_(display_name), | |
| 125 callback_(callback), | |
| 126 action_taken_(false) {} | |
| 127 | |
| 128 NotificationPermissionRequest::~NotificationPermissionRequest() {} | |
| 129 | |
| 130 int NotificationPermissionRequest::GetIconID() const { | |
| 131 return IDR_INFOBAR_DESKTOP_NOTIFICATIONS; | |
| 132 } | |
| 133 | |
| 134 base::string16 NotificationPermissionRequest::GetMessageText() const { | |
| 135 return l10n_util::GetStringFUTF16(IDS_NOTIFICATION_PERMISSIONS, | |
| 136 display_name_); | |
| 137 } | |
| 138 | |
| 139 base::string16 | |
| 140 NotificationPermissionRequest::GetMessageTextFragment() const { | |
| 141 return l10n_util::GetStringUTF16(IDS_NOTIFICATION_PERMISSIONS_FRAGMENT); | |
| 142 } | |
| 143 | |
| 144 bool NotificationPermissionRequest::HasUserGesture() const { | |
| 145 // Currently notification permission requests are only issued on | |
| 146 // user gesture. | |
| 147 return true; | |
| 148 } | |
| 149 | |
| 150 GURL NotificationPermissionRequest::GetRequestingHostname() const { | |
| 151 return origin_; | |
| 152 } | |
| 153 | |
| 154 void NotificationPermissionRequest::PermissionGranted() { | |
| 155 action_taken_ = true; | |
| 156 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1); | |
| 157 notification_service_->GrantPermission(origin_); | |
| 158 } | |
| 159 | |
| 160 void NotificationPermissionRequest::PermissionDenied() { | |
| 161 action_taken_ = true; | |
| 162 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1); | |
| 163 notification_service_->DenyPermission(origin_); | |
| 164 } | |
| 165 | |
| 166 void NotificationPermissionRequest::Cancelled() { | |
| 167 } | |
| 168 | |
| 169 void NotificationPermissionRequest::RequestFinished() { | |
| 170 if (!action_taken_) | |
| 171 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1); | |
| 172 | |
| 173 callback_.Run(); | |
| 174 | |
| 175 delete this; | |
| 176 } | |
| 177 | |
| 178 | |
| 179 // NotificationPermissionInfoBarDelegate -------------------------------------- | |
| 180 | |
| 181 // The delegate for the infobar shown when an origin requests notification | |
| 182 // permissions. | |
| 183 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | |
| 184 public: | |
| 185 // Creates a notification permission infobar and delegate and adds the infobar | |
| 186 // to |infobar_service|. | |
| 187 static void Create(InfoBarService* infobar_service, | |
| 188 DesktopNotificationService* notification_service, | |
| 189 const GURL& origin, | |
| 190 const base::string16& display_name, | |
| 191 const base::Closure& callback); | |
| 192 | |
| 193 private: | |
| 194 NotificationPermissionInfoBarDelegate( | |
| 195 DesktopNotificationService* notification_service, | |
| 196 const GURL& origin, | |
| 197 const base::string16& display_name, | |
| 198 const base::Closure& callback); | |
| 199 virtual ~NotificationPermissionInfoBarDelegate(); | |
| 200 | |
| 201 // ConfirmInfoBarDelegate: | |
| 202 virtual int GetIconID() const OVERRIDE; | |
| 203 virtual Type GetInfoBarType() const OVERRIDE; | |
| 204 virtual base::string16 GetMessageText() const OVERRIDE; | |
| 205 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | |
| 206 virtual bool Accept() OVERRIDE; | |
| 207 virtual bool Cancel() OVERRIDE; | |
| 208 | |
| 209 // The origin we are asking for permissions on. | |
| 210 GURL origin_; | |
| 211 | |
| 212 // The display name for the origin to be displayed. Will be different from | |
| 213 // origin_ for extensions. | |
| 214 base::string16 display_name_; | |
| 215 | |
| 216 // The notification service to be used. | |
| 217 DesktopNotificationService* notification_service_; | |
| 218 | |
| 219 // The callback information that tells us how to respond to javascript. | |
| 220 base::Closure callback_; | |
| 221 | |
| 222 // Whether the user clicked one of the buttons. | |
| 223 bool action_taken_; | |
| 224 | |
| 225 DISALLOW_COPY_AND_ASSIGN(NotificationPermissionInfoBarDelegate); | |
| 226 }; | |
| 227 | |
| 228 // static | |
| 229 void NotificationPermissionInfoBarDelegate::Create( | |
| 230 InfoBarService* infobar_service, | |
| 231 DesktopNotificationService* notification_service, | |
| 232 const GURL& origin, | |
| 233 const base::string16& display_name, | |
| 234 const base::Closure& callback) { | |
| 235 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | |
| 236 scoped_ptr<ConfirmInfoBarDelegate>( | |
| 237 new NotificationPermissionInfoBarDelegate( | |
| 238 notification_service, origin, display_name, callback)))); | |
| 239 } | |
| 240 | |
| 241 NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate( | |
| 242 DesktopNotificationService* notification_service, | |
| 243 const GURL& origin, | |
| 244 const base::string16& display_name, | |
| 245 const base::Closure& callback) | |
| 246 : ConfirmInfoBarDelegate(), | |
| 247 origin_(origin), | |
| 248 display_name_(display_name), | |
| 249 notification_service_(notification_service), | |
| 250 callback_(callback), | |
| 251 action_taken_(false) { | |
| 252 } | |
| 253 | |
| 254 NotificationPermissionInfoBarDelegate:: | |
| 255 ~NotificationPermissionInfoBarDelegate() { | |
| 256 if (!action_taken_) | |
| 257 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1); | |
| 258 | |
| 259 callback_.Run(); | |
| 260 } | |
| 261 | |
| 262 int NotificationPermissionInfoBarDelegate::GetIconID() const { | |
| 263 return IDR_INFOBAR_DESKTOP_NOTIFICATIONS; | |
| 264 } | |
| 265 | |
| 266 infobars::InfoBarDelegate::Type | |
| 267 NotificationPermissionInfoBarDelegate::GetInfoBarType() const { | |
| 268 return PAGE_ACTION_TYPE; | |
| 269 } | |
| 270 | |
| 271 base::string16 NotificationPermissionInfoBarDelegate::GetMessageText() const { | |
| 272 return l10n_util::GetStringFUTF16(IDS_NOTIFICATION_PERMISSIONS, | |
| 273 display_name_); | |
| 274 } | |
| 275 | |
| 276 base::string16 NotificationPermissionInfoBarDelegate::GetButtonLabel( | |
| 277 InfoBarButton button) const { | |
| 278 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
| 279 IDS_NOTIFICATION_PERMISSION_YES : IDS_NOTIFICATION_PERMISSION_NO); | |
| 280 } | |
| 281 | |
| 282 bool NotificationPermissionInfoBarDelegate::Accept() { | |
| 283 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1); | |
| 284 notification_service_->GrantPermission(origin_); | |
| 285 action_taken_ = true; | |
| 286 return true; | |
| 287 } | |
| 288 | |
| 289 bool NotificationPermissionInfoBarDelegate::Cancel() { | |
| 290 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1); | |
| 291 notification_service_->DenyPermission(origin_); | |
| 292 action_taken_ = true; | |
| 293 return true; | |
| 294 } | |
| 295 | |
| 296 void CancelNotification(const std::string& id) { | 68 void CancelNotification(const std::string& id) { |
| 297 g_browser_process->notification_ui_manager()->CancelById(id); | 69 g_browser_process->notification_ui_manager()->CancelById(id); |
| 298 } | 70 } |
| 299 | 71 |
| 300 } // namespace | 72 } // namespace |
| 301 | 73 |
| 302 | 74 |
| 303 // DesktopNotificationService ------------------------------------------------- | 75 // DesktopNotificationService ------------------------------------------------- |
| 304 | 76 |
| 305 // static | 77 // static |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 Notification notification(origin_url, icon, title, message, | 152 Notification notification(origin_url, icon, title, message, |
| 381 blink::WebTextDirectionDefault, | 153 blink::WebTextDirectionDefault, |
| 382 base::string16(), replace_id, delegate); | 154 base::string16(), replace_id, delegate); |
| 383 g_browser_process->notification_ui_manager()->Add(notification, profile); | 155 g_browser_process->notification_ui_manager()->Add(notification, profile); |
| 384 return notification.delegate_id(); | 156 return notification.delegate_id(); |
| 385 } | 157 } |
| 386 | 158 |
| 387 DesktopNotificationService::DesktopNotificationService( | 159 DesktopNotificationService::DesktopNotificationService( |
| 388 Profile* profile, | 160 Profile* profile, |
| 389 NotificationUIManager* ui_manager) | 161 NotificationUIManager* ui_manager) |
| 390 : profile_(profile), | 162 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS), |
| 163 profile_(profile), |
| 391 ui_manager_(ui_manager), | 164 ui_manager_(ui_manager), |
| 392 extension_registry_observer_(this) { | 165 extension_registry_observer_(this) { |
| 393 OnStringListPrefChanged( | 166 OnStringListPrefChanged( |
| 394 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); | 167 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); |
| 395 OnStringListPrefChanged( | 168 OnStringListPrefChanged( |
| 396 prefs::kMessageCenterDisabledSystemComponentIds, | 169 prefs::kMessageCenterDisabledSystemComponentIds, |
| 397 &disabled_system_component_ids_); | 170 &disabled_system_component_ids_); |
| 398 disabled_extension_id_pref_.Init( | 171 disabled_extension_id_pref_.Init( |
| 399 prefs::kMessageCenterDisabledExtensionIds, | 172 prefs::kMessageCenterDisabledExtensionIds, |
| 400 profile_->GetPrefs(), | 173 profile_->GetPrefs(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 411 base::Unretained(this), | 184 base::Unretained(this), |
| 412 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), | 185 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), |
| 413 base::Unretained(&disabled_system_component_ids_))); | 186 base::Unretained(&disabled_system_component_ids_))); |
| 414 extension_registry_observer_.Add( | 187 extension_registry_observer_.Add( |
| 415 extensions::ExtensionRegistry::Get(profile_)); | 188 extensions::ExtensionRegistry::Get(profile_)); |
| 416 } | 189 } |
| 417 | 190 |
| 418 DesktopNotificationService::~DesktopNotificationService() { | 191 DesktopNotificationService::~DesktopNotificationService() { |
| 419 } | 192 } |
| 420 | 193 |
| 421 void DesktopNotificationService::GrantPermission(const GURL& origin) { | |
| 422 ContentSettingsPattern primary_pattern = | |
| 423 ContentSettingsPattern::FromURLNoWildcard(origin); | |
| 424 profile_->GetHostContentSettingsMap()->SetContentSetting( | |
| 425 primary_pattern, | |
| 426 ContentSettingsPattern::Wildcard(), | |
| 427 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 428 NO_RESOURCE_IDENTIFIER, | |
| 429 CONTENT_SETTING_ALLOW); | |
| 430 } | |
| 431 | |
| 432 void DesktopNotificationService::DenyPermission(const GURL& origin) { | |
| 433 ContentSettingsPattern primary_pattern = | |
| 434 ContentSettingsPattern::FromURLNoWildcard(origin); | |
| 435 profile_->GetHostContentSettingsMap()->SetContentSetting( | |
| 436 primary_pattern, | |
| 437 ContentSettingsPattern::Wildcard(), | |
| 438 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 439 NO_RESOURCE_IDENTIFIER, | |
| 440 CONTENT_SETTING_BLOCK); | |
| 441 } | |
| 442 | |
| 443 ContentSetting DesktopNotificationService::GetDefaultContentSetting( | |
| 444 std::string* provider_id) { | |
| 445 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | |
| 446 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, provider_id); | |
| 447 } | |
| 448 | |
| 449 void DesktopNotificationService::SetDefaultContentSetting( | |
| 450 ContentSetting setting) { | |
| 451 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
| 452 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | |
| 453 } | |
| 454 | |
| 455 void DesktopNotificationService::ResetToDefaultContentSetting() { | |
| 456 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
| 457 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_DEFAULT); | |
| 458 } | |
| 459 | |
| 460 void DesktopNotificationService::GetNotificationsSettings( | |
| 461 ContentSettingsForOneType* settings) { | |
| 462 profile_->GetHostContentSettingsMap()->GetSettingsForOneType( | |
| 463 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 464 NO_RESOURCE_IDENTIFIER, | |
| 465 settings); | |
| 466 } | |
| 467 | |
| 468 void DesktopNotificationService::ClearSetting( | |
| 469 const ContentSettingsPattern& pattern) { | |
| 470 profile_->GetHostContentSettingsMap()->SetContentSetting( | |
| 471 pattern, | |
| 472 ContentSettingsPattern::Wildcard(), | |
| 473 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 474 NO_RESOURCE_IDENTIFIER, | |
| 475 CONTENT_SETTING_DEFAULT); | |
| 476 } | |
| 477 | |
| 478 void DesktopNotificationService::ResetAllOrigins() { | |
| 479 profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( | |
| 480 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
| 481 } | |
| 482 | |
| 483 ContentSetting DesktopNotificationService::GetContentSetting( | |
| 484 const GURL& origin) { | |
| 485 return profile_->GetHostContentSettingsMap() | |
| 486 ->GetContentSettingAndMaybeUpdateLastUsage( | |
| 487 origin, | |
| 488 origin, | |
| 489 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 490 NO_RESOURCE_IDENTIFIER); | |
| 491 } | |
| 492 | |
| 493 void DesktopNotificationService::RequestPermission( | |
| 494 const GURL& origin, | |
| 495 content::RenderFrameHost* render_frame_host, | |
| 496 const base::Closure& callback) { | |
| 497 // If |origin| hasn't been seen before and the default content setting for | |
| 498 // notifications is "ask", show an infobar. | |
| 499 // The cache can only answer queries on the IO thread once it's initialized, | |
| 500 // so don't ask the cache. | |
| 501 WebContents* web_contents = WebContents::FromRenderFrameHost( | |
| 502 render_frame_host); | |
| 503 ContentSetting setting = GetContentSetting(origin); | |
| 504 if (setting == CONTENT_SETTING_ASK) { | |
| 505 if (PermissionBubbleManager::Enabled()) { | |
| 506 PermissionBubbleManager* bubble_manager = | |
| 507 PermissionBubbleManager::FromWebContents(web_contents); | |
| 508 if (bubble_manager) { | |
| 509 bubble_manager->AddRequest(new NotificationPermissionRequest( | |
| 510 this, | |
| 511 origin, | |
| 512 DisplayNameForOriginInProcessId( | |
| 513 origin, render_frame_host->GetProcess()->GetID()), | |
| 514 callback)); | |
| 515 } | |
| 516 return; | |
| 517 } | |
| 518 | |
| 519 // Show an info bar requesting permission. | |
| 520 InfoBarService* infobar_service = | |
| 521 InfoBarService::FromWebContents(web_contents); | |
| 522 // |infobar_service| may be NULL, e.g., if this request originated in a | |
| 523 // browser action popup, extension background page, or any HTML that runs | |
| 524 // outside of a tab. | |
| 525 if (infobar_service) { | |
| 526 NotificationPermissionInfoBarDelegate::Create( | |
| 527 infobar_service, this, origin, | |
| 528 DisplayNameForOriginInProcessId( | |
| 529 origin, render_frame_host->GetProcess()->GetID()), | |
| 530 callback); | |
| 531 return; | |
| 532 } | |
| 533 } | |
| 534 | |
| 535 // Notify renderer immediately. | |
| 536 callback.Run(); | |
| 537 } | |
| 538 | |
| 539 void DesktopNotificationService::ShowDesktopNotification( | 194 void DesktopNotificationService::ShowDesktopNotification( |
| 540 const content::ShowDesktopNotificationHostMsgParams& params, | 195 const content::ShowDesktopNotificationHostMsgParams& params, |
| 541 content::RenderFrameHost* render_frame_host, | 196 content::RenderFrameHost* render_frame_host, |
| 542 content::DesktopNotificationDelegate* delegate, | 197 content::DesktopNotificationDelegate* delegate, |
| 543 base::Closure* cancel_callback) { | 198 base::Closure* cancel_callback) { |
| 544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 545 const GURL& origin = params.origin; | 200 const GURL& origin = params.origin; |
| 546 NotificationObjectProxy* proxy = | 201 NotificationObjectProxy* proxy = |
| 547 new NotificationObjectProxy(render_frame_host, delegate); | 202 new NotificationObjectProxy(render_frame_host, delegate); |
| 548 | 203 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 578 if (IsNotifierEnabled(notifier_id)) | 233 if (IsNotifierEnabled(notifier_id)) |
| 579 return base::UTF8ToUTF16((*iter)->name()); | 234 return base::UTF8ToUTF16((*iter)->name()); |
| 580 } | 235 } |
| 581 } | 236 } |
| 582 } | 237 } |
| 583 #endif | 238 #endif |
| 584 | 239 |
| 585 return base::UTF8ToUTF16(origin.host()); | 240 return base::UTF8ToUTF16(origin.host()); |
| 586 } | 241 } |
| 587 | 242 |
| 588 void DesktopNotificationService::NotifySettingsChange() { | |
| 589 content::NotificationService::current()->Notify( | |
| 590 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | |
| 591 content::Source<DesktopNotificationService>(this), | |
| 592 content::NotificationService::NoDetails()); | |
| 593 } | |
| 594 | |
| 595 NotificationUIManager* DesktopNotificationService::GetUIManager() { | 243 NotificationUIManager* DesktopNotificationService::GetUIManager() { |
| 596 // We defer setting ui_manager_ to the global singleton until we need it | 244 // We defer setting ui_manager_ to the global singleton until we need it |
| 597 // in order to avoid UI dependent construction during startup. | 245 // in order to avoid UI dependent construction during startup. |
| 598 if (!ui_manager_) | 246 if (!ui_manager_) |
| 599 ui_manager_ = g_browser_process->notification_ui_manager(); | 247 ui_manager_ = g_browser_process->notification_ui_manager(); |
| 600 return ui_manager_; | 248 return ui_manager_; |
| 601 } | 249 } |
| 602 | 250 |
| 603 bool DesktopNotificationService::IsNotifierEnabled( | 251 bool DesktopNotificationService::IsNotifierEnabled( |
| 604 const NotifierId& notifier_id) { | 252 const NotifierId& notifier_id) { |
| 605 switch (notifier_id.type) { | 253 switch (notifier_id.type) { |
| 606 case NotifierId::APPLICATION: | 254 case NotifierId::APPLICATION: |
| 607 return disabled_extension_ids_.find(notifier_id.id) == | 255 return disabled_extension_ids_.find(notifier_id.id) == |
| 608 disabled_extension_ids_.end(); | 256 disabled_extension_ids_.end(); |
| 609 case NotifierId::WEB_PAGE: | 257 case NotifierId::WEB_PAGE: |
| 610 return GetContentSetting(notifier_id.url) == CONTENT_SETTING_ALLOW; | 258 return DesktopNotificationProfileUtil::GetContentSetting( |
| 259 profile_, notifier_id.url) == CONTENT_SETTING_ALLOW; |
| 611 case NotifierId::SYSTEM_COMPONENT: | 260 case NotifierId::SYSTEM_COMPONENT: |
| 612 #if defined(OS_CHROMEOS) | 261 #if defined(OS_CHROMEOS) |
| 613 return disabled_system_component_ids_.find(notifier_id.id) == | 262 return disabled_system_component_ids_.find(notifier_id.id) == |
| 614 disabled_system_component_ids_.end(); | 263 disabled_system_component_ids_.end(); |
| 615 #else | 264 #else |
| 616 // We do not disable system component notifications. | 265 // We do not disable system component notifications. |
| 617 return true; | 266 return true; |
| 618 #endif | 267 #endif |
| 619 } | 268 } |
| 620 | 269 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 // Tell the IO thread that this extension's permission for notifications | 376 // Tell the IO thread that this extension's permission for notifications |
| 728 // has changed. | 377 // has changed. |
| 729 extensions::InfoMap* extension_info_map = | 378 extensions::InfoMap* extension_info_map = |
| 730 extensions::ExtensionSystem::Get(profile_)->info_map(); | 379 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 731 BrowserThread::PostTask( | 380 BrowserThread::PostTask( |
| 732 BrowserThread::IO, FROM_HERE, | 381 BrowserThread::IO, FROM_HERE, |
| 733 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 382 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
| 734 extension_info_map, notifier_id.id, !enabled)); | 383 extension_info_map, notifier_id.id, !enabled)); |
| 735 #endif | 384 #endif |
| 736 } | 385 } |
| OLD | NEW |