dom/mobileconnection/src/MobileConnection.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/mobileconnection/src/MobileConnection.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,735 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "mozilla/dom/MobileConnection.h"
     1.9 +
    1.10 +#include "GeneratedEvents.h"
    1.11 +#include "mozilla/dom/CFStateChangeEvent.h"
    1.12 +#include "mozilla/dom/DataErrorEvent.h"
    1.13 +#include "mozilla/dom/MozEmergencyCbModeEvent.h"
    1.14 +#include "mozilla/dom/MozOtaStatusEvent.h"
    1.15 +#include "mozilla/dom/USSDReceivedEvent.h"
    1.16 +#include "mozilla/Preferences.h"
    1.17 +#include "nsIDOMClassInfo.h"
    1.18 +#include "nsIDOMDOMRequest.h"
    1.19 +#include "nsIPermissionManager.h"
    1.20 +#include "nsIVariant.h"
    1.21 +
    1.22 +#include "nsJSUtils.h"
    1.23 +#include "nsJSON.h"
    1.24 +#include "mozilla/Services.h"
    1.25 +
    1.26 +#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
    1.27 +
    1.28 +using namespace mozilla::dom;
    1.29 +
    1.30 +class MobileConnection::Listener MOZ_FINAL : public nsIMobileConnectionListener
    1.31 +{
    1.32 +  MobileConnection* mMobileConnection;
    1.33 +
    1.34 +public:
    1.35 +  NS_DECL_ISUPPORTS
    1.36 +  NS_FORWARD_SAFE_NSIMOBILECONNECTIONLISTENER(mMobileConnection)
    1.37 +
    1.38 +  Listener(MobileConnection* aMobileConnection)
    1.39 +    : mMobileConnection(aMobileConnection)
    1.40 +  {
    1.41 +    MOZ_ASSERT(mMobileConnection);
    1.42 +  }
    1.43 +
    1.44 +  void Disconnect()
    1.45 +  {
    1.46 +    MOZ_ASSERT(mMobileConnection);
    1.47 +    mMobileConnection = nullptr;
    1.48 +  }
    1.49 +};
    1.50 +
    1.51 +NS_IMPL_ISUPPORTS(MobileConnection::Listener, nsIMobileConnectionListener)
    1.52 +
    1.53 +DOMCI_DATA(MozMobileConnection, MobileConnection)
    1.54 +
    1.55 +NS_IMPL_CYCLE_COLLECTION_CLASS(MobileConnection)
    1.56 +
    1.57 +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MobileConnection,
    1.58 +                                                  DOMEventTargetHelper)
    1.59 +  // Don't traverse mListener because it doesn't keep any reference to
    1.60 +  // MobileConnection but a raw pointer instead. Neither does mProvider because
    1.61 +  // it's an xpcom service and is only released at shutting down.
    1.62 +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
    1.63 +
    1.64 +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MobileConnection,
    1.65 +                                                DOMEventTargetHelper)
    1.66 +NS_IMPL_CYCLE_COLLECTION_UNLINK_END
    1.67 +
    1.68 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MobileConnection)
    1.69 +  NS_INTERFACE_MAP_ENTRY(nsIDOMMozMobileConnection)
    1.70 +  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozMobileConnection)
    1.71 +NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
    1.72 +
    1.73 +NS_IMPL_ADDREF_INHERITED(MobileConnection, DOMEventTargetHelper)
    1.74 +NS_IMPL_RELEASE_INHERITED(MobileConnection, DOMEventTargetHelper)
    1.75 +
    1.76 +NS_IMPL_EVENT_HANDLER(MobileConnection, voicechange)
    1.77 +NS_IMPL_EVENT_HANDLER(MobileConnection, datachange)
    1.78 +NS_IMPL_EVENT_HANDLER(MobileConnection, ussdreceived)
    1.79 +NS_IMPL_EVENT_HANDLER(MobileConnection, dataerror)
    1.80 +NS_IMPL_EVENT_HANDLER(MobileConnection, cfstatechange)
    1.81 +NS_IMPL_EVENT_HANDLER(MobileConnection, emergencycbmodechange)
    1.82 +NS_IMPL_EVENT_HANDLER(MobileConnection, otastatuschange)
    1.83 +NS_IMPL_EVENT_HANDLER(MobileConnection, iccchange)
    1.84 +NS_IMPL_EVENT_HANDLER(MobileConnection, radiostatechange)
    1.85 +
    1.86 +MobileConnection::MobileConnection(uint32_t aClientId)
    1.87 +: mClientId(aClientId)
    1.88 +{
    1.89 +  mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
    1.90 +  mWindow = nullptr;
    1.91 +
    1.92 +  // Not being able to acquire the provider isn't fatal since we check
    1.93 +  // for it explicitly below.
    1.94 +  if (!mProvider) {
    1.95 +    NS_WARNING("Could not acquire nsIMobileConnectionProvider!");
    1.96 +    return;
    1.97 +  }
    1.98 +}
    1.99 +
   1.100 +void
   1.101 +MobileConnection::Init(nsPIDOMWindow* aWindow)
   1.102 +{
   1.103 +  BindToOwner(aWindow);
   1.104 +
   1.105 +  mWindow = do_GetWeakReference(aWindow);
   1.106 +  mListener = new Listener(this);
   1.107 +
   1.108 +  if (CheckPermission("mobileconnection")) {
   1.109 +    DebugOnly<nsresult> rv = mProvider->RegisterMobileConnectionMsg(mClientId, mListener);
   1.110 +    NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
   1.111 +                     "Failed registering mobile connection messages with provider");
   1.112 +  }
   1.113 +}
   1.114 +
   1.115 +void
   1.116 +MobileConnection::Shutdown()
   1.117 +{
   1.118 +  if (mProvider && mListener) {
   1.119 +    mListener->Disconnect();
   1.120 +    mProvider->UnregisterMobileConnectionMsg(mClientId, mListener);
   1.121 +    mProvider = nullptr;
   1.122 +    mListener = nullptr;
   1.123 +  }
   1.124 +}
   1.125 +
   1.126 +// nsIDOMMozMobileConnection
   1.127 +
   1.128 +NS_IMETHODIMP
   1.129 +MobileConnection::GetLastKnownNetwork(nsAString& aNetwork)
   1.130 +{
   1.131 +  aNetwork.SetIsVoid(true);
   1.132 +
   1.133 +  if (!CheckPermission("mobilenetwork")) {
   1.134 +    return NS_OK;
   1.135 +  }
   1.136 +
   1.137 +  return mProvider->GetLastKnownNetwork(mClientId, aNetwork);
   1.138 +}
   1.139 +
   1.140 +NS_IMETHODIMP
   1.141 +MobileConnection::GetLastKnownHomeNetwork(nsAString& aNetwork)
   1.142 +{
   1.143 +  aNetwork.SetIsVoid(true);
   1.144 +
   1.145 +  if (!CheckPermission("mobilenetwork")) {
   1.146 +    return NS_OK;
   1.147 +  }
   1.148 +
   1.149 +  return mProvider->GetLastKnownHomeNetwork(mClientId, aNetwork);
   1.150 +}
   1.151 +
   1.152 +// All fields below require the "mobileconnection" permission.
   1.153 +
   1.154 +bool
   1.155 +MobileConnection::CheckPermission(const char* aType)
   1.156 +{
   1.157 +  nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
   1.158 +  NS_ENSURE_TRUE(window, false);
   1.159 +
   1.160 +  nsCOMPtr<nsIPermissionManager> permMgr =
   1.161 +    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
   1.162 +  NS_ENSURE_TRUE(permMgr, false);
   1.163 +
   1.164 +  uint32_t permission = nsIPermissionManager::DENY_ACTION;
   1.165 +  permMgr->TestPermissionFromWindow(window, aType, &permission);
   1.166 +  return permission == nsIPermissionManager::ALLOW_ACTION;
   1.167 +}
   1.168 +
   1.169 +NS_IMETHODIMP
   1.170 +MobileConnection::GetVoice(nsIDOMMozMobileConnectionInfo** aVoice)
   1.171 +{
   1.172 +  *aVoice = nullptr;
   1.173 +
   1.174 +  if (!mProvider || !CheckPermission("mobileconnection")) {
   1.175 +    return NS_OK;
   1.176 +  }
   1.177 +  return mProvider->GetVoiceConnectionInfo(mClientId, aVoice);
   1.178 +}
   1.179 +
   1.180 +NS_IMETHODIMP
   1.181 +MobileConnection::GetData(nsIDOMMozMobileConnectionInfo** aData)
   1.182 +{
   1.183 +  *aData = nullptr;
   1.184 +
   1.185 +  if (!mProvider || !CheckPermission("mobileconnection")) {
   1.186 +    return NS_OK;
   1.187 +  }
   1.188 +  return mProvider->GetDataConnectionInfo(mClientId, aData);
   1.189 +}
   1.190 +
   1.191 +NS_IMETHODIMP
   1.192 +MobileConnection::GetIccId(nsAString& aIccId)
   1.193 +{
   1.194 +  aIccId.SetIsVoid(true);
   1.195 +
   1.196 +  if (!mProvider || !CheckPermission("mobileconnection")) {
   1.197 +     return NS_OK;
   1.198 +  }
   1.199 +  return mProvider->GetIccId(mClientId, aIccId);
   1.200 +}
   1.201 +
   1.202 +NS_IMETHODIMP
   1.203 +MobileConnection::GetNetworkSelectionMode(nsAString& aNetworkSelectionMode)
   1.204 +{
   1.205 +  aNetworkSelectionMode.SetIsVoid(true);
   1.206 +
   1.207 +  if (!mProvider || !CheckPermission("mobileconnection")) {
   1.208 +     return NS_OK;
   1.209 +  }
   1.210 +  return mProvider->GetNetworkSelectionMode(mClientId, aNetworkSelectionMode);
   1.211 +}
   1.212 +
   1.213 +NS_IMETHODIMP
   1.214 +MobileConnection::GetRadioState(nsAString& aRadioState)
   1.215 +{
   1.216 +  aRadioState.SetIsVoid(true);
   1.217 +
   1.218 +  if (!mProvider || !CheckPermission("mobileconnection")) {
   1.219 +     return NS_OK;
   1.220 +  }
   1.221 +  return mProvider->GetRadioState(mClientId, aRadioState);
   1.222 +}
   1.223 +
   1.224 +NS_IMETHODIMP
   1.225 +MobileConnection::GetSupportedNetworkTypes(nsIVariant** aSupportedNetworkTypes)
   1.226 +{
   1.227 +  *aSupportedNetworkTypes = nullptr;
   1.228 +
   1.229 +  if (!mProvider || !CheckPermission("mobileconnection")) {
   1.230 +     return NS_OK;
   1.231 +  }
   1.232 +
   1.233 +  return mProvider->GetSupportedNetworkTypes(mClientId, aSupportedNetworkTypes);
   1.234 +}
   1.235 +
   1.236 +NS_IMETHODIMP
   1.237 +MobileConnection::GetNetworks(nsIDOMDOMRequest** aRequest)
   1.238 +{
   1.239 +  *aRequest = nullptr;
   1.240 +
   1.241 +  if (!CheckPermission("mobileconnection")) {
   1.242 +    return NS_OK;
   1.243 +  }
   1.244 +
   1.245 +  if (!mProvider) {
   1.246 +    return NS_ERROR_FAILURE;
   1.247 +  }
   1.248 +
   1.249 +  return mProvider->GetNetworks(mClientId, GetOwner(), aRequest);
   1.250 +}
   1.251 +
   1.252 +NS_IMETHODIMP
   1.253 +MobileConnection::SelectNetwork(nsIDOMMozMobileNetworkInfo* aNetwork, nsIDOMDOMRequest** aRequest)
   1.254 +{
   1.255 +  *aRequest = nullptr;
   1.256 +
   1.257 +  if (!CheckPermission("mobileconnection")) {
   1.258 +    return NS_OK;
   1.259 +  }
   1.260 +
   1.261 +  if (!mProvider) {
   1.262 +    return NS_ERROR_FAILURE;
   1.263 +  }
   1.264 +
   1.265 +  return mProvider->SelectNetwork(mClientId, GetOwner(), aNetwork, aRequest);
   1.266 +}
   1.267 +
   1.268 +NS_IMETHODIMP
   1.269 +MobileConnection::SelectNetworkAutomatically(nsIDOMDOMRequest** aRequest)
   1.270 +{
   1.271 +  *aRequest = nullptr;
   1.272 +
   1.273 +  if (!CheckPermission("mobileconnection")) {
   1.274 +    return NS_OK;
   1.275 +  }
   1.276 +
   1.277 +  if (!mProvider) {
   1.278 +    return NS_ERROR_FAILURE;
   1.279 +  }
   1.280 +
   1.281 +  return mProvider->SelectNetworkAutomatically(mClientId, GetOwner(), aRequest);
   1.282 +}
   1.283 +
   1.284 +NS_IMETHODIMP
   1.285 +MobileConnection::SetPreferredNetworkType(const nsAString& aType,
   1.286 +                                          nsIDOMDOMRequest** aDomRequest)
   1.287 +{
   1.288 +  *aDomRequest = nullptr;
   1.289 +
   1.290 +  if (!CheckPermission("mobileconnection")) {
   1.291 +    return NS_OK;
   1.292 +  }
   1.293 +
   1.294 +  if (!mProvider) {
   1.295 +    return NS_ERROR_FAILURE;
   1.296 +  }
   1.297 +
   1.298 +  return mProvider->SetPreferredNetworkType(mClientId, GetOwner(), aType, aDomRequest);
   1.299 +}
   1.300 +
   1.301 +NS_IMETHODIMP
   1.302 +MobileConnection::GetPreferredNetworkType(nsIDOMDOMRequest** aDomRequest)
   1.303 +{
   1.304 +  *aDomRequest = nullptr;
   1.305 +
   1.306 +  if (!CheckPermission("mobileconnection")) {
   1.307 +    return NS_OK;
   1.308 +  }
   1.309 +
   1.310 +  if (!mProvider) {
   1.311 +    return NS_ERROR_FAILURE;
   1.312 +  }
   1.313 +
   1.314 +  return mProvider->GetPreferredNetworkType(mClientId, GetOwner(), aDomRequest);
   1.315 +}
   1.316 +
   1.317 +NS_IMETHODIMP
   1.318 +MobileConnection::SetRoamingPreference(const nsAString& aMode, nsIDOMDOMRequest** aDomRequest)
   1.319 +{
   1.320 +  *aDomRequest = nullptr;
   1.321 +
   1.322 +  if (!CheckPermission("mobileconnection")) {
   1.323 +    return NS_OK;
   1.324 +  }
   1.325 +
   1.326 +  if (!mProvider) {
   1.327 +    return NS_ERROR_FAILURE;
   1.328 +  }
   1.329 +
   1.330 +  return mProvider->SetRoamingPreference(mClientId, GetOwner(), aMode, aDomRequest);
   1.331 +}
   1.332 +
   1.333 +NS_IMETHODIMP
   1.334 +MobileConnection::GetRoamingPreference(nsIDOMDOMRequest** aDomRequest)
   1.335 +{
   1.336 +  *aDomRequest = nullptr;
   1.337 +
   1.338 +  if (!CheckPermission("mobileconnection")) {
   1.339 +    return NS_OK;
   1.340 +  }
   1.341 +
   1.342 +  if (!mProvider) {
   1.343 +    return NS_ERROR_FAILURE;
   1.344 +  }
   1.345 +
   1.346 +  return mProvider->GetRoamingPreference(mClientId, GetOwner(), aDomRequest);
   1.347 +}
   1.348 +
   1.349 +NS_IMETHODIMP
   1.350 +MobileConnection::SetVoicePrivacyMode(bool aEnabled, nsIDOMDOMRequest** aDomRequest)
   1.351 +{
   1.352 +  *aDomRequest = nullptr;
   1.353 +
   1.354 +  if (!CheckPermission("mobileconnection")) {
   1.355 +    return NS_OK;
   1.356 +  }
   1.357 +
   1.358 +  if (!mProvider) {
   1.359 +    return NS_ERROR_FAILURE;
   1.360 +  }
   1.361 +
   1.362 +  return mProvider->SetVoicePrivacyMode(mClientId, GetOwner(), aEnabled, aDomRequest);
   1.363 +}
   1.364 +
   1.365 +NS_IMETHODIMP
   1.366 +MobileConnection::GetVoicePrivacyMode(nsIDOMDOMRequest** aDomRequest)
   1.367 +{
   1.368 +  *aDomRequest = nullptr;
   1.369 +
   1.370 +  if (!CheckPermission("mobileconnection")) {
   1.371 +    return NS_OK;
   1.372 +  }
   1.373 +
   1.374 +  if (!mProvider) {
   1.375 +    return NS_ERROR_FAILURE;
   1.376 +  }
   1.377 +
   1.378 +  return mProvider->GetVoicePrivacyMode(mClientId, GetOwner(), aDomRequest);
   1.379 +}
   1.380 +
   1.381 +NS_IMETHODIMP
   1.382 +MobileConnection::SendMMI(const nsAString& aMMIString,
   1.383 +                          nsIDOMDOMRequest** aRequest)
   1.384 +{
   1.385 +  if (!CheckPermission("mobileconnection")) {
   1.386 +    return NS_OK;
   1.387 +  }
   1.388 +
   1.389 +  if (!mProvider) {
   1.390 +    return NS_ERROR_FAILURE;
   1.391 +  }
   1.392 +
   1.393 +  return mProvider->SendMMI(mClientId, GetOwner(), aMMIString, aRequest);
   1.394 +}
   1.395 +
   1.396 +NS_IMETHODIMP
   1.397 +MobileConnection::CancelMMI(nsIDOMDOMRequest** aRequest)
   1.398 +{
   1.399 +  if (!CheckPermission("mobileconnection")) {
   1.400 +    return NS_OK;
   1.401 +  }
   1.402 +
   1.403 +  if (!mProvider) {
   1.404 +    return NS_ERROR_FAILURE;
   1.405 +  }
   1.406 +
   1.407 +  return mProvider->CancelMMI(mClientId, GetOwner(),aRequest);
   1.408 +}
   1.409 +
   1.410 +NS_IMETHODIMP
   1.411 +MobileConnection::GetCallForwardingOption(uint16_t aReason,
   1.412 +                                          nsIDOMDOMRequest** aRequest)
   1.413 +{
   1.414 +  *aRequest = nullptr;
   1.415 +
   1.416 +  if (!CheckPermission("mobileconnection")) {
   1.417 +    return NS_OK;
   1.418 +  }
   1.419 +
   1.420 +  if (!mProvider) {
   1.421 +    return NS_ERROR_FAILURE;
   1.422 +  }
   1.423 +
   1.424 +  return mProvider->GetCallForwardingOption(mClientId, GetOwner(), aReason, aRequest);
   1.425 +}
   1.426 +
   1.427 +NS_IMETHODIMP
   1.428 +MobileConnection::SetCallForwardingOption(nsIDOMMozMobileCFInfo* aCFInfo,
   1.429 +                                          nsIDOMDOMRequest** aRequest)
   1.430 +{
   1.431 +  *aRequest = nullptr;
   1.432 +
   1.433 +  if (!CheckPermission("mobileconnection")) {
   1.434 +    return NS_OK;
   1.435 +  }
   1.436 +
   1.437 +  if (!mProvider) {
   1.438 +    return NS_ERROR_FAILURE;
   1.439 +  }
   1.440 +
   1.441 +  return mProvider->SetCallForwardingOption(mClientId, GetOwner(), aCFInfo, aRequest);
   1.442 +}
   1.443 +
   1.444 +NS_IMETHODIMP
   1.445 +MobileConnection::GetCallBarringOption(JS::Handle<JS::Value> aOption,
   1.446 +                                       nsIDOMDOMRequest** aRequest)
   1.447 +{
   1.448 +  *aRequest = nullptr;
   1.449 +
   1.450 +  if (!CheckPermission("mobileconnection")) {
   1.451 +    return NS_OK;
   1.452 +  }
   1.453 +
   1.454 +  if (!mProvider) {
   1.455 +    return NS_ERROR_FAILURE;
   1.456 +  }
   1.457 +
   1.458 +  return mProvider->GetCallBarringOption(mClientId, GetOwner(), aOption, aRequest);
   1.459 +}
   1.460 +
   1.461 +NS_IMETHODIMP
   1.462 +MobileConnection::SetCallBarringOption(JS::Handle<JS::Value> aOption,
   1.463 +                                       nsIDOMDOMRequest** aRequest)
   1.464 +{
   1.465 +  *aRequest = nullptr;
   1.466 +
   1.467 +  if (!CheckPermission("mobileconnection")) {
   1.468 +    return NS_OK;
   1.469 +  }
   1.470 +
   1.471 +  if (!mProvider) {
   1.472 +    return NS_ERROR_FAILURE;
   1.473 +  }
   1.474 +
   1.475 +  return mProvider->SetCallBarringOption(mClientId, GetOwner(), aOption, aRequest);
   1.476 +}
   1.477 +
   1.478 +NS_IMETHODIMP
   1.479 +MobileConnection::ChangeCallBarringPassword(JS::Handle<JS::Value> aInfo,
   1.480 +                                            nsIDOMDOMRequest** aRequest)
   1.481 +{
   1.482 +  *aRequest = nullptr;
   1.483 +
   1.484 +  if (!CheckPermission("mobileconnection")) {
   1.485 +    return NS_OK;
   1.486 +  }
   1.487 +
   1.488 +  if (!mProvider) {
   1.489 +    return NS_ERROR_FAILURE;
   1.490 +  }
   1.491 +
   1.492 +  return mProvider->ChangeCallBarringPassword(mClientId, GetOwner(), aInfo, aRequest);
   1.493 +}
   1.494 +
   1.495 +NS_IMETHODIMP
   1.496 +MobileConnection::GetCallWaitingOption(nsIDOMDOMRequest** aRequest)
   1.497 +{
   1.498 +  *aRequest = nullptr;
   1.499 +
   1.500 +  if (!CheckPermission("mobileconnection")) {
   1.501 +    return NS_OK;
   1.502 +  }
   1.503 +
   1.504 +  if (!mProvider) {
   1.505 +    return NS_ERROR_FAILURE;
   1.506 +  }
   1.507 +
   1.508 +  return mProvider->GetCallWaitingOption(mClientId, GetOwner(), aRequest);
   1.509 +}
   1.510 +
   1.511 +NS_IMETHODIMP
   1.512 +MobileConnection::SetCallWaitingOption(bool aEnabled,
   1.513 +                                       nsIDOMDOMRequest** aRequest)
   1.514 +{
   1.515 +  *aRequest = nullptr;
   1.516 +
   1.517 +  if (!CheckPermission("mobileconnection")) {
   1.518 +    return NS_OK;
   1.519 +  }
   1.520 +
   1.521 +  if (!mProvider) {
   1.522 +    return NS_ERROR_FAILURE;
   1.523 +  }
   1.524 +
   1.525 +  return mProvider->SetCallWaitingOption(mClientId, GetOwner(), aEnabled, aRequest);
   1.526 +}
   1.527 +
   1.528 +NS_IMETHODIMP
   1.529 +MobileConnection::GetCallingLineIdRestriction(nsIDOMDOMRequest** aRequest)
   1.530 +{
   1.531 +  *aRequest = nullptr;
   1.532 +
   1.533 +  if (!CheckPermission("mobileconnection")) {
   1.534 +    return NS_OK;
   1.535 +  }
   1.536 +
   1.537 +  if (!mProvider) {
   1.538 +    return NS_ERROR_FAILURE;
   1.539 +  }
   1.540 +
   1.541 +  return mProvider->GetCallingLineIdRestriction(mClientId, GetOwner(), aRequest);
   1.542 +}
   1.543 +
   1.544 +NS_IMETHODIMP
   1.545 +MobileConnection::SetCallingLineIdRestriction(unsigned short aClirMode,
   1.546 +                                              nsIDOMDOMRequest** aRequest)
   1.547 +{
   1.548 +  *aRequest = nullptr;
   1.549 +
   1.550 +  if (!CheckPermission("mobileconnection")) {
   1.551 +    return NS_OK;
   1.552 +  }
   1.553 +
   1.554 +  if (!mProvider) {
   1.555 +    return NS_ERROR_FAILURE;
   1.556 +  }
   1.557 +
   1.558 +  return mProvider->SetCallingLineIdRestriction(mClientId, GetOwner(), aClirMode, aRequest);
   1.559 +}
   1.560 +
   1.561 +NS_IMETHODIMP
   1.562 +MobileConnection::ExitEmergencyCbMode(nsIDOMDOMRequest** aRequest)
   1.563 +{
   1.564 +  *aRequest = nullptr;
   1.565 +
   1.566 +  if (!CheckPermission("mobileconnection")) {
   1.567 +    return NS_OK;
   1.568 +  }
   1.569 +
   1.570 +  if (!mProvider) {
   1.571 +    return NS_ERROR_FAILURE;
   1.572 +  }
   1.573 +
   1.574 +  return mProvider->ExitEmergencyCbMode(mClientId, GetOwner(), aRequest);
   1.575 +}
   1.576 +
   1.577 +NS_IMETHODIMP
   1.578 +MobileConnection::SetRadioEnabled(bool aEnabled,
   1.579 +                                  nsIDOMDOMRequest** aRequest)
   1.580 +{
   1.581 +  *aRequest = nullptr;
   1.582 +
   1.583 +  if (!CheckPermission("mobileconnection")) {
   1.584 +    return NS_OK;
   1.585 +  }
   1.586 +
   1.587 +  if (!mProvider) {
   1.588 +    return NS_ERROR_FAILURE;
   1.589 +  }
   1.590 +
   1.591 +  return mProvider->SetRadioEnabled(mClientId, GetOwner(), aEnabled, aRequest);
   1.592 +}
   1.593 +
   1.594 +// nsIMobileConnectionListener
   1.595 +
   1.596 +NS_IMETHODIMP
   1.597 +MobileConnection::NotifyVoiceChanged()
   1.598 +{
   1.599 +  if (!CheckPermission("mobileconnection")) {
   1.600 +    return NS_OK;
   1.601 +  }
   1.602 +
   1.603 +  return DispatchTrustedEvent(NS_LITERAL_STRING("voicechange"));
   1.604 +}
   1.605 +
   1.606 +NS_IMETHODIMP
   1.607 +MobileConnection::NotifyDataChanged()
   1.608 +{
   1.609 +  if (!CheckPermission("mobileconnection")) {
   1.610 +    return NS_OK;
   1.611 +  }
   1.612 +
   1.613 +  return DispatchTrustedEvent(NS_LITERAL_STRING("datachange"));
   1.614 +}
   1.615 +
   1.616 +NS_IMETHODIMP
   1.617 +MobileConnection::NotifyUssdReceived(const nsAString& aMessage,
   1.618 +                                     bool aSessionEnded)
   1.619 +{
   1.620 +  if (!CheckPermission("mobileconnection")) {
   1.621 +    return NS_OK;
   1.622 +  }
   1.623 +
   1.624 +  USSDReceivedEventInit init;
   1.625 +  init.mBubbles = false;
   1.626 +  init.mCancelable = false;
   1.627 +  init.mMessage = aMessage;
   1.628 +  init.mSessionEnded = aSessionEnded;
   1.629 +
   1.630 +  nsRefPtr<USSDReceivedEvent> event =
   1.631 +    USSDReceivedEvent::Constructor(this, NS_LITERAL_STRING("ussdreceived"), init);
   1.632 +
   1.633 +  return DispatchTrustedEvent(event);
   1.634 +}
   1.635 +
   1.636 +NS_IMETHODIMP
   1.637 +MobileConnection::NotifyDataError(const nsAString& aMessage)
   1.638 +{
   1.639 +  if (!CheckPermission("mobileconnection")) {
   1.640 +    return NS_OK;
   1.641 +  }
   1.642 +
   1.643 +  DataErrorEventInit init;
   1.644 +  init.mBubbles = false;
   1.645 +  init.mCancelable = false;
   1.646 +  init.mMessage = aMessage;
   1.647 +
   1.648 +  nsRefPtr<DataErrorEvent> event =
   1.649 +    DataErrorEvent::Constructor(this, NS_LITERAL_STRING("dataerror"), init);
   1.650 +
   1.651 +  return DispatchTrustedEvent(event);
   1.652 +}
   1.653 +
   1.654 +NS_IMETHODIMP
   1.655 +MobileConnection::NotifyCFStateChange(bool aSuccess,
   1.656 +                                      unsigned short aAction,
   1.657 +                                      unsigned short aReason,
   1.658 +                                      const nsAString& aNumber,
   1.659 +                                      unsigned short aSeconds,
   1.660 +                                      unsigned short aServiceClass)
   1.661 +{
   1.662 +  if (!CheckPermission("mobileconnection")) {
   1.663 +    return NS_OK;
   1.664 +  }
   1.665 +
   1.666 +  CFStateChangeEventInit init;
   1.667 +  init.mBubbles = false;
   1.668 +  init.mCancelable = false;
   1.669 +  init.mSuccess = aSuccess;
   1.670 +  init.mAction = aAction;
   1.671 +  init.mReason = aReason;
   1.672 +  init.mNumber = aNumber;
   1.673 +  init.mTimeSeconds = aSeconds;
   1.674 +  init.mServiceClass = aServiceClass;
   1.675 +
   1.676 +  nsRefPtr<CFStateChangeEvent> event =
   1.677 +    CFStateChangeEvent::Constructor(this, NS_LITERAL_STRING("cfstatechange"), init);
   1.678 +
   1.679 +  return DispatchTrustedEvent(event);
   1.680 +}
   1.681 +
   1.682 +NS_IMETHODIMP
   1.683 +MobileConnection::NotifyEmergencyCbModeChanged(bool aActive,
   1.684 +                                               uint32_t aTimeoutMs)
   1.685 +{
   1.686 +  if (!CheckPermission("mobileconnection")) {
   1.687 +    return NS_OK;
   1.688 +  }
   1.689 +
   1.690 +  MozEmergencyCbModeEventInit init;
   1.691 +  init.mBubbles = false;
   1.692 +  init.mCancelable = false;
   1.693 +  init.mActive = aActive;
   1.694 +  init.mTimeoutMs = aTimeoutMs;
   1.695 +
   1.696 +  nsRefPtr<MozEmergencyCbModeEvent> event =
   1.697 +    MozEmergencyCbModeEvent::Constructor(this, NS_LITERAL_STRING("emergencycbmodechange"), init);
   1.698 +
   1.699 +  return DispatchTrustedEvent(event);
   1.700 +}
   1.701 +
   1.702 +NS_IMETHODIMP
   1.703 +MobileConnection::NotifyOtaStatusChanged(const nsAString& aStatus)
   1.704 +{
   1.705 +  if (!CheckPermission("mobileconnection")) {
   1.706 +    return NS_OK;
   1.707 +  }
   1.708 +
   1.709 +  MozOtaStatusEventInit init;
   1.710 +  init.mBubbles = false;
   1.711 +  init.mCancelable = false;
   1.712 +  init.mStatus = aStatus;
   1.713 +
   1.714 +  nsRefPtr<MozOtaStatusEvent> event =
   1.715 +    MozOtaStatusEvent::Constructor(this, NS_LITERAL_STRING("otastatuschange"), init);
   1.716 +
   1.717 +  return DispatchTrustedEvent(event);
   1.718 +}
   1.719 +
   1.720 +NS_IMETHODIMP
   1.721 +MobileConnection::NotifyIccChanged()
   1.722 +{
   1.723 +  if (!CheckPermission("mobileconnection")) {
   1.724 +    return NS_OK;
   1.725 +  }
   1.726 +
   1.727 +  return DispatchTrustedEvent(NS_LITERAL_STRING("iccchange"));
   1.728 +}
   1.729 +
   1.730 +NS_IMETHODIMP
   1.731 +MobileConnection::NotifyRadioStateChanged()
   1.732 +{
   1.733 +  if (!CheckPermission("mobileconnection")) {
   1.734 +    return NS_OK;
   1.735 +  }
   1.736 +
   1.737 +  return DispatchTrustedEvent(NS_LITERAL_STRING("radiostatechange"));
   1.738 +}

mercurial