LCOV - code coverage report
Current view: directory - dom/indexedDB - IDBEvents.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 43 32 74.4 %
Date: 2012-06-02 Functions: 12 7 58.3 %

       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                 : #include "IDBEvents.h"
      41                 : 
      42                 : #include "nsIIDBDatabaseException.h"
      43                 : #include "nsIPrivateDOMEvent.h"
      44                 : 
      45                 : #include "nsContentUtils.h"
      46                 : #include "nsDOMClassInfoID.h"
      47                 : #include "nsDOMException.h"
      48                 : #include "nsJSON.h"
      49                 : #include "nsThreadUtils.h"
      50                 : 
      51                 : #include "IDBRequest.h"
      52                 : #include "IDBTransaction.h"
      53                 : 
      54                 : USING_INDEXEDDB_NAMESPACE
      55                 : 
      56                 : namespace {
      57                 : 
      58                 : class EventFiringRunnable : public nsRunnable
      59               0 : {
      60                 : public:
      61               0 :   EventFiringRunnable(nsIDOMEventTarget* aTarget,
      62                 :                       nsIDOMEvent* aEvent)
      63               0 :   : mTarget(aTarget), mEvent(aEvent)
      64               0 :   { }
      65                 : 
      66               0 :   NS_IMETHOD Run() {
      67                 :     bool dummy;
      68               0 :     return mTarget->DispatchEvent(mEvent, &dummy);
      69                 :   }
      70                 : 
      71                 : private:
      72                 :   nsCOMPtr<nsIDOMEventTarget> mTarget;
      73                 :   nsCOMPtr<nsIDOMEvent> mEvent;
      74                 : };
      75                 : 
      76                 : } // anonymous namespace
      77                 : 
      78                 : already_AddRefed<nsDOMEvent>
      79            4782 : mozilla::dom::indexedDB::CreateGenericEvent(const nsAString& aType,
      80                 :                                             Bubbles aBubbles,
      81                 :                                             Cancelable aCancelable)
      82                 : {
      83            9564 :   nsRefPtr<nsDOMEvent> event(new nsDOMEvent(nsnull, nsnull));
      84            4782 :   nsresult rv = event->InitEvent(aType,
      85                 :                                  aBubbles == eDoesBubble ? true : false,
      86            4782 :                                  aCancelable == eCancelable ? true : false);
      87            4782 :   NS_ENSURE_SUCCESS(rv, nsnull);
      88                 : 
      89            4782 :   rv = event->SetTrusted(true);
      90            4782 :   NS_ENSURE_SUCCESS(rv, nsnull);
      91                 : 
      92            4782 :   return event.forget();
      93                 : }
      94                 : 
      95                 : // static
      96                 : already_AddRefed<nsDOMEvent>
      97              76 : IDBVersionChangeEvent::CreateInternal(const nsAString& aType,
      98                 :                                       PRUint64 aOldVersion,
      99                 :                                       PRUint64 aNewVersion)
     100                 : {
     101             152 :   nsRefPtr<IDBVersionChangeEvent> event(new IDBVersionChangeEvent());
     102                 : 
     103              76 :   nsresult rv = event->InitEvent(aType, false, false);
     104              76 :   NS_ENSURE_SUCCESS(rv, nsnull);
     105                 : 
     106              76 :   rv = event->SetTrusted(true);
     107              76 :   NS_ENSURE_SUCCESS(rv, nsnull);
     108                 : 
     109              76 :   event->mOldVersion = aOldVersion;
     110              76 :   event->mNewVersion = aNewVersion;
     111                 : 
     112                 :   nsDOMEvent* result;
     113              76 :   event.forget(&result);
     114              76 :   return result;
     115                 : }
     116                 : 
     117                 : // static
     118                 : already_AddRefed<nsIRunnable>
     119               0 : IDBVersionChangeEvent::CreateRunnableInternal(const nsAString& aType,
     120                 :                                               PRUint64 aOldVersion,
     121                 :                                               PRUint64 aNewVersion,
     122                 :                                               nsIDOMEventTarget* aTarget)
     123                 : {
     124                 :   nsRefPtr<nsDOMEvent> event =
     125               0 :     CreateInternal(aType, aOldVersion, aNewVersion);
     126               0 :   NS_ENSURE_TRUE(event, nsnull);
     127                 : 
     128               0 :   nsCOMPtr<nsIRunnable> runnable(new EventFiringRunnable(aTarget, event));
     129               0 :   return runnable.forget();
     130                 : }
     131                 : 
     132             845 : NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent, nsDOMEvent)
     133             845 : NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent, nsDOMEvent)
     134                 : 
     135            1989 : NS_INTERFACE_MAP_BEGIN(IDBVersionChangeEvent)
     136            1989 :   NS_INTERFACE_MAP_ENTRY(nsIIDBVersionChangeEvent)
     137            1979 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBVersionChangeEvent)
     138            1910 : NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
     139                 : 
     140                 : DOMCI_DATA(IDBVersionChangeEvent, IDBVersionChangeEvent)
     141                 : 
     142                 : NS_IMETHODIMP
     143               5 : IDBVersionChangeEvent::GetOldVersion(PRUint64* aOldVersion)
     144                 : {
     145               5 :   NS_ENSURE_ARG_POINTER(aOldVersion);
     146               5 :   *aOldVersion = mOldVersion;
     147               5 :   return NS_OK;
     148                 : }
     149                 : 
     150                 : NS_IMETHODIMP
     151               5 : IDBVersionChangeEvent::GetNewVersion(PRUint64* aNewVersion)
     152                 : {
     153               5 :   NS_ENSURE_ARG_POINTER(aNewVersion);
     154               5 :   *aNewVersion = mNewVersion;
     155               5 :   return NS_OK;
     156                 : }

Generated by: LCOV version 1.7