Back out 0014798942e0 (bug 1238427) for its bad implicit conversion constructor for 'TimerCallbackHolder'
authorPhil Ringnalda <philringnalda@gmail.com>
Wed, 20 Jan 2016 21:17:44 -0800
changeset 303105 f87d296b05288411bce7a722e232e71ffe088962
parent 303104 9e771bb631ce8d732af7d389837aed8561ac2bf6
child 303106 a24d6c2b7525f4e1f5a32c3d54444f01c09e82fe
push id8978
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 14:05:32 +0000
treeherdermozilla-aurora@b9a803752a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1238427
milestone46.0a1
backs out0014798942e0d6a257c3524c6dc1052d08877122
Back out 0014798942e0 (bug 1238427) for its bad implicit conversion constructor for 'TimerCallbackHolder' CLOSED TREE
dom/geolocation/nsGeolocation.cpp
dom/tests/browser/browser.ini
dom/tests/browser/browser_bug1238427.js
dom/tests/browser/geo_leak_test.html
--- a/dom/geolocation/nsGeolocation.cpp
+++ b/dom/geolocation/nsGeolocation.cpp
@@ -26,17 +26,16 @@
 #include "nsThreadUtils.h"
 #include "mozilla/HalWakeLock.h"
 #include "mozilla/Hal.h"
 #include "mozilla/Services.h"
 #include "mozilla/unused.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/dom/Event.h"
-#include "mozilla/WeakPtr.h"
 #include "mozilla/dom/PermissionMessageUtils.h"
 #include "mozilla/dom/SettingChangeNotificationBinding.h"
 #include "mozilla/dom/WakeLock.h"
 
 #include "nsJSUtils.h"
 #include "prdtoa.h"
 
 class nsIPrincipal;
@@ -71,67 +70,48 @@ class nsIPrincipal;
 
 using mozilla::Unused;          // <snicker>
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::hal;
 
 class nsGeolocationRequest final
  : public nsIContentPermissionRequest
+ , public nsITimerCallback
  , public nsIGeolocationUpdate
- , public SupportsWeakPtr<nsGeolocationRequest>
 {
  public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSICONTENTPERMISSIONREQUEST
+  NS_DECL_NSITIMERCALLBACK
   NS_DECL_NSIGEOLOCATIONUPDATE
 
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGeolocationRequest, nsIContentPermissionRequest)
 
   nsGeolocationRequest(Geolocation* aLocator,
                        const GeoPositionCallback& aCallback,
                        const GeoPositionErrorCallback& aErrorCallback,
                        PositionOptions* aOptions,
                        uint8_t aProtocolType,
                        bool aWatchPositionRequest = false,
                        int32_t aWatchId = 0);
-
-  MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsGeolocationRequest)
-
   void Shutdown();
 
   void SendLocation(nsIDOMGeoPosition* aLocation);
   bool WantsHighAccuracy() {return !mShutdown && mOptions && mOptions->mEnableHighAccuracy;}
   void SetTimeoutTimer();
   void StopTimeoutTimer();
   void NotifyErrorAndShutdown(uint16_t);
   nsIPrincipal* GetPrincipal();
 
   bool IsWatch() { return mIsWatchPositionRequest; }
   int32_t WatchId() { return mWatchId; }
  private:
   virtual ~nsGeolocationRequest();
 
-  class TimerCallbackHolder final : public nsITimerCallback
-  {
-  public:
-    NS_DECL_ISUPPORTS
-    NS_DECL_NSITIMERCALLBACK
-
-    TimerCallbackHolder(nsGeolocationRequest* aRequest)
-      : mRequest(aRequest)
-    {}
-
-  private:
-    ~TimerCallbackHolder() {}
-    WeakPtr<nsGeolocationRequest> mRequest;
-  };
-
-  void Notify();
-
   already_AddRefed<nsIDOMGeoPosition> AdjustedLocation(nsIDOMGeoPosition*);
 
   bool mIsWatchPositionRequest;
 
   nsCOMPtr<nsITimer> mTimeoutTimer;
   GeoPositionCallback mCallback;
   GeoPositionErrorCallback mErrorCallback;
   nsAutoPtr<PositionOptions> mOptions;
@@ -394,35 +374,36 @@ nsGeolocationRequest::nsGeolocationReque
     if (window) {
       mRequester = new nsContentPermissionRequester(window);
     }
   }
 }
 
 nsGeolocationRequest::~nsGeolocationRequest()
 {
-  StopTimeoutTimer();
 }
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGeolocationRequest)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentPermissionRequest)
   NS_INTERFACE_MAP_ENTRY(nsIContentPermissionRequest)
+  NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
   NS_INTERFACE_MAP_ENTRY(nsIGeolocationUpdate)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGeolocationRequest)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsGeolocationRequest)
 
 NS_IMPL_CYCLE_COLLECTION(nsGeolocationRequest, mCallback, mErrorCallback, mLocator)
 
