OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/notifications/WebKitNotification.h" | 32 #include "modules/notifications/WebKitNotification.h" |
33 | 33 |
34 #if ENABLE(LEGACY_NOTIFICATIONS) | 34 #if ENABLE(LEGACY_NOTIFICATIONS) |
35 | 35 |
36 #include "bindings/v8/ExceptionMessages.h" | |
37 #include "bindings/v8/ExceptionState.h" | 36 #include "bindings/v8/ExceptionState.h" |
38 #include "bindings/v8/ScriptWrappable.h" | 37 #include "bindings/v8/ScriptWrappable.h" |
39 #include "core/dom/ExecutionContext.h" | 38 #include "core/dom/ExecutionContext.h" |
40 #include "modules/notifications/NotificationCenter.h" | 39 #include "modules/notifications/NotificationCenter.h" |
41 #include "modules/notifications/NotificationClient.h" | 40 #include "modules/notifications/NotificationClient.h" |
42 | 41 |
43 namespace WebCore { | 42 namespace WebCore { |
44 | 43 |
45 PassRefPtr<WebKitNotification> WebKitNotification::create(const String& title, c
onst String& body, const String& iconUrl, ExecutionContext* context, ExceptionSt
ate& es, PassRefPtr<NotificationCenter> provider) | 44 PassRefPtr<WebKitNotification> WebKitNotification::create(const String& title, c
onst String& body, const String& iconUrl, ExecutionContext* context, ExceptionSt
ate& es, PassRefPtr<NotificationCenter> provider) |
46 { | 45 { |
47 RefPtr<WebKitNotification> notification(adoptRef(new WebKitNotification(titl
e, body, iconUrl, context, es, provider))); | 46 RefPtr<WebKitNotification> notification(adoptRef(new WebKitNotification(titl
e, body, iconUrl, context, es, provider))); |
48 notification->suspendIfNeeded(); | 47 notification->suspendIfNeeded(); |
49 | 48 |
50 return notification.release(); | 49 return notification.release(); |
51 } | 50 } |
52 | 51 |
53 WebKitNotification::WebKitNotification(const String& title, const String& body,
const String& iconUrl, ExecutionContext* context, ExceptionState& es, PassRefPtr
<NotificationCenter> provider) | 52 WebKitNotification::WebKitNotification(const String& title, const String& body,
const String& iconUrl, ExecutionContext* context, ExceptionState& es, PassRefPtr
<NotificationCenter> provider) |
54 : NotificationBase(title, context, provider->client()) | 53 : NotificationBase(title, context, provider->client()) |
55 { | 54 { |
56 ScriptWrappable::init(this); | 55 ScriptWrappable::init(this); |
57 | 56 |
58 if (provider->checkPermission() != NotificationClient::PermissionAllowed) { | 57 if (provider->checkPermission() != NotificationClient::PermissionAllowed) { |
59 es.throwSecurityError(ExceptionMessages::failedToExecute("createNotifica
tion", "NotificationCenter", "Notification permission has not been granted.")); | 58 es.throwSecurityError("Notification permission has not been granted."); |
60 return; | 59 return; |
61 } | 60 } |
62 | 61 |
63 KURL icon = iconUrl.isEmpty() ? KURL() : executionContext()->completeURL(ico
nUrl); | 62 KURL icon = iconUrl.isEmpty() ? KURL() : executionContext()->completeURL(ico
nUrl); |
64 if (!icon.isEmpty() && !icon.isValid()) { | 63 if (!icon.isEmpty() && !icon.isValid()) { |
65 es.throwDOMException(SyntaxError, ExceptionMessages::failedToExecute("cr
eateNotification", "NotificationCenter", "'" + iconUrl + "' is not a valid icon
URL.")); | 64 es.throwDOMException(SyntaxError, "'" + iconUrl + "' is not a valid icon
URL."); |
66 return; | 65 return; |
67 } | 66 } |
68 | 67 |
69 setBody(body); | 68 setBody(body); |
70 setIconUrl(icon); | 69 setIconUrl(icon); |
71 } | 70 } |
72 | 71 |
73 WebKitNotification::~WebKitNotification() | 72 WebKitNotification::~WebKitNotification() |
74 { | 73 { |
75 } | 74 } |
76 | 75 |
77 const AtomicString& WebKitNotification::interfaceName() const | 76 const AtomicString& WebKitNotification::interfaceName() const |
78 { | 77 { |
79 return EventTargetNames::WebKitNotification; | 78 return EventTargetNames::WebKitNotification; |
80 } | 79 } |
81 | 80 |
82 } // namespace WebCore | 81 } // namespace WebCore |
83 | 82 |
84 #endif // ENABLE(LEGACY_NOTIFICATIONS) | 83 #endif // ENABLE(LEGACY_NOTIFICATIONS) |
OLD | NEW |