From c53f7f15b117ff996322947859255c1c48a1d020 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 1 Jun 2018 22:35:44 -0400 Subject: [PATCH] Bug 1466213 part 2. Remove nsIDOMGeoPositionError. r=qdot --- dom/geolocation/PositionError.cpp | 29 +++++-------------- dom/geolocation/PositionError.h | 12 ++++---- dom/geolocation/nsGeolocation.cpp | 14 ++++----- dom/interfaces/geolocation/moz.build | 1 - .../geolocation/nsIDOMGeoPositionError.idl | 24 --------------- .../nsIDOMGeoPositionErrorCallback.idl | 4 +-- dom/ipc/ContentParent.cpp | 10 ++----- dom/system/NetworkGeolocationProvider.js | 3 +- dom/system/linux/GpsdLocationProvider.cpp | 12 ++++---- .../mac/CoreLocationLocationProvider.mm | 4 +-- .../windows/WindowsLocationProvider.cpp | 6 ++-- .../geolocation/test_errorcheck.html | 7 +++-- .../test_geolocation_position_unavailable.js | 4 ++- 13 files changed, 45 insertions(+), 85 deletions(-) delete mode 100644 dom/interfaces/geolocation/nsIDOMGeoPositionError.idl diff --git a/dom/geolocation/PositionError.cpp b/dom/geolocation/PositionError.cpp index 38698fffeee3..1792d160571b 100644 --- a/dom/geolocation/PositionError.cpp +++ b/dom/geolocation/PositionError.cpp @@ -11,15 +11,10 @@ namespace mozilla { namespace dom { -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PositionError) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPositionError) - NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionError) -NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PositionError, mParent) -NS_IMPL_CYCLE_COLLECTING_ADDREF(PositionError) -NS_IMPL_CYCLE_COLLECTING_RELEASE(PositionError) +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PositionError, AddRef) +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PositionError, Release) PositionError::PositionError(Geolocation* aParent, int16_t aCode) : mCode(aCode) @@ -29,33 +24,23 @@ PositionError::PositionError(Geolocation* aParent, int16_t aCode) PositionError::~PositionError() = default; - -NS_IMETHODIMP -PositionError::GetCode(int16_t *aCode) -{ - NS_ENSURE_ARG_POINTER(aCode); - *aCode = Code(); - return NS_OK; -} - -NS_IMETHODIMP -PositionError::GetMessage(nsAString& aMessage) +void +PositionError::GetMessage(nsAString& aMessage) const { switch (mCode) { - case nsIDOMGeoPositionError::PERMISSION_DENIED: + case PositionErrorBinding::PERMISSION_DENIED: aMessage = NS_LITERAL_STRING("User denied geolocation prompt"); break; - case nsIDOMGeoPositionError::POSITION_UNAVAILABLE: + case PositionErrorBinding::POSITION_UNAVAILABLE: aMessage = NS_LITERAL_STRING("Unknown error acquiring position"); break; - case nsIDOMGeoPositionError::TIMEOUT: + case PositionErrorBinding::TIMEOUT: aMessage = NS_LITERAL_STRING("Position acquisition timed out"); break; default: break; } - return NS_OK; } nsWrapperCache* diff --git a/dom/geolocation/PositionError.h b/dom/geolocation/PositionError.h index 0ffa09b376fd..2f7de5bf376a 100644 --- a/dom/geolocation/PositionError.h +++ b/dom/geolocation/PositionError.h @@ -7,7 +7,6 @@ #ifndef mozilla_dom_PositionError_h #define mozilla_dom_PositionError_h -#include "nsIDOMGeoPositionError.h" #include "nsWrapperCache.h" #include "nsISupportsImpl.h" #include "nsCycleCollectionParticipant.h" @@ -21,14 +20,11 @@ class PositionErrorCallback; class Geolocation; typedef CallbackObjectHolder GeoPositionErrorCallback; -class PositionError final : public nsIDOMGeoPositionError, - public nsWrapperCache +class PositionError final : public nsWrapperCache { public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PositionError) - - NS_DECL_NSIDOMGEOPOSITIONERROR + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PositionError) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(PositionError) PositionError(Geolocation* aParent, int16_t aCode); @@ -40,6 +36,8 @@ public: return mCode; } + void GetMessage(nsAString& aMessage) const; + void NotifyCallback(const GeoPositionErrorCallback& callback); private: ~PositionError(); diff --git a/dom/geolocation/nsGeolocation.cpp b/dom/geolocation/nsGeolocation.cpp index 4154da993ad5..b27ac9392afe 100644 --- a/dom/geolocation/nsGeolocation.cpp +++ b/dom/geolocation/nsGeolocation.cpp @@ -10,6 +10,7 @@ #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/PositionError.h" +#include "mozilla/dom/PositionErrorBinding.h" #include "mozilla/Preferences.h" #include "mozilla/Services.h" #include "mozilla/Telemetry.h" @@ -22,7 +23,6 @@ #include "nsContentUtils.h" #include "nsGlobalWindow.h" #include "nsIDocument.h" -#include "nsIDOMGeoPositionError.h" #include "nsINamed.h" #include "nsIObserverService.h" #include "nsIScriptError.h" @@ -270,7 +270,7 @@ void nsGeolocationRequest::Notify() { SetTimeoutTimer(); - NotifyErrorAndShutdown(nsIDOMGeoPositionError::TIMEOUT); + NotifyErrorAndShutdown(PositionErrorBinding::TIMEOUT); } void @@ -346,7 +346,7 @@ nsGeolocationRequest::Cancel() return NS_OK; } - NotifyError(nsIDOMGeoPositionError::PERMISSION_DENIED); + NotifyError(PositionErrorBinding::PERMISSION_DENIED); return NS_OK; } @@ -414,7 +414,7 @@ nsGeolocationRequest::Allow(JS::HandleValue aChoices) // if it is not a watch request and timeout is 0, // invoke the errorCallback (if present) with TIMEOUT code if (mOptions && mOptions->mTimeout == 0 && !mIsWatchPositionRequest) { - NotifyError(nsIDOMGeoPositionError::TIMEOUT); + NotifyError(PositionErrorBinding::TIMEOUT); return NS_OK; } @@ -425,7 +425,7 @@ nsGeolocationRequest::Allow(JS::HandleValue aChoices) if (NS_FAILED(rv)) { // Location provider error - NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE); + NotifyError(PositionErrorBinding::POSITION_UNAVAILABLE); return NS_OK; } @@ -504,7 +504,7 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition) } if (!wrapped) { - NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE); + NotifyError(PositionErrorBinding::POSITION_UNAVAILABLE); return; } @@ -789,7 +789,7 @@ nsGeolocationService::StartDevice(nsIPrincipal *aPrincipal) if (NS_FAILED(rv = mProvider->Startup()) || NS_FAILED(rv = mProvider->Watch(this))) { - NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE); + NotifyError(PositionErrorBinding::POSITION_UNAVAILABLE); return rv; } diff --git a/dom/interfaces/geolocation/moz.build b/dom/interfaces/geolocation/moz.build index 827ccf858a4a..432eb74e113d 100644 --- a/dom/interfaces/geolocation/moz.build +++ b/dom/interfaces/geolocation/moz.build @@ -12,7 +12,6 @@ XPIDL_SOURCES += [ 'nsIDOMGeoPosition.idl', 'nsIDOMGeoPositionCallback.idl', 'nsIDOMGeoPositionCoords.idl', - 'nsIDOMGeoPositionError.idl', 'nsIDOMGeoPositionErrorCallback.idl', ] diff --git a/dom/interfaces/geolocation/nsIDOMGeoPositionError.idl b/dom/interfaces/geolocation/nsIDOMGeoPositionError.idl deleted file mode 100644 index a2405e28e796..000000000000 --- a/dom/interfaces/geolocation/nsIDOMGeoPositionError.idl +++ /dev/null @@ -1,24 +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" - -// undef the GetMessage macro defined in winuser.h from the MS Platform SDK -%{C++ -#ifdef GetMessage -#undef GetMessage -#endif -%} - -[shim(PositionError), uuid(85255CC3-07BA-49FD-BC9B-18D2963DAF7F)] -interface nsIDOMGeoPositionError : nsISupports -{ - const unsigned short PERMISSION_DENIED = 1; - const unsigned short POSITION_UNAVAILABLE = 2; - const unsigned short TIMEOUT = 3; - - readonly attribute short code; - readonly attribute AString message; -}; diff --git a/dom/interfaces/geolocation/nsIDOMGeoPositionErrorCallback.idl b/dom/interfaces/geolocation/nsIDOMGeoPositionErrorCallback.idl index e2b707d8a9b2..62146d4394a7 100644 --- a/dom/interfaces/geolocation/nsIDOMGeoPositionErrorCallback.idl +++ b/dom/interfaces/geolocation/nsIDOMGeoPositionErrorCallback.idl @@ -5,9 +5,9 @@ #include "domstubs.idl" -interface nsIDOMGeoPositionError; +webidl PositionError; [scriptable, function, uuid(7D9B09D9-4843-43EB-A7A7-67F7DDA6B3C4)] interface nsIDOMGeoPositionErrorCallback : nsISupports { - void handleEvent(in nsIDOMGeoPositionError positionError); + void handleEvent(in PositionError positionError); }; diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index c331e21a6660..d79f7be3fc1a 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -51,6 +51,7 @@ #include "mozilla/dom/PContentBridgeParent.h" #include "mozilla/dom/PContentPermissionRequestParent.h" #include "mozilla/dom/PCycleCollectWithLogsParent.h" +#include "mozilla/dom/PositionError.h" #include "mozilla/dom/ServiceWorkerRegistrar.h" #include "mozilla/dom/power/PowerManagerService.h" #include "mozilla/dom/Permissions.h" @@ -123,7 +124,6 @@ #include "nsIDocShellTreeOwner.h" #include "nsIDocument.h" #include "nsIDOMGeoGeolocation.h" -#include "nsIDOMGeoPositionError.h" #include "nsIDragService.h" #include "mozilla/dom/WakeLock.h" #include "nsIDOMWindow.h" @@ -3895,13 +3895,9 @@ ContentParent::HandleEvent(nsIDOMGeoPosition* postion) } NS_IMETHODIMP -ContentParent::HandleEvent(nsIDOMGeoPositionError* postionError) +ContentParent::HandleEvent(PositionError* positionError) { - int16_t errorCode; - nsresult rv; - rv = postionError->GetCode(&errorCode); - NS_ENSURE_SUCCESS(rv,rv); - Unused << SendGeolocationError(errorCode); + Unused << SendGeolocationError(positionError->Code()); return NS_OK; } diff --git a/dom/system/NetworkGeolocationProvider.js b/dom/system/NetworkGeolocationProvider.js index bfa5a2aad851..40119de5025f 100644 --- a/dom/system/NetworkGeolocationProvider.js +++ b/dom/system/NetworkGeolocationProvider.js @@ -9,7 +9,8 @@ ChromeUtils.import("resource://gre/modules/Services.jsm"); Cu.importGlobalProperties(["XMLHttpRequest"]); -const POSITION_UNAVAILABLE = Ci.nsIDOMGeoPositionError.POSITION_UNAVAILABLE; +// PositionError has no interface object, so we can't use that here. +const POSITION_UNAVAILABLE = 2; var gLoggingEnabled = false; diff --git a/dom/system/linux/GpsdLocationProvider.cpp b/dom/system/linux/GpsdLocationProvider.cpp index eeee806dc174..759d8f8c932c 100644 --- a/dom/system/linux/GpsdLocationProvider.cpp +++ b/dom/system/linux/GpsdLocationProvider.cpp @@ -11,8 +11,8 @@ #include "mozilla/Atomics.h" #include "mozilla/FloatingPoint.h" #include "mozilla/LazyIdleThread.h" +#include "mozilla/dom/PositionErrorBinding.h" #include "nsGeoPosition.h" -#include "nsIDOMGeoPositionError.h" #include "nsProxyRelease.h" #include "nsThreadUtils.h" @@ -185,7 +185,7 @@ public: err = PollLoop5(); break; default: - err = nsIDOMGeoPositionError::POSITION_UNAVAILABLE; + err = PositionErrorBinding::POSITION_UNAVAILABLE; break; } @@ -301,7 +301,7 @@ protected: return err; #else - return nsIDOMGeoPositionError::POSITION_UNAVAILABLE; + return PositionErrorBinding::POSITION_UNAVAILABLE; #endif // GPSD_MAJOR_API_VERSION } @@ -313,13 +313,13 @@ protected: case EPERM: MOZ_FALLTHROUGH; case EROFS: - return nsIDOMGeoPositionError::PERMISSION_DENIED; + return PositionErrorBinding::PERMISSION_DENIED; case ETIME: MOZ_FALLTHROUGH; case ETIMEDOUT: - return nsIDOMGeoPositionError::TIMEOUT; + return PositionErrorBinding::TIMEOUT; default: - return nsIDOMGeoPositionError::POSITION_UNAVAILABLE; + return PositionErrorBinding::POSITION_UNAVAILABLE; } } diff --git a/dom/system/mac/CoreLocationLocationProvider.mm b/dom/system/mac/CoreLocationLocationProvider.mm index 5cb3d4f93eec..0a4e26047a0f 100644 --- a/dom/system/mac/CoreLocationLocationProvider.mm +++ b/dom/system/mac/CoreLocationLocationProvider.mm @@ -9,11 +9,11 @@ #include "nsGeoPosition.h" #include "nsIConsoleService.h" #include "nsServiceManagerUtils.h" -#include "nsIDOMGeoPositionError.h" #include "CoreLocationLocationProvider.h" #include "nsCocoaFeatures.h" #include "prtime.h" #include "mozilla/Telemetry.h" +#include "mozilla/dom/PositionErrorBinding.h" #include "MLSFallback.h" #include @@ -67,7 +67,7 @@ static const CLLocationAccuracy kDEFAULT_ACCURACY = kCLLocationAccuracyNearestTe console->LogStringMessage(NS_ConvertUTF8toUTF16([message UTF8String]).get()); if ([aError code] == kCLErrorDenied) { - mProvider->NotifyError(nsIDOMGeoPositionError::PERMISSION_DENIED); + mProvider->NotifyError(dom::PositionErrorBinding::PERMISSION_DENIED); return; } diff --git a/dom/system/windows/WindowsLocationProvider.cpp b/dom/system/windows/WindowsLocationProvider.cpp index fa7f8d8be1d8..e9ccdc7a3548 100644 --- a/dom/system/windows/WindowsLocationProvider.cpp +++ b/dom/system/windows/WindowsLocationProvider.cpp @@ -6,11 +6,11 @@ #include "WindowsLocationProvider.h" #include "nsGeoPosition.h" -#include "nsIDOMGeoPositionError.h" #include "nsComponentManagerUtils.h" #include "prtime.h" #include "MLSFallback.h" #include "mozilla/Telemetry.h" +#include "mozilla/dom/PositionErrorBinding.h" namespace mozilla { namespace dom { @@ -129,11 +129,11 @@ LocationEvent::OnStatusChanged(REFIID aReportType, uint16_t err; switch (aStatus) { case REPORT_ACCESS_DENIED: - err = nsIDOMGeoPositionError::PERMISSION_DENIED; + err = PositionErrorBinding::PERMISSION_DENIED; break; case REPORT_NOT_SUPPORTED: case REPORT_ERROR: - err = nsIDOMGeoPositionError::POSITION_UNAVAILABLE; + err = PositionErrorBinding::POSITION_UNAVAILABLE; break; default: return S_OK; diff --git a/dom/tests/mochitest/geolocation/test_errorcheck.html b/dom/tests/mochitest/geolocation/test_errorcheck.html index ffe5ce882b7b..cdab79c490d9 100644 --- a/dom/tests/mochitest/geolocation/test_errorcheck.html +++ b/dom/tests/mochitest/geolocation/test_errorcheck.html @@ -30,8 +30,11 @@ function test1() { } function errorCallback(error) { - is(error.code, - SpecialPowers.Ci.nsIDOMGeoPositionError.POSITION_UNAVAILABLE, "Geolocation error handler fired"); + // PositionError has no interface object, so we can't get constants off that. + is(error.code, error.POSITION_UNAVAILABLE, + "Geolocation error handler fired"); + is(error.POSITION_UNAVAILABLE, 2, + "Value of POSITION_UNAVAILABLE should be correct"); SimpleTest.finish(); } diff --git a/dom/tests/unit/test_geolocation_position_unavailable.js b/dom/tests/unit/test_geolocation_position_unavailable.js index 74440f86206f..de0a5fd5e026 100644 --- a/dom/tests/unit/test_geolocation_position_unavailable.js +++ b/dom/tests/unit/test_geolocation_position_unavailable.js @@ -4,7 +4,9 @@ function successCallback() { } function errorCallback(err) { - Assert.equal(Ci.nsIDOMGeoPositionError.POSITION_UNAVAILABLE, err.code); + // PositionError has no interface object, so we can't get constants off that. + Assert.equal(err.POSITION_UNAVAILABLE, err.code); + Assert.equal(2, err.code); do_test_finished(); }