Bug 1572292 - Rewrite EnsureHSTSDataReadyNative r=Ehsan
authorKershaw Chang <kershaw@mozilla.com>
Thu, 08 Aug 2019 23:47:38 +0000
changeset 487451 028f522d1e6aaa4cb7589588859cbf0db3010b30
parent 487450 9f551fcee77ecd379e7df7d85102f72b6e9ec8ab
child 487452 f59b7693d943faefcf49e13212df379eb5979895
child 487536 505047c3a1bdc160d7ac7d6e38318567e7a95f04
push id92260
push userkjang@mozilla.com
push dateMon, 12 Aug 2019 12:13:23 +0000
treeherderautoland@028f522d1e6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1572292
milestone70.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 1572292 - Rewrite EnsureHSTSDataReadyNative r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D41171
netwerk/ipc/NeckoParent.cpp
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
netwerk/protocol/http/nsIHttpProtocolHandler.idl
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -977,17 +977,17 @@ mozilla::ipc::IPCResult NeckoParent::Rec
 
 mozilla::ipc::IPCResult NeckoParent::RecvEnsureHSTSData(
     EnsureHSTSDataResolver&& aResolver) {
   auto callback = [aResolver{std::move(aResolver)}](bool aResult) {
     aResolver(aResult);
   };
   RefPtr<HSTSDataCallbackWrapper> wrapper =
       new HSTSDataCallbackWrapper(std::move(callback));
-  gHttpHandler->EnsureHSTSDataReadyNative(wrapper.forget());
+  gHttpHandler->EnsureHSTSDataReadyNative(wrapper);
   return IPC_OK();
 }
 
 PProxyConfigLookupParent* NeckoParent::AllocPProxyConfigLookupParent() {
 #ifdef MOZ_WEBRTC
   RefPtr<ProxyConfigLookupParent> actor = new ProxyConfigLookupParent();
   return actor.forget().take();
 #else
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -2530,36 +2530,36 @@ nsHttpsHandler::NewChannel(nsIURI* aURI,
 
 NS_IMETHODIMP
 nsHttpsHandler::AllowPort(int32_t aPort, const char* aScheme, bool* _retval) {
   // don't override anything.
   *_retval = false;
   return NS_OK;
 }
 
-nsresult nsHttpHandler::EnsureHSTSDataReadyNative(
-    already_AddRefed<mozilla::net::HSTSDataCallbackWrapper> aCallback) {
+NS_IMETHODIMP
+nsHttpHandler::EnsureHSTSDataReadyNative(
+    RefPtr<mozilla::net::HSTSDataCallbackWrapper> aCallback) {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsCOMPtr<nsIURI> uri;
   nsresult rv = NS_NewURI(getter_AddRefs(uri), "http://example.com");
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool shouldUpgrade = false;
   bool willCallback = false;
   OriginAttributes originAttributes;
-  RefPtr<HSTSDataCallbackWrapper> callback = aCallback;
-  auto func = [callback](bool aResult, nsresult aStatus) {
+  auto func = [callback(aCallback)](bool aResult, nsresult aStatus) {
     callback->DoCallback(aResult);
   };
   rv = NS_ShouldSecureUpgrade(uri, nullptr, nullptr, false, false,
                               originAttributes, shouldUpgrade, std::move(func),
                               willCallback);
   if (NS_FAILED(rv) || !willCallback) {
-    callback->DoCallback(false);
+    aCallback->DoCallback(false);
     return rv;
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsHttpHandler::EnsureHSTSDataReady(JSContext* aCx, Promise** aPromise) {
@@ -2595,17 +2595,17 @@ nsHttpHandler::EnsureHSTSDataReady(JSCon
 
   auto callback = [promise(promise)](bool aResult) {
     promise->MaybeResolve(aResult);
   };
 
   RefPtr<HSTSDataCallbackWrapper> wrapper =
       new HSTSDataCallbackWrapper(std::move(callback));
   promise.forget(aPromise);
-  return EnsureHSTSDataReadyNative(wrapper.forget());
+  return EnsureHSTSDataReadyNative(wrapper);
 }
 
 void nsHttpHandler::ShutdownConnectionManager() {
   // ensure connection manager is shutdown
   if (mConnMgr) {
     nsresult rv = mConnMgr->Shutdown();
     if (NS_FAILED(rv)) {
       LOG(
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -762,20 +762,16 @@ class nsHttpHandler final : public nsIHt
   TimeStamp mLastActiveTabLoadOptimizationHit;
 
  public:
   MOZ_MUST_USE nsresult NewChannelId(uint64_t& channelId);
 
   void BlacklistSpdy(const nsHttpConnectionInfo* ci);
   MOZ_MUST_USE bool IsSpdyBlacklisted(const nsHttpConnectionInfo* ci);
 
-  virtual nsresult EnsureHSTSDataReadyNative(
-      already_AddRefed<mozilla::net::HSTSDataCallbackWrapper> aCallback)
-      override;
-
  private:
   nsTHashtable<nsCStringHashKey> mBlacklistedSpdyOrigins;
 
   bool mThroughCaptivePortal;
 };
 
 extern StaticRefPtr<nsHttpHandler> gHttpHandler;
 
@@ -797,21 +793,16 @@ class nsHttpsHandler : public nsIHttpPro
   NS_DECL_NSIPROTOCOLHANDLER
   NS_FORWARD_NSIPROXIEDPROTOCOLHANDLER(gHttpHandler->)
   NS_FORWARD_NSIHTTPPROTOCOLHANDLER(gHttpHandler->)
   NS_FORWARD_NSISPECULATIVECONNECT(gHttpHandler->)
 
   nsHttpsHandler() = default;
 
   MOZ_MUST_USE nsresult Init();
-  virtual nsresult EnsureHSTSDataReadyNative(
-      already_AddRefed<mozilla::net::HSTSDataCallbackWrapper> aCallback)
-      override {
-    return gHttpHandler->EnsureHSTSDataReadyNative(std::move(aCallback));
-  }
 };
 
 //-----------------------------------------------------------------------------
 // HSTSDataCallbackWrapper - A threadsafe helper class to wrap the callback.
 //
 // We need this because dom::promise and EnsureHSTSDataResolver are not
 // threadsafe.
 //-----------------------------------------------------------------------------
--- a/netwerk/protocol/http/nsIHttpProtocolHandler.idl
+++ b/netwerk/protocol/http/nsIHttpProtocolHandler.idl
@@ -7,17 +7,18 @@
 
 %{C++
 namespace mozilla {
 namespace net {
 class HSTSDataCallbackWrapper;
 }
 }
 %}
-[ptr] native HSTSDataCallbackWrapperPtr(mozilla::net::HSTSDataCallbackWrapper);
+
+native HSTSDataCallbackWrapperAlreadyAddRefed(RefPtr<mozilla::net::HSTSDataCallbackWrapper>);
 
 [scriptable, builtinclass, uuid(c48126d9-2ddd-485b-a51a-378e917e75f8)]
 interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
 {
     /**
      * Get the HTTP advertised user agent string.
      */
     [must_use] readonly attribute ACString userAgent;
@@ -68,20 +69,18 @@ interface nsIHttpProtocolHandler : nsIPr
      * See bug 1521729 for more details.
      */
     [implicit_jscontext]
     Promise EnsureHSTSDataReady();
 
     /**
      * A C++ friendly version of EnsureHSTSDataReady
      */
-    %{C++
-        virtual nsresult EnsureHSTSDataReadyNative(
-            already_AddRefed<mozilla::net::HSTSDataCallbackWrapper> aCallback) = 0;
-    %}
+    [noscript]
+    void EnsureHSTSDataReadyNative(in HSTSDataCallbackWrapperAlreadyAddRefed aCallback);
 };
 
 %{C++
 // ----------- Categories -----------
 /**
  * At initialization time, the HTTP handler will initialize each service
  * registered under this category:
  */