diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/renderer/notification_provider.cc | 62 | ||||
-rw-r--r-- | chrome/renderer/notification_provider.h | 27 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 2 |
4 files changed, 31 insertions, 68 deletions
diff --git a/chrome/renderer/notification_provider.cc b/chrome/renderer/notification_provider.cc index 505349d..0c1b789 100644 --- a/chrome/renderer/notification_provider.cc +++ b/chrome/renderer/notification_provider.cc @@ -60,6 +60,19 @@ void NotificationProvider::requestPermission( GURL(origin), id)); } +bool NotificationProvider::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(NotificationProvider, message) + IPC_MESSAGE_HANDLER(ViewMsg_PostDisplayToNotificationObject, OnDisplay); + IPC_MESSAGE_HANDLER(ViewMsg_PostErrorToNotificationObject, OnError); + IPC_MESSAGE_HANDLER(ViewMsg_PostCloseToNotificationObject, OnClose); + IPC_MESSAGE_HANDLER(ViewMsg_PermissionRequestDone, + OnPermissionRequestComplete); + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + bool NotificationProvider::ShowHTML(const WebNotification& notification, int id) { DCHECK(notification.isHTML()); @@ -78,30 +91,6 @@ bool NotificationProvider::ShowText(const WebNotification& notification, } void NotificationProvider::OnDisplay(int id) { - RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(this, &NotificationProvider::HandleOnDisplay, id)); -} - -void NotificationProvider::OnError(int id, const WebString& message) { - RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(this, &NotificationProvider::HandleOnError, - id, message)); -} - -void NotificationProvider::OnClose(int id, bool by_user) { - RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(this, &NotificationProvider::HandleOnClose, - id, by_user)); -} - -void NotificationProvider::OnPermissionRequestComplete(int id) { - RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(this, - &NotificationProvider::HandleOnPermissionRequestComplete, id)); -} - -void NotificationProvider::HandleOnDisplay(int id) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); WebNotification notification; bool found = manager_.GetNotification(id, ¬ification); // |found| may be false if the WebNotification went out of scope in @@ -110,8 +99,7 @@ void NotificationProvider::HandleOnDisplay(int id) { notification.dispatchDisplayEvent(); } -void NotificationProvider::HandleOnError(int id, const WebString& message) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); +void NotificationProvider::OnError(int id, const WebString& message) { WebNotification notification; bool found = manager_.GetNotification(id, ¬ification); // |found| may be false if the WebNotification went out of scope in @@ -120,8 +108,7 @@ void NotificationProvider::HandleOnError(int id, const WebString& message) { notification.dispatchErrorEvent(message); } -void NotificationProvider::HandleOnClose(int id, bool by_user) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); +void NotificationProvider::OnClose(int id, bool by_user) { WebNotification notification; bool found = manager_.GetNotification(id, ¬ification); // |found| may be false if the WebNotification went out of scope in @@ -131,30 +118,13 @@ void NotificationProvider::HandleOnClose(int id, bool by_user) { manager_.UnregisterNotification(id); } -void NotificationProvider::HandleOnPermissionRequestComplete(int id) { - DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI); +void NotificationProvider::OnPermissionRequestComplete(int id) { WebNotificationPermissionCallback* callback = manager_.GetCallback(id); DCHECK(callback); callback->permissionRequestComplete(); manager_.OnPermissionRequestComplete(id); } -bool NotificationProvider::OnMessageReceived(const IPC::Message& message) { - if (message.routing_id() != view_->routing_id()) - return false; - - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(NotificationProvider, message) - IPC_MESSAGE_HANDLER(ViewMsg_PostDisplayToNotificationObject, OnDisplay); - IPC_MESSAGE_HANDLER(ViewMsg_PostErrorToNotificationObject, OnError); - IPC_MESSAGE_HANDLER(ViewMsg_PostCloseToNotificationObject, OnClose); - IPC_MESSAGE_HANDLER(ViewMsg_PermissionRequestDone, - OnPermissionRequestComplete); - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - bool NotificationProvider::Send(IPC::Message* message) { return RenderThread::current()->Send(message); } diff --git a/chrome/renderer/notification_provider.h b/chrome/renderer/notification_provider.h index ec0a05c..f08d031 100644 --- a/chrome/renderer/notification_provider.h +++ b/chrome/renderer/notification_provider.h @@ -9,7 +9,6 @@ #include "chrome/common/desktop_notifications/active_notification_tracker.h" #include "ipc/ipc_channel.h" -#include "ipc/ipc_channel_proxy.h" #include "webkit/api/public/WebNotification.h" #include "webkit/api/public/WebNotificationPresenter.h" @@ -18,14 +17,14 @@ namespace WebKit { class WebNotificationPermissionCallback; } -class NotificationProvider : public WebKit::WebNotificationPresenter, - public IPC::ChannelProxy::MessageFilter { +// NotificationProvider class is owned by the RenderView. Only +// to be used on the UI thread. +class NotificationProvider : public WebKit::WebNotificationPresenter { public: explicit NotificationProvider(RenderView* view); ~NotificationProvider() {} - // WebKit::WebNotificationPresenter interface. Called from WebKit - // on the UI thread. + // WebKit::WebNotificationPresenter interface. virtual bool show(const WebKit::WebNotification& proxy); virtual void cancel(const WebKit::WebNotification& proxy); virtual void objectDestroyed(const WebKit::WebNotification& proxy); @@ -34,26 +33,20 @@ class NotificationProvider : public WebKit::WebNotificationPresenter, virtual void requestPermission(const WebKit::WebString& origin, WebKit::WebNotificationPermissionCallback* callback); -private: - // Internal methods used on the UI thread. + // IPC message handler called from RenderView. + bool OnMessageReceived(const IPC::Message& message); + + private: + // Internal methods used to show notifications. bool ShowHTML(const WebKit::WebNotification& notification, int id); bool ShowText(const WebKit::WebNotification& notification, int id); - // Callback methods invoked when events happen on active notifications. + // IPC handlers. void OnDisplay(int id); void OnError(int id, const WebKit::WebString& message); void OnClose(int id, bool by_user); void OnPermissionRequestComplete(int id); - // Internal versions of the IPC handlers which run on the UI thread. - void HandleOnDisplay(int id); - void HandleOnError(int id, const WebKit::WebString& message); - void HandleOnClose(int id, bool by_user); - void HandleOnPermissionRequestComplete(int id); - - // IPC::ChannelProxy::MessageFilter override - virtual bool OnMessageReceived(const IPC::Message& message); - bool Send(IPC::Message* message); // Non-owned pointer to the RenderView object which created and owns diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index f4618da..5691a84 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -230,6 +230,8 @@ RenderView::RenderView(RenderThreadBase* render_thread, delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync), preferred_width_(0), send_preferred_width_changes_(false), + ALLOW_THIS_IN_INITIALIZER_LIST( + notification_provider_(new NotificationProvider(this))), determine_page_text_after_loading_stops_(false), view_type_(ViewType::INVALID), browser_window_id_(-1), @@ -262,7 +264,6 @@ RenderView::~RenderView() { #endif render_thread_->RemoveFilter(audio_message_filter_); - render_thread_->RemoveFilter(notification_provider_.get()); #ifndef NDEBUG // Make sure we are no longer referenced by the ViewMap. @@ -346,8 +347,6 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd, devtools_agent_.reset(new DevToolsAgent(routing_id, this)); - notification_provider_ = new NotificationProvider(this); - webwidget_ = WebView::Create(this); Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); webkit_preferences_.Apply(webview()); @@ -376,7 +375,6 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd, audio_message_filter_ = new AudioMessageFilter(routing_id_); render_thread_->AddFilter(audio_message_filter_); - render_thread_->AddFilter(notification_provider_.get()); } void RenderView::OnMessageReceived(const IPC::Message& message) { @@ -389,6 +387,8 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { return; if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) return; + if (notification_provider_->OnMessageReceived(message)) + return; IPC_BEGIN_MESSAGE_MAP(RenderView, message) IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail) diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 43d1643..16b4fe0 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -912,7 +912,7 @@ class RenderView : public RenderWidget, std::string last_selection_; // Hopds a reference to the service which provides desktop notifications. - scoped_refptr<NotificationProvider> notification_provider_; + scoped_ptr<NotificationProvider> notification_provider_; // Set to true if request for capturing page text has been made. bool determine_page_text_after_loading_stops_; |