dom/icc/src/IccListener.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "IccListener.h"
     7 #include "Icc.h"
     8 #include "IccManager.h"
     9 #include "nsIDOMClassInfo.h"
    10 #include "nsIDOMIccInfo.h"
    11 #include "nsRadioInterfaceLayer.h"
    13 using namespace mozilla::dom;
    15 NS_IMPL_ISUPPORTS(IccListener, nsIIccListener)
    17 IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId)
    18   : mClientId(aClientId)
    19   , mIccManager(aIccManager)
    20 {
    21   MOZ_ASSERT(mIccManager);
    23   mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
    25   if (!mProvider) {
    26     NS_WARNING("Could not acquire nsIIccProvider!");
    27     return;
    28   }
    30   nsCOMPtr<nsIDOMMozIccInfo> iccInfo;
    31   mProvider->GetIccInfo(mClientId, getter_AddRefs(iccInfo));
    32   if (iccInfo) {
    33     nsString iccId;
    34     iccInfo->GetIccid(iccId);
    35     if (!iccId.IsEmpty()) {
    36       mIcc = new Icc(mIccManager->GetOwner(), mClientId, iccId);
    37     }
    38   }
    40   DebugOnly<nsresult> rv = mProvider->RegisterIccMsg(mClientId, this);
    41   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
    42                    "Failed registering icc messages with provider");
    43 }
    45 IccListener::~IccListener()
    46 {
    47   Shutdown();
    48 }
    50 void
    51 IccListener::Shutdown()
    52 {
    53   if (mProvider) {
    54     mProvider->UnregisterIccMsg(mClientId, this);
    55     mProvider = nullptr;
    56   }
    58   if (mIcc) {
    59     mIcc->Shutdown();
    60     mIcc = nullptr;
    61   }
    63   mIccManager = nullptr;
    64 }
    66 // nsIIccListener
    68 NS_IMETHODIMP
    69 IccListener::NotifyStkCommand(const nsAString& aMessage)
    70 {
    71   if (!mIcc) {
    72     return NS_OK;
    73   }
    75   return mIcc->NotifyStkEvent(NS_LITERAL_STRING("stkcommand"), aMessage);
    76 }
    78 NS_IMETHODIMP
    79 IccListener::NotifyStkSessionEnd()
    80 {
    81   if (!mIcc) {
    82     return NS_OK;
    83   }
    85   return mIcc->NotifyEvent(NS_LITERAL_STRING("stksessionend"));
    86 }
    88 NS_IMETHODIMP
    89 IccListener::NotifyCardStateChanged()
    90 {
    91   if (!mIcc) {
    92     return NS_OK;
    93   }
    95   return mIcc->NotifyEvent(NS_LITERAL_STRING("cardstatechange"));
    96 }
    98 NS_IMETHODIMP
    99 IccListener::NotifyIccInfoChanged()
   100 {
   101   nsCOMPtr<nsIDOMMozIccInfo> iccInfo;
   102   mProvider->GetIccInfo(mClientId, getter_AddRefs(iccInfo));
   104   // Create/delete icc object based on current iccInfo.
   105   // 1. If the mIcc is nullptr and iccInfo has valid data, create icc object and
   106   //    notify mIccManager a new icc is added.
   107   // 2. If the mIcc is not nullptr and iccInfo becomes to null, delete existed
   108   //    icc object and notify mIccManager the icc is removed.
   109   if (!mIcc) {
   110     if (iccInfo) {
   111       nsString iccId;
   112       iccInfo->GetIccid(iccId);
   113       if (!iccId.IsEmpty()) {
   114         mIcc = new Icc(mIccManager->GetOwner(), mClientId, iccId);
   115         mIccManager->NotifyIccAdd(iccId);
   116         mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
   117       }
   118     }
   119   } else {
   120     mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
   121     if (!iccInfo) {
   122       nsString iccId = mIcc->GetIccId();
   123       mIcc->Shutdown();
   124       mIcc = nullptr;
   125       mIccManager->NotifyIccRemove(iccId);
   126     }
   127   }
   129   return NS_OK;
   130 }

mercurial