1 /* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 */ 30 31 #ifndef WebNotification_h 32 #define WebNotification_h 33 34 #include "../platform/WebCommon.h" 35 #include "WebTextDirection.h" 36 37 #if BLINK_IMPLEMENTATION 38 namespace WebCore { class NotificationBase; } 39 namespace WTF { template <typename T> class PassRefPtr; } 40 #endif 41 42 namespace WTF { 43 class AtomicString; 44 } 45 46 namespace blink { 47 48 class WebNotificationPrivate; 49 class WebURL; 50 class WebString; 51 52 // Represents access to a desktop notification. 53 class WebNotification { 54 public: WebNotification()55 WebNotification() : m_private(0) { } WebNotification(const WebNotification & other)56 WebNotification(const WebNotification& other) : m_private(0) { assign(other); } 57 ~WebNotification()58 ~WebNotification() { reset(); } 59 60 BLINK_EXPORT void reset(); 61 BLINK_EXPORT void assign(const WebNotification&); 62 63 WebNotification& operator=(const WebNotification& other) 64 { 65 assign(other); 66 return *this; 67 } 68 69 // Operators required to put WebNotification in an ordered map. equals(const WebNotification & other)70 bool equals(const WebNotification& other) const { return m_private == other.m_private; } 71 BLINK_EXPORT bool lessThan(const WebNotification& other) const; 72 73 // DEPRECATED: Always returns false. 74 BLINK_EXPORT bool isHTML() const; 75 76 // DEPRECATED: Always returns an invalid URL. 77 BLINK_EXPORT WebURL url() const; 78 79 BLINK_EXPORT WebURL iconURL() const; 80 BLINK_EXPORT WebString title() const; 81 BLINK_EXPORT WebString body() const; 82 BLINK_EXPORT WebTextDirection direction() const; 83 84 BLINK_EXPORT WebString replaceId() const; 85 86 // Called to indicate the notification has been displayed. 87 BLINK_EXPORT void dispatchDisplayEvent(); 88 89 // Called to indicate an error has occurred with this notification. 90 BLINK_EXPORT void dispatchErrorEvent(const WebString& errorMessage); 91 92 // Called to indicate the notification has been closed. If it was 93 // closed by the user (as opposed to automatically by the system), 94 // the byUser parameter will be true. 95 BLINK_EXPORT void dispatchCloseEvent(bool byUser); 96 97 // Called to indicate the notification was clicked on. 98 BLINK_EXPORT void dispatchClickEvent(); 99 100 #if BLINK_IMPLEMENTATION 101 WebNotification(const WTF::PassRefPtr<WebCore::NotificationBase>&); 102 WebNotification& operator=(const WTF::PassRefPtr<WebCore::NotificationBase>&); 103 operator WTF::PassRefPtr<WebCore::NotificationBase>() const; 104 #endif 105 106 private: 107 void assign(WebNotificationPrivate*); 108 WebNotificationPrivate* m_private; 109 }; 110 111 inline bool operator==(const WebNotification& a, const WebNotification& b) 112 { 113 return a.equals(b); 114 } 115 116 inline bool operator!=(const WebNotification& a, const WebNotification& b) 117 { 118 return !a.equals(b); 119 } 120 121 inline bool operator<(const WebNotification& a, const WebNotification& b) 122 { 123 return a.lessThan(b); 124 } 125 126 } // namespace blink 127 128 #endif 129