-void
-nsGeolocationRequest::Notify()
+NS_IMETHODIMP
+nsGeolocationRequest::Notify(nsITimer* aTimer)
 {
   StopTimeoutTimer();
   NotifyErrorAndShutdown(nsIDOMGeoPositionError::TIMEOUT);
+  return NS_OK;
 }
 
 void
 nsGeolocationRequest::NotifyErrorAndShutdown(uint16_t aErrorCode)
 {
   MOZ_ASSERT(!mShutdown, "timeout after shutdown");
 
   if (!mIsWatchPositionRequest) {
@@ -575,18 +556,17 @@ nsGeolocationRequest::SetTimeoutTimer()
 
     if (timeout < 0) {
       timeout = 0;
     } else if (timeout < 10) {
       timeout = 10;
     }
 
     mTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
-    RefPtr<TimerCallbackHolder> holder = new TimerCallbackHolder(this);
-    mTimeoutTimer->InitWithCallback(holder, timeout, nsITimer::TYPE_ONE_SHOT);
+    mTimeoutTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT);
   }
 }
 
 void
 nsGeolocationRequest::StopTimeoutTimer()
 {
   if (mTimeoutTimer) {
     mTimeoutTimer->Cancel();
@@ -756,45 +736,31 @@ nsGeolocationRequest::NotifyError(uint16
 }
 
 void
 nsGeolocationRequest::Shutdown()
 {
   MOZ_ASSERT(!mShutdown, "request shutdown twice");
   mShutdown = true;
 
-  StopTimeoutTimer();
+  if (mTimeoutTimer) {
+    mTimeoutTimer->Cancel();
+    mTimeoutTimer = nullptr;
+  }
 
   // If there are no other high accuracy requests, the geolocation service will
   // notify the provider to switch to the default accuracy.
   if (mOptions && mOptions->mEnableHighAccuracy) {
     RefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
     if (gs) {
       gs->UpdateAccuracy();
     }
   }
 }
 
-
-////////////////////////////////////////////////////
-// nsGeolocationRequest::TimerCallbackHolder
-////////////////////////////////////////////////////
-
-NS_IMPL_ISUPPORTS(nsGeolocationRequest::TimerCallbackHolder, nsISupports, nsITimerCallback)
-
-NS_IMETHODIMP
-nsGeolocationRequest::TimerCallbackHolder::Notify(nsITimer*)
-{
-  if (mRequest) {
-    mRequest->Notify();
-  }
-  return NS_OK;
-}
-
-
 ////////////////////////////////////////////////////
 // nsGeolocationService
 ////////////////////////////////////////////////////
 NS_INTERFACE_MAP_BEGIN(nsGeolocationService)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGeolocationUpdate)
   NS_INTERFACE_MAP_ENTRY(nsIGeolocationUpdate)
   NS_INTERFACE_MAP_ENTRY(nsIObserver)
 NS_INTERFACE_MAP_END
--- a/dom/tests/browser/browser.ini
+++ b/dom/tests/browser/browser.ini
@@ -2,31 +2,29 @@
 skip-if = e10s # Bug ?????? - most of these tests fail for currently unknown reasons.
 support-files =
   browser_frame_elements.html
   page_privatestorageevent.html
   position.html
   test-console-api.html
   test_bug1004814.html
   worker_bug1004814.js
-  geo_leak_test.html
 
 [browser_test_toolbars_visibility.js]
 support-files =
   test_new_window_from_content_child.html
 [browser_bug1008941_dismissGeolocationHanger.js]
 skip-if = buildapp == 'mulet'
 [browser_test__content.js]
 [browser_ConsoleAPITests.js]
 [browser_ConsoleStorageAPITests.js]
 [browser_ConsoleStoragePBTest_perwindowpb.js]
 [browser_autofocus_background.js]
 skip-if= buildapp == 'mulet'
 [browser_autofocus_preference.js]
-[browser_bug1238427.js]
 [browser_bug396843.js]
 [browser_focus_steal_from_chrome.js]
 [browser_focus_steal_from_chrome_during_mousedown.js]
 [browser_frame_elements.js]
 [browser_localStorage_privatestorageevent.js]
 [browser_test_new_window_from_content.js]
 skip-if = (toolkit == 'android' || buildapp == 'b2g' || buildapp == 'mulet')
 support-files =
deleted file mode 100644
--- a/dom/tests/browser/browser_bug1238427.js
+++ /dev/null
@@ -1,31 +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/.
- */
-
-"use strict";
-
-const TEST_URI = "http://example.com/" +
-                 "browser/dom/tests/browser/geo_leak_test.html";
-
-const BASE_GEO_URL = "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs";
-
-add_task(function* () {
-  Services.prefs.setBoolPref("geo.prompt.testing", true);
-  Services.prefs.setBoolPref("geo.prompt.testing.allow", true);
-
-  // Make the geolocation provider responder very slowly to ensure that
-  // it does not reply before we close the tab.
-  Services.prefs.setCharPref("geo.wifi.uri", BASE_GEO_URL + "?delay=100000");
-
-  // Open the test URI and close it. The test harness will make sure that the
-  // page is cleaned up after some GCs. If geolocation is not shut down properly,
-  // it will show up as a non-shutdown leak.
-  yield BrowserTestUtils.withNewTab({
-    gBrowser,
-    url: TEST_URI
-  }, function* (browser) { /* ... */ });
-
-  ok(true, "Need to do something in this test");
-});
-
deleted file mode 100644
--- a/dom/tests/browser/geo_leak_test.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
-<title>Geolocation incomplete position leak test</title>
-<script type="text/javascript">
-
-function successCallback(position) {}
-function errorCallback() {}
-
-function init() {
-  navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
-}
-</script>
-</head>
-<body onload="init()">
-</body>
-</html>