Bug 1300474 - Replace nsAutoPtr usages in geolocation with UniquePtr. r?jdm
MozReview-Commit-ID: KcJj8VKjLpj
--- a/dom/geolocation/nsGeolocation.cpp
+++ b/dom/geolocation/nsGeolocation.cpp
@@ -3,18 +3,17 @@
/* 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 "nsXULAppAPI.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/Telemetry.h"
-
-#include "nsAutoPtr.h"
+#include "mozilla/UniquePtr.h"
#include "nsGeolocation.h"
#include "nsDOMClassInfoID.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsContentUtils.h"
#include "nsContentPermissionHelper.h"
#include "nsIDocument.h"
@@ -69,17 +68,17 @@ class nsGeolocationRequest final
NS_DECL_NSICONTENTPERMISSIONREQUEST
NS_DECL_NSIGEOLOCATIONUPDATE
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGeolocationRequest, nsIContentPermissionRequest)
nsGeolocationRequest(Geolocation* aLocator,
GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
- nsAutoPtr<PositionOptions>&& aOptions,
+ UniquePtr<PositionOptions>&& aOptions,
uint8_t aProtocolType,
bool aWatchPositionRequest = false,
int32_t aWatchId = 0);
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsGeolocationRequest)
void Shutdown();
@@ -112,30 +111,30 @@ class nsGeolocationRequest final
void Notify();
bool mIsWatchPositionRequest;
nsCOMPtr<nsITimer> mTimeoutTimer;
GeoPositionCallback mCallback;
GeoPositionErrorCallback mErrorCallback;
- nsAutoPtr<PositionOptions> mOptions;
+ UniquePtr<PositionOptions> mOptions;
RefPtr<Geolocation> mLocator;
int32_t mWatchId;
bool mShutdown;
nsCOMPtr<nsIContentPermissionRequester> mRequester;
uint8_t mProtocolType;
};
-static nsAutoPtr<PositionOptions>
+static UniquePtr<PositionOptions>
CreatePositionOptionsCopy(const PositionOptions& aOptions)
{
- nsAutoPtr<PositionOptions> geoOptions(new PositionOptions());
+ UniquePtr<PositionOptions> geoOptions = MakeUnique<PositionOptions>();
geoOptions->mEnableHighAccuracy = aOptions.mEnableHighAccuracy;
geoOptions->mMaximumAge = aOptions.mMaximumAge;
geoOptions->mTimeout = aOptions.mTimeout;
return geoOptions;
}
@@ -286,17 +285,17 @@ PositionError::NotifyCallback(const GeoP
}
////////////////////////////////////////////////////
// nsGeolocationRequest
////////////////////////////////////////////////////
nsGeolocationRequest::nsGeolocationRequest(Geolocation* aLocator,
GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
- nsAutoPtr<PositionOptions>&& aOptions,
+ UniquePtr<PositionOptions>&& aOptions,
uint8_t aProtocolType,
bool aWatchPositionRequest,
int32_t aWatchId)
: mIsWatchPositionRequest(aWatchPositionRequest),
mCallback(Move(aCallback)),
mErrorCallback(Move(aErrorCallback)),
mOptions(Move(aOptions)),
mLocator(aLocator),
@@ -1203,29 +1202,29 @@ Geolocation::GetCurrentPosition(Position
}
return;
}
NS_IMETHODIMP
Geolocation::GetCurrentPosition(nsIDOMGeoPositionCallback* aCallback,
nsIDOMGeoPositionErrorCallback* aErrorCallback,
- nsAutoPtr<PositionOptions>&& aOptions)
+ UniquePtr<PositionOptions>&& aOptions)
{
NS_ENSURE_ARG_POINTER(aCallback);
return GetCurrentPosition(GeoPositionCallback(aCallback),
GeoPositionErrorCallback(aErrorCallback),
Move(aOptions));
}
nsresult
Geolocation::GetCurrentPosition(GeoPositionCallback callback,
GeoPositionErrorCallback errorCallback,
- nsAutoPtr<PositionOptions>&& options)
+ UniquePtr<PositionOptions>&& options)
{
if (mPendingCallbacks.Length() > MAX_GEO_REQUESTS_PER_WINDOW) {
return NS_ERROR_NOT_AVAILABLE;
}
// After this we hand over ownership of options to our nsGeolocationRequest.
// Count the number of requests per protocol/scheme.
@@ -1281,30 +1280,30 @@ Geolocation::WatchPosition(PositionCallb
}
return ret;
}
NS_IMETHODIMP
Geolocation::WatchPosition(nsIDOMGeoPositionCallback *aCallback,
nsIDOMGeoPositionErrorCallback *aErrorCallback,
- nsAutoPtr<PositionOptions>&& aOptions,
+ UniquePtr<PositionOptions>&& aOptions,
int32_t* aRv)
{
NS_ENSURE_ARG_POINTER(aCallback);
return WatchPosition(GeoPositionCallback(aCallback),
GeoPositionErrorCallback(aErrorCallback),
Move(aOptions), aRv);
}
nsresult
Geolocation::WatchPosition(GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
- nsAutoPtr<PositionOptions>&& aOptions,
+ UniquePtr<PositionOptions>&& aOptions,
int32_t* aRv)
{
if (mWatchingCallbacks.Length() > MAX_GEO_REQUESTS_PER_WINDOW) {
return NS_ERROR_NOT_AVAILABLE;
}
// Count the number of requests per protocol/scheme.
Telemetry::Accumulate(Telemetry::GEOLOCATION_WATCHPOSITION_SECURE_ORIGIN,
--- a/dom/geolocation/nsGeolocation.h
+++ b/dom/geolocation/nsGeolocation.h
@@ -172,20 +172,20 @@ public:
bool HighAccuracyRequested();
private:
~Geolocation();
nsresult GetCurrentPosition(GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
- nsAutoPtr<PositionOptions>&& aOptions);
+ UniquePtr<PositionOptions>&& aOptions);
nsresult WatchPosition(GeoPositionCallback aCallback,
GeoPositionErrorCallback aErrorCallback,
- nsAutoPtr<PositionOptions>&& aOptions, int32_t* aRv);
+ UniquePtr<PositionOptions>&& aOptions, int32_t* aRv);
bool RegisterRequestWithPrompt(nsGeolocationRequest* request);
// Check if clearWatch is already called
bool IsAlreadyCleared(nsGeolocationRequest* aRequest);
// Two callback arrays. The first |mPendingCallbacks| holds objects for only
// one callback and then they are released/removed from the array. The second
--- a/dom/interfaces/geolocation/nsIDOMGeoGeolocation.idl
+++ b/dom/interfaces/geolocation/nsIDOMGeoGeolocation.idl
@@ -6,23 +6,23 @@
interface nsIDOMGeoPositionCallback;
interface nsIDOMGeoPositionErrorCallback;
%{C++
namespace mozilla {
namespace dom {
struct PositionOptions;
-}
-}
+} // namespace dom
+} // namespace mozilla
-template<class T> class nsAutoPtr;
+#include "mozilla/UniquePtr.h"
%}
-native PositionOptionsRef(nsAutoPtr<mozilla::dom::PositionOptions>&&);
+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 getCurrentPosition(in nsIDOMGeoPositionCallback callback,
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -3943,17 +3943,17 @@ AddGeolocationListener(nsIDOMGeoPosition
nsIDOMGeoPositionErrorCallback* errorCallBack,
bool highAccuracy)
{
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
if (!geo) {
return -1;
}
- nsAutoPtr<PositionOptions> options(new PositionOptions());
+ UniquePtr<PositionOptions> options = MakeUnique<PositionOptions>();
options->mTimeout = 0;
options->mMaximumAge = 0;
options->mEnableHighAccuracy = highAccuracy;
int32_t retval = 1;
geo->WatchPosition(watcher, errorCallBack, Move(options), &retval);
return retval;
}