Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


Quelle  JSValidatorParent.cpp  Sprache: C


/* 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/JSValidatorParent.h"

#include "HttpBaseChannel.h"
#include "mozilla/RefPtr.h"
#include "mozilla/dom/JSOracleParent.h"
#include "mozilla/dom/JSValidatorUtils.h"
#include "mozilla/net/OpaqueResponseUtils.h"
#include "nsCOMPtr.h"

namespace mozilla::dom {
/* static */
already_AddRefed<JSValidatorParent> JSValidatorParent::Create() {
  RefPtr<JSValidatorParent> validator = new JSValidatorParent();
  JSOracleParent::WithJSOracle([validator](JSOracleParent* aParent) {
    MOZ_ASSERT_IF(aParent, aParent->CanSend());
    if (aParent) {
      MOZ_ALWAYS_TRUE(aParent->SendPJSValidatorConstructor(validator));
    }
  });
  return validator.forget();
}

void JSValidatorParent::IsOpaqueResponseAllowed(
    const std::function<void(Maybe<Shmem>, ValidatorResult)>& aCallback) {
  JSOracleParent::WithJSOracle([=, self = RefPtr{this}](const auto* aParent) {
    if (aParent) {
      MOZ_DIAGNOSTIC_ASSERT(self->CanSend());
      self->SendIsOpaqueResponseAllowed()->Then(
          GetMainThreadSerialEventTarget(), __func__,
          [aCallback](
              const IsOpaqueResponseAllowedPromise::ResolveOrRejectValue&
                  aResult) {
            if (aResult.IsResolve()) {
              auto [data, result] = aResult.ResolveValue();
              aCallback(std::move(data), result);
            } else {
              // For cases like the Utility Process crashes, the promise will be
              // rejected due to sending failures, and we'll block the request
              // since we can't validate it.
              aCallback(Nothing(), ValidatorResult::Failure);
            }
          });
    } else {
      aCallback(Nothing(), ValidatorResult::Failure);
    }
  });
}

void JSValidatorParent::OnDataAvailable(const nsACString& aData) {
  JSOracleParent::WithJSOracle(
      [self = RefPtr{this}, data = nsCString{aData}](const auto* aParent) {
        if (!aParent) {
          return;
        }

        if (self->CanSend()) {
          Shmem sharedData;
          nsresult rv =
              JSValidatorUtils::CopyCStringToShmem(self, data, sharedData);
          if (NS_FAILED(rv)) {
            return;
          }
          (void)self->SendOnDataAvailable(std::move(sharedData));
        }
      });
}

void JSValidatorParent::OnStopRequest(nsresult aResult, nsIRequest& aRequest) {
  JSOracleParent::WithJSOracle(
      [self = RefPtr{this}, aResult,
       request = nsCOMPtr{&aRequest}](const auto* aParent) {
        if (!aParent) {
          return;
        }
        if (self->CanSend() && request) {
          nsCOMPtr<net::HttpBaseChannel> httpBaseChannel =
              do_QueryInterface(request);
          MOZ_ASSERT(httpBaseChannel);

          nsAutoCString contentCharset;
          (void)httpBaseChannel->GetContentCharset(contentCharset);

          nsAutoString hintCharset;
          (void)httpBaseChannel->GetClassicScriptHintCharset(hintCharset);

          nsAutoString documentCharset;
          (void)httpBaseChannel->GetDocumentCharacterSet(documentCharset);

          (void)self->SendOnStopRequest(aResult, contentCharset, hintCharset,
                                        documentCharset);
        }
      });
}
}  // namespace mozilla::dom

Messung
CHZG
861008991

¤ Dauer der Verarbeitung: 0.4 Sekunden  (vorverarbeitet am  2026-11-25) ¤

*© Formatika GbR, Deutschland







                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

letze Version des Elbe Quellennavigators


letze Version des Demonstrationsprogramms Goedel
letze Version des Bille Abgleichprogramms
Version

Jenseits des Üblichen ....

Besucher

Besucher

Statistik
#Sources=1,188,972
#Domains=963,782