OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 18 matching lines...) Expand all Loading... |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 #include "config.h" | 32 #include "config.h" |
33 | 33 |
34 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) | 34 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) |
35 | 35 |
36 #include "modules/notifications/Notification.h" | 36 #include "modules/notifications/Notification.h" |
37 | 37 |
38 #include "bindings/v8/Dictionary.h" | 38 #include "bindings/v8/Dictionary.h" |
39 #include "bindings/v8/ExceptionState.h" | |
40 #include "core/dom/Document.h" | 39 #include "core/dom/Document.h" |
41 #include "core/dom/ErrorEvent.h" | 40 #include "core/dom/ErrorEvent.h" |
42 #include "core/dom/EventNames.h" | 41 #include "core/dom/EventNames.h" |
43 #include "core/loader/ThreadableLoader.h" | 42 #include "core/loader/ThreadableLoader.h" |
44 #include "core/page/DOMWindow.h" | 43 #include "core/page/DOMWindow.h" |
45 #include "core/page/WindowFocusAllowedIndicator.h" | 44 #include "core/page/WindowFocusAllowedIndicator.h" |
46 #include "core/platform/network/ResourceRequest.h" | 45 #include "core/platform/network/ResourceRequest.h" |
47 #include "core/platform/network/ResourceResponse.h" | 46 #include "core/platform/network/ResourceResponse.h" |
48 #include "core/workers/WorkerGlobalScope.h" | 47 #include "core/workers/WorkerGlobalScope.h" |
49 #include "modules/notifications/DOMWindowNotifications.h" | 48 #include "modules/notifications/DOMWindowNotifications.h" |
50 #include "modules/notifications/NotificationCenter.h" | 49 #include "modules/notifications/NotificationCenter.h" |
51 #include "modules/notifications/NotificationClient.h" | 50 #include "modules/notifications/NotificationClient.h" |
52 #include "modules/notifications/NotificationController.h" | 51 #include "modules/notifications/NotificationController.h" |
53 #include "modules/notifications/NotificationPermissionCallback.h" | 52 #include "modules/notifications/NotificationPermissionCallback.h" |
54 | 53 |
55 namespace WebCore { | 54 namespace WebCore { |
56 | 55 |
57 Notification::Notification() | 56 Notification::Notification() |
58 : ActiveDOMObject(0) | 57 : ActiveDOMObject(0) |
59 { | 58 { |
60 ScriptWrappable::init(this); | 59 ScriptWrappable::init(this); |
61 } | 60 } |
62 | 61 |
63 #if ENABLE(LEGACY_NOTIFICATIONS) | 62 #if ENABLE(LEGACY_NOTIFICATIONS) |
64 Notification::Notification(const KURL& url, ScriptExecutionContext* context, Exc
eptionState& es, PassRefPtr<NotificationCenter> provider) | 63 Notification::Notification(const KURL& url, ScriptExecutionContext* context, Exc
eptionCode& ec, PassRefPtr<NotificationCenter> provider) |
65 : ActiveDOMObject(context) | 64 : ActiveDOMObject(context) |
66 , m_isHTML(true) | 65 , m_isHTML(true) |
67 , m_state(Idle) | 66 , m_state(Idle) |
68 , m_notificationCenter(provider) | 67 , m_notificationCenter(provider) |
69 { | 68 { |
70 ScriptWrappable::init(this); | 69 ScriptWrappable::init(this); |
71 if (m_notificationCenter->checkPermission() != NotificationClient::Permissio
nAllowed) { | 70 if (m_notificationCenter->checkPermission() != NotificationClient::Permissio
nAllowed) { |
72 es.throwDOMException(SecurityError); | 71 ec = SecurityError; |
73 return; | 72 return; |
74 } | 73 } |
75 | 74 |
76 if (url.isEmpty() || !url.isValid()) { | 75 if (url.isEmpty() || !url.isValid()) { |
77 es.throwDOMException(SyntaxError); | 76 ec = SyntaxError; |
78 return; | 77 return; |
79 } | 78 } |
80 | 79 |
81 m_notificationURL = url; | 80 m_notificationURL = url; |
82 } | 81 } |
83 #endif | 82 #endif |
84 | 83 |
85 #if ENABLE(LEGACY_NOTIFICATIONS) | 84 #if ENABLE(LEGACY_NOTIFICATIONS) |
86 Notification::Notification(const String& title, const String& body, const String
& iconURI, ScriptExecutionContext* context, ExceptionState& es, PassRefPtr<Notif
icationCenter> provider) | 85 Notification::Notification(const String& title, const String& body, const String
& iconURI, ScriptExecutionContext* context, ExceptionCode& ec, PassRefPtr<Notifi
cationCenter> provider) |
87 : ActiveDOMObject(context) | 86 : ActiveDOMObject(context) |
88 , m_isHTML(false) | 87 , m_isHTML(false) |
89 , m_title(title) | 88 , m_title(title) |
90 , m_body(body) | 89 , m_body(body) |
91 , m_state(Idle) | 90 , m_state(Idle) |
92 , m_notificationCenter(provider) | 91 , m_notificationCenter(provider) |
93 { | 92 { |
94 ScriptWrappable::init(this); | 93 ScriptWrappable::init(this); |
95 if (m_notificationCenter->checkPermission() != NotificationClient::Permissio
nAllowed) { | 94 if (m_notificationCenter->checkPermission() != NotificationClient::Permissio
nAllowed) { |
96 es.throwDOMException(SecurityError); | 95 ec = SecurityError; |
97 return; | 96 return; |
98 } | 97 } |
99 | 98 |
100 m_icon = iconURI.isEmpty() ? KURL() : scriptExecutionContext()->completeURL(
iconURI); | 99 m_icon = iconURI.isEmpty() ? KURL() : scriptExecutionContext()->completeURL(
iconURI); |
101 if (!m_icon.isEmpty() && !m_icon.isValid()) { | 100 if (!m_icon.isEmpty() && !m_icon.isValid()) { |
102 es.throwDOMException(SyntaxError); | 101 ec = SyntaxError; |
103 return; | 102 return; |
104 } | 103 } |
105 } | 104 } |
106 #endif | 105 #endif |
107 | 106 |
108 #if ENABLE(NOTIFICATIONS) | 107 #if ENABLE(NOTIFICATIONS) |
109 Notification::Notification(ScriptExecutionContext* context, const String& title) | 108 Notification::Notification(ScriptExecutionContext* context, const String& title) |
110 : ActiveDOMObject(context) | 109 : ActiveDOMObject(context) |
111 , m_isHTML(false) | 110 , m_isHTML(false) |
112 , m_title(title) | 111 , m_title(title) |
113 , m_state(Idle) | 112 , m_state(Idle) |
114 , m_taskTimer(adoptPtr(new Timer<Notification>(this, &Notification::taskTime
rFired))) | 113 , m_taskTimer(adoptPtr(new Timer<Notification>(this, &Notification::taskTime
rFired))) |
115 { | 114 { |
116 ScriptWrappable::init(this); | 115 ScriptWrappable::init(this); |
117 m_notificationCenter = DOMWindowNotifications::webkitNotifications(toDocumen
t(context)->domWindow()); | 116 m_notificationCenter = DOMWindowNotifications::webkitNotifications(toDocumen
t(context)->domWindow()); |
118 | 117 |
119 ASSERT(m_notificationCenter->client()); | 118 ASSERT(m_notificationCenter->client()); |
120 m_taskTimer->startOneShot(0); | 119 m_taskTimer->startOneShot(0); |
121 } | 120 } |
122 #endif | 121 #endif |
123 | 122 |
124 Notification::~Notification() | 123 Notification::~Notification() |
125 { | 124 { |
126 } | 125 } |
127 | 126 |
128 #if ENABLE(LEGACY_NOTIFICATIONS) | 127 #if ENABLE(LEGACY_NOTIFICATIONS) |
129 PassRefPtr<Notification> Notification::create(const KURL& url, ScriptExecutionCo
ntext* context, ExceptionState& es, PassRefPtr<NotificationCenter> provider) | 128 PassRefPtr<Notification> Notification::create(const KURL& url, ScriptExecutionCo
ntext* context, ExceptionCode& ec, PassRefPtr<NotificationCenter> provider) |
130 { | 129 { |
131 RefPtr<Notification> notification(adoptRef(new Notification(url, context, es
, provider))); | 130 RefPtr<Notification> notification(adoptRef(new Notification(url, context, ec
, provider))); |
132 notification->suspendIfNeeded(); | 131 notification->suspendIfNeeded(); |
133 return notification.release(); | 132 return notification.release(); |
134 } | 133 } |
135 | 134 |
136 PassRefPtr<Notification> Notification::create(const String& title, const String&
body, const String& iconURI, ScriptExecutionContext* context, ExceptionState& e
s, PassRefPtr<NotificationCenter> provider) | 135 PassRefPtr<Notification> Notification::create(const String& title, const String&
body, const String& iconURI, ScriptExecutionContext* context, ExceptionCode& ec
, PassRefPtr<NotificationCenter> provider) |
137 { | 136 { |
138 RefPtr<Notification> notification(adoptRef(new Notification(title, body, ico
nURI, context, es, provider))); | 137 RefPtr<Notification> notification(adoptRef(new Notification(title, body, ico
nURI, context, ec, provider))); |
139 notification->suspendIfNeeded(); | 138 notification->suspendIfNeeded(); |
140 return notification.release(); | 139 return notification.release(); |
141 } | 140 } |
142 #endif | 141 #endif |
143 | 142 |
144 #if ENABLE(NOTIFICATIONS) | 143 #if ENABLE(NOTIFICATIONS) |
145 PassRefPtr<Notification> Notification::create(ScriptExecutionContext* context, c
onst String& title, const Dictionary& options) | 144 PassRefPtr<Notification> Notification::create(ScriptExecutionContext* context, c
onst String& title, const Dictionary& options) |
146 { | 145 { |
147 RefPtr<Notification> notification(adoptRef(new Notification(context, title))
); | 146 RefPtr<Notification> notification(adoptRef(new Notification(context, title))
); |
148 String argument; | 147 String argument; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 void Notification::requestPermission(ScriptExecutionContext* context, PassRefPtr
<NotificationPermissionCallback> callback) | 288 void Notification::requestPermission(ScriptExecutionContext* context, PassRefPtr
<NotificationPermissionCallback> callback) |
290 { | 289 { |
291 ASSERT(toDocument(context)->page()); | 290 ASSERT(toDocument(context)->page()); |
292 NotificationController::from(toDocument(context)->page())->client()->request
Permission(context, callback); | 291 NotificationController::from(toDocument(context)->page())->client()->request
Permission(context, callback); |
293 } | 292 } |
294 #endif | 293 #endif |
295 | 294 |
296 } // namespace WebCore | 295 } // namespace WebCore |
297 | 296 |
298 #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) | 297 #endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) |
OLD | NEW |