Bug 1466298 part 3. Remove nsIDOMGeoGeolocation. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 04 Jun 2018 12:41:09 -0400
changeset 475430 2fc5f7be292eb229d4e696a13c4d0edcec3bf453
parent 475429 1b156f1b15aecdaa199da0e16eccf3679536705a
child 475431 784d3bfa1281ad2208bb19b79103dd47b6486670
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1466298
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466298 part 3. Remove nsIDOMGeoGeolocation. r=mccr8
dom/geolocation/nsGeolocation.cpp
dom/geolocation/nsGeolocation.h
dom/interfaces/geolocation/moz.build
dom/interfaces/geolocation/nsIDOMGeoGeolocation.idl
dom/ipc/ContentParent.cpp
--- a/dom/geolocation/nsGeolocation.cpp
+++ b/dom/geolocation/nsGeolocation.cpp
@@ -911,18 +911,17 @@ nsGeolocationService::RemoveLocator(Geol
 }
 
 ////////////////////////////////////////////////////
 // Geolocation
 ////////////////////////////////////////////////////
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Geolocation)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoGeolocation)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMGeoGeolocation)
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_INTERFACE_MAP_ENTRY(nsIGeolocationUpdate)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(Geolocation)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(Geolocation)
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Geolocation,
                                       mPendingCallbacks,
@@ -1177,17 +1176,17 @@ void
 Geolocation::GetCurrentPosition(PositionCallback& aCallback,
                                 PositionErrorCallback* aErrorCallback,
                                 const PositionOptions& aOptions,
                                 CallerType aCallerType,
                                 ErrorResult& aRv)
 {
   nsresult rv = GetCurrentPosition(GeoPositionCallback(&aCallback),
                                    GeoPositionErrorCallback(aErrorCallback),
-                                   std::move(CreatePositionOptionsCopy(aOptions)),
+                                   CreatePositionOptionsCopy(aOptions),
                                    aCallerType);
 
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
   }
 }
 
 static nsIEventTarget* MainThreadTarget(Geolocation* geo)
@@ -1252,101 +1251,99 @@ Geolocation::GetCurrentPosition(GeoPosit
 
 int32_t
 Geolocation::WatchPosition(PositionCallback& aCallback,
                            PositionErrorCallback* aErrorCallback,
                            const PositionOptions& aOptions,
                            CallerType aCallerType,
                            ErrorResult& aRv)
 {
-  int32_t ret = 0;
-  nsresult rv = WatchPosition(GeoPositionCallback(&aCallback),
-                              GeoPositionErrorCallback(aErrorCallback),
-                              std::move(CreatePositionOptionsCopy(aOptions)),
-                              aCallerType,
-                              &ret);
-
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
-  }
-
-  return ret;
+  return WatchPosition(GeoPositionCallback(&aCallback),
+                       GeoPositionErrorCallback(aErrorCallback),
+                       CreatePositionOptionsCopy(aOptions),
+                       aCallerType,
+                       aRv);
 }
 
-NS_IMETHODIMP
+int32_t
 Geolocation::WatchPosition(nsIDOMGeoPositionCallback *aCallback,
                            nsIDOMGeoPositionErrorCallback *aErrorCallback,
-                           UniquePtr<PositionOptions>&& aOptions,
-                           int32_t* aRv)
+                           UniquePtr<PositionOptions>&& aOptions)
 {
-  NS_ENSURE_ARG_POINTER(aCallback);
+  MOZ_ASSERT(aCallback);
 
   return WatchPosition(GeoPositionCallback(aCallback),
                        GeoPositionErrorCallback(aErrorCallback),
                        std::move(aOptions), CallerType::System,
-                       aRv);
+                       IgnoreErrors());
 }
 
