Sat, 03 Jan 2015 20:18:00 +0100
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 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "ipc/TelephonyIPCProvider.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/dom/ContentChild.h" |
michael@0 | 9 | #include "mozilla/dom/telephony/TelephonyChild.h" |
michael@0 | 10 | #include "mozilla/Preferences.h" |
michael@0 | 11 | |
michael@0 | 12 | USING_TELEPHONY_NAMESPACE |
michael@0 | 13 | using namespace mozilla::dom; |
michael@0 | 14 | |
michael@0 | 15 | namespace { |
michael@0 | 16 | |
michael@0 | 17 | const char* kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces"; |
michael@0 | 18 | #define kPrefDefaultServiceId "dom.telephony.defaultServiceId" |
michael@0 | 19 | const char* kObservedPrefs[] = { |
michael@0 | 20 | kPrefDefaultServiceId, |
michael@0 | 21 | nullptr |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | uint32_t |
michael@0 | 25 | getDefaultServiceId() |
michael@0 | 26 | { |
michael@0 | 27 | int32_t id = mozilla::Preferences::GetInt(kPrefDefaultServiceId, 0); |
michael@0 | 28 | int32_t numRil = mozilla::Preferences::GetInt(kPrefRilNumRadioInterfaces, 1); |
michael@0 | 29 | |
michael@0 | 30 | if (id >= numRil || id < 0) { |
michael@0 | 31 | id = 0; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | return id; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | } // Anonymous namespace |
michael@0 | 38 | |
michael@0 | 39 | NS_IMPL_ISUPPORTS(TelephonyIPCProvider, |
michael@0 | 40 | nsITelephonyProvider, |
michael@0 | 41 | nsITelephonyListener, |
michael@0 | 42 | nsIObserver) |
michael@0 | 43 | |
michael@0 | 44 | TelephonyIPCProvider::TelephonyIPCProvider() |
michael@0 | 45 | { |
michael@0 | 46 | // Deallocated in ContentChild::DeallocPTelephonyChild(). |
michael@0 | 47 | mPTelephonyChild = new TelephonyChild(this); |
michael@0 | 48 | ContentChild::GetSingleton()->SendPTelephonyConstructor(mPTelephonyChild); |
michael@0 | 49 | |
michael@0 | 50 | Preferences::AddStrongObservers(this, kObservedPrefs); |
michael@0 | 51 | mDefaultServiceId = getDefaultServiceId(); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | TelephonyIPCProvider::~TelephonyIPCProvider() |
michael@0 | 55 | { |
michael@0 | 56 | mPTelephonyChild->Send__delete__(mPTelephonyChild); |
michael@0 | 57 | mPTelephonyChild = nullptr; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | /* |
michael@0 | 61 | * Implementation of nsIObserver. |
michael@0 | 62 | */ |
michael@0 | 63 | |
michael@0 | 64 | NS_IMETHODIMP |
michael@0 | 65 | TelephonyIPCProvider::Observe(nsISupports* aSubject, |
michael@0 | 66 | const char* aTopic, |
michael@0 | 67 | const char16_t* aData) |
michael@0 | 68 | { |
michael@0 | 69 | if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { |
michael@0 | 70 | nsDependentString data(aData); |
michael@0 | 71 | if (data.EqualsLiteral(kPrefDefaultServiceId)) { |
michael@0 | 72 | mDefaultServiceId = getDefaultServiceId(); |
michael@0 | 73 | } |
michael@0 | 74 | return NS_OK; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | MOZ_ASSERT(false, "TelephonyIPCProvider got unexpected topic!"); |
michael@0 | 78 | return NS_ERROR_UNEXPECTED; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | /* |
michael@0 | 82 | * Implementation of nsITelephonyProvider. |
michael@0 | 83 | */ |
michael@0 | 84 | |
michael@0 | 85 | NS_IMETHODIMP |
michael@0 | 86 | TelephonyIPCProvider::GetDefaultServiceId(uint32_t* aServiceId) |
michael@0 | 87 | { |
michael@0 | 88 | *aServiceId = mDefaultServiceId; |
michael@0 | 89 | return NS_OK; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | NS_IMETHODIMP |
michael@0 | 93 | TelephonyIPCProvider::RegisterListener(nsITelephonyListener *aListener) |
michael@0 | 94 | { |
michael@0 | 95 | MOZ_ASSERT(!mListeners.Contains(aListener)); |
michael@0 | 96 | |
michael@0 | 97 | // nsTArray doesn't fail. |
michael@0 | 98 | mListeners.AppendElement(aListener); |
michael@0 | 99 | |
michael@0 | 100 | if (mListeners.Length() == 1) { |
michael@0 | 101 | mPTelephonyChild->SendRegisterListener(); |
michael@0 | 102 | } |
michael@0 | 103 | return NS_OK; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | NS_IMETHODIMP |
michael@0 | 107 | TelephonyIPCProvider::UnregisterListener(nsITelephonyListener *aListener) |
michael@0 | 108 | { |
michael@0 | 109 | MOZ_ASSERT(mListeners.Contains(aListener)); |
michael@0 | 110 | |
michael@0 | 111 | // We always have the element here, so it can't fail. |
michael@0 | 112 | mListeners.RemoveElement(aListener); |
michael@0 | 113 | |
michael@0 | 114 | if (!mListeners.Length()) { |
michael@0 | 115 | mPTelephonyChild->SendUnregisterListener(); |
michael@0 | 116 | } |
michael@0 | 117 | return NS_OK; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | nsresult |
michael@0 | 121 | TelephonyIPCProvider::SendRequest(nsITelephonyListener *aListener, |
michael@0 | 122 | nsITelephonyCallback *aCallback, |
michael@0 | 123 | const IPCTelephonyRequest& aRequest) |
michael@0 | 124 | { |
michael@0 | 125 | // Life time of newly allocated TelephonyRequestChild instance is managed by |
michael@0 | 126 | // IPDL itself. |
michael@0 | 127 | TelephonyRequestChild* actor = new TelephonyRequestChild(aListener, aCallback); |
michael@0 | 128 | mPTelephonyChild->SendPTelephonyRequestConstructor(actor, aRequest); |
michael@0 | 129 | return NS_OK; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | NS_IMETHODIMP |
michael@0 | 133 | TelephonyIPCProvider::EnumerateCalls(nsITelephonyListener *aListener) |
michael@0 | 134 | { |
michael@0 | 135 | return SendRequest(aListener, nullptr, EnumerateCallsRequest()); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | NS_IMETHODIMP |
michael@0 | 139 | TelephonyIPCProvider::Dial(uint32_t aClientId, const nsAString& aNumber, |
michael@0 | 140 | bool aIsEmergency, nsITelephonyCallback *aCallback) |
michael@0 | 141 | { |
michael@0 | 142 | return SendRequest(nullptr, aCallback, |
michael@0 | 143 | DialRequest(aClientId, nsString(aNumber), aIsEmergency)); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | NS_IMETHODIMP |
michael@0 | 147 | TelephonyIPCProvider::HangUp(uint32_t aClientId, uint32_t aCallIndex) |
michael@0 | 148 | { |
michael@0 | 149 | mPTelephonyChild->SendHangUpCall(aClientId, aCallIndex); |
michael@0 | 150 | return NS_OK; |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | NS_IMETHODIMP |
michael@0 | 154 | TelephonyIPCProvider::AnswerCall(uint32_t aClientId, uint32_t aCallIndex) |
michael@0 | 155 | { |
michael@0 | 156 | mPTelephonyChild->SendAnswerCall(aClientId, aCallIndex); |
michael@0 | 157 | return NS_OK; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | NS_IMETHODIMP |
michael@0 | 161 | TelephonyIPCProvider::RejectCall(uint32_t aClientId, uint32_t aCallIndex) |
michael@0 | 162 | { |
michael@0 | 163 | mPTelephonyChild->SendRejectCall(aClientId, aCallIndex); |
michael@0 | 164 | return NS_OK; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | NS_IMETHODIMP |
michael@0 | 168 | TelephonyIPCProvider::HoldCall(uint32_t aClientId, uint32_t aCallIndex) |
michael@0 | 169 | { |
michael@0 | 170 | mPTelephonyChild->SendHoldCall(aClientId, aCallIndex); |
michael@0 | 171 | return NS_OK; |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | NS_IMETHODIMP |
michael@0 | 175 | TelephonyIPCProvider::ResumeCall(uint32_t aClientId, uint32_t aCallIndex) |
michael@0 | 176 | { |
michael@0 | 177 | mPTelephonyChild->SendResumeCall(aClientId, aCallIndex); |
michael@0 | 178 | return NS_OK; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | NS_IMETHODIMP |
michael@0 | 182 | TelephonyIPCProvider::ConferenceCall(uint32_t aClientId) |
michael@0 | 183 | { |
michael@0 | 184 | mPTelephonyChild->SendConferenceCall(aClientId); |
michael@0 | 185 | return NS_OK; |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | NS_IMETHODIMP |
michael@0 | 189 | TelephonyIPCProvider::SeparateCall(uint32_t aClientId, uint32_t aCallIndex) |
michael@0 | 190 | { |
michael@0 | 191 | mPTelephonyChild->SendSeparateCall(aClientId, aCallIndex); |
michael@0 | 192 | return NS_OK; |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | NS_IMETHODIMP |
michael@0 | 196 | TelephonyIPCProvider::HoldConference(uint32_t aClientId) |
michael@0 | 197 | { |
michael@0 | 198 | mPTelephonyChild->SendHoldConference(aClientId); |
michael@0 | 199 | return NS_OK; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | NS_IMETHODIMP |
michael@0 | 203 | TelephonyIPCProvider::ResumeConference(uint32_t aClientId) |
michael@0 | 204 | { |
michael@0 | 205 | mPTelephonyChild->SendResumeConference(aClientId); |
michael@0 | 206 | return NS_OK; |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | NS_IMETHODIMP |
michael@0 | 210 | TelephonyIPCProvider::StartTone(uint32_t aClientId, const nsAString& aDtmfChar) |
michael@0 | 211 | { |
michael@0 | 212 | mPTelephonyChild->SendStartTone(aClientId, nsString(aDtmfChar)); |
michael@0 | 213 | return NS_OK; |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | NS_IMETHODIMP |
michael@0 | 217 | TelephonyIPCProvider::StopTone(uint32_t aClientId) |
michael@0 | 218 | { |
michael@0 | 219 | mPTelephonyChild->SendStopTone(aClientId); |
michael@0 | 220 | return NS_OK; |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | NS_IMETHODIMP |
michael@0 | 224 | TelephonyIPCProvider::GetMicrophoneMuted(bool* aMuted) |
michael@0 | 225 | { |
michael@0 | 226 | mPTelephonyChild->SendGetMicrophoneMuted(aMuted); |
michael@0 | 227 | return NS_OK; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | NS_IMETHODIMP |
michael@0 | 231 | TelephonyIPCProvider::SetMicrophoneMuted(bool aMuted) |
michael@0 | 232 | { |
michael@0 | 233 | mPTelephonyChild->SendSetMicrophoneMuted(aMuted); |
michael@0 | 234 | return NS_OK; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | NS_IMETHODIMP |
michael@0 | 238 | TelephonyIPCProvider::GetSpeakerEnabled(bool* aEnabled) |
michael@0 | 239 | { |
michael@0 | 240 | mPTelephonyChild->SendGetSpeakerEnabled(aEnabled); |
michael@0 | 241 | return NS_OK; |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | NS_IMETHODIMP |
michael@0 | 245 | TelephonyIPCProvider::SetSpeakerEnabled(bool aEnabled) |
michael@0 | 246 | { |
michael@0 | 247 | mPTelephonyChild->SendSetSpeakerEnabled(aEnabled); |
michael@0 | 248 | return NS_OK; |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | // nsITelephonyListener |
michael@0 | 252 | |
michael@0 | 253 | NS_IMETHODIMP |
michael@0 | 254 | TelephonyIPCProvider::CallStateChanged(uint32_t aClientId, |
michael@0 | 255 | uint32_t aCallIndex, |
michael@0 | 256 | uint16_t aCallState, |
michael@0 | 257 | const nsAString& aNumber, |
michael@0 | 258 | bool aIsActive, |
michael@0 | 259 | bool aIsOutgoing, |
michael@0 | 260 | bool aIsEmergency, |
michael@0 | 261 | bool aIsConference, |
michael@0 | 262 | bool aIsSwitchable, |
michael@0 | 263 | bool aIsMergeable) |
michael@0 | 264 | { |
michael@0 | 265 | for (uint32_t i = 0; i < mListeners.Length(); i++) { |
michael@0 | 266 | mListeners[i]->CallStateChanged(aClientId, aCallIndex, aCallState, aNumber, |
michael@0 | 267 | aIsActive, aIsOutgoing, aIsEmergency, |
michael@0 | 268 | aIsConference, aIsSwitchable, aIsMergeable); |
michael@0 | 269 | } |
michael@0 | 270 | return NS_OK; |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | NS_IMETHODIMP |
michael@0 | 274 | TelephonyIPCProvider::ConferenceCallStateChanged(uint16_t aCallState) |
michael@0 | 275 | { |
michael@0 | 276 | for (uint32_t i = 0; i < mListeners.Length(); i++) { |
michael@0 | 277 | mListeners[i]->ConferenceCallStateChanged(aCallState); |
michael@0 | 278 | } |
michael@0 | 279 | return NS_OK; |
michael@0 | 280 | } |
michael@0 | 281 | |
michael@0 | 282 | NS_IMETHODIMP |
michael@0 | 283 | TelephonyIPCProvider::EnumerateCallStateComplete() |
michael@0 | 284 | { |
michael@0 | 285 | MOZ_CRASH("Not a EnumerateCalls request!"); |
michael@0 | 286 | } |
michael@0 | 287 | |
michael@0 | 288 | NS_IMETHODIMP |
michael@0 | 289 | TelephonyIPCProvider::EnumerateCallState(uint32_t aClientId, |
michael@0 | 290 | uint32_t aCallIndex, |
michael@0 | 291 | uint16_t aCallState, |
michael@0 | 292 | const nsAString& aNumber, |
michael@0 | 293 | bool aIsActive, |
michael@0 | 294 | bool aIsOutgoing, |
michael@0 | 295 | bool aIsEmergency, |
michael@0 | 296 | bool aIsConference, |
michael@0 | 297 | bool aIsSwitchable, |
michael@0 | 298 | bool aIsMergeable) |
michael@0 | 299 | { |
michael@0 | 300 | MOZ_CRASH("Not a EnumerateCalls request!"); |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | NS_IMETHODIMP |
michael@0 | 304 | TelephonyIPCProvider::NotifyCdmaCallWaiting(uint32_t aClientId, |
michael@0 | 305 | const nsAString& aNumber) |
michael@0 | 306 | { |
michael@0 | 307 | for (uint32_t i = 0; i < mListeners.Length(); i++) { |
michael@0 | 308 | mListeners[i]->NotifyCdmaCallWaiting(aClientId, aNumber); |
michael@0 | 309 | } |
michael@0 | 310 | return NS_OK; |
michael@0 | 311 | } |
michael@0 | 312 | |
michael@0 | 313 | NS_IMETHODIMP |
michael@0 | 314 | TelephonyIPCProvider::NotifyConferenceError(const nsAString& aName, |
michael@0 | 315 | const nsAString& aMessage) |
michael@0 | 316 | { |
michael@0 | 317 | for (uint32_t i = 0; i < mListeners.Length(); i++) { |
michael@0 | 318 | mListeners[i]->NotifyConferenceError(aName, aMessage); |
michael@0 | 319 | } |
michael@0 | 320 | return NS_OK; |
michael@0 | 321 | } |
michael@0 | 322 | |
michael@0 | 323 | NS_IMETHODIMP |
michael@0 | 324 | TelephonyIPCProvider::NotifyError(uint32_t aClientId, int32_t aCallIndex, |
michael@0 | 325 | const nsAString& aError) |
michael@0 | 326 | { |
michael@0 | 327 | for (uint32_t i = 0; i < mListeners.Length(); i++) { |
michael@0 | 328 | mListeners[i]->NotifyError(aClientId, aCallIndex, aError); |
michael@0 | 329 | } |
michael@0 | 330 | return NS_OK; |
michael@0 | 331 | } |
michael@0 | 332 | |
michael@0 | 333 | NS_IMETHODIMP |
michael@0 | 334 | TelephonyIPCProvider::SupplementaryServiceNotification(uint32_t aClientId, |
michael@0 | 335 | int32_t aCallIndex, |
michael@0 | 336 | uint16_t aNotification) |
michael@0 | 337 | { |
michael@0 | 338 | for (uint32_t i = 0; i < mListeners.Length(); i++) { |
michael@0 | 339 | mListeners[i]->SupplementaryServiceNotification(aClientId, aCallIndex, |
michael@0 | 340 | aNotification); |
michael@0 | 341 | } |
michael@0 | 342 | return NS_OK; |
michael@0 | 343 | } |