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

Side by Side Diff: chrome/browser/extensions/api/notification/notification_api.cc

Issue 12221127: Actually prevent sending notifications from apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 10 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/browser/extensions/api/notification/notification_api.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 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 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/extensions/api/notification/notification_api.h" 5 #include "chrome/browser/extensions/api/notification/notification_api.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/event_names.h" 11 #include "chrome/browser/extensions/event_names.h"
12 #include "chrome/browser/extensions/event_router.h" 12 #include "chrome/browser/extensions/event_router.h"
13 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/notifications/desktop_notification_service.h"
15 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
14 #include "chrome/browser/notifications/notification.h" 16 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_ui_manager.h" 17 #include "chrome/browser/notifications/notification_ui_manager.h"
16 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
17 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
18 #include "ui/notifications/notification_types.h" 20 #include "ui/notifications/notification_types.h"
19 21
20 namespace extensions { 22 namespace extensions {
21 23
22 namespace { 24 namespace {
23 25
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 extension_->id(), 189 extension_->id(),
188 id)); // ownership is passed to Notification 190 id)); // ownership is passed to Notification
189 Notification notification(type, extension_->url(), icon_url, title, message, 191 Notification notification(type, extension_->url(), icon_url, title, message,
190 WebKit::WebTextDirectionDefault, 192 WebKit::WebTextDirectionDefault,
191 string16(), UTF8ToUTF16(api_delegate->id()), 193 string16(), UTF8ToUTF16(api_delegate->id()),
192 optional_fields.get(), api_delegate); 194 optional_fields.get(), api_delegate);
193 195
194 g_browser_process->notification_ui_manager()->Add(notification, profile()); 196 g_browser_process->notification_ui_manager()->Add(notification, profile());
195 } 197 }
196 198
199 bool NotificationApiFunction::IsNotificationApiEnabled() {
200 DesktopNotificationService* service =
201 DesktopNotificationServiceFactory::GetForProfile(profile());
202 return service->IsExtensionEnabled(extension_->id());
203 }
204
205 bool NotificationApiFunction::RunImpl() {
206 if (!IsNotificationApiEnabled()) {
207 SendResponse(false);
208 return true;
209 }
210
211 return RunNotificationApi();
212 }
213
197 const char kNotificationPrefix[] = "extension.api."; 214 const char kNotificationPrefix[] = "extension.api.";
198 215
199 static uint64 next_id_ = 0; 216 static uint64 next_id_ = 0;
200 217
201 NotificationCreateFunction::NotificationCreateFunction() { 218 NotificationCreateFunction::NotificationCreateFunction() {
202 } 219 }
203 220
204 NotificationCreateFunction::~NotificationCreateFunction() { 221 NotificationCreateFunction::~NotificationCreateFunction() {
205 } 222 }
206 223
207 bool NotificationCreateFunction::RunImpl() { 224 bool NotificationCreateFunction::RunNotificationApi() {
208 params_ = api::experimental_notification::Create::Params::Create(*args_); 225 params_ = api::experimental_notification::Create::Params::Create(*args_);
209 EXTENSION_FUNCTION_VALIDATE(params_.get()); 226 EXTENSION_FUNCTION_VALIDATE(params_.get());
210 227
211 // If the caller provided a notificationId, use that. Otherwise, generate 228 // If the caller provided a notificationId, use that. Otherwise, generate
212 // one. Note that there's nothing stopping an app developer from passing in 229 // one. Note that there's nothing stopping an app developer from passing in
213 // arbitrary "extension.api.999" notificationIds that will collide with 230 // arbitrary "extension.api.999" notificationIds that will collide with
214 // future generated IDs. It doesn't seem necessary to try to prevent this; if 231 // future generated IDs. It doesn't seem necessary to try to prevent this; if
215 // developers want to hurt themselves, we'll let them. 232 // developers want to hurt themselves, we'll let them.
216 const std::string extension_id(extension_->id()); 233 const std::string extension_id(extension_->id());
217 std::string notification_id; 234 std::string notification_id;
(...skipping 10 matching lines...) Expand all
228 245
229 return true; 246 return true;
230 } 247 }
231 248
232 NotificationUpdateFunction::NotificationUpdateFunction() { 249 NotificationUpdateFunction::NotificationUpdateFunction() {
233 } 250 }
234 251
235 NotificationUpdateFunction::~NotificationUpdateFunction() { 252 NotificationUpdateFunction::~NotificationUpdateFunction() {
236 } 253 }
237 254
238 bool NotificationUpdateFunction::RunImpl() { 255 bool NotificationUpdateFunction::RunNotificationApi() {
239 params_ = api::experimental_notification::Update::Params::Create(*args_); 256 params_ = api::experimental_notification::Update::Params::Create(*args_);
240 EXTENSION_FUNCTION_VALIDATE(params_.get()); 257 EXTENSION_FUNCTION_VALIDATE(params_.get());
241 258
242 if (g_browser_process->notification_ui_manager()-> 259 if (g_browser_process->notification_ui_manager()->
243 DoesIdExist(NotificationApiDelegate::CreateScopedIdentifier( 260 DoesIdExist(NotificationApiDelegate::CreateScopedIdentifier(
244 extension_->id(), params_->notification_id))) { 261 extension_->id(), params_->notification_id))) {
245 CreateNotification(params_->notification_id, &params_->options); 262 CreateNotification(params_->notification_id, &params_->options);
246 SetResult(Value::CreateBooleanValue(true)); 263 SetResult(Value::CreateBooleanValue(true));
247 } else { 264 } else {
248 SetResult(Value::CreateBooleanValue(false)); 265 SetResult(Value::CreateBooleanValue(false));
249 } 266 }
250 267
251 SendResponse(true); 268 SendResponse(true);
252 269
253 return true; 270 return true;
254 } 271 }
255 272
256 NotificationDeleteFunction::NotificationDeleteFunction() { 273 NotificationDeleteFunction::NotificationDeleteFunction() {
257 } 274 }
258 275
259 NotificationDeleteFunction::~NotificationDeleteFunction() { 276 NotificationDeleteFunction::~NotificationDeleteFunction() {
260 } 277 }
261 278
262 bool NotificationDeleteFunction::RunImpl() { 279 bool NotificationDeleteFunction::RunNotificationApi() {
263 params_ = api::experimental_notification::Delete::Params::Create(*args_); 280 params_ = api::experimental_notification::Delete::Params::Create(*args_);
264 EXTENSION_FUNCTION_VALIDATE(params_.get()); 281 EXTENSION_FUNCTION_VALIDATE(params_.get());
265 282
266 bool cancel_result = g_browser_process->notification_ui_manager()-> 283 bool cancel_result = g_browser_process->notification_ui_manager()->
267 CancelById(NotificationApiDelegate::CreateScopedIdentifier( 284 CancelById(NotificationApiDelegate::CreateScopedIdentifier(
268 extension_->id(), params_->notification_id)); 285 extension_->id(), params_->notification_id));
269 286
270 SetResult(Value::CreateBooleanValue(cancel_result)); 287 SetResult(Value::CreateBooleanValue(cancel_result));
271 SendResponse(true); 288 SendResponse(true);
272 289
273 return true; 290 return true;
274 } 291 }
275 292
276 } // namespace extensions 293 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/notification/notification_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698