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