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" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 } | 135 } |
| 136 | 136 |
| 137 DesktopNotificationService::~DesktopNotificationService() { | 137 DesktopNotificationService::~DesktopNotificationService() { |
| 138 } | 138 } |
| 139 | 139 |
| 140 void DesktopNotificationService::RequestNotificationPermission( | 140 void DesktopNotificationService::RequestNotificationPermission( |
| 141 content::WebContents* web_contents, | 141 content::WebContents* web_contents, |
| 142 const PermissionRequestID& request_id, | 142 const PermissionRequestID& request_id, |
| 143 const GURL& requesting_origin, | 143 const GURL& requesting_origin, |
| 144 bool user_gesture, | 144 bool user_gesture, |
| 145 const NotificationPermissionCallback& callback) { | 145 const base::Callback<void(bool)>& result_callback) { |
| 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 147 | 147 |
| 148 #if defined(ENABLE_EXTENSIONS) | 148 #if defined(ENABLE_EXTENSIONS) |
| 149 extensions::InfoMap* extension_info_map = | 149 extensions::InfoMap* extension_info_map = |
| 150 extensions::ExtensionSystem::Get(profile_)->info_map(); | 150 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 151 const extensions::Extension* extension = NULL; | 151 const extensions::Extension* extension = NULL; |
| 152 if (extension_info_map) { | 152 if (extension_info_map) { |
| 153 extensions::ExtensionSet extensions; | 153 extensions::ExtensionSet extensions; |
| 154 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( | 154 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( |
| 155 requesting_origin, | 155 requesting_origin, |
| 156 request_id.render_process_id(), | 156 request_id.render_process_id(), |
| 157 extensions::APIPermission::kNotifications, | 157 extensions::APIPermission::kNotifications, |
| 158 &extensions); | 158 &extensions); |
| 159 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); | 159 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
| 160 iter != extensions.end(); ++iter) { | 160 iter != extensions.end(); ++iter) { |
| 161 if (IsNotifierEnabled(NotifierId( | 161 if (IsNotifierEnabled(NotifierId( |
| 162 NotifierId::APPLICATION, (*iter)->id()))) { | 162 NotifierId::APPLICATION, (*iter)->id()))) { |
| 163 extension = iter->get(); | 163 extension = iter->get(); |
| 164 break; | 164 break; |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 if (IsExtensionWithPermissionOrSuggestInConsole( | 168 if (IsExtensionWithPermissionOrSuggestInConsole( |
| 169 extensions::APIPermission::kNotifications, | 169 extensions::APIPermission::kNotifications, |
| 170 extension, | 170 extension, |
| 171 web_contents->GetRenderViewHost())) { | 171 web_contents->GetRenderViewHost())) { |
| 172 callback.Run(blink::WebNotificationPermissionAllowed); | 172 result_callback.Run(true); |
| 173 return; | 173 return; |
| 174 } | 174 } |
| 175 #endif | 175 #endif |
| 176 | 176 |
| 177 RequestPermission( | 177 RequestPermission(web_contents, |
| 178 web_contents, | 178 request_id, |
| 179 request_id, | 179 requesting_origin, |
| 180 requesting_origin, | 180 user_gesture, |
| 181 user_gesture, | 181 result_callback); |
|
Peter Beverloo
2014/10/24 14:37:28
Please remove the WeakPtrFactory from the DesktopN
Miguel Garcia
2014/10/24 16:05:32
Done.
| |
| 182 base::Bind(&DesktopNotificationService::OnNotificationPermissionRequested, | |
| 183 weak_factory_.GetWeakPtr(), | |
| 184 callback)); | |
| 185 } | 182 } |
| 186 | 183 |
| 187 void DesktopNotificationService::ShowDesktopNotification( | 184 void DesktopNotificationService::ShowDesktopNotification( |
| 188 const content::ShowDesktopNotificationHostMsgParams& params, | 185 const content::ShowDesktopNotificationHostMsgParams& params, |
| 189 content::RenderFrameHost* render_frame_host, | 186 content::RenderFrameHost* render_frame_host, |
| 190 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 187 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| 191 base::Closure* cancel_callback) { | 188 base::Closure* cancel_callback) { |
| 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 193 const GURL& origin = params.origin; | 190 const GURL& origin = params.origin; |
| 194 NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); | 191 NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 const GURL& embedder_origin, | 347 const GURL& embedder_origin, |
| 351 bool allowed) { | 348 bool allowed) { |
| 352 if (allowed) { | 349 if (allowed) { |
| 353 DesktopNotificationProfileUtil::GrantPermission( | 350 DesktopNotificationProfileUtil::GrantPermission( |
| 354 profile_, requesting_origin); | 351 profile_, requesting_origin); |
| 355 } else { | 352 } else { |
| 356 DesktopNotificationProfileUtil::DenyPermission(profile_, requesting_origin); | 353 DesktopNotificationProfileUtil::DenyPermission(profile_, requesting_origin); |
| 357 } | 354 } |
| 358 } | 355 } |
| 359 | 356 |
| 360 void DesktopNotificationService::OnNotificationPermissionRequested( | |
| 361 const NotificationPermissionCallback& callback, bool allowed) { | |
| 362 blink::WebNotificationPermission permission = allowed ? | |
| 363 blink::WebNotificationPermissionAllowed : | |
| 364 blink::WebNotificationPermissionDenied; | |
| 365 | |
| 366 callback.Run(permission); | |
| 367 } | |
| 368 | |
| 369 void DesktopNotificationService::FirePermissionLevelChangedEvent( | 357 void DesktopNotificationService::FirePermissionLevelChangedEvent( |
| 370 const NotifierId& notifier_id, bool enabled) { | 358 const NotifierId& notifier_id, bool enabled) { |
| 371 #if defined(ENABLE_EXTENSIONS) | 359 #if defined(ENABLE_EXTENSIONS) |
| 372 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); | 360 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); |
| 373 extensions::api::notifications::PermissionLevel permission = | 361 extensions::api::notifications::PermissionLevel permission = |
| 374 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED | 362 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED |
| 375 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; | 363 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; |
| 376 scoped_ptr<base::ListValue> args(new base::ListValue()); | 364 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 377 args->Append(new base::StringValue( | 365 args->Append(new base::StringValue( |
| 378 extensions::api::notifications::ToString(permission))); | 366 extensions::api::notifications::ToString(permission))); |
| 379 scoped_ptr<extensions::Event> event(new extensions::Event( | 367 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 380 extensions::api::notifications::OnPermissionLevelChanged::kEventName, | 368 extensions::api::notifications::OnPermissionLevelChanged::kEventName, |
| 381 args.Pass())); | 369 args.Pass())); |
| 382 extensions::EventRouter::Get(profile_) | 370 extensions::EventRouter::Get(profile_) |
| 383 ->DispatchEventToExtension(notifier_id.id, event.Pass()); | 371 ->DispatchEventToExtension(notifier_id.id, event.Pass()); |
| 384 | 372 |
| 385 // Tell the IO thread that this extension's permission for notifications | 373 // Tell the IO thread that this extension's permission for notifications |
| 386 // has changed. | 374 // has changed. |
| 387 extensions::InfoMap* extension_info_map = | 375 extensions::InfoMap* extension_info_map = |
| 388 extensions::ExtensionSystem::Get(profile_)->info_map(); | 376 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 389 BrowserThread::PostTask( | 377 BrowserThread::PostTask( |
| 390 BrowserThread::IO, FROM_HERE, | 378 BrowserThread::IO, FROM_HERE, |
| 391 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 379 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
| 392 extension_info_map, notifier_id.id, !enabled)); | 380 extension_info_map, notifier_id.id, !enabled)); |
| 393 #endif | 381 #endif |
| 394 } | 382 } |
| OLD | NEW |