Bug 960426 - Part 2: Modifications for IDL change. r=blassey
authorJohn Shih <jshih@mozilla.com>
Wed, 05 Mar 2014 11:54:55 +0800
changeset 194145 08c1d13ed194716d5018f8053dd9176bc70b2484
parent 194144 ae8a5c6d6340d45fea76aa2a70364f2be3315518
child 194146 f2a47d87402d15db2a14468223a763dda0eaea17
push idunknown
push userunknown
push dateunknown
reviewersblassey
bugs960426
milestone31.0a1
Bug 960426 - Part 2: Modifications for IDL change. r=blassey
content/base/src/nsGkAtomList.h
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/bindings/Bindings.conf
dom/bindings/crashtests/832899.html
dom/network/interfaces/nsIMozNavigatorNetwork.idl
dom/network/src/Connection.cpp
dom/network/src/Connection.h
dom/network/src/Constants.h
dom/network/tests/test_network_basics.html
dom/webidl/moz.build
hal/fallback/FallbackNetwork.cpp
hal/sandbox/PHal.ipdl
netwerk/protocol/http/nsHttpHandler.cpp
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -807,16 +807,17 @@ GK_ATOM(onsent, "onsent")
 GK_ATOM(onset, "onset")
 GK_ATOM(onshow, "onshow")
 GK_ATOM(onstatechange, "onstatechange")
 GK_ATOM(onstatuschanged, "onstatuschanged")
 GK_ATOM(onstkcommand, "onstkcommand")
 GK_ATOM(onstksessionend, "onstksessionend")
 GK_ATOM(onsubmit, "onsubmit")
 GK_ATOM(onsuccess, "onsuccess")
+GK_ATOM(ontypechange, "ontypechange")
 GK_ATOM(ontext, "ontext")
 GK_ATOM(ontouchstart, "ontouchstart")
 GK_ATOM(ontouchend, "ontouchend")
 GK_ATOM(ontouchmove, "ontouchmove")
 GK_ATOM(ontouchenter, "ontouchenter")
 GK_ATOM(ontouchleave, "ontouchleave")
 GK_ATOM(ontouchcancel, "ontouchcancel")
 GK_ATOM(ontransitionend, "ontransitionend")
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1582,28 +1582,31 @@ Navigator::GetGamepads(nsTArray<nsRefPtr
 }
 #endif
 
 //*****************************************************************************
 //    Navigator::nsIMozNavigatorNetwork
 //*****************************************************************************
 
 NS_IMETHODIMP
-Navigator::GetMozConnection(nsISupports** aConnection)
+Navigator::GetProperties(nsINetworkProperties** aProperties)
 {
-  nsCOMPtr<nsINetworkProperties> properties = GetMozConnection();
-  properties.forget(aConnection);
+  ErrorResult rv;
+  NS_IF_ADDREF(*aProperties = GetConnection(rv));
   return NS_OK;
 }
 
 network::Connection*
-Navigator::GetMozConnection()
+Navigator::GetConnection(ErrorResult& aRv)
 {
   if (!mConnection) {
-    NS_ENSURE_TRUE(mWindow, nullptr);
+    if (!mWindow) {
+      aRv.Throw(NS_ERROR_UNEXPECTED);
+      return nullptr;
+    }
     NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
 
     mConnection = new network::Connection();
     mConnection->Init(mWindow);
   }
 
   return mConnection;
 }
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -17,17 +17,16 @@
 #include "nsHashKeys.h"
 #include "nsInterfaceHashtable.h"
 #include "nsString.h"
 #include "nsTArray.h"
 
 class nsPluginArray;
 class nsMimeTypeArray;
 class nsPIDOMWindow;
