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

Side by Side Diff: Source/modules/notifications/Notification.cpp

Issue 923443005: Disallow constructing the Notification object in a Service Worker. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 Notification* Notification::create(ExecutionContext* context, const String& titl e, const NotificationOptions& options, ExceptionState& exceptionState) 60 Notification* Notification::create(ExecutionContext* context, const String& titl e, const NotificationOptions& options, ExceptionState& exceptionState)
61 { 61 {
62 // The Web Notification constructor may be disabled through a runtime featur e. The 62 // The Web Notification constructor may be disabled through a runtime featur e. The
63 // behavior of the constructor is changing, but not completely agreed upon y et. 63 // behavior of the constructor is changing, but not completely agreed upon y et.
64 if (!RuntimeEnabledFeatures::notificationConstructorEnabled()) { 64 if (!RuntimeEnabledFeatures::notificationConstructorEnabled()) {
65 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead."); 65 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead.");
66 return nullptr; 66 return nullptr;
67 } 67 }
68 68
69 // The Web Notification constructor may not be used in Service Worker contex ts.
70 if (context->isServiceWorkerGlobalScope()) {
71 exceptionState.throwTypeError("Illegal constructor.");
72 return nullptr;
73 }
74
69 Notification* notification = new Notification(title, context); 75 Notification* notification = new Notification(title, context);
70 76
71 notification->setBody(options.body()); 77 notification->setBody(options.body());
72 notification->setTag(options.tag()); 78 notification->setTag(options.tag());
73 notification->setLang(options.lang()); 79 notification->setLang(options.lang());
74 notification->setDir(options.dir()); 80 notification->setDir(options.dir());
75 if (options.hasIcon()) { 81 if (options.hasIcon()) {
76 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); 82 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon());
77 if (!iconUrl.isEmpty() && iconUrl.isValid()) 83 if (!iconUrl.isEmpty() && iconUrl.isValid())
78 notification->setIconUrl(iconUrl); 84 notification->setIconUrl(iconUrl);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); 265 return m_state == NotificationStateShowing || m_asyncRunner.isActive();
260 } 266 }
261 267
262 void Notification::trace(Visitor* visitor) 268 void Notification::trace(Visitor* visitor)
263 { 269 {
264 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); 270 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor);
265 ActiveDOMObject::trace(visitor); 271 ActiveDOMObject::trace(visitor);
266 } 272 }
267 273
268 } // namespace blink 274 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698