| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_RENDERER_NOTIFICATION_PROVIDER_H_ | 5 #ifndef CHROME_RENDERER_NOTIFICATION_PROVIDER_H_ |
| 6 #define CHROME_RENDERER_NOTIFICATION_PROVIDER_H_ | 6 #define CHROME_RENDERER_NOTIFICATION_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "chrome/common/desktop_notifications/active_notification_tracker.h" | 10 #include "chrome/common/desktop_notifications/active_notification_tracker.h" |
| 11 #include "ipc/ipc_channel.h" | 11 #include "ipc/ipc_channel.h" |
| 12 #include "ipc/ipc_channel_proxy.h" | |
| 13 #include "webkit/api/public/WebNotification.h" | 12 #include "webkit/api/public/WebNotification.h" |
| 14 #include "webkit/api/public/WebNotificationPresenter.h" | 13 #include "webkit/api/public/WebNotificationPresenter.h" |
| 15 | 14 |
| 16 class RenderView; | 15 class RenderView; |
| 17 namespace WebKit { | 16 namespace WebKit { |
| 18 class WebNotificationPermissionCallback; | 17 class WebNotificationPermissionCallback; |
| 19 } | 18 } |
| 20 | 19 |
| 21 class NotificationProvider : public WebKit::WebNotificationPresenter, | 20 // NotificationProvider class is owned by the RenderView. Only |
| 22 public IPC::ChannelProxy::MessageFilter { | 21 // to be used on the UI thread. |
| 22 class NotificationProvider : public WebKit::WebNotificationPresenter { |
| 23 public: | 23 public: |
| 24 explicit NotificationProvider(RenderView* view); | 24 explicit NotificationProvider(RenderView* view); |
| 25 ~NotificationProvider() {} | 25 ~NotificationProvider() {} |
| 26 | 26 |
| 27 // WebKit::WebNotificationPresenter interface. Called from WebKit | 27 // WebKit::WebNotificationPresenter interface. |
| 28 // on the UI thread. | |
| 29 virtual bool show(const WebKit::WebNotification& proxy); | 28 virtual bool show(const WebKit::WebNotification& proxy); |
| 30 virtual void cancel(const WebKit::WebNotification& proxy); | 29 virtual void cancel(const WebKit::WebNotification& proxy); |
| 31 virtual void objectDestroyed(const WebKit::WebNotification& proxy); | 30 virtual void objectDestroyed(const WebKit::WebNotification& proxy); |
| 32 virtual WebKit::WebNotificationPresenter::Permission checkPermission( | 31 virtual WebKit::WebNotificationPresenter::Permission checkPermission( |
| 33 const WebKit::WebString& origin); | 32 const WebKit::WebString& origin); |
| 34 virtual void requestPermission(const WebKit::WebString& origin, | 33 virtual void requestPermission(const WebKit::WebString& origin, |
| 35 WebKit::WebNotificationPermissionCallback* callback); | 34 WebKit::WebNotificationPermissionCallback* callback); |
| 36 | 35 |
| 37 private: | 36 // IPC message handler called from RenderView. |
| 38 // Internal methods used on the UI thread. | 37 bool OnMessageReceived(const IPC::Message& message); |
| 38 |
| 39 private: |
| 40 // Internal methods used to show notifications. |
| 39 bool ShowHTML(const WebKit::WebNotification& notification, int id); | 41 bool ShowHTML(const WebKit::WebNotification& notification, int id); |
| 40 bool ShowText(const WebKit::WebNotification& notification, int id); | 42 bool ShowText(const WebKit::WebNotification& notification, int id); |
| 41 | 43 |
| 42 // Callback methods invoked when events happen on active notifications. | 44 // IPC handlers. |
| 43 void OnDisplay(int id); | 45 void OnDisplay(int id); |
| 44 void OnError(int id, const WebKit::WebString& message); | 46 void OnError(int id, const WebKit::WebString& message); |
| 45 void OnClose(int id, bool by_user); | 47 void OnClose(int id, bool by_user); |
| 46 void OnPermissionRequestComplete(int id); | 48 void OnPermissionRequestComplete(int id); |
| 47 | 49 |
| 48 // Internal versions of the IPC handlers which run on the UI thread. | |
| 49 void HandleOnDisplay(int id); | |
| 50 void HandleOnError(int id, const WebKit::WebString& message); | |
| 51 void HandleOnClose(int id, bool by_user); | |
| 52 void HandleOnPermissionRequestComplete(int id); | |
| 53 | |
| 54 // IPC::ChannelProxy::MessageFilter override | |
| 55 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 56 | |
| 57 bool Send(IPC::Message* message); | 50 bool Send(IPC::Message* message); |
| 58 | 51 |
| 59 // Non-owned pointer to the RenderView object which created and owns | 52 // Non-owned pointer to the RenderView object which created and owns |
| 60 // this object. | 53 // this object. |
| 61 RenderView* view_; | 54 RenderView* view_; |
| 62 | 55 |
| 63 // A tracker object which manages the active notifications and the IDs | 56 // A tracker object which manages the active notifications and the IDs |
| 64 // that are used to refer to them over IPC. | 57 // that are used to refer to them over IPC. |
| 65 ActiveNotificationTracker manager_; | 58 ActiveNotificationTracker manager_; |
| 66 | 59 |
| 67 DISALLOW_COPY_AND_ASSIGN(NotificationProvider); | 60 DISALLOW_COPY_AND_ASSIGN(NotificationProvider); |
| 68 }; | 61 }; |
| 69 | 62 |
| 70 #endif // CHROME_RENDERER_NOTIFICATION_PROVIDER_H_ | 63 #endif // CHROME_RENDERER_NOTIFICATION_PROVIDER_H_ |
| OLD | NEW |