-nsresult
+// On errors we return -1 because that's not a valid watch id and will
+// get ignored in clearWatch.
+int32_t
 Geolocation::WatchPosition(GeoPositionCallback aCallback,
                            GeoPositionErrorCallback aErrorCallback,
                            UniquePtr<PositionOptions>&& aOptions,
                            CallerType aCallerType,
-                           int32_t* aRv)
+                           ErrorResult& aRv)
 {
   if (mWatchingCallbacks.Length() > MAX_GEO_REQUESTS_PER_WINDOW) {
-    return NS_ERROR_NOT_AVAILABLE;
+    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+    return -1;
   }
 
   // Count the number of requests per protocol/scheme.
   Telemetry::Accumulate(Telemetry::GEOLOCATION_WATCHPOSITION_SECURE_ORIGIN,
                         static_cast<uint8_t>(mProtocolType));
 
   // The watch ID:
-  *aRv = mLastWatchId++;
+  int32_t watchId = mLastWatchId++;
 
   nsIEventTarget* target = MainThreadTarget(this);
   RefPtr<nsGeolocationRequest> request =
     new nsGeolocationRequest(this, std::move(aCallback), std::move(aErrorCallback),
                              std::move(aOptions),
                              static_cast<uint8_t>(mProtocolType), target, true,
-                             EventStateManager::IsHandlingUserInput(), *aRv);
+                             EventStateManager::IsHandlingUserInput(), watchId);
 
   if (!sGeoEnabled || ShouldBlockInsecureRequests() ||
       nsContentUtils::ResistFingerprinting(aCallerType)) {
     nsCOMPtr<nsIRunnable> ev = new RequestAllowEvent(false, request);
     target->Dispatch(ev.forget());
-    return NS_OK;
+    return watchId;
   }
 
   if (!mOwner && aCallerType != CallerType::System) {
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return -1;
   }
 
   if (mOwner) {
-    if (!RegisterRequestWithPrompt(request))
-      return NS_ERROR_NOT_AVAILABLE;
+    if (!RegisterRequestWithPrompt(request)) {
+      aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+      return -1;
+    }
 
-    return NS_OK;
+    return watchId;
   }
 
   if (aCallerType != CallerType::System) {
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return -1;
   }
 
   request->Allow(JS::UndefinedHandleValue);
-
-  return NS_OK;
+  return watchId;
 }
 
-NS_IMETHODIMP
+void
 Geolocation::ClearWatch(int32_t aWatchId)
 {
   if (aWatchId < 0) {
-    return NS_OK;
+    return;
   }
 
   if (!mClearedWatchIDs.Contains(aWatchId)) {
     mClearedWatchIDs.AppendElement(aWatchId);
   }
 
   for (uint32_t i = 0, length = mWatchingCallbacks.Length(); i < length; ++i) {
     if (mWatchingCallbacks[i]->WatchId() == aWatchId) {
@@ -1362,18 +1359,16 @@ Geolocation::ClearWatch(int32_t aWatchId
   for (uint32_t i = 0, length = mPendingRequests.Length(); i < length; ++i) {
     if (mPendingRequests[i]->IsWatch() &&
         (mPendingRequests[i]->WatchId() == aWatchId)) {
       mPendingRequests[i]->Shutdown();
       mPendingRequests.RemoveElementAt(i);
       break;
     }
   }
-
-  return NS_OK;
 }
 
 bool
 Geolocation::WindowOwnerStillExists()
 {
   // an owner was never set when Geolocation
   // was created, which means that this object
   // is being used without a window.
--- a/dom/geolocation/nsGeolocation.h
+++ b/dom/geolocation/nsGeolocation.h
@@ -16,17 +16,16 @@
 #include "nsITimer.h"
 #include "nsIObserver.h"
 #include "nsWrapperCache.h"
 
 #include "nsWeakPtr.h"
 #include "nsCycleCollectionParticipant.h"
 
 #include "nsGeoPosition.h"
-#include "nsIDOMGeoGeolocation.h"
 #include "nsIDOMGeoPosition.h"
 #include "nsIDOMGeoPositionCallback.h"
 #include "nsIDOMGeoPositionErrorCallback.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/GeolocationBinding.h"
 #include "mozilla/dom/CallbackObject.h"
 
 #include "nsIGeolocationProvider.h"
@@ -115,27 +114,25 @@ private:
 };
 
 namespace mozilla {
 namespace dom {
 
 /**
  * Can return a geolocation info
  */
-class Geolocation final : public nsIDOMGeoGeolocation,
-                          public nsIGeolocationUpdate,
+class Geolocation final : public nsIGeolocationUpdate,
                           public nsWrapperCache
 {
 public:
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Geolocation, nsIDOMGeoGeolocation)
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Geolocation)
 
   NS_DECL_NSIGEOLOCATIONUPDATE
-  NS_DECL_NSIDOMGEOGEOLOCATION
 
   Geolocation();
 
   nsresult Init(nsPIDOMWindowInner* aContentDom = nullptr);
 
   nsPIDOMWindowInner* GetParentObject() const;
   virtual JSObject* WrapObject(JSContext *aCtx, JS::Handle<JSObject*> aGivenProto) override;
 
@@ -144,16 +141,22 @@ public:
                         const PositionOptions& aOptions,
                         CallerType aCallerType,
                         ErrorResult& aRv);
   void GetCurrentPosition(PositionCallback& aCallback,
                           PositionErrorCallback* aErrorCallback,
                           const PositionOptions& aOptions,
                           CallerType aCallerType,
                           ErrorResult& aRv);
+  void ClearWatch(int32_t aWatchId);
+
+  // A WatchPosition for C++ use.  Returns -1 if we failed to actually watch.
+  int32_t WatchPosition(nsIDOMGeoPositionCallback* aCallback,
+                        nsIDOMGeoPositionErrorCallback* aErrorCallback,
+                        UniquePtr<PositionOptions>&& aOptions);
 
   // Returns true if any of the callbacks are repeating
   bool HasActiveCallbacks();
 
   // Register an allowed request
   void NotifyAllowedRequest(nsGeolocationRequest* aRequest);
 
   // Remove request from all callbacks arrays
@@ -184,21 +187,21 @@ public:
 private:
 
   ~Geolocation();
 
   nsresult GetCurrentPosition(GeoPositionCallback aCallback,
                               GeoPositionErrorCallback aErrorCallback,
                               UniquePtr<PositionOptions>&& aOptions,
                               CallerType aCallerType);
-  nsresult WatchPosition(GeoPositionCallback aCallback,
-                         GeoPositionErrorCallback aErrorCallback,
-                         UniquePtr<PositionOptions>&& aOptions,
-                         CallerType aCallerType,
-                         int32_t* aRv);
+  int32_t WatchPosition(GeoPositionCallback aCallback,
+                        GeoPositionErrorCallback aErrorCallback,
+                        UniquePtr<PositionOptions>&& aOptions,
+                        CallerType aCallerType,
+                        ErrorResult& aRv);
 
   bool RegisterRequestWithPrompt(nsGeolocationRequest* request);
 
   // Check if clearWatch is already called
   bool IsAlreadyCleared(nsGeolocationRequest* aRequest);
 
   // Returns whether the Geolocation object should block requests
   // within a context that is not secure.
@@ -237,18 +240,11 @@ private:
   // Array containing already cleared watch IDs
   nsTArray<int32_t> mClearedWatchIDs;
 
   // Our cached non-window singleton.
   static mozilla::StaticRefPtr<Geolocation> sNonWindowSingleton;
 };
 
 } // namespace dom
-
-inline nsISupports*
-ToSupports(dom::Geolocation* aGeolocation)
-{
-  return ToSupports(static_cast<nsIDOMGeoGeolocation*>(aGeolocation));
-}
-
 } // namespace mozilla
 
 #endif /* nsGeoLocation_h */
