Пример #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();
}
Пример #2
0
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;
  }
}
Пример #3
0
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;
}
Пример #4
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);
}
Пример #5
0
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();
}
Пример #6
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);
}
Пример #7
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);
}
Пример #8
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;
}
Пример #9
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);
}