netwerk/protocol/http/ClassifierDummyChannelParent.cpp
author Jeff Gilbert <jgilbert@mozilla.com>
Sun, 16 Feb 2020 04:07:20 +0000
changeset 514200 fb59957df14467695b956a7614faa7720c36b4cf
parent 510785 25b89047cf0d49734cbcd97c1351c17d39ab55a2
child 520372 8df44770d70f647742cefcae1e60150f66a35a48
permissions -rw-r--r--
Bug 1615851 - layer::Image::GetAsSourceSurface is fallible. r=lsalzman This fixes a crash, where we expected it to be infallible. Differential Revision: https://phabricator.services.mozilla.com/D63005

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "ClassifierDummyChannelParent.h"
#include "mozilla/net/AsyncUrlChannelClassifier.h"
#include "mozilla/Unused.h"
#include "nsIPrincipal.h"
#include "nsNetUtil.h"

namespace mozilla {
namespace net {

ClassifierDummyChannelParent::ClassifierDummyChannelParent()
    : mIPCActive(true) {}

ClassifierDummyChannelParent::~ClassifierDummyChannelParent() = default;

void ClassifierDummyChannelParent::Init(
    nsIURI* aURI, nsIURI* aTopWindowURI,
    nsIPrincipal* aContentBlockingAllowListPrincipal,
    nsresult aTopWindowURIResult, nsILoadInfo* aLoadInfo) {
  MOZ_ASSERT(mIPCActive);

  RefPtr<ClassifierDummyChannelParent> self = this;
  auto onExit =
      MakeScopeExit([self] { Unused << Send__delete__(self, false); });

  if (!aURI) {
    return;
  }

  RefPtr<ClassifierDummyChannel> channel = new ClassifierDummyChannel(
      aURI, aTopWindowURI, aContentBlockingAllowListPrincipal,
      aTopWindowURIResult, aLoadInfo);

  bool willCallback = NS_SUCCEEDED(AsyncUrlChannelClassifier::CheckChannel(
      channel, [self = std::move(self), channel]() {
        if (self->mIPCActive) {
          Unused << Send__delete__(self, channel->GetClassificationFlags());
        }
      }));

  if (willCallback) {
    onExit.release();
  }
}

void ClassifierDummyChannelParent::ActorDestroy(ActorDestroyReason aWhy) {
  mIPCActive = false;
}

}  // namespace net
}  // namespace mozilla