| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/desktop_notification_handler.h" | 5 #include "chrome/browser/desktop_notification_handler.h" |
| 6 | 6 |
| 7 #include "chrome/browser/notifications/desktop_notification_service.h" | 7 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "content/browser/renderer_host/render_process_host.h" | 11 #include "content/browser/renderer_host/render_process_host.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/common/desktop_notification_messages.h" | 13 #include "content/common/desktop_notification_messages.h" |
| 13 | 14 |
| 14 DesktopNotificationHandler::DesktopNotificationHandler( | 15 DesktopNotificationHandler::DesktopNotificationHandler( |
| 15 TabContents* tab, RenderProcessHost* process) | 16 TabContents* tab, RenderProcessHost* process) |
| 16 : tab_(tab), | 17 : tab_(tab), |
| 17 process_(process) { | 18 process_(process) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 30 IPC_END_MESSAGE_MAP() | 31 IPC_END_MESSAGE_MAP() |
| 31 | 32 |
| 32 return handled; | 33 return handled; |
| 33 } | 34 } |
| 34 | 35 |
| 35 void DesktopNotificationHandler::OnShow( | 36 void DesktopNotificationHandler::OnShow( |
| 36 const IPC::Message& message, | 37 const IPC::Message& message, |
| 37 const DesktopNotificationHostMsg_Show_Params& params) { | 38 const DesktopNotificationHostMsg_Show_Params& params) { |
| 38 RenderProcessHost* process = GetRenderProcessHost(); | 39 RenderProcessHost* process = GetRenderProcessHost(); |
| 39 DesktopNotificationService* service = | 40 DesktopNotificationService* service = |
| 40 process->profile()->GetDesktopNotificationService(); | 41 DesktopNotificationServiceFactory::GetForProfile(process->profile()); |
| 41 | 42 |
| 42 service->ShowDesktopNotification( | 43 service->ShowDesktopNotification( |
| 43 params, | 44 params, |
| 44 process->id(), | 45 process->id(), |
| 45 message.routing_id(), | 46 message.routing_id(), |
| 46 DesktopNotificationService::PageNotification); | 47 DesktopNotificationService::PageNotification); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void DesktopNotificationHandler::OnCancel(const IPC::Message& message, | 50 void DesktopNotificationHandler::OnCancel(const IPC::Message& message, |
| 50 int notification_id) { | 51 int notification_id) { |
| 51 RenderProcessHost* process = GetRenderProcessHost(); | 52 RenderProcessHost* process = GetRenderProcessHost(); |
| 52 DesktopNotificationService* service = | 53 DesktopNotificationService* service = |
| 53 process->profile()->GetDesktopNotificationService(); | 54 DesktopNotificationServiceFactory::GetForProfile(process->profile()); |
| 54 | 55 |
| 55 service->CancelDesktopNotification( | 56 service->CancelDesktopNotification( |
| 56 process->id(), | 57 process->id(), |
| 57 message.routing_id(), | 58 message.routing_id(), |
| 58 notification_id); | 59 notification_id); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void DesktopNotificationHandler::OnRequestPermission( | 62 void DesktopNotificationHandler::OnRequestPermission( |
| 62 const IPC::Message& message, const GURL& source_origin, | 63 const IPC::Message& message, const GURL& source_origin, |
| 63 int callback_context) { | 64 int callback_context) { |
| 64 RenderProcessHost* process = GetRenderProcessHost(); | 65 RenderProcessHost* process = GetRenderProcessHost(); |
| 65 Browser* browser = BrowserList::GetLastActive(); | 66 Browser* browser = BrowserList::GetLastActive(); |
| 66 // We may not have a BrowserList if the chrome browser process is launched as | 67 // We may not have a BrowserList if the chrome browser process is launched as |
| 67 // a ChromeFrame process in which case we attempt to use the TabContents | 68 // a ChromeFrame process in which case we attempt to use the TabContents |
| 68 // provided by the RenderViewHostDelegate. | 69 // provided by the RenderViewHostDelegate. |
| 69 TabContents* tab = browser ? browser->GetSelectedTabContents() : tab_; | 70 TabContents* tab = browser ? browser->GetSelectedTabContents() : tab_; |
| 70 if (!tab) | 71 if (!tab) |
| 71 return; | 72 return; |
| 72 | 73 |
| 73 DesktopNotificationService* service = | 74 DesktopNotificationService* service = |
| 74 tab->profile()->GetDesktopNotificationService(); | 75 DesktopNotificationServiceFactory::GetForProfile(tab->profile()); |
| 75 service->RequestPermission( | 76 service->RequestPermission( |
| 76 source_origin, | 77 source_origin, |
| 77 process->id(), | 78 process->id(), |
| 78 message.routing_id(), | 79 message.routing_id(), |
| 79 callback_context, | 80 callback_context, |
| 80 tab); | 81 tab); |
| 81 } | 82 } |
| 82 | 83 |
| 83 RenderProcessHost* DesktopNotificationHandler::GetRenderProcessHost() { | 84 RenderProcessHost* DesktopNotificationHandler::GetRenderProcessHost() { |
| 84 return tab_ ? tab_->GetRenderProcessHost() : process_; | 85 return tab_ ? tab_->GetRenderProcessHost() : process_; |
| 85 } | 86 } |
| 86 | 87 |
| 87 DesktopNotificationHandlerForTC::DesktopNotificationHandlerForTC( | 88 DesktopNotificationHandlerForTC::DesktopNotificationHandlerForTC( |
| 88 TabContents* tab_contents, | 89 TabContents* tab_contents, |
| 89 RenderProcessHost* process) | 90 RenderProcessHost* process) |
| 90 : TabContentsObserver(tab_contents), | 91 : TabContentsObserver(tab_contents), |
| 91 handler_(tab_contents, process) { | 92 handler_(tab_contents, process) { |
| 92 } | 93 } |
| 93 | 94 |
| 94 bool DesktopNotificationHandlerForTC::OnMessageReceived( | 95 bool DesktopNotificationHandlerForTC::OnMessageReceived( |
| 95 const IPC::Message& message) { | 96 const IPC::Message& message) { |
| 96 return handler_.OnMessageReceived(message); | 97 return handler_.OnMessageReceived(message); |
| 97 } | 98 } |
| OLD | NEW |