dom/icc/src/IccListener.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial