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( |
|
Bernhard Bauer
2014/10/20 14:57:24
You could now probably fit more of the parameters
Miguel Garcia
2014/10/21 17:17:12
Done. But git cl format does not like it and I rat
| |
| 178 web_contents, | 178 web_contents, |
| 179 request_id, | 179 request_id, |
| 180 requesting_origin, | 180 requesting_origin, |
| 181 user_gesture, | 181 user_gesture, |
| 182 base::Bind(&DesktopNotificationService::OnNotificationPermissionRequested, | 182 result_callback); |
| 183 weak_factory_.GetWeakPtr(), | |
| 184 callback)); | |
| 185 } | 183 } |
| 186 | 184 |
| 187 void DesktopNotificationService::ShowDesktopNotification( | 185 void DesktopNotificationService::ShowDesktopNotification( |
| 188 const content::ShowDesktopNotificationHostMsgParams& params, | 186 const content::ShowDesktopNotificationHostMsgParams& params, |
| 189 content::RenderFrameHost* render_frame_host, | 187 content::RenderFrameHost* render_frame_host, |
| 190 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 188 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| 191 base::Closure* cancel_callback) { | 189 base::Closure* cancel_callback) { |
| 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 193 const GURL& origin = params.origin; | 191 const GURL& origin = params.origin; |
| 194 NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); | 192 NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 const GURL& embedder_origin, | 348 const GURL& embedder_origin, |
| 351 bool allowed) { | 349 bool allowed) { |
| 352 if (allowed) { | 350 if (allowed) { |
| 353 DesktopNotificationProfileUtil::GrantPermission( | 351 DesktopNotificationProfileUtil::GrantPermission( |
| 354 profile_, requesting_origin); | 352 profile_, requesting_origin); |
| 355 } else { | 353 } else { |
| 356 DesktopNotificationProfileUtil::DenyPermission(profile_, requesting_origin); | 354 DesktopNotificationProfileUtil::DenyPermission(profile_, requesting_origin); |
| 357 } | 355 } |
| 358 } | 356 } |
| 359 | 357 |
| 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( | 358 void DesktopNotificationService::FirePermissionLevelChangedEvent( |
| 370 const NotifierId& notifier_id, bool enabled) { | 359 const NotifierId& notifier_id, bool enabled) { |
| 371 #if defined(ENABLE_EXTENSIONS) | 360 #if defined(ENABLE_EXTENSIONS) |
| 372 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); | 361 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); |
| 373 extensions::api::notifications::PermissionLevel permission = | 362 extensions::api::notifications::PermissionLevel permission = |
| 374 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED | 363 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED |
| 375 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; | 364 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; |
| 376 scoped_ptr<base::ListValue> args(new base::ListValue()); | 365 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 377 args->Append(new base::StringValue( | 366 args->Append(new base::StringValue( |
| 378 extensions::api::notifications::ToString(permission))); | 367 extensions::api::notifications::ToString(permission))); |
| 379 scoped_ptr<extensions::Event> event(new extensions::Event( | 368 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 380 extensions::api::notifications::OnPermissionLevelChanged::kEventName, | 369 extensions::api::notifications::OnPermissionLevelChanged::kEventName, |
| 381 args.Pass())); | 370 args.Pass())); |
| 382 extensions::EventRouter::Get(profile_) | 371 extensions::EventRouter::Get(profile_) |
| 383 ->DispatchEventToExtension(notifier_id.id, event.Pass()); | 372 ->DispatchEventToExtension(notifier_id.id, event.Pass()); |
| 384 | 373 |
| 385 // Tell the IO thread that this extension's permission for notifications | 374 // Tell the IO thread that this extension's permission for notifications |
| 386 // has changed. | 375 // has changed. |
| 387 extensions::InfoMap* extension_info_map = | 376 extensions::InfoMap* extension_info_map = |
| 388 extensions::ExtensionSystem::Get(profile_)->info_map(); | 377 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 389 BrowserThread::PostTask( | 378 BrowserThread::PostTask( |
| 390 BrowserThread::IO, FROM_HERE, | 379 BrowserThread::IO, FROM_HERE, |
| 391 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 380 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
| 392 extension_info_map, notifier_id.id, !enabled)); | 381 extension_info_map, notifier_id.id, !enabled)); |
| 393 #endif | 382 #endif |
| 394 } | 383 } |
| OLD | NEW |