Exemple #1
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();
}
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();
}
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();
}
Exemple #4
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);
  }
}
void
nsDOMTouchEvent::InitTouchEvent(const nsAString& aType,
                                bool aCanBubble,
                                bool aCancelable,
                                nsIDOMWindow* aView,
                                int32_t aDetail,
                                bool aCtrlKey,
                                bool aAltKey,
                                bool aShiftKey,
                                bool aMetaKey,
                                nsDOMTouchList* aTouches,
                                nsDOMTouchList* aTargetTouches,
                                nsDOMTouchList* aChangedTouches,
                                mozilla::ErrorResult& aRv)
{
  aRv = nsDOMUIEvent::InitUIEvent(aType,
                                  aCanBubble,
                                  aCancelable,
                                  aView,
                                  aDetail);
  if (aRv.Failed()) {
    return;
  }

  static_cast<nsInputEvent*>(mEvent)->InitBasicModifiers(aCtrlKey, aAltKey,
                                                         aShiftKey, aMetaKey);
  mTouches = aTouches;
  mTargetTouches = aTargetTouches;
  mChangedTouches = aChangedTouches;
}
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);
  }
}
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;
  }
}
// static
void
URL::CreateObjectURL(const GlobalObject& aGlobal, JSObject* aBlob,
                     const mozilla::dom::objectURLOptions& aOptions,
                     nsString& aResult, mozilla::ErrorResult& aRv)
{
  JSContext* cx = aGlobal.GetContext();
  WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx);

  nsCOMPtr<nsIDOMBlob> blob = file::GetDOMBlobFromJSObject(aBlob);
  if (!blob) {
    SetDOMStringToNull(aResult);

    NS_NAMED_LITERAL_STRING(argStr, "Argument 1 of URL.createObjectURL");
    NS_NAMED_LITERAL_STRING(blobStr, "Blob");
    aRv.ThrowTypeError(MSG_DOES_NOT_IMPLEMENT_INTERFACE, &argStr, &blobStr);
    return;
  }

  nsRefPtr<CreateURLRunnable> runnable =
    new CreateURLRunnable(workerPrivate, blob, aOptions, aResult);

  if (!runnable->Dispatch(cx)) {
    JS_ReportPendingException(cx);
  }
}
Exemple #9
0
void
DOMRequest::Then(JSContext* aCx, AnyCallback* aResolveCallback,
                 AnyCallback* aRejectCallback,
                 JS::MutableHandle<JS::Value> aRetval,
                 mozilla::ErrorResult& aRv)
{
  if (!mPromise) {
    mPromise = Promise::Create(DOMEventTargetHelper::GetParentObject(), aRv);
    if (aRv.Failed()) {
      return;
    }
    if (mDone) {
      // Since we create mPromise lazily, it's possible that the DOMRequest object
      // has already fired its success/error event.  In that case we should
      // manually resolve/reject mPromise here.  mPromise will take care of
      // calling the callbacks on |promise| as needed.
      if (mError) {
        mPromise->MaybeRejectBrokenly(mError);
      } else {
        mPromise->MaybeResolve(mResult);
      }
    }
  }

  // Just use the global of the Promise itself as the callee global.
  JS::Rooted<JSObject*> global(aCx, mPromise->PromiseObj());
  global = js::GetGlobalForObjectCrossCompartment(global);
  mPromise->Then(aCx, global, aResolveCallback, aRejectCallback, aRetval, aRv);
}
Exemple #10
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;
  }
}
void
DataTransfer::MozGetDataAt(JSContext* aCx, const nsAString& aFormat,
                           uint32_t aIndex,
                           JS::MutableHandle<JS::Value> aRetval,
                           nsIPrincipal& aSubjectPrincipal,
                           mozilla::ErrorResult& aRv)
{
  nsCOMPtr<nsIVariant> data;
  aRv = GetDataAtInternal(aFormat, aIndex, &aSubjectPrincipal,
                          getter_AddRefs(data));
  if (aRv.Failed()) {
    return;
  }

  if (!data) {
    aRetval.setNull();
    return;
  }

  JS::Rooted<JS::Value> result(aCx);
  if (!VariantToJsval(aCx, data, aRetval)) {
    aRv = NS_ERROR_FAILURE;
    return;
  }
}
Exemple #12
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;
}
already_AddRefed<WakeLock>
PowerManagerService::NewWakeLock(const nsAString& aTopic,
                                 nsIDOMWindow* aWindow,
                                 mozilla::ErrorResult& aRv)
{
  nsRefPtr<WakeLock> wakelock = new WakeLock();
  aRv = wakelock->Init(aTopic, aWindow);
  if (aRv.Failed()) {
    return nullptr;
  }

  return wakelock.forget();
}
Exemple #14
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);
}
Exemple #15
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);
}
Exemple #16
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);
}
Exemple #17
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;
}
Exemple #18
0
void
Cache::RecvAddAllResponse(RequestId aRequestId,
                          const mozilla::ErrorResult& aError)
{
  nsRefPtr<Promise> promise = RemoveRequestPromise(aRequestId);

  if (aError.Failed()) {
    // TODO: Remove this const_cast (bug 1152078).
    // It is safe for now since this ErrorResult is handed off to us by IPDL
    // and is thrown into the trash afterwards.
    promise->MaybeReject(const_cast<ErrorResult&>(aError));
    return;
  }

  promise->MaybeResolve(JS::UndefinedHandleValue);
}
Exemple #19
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);
}
Exemple #20
0
JS::Value
DataTransfer::MozGetDataAt(JSContext* aCx, const nsAString& aFormat,
                           uint32_t aIndex, mozilla::ErrorResult& aRv)
{
  nsCOMPtr<nsIVariant> data;
  aRv = MozGetDataAt(aFormat, aIndex, getter_AddRefs(data));
  if (aRv.Failed()) {
    return JS::UndefinedValue();
  }

  if (!data) {
    return JS::NullValue();
  }

  JS::Rooted<JS::Value> result(aCx);
  JS::Rooted<JSObject*> scope(aCx, GetWrapper());
  if (!VariantToJsval(aCx, scope, data, &result)) {
    aRv = NS_ERROR_FAILURE;
    return JS::UndefinedValue();
  }

  return result;
}
Exemple #21
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);
}
Exemple #22
0
already_AddRefed<Promise>
DOMRequest::Then(JSContext* aCx, AnyCallback* aResolveCallback,
                 AnyCallback* aRejectCallback, mozilla::ErrorResult& aRv)
{
  if (!mPromise) {
    mPromise = Promise::Create(DOMEventTargetHelper::GetParentObject(), aRv);
    if (aRv.Failed()) {
      return nullptr;
    }
    if (mDone) {
      // Since we create mPromise lazily, it's possible that the DOMRequest object
      // has already fired its success/error event.  In that case we should
      // manually resolve/reject mPromise here.  mPromise will take care of
      // calling the callbacks on |promise| as needed.
      if (mError) {
        mPromise->MaybeRejectBrokenly(mError);
      } else {
        mPromise->MaybeResolve(mResult);
      }
    }
  }

  return mPromise->Then(aCx, aResolveCallback, aRejectCallback, aRv);
}
void
nsROCSSPrimitiveValue::SetStringValue(uint16_t aType, const nsAString& aString,
                                      mozilla::ErrorResult& aRv)
{
  aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
}