-class nsIDOMMozConnection;
 class nsIDOMMozMobileMessageManager;
 class nsIDOMNavigatorSystemMessages;
 class nsDOMCameraManager;
 class nsDOMDeviceStorage;
 class nsIDOMBlob;
 
 namespace mozilla {
 namespace dom {
@@ -194,17 +193,17 @@ public:
   void GetDeviceStorages(const nsAString& aType,
                          nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
                          ErrorResult& aRv);
   DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
   bool MozIsLocallyAvailable(const nsAString& aURI, bool aWhenOffline,
                              ErrorResult& aRv);
   nsIDOMMozMobileMessageManager* GetMozMobileMessage();
   Telephony* GetMozTelephony(ErrorResult& aRv);
-  network::Connection* GetMozConnection();
+  network::Connection* GetConnection(ErrorResult& aRv);
   nsDOMCameraManager* GetMozCameras(ErrorResult& aRv);
   void MozSetMessageHandler(const nsAString& aType,
                             systemMessageCallback* aCallback,
                             ErrorResult& aRv);
   bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv);
 #ifdef MOZ_B2G_RIL
   MobileConnectionArray* GetMozMobileConnections(ErrorResult& aRv);
   CellBroadcast* GetMozCellBroadcast(ErrorResult& aRv);
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -772,20 +772,16 @@ DOMInterfaces = {
 {
     'workers': True,
 }],
 
 'MozCellBroadcast': {
     'nativeType': 'mozilla::dom::CellBroadcast',
 },
 
-'MozConnection': {
-    'nativeType': 'mozilla::dom::network::Connection',
-},
-
 'MozIcc': {
     'nativeType': 'mozilla::dom::Icc',
 },
 
 'MozMobileConnectionArray': {
     'nativeType': 'mozilla::dom::MobileConnectionArray',
     'resultNotAddRefed': [ 'item' ]
 },
@@ -821,16 +817,20 @@ DOMInterfaces = {
 
 'MutationRecord': {
     'nativeType': 'nsDOMMutationRecord',
     'headerFile': 'nsDOMMutationObserver.h',
     'resultNotAddRefed': [ 'target', 'addedNodes', 'removedNodes',
                            'previousSibling', 'nextSibling' ]
 },
 
+'NetworkInformation': {
+    'nativeType': 'mozilla::dom::network::Connection',
+},
+
 'Node': {
     'nativeType': 'nsINode',
     'concrete': False,
     'resultNotAddRefed': [ 'ownerDocument', 'parentNode', 'parentElement',
                            'childNodes', 'firstChild', 'lastChild',
                            'previousSibling', 'nextSibling', 'insertBefore',
                            'appendChild', 'replaceChild', 'removeChild',
                            'attributes' ]
--- a/dom/bindings/crashtests/832899.html
+++ b/dom/bindings/crashtests/832899.html
@@ -1,5 +1,5 @@
 <!DOCTYPE html>
 <script>
   var ev = document.createEvent("Events");
-  EventTarget.prototype.dispatchEvent.call(navigator.mozConnection, ev);
+  EventTarget.prototype.dispatchEvent.call(navigator.connection, ev);
 </script>
--- a/dom/network/interfaces/nsIMozNavigatorNetwork.idl
+++ b/dom/network/interfaces/nsIMozNavigatorNetwork.idl
@@ -1,12 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
-[uuid(7f021f5d-f704-4a29-b166-829595169aaf)]
+interface nsINetworkProperties;
+
+[uuid(7956523b-631e-4f80-94a5-3883bcfd6bf3)]
 interface nsIMozNavigatorNetwork : nsISupports
 {
-  // This is a MozConnection
-  readonly attribute nsISupports mozConnection;
+  readonly attribute nsINetworkProperties properties;
 };
--- a/dom/network/src/Connection.cpp
+++ b/dom/network/src/Connection.cpp
@@ -1,45 +1,40 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <limits>
 #include "mozilla/Hal.h"
 #include "mozilla/dom/network/Connection.h"
-#include "mozilla/dom/MozConnectionBinding.h"
 #include "nsIDOMClassInfo.h"
 #include "mozilla/Preferences.h"
 #include "Constants.h"
 
 /**
  * We have to use macros here because our leak analysis tool things we are
  * leaking strings when we have |static const nsString|. Sad :(
  */
-#define CHANGE_EVENT_NAME NS_LITERAL_STRING("change")
+#define CHANGE_EVENT_NAME NS_LITERAL_STRING("typechange")
 
 namespace mozilla {
 namespace dom {
 namespace network {
 
-const char* Connection::sMeteredPrefName     = "dom.network.metered";
-const bool  Connection::sMeteredDefaultValue = false;
-
 NS_IMPL_QUERY_INTERFACE_INHERITED1(Connection, nsDOMEventTargetHelper,
                                    nsINetworkProperties)
 
 // Don't use |Connection| alone, since that confuses nsTraceRefcnt since
 // we're not the only class with that name.
 NS_IMPL_ADDREF_INHERITED(dom::network::Connection, nsDOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(dom::network::Connection, nsDOMEventTargetHelper)
 
 Connection::Connection()
-  : mCanBeMetered(kDefaultCanBeMetered)
-  , mBandwidth(kDefaultBandwidth)
+  : mType(static_cast<ConnectionType>(kDefaultType))
   , mIsWifi(kDefaultIsWifi)
   , mDHCPGateway(kDefaultDHCPGateway)
 {
   SetIsDOMBinding();
 }
 
 void
 Connection::Init(nsPIDOMWindow* aWindow)
@@ -55,36 +50,16 @@ Connection::Init(nsPIDOMWindow* aWindow)
 }
 
 void
 Connection::Shutdown()
 {
   hal::UnregisterNetworkObserver(this);
 }
 
-double
-Connection::Bandwidth() const
-{
-  if (mBandwidth == kDefaultBandwidth) {
-    return std::numeric_limits<double>::infinity();
-  }
-
-  return mBandwidth;
-}
-
-bool
-Connection::Metered() const
-{
-  if (!mCanBeMetered) {
-    return false;
-  }
-
-  return Preferences::GetBool(sMeteredPrefName, sMeteredDefaultValue);
-}
-
 NS_IMETHODIMP
 Connection::GetIsWifi(bool *aIsWifi)
 {
   *aIsWifi = mIsWifi;
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -92,39 +67,36 @@ Connection::GetDhcpGateway(uint32_t *aGW
 {
   *aGW = mDHCPGateway;
   return NS_OK;
 }
 
 void
 Connection::UpdateFromNetworkInfo(const hal::NetworkInformation& aNetworkInfo)
 {
-  mBandwidth = aNetworkInfo.bandwidth();
-  mCanBeMetered = aNetworkInfo.canBeMetered();
+  mType = static_cast<ConnectionType>(aNetworkInfo.type());
   mIsWifi = aNetworkInfo.isWifi();
   mDHCPGateway = aNetworkInfo.dhcpGateway();
 }
 
 void
 Connection::Notify(const hal::NetworkInformation& aNetworkInfo)
 {
-  double previousBandwidth = mBandwidth;
-  bool previousCanBeMetered = mCanBeMetered;
+  ConnectionType previousType = mType;
 
   UpdateFromNetworkInfo(aNetworkInfo);
 
-  if (previousBandwidth == mBandwidth &&
-      previousCanBeMetered == mCanBeMetered) {
+  if (previousType == mType) {
     return;
   }
 
   DispatchTrustedEvent(CHANGE_EVENT_NAME);
 }
 
 JSObject*
 Connection::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
-  return MozConnectionBinding::Wrap(aCx, aScope, this);
+  return NetworkInformationBinding::Wrap(aCx, aScope, this);
 }
 
 } // namespace network
 } // namespace dom
 } // namespace mozilla
--- a/dom/network/src/Connection.h
+++ b/dom/network/src/Connection.h
@@ -6,16 +6,17 @@
 #ifndef mozilla_dom_network_Connection_h
 #define mozilla_dom_network_Connection_h
 
 #include "nsINetworkProperties.h"
 #include "nsDOMEventTargetHelper.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Observer.h"
 #include "Types.h"
+#include "mozilla/dom/NetworkInformationBinding.h"
 
 namespace mozilla {
 
 namespace hal {
 class NetworkInformation;
 } // namespace hal
 
 namespace dom {
@@ -39,50 +40,40 @@ public:
   // For IObserver
   void Notify(const hal::NetworkInformation& aNetworkInfo);
 
   // WebIDL
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
-  double Bandwidth() const;
+  ConnectionType Type() const { return mType; }
 
-  bool Metered() const;
-
-  IMPL_EVENT_HANDLER(change)
+  IMPL_EVENT_HANDLER(typechange)
 
 private:
   /**
    * Update the connection information stored in the object using a
    * NetworkInformation object.
    */
   void UpdateFromNetworkInfo(const hal::NetworkInformation& aNetworkInfo);
 
   /**
-   * If the connection is of a type that can be metered.
+   * The type of current connection.
    */
-  bool mCanBeMetered;
-
-  /**
-   * The connection bandwidth.
-   */
-  double mBandwidth;
+  ConnectionType mType;
 
   /**
    * If the connection is WIFI
    */
   bool mIsWifi;
 
   /**
    * DHCP Gateway information for IPV4, in network byte order. 0 if unassigned.
    */
   uint32_t mDHCPGateway;
-
-  static const char* sMeteredPrefName;
-  static const bool  sMeteredDefaultValue;
 };
 
 } // namespace network
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_network_Connection_h
--- a/dom/network/src/Constants.h
+++ b/dom/network/src/Constants.h
@@ -8,18 +8,17 @@
 
 /**
  * A set of constants to be used by network backends.
  */
 namespace mozilla {
 namespace dom {
 namespace network {
 
-  static const double kDefaultBandwidth    = -1.0;
-  static const bool   kDefaultCanBeMetered = false;
+  static const uint32_t kDefaultType = 5; // ConnectionType::None
   static const bool   kDefaultIsWifi = false;
   static const uint32_t kDefaultDHCPGateway = 0;
 
 } // namespace network
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_network_Constants_h__
--- a/dom/network/tests/test_network_basics.html
+++ b/dom/network/tests/test_network_basics.html
@@ -7,44 +7,32 @@
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script type="application/javascript">
 
-/** Test for Network API **/
-function checkInterface(aInterface) {
-  ok(!(aInterface in window), aInterface + " should not exist");
-  ok(!(("Moz" + aInterface) in window), aInterface + " should not exist");
-}
+/** Test for Network Information API **/
+function test() {
+  ok('connection' in navigator, "navigator.connection should exist");
 
-function test() {
-  ok('mozConnection' in navigator, "navigator.mozConnection should exist");
-
-  ok(navigator.mozConnection, "navigator.mozConnection returns an object");
+  ok(navigator.connection, "navigator.connection returns an object");
 
-  ok(navigator.mozConnection instanceof EventTarget,
-     "navigator.mozConnection is a EventTarget object");
-
-  checkInterface("Connection");
+  ok(navigator.connection instanceof EventTarget,
+     "navigator.connection is a EventTarget object");
 
-  ok('bandwidth' in navigator.mozConnection,
-     "bandwidth should be a Connection attribute");
-  is(navigator.mozConnection.bandwidth, Infinity,
-     "By default connection.bandwidth is equals to Infinity");
-
-  ok('metered' in navigator.mozConnection,
-     "metered should be a Connection attribute");
-  is(navigator.mozConnection.metered, false,
-     "By default the connection is not metered");
+  ok('type' in navigator.connection,
+     "type should be a Connection attribute");
+  is(navigator.connection.type, "none",
+     "By default connection.type equals to none");
 
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
-SpecialPowers.pushPrefEnv({'set': [["dom.network.enabled", true]]}, test);
+SpecialPowers.pushPrefEnv({'set': [["dom.netinfo.enabled", true]]}, test);
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -234,28 +234,28 @@ WEBIDL_FILES = [
     'MessagePort.webidl',
     'MessagePortList.webidl',
     'MimeType.webidl',
     'MimeTypeArray.webidl',
     'MobileMessageManager.webidl',
     'MouseEvent.webidl',
     'MouseScrollEvent.webidl',
     'MozActivity.webidl',
-    'MozConnection.webidl',
     'MozMmsMessage.webidl',
     'MozMobileConnection.webidl',
     'MozNamedAttrMap.webidl',
     'MozNetworkStats.webidl',
     'MozPowerManager.webidl',
     'MozTimeManager.webidl',
     'MozWakeLock.webidl',
     'MutationEvent.webidl',
     'MutationObserver.webidl',
     'NativeOSFileInternals.webidl',
     'NetDashboard.webidl',
+    'NetworkInformation.webidl',
     'NetworkOptions.webidl',
     'Node.webidl',
     'NodeFilter.webidl',
     'NodeIterator.webidl',
     'NodeList.webidl',
     'Notification.webidl',
     'NotifyAudioAvailableEvent.webidl',
     'NotifyPaintEvent.webidl',
--- a/hal/fallback/FallbackNetwork.cpp
+++ b/hal/fallback/FallbackNetwork.cpp
@@ -17,16 +17,15 @@ EnableNetworkNotifications()
 
 void
 DisableNetworkNotifications()
 {}
 
 void
 GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
 {
-  aNetworkInfo->bandwidth() = dom::network::kDefaultBandwidth;
-  aNetworkInfo->canBeMetered() = dom::network::kDefaultCanBeMetered;
+  aNetworkInfo->type() = dom::network::kDefaultType;
   aNetworkInfo->isWifi() = dom::network::kDefaultIsWifi;
   aNetworkInfo->dhcpGateway() = dom::network::kDefaultDHCPGateway;
 }
 
 } // namespace hal_impl
 } // namespace mozilla
--- a/hal/sandbox/PHal.ipdl
+++ b/hal/sandbox/PHal.ipdl
@@ -44,18 +44,17 @@ struct LightConfiguration {
 struct SensorData {
   SensorType sensor;
   PRTime timestamp;
   float[] values;
   SensorAccuracyType accuracy;
 };
 
 struct NetworkInformation {
-  double bandwidth;
-  bool   canBeMetered;
+  uint32_t type;
   bool   isWifi;
   uint32_t dhcpGateway;
 };
 
 struct SwitchEvent {
   SwitchDevice device;
   SwitchState status;
 };
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -1923,20 +1923,18 @@ nsHttpHandler::TickleWifi(nsIInterfaceRe
 
     nsCOMPtr<nsIDOMNavigator> domNavigator;
     domWindow->GetNavigator(getter_AddRefs(domNavigator));
     nsCOMPtr<nsIMozNavigatorNetwork> networkNavigator =
         do_QueryInterface(domNavigator);
     if (!networkNavigator)
         return;
 
-    nsCOMPtr<nsISupports> mozConnection;
-    networkNavigator->GetMozConnection(getter_AddRefs(mozConnection));
-    nsCOMPtr<nsINetworkProperties> networkProperties =
-        do_QueryInterface(mozConnection);
+    nsCOMPtr<nsINetworkProperties> networkProperties;
+    networkNavigator->GetProperties(getter_AddRefs(networkProperties));
     if (!networkProperties)
         return;
 
     uint32_t gwAddress;
     bool isWifi;
     nsresult rv;
 
     rv = networkProperties->GetDhcpGateway(&gwAddress);