• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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/notifications/notification_object_proxy.h"
6 
7 #include "base/guid.h"
8 #include "base/strings/stringprintf.h"
9 #include "content/public/browser/desktop_notification_delegate.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/web_contents.h"
13 
NotificationObjectProxy(content::RenderFrameHost * render_frame_host,content::DesktopNotificationDelegate * delegate)14 NotificationObjectProxy::NotificationObjectProxy(
15     content::RenderFrameHost* render_frame_host,
16     content::DesktopNotificationDelegate* delegate)
17     : render_process_id_(render_frame_host->GetProcess()->GetID()),
18       render_frame_id_(render_frame_host->GetRoutingID()),
19       delegate_(delegate),
20       displayed_(false),
21       id_(base::GenerateGUID()) {
22 }
23 
Display()24 void NotificationObjectProxy::Display() {
25   // This method is called each time the notification is shown to the user
26   // but we only want to fire the event the first time.
27   if (displayed_)
28     return;
29   displayed_ = true;
30 
31   delegate_->NotificationDisplayed();
32 }
33 
Error()34 void NotificationObjectProxy::Error() {
35   delegate_->NotificationError();
36 }
37 
Close(bool by_user)38 void NotificationObjectProxy::Close(bool by_user) {
39   delegate_->NotificationClosed(by_user);
40 }
41 
Click()42 void NotificationObjectProxy::Click() {
43   delegate_->NotificationClick();
44 }
45 
id() const46 std::string NotificationObjectProxy::id() const {
47   return id_;
48 }
49 
process_id() const50 int NotificationObjectProxy::process_id() const {
51   return render_process_id_;
52 }
53 
GetWebContents() const54 content::WebContents* NotificationObjectProxy::GetWebContents() const {
55   return content::WebContents::FromRenderFrameHost(
56       content::RenderFrameHost::FromID(render_process_id_, render_frame_id_));
57 }
58