Example #1
0
already_AddRefed<IIRFilterNode>
AudioContext::CreateIIRFilter(const mozilla::dom::binding_detail::AutoSequence<double>& aFeedforward,
                              const mozilla::dom::binding_detail::AutoSequence<double>& aFeedback,
                              mozilla::ErrorResult& aRv)
{
  if (CheckClosed(aRv)) {
    return nullptr;
  }

  if (aFeedforward.Length() == 0 || aFeedforward.Length() > 20) {
    aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
    return nullptr;
  }

  if (aFeedback.Length() == 0 || aFeedback.Length() > 20) {
    aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
    return nullptr;
  }

  bool feedforwardAllZeros = true;
  for (size_t i = 0; i < aFeedforward.Length(); ++i) {
    if (aFeedforward.Elements()[i] != 0.0) {
      feedforwardAllZeros = false;
    }
  }

  if (feedforwardAllZeros || aFeedback.Elements()[0] == 0.0) {
    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
    return nullptr;
  }

  RefPtr<IIRFilterNode> filterNode =
    new IIRFilterNode(this, aFeedforward, aFeedback);
  return filterNode.forget();
}
Example #2
0
void
nsImageLoadingContent::ForceReload(const mozilla::dom::Optional<bool>& aNotify,
                                   mozilla::ErrorResult& aError)
{
  nsCOMPtr<nsIURI> currentURI;
  GetCurrentURI(getter_AddRefs(currentURI));
  if (!currentURI) {
    aError.Throw(NS_ERROR_NOT_AVAILABLE);
    return;
  }

  // defaults to true
  bool notify = !aNotify.WasPassed() || aNotify.Value();

  // We keep this flag around along with the old URI even for failed requests
  // without a live request object
  ImageLoadType loadType = \
    (mCurrentRequestFlags & REQUEST_IS_IMAGESET) ? eImageLoadType_Imageset
                                                 : eImageLoadType_Normal;
  nsresult rv = LoadImage(currentURI, true, notify, loadType, true, nullptr,
                          nsIRequest::VALIDATE_ALWAYS);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
}
already_AddRefed<mozilla::dom::DocumentType>
NS_NewDOMDocumentType(nsNodeInfoManager* aNodeInfoManager,
                      nsIAtom *aName,
                      const nsAString& aPublicId,
                      const nsAString& aSystemId,
                      const nsAString& aInternalSubset,
                      mozilla::ErrorResult& rv)
{
  if (!aName) {
    rv.Throw(NS_ERROR_INVALID_POINTER);
    return nullptr;
  }

  nsCOMPtr<nsINodeInfo> ni =
    aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nullptr,
                                  kNameSpaceID_None,
                                  nsIDOMNode::DOCUMENT_TYPE_NODE,
                                  aName);
  if (!ni) {
    rv.Throw(NS_ERROR_OUT_OF_MEMORY);
    return nullptr;
  }

  nsRefPtr<mozilla::dom::DocumentType> docType =
    new mozilla::dom::DocumentType(ni.forget(), aPublicId, aSystemId, aInternalSubset);
  return docType.forget();
}
Example #4
0
/*static */already_AddRefed<nsDOMParser>
nsDOMParser::Constructor(nsISupports* aOwner, mozilla::ErrorResult& rv)
{
  nsCOMPtr<nsIPrincipal> prin;
  nsCOMPtr<nsIURI> documentURI;
  nsCOMPtr<nsIURI> baseURI;
  // No arguments; use the subject principal
  nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
  if (!secMan) {
    rv.Throw(NS_ERROR_UNEXPECTED);
    return nullptr;
  }

  rv = secMan->GetSubjectPrincipal(getter_AddRefs(prin));
  if (rv.Failed()) {
    return nullptr;
  }

  // We're called from JS; there better be a subject principal, really.
  if (!prin) {
    rv.Throw(NS_ERROR_UNEXPECTED);
    return nullptr;
  }

  nsRefPtr<nsDOMParser> domParser = new nsDOMParser(aOwner);
  rv = domParser->InitInternal(aOwner, prin, documentURI, baseURI);
  if (rv.Failed()) {
    return nullptr;
  }
  return domParser.forget();
}
Example #5
0
void
TCPSocket::UpgradeToSecure(mozilla::ErrorResult& aRv)
{
  if (mReadyState != TCPReadyState::Open) {
    aRv.Throw(NS_ERROR_FAILURE);
    return;
  }

  if (mSsl) {
    return;
  }

  mSsl = true;

  if (mSocketBridgeChild) {
    mSocketBridgeChild->SendStartTLS();
    return;
  }

  uint32_t count = 0;
  mMultiplexStream->GetCount(&count);
  if (!count) {
    ActivateTLS();
  } else {
    mWaitingForStartTLS = true;
  }
}
Example #6
0
void
TCPSocket::UpgradeToSecure(mozilla::ErrorResult& aRv)
{
  if (mReadyState != TCPReadyState::Open) {
    aRv.Throw(NS_ERROR_FAILURE);
    return;
  }

  if (mSsl) {
    return;
  }

  mSsl = true;

  if (mSocketBridgeChild) {
    mSocketBridgeChild->SendStartTLS();
    return;
  }

  if (!mAsyncCopierActive) {
    ActivateTLS();
  } else {
    mWaitingForStartTLS = true;
  }
}
Example #7
0
void
HTMLAnchorElement::GetText(nsAString& aText, mozilla::ErrorResult& aRv)
{
  if (NS_WARN_IF(!nsContentUtils::GetNodeTextContent(this, true, aText, fallible))) {
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
  }
}
Example #8
0
JS::Value
IDBRequest::GetResult(JSContext* aCx, mozilla::ErrorResult& aRv) const
{
  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");

  if (!mHaveResultOrErrorCode) {
    // XXX Need a real error code here.
    aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
  }

  return mResultVal;
}
Example #9
0
void
nsDOMParser::Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI,
                  nsIURI* aBaseURI, mozilla::ErrorResult& rv)
{
  AttemptedInitMarker marker(&mAttemptedInit);

  JSContext *cx = nsContentUtils::GetCurrentJSContext();
  if (!cx) {
    rv.Throw(NS_ERROR_UNEXPECTED);
    return;
  }

  nsIScriptContext* scriptContext = GetScriptContextFromJSContext(cx);

  nsCOMPtr<nsIPrincipal> principal = aPrincipal;

  if (!principal && !aDocumentURI) {
    nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
    if (!secMan) {
      rv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }

    rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal));
    if (rv.Failed()) {
      return;
    }

    // We're called from JS; there better be a subject principal, really.
    if (!principal) {
      rv.Throw(NS_ERROR_UNEXPECTED);
      return;
    }
  }

  rv = Init(principal, aDocumentURI, aBaseURI,
            scriptContext ? scriptContext->GetGlobalObject() : nullptr);
}
Example #10
0
already_AddRefed<TCPSocket>
LegacyMozTCPSocket::Open(const nsAString& aHost,
                         uint16_t aPort,
                         const SocketOptions& aOptions,
                         mozilla::ErrorResult& aRv)
{
  AutoJSAPI api;
  if (NS_WARN_IF(!api.Init(mGlobal))) {
    aRv.Throw(NS_ERROR_FAILURE);
    return nullptr;
  }
  GlobalObject globalObj(api.cx(), mGlobal->GetGlobalJSObject());
  return TCPSocket::Constructor(globalObj, aHost, aPort, aOptions, aRv);
}
Example #11
0
void
nsHistory::SetScrollRestoration(mozilla::dom::ScrollRestoration aMode,
                                mozilla::ErrorResult& aRv)
{
  nsCOMPtr<nsPIDOMWindowInner> win(do_QueryReferent(mInnerWindow));
  if (!win || !win->HasActiveDocument() || !win->GetDocShell()) {
    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
    return;
  }

  win->GetDocShell()->
    SetCurrentScrollRestorationIsManual(
      aMode == mozilla::dom::ScrollRestoration::Manual);
}
Example #12
0
ScrollRestoration
nsHistory::GetScrollRestoration(mozilla::ErrorResult& aRv)
{
  nsCOMPtr<nsPIDOMWindowInner> win(do_QueryReferent(mInnerWindow));
  if (!win || !win->HasActiveDocument() || !win->GetDocShell()) {
    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
    return mozilla::dom::ScrollRestoration::Auto;
  }

  bool currentScrollRestorationIsManual = false;
  win->GetDocShell()->
    GetCurrentScrollRestorationIsManual(&currentScrollRestorationIsManual);
  return currentScrollRestorationIsManual ?
    mozilla::dom::ScrollRestoration::Manual :
    mozilla::dom::ScrollRestoration::Auto;
}
Example #13
0
void
DOMParser::Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI,
                nsIURI* aBaseURI, mozilla::ErrorResult& rv)
{
  AttemptedInitMarker marker(&mAttemptedInit);

  JSContext *cx = nsContentUtils::GetCurrentJSContext();
  if (!cx) {
    rv.Throw(NS_ERROR_UNEXPECTED);
    return;
  }

  nsIScriptContext* scriptContext = GetScriptContextFromJSContext(cx);

  nsCOMPtr<nsIPrincipal> principal = aPrincipal;
  if (!principal && !aDocumentURI) {
    principal = nsContentUtils::SubjectPrincipal();
  }

  rv = Init(principal, aDocumentURI, aBaseURI,
            scriptContext ? scriptContext->GetGlobalObject() : nullptr);
}
Example #14
0
/*
 * Tests if and how a node should be filtered. Uses mWhatToShow and
 * mFilter to test the node.
 * @param aNode     Node to test
 * @param aResult   Whether we succeeded
 * @returns         Filtervalue. See NodeFilter.webidl
 */
int16_t nsTraversal::TestNode(nsINode* aNode, mozilla::ErrorResult& aResult) {
  if (mInAcceptNode) {
    aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
    return 0;
  }

  uint16_t nodeType = aNode->NodeType();

  if (nodeType <= 12 && !((1 << (nodeType - 1)) & mWhatToShow)) {
    return NodeFilter_Binding::FILTER_SKIP;
  }

  if (!mFilter) {
    // No filter, just accept
    return NodeFilter_Binding::FILTER_ACCEPT;
  }

  AutoRestore<bool> inAcceptNode(mInAcceptNode);
  mInAcceptNode = true;
  // No need to pass in an execution reason, since the generated default,
  // "NodeFilter.acceptNode", is pretty much exactly what we'd say anyway.
  return mFilter->AcceptNode(*aNode, aResult, nullptr,
                             CallbackObject::eRethrowExceptions);
}
void
nsROCSSPrimitiveValue::SetStringValue(uint16_t aType, const nsAString& aString,
                                      mozilla::ErrorResult& aRv)
{
  aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
}