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

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

Issue 901843006: Allow the embedder to disable the Notification constructor. (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 22 matching lines...) Expand all
33 33
34 #include "bindings/core/v8/ScriptWrappable.h" 34 #include "bindings/core/v8/ScriptWrappable.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/ExecutionContext.h" 36 #include "core/dom/ExecutionContext.h"
37 #include "core/dom/ExecutionContextTask.h" 37 #include "core/dom/ExecutionContextTask.h"
38 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" 38 #include "core/dom/ScopedWindowFocusAllowedIndicator.h"
39 #include "core/events/Event.h" 39 #include "core/events/Event.h"
40 #include "core/frame/UseCounter.h" 40 #include "core/frame/UseCounter.h"
41 #include "modules/notifications/NotificationOptions.h" 41 #include "modules/notifications/NotificationOptions.h"
42 #include "modules/notifications/NotificationPermissionClient.h" 42 #include "modules/notifications/NotificationPermissionClient.h"
43 #include "platform/RuntimeEnabledFeatures.h"
43 #include "platform/UserGestureIndicator.h" 44 #include "platform/UserGestureIndicator.h"
44 #include "public/platform/Platform.h" 45 #include "public/platform/Platform.h"
45 #include "public/platform/WebSerializedOrigin.h" 46 #include "public/platform/WebSerializedOrigin.h"
46 #include "public/platform/modules/notifications/WebNotificationData.h" 47 #include "public/platform/modules/notifications/WebNotificationData.h"
47 #include "public/platform/modules/notifications/WebNotificationManager.h" 48 #include "public/platform/modules/notifications/WebNotificationManager.h"
48 49
49 namespace blink { 50 namespace blink {
50 namespace { 51 namespace {
51 52
52 WebNotificationManager* notificationManager() 53 WebNotificationManager* notificationManager()
53 { 54 {
54 return Platform::current()->notificationManager(); 55 return Platform::current()->notificationManager();
55 } 56 }
56 57
57 } // namespace 58 } // namespace
58 59
59 Notification* Notification::create(ExecutionContext* context, const String& titl e, const NotificationOptions& options) 60 Notification* Notification::create(ExecutionContext* context, const String& titl e, const NotificationOptions& options, ExceptionState& exceptionState)
60 { 61 {
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.
64 if (!RuntimeEnabledFeatures::notificationConstructorEnabled()) {
65 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg istration.showNotification() instead.");
66 return nullptr;
67 }
68
61 Notification* notification = new Notification(title, context); 69 Notification* notification = new Notification(title, context);
62 70
63 notification->setBody(options.body()); 71 notification->setBody(options.body());
64 notification->setTag(options.tag()); 72 notification->setTag(options.tag());
65 notification->setLang(options.lang()); 73 notification->setLang(options.lang());
66 notification->setDir(options.dir()); 74 notification->setDir(options.dir());
67 if (options.hasIcon()) { 75 if (options.hasIcon()) {
68 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); 76 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon());
69 if (!iconUrl.isEmpty() && iconUrl.isValid()) 77 if (!iconUrl.isEmpty() && iconUrl.isValid())
70 notification->setIconUrl(iconUrl); 78 notification->setIconUrl(iconUrl);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); 259 return m_state == NotificationStateShowing || m_asyncRunner.isActive();
252 } 260 }
253 261
254 void Notification::trace(Visitor* visitor) 262 void Notification::trace(Visitor* visitor)
255 { 263 {
256 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); 264 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor);
257 ActiveDOMObject::trace(visitor); 265 ActiveDOMObject::trace(visitor);
258 } 266 }
259 267
260 } // namespace blink 268 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/modules/notifications/Notification.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698