| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/desktop_notification_handler.h" | |
| 6 | |
| 7 #include "chrome/browser/notifications/desktop_notification_service.h" | |
| 8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/common/url_constants.h" | |
| 11 #include "content/browser/renderer_host/render_process_host.h" | |
| 12 #include "content/browser/renderer_host/render_view_host.h" | |
| 13 #include "content/browser/renderer_host/render_view_host_delegate.h" | |
| 14 #include "content/common/desktop_notification_messages.h" | |
| 15 | |
| 16 // static | |
| 17 DesktopNotificationHandler* | |
| 18 DesktopNotificationHandler::Create(RenderViewHost* render_view_host) { | |
| 19 return new DesktopNotificationHandler(render_view_host); | |
| 20 } | |
| 21 | |
| 22 DesktopNotificationHandler::~DesktopNotificationHandler() { | |
| 23 } | |
| 24 | |
| 25 DesktopNotificationHandler::DesktopNotificationHandler( | |
| 26 RenderViewHost* render_view_host) | |
| 27 : RenderViewHostObserver(render_view_host) { | |
| 28 } | |
| 29 | |
| 30 bool DesktopNotificationHandler::OnMessageReceived( | |
| 31 const IPC::Message& message) { | |
| 32 bool handled = true; | |
| 33 | |
| 34 IPC_BEGIN_MESSAGE_MAP(DesktopNotificationHandler, message) | |
| 35 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, OnShow) | |
| 36 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, OnCancel) | |
| 37 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, | |
| 38 OnRequestPermission) | |
| 39 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 40 IPC_END_MESSAGE_MAP() | |
| 41 | |
| 42 return handled; | |
| 43 } | |
| 44 | |
| 45 void DesktopNotificationHandler::OnShow( | |
| 46 const DesktopNotificationHostMsg_Show_Params& params) { | |
| 47 // Disallow HTML notifications from unwanted schemes. javascript: | |
| 48 // in particular allows unwanted cross-domain access. | |
| 49 GURL url = params.contents_url; | |
| 50 if (params.is_html && | |
| 51 !url.SchemeIs(chrome::kHttpScheme) && | |
| 52 !url.SchemeIs(chrome::kHttpsScheme) && | |
| 53 !url.SchemeIs(chrome::kExtensionScheme) && | |
| 54 !url.SchemeIs(chrome::kDataScheme)) { | |
| 55 return; | |
| 56 } | |
| 57 | |
| 58 RenderProcessHost* process = render_view_host()->process(); | |
| 59 DesktopNotificationService* service = | |
| 60 DesktopNotificationServiceFactory::GetForProfile(process->profile()); | |
| 61 | |
| 62 service->ShowDesktopNotification( | |
| 63 params, | |
| 64 process->id(), | |
| 65 routing_id(), | |
| 66 DesktopNotificationService::PageNotification); | |
| 67 } | |
| 68 | |
| 69 void DesktopNotificationHandler::OnCancel(int notification_id) { | |
| 70 RenderProcessHost* process = render_view_host()->process(); | |
| 71 DesktopNotificationService* service = | |
| 72 DesktopNotificationServiceFactory::GetForProfile(process->profile()); | |
| 73 | |
| 74 service->CancelDesktopNotification( | |
| 75 process->id(), | |
| 76 routing_id(), | |
| 77 notification_id); | |
| 78 } | |
| 79 | |
| 80 void DesktopNotificationHandler::OnRequestPermission( | |
| 81 const GURL& source_origin, int callback_context) { | |
| 82 if (render_view_host()->delegate()->RequestDesktopNotificationPermission( | |
| 83 source_origin, callback_context)) { | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 RenderProcessHost* process = render_view_host()->process(); | |
| 88 DesktopNotificationService* service = | |
| 89 DesktopNotificationServiceFactory::GetForProfile(process->profile()); | |
| 90 service->RequestPermission( | |
| 91 source_origin, process->id(), routing_id(), callback_context, NULL); | |
| 92 } | |
| OLD | NEW |