Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/renderer/notification_provider.cc

Issue 276032: Refactor notification provider in renderer process to not use a message filte... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/notification_provider.h ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/renderer/notification_provider.h" 5 #include "chrome/renderer/notification_provider.h"
6 6
7 #include "base/task.h" 7 #include "base/task.h"
8 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
9 #include "chrome/renderer/render_thread.h" 9 #include "chrome/renderer/render_thread.h"
10 #include "chrome/renderer/render_view.h" 10 #include "chrome/renderer/render_view.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 void NotificationProvider::requestPermission( 55 void NotificationProvider::requestPermission(
56 const WebString& origin, WebNotificationPermissionCallback* callback) { 56 const WebString& origin, WebNotificationPermissionCallback* callback) {
57 int id = manager_.RegisterPermissionRequest(callback); 57 int id = manager_.RegisterPermissionRequest(callback);
58 58
59 Send(new ViewHostMsg_RequestNotificationPermission(view_->routing_id(), 59 Send(new ViewHostMsg_RequestNotificationPermission(view_->routing_id(),
60 GURL(origin), id)); 60 GURL(origin), id));
61 } 61 }
62 62
63 bool NotificationProvider::OnMessageReceived(const IPC::Message& message) {
64 bool handled = true;
65 IPC_BEGIN_MESSAGE_MAP(NotificationProvider, message)
66 IPC_MESSAGE_HANDLER(ViewMsg_PostDisplayToNotificationObject, OnDisplay);
67 IPC_MESSAGE_HANDLER(ViewMsg_PostErrorToNotificationObject, OnError);
68 IPC_MESSAGE_HANDLER(ViewMsg_PostCloseToNotificationObject, OnClose);
69 IPC_MESSAGE_HANDLER(ViewMsg_PermissionRequestDone,
70 OnPermissionRequestComplete);
71 IPC_MESSAGE_UNHANDLED(handled = false)
72 IPC_END_MESSAGE_MAP()
73 return handled;
74 }
75
63 bool NotificationProvider::ShowHTML(const WebNotification& notification, 76 bool NotificationProvider::ShowHTML(const WebNotification& notification,
64 int id) { 77 int id) {
65 DCHECK(notification.isHTML()); 78 DCHECK(notification.isHTML());
66 return Send(new ViewHostMsg_ShowDesktopNotification(view_->routing_id(), 79 return Send(new ViewHostMsg_ShowDesktopNotification(view_->routing_id(),
67 GURL(view_->webview()->mainFrame()->url()), 80 GURL(view_->webview()->mainFrame()->url()),
68 notification.url(), id)); 81 notification.url(), id));
69 } 82 }
70 83
71 bool NotificationProvider::ShowText(const WebNotification& notification, 84 bool NotificationProvider::ShowText(const WebNotification& notification,
72 int id) { 85 int id) {
73 DCHECK(!notification.isHTML()); 86 DCHECK(!notification.isHTML());
74 return Send(new ViewHostMsg_ShowDesktopNotificationText(view_->routing_id(), 87 return Send(new ViewHostMsg_ShowDesktopNotificationText(view_->routing_id(),
75 GURL(view_->webview()->mainFrame()->url()), 88 GURL(view_->webview()->mainFrame()->url()),
76 GURL(notification.icon()), 89 GURL(notification.icon()),
77 notification.title(), notification.body(), id)); 90 notification.title(), notification.body(), id));
78 } 91 }
79 92
80 void NotificationProvider::OnDisplay(int id) { 93 void NotificationProvider::OnDisplay(int id) {
81 RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE,
82 NewRunnableMethod(this, &NotificationProvider::HandleOnDisplay, id));
83 }
84
85 void NotificationProvider::OnError(int id, const WebString& message) {
86 RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE,
87 NewRunnableMethod(this, &NotificationProvider::HandleOnError,
88 id, message));
89 }
90
91 void NotificationProvider::OnClose(int id, bool by_user) {
92 RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE,
93 NewRunnableMethod(this, &NotificationProvider::HandleOnClose,
94 id, by_user));
95 }
96
97 void NotificationProvider::OnPermissionRequestComplete(int id) {
98 RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE,
99 NewRunnableMethod(this,
100 &NotificationProvider::HandleOnPermissionRequestComplete, id));
101 }
102
103 void NotificationProvider::HandleOnDisplay(int id) {
104 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
105 WebNotification notification; 94 WebNotification notification;
106 bool found = manager_.GetNotification(id, &notification); 95 bool found = manager_.GetNotification(id, &notification);
107 // |found| may be false if the WebNotification went out of scope in 96 // |found| may be false if the WebNotification went out of scope in
108 // the page before it was actually displayed to the user. 97 // the page before it was actually displayed to the user.
109 if (found) 98 if (found)
110 notification.dispatchDisplayEvent(); 99 notification.dispatchDisplayEvent();
111 } 100 }
112 101
113 void NotificationProvider::HandleOnError(int id, const WebString& message) { 102 void NotificationProvider::OnError(int id, const WebString& message) {
114 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
115 WebNotification notification; 103 WebNotification notification;
116 bool found = manager_.GetNotification(id, &notification); 104 bool found = manager_.GetNotification(id, &notification);
117 // |found| may be false if the WebNotification went out of scope in 105 // |found| may be false if the WebNotification went out of scope in
118 // the page before the error occurred. 106 // the page before the error occurred.
119 if (found) 107 if (found)
120 notification.dispatchErrorEvent(message); 108 notification.dispatchErrorEvent(message);
121 } 109 }
122 110
123 void NotificationProvider::HandleOnClose(int id, bool by_user) { 111 void NotificationProvider::OnClose(int id, bool by_user) {
124 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
125 WebNotification notification; 112 WebNotification notification;
126 bool found = manager_.GetNotification(id, &notification); 113 bool found = manager_.GetNotification(id, &notification);
127 // |found| may be false if the WebNotification went out of scope in 114 // |found| may be false if the WebNotification went out of scope in
128 // the page before the associated toast was closed by the user. 115 // the page before the associated toast was closed by the user.
129 if (found) 116 if (found)
130 notification.dispatchCloseEvent(by_user); 117 notification.dispatchCloseEvent(by_user);
131 manager_.UnregisterNotification(id); 118 manager_.UnregisterNotification(id);
132 } 119 }
133 120
134 void NotificationProvider::HandleOnPermissionRequestComplete(int id) { 121 void NotificationProvider::OnPermissionRequestComplete(int id) {
135 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
136 WebNotificationPermissionCallback* callback = manager_.GetCallback(id); 122 WebNotificationPermissionCallback* callback = manager_.GetCallback(id);
137 DCHECK(callback); 123 DCHECK(callback);
138 callback->permissionRequestComplete(); 124 callback->permissionRequestComplete();
139 manager_.OnPermissionRequestComplete(id); 125 manager_.OnPermissionRequestComplete(id);
140 } 126 }
141 127
142 bool NotificationProvider::OnMessageReceived(const IPC::Message& message) {
143 if (message.routing_id() != view_->routing_id())
144 return false;
145
146 bool handled = true;
147 IPC_BEGIN_MESSAGE_MAP(NotificationProvider, message)
148 IPC_MESSAGE_HANDLER(ViewMsg_PostDisplayToNotificationObject, OnDisplay);
149 IPC_MESSAGE_HANDLER(ViewMsg_PostErrorToNotificationObject, OnError);
150 IPC_MESSAGE_HANDLER(ViewMsg_PostCloseToNotificationObject, OnClose);
151 IPC_MESSAGE_HANDLER(ViewMsg_PermissionRequestDone,
152 OnPermissionRequestComplete);
153 IPC_MESSAGE_UNHANDLED(handled = false)
154 IPC_END_MESSAGE_MAP()
155 return handled;
156 }
157
158 bool NotificationProvider::Send(IPC::Message* message) { 128 bool NotificationProvider::Send(IPC::Message* message) {
159 return RenderThread::current()->Send(message); 129 return RenderThread::current()->Send(message);
160 } 130 }
OLDNEW
« no previous file with comments | « chrome/renderer/notification_provider.h ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698