| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 base::Bind(&ProfileLoadedCallback, operation, origin, | 157 base::Bind(&ProfileLoadedCallback, operation, origin, |
| 158 persistent_notification_id, action_index)); | 158 persistent_notification_id, action_index)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 161 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
| 162 BrowserContext* browser_context, | 162 BrowserContext* browser_context, |
| 163 int64_t persistent_notification_id, | 163 int64_t persistent_notification_id, |
| 164 const GURL& origin, | 164 const GURL& origin, |
| 165 int action_index) { | 165 int action_index) { |
| 166 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 166 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 167 blink::WebNotificationPermission permission = | 167 blink::mojom::PermissionStatus permission_status = |
| 168 CheckPermissionOnUIThread(browser_context, origin, | 168 CheckPermissionOnUIThread(browser_context, origin, |
| 169 kInvalidRenderProcessId); | 169 kInvalidRenderProcessId); |
| 170 | 170 |
| 171 // TODO(peter): Change this to a CHECK() when Issue 555572 is resolved. | 171 // TODO(peter): Change this to a CHECK() when Issue 555572 is resolved. |
| 172 // Also change this method to be const again. | 172 // Also change this method to be const again. |
| 173 if (permission != blink::WebNotificationPermissionAllowed) { | 173 if (permission_status != blink::mojom::PermissionStatus::GRANTED) { |
| 174 content::RecordAction(base::UserMetricsAction( | 174 content::RecordAction(base::UserMetricsAction( |
| 175 "Notifications.Persistent.ClickedWithoutPermission")); | 175 "Notifications.Persistent.ClickedWithoutPermission")); |
| 176 return; | 176 return; |
| 177 } | 177 } |
| 178 | 178 |
| 179 if (action_index == -1) { | 179 if (action_index == -1) { |
| 180 content::RecordAction(base::UserMetricsAction( | 180 content::RecordAction(base::UserMetricsAction( |
| 181 "Notifications.Persistent.Clicked")); | 181 "Notifications.Persistent.Clicked")); |
| 182 } else { | 182 } else { |
| 183 content::RecordAction(base::UserMetricsAction( | 183 content::RecordAction(base::UserMetricsAction( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 207 } else { | 207 } else { |
| 208 content::RecordAction(base::UserMetricsAction( | 208 content::RecordAction(base::UserMetricsAction( |
| 209 "Notifications.Persistent.ClosedProgrammatically")); | 209 "Notifications.Persistent.ClosedProgrammatically")); |
| 210 } | 210 } |
| 211 content::NotificationEventDispatcher::GetInstance() | 211 content::NotificationEventDispatcher::GetInstance() |
| 212 ->DispatchNotificationCloseEvent( | 212 ->DispatchNotificationCloseEvent( |
| 213 browser_context, persistent_notification_id, origin, by_user, | 213 browser_context, persistent_notification_id, origin, by_user, |
| 214 base::Bind(&OnCloseEventDispatchComplete)); | 214 base::Bind(&OnCloseEventDispatchComplete)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 blink::WebNotificationPermission | 217 blink::mojom::PermissionStatus |
| 218 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( | 218 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( |
| 219 BrowserContext* browser_context, | 219 BrowserContext* browser_context, |
| 220 const GURL& origin, | 220 const GURL& origin, |
| 221 int render_process_id) { | 221 int render_process_id) { |
| 222 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 222 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 223 | 223 |
| 224 Profile* profile = Profile::FromBrowserContext(browser_context); | 224 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 225 DCHECK(profile); | 225 DCHECK(profile); |
| 226 | 226 |
| 227 #if defined(ENABLE_EXTENSIONS) | 227 #if defined(ENABLE_EXTENSIONS) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 241 if (extension && | 241 if (extension && |
| 242 extension->permissions_data()->HasAPIPermission( | 242 extension->permissions_data()->HasAPIPermission( |
| 243 extensions::APIPermission::kNotifications) && | 243 extensions::APIPermission::kNotifications) && |
| 244 process_map->Contains(extension->id(), render_process_id)) { | 244 process_map->Contains(extension->id(), render_process_id)) { |
| 245 NotifierStateTracker* notifier_state_tracker = | 245 NotifierStateTracker* notifier_state_tracker = |
| 246 NotifierStateTrackerFactory::GetForProfile(profile); | 246 NotifierStateTrackerFactory::GetForProfile(profile); |
| 247 DCHECK(notifier_state_tracker); | 247 DCHECK(notifier_state_tracker); |
| 248 | 248 |
| 249 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); | 249 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
| 250 if (notifier_state_tracker->IsNotifierEnabled(notifier_id)) | 250 if (notifier_state_tracker->IsNotifierEnabled(notifier_id)) |
| 251 return blink::WebNotificationPermissionAllowed; | 251 return blink::mojom::PermissionStatus::GRANTED; |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 #endif | 254 #endif |
| 255 | 255 |
| 256 ContentSetting setting = | 256 ContentSetting setting = |
| 257 DesktopNotificationProfileUtil::GetContentSetting(profile, origin); | 257 DesktopNotificationProfileUtil::GetContentSetting(profile, origin); |
| 258 | 258 |
| 259 if (setting == CONTENT_SETTING_ALLOW) | 259 if (setting == CONTENT_SETTING_ALLOW) |
| 260 return blink::WebNotificationPermissionAllowed; | 260 return blink::mojom::PermissionStatus::GRANTED; |
| 261 if (setting == CONTENT_SETTING_BLOCK) | 261 if (setting == CONTENT_SETTING_BLOCK) |
| 262 return blink::WebNotificationPermissionDenied; | 262 return blink::mojom::PermissionStatus::DENIED; |
| 263 | 263 |
| 264 return blink::WebNotificationPermissionDefault; | 264 return blink::mojom::PermissionStatus::ASK; |
| 265 } | 265 } |
| 266 | 266 |
| 267 blink::WebNotificationPermission | 267 blink::mojom::PermissionStatus |
| 268 PlatformNotificationServiceImpl::CheckPermissionOnIOThread( | 268 PlatformNotificationServiceImpl::CheckPermissionOnIOThread( |
| 269 content::ResourceContext* resource_context, | 269 content::ResourceContext* resource_context, |
| 270 const GURL& origin, | 270 const GURL& origin, |
| 271 int render_process_id) { | 271 int render_process_id) { |
| 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 272 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 273 | 273 |
| 274 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 274 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 275 #if defined(ENABLE_EXTENSIONS) | 275 #if defined(ENABLE_EXTENSIONS) |
| 276 // Extensions support an API permission named "notification". This will grant | 276 // Extensions support an API permission named "notification". This will grant |
| 277 // not only grant permission for using the Chrome App extension API, but also | 277 // not only grant permission for using the Chrome App extension API, but also |
| 278 // for the Web Notification API. | 278 // for the Web Notification API. |
| 279 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 279 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
| 280 extensions::InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); | 280 extensions::InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); |
| 281 const extensions::ProcessMap& process_map = | 281 const extensions::ProcessMap& process_map = |
| 282 extension_info_map->process_map(); | 282 extension_info_map->process_map(); |
| 283 | 283 |
| 284 const extensions::Extension* extension = | 284 const extensions::Extension* extension = |
| 285 extension_info_map->extensions().GetByID(origin.host()); | 285 extension_info_map->extensions().GetByID(origin.host()); |
| 286 | 286 |
| 287 if (extension && | 287 if (extension && |
| 288 extension->permissions_data()->HasAPIPermission( | 288 extension->permissions_data()->HasAPIPermission( |
| 289 extensions::APIPermission::kNotifications) && | 289 extensions::APIPermission::kNotifications) && |
| 290 process_map.Contains(extension->id(), render_process_id)) { | 290 process_map.Contains(extension->id(), render_process_id)) { |
| 291 if (!extension_info_map->AreNotificationsDisabled(extension->id())) | 291 if (!extension_info_map->AreNotificationsDisabled(extension->id())) |
| 292 return blink::WebNotificationPermissionAllowed; | 292 return blink::mojom::PermissionStatus::GRANTED; |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 #endif | 295 #endif |
| 296 | 296 |
| 297 // No enabled extensions exist, so check the normal host content settings. | 297 // No enabled extensions exist, so check the normal host content settings. |
| 298 HostContentSettingsMap* host_content_settings_map = | 298 HostContentSettingsMap* host_content_settings_map = |
| 299 io_data->GetHostContentSettingsMap(); | 299 io_data->GetHostContentSettingsMap(); |
| 300 ContentSetting setting = host_content_settings_map->GetContentSetting( | 300 ContentSetting setting = host_content_settings_map->GetContentSetting( |
| 301 origin, | 301 origin, |
| 302 origin, | 302 origin, |
| 303 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 303 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 304 content_settings::ResourceIdentifier()); | 304 content_settings::ResourceIdentifier()); |
| 305 | 305 |
| 306 if (setting == CONTENT_SETTING_ALLOW) | 306 if (setting == CONTENT_SETTING_ALLOW) |
| 307 return blink::WebNotificationPermissionAllowed; | 307 return blink::mojom::PermissionStatus::GRANTED; |
| 308 if (setting == CONTENT_SETTING_BLOCK) | 308 if (setting == CONTENT_SETTING_BLOCK) |
| 309 return blink::WebNotificationPermissionDenied; | 309 return blink::mojom::PermissionStatus::DENIED; |
| 310 | 310 |
| 311 return blink::WebNotificationPermissionDefault; | 311 return blink::mojom::PermissionStatus::ASK; |
| 312 } | 312 } |
| 313 | 313 |
| 314 void PlatformNotificationServiceImpl::DisplayNotification( | 314 void PlatformNotificationServiceImpl::DisplayNotification( |
| 315 BrowserContext* browser_context, | 315 BrowserContext* browser_context, |
| 316 const GURL& origin, | 316 const GURL& origin, |
| 317 const content::PlatformNotificationData& notification_data, | 317 const content::PlatformNotificationData& notification_data, |
| 318 const content::NotificationResources& notification_resources, | 318 const content::NotificationResources& notification_resources, |
| 319 std::unique_ptr<content::DesktopNotificationDelegate> delegate, | 319 std::unique_ptr<content::DesktopNotificationDelegate> delegate, |
| 320 base::Closure* cancel_callback) { | 320 base::Closure* cancel_callback) { |
| 321 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 321 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 533 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 534 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 534 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 535 DCHECK(extension); | 535 DCHECK(extension); |
| 536 | 536 |
| 537 return base::UTF8ToUTF16(extension->name()); | 537 return base::UTF8ToUTF16(extension->name()); |
| 538 } | 538 } |
| 539 #endif | 539 #endif |
| 540 | 540 |
| 541 return base::string16(); | 541 return base::string16(); |
| 542 } | 542 } |
| OLD | NEW |