Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2317)

Unified Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 578883003: Remove the strict dependency on WebContents for Web Notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/desktop_notification_service.cc
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index c53742b75fb2f626fc4704d57af2862bf9b577f7..39fbb586de0a662b9e81ffc45cc09c0f7bd55bb6 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -30,7 +30,6 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/show_desktop_notification_params.h"
#include "ui/base/webui/web_ui_util.h"
@@ -47,11 +46,11 @@
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
+#include "extensions/common/permissions/permissions_data.h"
#endif
using blink::WebTextDirection;
using content::BrowserThread;
-using content::RenderViewHost;
using content::WebContents;
using message_center::NotifierId;
@@ -147,49 +146,46 @@ void DesktopNotificationService::RequestNotificationPermission(
void DesktopNotificationService::ShowDesktopNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
- content::RenderFrameHost* render_frame_host,
scoped_ptr<content::DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- const GURL& origin = params.origin;
- NotificationObjectProxy* proxy =
- new NotificationObjectProxy(render_frame_host, delegate.Pass());
- base::string16 display_source = DisplayNameForOriginInProcessId(
- origin, render_frame_host->GetProcess()->GetID());
- Notification notification(origin, params.icon_url, params.title,
+ NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass());
+
+ base::string16 display_source = DisplayNameForOrigin(params.origin);
+ Notification notification(params.origin, params.icon_url, params.title,
params.body, params.direction, display_source, params.replace_id,
proxy);
- // The webkit notification doesn't timeout.
+ // Web Notifications never timeout.
notification.set_never_timeout(true);
g_browser_process->notification_ui_manager()->Add(notification, profile_);
- if (cancel_callback)
- *cancel_callback = base::Bind(&CancelNotification, proxy->id());
- DesktopNotificationProfileUtil::UsePermission(profile_, origin);
+ DCHECK(cancel_callback);
+ *cancel_callback = base::Bind(&CancelNotification, proxy->id());
+
+ DesktopNotificationProfileUtil::UsePermission(profile_, params.origin);
}
-base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId(
- const GURL& origin, int process_id) {
+base::string16 DesktopNotificationService::DisplayNameForOrigin(
Peter Beverloo 2014/09/17 16:24:08 This mimics the behavior of GetExtensionsWithAPIPe
dewittj 2014/09/17 16:58:48 +dcheng who wrote GetExtensionsWithAPIPermissionFo
dcheng 2014/10/03 18:40:06 It looks like I did this since it was suggested by
not at google - send to devlin 2014/10/17 16:12:27 Extension pages can end up being hosted in other p
+ const GURL& origin) {
#if defined(ENABLE_EXTENSIONS)
// If the source is an extension, lookup the display name.
if (origin.SchemeIs(extensions::kExtensionScheme)) {
extensions::InfoMap* extension_info_map =
extensions::ExtensionSystem::Get(profile_)->info_map();
if (extension_info_map) {
- extensions::ExtensionSet extensions;
- extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
- origin,
- process_id,
- extensions::APIPermission::kNotifications,
- &extensions);
- for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
- iter != extensions.end(); ++iter) {
- NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
+ const std::string& extension_id = origin.host();
+ const extensions::Extension* extension =
+ extension_info_map->extensions().GetByID(extension_id);
+
+ if (extension &&
+ extension->permissions_data()->HasAPIPermission(
+ extensions::APIPermission::kNotifications)) {
+ NotifierId notifier_id(NotifierId::APPLICATION, extension_id);
if (IsNotifierEnabled(notifier_id))
- return base::UTF8ToUTF16((*iter)->name());
+ return base::UTF8ToUTF16(extension->name());
}
}
}

Powered by Google App Engine
This is Rietveld 408576698