summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/desktop_notification_handler.cc87
-rw-r--r--chrome/browser/desktop_notification_handler.h43
-rw-r--r--chrome/browser/extensions/extension_host.cc9
-rw-r--r--chrome/browser/extensions/extension_host.h4
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc41
-rw-r--r--chrome/browser/renderer_host/render_view_host.h5
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc4
-rw-r--r--chrome/browser/tab_contents/tab_contents.h5
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/common/render_messages_internal.h8
-rw-r--r--chrome/common/render_messages_params.cc6
-rw-r--r--chrome/common/render_messages_params.h3
-rw-r--r--chrome/renderer/notification_provider.cc7
13 files changed, 172 insertions, 52 deletions
diff --git a/chrome/browser/desktop_notification_handler.cc b/chrome/browser/desktop_notification_handler.cc
new file mode 100644
index 0000000..b5973ef
--- /dev/null
+++ b/chrome/browser/desktop_notification_handler.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/desktop_notification_handler.h"
+
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/render_messages.h"
+#include "chrome/common/render_messages_params.h"
+
+DesktopNotificationHandler::DesktopNotificationHandler(
+ TabContents* tab, RenderProcessHost* process)
+ : tab_(tab),
+ process_(process) {
+}
+
+bool DesktopNotificationHandler::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+
+ IPC_BEGIN_MESSAGE_MAP(DesktopNotificationHandler, message)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDesktopNotification,
+ OnShowDesktopNotification)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CancelDesktopNotification,
+ OnCancelDesktopNotification)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_RequestNotificationPermission,
+ OnRequestNotificationPermission)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void DesktopNotificationHandler::OnShowDesktopNotification(
+ const ViewHostMsg_ShowNotification_Params& params) {
+ RenderProcessHost* process = GetRenderProcessHost();
+ DesktopNotificationService* service =
+ process->profile()->GetDesktopNotificationService();
+
+ service->ShowDesktopNotification(
+ params,
+ process->id(),
+ params.routing_id,
+ DesktopNotificationService::PageNotification);
+}
+
+void DesktopNotificationHandler::OnCancelDesktopNotification(
+ int routing_id, int notification_id) {
+ RenderProcessHost* process = GetRenderProcessHost();
+ DesktopNotificationService* service =
+ process_->profile()->GetDesktopNotificationService();
+
+ service->CancelDesktopNotification(
+ process_->id(),
+ routing_id,
+ notification_id);
+}
+
+void DesktopNotificationHandler::OnRequestNotificationPermission(
+ int routing_id, const GURL& source_origin, int callback_context) {
+ RenderProcessHost* process = GetRenderProcessHost();
+ Browser* browser = BrowserList::GetLastActive();
+ // We may not have a BrowserList if the chrome browser process is launched as
+ // a ChromeFrame process in which case we attempt to use the TabContents
+ // provided by the RenderViewHostDelegate.
+ TabContents* tab = browser ? browser->GetSelectedTabContents() : tab_;
+ if (!tab)
+ return;
+
+ DesktopNotificationService* service =
+ tab->profile()->GetDesktopNotificationService();
+ service->RequestPermission(
+ source_origin,
+ process->id(),
+ routing_id,
+ callback_context,
+ tab);
+}
+
+RenderProcessHost* DesktopNotificationHandler::GetRenderProcessHost() {
+ return tab_ ? tab_->GetRenderProcessHost() : process_;
+}
+
diff --git a/chrome/browser/desktop_notification_handler.h b/chrome/browser/desktop_notification_handler.h
new file mode 100644
index 0000000..7fce602
--- /dev/null
+++ b/chrome/browser/desktop_notification_handler.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DESKTOP_NOTIFICATION_HANDLER_H_
+#define CHROME_BROWSER_DESKTOP_NOTIFICATION_HANDLER_H_
+#pragma once
+
+#include "chrome/browser/tab_contents/web_navigation_observer.h"
+
+struct ViewHostMsg_ShowNotification_Params;
+class RenderProcessHost;
+
+// Per-tab Desktop notification handler. Handles desktop notification IPCs
+// coming in from the renderer.
+class DesktopNotificationHandler : public WebNavigationObserver {
+ public:
+ explicit DesktopNotificationHandler(TabContents* tab_contents,
+ RenderProcessHost* process);
+ virtual ~DesktopNotificationHandler() {}
+
+ // WebNavigationObserver implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message);
+
+ RenderProcessHost* GetRenderProcessHost();
+
+ private:
+ // IPC handlers.
+ void OnShowDesktopNotification(
+ const ViewHostMsg_ShowNotification_Params& params);
+ void OnCancelDesktopNotification(int routing_id, int notification_id);
+ void OnRequestNotificationPermission(int routing_id, const GURL& origin,
+ int callback_id);
+
+ private:
+ TabContents* tab_;
+ RenderProcessHost* process_;
+
+ DISALLOW_COPY_AND_ASSIGN(DesktopNotificationHandler);
+};
+
+#endif // CHROME_BROWSER_DESKTOP_NOTIFICATION_HANDLER_H_
+
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 3c707b8..dc26c1f 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/browser_window.h"
#include "chrome/browser/browsing_instance.h"
#include "chrome/browser/debugger/devtools_manager.h"
+#include "chrome/browser/desktop_notification_handler.h"
#include "chrome/browser/dom_ui/dom_ui_factory.h"
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/extensions/extension_tabs_module.h"
@@ -146,6 +147,9 @@ ExtensionHost::ExtensionHost(const Extension* extension,
// be the same extension that this points to.
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
Source<Profile>(profile_));
+
+ desktop_notification_handler_.reset(
+ new DesktopNotificationHandler(NULL, render_process_host()));
}
ExtensionHost::~ExtensionHost() {
@@ -763,6 +767,11 @@ bool ExtensionHost::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
+
+ if (!handled) {
+ // Pass desktop notification IPCs to the DesktopNotificationHandler.
+ handled = desktop_notification_handler_->OnMessageReceived(message);
+ }
return handled;
}
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index c9422ce..3ace800 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -31,6 +31,7 @@ class RenderProcessHost;
class RenderWidgetHostView;
class TabContents;
struct WebPreferences;
+class DesktopNotificationHandler;
// This class is the browser component of an extension component's RenderView.
// It handles setting up the renderer process, if needed, with special
@@ -285,6 +286,9 @@ class ExtensionHost : public RenderViewHostDelegate,
// FileSelectHelper, lazily created.
scoped_ptr<FileSelectHelper> file_select_helper_;
+ // Handles desktop notification IPCs.
+ scoped_ptr<DesktopNotificationHandler> desktop_notification_handler_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionHost);
};
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index e6178d8..7378720 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -15,7 +15,6 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
-#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/child_process_security_policy.h"
@@ -26,7 +25,6 @@
#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/net/predictor_api.h"
-#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/print_preview_tab_controller.h"
@@ -788,12 +786,6 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_FORWARD(ViewHostMsg_JSOutOfMemory, delegate_,
RenderViewHostDelegate::OnJSOutOfMemory)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDesktopNotification,
- OnShowDesktopNotification)
- IPC_MESSAGE_HANDLER(ViewHostMsg_CancelDesktopNotification,
- OnCancelDesktopNotification)
- IPC_MESSAGE_HANDLER(ViewHostMsg_RequestNotificationPermission,
- OnRequestNotificationPermission)
IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRequest, OnExtensionRequest)
IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged)
IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionPostMessage,
@@ -1479,39 +1471,6 @@ void RenderViewHost::ForwardMessageFromExternalHost(const std::string& message,
target));
}
-void RenderViewHost::OnShowDesktopNotification(
- const ViewHostMsg_ShowNotification_Params& params) {
- DesktopNotificationService* service =
- process()->profile()->GetDesktopNotificationService();
-
- service->ShowDesktopNotification(
- params, process()->id(), routing_id(),
- DesktopNotificationService::PageNotification);
-}
-
-void RenderViewHost::OnCancelDesktopNotification(int notification_id) {
- DesktopNotificationService* service=
- process()->profile()->GetDesktopNotificationService();
- service->CancelDesktopNotification(
- process()->id(), routing_id(), notification_id);
-}
-
-void RenderViewHost::OnRequestNotificationPermission(
- const GURL& source_origin, int callback_context) {
- Browser* browser = BrowserList::GetLastActive();
- // We may not have a BrowserList if the chrome browser process is launched as
- // a ChromeFrame process in which case we attempt to use the TabContents
- // provided by the RenderViewHostDelegate.
- TabContents* tab = browser ? browser->GetSelectedTabContents() :
- (delegate_ ? delegate_->GetAsTabContents() : NULL);
- if (tab) {
- DesktopNotificationService* service =
- process()->profile()->GetDesktopNotificationService();
- service->RequestPermission(
- source_origin, process()->id(), routing_id(), callback_context, tab);
- }
-}
-
void RenderViewHost::OnExtensionRequest(
const ViewHostMsg_DomMessage_Params& params) {
if (!ChildProcessSecurityPolicy::GetInstance()->
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index bb49437..df00cb1 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -46,7 +46,6 @@ struct ViewHostMsg_DidPrintPage_Params;
struct ViewHostMsg_DomMessage_Params;
struct ViewHostMsg_PageHasOSDD_Type;
struct ViewHostMsg_RunFileChooser_Params;
-struct ViewHostMsg_ShowNotification_Params;
struct ViewHostMsg_ShowPopup_Params;
struct ViewMsg_Navigate_Params;
struct WebApplicationInfo;
@@ -616,10 +615,6 @@ class RenderViewHost : public RenderWidgetHost {
void OnDevToolsRuntimePropertyChanged(const std::string& name,
const std::string& value);
void OnMsgShouldCloseACK(bool proceed);
- void OnShowDesktopNotification(
- const ViewHostMsg_ShowNotification_Params& params);
- void OnCancelDesktopNotification(int notification_id);
- void OnRequestNotificationPermission(const GURL& origin, int callback_id);
void OnExtensionRequest(const ViewHostMsg_DomMessage_Params& params);
void OnExtensionPostMessage(int port_id, const std::string& message);
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 2554daa..a722215 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -25,6 +25,7 @@
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/defaults.h"
+#include "chrome/browser/desktop_notification_handler.h"
#include "chrome/browser/dom_operation_notification_details.h"
#include "chrome/browser/dom_ui/dom_ui.h"
#include "chrome/browser/download/download_item_model.h"
@@ -595,6 +596,9 @@ TabContents::TabContents(Profile* profile,
AddNavigationObserver(prerender_plt_recorder_.get());
AddNavigationObserver(&fav_icon_helper_);
AddNavigationObserver(printing_.get());
+ desktop_notification_handler_.reset(
+ new DesktopNotificationHandler(this, GetRenderProcessHost()));
+ AddNavigationObserver(desktop_notification_handler_.get());
}
TabContents::~TabContents() {
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index b0af381..880a390 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -84,6 +84,7 @@ struct ViewHostMsg_DomMessage_Params;
struct ViewHostMsg_FrameNavigate_Params;
class WebNavigationObserver;
struct WebPreferences;
+class DesktopNotificationHandler;
// Describes what goes in the main content area of a tab. TabContents is
// the only type of TabContents, and these should be merged together.
@@ -1149,6 +1150,10 @@ class TabContents : public PageNavigator,
// RenderViewHost::ContentSettingsDelegate.
scoped_ptr<TabSpecificContentSettings> content_settings_delegate_;
+ // Handles desktop notification IPCs.
+ scoped_ptr<DesktopNotificationHandler> desktop_notification_handler_;
+
+
// Data for loading state ----------------------------------------------------
// Indicates whether we're currently loading a resource.
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 6c76195..226ab60 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -826,6 +826,8 @@
'browser/default_encoding_combo_model.h',
'browser/defaults.cc',
'browser/defaults.h',
+ 'browser/desktop_notification_handler.cc',
+ 'browser/desktop_notification_handler.h',
'browser/device_orientation/accelerometer_mac.cc',
'browser/device_orientation/accelerometer_mac.h',
'browser/device_orientation/data_fetcher.h',
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 55e467a..0cc2db5 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -2180,9 +2180,11 @@ IPC_MESSAGE_CONTROL1(ViewHostMsg_DocumentDetached,
// a desktop notification.
IPC_MESSAGE_ROUTED1(ViewHostMsg_ShowDesktopNotification,
ViewHostMsg_ShowNotification_Params)
-IPC_MESSAGE_ROUTED1(ViewHostMsg_CancelDesktopNotification,
- int /* notification_id */ )
-IPC_MESSAGE_ROUTED2(ViewHostMsg_RequestNotificationPermission,
+IPC_MESSAGE_ROUTED2(ViewHostMsg_CancelDesktopNotification,
+ int /* routing_id */,
+ int /* notification_id */)
+IPC_MESSAGE_ROUTED3(ViewHostMsg_RequestNotificationPermission,
+ int /* routing_id */,
GURL /* origin */,
int /* callback_context */)
IPC_SYNC_MESSAGE_ROUTED1_1(ViewHostMsg_CheckNotificationPermission,
diff --git a/chrome/common/render_messages_params.cc b/chrome/common/render_messages_params.cc
index 59a17bd..409776b 100644
--- a/chrome/common/render_messages_params.cc
+++ b/chrome/common/render_messages_params.cc
@@ -1311,6 +1311,7 @@ void ParamTraits<ViewHostMsg_ShowNotification_Params>::Write(
WriteParam(m, p.direction);
WriteParam(m, p.replace_id);
WriteParam(m, p.notification_id);
+ WriteParam(m, p.routing_id);
}
bool ParamTraits<ViewHostMsg_ShowNotification_Params>::Read(
@@ -1326,7 +1327,8 @@ bool ParamTraits<ViewHostMsg_ShowNotification_Params>::Read(
ReadParam(m, iter, &p->body) &&
ReadParam(m, iter, &p->direction) &&
ReadParam(m, iter, &p->replace_id) &&
- ReadParam(m, iter, &p->notification_id);
+ ReadParam(m, iter, &p->notification_id) &&
+ ReadParam(m, iter, &p->routing_id);
}
void ParamTraits<ViewHostMsg_ShowNotification_Params>::Log(
@@ -1350,6 +1352,8 @@ void ParamTraits<ViewHostMsg_ShowNotification_Params>::Log(
LogParam(p.replace_id, l);
l->append(",");
LogParam(p.notification_id, l);
+ l->append(",");
+ LogParam(p.routing_id, l);
l->append(")");
}
diff --git a/chrome/common/render_messages_params.h b/chrome/common/render_messages_params.h
index ce4b18c..88473c6c 100644
--- a/chrome/common/render_messages_params.h
+++ b/chrome/common/render_messages_params.h
@@ -742,6 +742,9 @@ struct ViewHostMsg_ShowNotification_Params {
// Notification ID for sending events back for this notification.
int notification_id;
+
+ // The routing id of the message.
+ int routing_id;
};
// Creates a new view via a control message since the view doesn't yet exist.
diff --git a/chrome/renderer/notification_provider.cc b/chrome/renderer/notification_provider.cc
index 8bdf244..170db3a 100644
--- a/chrome/renderer/notification_provider.cc
+++ b/chrome/renderer/notification_provider.cc
@@ -46,7 +46,8 @@ void NotificationProvider::cancel(const WebNotification& notification) {
bool id_found = manager_.GetId(notification, id);
// Won't be found if the notification has already been closed by the user.
if (id_found)
- Send(new ViewHostMsg_CancelDesktopNotification(routing_id(), id));
+ Send(new ViewHostMsg_CancelDesktopNotification(routing_id(), routing_id(),
+ id));
}
void NotificationProvider::objectDestroyed(
@@ -78,6 +79,7 @@ void NotificationProvider::requestPermission(
int id = manager_.RegisterPermissionRequest(callback);
Send(new ViewHostMsg_RequestNotificationPermission(routing_id(),
+ routing_id(),
GURL(origin.toString()),
id));
}
@@ -119,6 +121,7 @@ bool NotificationProvider::ShowHTML(const WebNotification& notification,
params.contents_url = notification.url();
params.notification_id = id;
params.replace_id = notification.replaceId();
+ params.routing_id = routing_id();
return Send(new ViewHostMsg_ShowDesktopNotification(routing_id(), params));
}
@@ -135,7 +138,7 @@ bool NotificationProvider::ShowText(const WebNotification& notification,
params.direction = notification.direction();
params.notification_id = id;
params.replace_id = notification.replaceId();
-
+ params.routing_id = routing_id();
return Send(new ViewHostMsg_ShowDesktopNotification(routing_id(), params));
}