--- a/dom/interfaces/geolocation/moz.build
+++ b/dom/interfaces/geolocation/moz.build
@@ -3,17 +3,16 @@
 # 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/.
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "Geolocation")
 
 XPIDL_SOURCES += [
-    'nsIDOMGeoGeolocation.idl',
     'nsIDOMGeoPosition.idl',
     'nsIDOMGeoPositionCallback.idl',
     'nsIDOMGeoPositionCoords.idl',
     'nsIDOMGeoPositionErrorCallback.idl',
 ]
 
 XPIDL_MODULE = 'dom_geolocation'
 
deleted file mode 100644
--- a/dom/interfaces/geolocation/nsIDOMGeoGeolocation.idl
+++ /dev/null
@@ -1,29 +0,0 @@
-/* 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 "domstubs.idl"
-
-interface nsIDOMGeoPositionCallback;
-interface nsIDOMGeoPositionErrorCallback;
-
-%{C++
-namespace mozilla {
-namespace dom {
-struct PositionOptions;
-} // namespace dom
-} // namespace mozilla
-
-#include "mozilla/UniquePtr.h"
-%}
-
-native PositionOptionsRef(mozilla::UniquePtr<mozilla::dom::PositionOptions>&&);
-
-[builtinclass, uuid(9142ab45-0ab5-418c-9bab-338a6d271d4f)]
-interface nsIDOMGeoGeolocation : nsISupports
-{
-  int32_t watchPosition(in nsIDOMGeoPositionCallback callback,
-                        in nsIDOMGeoPositionErrorCallback errorCallback,
-                        in PositionOptionsRef options);
-  void clearWatch(in long watchId);
-};
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -3837,19 +3837,17 @@ AddGeolocationListener(nsIDOMGeoPosition
                        bool highAccuracy)
 {
   RefPtr<Geolocation> geo = Geolocation::NonWindowSingleton();
 
   UniquePtr<PositionOptions> options = MakeUnique<PositionOptions>();
   options->mTimeout = 0;
   options->mMaximumAge = 0;
   options->mEnableHighAccuracy = highAccuracy;
-  int32_t retval = 1;
-  geo->WatchPosition(watcher, errorCallBack, std::move(options), &retval);
-  return retval;
+  return geo->WatchPosition(watcher, errorCallBack, std::move(options));
 }
 
 mozilla::ipc::IPCResult
 ContentParent::RecvAddGeolocationListener(const IPC::Principal& aPrincipal,
                                           const bool& aHighAccuracy)
 {
   // To ensure no geolocation updates are skipped, we always force the
   // creation of a new listener.