1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 et sw=2 tw=80: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Indexed Database.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2010
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Ben Turner <bent.mozilla@gmail.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef mozilla_dom_indexeddb_idbevents_h__
41 : #define mozilla_dom_indexeddb_idbevents_h__
42 :
43 : #include "mozilla/dom/indexedDB/IndexedDatabase.h"
44 :
45 : #include "nsIIDBVersionChangeEvent.h"
46 : #include "nsIRunnable.h"
47 :
48 : #include "nsDOMEvent.h"
49 :
50 : #include "mozilla/dom/indexedDB/IDBObjectStore.h"
51 :
52 : #define SUCCESS_EVT_STR "success"
53 : #define ERROR_EVT_STR "error"
54 : #define COMPLETE_EVT_STR "complete"
55 : #define ABORT_EVT_STR "abort"
56 : #define VERSIONCHANGE_EVT_STR "versionchange"
57 : #define BLOCKED_EVT_STR "blocked"
58 : #define UPGRADENEEDED_EVT_STR "upgradeneeded"
59 :
60 : BEGIN_INDEXEDDB_NAMESPACE
61 :
62 : enum Bubbles {
63 : eDoesNotBubble,
64 : eDoesBubble
65 : };
66 :
67 : enum Cancelable {
68 : eNotCancelable,
69 : eCancelable
70 : };
71 :
72 : already_AddRefed<nsDOMEvent>
73 : CreateGenericEvent(const nsAString& aType,
74 : Bubbles aBubbles,
75 : Cancelable aCancelable);
76 :
77 : class IDBVersionChangeEvent : public nsDOMEvent,
78 : public nsIIDBVersionChangeEvent
79 : {
80 : public:
81 : NS_DECL_ISUPPORTS_INHERITED
82 467 : NS_FORWARD_TO_NSDOMEVENT
83 : NS_DECL_NSIIDBVERSIONCHANGEEVENT
84 :
85 : inline static already_AddRefed<nsDOMEvent>
86 4 : Create(PRInt64 aOldVersion,
87 : PRInt64 aNewVersion)
88 : {
89 4 : return CreateInternal(NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR),
90 4 : aOldVersion, aNewVersion);
91 : }
92 :
93 : inline static already_AddRefed<nsDOMEvent>
94 1 : CreateBlocked(PRUint64 aOldVersion,
95 : PRUint64 aNewVersion)
96 : {
97 1 : return CreateInternal(NS_LITERAL_STRING(BLOCKED_EVT_STR),
98 1 : aOldVersion, aNewVersion);
99 : }
100 :
101 : inline static already_AddRefed<nsDOMEvent>
102 71 : CreateUpgradeNeeded(PRUint64 aOldVersion,
103 : PRUint64 aNewVersion)
104 : {
105 71 : return CreateInternal(NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR),
106 71 : aOldVersion, aNewVersion);
107 : }
108 :
109 : inline static already_AddRefed<nsIRunnable>
110 : CreateRunnable(PRUint64 aOldVersion,
111 : PRUint64 aNewVersion,
112 : nsIDOMEventTarget* aTarget)
113 : {
114 : return CreateRunnableInternal(NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR),
115 : aOldVersion, aNewVersion, aTarget);
116 : }
117 :
118 : static already_AddRefed<nsIRunnable>
119 : CreateBlockedRunnable(PRUint64 aOldVersion,
120 : PRUint64 aNewVersion,
121 : nsIDOMEventTarget* aTarget)
122 : {
123 : return CreateRunnableInternal(NS_LITERAL_STRING(BLOCKED_EVT_STR),
124 : aOldVersion, aNewVersion, aTarget);
125 : }
126 :
127 : protected:
128 76 : IDBVersionChangeEvent() : nsDOMEvent(nsnull, nsnull) { }
129 304 : virtual ~IDBVersionChangeEvent() { }
130 :
131 : static already_AddRefed<nsDOMEvent>
132 : CreateInternal(const nsAString& aType,
133 : PRUint64 aOldVersion,
134 : PRUint64 aNewVersion);
135 :
136 : static already_AddRefed<nsIRunnable>
137 : CreateRunnableInternal(const nsAString& aType,
138 : PRUint64 aOldVersion,
139 : PRUint64 aNewVersion,
140 : nsIDOMEventTarget* aTarget);
141 :
142 : PRUint64 mOldVersion;
143 : PRUint64 mNewVersion;
144 : };
145 :
146 : END_INDEXEDDB_NAMESPACE
147 :
148 : #endif // mozilla_dom_indexeddb_idbevents_h__
|