DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "mozilla/dom/PlayPromise.h"
#include "mozilla/dom/PlayPromise.h"
#include "mozilla/Logging.h"
#include "mozilla/Telemetry.h"

extern mozilla::LazyLogModule gMediaElementLog;

#define PLAY_PROMISE_LOG(msg, ...) \
  MOZ_LOG(gMediaElementLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
  MOZ_LOG(gMediaElementLog, LogLevel::Debug, (msg, ##__VA_ARGS__))

namespace mozilla {
namespace dom {

PlayPromise::PlayPromise(nsIGlobalObject* aGlobal) : Promise(aGlobal) {}
PlayPromise::PlayPromise(nsIGlobalObject* aGlobal) : Promise(aGlobal) {}

PlayPromise::~PlayPromise() {
  if (!mFulfilled && PromiseObj()) {
    MaybeReject(NS_ERROR_DOM_ABORT_ERR);
  }
  }
}

/* static */
already_AddRefed<PlayPromise> PlayPromise::Create(nsIGlobalObject* aGlobal,
                                                  ErrorResult& aRv) {
                                                  ErrorResult& aRv) {
  RefPtr<PlayPromise> promise = new PlayPromise(aGlobal);
  promise->CreateWrapper(aRv);
  return aRv.Failed() ? nullptr : promise.forget();
}

void PlayPromise::MaybeResolveWithUndefined() {
void PlayPromise::MaybeResolveWithUndefined() {
  if (mFulfilled) {
    return;
  }
  mFulfilled = true;
  PLAY_PROMISE_LOG("PlayPromise %p resolved with undefined", this);
  PLAY_PROMISE_LOG("PlayPromise %p resolved with undefined", this);
  auto reason = Telemetry::LABELS_MEDIA_PLAY_PROMISE_RESOLUTION::Resolved;
  Telemetry::AccumulateCategorical(reason);
  Promise::MaybeResolveWithUndefined();
}


using PlayLabel = Telemetry::LABELS_MEDIA_PLAY_PROMISE_RESOLUTION;

struct PlayPromiseTelemetryResult {
  nsresult mValue;
  PlayLabel mLabel;
  const char* mName;
};

static const PlayPromiseTelemetryResult sPlayPromiseTelemetryResults[] = {
static const PlayPromiseTelemetryResult sPlayPromiseTelemetryResults[] = {
    {
        NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR,
        PlayLabel::NotAllowedErr,
        "NotAllowedErr",
    },
    },
    {
        NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR,
        PlayLabel::SrcNotSupportedErr,
        "SrcNotSupportedErr",
    },
    },
    {
        NS_ERROR_DOM_MEDIA_ABORT_ERR,
        PlayLabel::PauseAbortErr,
        "PauseAbortErr",
    },
    },
    {
        NS_ERROR_DOM_ABORT_ERR,
        NS_ERROR_DOM_ABORT_ERR,
        PlayLabel::AbortErr,
        "AbortErr",
    },
};


static const PlayPromiseTelemetryResult* FindPlayPromiseTelemetryResult(
    nsresult aReason) {
  for (const auto& p : sPlayPromiseTelemetryResults) {
  for (const auto& p : sPlayPromiseTelemetryResults) {
    if (p.mValue == aReason) {
    if (p.mValue == aReason) {
      return &p;
    }
  }
  }
  return nullptr;
}

static PlayLabel ToPlayResultLabel(nsresult aReason) {
  auto p = FindPlayPromiseTelemetryResult(aReason);
  auto p = FindPlayPromiseTelemetryResult(aReason);
  return p ? p->mLabel : PlayLabel::UnknownErr;
}

static const char* ToPlayResultStr(nsresult aReason) {
  auto p = FindPlayPromiseTelemetryResult(aReason);
  auto p = FindPlayPromiseTelemetryResult(aReason);
  return p ? p->mName : "UnknownErr";
}

void PlayPromise::MaybeReject(nsresult aReason) {
  if (mFulfilled) {
  if (mFulfilled) {
    return;
  }
  mFulfilled = true;
  PLAY_PROMISE_LOG("PlayPromise %p rejected with 0x%x (%s)", this,
                   static_cast<uint32_t>(aReason), ToPlayResultStr(aReason));
                   static_cast<uint32_t>(aReason), ToPlayResultStr(aReason));
  Telemetry::AccumulateCategorical(ToPlayResultLabel(aReason));
  Promise::MaybeReject(aReason);
}

}  // namespace dom
}  // namespace mozilla